aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-07-13 15:09:57 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-07-13 15:09:57 -0400
commit858655116bfc722837e3aec0909b8e9d08f96996 (patch)
treeef9171d51ffcd01e40d1131d62be32e5a7d371dc
parent239dab4636f7f5f971ac39b5ca84254cff112cac (diff)
parent1b2c14b44adcb7836528640bfdc40bf7499d987d (diff)
Merge branch 'v4l_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media
Pull media updates from Mauro Carvalho Chehab: "This series contain: - new i2c video drivers: ml86v7667 (video decoder), ths8200 (video encoder) - a new video driver for EasyCap cards based on Fushicai USBTV007 - Improved support for OF and embedded systems, with V4L2 async initialization and a better support for clocks - API cleanups on the ioctls used by the v4l2 debug tool - Lots of cleanups - As usual, several driver improvements and new cards additions - Revert two changesets that change the minimal symbol rate for stv0399, as request by Manu - Update MAINTAINERS and other files to point to my new e-mail" * 'v4l_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media: (378 commits) MAINTAINERS & ABI: Update to point to my new email [media] stb0899: restore minimal rate to 5Mbauds [media] exynos4-is: Correct colorspace handling at FIMC-LITE [media] exynos4-is: Set valid initial format on FIMC.n subdevs [media] exynos4-is: Set valid initial format on FIMC-IS-ISP subdev pads [media] exynos4-is: Fix format propagation on FIMC-IS-ISP subdev [media] exynos4-is: Set valid initial format at FIMC-LITE [media] exynos4-is: Fix format propagation on FIMC-LITE.n subdevs [media] MAINTAINERS: Update S5P/Exynos FIMC driver entry [media] Documentation: Update driver's directory in video4linux/fimc.txt [media] exynos4-is: Change fimc-is firmware file names [media] exynos4-is: Add support for Exynos5250 MIPI-CSIS [media] exynos4-is: Add Exynos5250 SoC support to fimc-lite driver [media] exynos4-is: Drop drvdata handling in fimc-lite for non-dt platforms [media] media: i2c: tvp514x: remove manual setting of subdev name [media] media: i2c: tvp7002: remove manual setting of subdev name [media] mem2mem: set missing v4l2_dev pointer [media] wl128x: add missing struct v4l2_device [media] tvp514x: Fix init seqeunce [media] saa7134: Fix sparse warnings by adding __user annotation ...
-rw-r--r--Documentation/ABI/testing/sysfs-devices-edac14
-rw-r--r--Documentation/DocBook/media/v4l/compat.xml14
-rw-r--r--Documentation/DocBook/media/v4l/v4l2.xml11
-rw-r--r--Documentation/DocBook/media/v4l/vidioc-dbg-g-chip-ident.xml271
-rw-r--r--Documentation/DocBook/media/v4l/vidioc-dbg-g-chip-info.xml20
-rw-r--r--Documentation/DocBook/media/v4l/vidioc-dbg-g-register.xml64
-rw-r--r--Documentation/DocBook/media/v4l/vidioc-querystd.xml3
-rw-r--r--Documentation/devicetree/bindings/media/exynos-fimc-lite.txt6
-rw-r--r--Documentation/devicetree/bindings/media/i2c/mt9p031.txt40
-rw-r--r--Documentation/devicetree/bindings/media/i2c/tvp514x.txt44
-rw-r--r--Documentation/devicetree/bindings/media/samsung-fimc.txt26
-rw-r--r--Documentation/devicetree/bindings/media/samsung-mipi-csis.txt4
-rw-r--r--Documentation/devicetree/bindings/media/sh_mobile_ceu.txt18
-rw-r--r--Documentation/media-framework.txt2
-rw-r--r--Documentation/video4linux/CARDLIST.bttv3
-rw-r--r--Documentation/video4linux/CARDLIST.saa71341
-rw-r--r--Documentation/video4linux/CARDLIST.tuner6
-rw-r--r--Documentation/video4linux/fimc.txt21
-rw-r--r--Documentation/video4linux/v4l2-framework.txt103
-rw-r--r--Documentation/zh_CN/video4linux/v4l2-framework.txt13
-rw-r--r--MAINTAINERS50
-rw-r--r--arch/arm/mach-davinci/board-dm365-evm.c1
-rw-r--r--drivers/base/dma-buf.c5
-rw-r--r--drivers/media/common/saa7146/saa7146_video.c23
-rw-r--r--drivers/media/common/siano/smscoreapi.c23
-rw-r--r--drivers/media/common/siano/smsdvb-main.c1
-rw-r--r--drivers/media/common/tveeprom.c142
-rw-r--r--drivers/media/dvb-core/dmxdev.c8
-rw-r--r--drivers/media/dvb-core/dvb-usb-ids.h2
-rw-r--r--drivers/media/dvb-frontends/au8522_decoder.c21
-rw-r--r--drivers/media/dvb-frontends/dib8000.c4
-rw-r--r--drivers/media/dvb-frontends/drxk.h2
-rw-r--r--drivers/media/dvb-frontends/drxk_hard.c3154
-rw-r--r--drivers/media/dvb-frontends/drxk_hard.h277
-rw-r--r--drivers/media/dvb-frontends/stb0899_algo.c105
-rw-r--r--drivers/media/dvb-frontends/stb0899_drv.c5
-rw-r--r--drivers/media/dvb-frontends/stb0899_drv.h5
-rw-r--r--drivers/media/i2c/Kconfig18
-rw-r--r--drivers/media/i2c/Makefile2
-rw-r--r--drivers/media/i2c/ad9389b.c35
-rw-r--r--drivers/media/i2c/adp1653.c5
-rw-r--r--drivers/media/i2c/adv7170.c16
-rw-r--r--drivers/media/i2c/adv7175.c12
-rw-r--r--drivers/media/i2c/adv7180.c79
-rw-r--r--drivers/media/i2c/adv7183.c80
-rw-r--r--drivers/media/i2c/adv7343.c10
-rw-r--r--drivers/media/i2c/adv7393.c18
-rw-r--r--drivers/media/i2c/adv7604.c33
-rw-r--r--drivers/media/i2c/ak881x.c39
-rw-r--r--drivers/media/i2c/as3645a.c7
-rw-r--r--drivers/media/i2c/bt819.c26
-rw-r--r--drivers/media/i2c/bt856.c12
-rw-r--r--drivers/media/i2c/bt866.c16
-rw-r--r--drivers/media/i2c/cs5345.c25
-rw-r--r--drivers/media/i2c/cs53l32a.c14
-rw-r--r--drivers/media/i2c/cx25840/cx25840-core.c72
-rw-r--r--drivers/media/i2c/cx25840/cx25840-core.h34
-rw-r--r--drivers/media/i2c/cx25840/cx25840-ir.c7
-rw-r--r--drivers/media/i2c/ir-kbd-i2c.c10
-rw-r--r--drivers/media/i2c/ks0127.c36
-rw-r--r--drivers/media/i2c/m52790.c22
-rw-r--r--drivers/media/i2c/m5mols/m5mols_core.c43
-rw-r--r--drivers/media/i2c/ml86v7667.c431
-rw-r--r--drivers/media/i2c/msp3400-driver.c15
-rw-r--r--drivers/media/i2c/mt9m032.c13
-rw-r--r--drivers/media/i2c/mt9p031.c87
-rw-r--r--drivers/media/i2c/mt9t001.c4
-rw-r--r--drivers/media/i2c/mt9v011.c34
-rw-r--r--drivers/media/i2c/mt9v032.c8
-rw-r--r--drivers/media/i2c/noon010pc30.c41
-rw-r--r--drivers/media/i2c/ov7640.c6
-rw-r--r--drivers/media/i2c/ov7670.c26
-rw-r--r--drivers/media/i2c/s5c73m3/s5c73m3-core.c88
-rw-r--r--drivers/media/i2c/s5c73m3/s5c73m3-spi.c4
-rw-r--r--drivers/media/i2c/s5k6aa.c73
-rw-r--r--drivers/media/i2c/saa6588.c19
-rw-r--r--drivers/media/i2c/saa7110.c17
-rw-r--r--drivers/media/i2c/saa7115.c297
-rw-r--r--drivers/media/i2c/saa7127.c55
-rw-r--r--drivers/media/i2c/saa717x.c16
-rw-r--r--drivers/media/i2c/saa7185.c12
-rw-r--r--drivers/media/i2c/saa7191.c28
-rw-r--r--drivers/media/i2c/smiapp/smiapp-core.c20
-rw-r--r--drivers/media/i2c/soc_camera/imx074.c51
-rw-r--r--drivers/media/i2c/soc_camera/mt9m001.c50
-rw-r--r--drivers/media/i2c/soc_camera/mt9m111.c53
-rw-r--r--drivers/media/i2c/soc_camera/mt9t031.c54
-rw-r--r--drivers/media/i2c/soc_camera/mt9t112.c35
-rw-r--r--drivers/media/i2c/soc_camera/mt9v022.c64
-rw-r--r--drivers/media/i2c/soc_camera/ov2640.c35
-rw-r--r--drivers/media/i2c/soc_camera/ov5642.c39
-rw-r--r--drivers/media/i2c/soc_camera/ov6650.c29
-rw-r--r--drivers/media/i2c/soc_camera/ov772x.c31
-rw-r--r--drivers/media/i2c/soc_camera/ov9640.c35
-rw-r--r--drivers/media/i2c/soc_camera/ov9640.h1
-rw-r--r--drivers/media/i2c/soc_camera/ov9740.c35
-rw-r--r--drivers/media/i2c/soc_camera/rj54n1cb0c.c48
-rw-r--r--drivers/media/i2c/soc_camera/tw9910.c33
-rw-r--r--drivers/media/i2c/sony-btf-mpx.c5
-rw-r--r--drivers/media/i2c/sr030pc30.c280
-rw-r--r--drivers/media/i2c/tda7432.c4
-rw-r--r--drivers/media/i2c/tda9840.c16
-rw-r--r--drivers/media/i2c/tea6415c.c16
-rw-r--r--drivers/media/i2c/tea6420.c16
-rw-r--r--drivers/media/i2c/ths7303.c81
-rw-r--r--drivers/media/i2c/ths8200.c556
-rw-r--r--drivers/media/i2c/ths8200_regs.h161
-rw-r--r--drivers/media/i2c/tlv320aic23b.c4
-rw-r--r--drivers/media/i2c/tvaudio.c14
-rw-r--r--drivers/media/i2c/tvp514x.c87
-rw-r--r--drivers/media/i2c/tvp5150.c50
-rw-r--r--drivers/media/i2c/tvp7002.c143
-rw-r--r--drivers/media/i2c/tw2804.c6
-rw-r--r--drivers/media/i2c/tw9903.c5
-rw-r--r--drivers/media/i2c/tw9906.c5
-rw-r--r--drivers/media/i2c/uda1342.c3
-rw-r--r--drivers/media/i2c/upd64031a.c24
-rw-r--r--drivers/media/i2c/upd64083.c24
-rw-r--r--drivers/media/i2c/vp27smpx.c12
-rw-r--r--drivers/media/i2c/vpx3220.c29
-rw-r--r--drivers/media/i2c/vs6624.c46
-rw-r--r--drivers/media/i2c/wm8739.c13
-rw-r--r--drivers/media/i2c/wm8775.c13
-rw-r--r--drivers/media/media-device.c3
-rw-r--r--drivers/media/media-entity.c81
-rw-r--r--drivers/media/parport/bw-qcam.c2
-rw-r--r--drivers/media/pci/Kconfig4
-rw-r--r--drivers/media/pci/b2c2/flexcop-pci.c13
-rw-r--r--drivers/media/pci/bt8xx/bttv-cards.c52
-rw-r--r--drivers/media/pci/bt8xx/bttv-driver.c48
-rw-r--r--drivers/media/pci/bt8xx/bttv.h4
-rw-r--r--drivers/media/pci/cx18/cx18-av-core.c36
-rw-r--r--drivers/media/pci/cx18/cx18-av-core.h1
-rw-r--r--drivers/media/pci/cx18/cx18-ioctl.c82
-rw-r--r--drivers/media/pci/cx23885/cx23885-417.c9
-rw-r--r--drivers/media/pci/cx23885/cx23885-ioctl.c145
-rw-r--r--drivers/media/pci/cx23885/cx23885-ioctl.h4
-rw-r--r--drivers/media/pci/cx23885/cx23885-video.c9
-rw-r--r--drivers/media/pci/cx23885/cx23888-ir.c31
-rw-r--r--drivers/media/pci/cx88/cx88-cards.c12
-rw-r--r--drivers/media/pci/cx88/cx88-core.c7
-rw-r--r--drivers/media/pci/cx88/cx88-video.c25
-rw-r--r--drivers/media/pci/cx88/cx88.h8
-rw-r--r--drivers/media/pci/dm1105/dm1105.c13
-rw-r--r--drivers/media/pci/ivtv/ivtv-driver.c8
-rw-r--r--drivers/media/pci/ivtv/ivtv-ioctl.c45
-rw-r--r--drivers/media/pci/mantis/hopper_cards.c13
-rw-r--r--drivers/media/pci/mantis/mantis_cards.c13
-rw-r--r--drivers/media/pci/mantis/mantis_vp1041.c2
-rw-r--r--drivers/media/pci/pluto2/pluto2.c13
-rw-r--r--drivers/media/pci/pt1/pt1.c15
-rw-r--r--drivers/media/pci/saa7134/saa6752hs.c525
-rw-r--r--drivers/media/pci/saa7134/saa7134-empress.c33
-rw-r--r--drivers/media/pci/saa7134/saa7134-video.c260
-rw-r--r--drivers/media/pci/saa7134/saa7134.h17
-rw-r--r--drivers/media/pci/saa7146/mxb.c23
-rw-r--r--drivers/media/pci/saa7164/saa7164-core.c8
-rw-r--r--drivers/media/pci/saa7164/saa7164-encoder.c58
-rw-r--r--drivers/media/pci/saa7164/saa7164-vbi.c24
-rw-r--r--drivers/media/pci/saa7164/saa7164.h5
-rw-r--r--drivers/media/pci/sta2x11/sta2x11_vip.c3
-rw-r--r--drivers/media/pci/ttpci/budget-av.c2
-rw-r--r--drivers/media/pci/ttpci/budget-ci.c2
-rw-r--r--drivers/media/pci/zoran/zoran_card.c2
-rw-r--r--drivers/media/pci/zoran/zoran_driver.c23
-rw-r--r--drivers/media/platform/Kconfig2
-rw-r--r--drivers/media/platform/blackfin/bfin_capture.c81
-rw-r--r--drivers/media/platform/blackfin/ppi.c12
-rw-r--r--drivers/media/platform/coda.c635
-rw-r--r--drivers/media/platform/coda.h11
-rw-r--r--drivers/media/platform/davinci/vpbe_display.c31
-rw-r--r--drivers/media/platform/davinci/vpbe_osd.c24
-rw-r--r--drivers/media/platform/davinci/vpif.c45
-rw-r--r--drivers/media/platform/davinci/vpif_capture.c160
-rw-r--r--drivers/media/platform/davinci/vpif_capture.h5
-rw-r--r--drivers/media/platform/davinci/vpif_display.c153
-rw-r--r--drivers/media/platform/davinci/vpif_display.h5
-rw-r--r--drivers/media/platform/exynos-gsc/gsc-core.c2
-rw-r--r--drivers/media/platform/exynos4-is/Kconfig5
-rw-r--r--drivers/media/platform/exynos4-is/Makefile5
-rw-r--r--drivers/media/platform/exynos4-is/common.c53
-rw-r--r--drivers/media/platform/exynos4-is/common.h16
-rw-r--r--drivers/media/platform/exynos4-is/fimc-capture.c412
-rw-r--r--drivers/media/platform/exynos4-is/fimc-core.c11
-rw-r--r--drivers/media/platform/exynos4-is/fimc-core.h15
-rw-r--r--drivers/media/platform/exynos4-is/fimc-is-i2c.c2
-rw-r--r--drivers/media/platform/exynos4-is/fimc-is-param.c84
-rw-r--r--drivers/media/platform/exynos4-is/fimc-is-regs.c4
-rw-r--r--drivers/media/platform/exynos4-is/fimc-is.c12
-rw-r--r--drivers/media/platform/exynos4-is/fimc-is.h12
-rw-r--r--drivers/media/platform/exynos4-is/fimc-isp.c130
-rw-r--r--drivers/media/platform/exynos4-is/fimc-isp.h21
-rw-r--r--drivers/media/platform/exynos4-is/fimc-lite-reg.c55
-rw-r--r--drivers/media/platform/exynos4-is/fimc-lite-reg.h10
-rw-r--r--drivers/media/platform/exynos4-is/fimc-lite.c321
-rw-r--r--drivers/media/platform/exynos4-is/fimc-lite.h35
-rw-r--r--drivers/media/platform/exynos4-is/fimc-m2m.c1
-rw-r--r--drivers/media/platform/exynos4-is/fimc-reg.c7
-rw-r--r--drivers/media/platform/exynos4-is/media-dev.c272
-rw-r--r--drivers/media/platform/exynos4-is/media-dev.h54
-rw-r--r--drivers/media/platform/exynos4-is/mipi-csis.c67
-rw-r--r--drivers/media/platform/fsl-viu.c2
-rw-r--r--drivers/media/platform/indycam.c12
-rw-r--r--drivers/media/platform/m2m-deinterlace.c1
-rw-r--r--drivers/media/platform/marvell-ccic/cafe-driver.c4
-rw-r--r--drivers/media/platform/marvell-ccic/mcam-core.c67
-rw-r--r--drivers/media/platform/marvell-ccic/mcam-core.h9
-rw-r--r--drivers/media/platform/marvell-ccic/mmp-driver.c4
-rw-r--r--drivers/media/platform/mem2mem_testdev.c3
-rw-r--r--drivers/media/platform/mx2_emmaprp.c1
-rw-r--r--drivers/media/platform/omap/omap_vout.c3
-rw-r--r--drivers/media/platform/omap24xxcam.c9
-rw-r--r--drivers/media/platform/omap24xxcam.h3
-rw-r--r--drivers/media/platform/omap3isp/isp.c51
-rw-r--r--drivers/media/platform/omap3isp/ispccdc.c2
-rw-r--r--drivers/media/platform/omap3isp/ispccp2.c21
-rw-r--r--drivers/media/platform/omap3isp/ispcsi2.c2
-rw-r--r--drivers/media/platform/omap3isp/ispqueue.h1
-rw-r--r--drivers/media/platform/omap3isp/ispvideo.c6
-rw-r--r--drivers/media/platform/s3c-camif/camif-capture.c2
-rw-r--r--drivers/media/platform/s3c-camif/camif-core.c6
-rw-r--r--drivers/media/platform/s3c-camif/camif-regs.c6
-rw-r--r--drivers/media/platform/s5p-mfc/s5p_mfc.c2
-rw-r--r--drivers/media/platform/s5p-tv/hdmi_drv.c39
-rw-r--r--drivers/media/platform/s5p-tv/mixer_drv.c22
-rw-r--r--drivers/media/platform/s5p-tv/mixer_video.c3
-rw-r--r--drivers/media/platform/s5p-tv/sdo_drv.c22
-rw-r--r--drivers/media/platform/s5p-tv/sii9234_drv.c4
-rw-r--r--drivers/media/platform/sh_veu.c5
-rw-r--r--drivers/media/platform/sh_vou.c34
-rw-r--r--drivers/media/platform/soc_camera/Kconfig12
-rw-r--r--drivers/media/platform/soc_camera/Makefile6
-rw-r--r--drivers/media/platform/soc_camera/atmel-isi.c38
-rw-r--r--drivers/media/platform/soc_camera/mx1_camera.c48
-rw-r--r--drivers/media/platform/soc_camera/mx2_camera.c41
-rw-r--r--drivers/media/platform/soc_camera/mx3_camera.c44
-rw-r--r--drivers/media/platform/soc_camera/omap1_camera.c41
-rw-r--r--drivers/media/platform/soc_camera/pxa_camera.c46
-rw-r--r--drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c642
-rw-r--r--drivers/media/platform/soc_camera/sh_mobile_csi2.c161
-rw-r--r--drivers/media/platform/soc_camera/soc_camera.c737
-rw-r--r--drivers/media/platform/soc_camera/soc_camera_platform.c14
-rw-r--r--drivers/media/platform/soc_camera/soc_scale_crop.c402
-rw-r--r--drivers/media/platform/soc_camera/soc_scale_crop.h47
-rw-r--r--drivers/media/platform/timblogiw.c11
-rw-r--r--drivers/media/platform/via-camera.c24
-rw-r--r--drivers/media/radio/radio-keene.c7
-rw-r--r--drivers/media/radio/radio-sf16fmi.c127
-rw-r--r--drivers/media/radio/radio-si476x.c11
-rw-r--r--drivers/media/radio/radio-tea5764.c190
-rw-r--r--drivers/media/radio/radio-timb.c81
-rw-r--r--drivers/media/radio/saa7706h.c66
-rw-r--r--drivers/media/radio/tef6862.c24
-rw-r--r--drivers/media/radio/wl128x/fmdrv.h2
-rw-r--r--drivers/media/radio/wl128x/fmdrv_common.c24
-rw-r--r--drivers/media/radio/wl128x/fmdrv_v4l2.c8
-rw-r--r--drivers/media/rc/gpio-ir-recv.c2
-rw-r--r--drivers/media/rc/keymaps/Makefile1
-rw-r--r--drivers/media/rc/keymaps/rc-delock-61959.c83
-rw-r--r--drivers/media/tuners/r820t.c18
-rw-r--r--drivers/media/usb/Kconfig5
-rw-r--r--drivers/media/usb/Makefile1
-rw-r--r--drivers/media/usb/au0828/au0828-video.c40
-rw-r--r--drivers/media/usb/cx231xx/cx231xx-417.c1
-rw-r--r--drivers/media/usb/cx231xx/cx231xx-avcore.c1
-rw-r--r--drivers/media/usb/cx231xx/cx231xx-cards.c1
-rw-r--r--drivers/media/usb/cx231xx/cx231xx-vbi.c1
-rw-r--r--drivers/media/usb/cx231xx/cx231xx-video.c424
-rw-r--r--drivers/media/usb/cx231xx/cx231xx.h2
-rw-r--r--drivers/media/usb/dvb-usb-v2/af9035.c66
-rw-r--r--drivers/media/usb/dvb-usb-v2/af9035.h11
-rw-r--r--drivers/media/usb/dvb-usb-v2/dvb_usb.h2
-rw-r--r--drivers/media/usb/dvb-usb-v2/it913x.c5
-rw-r--r--drivers/media/usb/dvb-usb-v2/mxl111sf-tuner.c8
-rw-r--r--drivers/media/usb/dvb-usb-v2/mxl111sf.c90
-rw-r--r--drivers/media/usb/dvb-usb-v2/rtl28xxu.c180
-rw-r--r--drivers/media/usb/dvb-usb-v2/rtl28xxu.h6
-rw-r--r--drivers/media/usb/dvb-usb/az6027.c2
-rw-r--r--drivers/media/usb/dvb-usb/pctv452e.c2
-rw-r--r--drivers/media/usb/em28xx/em28xx-cards.c239
-rw-r--r--drivers/media/usb/em28xx/em28xx-core.c27
-rw-r--r--drivers/media/usb/em28xx/em28xx-dvb.c73
-rw-r--r--drivers/media/usb/em28xx/em28xx-input.c1
-rw-r--r--drivers/media/usb/em28xx/em28xx-reg.h23
-rw-r--r--drivers/media/usb/em28xx/em28xx-video.c66
-rw-r--r--drivers/media/usb/em28xx/em28xx.h7
-rw-r--r--drivers/media/usb/gspca/gspca.c32
-rw-r--r--drivers/media/usb/gspca/gspca.h6
-rw-r--r--drivers/media/usb/gspca/pac7302.c19
-rw-r--r--drivers/media/usb/gspca/sn9c20x.c69
-rw-r--r--drivers/media/usb/hdpvr/Kconfig2
-rw-r--r--drivers/media/usb/hdpvr/hdpvr-control.c34
-rw-r--r--drivers/media/usb/hdpvr/hdpvr-core.c8
-rw-r--r--drivers/media/usb/hdpvr/hdpvr-video.c110
-rw-r--r--drivers/media/usb/hdpvr/hdpvr.h3
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-hdw.c42
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-hdw.h13
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-io.c4
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-v4l2.c43
-rw-r--r--drivers/media/usb/sn9c102/sn9c102.h3
-rw-r--r--drivers/media/usb/sn9c102/sn9c102_core.c13
-rw-r--r--drivers/media/usb/stk1160/stk1160-v4l.c41
-rw-r--r--drivers/media/usb/tm6000/tm6000-cards.c2
-rw-r--r--drivers/media/usb/tm6000/tm6000-video.c13
-rw-r--r--drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c2
-rw-r--r--drivers/media/usb/usbtv/Kconfig10
-rw-r--r--drivers/media/usb/usbtv/Makefile1
-rw-r--r--drivers/media/usb/usbtv/usbtv.c696
-rw-r--r--drivers/media/usb/usbvision/usbvision-video.c19
-rw-r--r--drivers/media/usb/uvc/Kconfig1
-rw-r--r--drivers/media/usb/uvc/uvc_driver.c41
-rw-r--r--drivers/media/usb/uvc/uvc_status.c21
-rw-r--r--drivers/media/usb/uvc/uvc_v4l2.c14
-rw-r--r--drivers/media/usb/uvc/uvcvideo.h7
-rw-r--r--drivers/media/v4l2-core/Makefile3
-rw-r--r--drivers/media/v4l2-core/v4l2-async.c284
-rw-r--r--drivers/media/v4l2-core/v4l2-clk.c242
-rw-r--r--drivers/media/v4l2-core/v4l2-common.c60
-rw-r--r--drivers/media/v4l2-core/v4l2-compat-ioctl32.c1
-rw-r--r--drivers/media/v4l2-core/v4l2-dev.c40
-rw-r--r--drivers/media/v4l2-core/v4l2-device.c13
-rw-r--r--drivers/media/v4l2-core/v4l2-ioctl.c83
-rw-r--r--drivers/media/v4l2-core/videobuf-dma-contig.c19
-rw-r--r--drivers/media/v4l2-core/videobuf-dma-sg.c10
-rw-r--r--drivers/media/v4l2-core/videobuf-vmalloc.c10
-rw-r--r--drivers/media/v4l2-core/videobuf2-core.c4
-rw-r--r--drivers/staging/media/davinci_vpfe/dm365_ipipe.c4
-rw-r--r--drivers/staging/media/davinci_vpfe/dm365_ipipeif.c4
-rw-r--r--drivers/staging/media/davinci_vpfe/dm365_isif.c4
-rw-r--r--drivers/staging/media/davinci_vpfe/dm365_resizer.c14
-rw-r--r--drivers/staging/media/davinci_vpfe/vpfe_video.c14
-rw-r--r--drivers/staging/media/dt3155v4l/dt3155v4l.c1
-rw-r--r--drivers/staging/media/go7007/go7007-usb.c4
-rw-r--r--drivers/staging/media/lirc/lirc_imon.c7
-rw-r--r--drivers/staging/media/solo6x10/solo6x10-tw28.c112
-rw-r--r--drivers/staging/media/solo6x10/solo6x10-v4l2-enc.c38
-rw-r--r--drivers/usb/gadget/f_uvc.c9
-rw-r--r--drivers/usb/gadget/uvc.h2
-rw-r--r--include/media/davinci/vpbe_osd.h4
-rw-r--r--include/media/media-device.h9
-rw-r--r--include/media/media-entity.h5
-rw-r--r--include/media/rc-map.h1
-rw-r--r--include/media/s5p_fimc.h58
-rw-r--r--include/media/sh_mobile_ceu.h2
-rw-r--r--include/media/sh_mobile_csi2.h2
-rw-r--r--include/media/soc_camera.h43
-rw-r--r--include/media/ths7303.h2
-rw-r--r--include/media/tveeprom.h11
-rw-r--r--include/media/tvp7002.h46
-rw-r--r--include/media/v4l2-async.h105
-rw-r--r--include/media/v4l2-chip-ident.h352
-rw-r--r--include/media/v4l2-clk.h54
-rw-r--r--include/media/v4l2-common.h10
-rw-r--r--include/media/v4l2-dev.h5
-rw-r--r--include/media/v4l2-int-device.h3
-rw-r--r--include/media/v4l2-ioctl.h2
-rw-r--r--include/media/v4l2-subdev.h14
-rw-r--r--include/uapi/linux/v4l2-controls.h4
-rw-r--r--include/uapi/linux/videodev2.h27
359 files changed, 10887 insertions, 9847 deletions
diff --git a/Documentation/ABI/testing/sysfs-devices-edac b/Documentation/ABI/testing/sysfs-devices-edac
index 30ee78aaed75..6568e0010e1a 100644
--- a/Documentation/ABI/testing/sysfs-devices-edac
+++ b/Documentation/ABI/testing/sysfs-devices-edac
@@ -77,7 +77,7 @@ Description: Read/Write attribute file that controls memory scrubbing.
77 77
78What: /sys/devices/system/edac/mc/mc*/max_location 78What: /sys/devices/system/edac/mc/mc*/max_location
79Date: April 2012 79Date: April 2012
80Contact: Mauro Carvalho Chehab <mchehab@redhat.com> 80Contact: Mauro Carvalho Chehab <m.chehab@samsung.com>
81 linux-edac@vger.kernel.org 81 linux-edac@vger.kernel.org
82Description: This attribute file displays the information about the last 82Description: This attribute file displays the information about the last
83 available memory slot in this memory controller. It is used by 83 available memory slot in this memory controller. It is used by
@@ -85,7 +85,7 @@ Description: This attribute file displays the information about the last
85 85
86What: /sys/devices/system/edac/mc/mc*/(dimm|rank)*/size 86What: /sys/devices/system/edac/mc/mc*/(dimm|rank)*/size
87Date: April 2012 87Date: April 2012
88Contact: Mauro Carvalho Chehab <mchehab@redhat.com> 88Contact: Mauro Carvalho Chehab <m.chehab@samsung.com>
89 linux-edac@vger.kernel.org 89 linux-edac@vger.kernel.org
90Description: This attribute file will display the size of dimm or rank. 90Description: This attribute file will display the size of dimm or rank.
91 For dimm*/size, this is the size, in MB of the DIMM memory 91 For dimm*/size, this is the size, in MB of the DIMM memory
@@ -96,14 +96,14 @@ Description: This attribute file will display the size of dimm or rank.
96 96
97What: /sys/devices/system/edac/mc/mc*/(dimm|rank)*/dimm_dev_type 97What: /sys/devices/system/edac/mc/mc*/(dimm|rank)*/dimm_dev_type
98Date: April 2012 98Date: April 2012
99Contact: Mauro Carvalho Chehab <mchehab@redhat.com> 99Contact: Mauro Carvalho Chehab <m.chehab@samsung.com>
100 linux-edac@vger.kernel.org 100 linux-edac@vger.kernel.org
101Description: This attribute file will display what type of DRAM device is 101Description: This attribute file will display what type of DRAM device is
102 being utilized on this DIMM (x1, x2, x4, x8, ...). 102 being utilized on this DIMM (x1, x2, x4, x8, ...).
103 103
104What: /sys/devices/system/edac/mc/mc*/(dimm|rank)*/dimm_edac_mode 104What: /sys/devices/system/edac/mc/mc*/(dimm|rank)*/dimm_edac_mode
105Date: April 2012 105Date: April 2012
106Contact: Mauro Carvalho Chehab <mchehab@redhat.com> 106Contact: Mauro Carvalho Chehab <m.chehab@samsung.com>
107 linux-edac@vger.kernel.org 107 linux-edac@vger.kernel.org
108Description: This attribute file will display what type of Error detection 108Description: This attribute file will display what type of Error detection
109 and correction is being utilized. For example: S4ECD4ED would 109 and correction is being utilized. For example: S4ECD4ED would
@@ -111,7 +111,7 @@ Description: This attribute file will display what type of Error detection
111 111
112What: /sys/devices/system/edac/mc/mc*/(dimm|rank)*/dimm_label 112What: /sys/devices/system/edac/mc/mc*/(dimm|rank)*/dimm_label
113Date: April 2012 113Date: April 2012
114Contact: Mauro Carvalho Chehab <mchehab@redhat.com> 114Contact: Mauro Carvalho Chehab <m.chehab@samsung.com>
115 linux-edac@vger.kernel.org 115 linux-edac@vger.kernel.org
116Description: This control file allows this DIMM to have a label assigned 116Description: This control file allows this DIMM to have a label assigned
117 to it. With this label in the module, when errors occur 117 to it. With this label in the module, when errors occur
@@ -126,14 +126,14 @@ Description: This control file allows this DIMM to have a label assigned
126 126
127What: /sys/devices/system/edac/mc/mc*/(dimm|rank)*/dimm_location 127What: /sys/devices/system/edac/mc/mc*/(dimm|rank)*/dimm_location
128Date: April 2012 128Date: April 2012
129Contact: Mauro Carvalho Chehab <mchehab@redhat.com> 129Contact: Mauro Carvalho Chehab <m.chehab@samsung.com>
130 linux-edac@vger.kernel.org 130 linux-edac@vger.kernel.org
131Description: This attribute file will display the location (csrow/channel, 131Description: This attribute file will display the location (csrow/channel,
132 branch/channel/slot or channel/slot) of the dimm or rank. 132 branch/channel/slot or channel/slot) of the dimm or rank.
133 133
134What: /sys/devices/system/edac/mc/mc*/(dimm|rank)*/dimm_mem_type 134What: /sys/devices/system/edac/mc/mc*/(dimm|rank)*/dimm_mem_type
135Date: April 2012 135Date: April 2012
136Contact: Mauro Carvalho Chehab <mchehab@redhat.com> 136Contact: Mauro Carvalho Chehab <m.chehab@samsung.com>
137 linux-edac@vger.kernel.org 137 linux-edac@vger.kernel.org
138Description: This attribute file will display what type of memory is 138Description: This attribute file will display what type of memory is
139 currently on this csrow. Normally, either buffered or 139 currently on this csrow. Normally, either buffered or
diff --git a/Documentation/DocBook/media/v4l/compat.xml b/Documentation/DocBook/media/v4l/compat.xml
index f43542ae2981..0c7195e3e093 100644
--- a/Documentation/DocBook/media/v4l/compat.xml
+++ b/Documentation/DocBook/media/v4l/compat.xml
@@ -2254,7 +2254,7 @@ video encoding.</para>
2254 <orderedlist> 2254 <orderedlist>
2255 <listitem> 2255 <listitem>
2256 <para>The <constant>VIDIOC_G_CHIP_IDENT</constant> ioctl was renamed 2256 <para>The <constant>VIDIOC_G_CHIP_IDENT</constant> ioctl was renamed
2257to <constant>VIDIOC_G_CHIP_IDENT_OLD</constant> and &VIDIOC-DBG-G-CHIP-IDENT; 2257to <constant>VIDIOC_G_CHIP_IDENT_OLD</constant> and <constant>VIDIOC_DBG_G_CHIP_IDENT</constant>
2258was introduced in its place. The old struct <structname>v4l2_chip_ident</structname> 2258was introduced in its place. The old struct <structname>v4l2_chip_ident</structname>
2259was renamed to <structname id="v4l2-chip-ident-old">v4l2_chip_ident_old</structname>.</para> 2259was renamed to <structname id="v4l2-chip-ident-old">v4l2_chip_ident_old</structname>.</para>
2260 </listitem> 2260 </listitem>
@@ -2513,6 +2513,16 @@ that used it. It was originally scheduled for removal in 2.6.35.
2513 </orderedlist> 2513 </orderedlist>
2514 </section> 2514 </section>
2515 2515
2516 <section>
2517 <title>V4L2 in Linux 3.11</title>
2518 <orderedlist>
2519 <listitem>
2520 <para>Remove obsolete <constant>VIDIOC_DBG_G_CHIP_IDENT</constant> ioctl.
2521 </para>
2522 </listitem>
2523 </orderedlist>
2524 </section>
2525
2516 <section id="other"> 2526 <section id="other">
2517 <title>Relation of V4L2 to other Linux multimedia APIs</title> 2527 <title>Relation of V4L2 to other Linux multimedia APIs</title>
2518 2528
@@ -2596,7 +2606,7 @@ and may change in the future.</para>
2596ioctls.</para> 2606ioctls.</para>
2597 </listitem> 2607 </listitem>
2598 <listitem> 2608 <listitem>
2599 <para>&VIDIOC-DBG-G-CHIP-IDENT; ioctl.</para> 2609 <para>&VIDIOC-DBG-G-CHIP-INFO; ioctl.</para>
2600 </listitem> 2610 </listitem>
2601 <listitem> 2611 <listitem>
2602 <para>&VIDIOC-ENUM-DV-TIMINGS;, &VIDIOC-QUERY-DV-TIMINGS; and 2612 <para>&VIDIOC-ENUM-DV-TIMINGS;, &VIDIOC-QUERY-DV-TIMINGS; and
diff --git a/Documentation/DocBook/media/v4l/v4l2.xml b/Documentation/DocBook/media/v4l/v4l2.xml
index bfe823dd0f31..8469fe13945c 100644
--- a/Documentation/DocBook/media/v4l/v4l2.xml
+++ b/Documentation/DocBook/media/v4l/v4l2.xml
@@ -141,6 +141,14 @@ structs, ioctls) must be noted in more detail in the history chapter
141applications. --> 141applications. -->
142 142
143 <revision> 143 <revision>
144 <revnumber>3.11</revnumber>
145 <date>2013-05-26</date>
146 <authorinitials>hv</authorinitials>
147 <revremark>Remove obsolete VIDIOC_DBG_G_CHIP_IDENT ioctl.
148 </revremark>
149 </revision>
150
151 <revision>
144 <revnumber>3.10</revnumber> 152 <revnumber>3.10</revnumber>
145 <date>2013-03-25</date> 153 <date>2013-03-25</date>
146 <authorinitials>hv</authorinitials> 154 <authorinitials>hv</authorinitials>
@@ -493,7 +501,7 @@ and discussions on the V4L mailing list.</revremark>
493</partinfo> 501</partinfo>
494 502
495<title>Video for Linux Two API Specification</title> 503<title>Video for Linux Two API Specification</title>
496 <subtitle>Revision 3.10</subtitle> 504 <subtitle>Revision 3.11</subtitle>
497 505
498 <chapter id="common"> 506 <chapter id="common">
499 &sub-common; 507 &sub-common;
@@ -547,7 +555,6 @@ and discussions on the V4L mailing list.</revremark>
547 <!-- All ioctls go here. --> 555 <!-- All ioctls go here. -->
548 &sub-create-bufs; 556 &sub-create-bufs;
549 &sub-cropcap; 557 &sub-cropcap;
550 &sub-dbg-g-chip-ident;
551 &sub-dbg-g-chip-info; 558 &sub-dbg-g-chip-info;
552 &sub-dbg-g-register; 559 &sub-dbg-g-register;
553 &sub-decoder-cmd; 560 &sub-decoder-cmd;
diff --git a/Documentation/DocBook/media/v4l/vidioc-dbg-g-chip-ident.xml b/Documentation/DocBook/media/v4l/vidioc-dbg-g-chip-ident.xml
deleted file mode 100644
index 921e18550d26..000000000000
--- a/Documentation/DocBook/media/v4l/vidioc-dbg-g-chip-ident.xml
+++ /dev/null
@@ -1,271 +0,0 @@
1<refentry id="vidioc-dbg-g-chip-ident">
2 <refmeta>
3 <refentrytitle>ioctl VIDIOC_DBG_G_CHIP_IDENT</refentrytitle>
4 &manvol;
5 </refmeta>
6
7 <refnamediv>
8 <refname>VIDIOC_DBG_G_CHIP_IDENT</refname>
9 <refpurpose>Identify the chips on a TV card</refpurpose>
10 </refnamediv>
11
12 <refsynopsisdiv>
13 <funcsynopsis>
14 <funcprototype>
15 <funcdef>int <function>ioctl</function></funcdef>
16 <paramdef>int <parameter>fd</parameter></paramdef>
17 <paramdef>int <parameter>request</parameter></paramdef>
18 <paramdef>struct v4l2_dbg_chip_ident
19*<parameter>argp</parameter></paramdef>
20 </funcprototype>
21 </funcsynopsis>
22 </refsynopsisdiv>
23
24 <refsect1>
25 <title>Arguments</title>
26
27 <variablelist>
28 <varlistentry>
29 <term><parameter>fd</parameter></term>
30 <listitem>
31 <para>&fd;</para>
32 </listitem>
33 </varlistentry>
34 <varlistentry>
35 <term><parameter>request</parameter></term>
36 <listitem>
37 <para>VIDIOC_DBG_G_CHIP_IDENT</para>
38 </listitem>
39 </varlistentry>
40 <varlistentry>
41 <term><parameter>argp</parameter></term>
42 <listitem>
43 <para></para>
44 </listitem>
45 </varlistentry>
46 </variablelist>
47 </refsect1>
48
49 <refsect1>
50 <title>Description</title>
51
52 <note>
53 <title>Experimental</title>
54
55 <para>This is an <link
56linkend="experimental">experimental</link> interface and may change in
57the future.</para>
58 </note>
59
60 <para>For driver debugging purposes this ioctl allows test
61applications to query the driver about the chips present on the TV
62card. Regular applications must not use it. When you found a chip
63specific bug, please contact the linux-media mailing list (&v4l-ml;)
64so it can be fixed.</para>
65
66 <para>To query the driver applications must initialize the
67<structfield>match.type</structfield> and
68<structfield>match.addr</structfield> or <structfield>match.name</structfield>
69fields of a &v4l2-dbg-chip-ident;
70and call <constant>VIDIOC_DBG_G_CHIP_IDENT</constant> with a pointer to
71this structure. On success the driver stores information about the
72selected chip in the <structfield>ident</structfield> and
73<structfield>revision</structfield> fields. On failure the structure
74remains unchanged.</para>
75
76 <para>When <structfield>match.type</structfield> is
77<constant>V4L2_CHIP_MATCH_HOST</constant>,
78<structfield>match.addr</structfield> selects the nth non-&i2c; chip
79on the TV card. You can enumerate all chips by starting at zero and
80incrementing <structfield>match.addr</structfield> by one until
81<constant>VIDIOC_DBG_G_CHIP_IDENT</constant> fails with an &EINVAL;.
82The number zero always selects the host chip, &eg; the chip connected
83to the PCI or USB bus.</para>
84
85 <para>When <structfield>match.type</structfield> is
86<constant>V4L2_CHIP_MATCH_I2C_DRIVER</constant>,
87<structfield>match.name</structfield> contains the I2C driver name.
88For instance
89<constant>"saa7127"</constant> will match any chip
90supported by the saa7127 driver, regardless of its &i2c; bus address.
91When multiple chips supported by the same driver are present, the
92ioctl will return <constant>V4L2_IDENT_AMBIGUOUS</constant> in the
93<structfield>ident</structfield> field.</para>
94
95 <para>When <structfield>match.type</structfield> is
96<constant>V4L2_CHIP_MATCH_I2C_ADDR</constant>,
97<structfield>match.addr</structfield> selects a chip by its 7 bit
98&i2c; bus address.</para>
99
100 <para>When <structfield>match.type</structfield> is
101<constant>V4L2_CHIP_MATCH_AC97</constant>,
102<structfield>match.addr</structfield> selects the nth AC97 chip
103on the TV card. You can enumerate all chips by starting at zero and
104incrementing <structfield>match.addr</structfield> by one until
105<constant>VIDIOC_DBG_G_CHIP_IDENT</constant> fails with an &EINVAL;.</para>
106
107 <para>On success, the <structfield>ident</structfield> field will
108contain a chip ID from the Linux
109<filename>media/v4l2-chip-ident.h</filename> header file, and the
110<structfield>revision</structfield> field will contain a driver
111specific value, or zero if no particular revision is associated with
112this chip.</para>
113
114 <para>When the driver could not identify the selected chip,
115<structfield>ident</structfield> will contain
116<constant>V4L2_IDENT_UNKNOWN</constant>. When no chip matched
117the ioctl will succeed but the
118<structfield>ident</structfield> field will contain
119<constant>V4L2_IDENT_NONE</constant>. If multiple chips matched,
120<structfield>ident</structfield> will contain
121<constant>V4L2_IDENT_AMBIGUOUS</constant>. In all these cases the
122<structfield>revision</structfield> field remains unchanged.</para>
123
124 <para>This ioctl is optional, not all drivers may support it. It
125was introduced in Linux 2.6.21, but the API was changed to the
126one described here in 2.6.29.</para>
127
128 <para>We recommended the <application>v4l2-dbg</application>
129utility over calling this ioctl directly. It is available from the
130LinuxTV v4l-dvb repository; see <ulink
131url="http://linuxtv.org/repo/">http://linuxtv.org/repo/</ulink> for
132access instructions.</para>
133
134 <!-- Note for convenience vidioc-dbg-g-register.sgml
135 contains a duplicate of this table. -->
136 <table pgwide="1" frame="none" id="ident-v4l2-dbg-match">
137 <title>struct <structname>v4l2_dbg_match</structname></title>
138 <tgroup cols="4">
139 &cs-ustr;
140 <tbody valign="top">
141 <row>
142 <entry>__u32</entry>
143 <entry><structfield>type</structfield></entry>
144 <entry>See <xref linkend="ident-chip-match-types" /> for a list of
145possible types.</entry>
146 </row>
147 <row>
148 <entry>union</entry>
149 <entry>(anonymous)</entry>
150 </row>
151 <row>
152 <entry></entry>
153 <entry>__u32</entry>
154 <entry><structfield>addr</structfield></entry>
155 <entry>Match a chip by this number, interpreted according
156to the <structfield>type</structfield> field.</entry>
157 </row>
158 <row>
159 <entry></entry>
160 <entry>char</entry>
161 <entry><structfield>name[32]</structfield></entry>
162 <entry>Match a chip by this name, interpreted according
163to the <structfield>type</structfield> field.</entry>
164 </row>
165 </tbody>
166 </tgroup>
167 </table>
168
169 <table pgwide="1" frame="none" id="v4l2-dbg-chip-ident">
170 <title>struct <structname>v4l2_dbg_chip_ident</structname></title>
171 <tgroup cols="3">
172 &cs-str;
173 <tbody valign="top">
174 <row>
175 <entry>struct v4l2_dbg_match</entry>
176 <entry><structfield>match</structfield></entry>
177 <entry>How to match the chip, see <xref linkend="ident-v4l2-dbg-match" />.</entry>
178 </row>
179 <row>
180 <entry>__u32</entry>
181 <entry><structfield>ident</structfield></entry>
182 <entry>A chip identifier as defined in the Linux
183<filename>media/v4l2-chip-ident.h</filename> header file, or one of
184the values from <xref linkend="chip-ids" />.</entry>
185 </row>
186 <row>
187 <entry>__u32</entry>
188 <entry><structfield>revision</structfield></entry>
189 <entry>A chip revision, chip and driver specific.</entry>
190 </row>
191 </tbody>
192 </tgroup>
193 </table>
194
195 <!-- Note for convenience vidioc-dbg-g-register.sgml
196 contains a duplicate of this table. -->
197 <table pgwide="1" frame="none" id="ident-chip-match-types">
198 <title>Chip Match Types</title>
199 <tgroup cols="3">
200 &cs-def;
201 <tbody valign="top">
202 <row>
203 <entry><constant>V4L2_CHIP_MATCH_BRIDGE</constant></entry>
204 <entry>0</entry>
205 <entry>Match the nth chip on the card, zero for the
206 bridge chip. Does not match sub-devices.</entry>
207 </row>
208 <row>
209 <entry><constant>V4L2_CHIP_MATCH_I2C_DRIVER</constant></entry>
210 <entry>1</entry>
211 <entry>Match an &i2c; chip by its driver name.</entry>
212 </row>
213 <row>
214 <entry><constant>V4L2_CHIP_MATCH_I2C_ADDR</constant></entry>
215 <entry>2</entry>
216 <entry>Match a chip by its 7 bit &i2c; bus address.</entry>
217 </row>
218 <row>
219 <entry><constant>V4L2_CHIP_MATCH_AC97</constant></entry>
220 <entry>3</entry>
221 <entry>Match the nth anciliary AC97 chip.</entry>
222 </row>
223 <row>
224 <entry><constant>V4L2_CHIP_MATCH_SUBDEV</constant></entry>
225 <entry>4</entry>
226 <entry>Match the nth sub-device. Can't be used with this ioctl.</entry>
227 </row>
228 </tbody>
229 </tgroup>
230 </table>
231
232 <!-- This is an anonymous enum in media/v4l2-chip-ident.h. -->
233 <table pgwide="1" frame="none" id="chip-ids">
234 <title>Chip Identifiers</title>
235 <tgroup cols="3">
236 &cs-def;
237 <tbody valign="top">
238 <row>
239 <entry><constant>V4L2_IDENT_NONE</constant></entry>
240 <entry>0</entry>
241 <entry>No chip matched.</entry>
242 </row>
243 <row>
244 <entry><constant>V4L2_IDENT_AMBIGUOUS</constant></entry>
245 <entry>1</entry>
246 <entry>Multiple chips matched.</entry>
247 </row>
248 <row>
249 <entry><constant>V4L2_IDENT_UNKNOWN</constant></entry>
250 <entry>2</entry>
251 <entry>A chip is present at this address, but the driver
252could not identify it.</entry>
253 </row>
254 </tbody>
255 </tgroup>
256 </table>
257 </refsect1>
258
259 <refsect1>
260 &return-value;
261
262 <variablelist>
263 <varlistentry>
264 <term><errorcode>EINVAL</errorcode></term>
265 <listitem>
266 <para>The <structfield>match_type</structfield> is invalid.</para>
267 </listitem>
268 </varlistentry>
269 </variablelist>
270 </refsect1>
271</refentry>
diff --git a/Documentation/DocBook/media/v4l/vidioc-dbg-g-chip-info.xml b/Documentation/DocBook/media/v4l/vidioc-dbg-g-chip-info.xml
index e1cece6c5de1..4c4603c135fe 100644
--- a/Documentation/DocBook/media/v4l/vidioc-dbg-g-chip-info.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-dbg-g-chip-info.xml
@@ -73,8 +73,7 @@ fields of a &v4l2-dbg-chip-info;
73and call <constant>VIDIOC_DBG_G_CHIP_INFO</constant> with a pointer to 73and call <constant>VIDIOC_DBG_G_CHIP_INFO</constant> with a pointer to
74this structure. On success the driver stores information about the 74this structure. On success the driver stores information about the
75selected chip in the <structfield>name</structfield> and 75selected chip in the <structfield>name</structfield> and
76<structfield>flags</structfield> fields. On failure the structure 76<structfield>flags</structfield> fields.</para>
77remains unchanged.</para>
78 77
79 <para>When <structfield>match.type</structfield> is 78 <para>When <structfield>match.type</structfield> is
80<constant>V4L2_CHIP_MATCH_BRIDGE</constant>, 79<constant>V4L2_CHIP_MATCH_BRIDGE</constant>,
@@ -132,7 +131,7 @@ to the <structfield>type</structfield> field.</entry>
132 <entry>char</entry> 131 <entry>char</entry>
133 <entry><structfield>name[32]</structfield></entry> 132 <entry><structfield>name[32]</structfield></entry>
134 <entry>Match a chip by this name, interpreted according 133 <entry>Match a chip by this name, interpreted according
135to the <structfield>type</structfield> field.</entry> 134to the <structfield>type</structfield> field. Currently unused.</entry>
136 </row> 135 </row>
137 </tbody> 136 </tbody>
138 </tgroup> 137 </tgroup>
@@ -183,21 +182,6 @@ is set, then the driver supports reading registers from the device. If
183 bridge chip. Does not match sub-devices.</entry> 182 bridge chip. Does not match sub-devices.</entry>
184 </row> 183 </row>
185 <row> 184 <row>
186 <entry><constant>V4L2_CHIP_MATCH_I2C_DRIVER</constant></entry>
187 <entry>1</entry>
188 <entry>Match an &i2c; chip by its driver name. Can't be used with this ioctl.</entry>
189 </row>
190 <row>
191 <entry><constant>V4L2_CHIP_MATCH_I2C_ADDR</constant></entry>
192 <entry>2</entry>
193 <entry>Match a chip by its 7 bit &i2c; bus address. Can't be used with this ioctl.</entry>
194 </row>
195 <row>
196 <entry><constant>V4L2_CHIP_MATCH_AC97</constant></entry>
197 <entry>3</entry>
198 <entry>Match the nth anciliary AC97 chip. Can't be used with this ioctl.</entry>
199 </row>
200 <row>
201 <entry><constant>V4L2_CHIP_MATCH_SUBDEV</constant></entry> 185 <entry><constant>V4L2_CHIP_MATCH_SUBDEV</constant></entry>
202 <entry>4</entry> 186 <entry>4</entry>
203 <entry>Match the nth sub-device.</entry> 187 <entry>Match the nth sub-device.</entry>
diff --git a/Documentation/DocBook/media/v4l/vidioc-dbg-g-register.xml b/Documentation/DocBook/media/v4l/vidioc-dbg-g-register.xml
index d13bac9e2445..3d038e75d12b 100644
--- a/Documentation/DocBook/media/v4l/vidioc-dbg-g-register.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-dbg-g-register.xml
@@ -76,7 +76,7 @@ compiled with the <constant>CONFIG_VIDEO_ADV_DEBUG</constant> option
76to enable these ioctls.</para> 76to enable these ioctls.</para>
77 77
78 <para>To write a register applications must initialize all fields 78 <para>To write a register applications must initialize all fields
79of a &v4l2-dbg-register; and call 79of a &v4l2-dbg-register; except for <structfield>size</structfield> and call
80<constant>VIDIOC_DBG_S_REGISTER</constant> with a pointer to this 80<constant>VIDIOC_DBG_S_REGISTER</constant> with a pointer to this
81structure. The <structfield>match.type</structfield> and 81structure. The <structfield>match.type</structfield> and
82<structfield>match.addr</structfield> or <structfield>match.name</structfield> 82<structfield>match.addr</structfield> or <structfield>match.name</structfield>
@@ -91,8 +91,8 @@ written into the register.</para>
91<structfield>reg</structfield> fields, and call 91<structfield>reg</structfield> fields, and call
92<constant>VIDIOC_DBG_G_REGISTER</constant> with a pointer to this 92<constant>VIDIOC_DBG_G_REGISTER</constant> with a pointer to this
93structure. On success the driver stores the register value in the 93structure. On success the driver stores the register value in the
94<structfield>val</structfield> field. On failure the structure remains 94<structfield>val</structfield> field and the size (in bytes) of the
95unchanged.</para> 95value in <structfield>size</structfield>.</para>
96 96
97 <para>When <structfield>match.type</structfield> is 97 <para>When <structfield>match.type</structfield> is
98<constant>V4L2_CHIP_MATCH_BRIDGE</constant>, 98<constant>V4L2_CHIP_MATCH_BRIDGE</constant>,
@@ -102,39 +102,9 @@ chip connected to the PCI or USB bus. You can find out which chips are
102present with the &VIDIOC-DBG-G-CHIP-INFO; ioctl.</para> 102present with the &VIDIOC-DBG-G-CHIP-INFO; ioctl.</para>
103 103
104 <para>When <structfield>match.type</structfield> is 104 <para>When <structfield>match.type</structfield> is
105<constant>V4L2_CHIP_MATCH_I2C_DRIVER</constant>,
106<structfield>match.name</structfield> contains the I2C driver name.
107For instance
108<constant>"saa7127"</constant> will match any chip
109supported by the saa7127 driver, regardless of its &i2c; bus address.
110When multiple chips supported by the same driver are present, the
111effect of these ioctls is undefined. Again with the
112&VIDIOC-DBG-G-CHIP-INFO; ioctl you can find out which &i2c; chips are
113present.</para>
114
115 <para>When <structfield>match.type</structfield> is
116<constant>V4L2_CHIP_MATCH_I2C_ADDR</constant>,
117<structfield>match.addr</structfield> selects a chip by its 7 bit &i2c;
118bus address.</para>
119
120 <para>When <structfield>match.type</structfield> is
121<constant>V4L2_CHIP_MATCH_AC97</constant>,
122<structfield>match.addr</structfield> selects the nth AC97 chip
123on the TV card.</para>
124
125 <para>When <structfield>match.type</structfield> is
126<constant>V4L2_CHIP_MATCH_SUBDEV</constant>, 105<constant>V4L2_CHIP_MATCH_SUBDEV</constant>,
127<structfield>match.addr</structfield> selects the nth sub-device.</para> 106<structfield>match.addr</structfield> selects the nth sub-device.</para>
128 107
129 <note>
130 <title>Success not guaranteed</title>
131
132 <para>Due to a flaw in the Linux &i2c; bus driver these ioctls may
133return successfully without actually reading or writing a register. To
134catch the most likely failure we recommend a &VIDIOC-DBG-G-CHIP-INFO;
135call confirming the presence of the selected &i2c; chip.</para>
136 </note>
137
138 <para>These ioctls are optional, not all drivers may support them. 108 <para>These ioctls are optional, not all drivers may support them.
139However when a driver supports these ioctls it must also support 109However when a driver supports these ioctls it must also support
140&VIDIOC-DBG-G-CHIP-INFO;. Conversely it may support 110&VIDIOC-DBG-G-CHIP-INFO;. Conversely it may support
@@ -150,7 +120,7 @@ LinuxTV v4l-dvb repository; see <ulink
150url="http://linuxtv.org/repo/">http://linuxtv.org/repo/</ulink> for 120url="http://linuxtv.org/repo/">http://linuxtv.org/repo/</ulink> for
151access instructions.</para> 121access instructions.</para>
152 122
153 <!-- Note for convenience vidioc-dbg-g-chip-ident.sgml 123 <!-- Note for convenience vidioc-dbg-g-chip-info.sgml
154 contains a duplicate of this table. --> 124 contains a duplicate of this table. -->
155 <table pgwide="1" frame="none" id="v4l2-dbg-match"> 125 <table pgwide="1" frame="none" id="v4l2-dbg-match">
156 <title>struct <structname>v4l2_dbg_match</structname></title> 126 <title>struct <structname>v4l2_dbg_match</structname></title>
@@ -160,7 +130,7 @@ access instructions.</para>
160 <row> 130 <row>
161 <entry>__u32</entry> 131 <entry>__u32</entry>
162 <entry><structfield>type</structfield></entry> 132 <entry><structfield>type</structfield></entry>
163 <entry>See <xref linkend="ident-chip-match-types" /> for a list of 133 <entry>See <xref linkend="chip-match-types" /> for a list of
164possible types.</entry> 134possible types.</entry>
165 </row> 135 </row>
166 <row> 136 <row>
@@ -179,7 +149,7 @@ to the <structfield>type</structfield> field.</entry>
179 <entry>char</entry> 149 <entry>char</entry>
180 <entry><structfield>name[32]</structfield></entry> 150 <entry><structfield>name[32]</structfield></entry>
181 <entry>Match a chip by this name, interpreted according 151 <entry>Match a chip by this name, interpreted according
182to the <structfield>type</structfield> field.</entry> 152to the <structfield>type</structfield> field. Currently unused.</entry>
183 </row> 153 </row>
184 </tbody> 154 </tbody>
185 </tgroup> 155 </tgroup>
@@ -199,6 +169,11 @@ to the <structfield>type</structfield> field.</entry>
199 <entry>How to match the chip, see <xref linkend="v4l2-dbg-match" />.</entry> 169 <entry>How to match the chip, see <xref linkend="v4l2-dbg-match" />.</entry>
200 </row> 170 </row>
201 <row> 171 <row>
172 <entry>__u32</entry>
173 <entry><structfield>size</structfield></entry>
174 <entry>The register size in bytes.</entry>
175 </row>
176 <row>
202 <entry>__u64</entry> 177 <entry>__u64</entry>
203 <entry><structfield>reg</structfield></entry> 178 <entry><structfield>reg</structfield></entry>
204 <entry>A register number.</entry> 179 <entry>A register number.</entry>
@@ -213,7 +188,7 @@ register.</entry>
213 </tgroup> 188 </tgroup>
214 </table> 189 </table>
215 190
216 <!-- Note for convenience vidioc-dbg-g-chip-ident.sgml 191 <!-- Note for convenience vidioc-dbg-g-chip-info.sgml
217 contains a duplicate of this table. --> 192 contains a duplicate of this table. -->
218 <table pgwide="1" frame="none" id="chip-match-types"> 193 <table pgwide="1" frame="none" id="chip-match-types">
219 <title>Chip Match Types</title> 194 <title>Chip Match Types</title>
@@ -227,21 +202,6 @@ register.</entry>
227 bridge chip. Does not match sub-devices.</entry> 202 bridge chip. Does not match sub-devices.</entry>
228 </row> 203 </row>
229 <row> 204 <row>
230 <entry><constant>V4L2_CHIP_MATCH_I2C_DRIVER</constant></entry>
231 <entry>1</entry>
232 <entry>Match an &i2c; chip by its driver name.</entry>
233 </row>
234 <row>
235 <entry><constant>V4L2_CHIP_MATCH_I2C_ADDR</constant></entry>
236 <entry>2</entry>
237 <entry>Match a chip by its 7 bit &i2c; bus address.</entry>
238 </row>
239 <row>
240 <entry><constant>V4L2_CHIP_MATCH_AC97</constant></entry>
241 <entry>3</entry>
242 <entry>Match the nth anciliary AC97 chip.</entry>
243 </row>
244 <row>
245 <entry><constant>V4L2_CHIP_MATCH_SUBDEV</constant></entry> 205 <entry><constant>V4L2_CHIP_MATCH_SUBDEV</constant></entry>
246 <entry>4</entry> 206 <entry>4</entry>
247 <entry>Match the nth sub-device.</entry> 207 <entry>Match the nth sub-device.</entry>
diff --git a/Documentation/DocBook/media/v4l/vidioc-querystd.xml b/Documentation/DocBook/media/v4l/vidioc-querystd.xml
index fe80a183d957..222348542182 100644
--- a/Documentation/DocBook/media/v4l/vidioc-querystd.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-querystd.xml
@@ -54,7 +54,8 @@ standard automatically. To do so, applications call <constant>
54VIDIOC_QUERYSTD</constant> with a pointer to a &v4l2-std-id; type. The 54VIDIOC_QUERYSTD</constant> with a pointer to a &v4l2-std-id; type. The
55driver stores here a set of candidates, this can be a single flag or a 55driver stores here a set of candidates, this can be a single flag or a
56set of supported standards if for example the hardware can only 56set of supported standards if for example the hardware can only
57distinguish between 50 and 60 Hz systems. When detection is not 57distinguish between 50 and 60 Hz systems. If no signal was detected,
58then the driver will return V4L2_STD_UNKNOWN. When detection is not
58possible or fails, the set must contain all standards supported by the 59possible or fails, the set must contain all standards supported by the
59current video input or output.</para> 60current video input or output.</para>
60 61
diff --git a/Documentation/devicetree/bindings/media/exynos-fimc-lite.txt b/Documentation/devicetree/bindings/media/exynos-fimc-lite.txt
index de9f6b78ee51..0bf6fb7fbeab 100644
--- a/Documentation/devicetree/bindings/media/exynos-fimc-lite.txt
+++ b/Documentation/devicetree/bindings/media/exynos-fimc-lite.txt
@@ -2,8 +2,10 @@ Exynos4x12/Exynos5 SoC series camera host interface (FIMC-LITE)
2 2
3Required properties: 3Required properties:
4 4
5- compatible : should be "samsung,exynos4212-fimc-lite" for Exynos4212 and 5- compatible : should be one of:
6 Exynos4412 SoCs; 6 "samsung,exynos4212-fimc-lite" for Exynos4212/4412 SoCs,
7 "samsung,exynos5250-fimc-lite" for Exynos5250 compatible
8 devices;
7- reg : physical base address and size of the device memory mapped 9- reg : physical base address and size of the device memory mapped
8 registers; 10 registers;
9- interrupts : should contain FIMC-LITE interrupt; 11- interrupts : should contain FIMC-LITE interrupt;
diff --git a/Documentation/devicetree/bindings/media/i2c/mt9p031.txt b/Documentation/devicetree/bindings/media/i2c/mt9p031.txt
new file mode 100644
index 000000000000..cb60443ff78f
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/i2c/mt9p031.txt
@@ -0,0 +1,40 @@
1* Aptina 1/2.5-Inch 5Mp CMOS Digital Image Sensor
2
3The Aptina MT9P031 is a 1/2.5-inch CMOS active pixel digital image sensor with
4an active array size of 2592H x 1944V. It is programmable through a simple
5two-wire serial interface.
6
7Required Properties:
8- compatible: value should be either one among the following
9 (a) "aptina,mt9p031" for mt9p031 sensor
10 (b) "aptina,mt9p031m" for mt9p031m sensor
11
12- input-clock-frequency: Input clock frequency.
13
14- pixel-clock-frequency: Pixel clock frequency.
15
16Optional Properties:
17- reset-gpios: Chip reset GPIO
18
19For further reading on port node refer to
20Documentation/devicetree/bindings/media/video-interfaces.txt.
21
22Example:
23
24 i2c0@1c22000 {
25 ...
26 ...
27 mt9p031@5d {
28 compatible = "aptina,mt9p031";
29 reg = <0x5d>;
30 reset-gpios = <&gpio3 30 0>;
31
32 port {
33 mt9p031_1: endpoint {
34 input-clock-frequency = <6000000>;
35 pixel-clock-frequency = <96000000>;
36 };
37 };
38 };
39 ...
40 };
diff --git a/Documentation/devicetree/bindings/media/i2c/tvp514x.txt b/Documentation/devicetree/bindings/media/i2c/tvp514x.txt
new file mode 100644
index 000000000000..46752cc71f2e
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/i2c/tvp514x.txt
@@ -0,0 +1,44 @@
1* Texas Instruments TVP514x video decoder
2
3The TVP5146/TVP5146m2/TVP5147/TVP5147m1 device is high quality, single-chip
4digital video decoder that digitizes and decodes all popular baseband analog
5video formats into digital video component. The tvp514x decoder supports analog-
6to-digital (A/D) conversion of component RGB and YPbPr signals as well as A/D
7conversion and decoding of NTSC, PAL and SECAM composite and S-video into
8component YCbCr.
9
10Required Properties :
11- compatible : value should be either one among the following
12 (a) "ti,tvp5146" for tvp5146 decoder.
13 (b) "ti,tvp5146m2" for tvp5146m2 decoder.
14 (c) "ti,tvp5147" for tvp5147 decoder.
15 (d) "ti,tvp5147m1" for tvp5147m1 decoder.
16
17- hsync-active: HSYNC Polarity configuration for endpoint.
18
19- vsync-active: VSYNC Polarity configuration for endpoint.
20
21- pclk-sample: Clock polarity of the endpoint.
22
23For further reading on port node refer to Documentation/devicetree/bindings/
24media/video-interfaces.txt.
25
26Example:
27
28 i2c0@1c22000 {
29 ...
30 ...
31 tvp514x@5c {
32 compatible = "ti,tvp5146";
33 reg = <0x5c>;
34
35 port {
36 tvp514x_1: endpoint {
37 hsync-active = <1>;
38 vsync-active = <1>;
39 pclk-sample = <0>;
40 };
41 };
42 };
43 ...
44 };
diff --git a/Documentation/devicetree/bindings/media/samsung-fimc.txt b/Documentation/devicetree/bindings/media/samsung-fimc.txt
index 51c776b7f7a3..96312f6c4c26 100644
--- a/Documentation/devicetree/bindings/media/samsung-fimc.txt
+++ b/Documentation/devicetree/bindings/media/samsung-fimc.txt
@@ -127,22 +127,22 @@ Example:
127 }; 127 };
128 }; 128 };
129 }; 129 };
130 };
131 130
132 /* MIPI CSI-2 bus IF sensor */ 131 /* MIPI CSI-2 bus IF sensor */
133 s5c73m3: sensor@0x1a { 132 s5c73m3: sensor@0x1a {
134 compatible = "samsung,s5c73m3"; 133 compatible = "samsung,s5c73m3";
135 reg = <0x1a>; 134 reg = <0x1a>;
136 vddio-supply = <...>; 135 vddio-supply = <...>;
137 136
138 clock-frequency = <24000000>; 137 clock-frequency = <24000000>;
139 clocks = <...>; 138 clocks = <...>;
140 clock-names = "mclk"; 139 clock-names = "mclk";
141 140
142 port { 141 port {
143 s5c73m3_1: endpoint { 142 s5c73m3_1: endpoint {
144 data-lanes = <1 2 3 4>; 143 data-lanes = <1 2 3 4>;
145 remote-endpoint = <&csis0_ep>; 144 remote-endpoint = <&csis0_ep>;
145 };
146 }; 146 };
147 }; 147 };
148 }; 148 };
diff --git a/Documentation/devicetree/bindings/media/samsung-mipi-csis.txt b/Documentation/devicetree/bindings/media/samsung-mipi-csis.txt
index 5f8e28e2484f..be45f0b1a449 100644
--- a/Documentation/devicetree/bindings/media/samsung-mipi-csis.txt
+++ b/Documentation/devicetree/bindings/media/samsung-mipi-csis.txt
@@ -5,8 +5,8 @@ Required properties:
5 5
6- compatible : "samsung,s5pv210-csis" for S5PV210 (S5PC110), 6- compatible : "samsung,s5pv210-csis" for S5PV210 (S5PC110),
7 "samsung,exynos4210-csis" for Exynos4210 (S5PC210), 7 "samsung,exynos4210-csis" for Exynos4210 (S5PC210),
8 "samsung,exynos4212-csis" for Exynos4212/Exynos4412 8 "samsung,exynos4212-csis" for Exynos4212/Exynos4412,
9 SoC series; 9 "samsung,exynos5250-csis" for Exynos5250;
10- reg : offset and length of the register set for the device; 10- reg : offset and length of the register set for the device;
11- interrupts : should contain MIPI CSIS interrupt; the format of the 11- interrupts : should contain MIPI CSIS interrupt; the format of the
12 interrupt specifier depends on the interrupt controller; 12 interrupt specifier depends on the interrupt controller;
diff --git a/Documentation/devicetree/bindings/media/sh_mobile_ceu.txt b/Documentation/devicetree/bindings/media/sh_mobile_ceu.txt
new file mode 100644
index 000000000000..1ce4e46bcbb7
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/sh_mobile_ceu.txt
@@ -0,0 +1,18 @@
1Bindings, specific for the sh_mobile_ceu_camera.c driver:
2 - compatible: Should be "renesas,sh-mobile-ceu"
3 - reg: register base and size
4 - interrupts: the interrupt number
5 - interrupt-parent: the interrupt controller
6 - renesas,max-width: maximum image width, supported on this SoC
7 - renesas,max-height: maximum image height, supported on this SoC
8
9Example:
10
11ceu0: ceu@0xfe910000 {
12 compatible = "renesas,sh-mobile-ceu";
13 reg = <0xfe910000 0xa0>;
14 interrupt-parent = <&intcs>;
15 interrupts = <0x880>;
16 renesas,max-width = <8188>;
17 renesas,max-height = <8188>;
18};
diff --git a/Documentation/media-framework.txt b/Documentation/media-framework.txt
index eeced24e56af..f552a75c0e70 100644
--- a/Documentation/media-framework.txt
+++ b/Documentation/media-framework.txt
@@ -265,7 +265,7 @@ connected to another pad through an enabled link
265 media_entity_find_link(struct media_pad *source, 265 media_entity_find_link(struct media_pad *source,
266 struct media_pad *sink); 266 struct media_pad *sink);
267 267
268 media_entity_remote_source(struct media_pad *pad); 268 media_entity_remote_pad(struct media_pad *pad);
269 269
270Refer to the kerneldoc documentation for more information. 270Refer to the kerneldoc documentation for more information.
271 271
diff --git a/Documentation/video4linux/CARDLIST.bttv b/Documentation/video4linux/CARDLIST.bttv
index 581f666a76cf..f14475011fea 100644
--- a/Documentation/video4linux/CARDLIST.bttv
+++ b/Documentation/video4linux/CARDLIST.bttv
@@ -160,3 +160,6 @@
160159 -> ProVideo PV183 [1830:1540,1831:1540,1832:1540,1833:1540,1834:1540,1835:1540,1836:1540,1837:1540] 160159 -> ProVideo PV183 [1830:1540,1831:1540,1832:1540,1833:1540,1834:1540,1835:1540,1836:1540,1837:1540]
161160 -> Tongwei Video Technology TD-3116 [f200:3116] 161160 -> Tongwei Video Technology TD-3116 [f200:3116]
162161 -> Aposonic W-DVR [0279:0228] 162161 -> Aposonic W-DVR [0279:0228]
163162 -> Adlink MPG24
164163 -> Bt848 Capture 14MHz
165164 -> CyberVision CV06 (SV)
diff --git a/Documentation/video4linux/CARDLIST.saa7134 b/Documentation/video4linux/CARDLIST.saa7134
index b3ad68309109..8df17d063499 100644
--- a/Documentation/video4linux/CARDLIST.saa7134
+++ b/Documentation/video4linux/CARDLIST.saa7134
@@ -190,3 +190,4 @@
190189 -> Kworld PC150-U [17de:a134] 190189 -> Kworld PC150-U [17de:a134]
191190 -> Asus My Cinema PS3-100 [1043:48cd] 191190 -> Asus My Cinema PS3-100 [1043:48cd]
192191 -> Hawell HW-9004V1 192191 -> Hawell HW-9004V1
193192 -> AverMedia AverTV Satellite Hybrid+FM A706 [1461:2055]
diff --git a/Documentation/video4linux/CARDLIST.tuner b/Documentation/video4linux/CARDLIST.tuner
index 5b83a3ff15c2..ac8862184962 100644
--- a/Documentation/video4linux/CARDLIST.tuner
+++ b/Documentation/video4linux/CARDLIST.tuner
@@ -86,6 +86,6 @@ tuner=85 - Philips FQ1236 MK5
86tuner=86 - Tena TNF5337 MFD 86tuner=86 - Tena TNF5337 MFD
87tuner=87 - Xceive 4000 tuner 87tuner=87 - Xceive 4000 tuner
88tuner=88 - Xceive 5000C tuner 88tuner=88 - Xceive 5000C tuner
89tuner=89 - Sony PAL+SECAM (BTF-PG472Z) 89tuner=89 - Sony BTF-PG472Z PAL/SECAM
90tuner=90 - Sony NTSC-M-JP (BTF-PK467Z) 90tuner=90 - Sony BTF-PK467Z NTSC-M-JP
91tuner=91 - Sony NTSC-M (BTF-PB463Z) 91tuner=91 - Sony BTF-PB463Z NTSC-M
diff --git a/Documentation/video4linux/fimc.txt b/Documentation/video4linux/fimc.txt
index 25f4d3402722..e51f1b5b7324 100644
--- a/Documentation/video4linux/fimc.txt
+++ b/Documentation/video4linux/fimc.txt
@@ -1,6 +1,6 @@
1Samsung S5P/EXYNOS4 FIMC driver 1Samsung S5P/EXYNOS4 FIMC driver
2 2
3Copyright (C) 2012 Samsung Electronics Co., Ltd. 3Copyright (C) 2012 - 2013 Samsung Electronics Co., Ltd.
4--------------------------------------------------------------------------- 4---------------------------------------------------------------------------
5 5
6The FIMC (Fully Interactive Mobile Camera) device available in Samsung 6The FIMC (Fully Interactive Mobile Camera) device available in Samsung
@@ -10,7 +10,7 @@ data from LCD controller (FIMD) through the SoC internal writeback data
10path. There are multiple FIMC instances in the SoCs (up to 4), having 10path. There are multiple FIMC instances in the SoCs (up to 4), having
11slightly different capabilities, like pixel alignment constraints, rotator 11slightly different capabilities, like pixel alignment constraints, rotator
12availability, LCD writeback support, etc. The driver is located at 12availability, LCD writeback support, etc. The driver is located at
13drivers/media/platform/s5p-fimc directory. 13drivers/media/platform/exynos4-is directory.
14 14
151. Supported SoCs 151. Supported SoCs
16================= 16=================
@@ -36,21 +36,21 @@ Not currently supported:
36===================== 36=====================
37 37
38- media device driver 38- media device driver
39 drivers/media/platform/s5p-fimc/fimc-mdevice.[ch] 39 drivers/media/platform/exynos4-is/media-dev.[ch]
40 40
41 - camera capture video device driver 41 - camera capture video device driver
42 drivers/media/platform/s5p-fimc/fimc-capture.c 42 drivers/media/platform/exynos4-is/fimc-capture.c
43 43
44 - MIPI-CSI2 receiver subdev 44 - MIPI-CSI2 receiver subdev
45 drivers/media/platform/s5p-fimc/mipi-csis.[ch] 45 drivers/media/platform/exynos4-is/mipi-csis.[ch]
46 46
47 - video post-processor (mem-to-mem) 47 - video post-processor (mem-to-mem)
48 drivers/media/platform/s5p-fimc/fimc-core.c 48 drivers/media/platform/exynos4-is/fimc-core.c
49 49
50 - common files 50 - common files
51 drivers/media/platform/s5p-fimc/fimc-core.h 51 drivers/media/platform/exynos4-is/fimc-core.h
52 drivers/media/platform/s5p-fimc/fimc-reg.h 52 drivers/media/platform/exynos4-is/fimc-reg.h
53 drivers/media/platform/s5p-fimc/regs-fimc.h 53 drivers/media/platform/exynos4-is/regs-fimc.h
54 54
554. User space interfaces 554. User space interfaces
56======================== 56========================
@@ -143,7 +143,8 @@ or retrieve the information from /dev/media? with help of the media-ctl tool:
1436. Platform support 1436. Platform support
144=================== 144===================
145 145
146The machine code (plat-s5p and arch/arm/mach-*) must select following options 146The machine code (arch/arm/plat-samsung and arch/arm/mach-*) must select
147following options:
147 148
148CONFIG_S5P_DEV_FIMC0 mandatory 149CONFIG_S5P_DEV_FIMC0 mandatory
149CONFIG_S5P_DEV_FIMC1 \ 150CONFIG_S5P_DEV_FIMC1 \
diff --git a/Documentation/video4linux/v4l2-framework.txt b/Documentation/video4linux/v4l2-framework.txt
index a300b283a1a0..6c4866b49eb5 100644
--- a/Documentation/video4linux/v4l2-framework.txt
+++ b/Documentation/video4linux/v4l2-framework.txt
@@ -246,7 +246,6 @@ may be NULL if the subdev driver does not support anything from that category.
246It looks like this: 246It looks like this:
247 247
248struct v4l2_subdev_core_ops { 248struct v4l2_subdev_core_ops {
249 int (*g_chip_ident)(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip);
250 int (*log_status)(struct v4l2_subdev *sd); 249 int (*log_status)(struct v4l2_subdev *sd);
251 int (*init)(struct v4l2_subdev *sd, u32 val); 250 int (*init)(struct v4l2_subdev *sd, u32 val);
252 ... 251 ...
@@ -326,8 +325,27 @@ that width, height and the media bus pixel code are equal on both source and
326sink of the link. Subdev drivers are also free to use this function to 325sink of the link. Subdev drivers are also free to use this function to
327perform the checks mentioned above in addition to their own checks. 326perform the checks mentioned above in addition to their own checks.
328 327
329A device (bridge) driver needs to register the v4l2_subdev with the 328There are currently two ways to register subdevices with the V4L2 core. The
330v4l2_device: 329first (traditional) possibility is to have subdevices registered by bridge
330drivers. This can be done when the bridge driver has the complete information
331about subdevices connected to it and knows exactly when to register them. This
332is typically the case for internal subdevices, like video data processing units
333within SoCs or complex PCI(e) boards, camera sensors in USB cameras or connected
334to SoCs, which pass information about them to bridge drivers, usually in their
335platform data.
336
337There are however also situations where subdevices have to be registered
338asynchronously to bridge devices. An example of such a configuration is a Device
339Tree based system where information about subdevices is made available to the
340system independently from the bridge devices, e.g. when subdevices are defined
341in DT as I2C device nodes. The API used in this second case is described further
342below.
343
344Using one or the other registration method only affects the probing process, the
345run-time bridge-subdevice interaction is in both cases the same.
346
347In the synchronous case a device (bridge) driver needs to register the
348v4l2_subdev with the v4l2_device:
331 349
332 int err = v4l2_device_register_subdev(v4l2_dev, sd); 350 int err = v4l2_device_register_subdev(v4l2_dev, sd);
333 351
@@ -346,24 +364,24 @@ Afterwards the subdev module can be unloaded and sd->dev == NULL.
346 364
347You can call an ops function either directly: 365You can call an ops function either directly:
348 366
349 err = sd->ops->core->g_chip_ident(sd, &chip); 367 err = sd->ops->core->g_std(sd, &norm);
350 368
351but it is better and easier to use this macro: 369but it is better and easier to use this macro:
352 370
353 err = v4l2_subdev_call(sd, core, g_chip_ident, &chip); 371 err = v4l2_subdev_call(sd, core, g_std, &norm);
354 372
355The macro will to the right NULL pointer checks and returns -ENODEV if subdev 373The macro will to the right NULL pointer checks and returns -ENODEV if subdev
356is NULL, -ENOIOCTLCMD if either subdev->core or subdev->core->g_chip_ident is 374is NULL, -ENOIOCTLCMD if either subdev->core or subdev->core->g_std is
357NULL, or the actual result of the subdev->ops->core->g_chip_ident ops. 375NULL, or the actual result of the subdev->ops->core->g_std ops.
358 376
359It is also possible to call all or a subset of the sub-devices: 377It is also possible to call all or a subset of the sub-devices:
360 378
361 v4l2_device_call_all(v4l2_dev, 0, core, g_chip_ident, &chip); 379 v4l2_device_call_all(v4l2_dev, 0, core, g_std, &norm);
362 380
363Any subdev that does not support this ops is skipped and error results are 381Any subdev that does not support this ops is skipped and error results are
364ignored. If you want to check for errors use this: 382ignored. If you want to check for errors use this:
365 383
366 err = v4l2_device_call_until_err(v4l2_dev, 0, core, g_chip_ident, &chip); 384 err = v4l2_device_call_until_err(v4l2_dev, 0, core, g_std, &norm);
367 385
368Any error except -ENOIOCTLCMD will exit the loop with that error. If no 386Any error except -ENOIOCTLCMD will exit the loop with that error. If no
369errors (except -ENOIOCTLCMD) occurred, then 0 is returned. 387errors (except -ENOIOCTLCMD) occurred, then 0 is returned.
@@ -394,6 +412,30 @@ controlled through GPIO pins. This distinction is only relevant when setting
394up the device, but once the subdev is registered it is completely transparent. 412up the device, but once the subdev is registered it is completely transparent.
395 413
396 414
415In the asynchronous case subdevice probing can be invoked independently of the
416bridge driver availability. The subdevice driver then has to verify whether all
417the requirements for a successful probing are satisfied. This can include a
418check for a master clock availability. If any of the conditions aren't satisfied
419the driver might decide to return -EPROBE_DEFER to request further reprobing
420attempts. Once all conditions are met the subdevice shall be registered using
421the v4l2_async_register_subdev() function. Unregistration is performed using
422the v4l2_async_unregister_subdev() call. Subdevices registered this way are
423stored in a global list of subdevices, ready to be picked up by bridge drivers.
424
425Bridge drivers in turn have to register a notifier object with an array of
426subdevice descriptors that the bridge device needs for its operation. This is
427performed using the v4l2_async_notifier_register() call. To unregister the
428notifier the driver has to call v4l2_async_notifier_unregister(). The former of
429the two functions takes two arguments: a pointer to struct v4l2_device and a
430pointer to struct v4l2_async_notifier. The latter contains a pointer to an array
431of pointers to subdevice descriptors of type struct v4l2_async_subdev type. The
432V4L2 core will then use these descriptors to match asynchronously registered
433subdevices to them. If a match is detected the .bound() notifier callback is
434called. After all subdevices have been located the .complete() callback is
435called. When a subdevice is removed from the system the .unbind() method is
436called. All three callbacks are optional.
437
438
397V4L2 sub-device userspace API 439V4L2 sub-device userspace API
398----------------------------- 440-----------------------------
399 441
@@ -575,9 +617,13 @@ of the video device exits.
575The default video_device_release() callback just calls kfree to free the 617The default video_device_release() callback just calls kfree to free the
576allocated memory. 618allocated memory.
577 619
620There is also a video_device_release_empty() function that does nothing
621(is empty) and can be used if the struct is embedded and there is nothing
622to do when it is released.
623
578You should also set these fields: 624You should also set these fields:
579 625
580- v4l2_dev: set to the v4l2_device parent device. 626- v4l2_dev: must be set to the v4l2_device parent device.
581 627
582- name: set to something descriptive and unique. 628- name: set to something descriptive and unique.
583 629
@@ -614,15 +660,16 @@ You should also set these fields:
614 If you want to have a separate priority state per (group of) device node(s), 660 If you want to have a separate priority state per (group of) device node(s),
615 then you can point it to your own struct v4l2_prio_state. 661 then you can point it to your own struct v4l2_prio_state.
616 662
617- parent: you only set this if v4l2_device was registered with NULL as 663- dev_parent: you only set this if v4l2_device was registered with NULL as
618 the parent device struct. This only happens in cases where one hardware 664 the parent device struct. This only happens in cases where one hardware
619 device has multiple PCI devices that all share the same v4l2_device core. 665 device has multiple PCI devices that all share the same v4l2_device core.
620 666
621 The cx88 driver is an example of this: one core v4l2_device struct, but 667 The cx88 driver is an example of this: one core v4l2_device struct, but
622 it is used by both an raw video PCI device (cx8800) and a MPEG PCI device 668 it is used by both a raw video PCI device (cx8800) and a MPEG PCI device
623 (cx8802). Since the v4l2_device cannot be associated with a particular 669 (cx8802). Since the v4l2_device cannot be associated with two PCI devices
624 PCI device it is setup without a parent device. But when the struct 670 at the same time it is setup without a parent device. But when the struct
625 video_device is setup you do know which parent PCI device to use. 671 video_device is initialized you *do* know which parent PCI device to use and
672 so you set dev_device to the correct PCI device.
626 673
627- flags: optional. Set to V4L2_FL_USE_FH_PRIO if you want to let the framework 674- flags: optional. Set to V4L2_FL_USE_FH_PRIO if you want to let the framework
628 handle the VIDIOC_G/S_PRIORITY ioctls. This requires that you use struct 675 handle the VIDIOC_G/S_PRIORITY ioctls. This requires that you use struct
@@ -1061,3 +1108,29 @@ available event type is 'class base + 1'.
1061 1108
1062An example on how the V4L2 events may be used can be found in the OMAP 1109An example on how the V4L2 events may be used can be found in the OMAP
10633 ISP driver (drivers/media/platform/omap3isp). 11103 ISP driver (drivers/media/platform/omap3isp).
1111
1112
1113V4L2 clocks
1114-----------
1115
1116Many subdevices, like camera sensors, TV decoders and encoders, need a clock
1117signal to be supplied by the system. Often this clock is supplied by the
1118respective bridge device. The Linux kernel provides a Common Clock Framework for
1119this purpose. However, it is not (yet) available on all architectures. Besides,
1120the nature of the multi-functional (clock, data + synchronisation, I2C control)
1121connection of subdevices to the system might impose special requirements on the
1122clock API usage. E.g. V4L2 has to support clock provider driver unregistration
1123while a subdevice driver is holding a reference to the clock. For these reasons
1124a V4L2 clock helper API has been developed and is provided to bridge and
1125subdevice drivers.
1126
1127The API consists of two parts: two functions to register and unregister a V4L2
1128clock source: v4l2_clk_register() and v4l2_clk_unregister() and calls to control
1129a clock object, similar to the respective generic clock API calls:
1130v4l2_clk_get(), v4l2_clk_put(), v4l2_clk_enable(), v4l2_clk_disable(),
1131v4l2_clk_get_rate(), and v4l2_clk_set_rate(). Clock suppliers have to provide
1132clock operations that will be called when clock users invoke respective API
1133methods.
1134
1135It is expected that once the CCF becomes available on all relevant
1136architectures this API will be removed.
diff --git a/Documentation/zh_CN/video4linux/v4l2-framework.txt b/Documentation/zh_CN/video4linux/v4l2-framework.txt
index 44c1d934c4e3..0da95dbaef34 100644
--- a/Documentation/zh_CN/video4linux/v4l2-framework.txt
+++ b/Documentation/zh_CN/video4linux/v4l2-framework.txt
@@ -247,7 +247,6 @@ i2c_client 结构体,i2c_set_clientdata() 函数可用于保存一个 v4l2_sub
247这些结构体定义如下: 247这些结构体定义如下:
248 248
249struct v4l2_subdev_core_ops { 249struct v4l2_subdev_core_ops {
250 int (*g_chip_ident)(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip);
251 int (*log_status)(struct v4l2_subdev *sd); 250 int (*log_status)(struct v4l2_subdev *sd);
252 int (*init)(struct v4l2_subdev *sd, u32 val); 251 int (*init)(struct v4l2_subdev *sd, u32 val);
253 ... 252 ...
@@ -337,24 +336,24 @@ subdev->dev 域就指向了 v4l2_device。
337 336
338注册之设备后,可通过以下方式直接调用其操作函数: 337注册之设备后,可通过以下方式直接调用其操作函数:
339 338
340 err = sd->ops->core->g_chip_ident(sd, &chip); 339 err = sd->ops->core->g_std(sd, &norm);
341 340
342但使用如下宏会比较容易且合适: 341但使用如下宏会比较容易且合适:
343 342
344 err = v4l2_subdev_call(sd, core, g_chip_ident, &chip); 343 err = v4l2_subdev_call(sd, core, g_std, &norm);
345 344
346这个宏将会做 NULL 指针检查,如果 subdev 为 NULL,则返回-ENODEV;如果 345这个宏将会做 NULL 指针检查,如果 subdev 为 NULL,则返回-ENODEV;如果
347subdev->core 或 subdev->core->g_chip_ident 为 NULL,则返回 -ENOIOCTLCMD; 346subdev->core 或 subdev->core->g_std 为 NULL,则返回 -ENOIOCTLCMD;
348否则将返回 subdev->ops->core->g_chip_ident ops 调用的实际结果。 347否则将返回 subdev->ops->core->g_std ops 调用的实际结果。
349 348
350有时也可能同时调用所有或一系列子设备的某个操作函数: 349有时也可能同时调用所有或一系列子设备的某个操作函数:
351 350
352 v4l2_device_call_all(v4l2_dev, 0, core, g_chip_ident, &chip); 351 v4l2_device_call_all(v4l2_dev, 0, core, g_std, &norm);
353 352
354任何不支持此操作的子设备都会被跳过,并忽略错误返回值。但如果你需要 353任何不支持此操作的子设备都会被跳过,并忽略错误返回值。但如果你需要
355检查出错码,则可使用如下函数: 354检查出错码,则可使用如下函数:
356 355
357 err = v4l2_device_call_until_err(v4l2_dev, 0, core, g_chip_ident, &chip); 356 err = v4l2_device_call_until_err(v4l2_dev, 0, core, g_std, &norm);
358 357
359除 -ENOIOCTLCMD 外的任何错误都会跳出循环并返回错误值。如果(除 -ENOIOCTLCMD 358除 -ENOIOCTLCMD 外的任何错误都会跳出循环并返回错误值。如果(除 -ENOIOCTLCMD
360外)没有错误发生,则返回 0。 359外)没有错误发生,则返回 0。
diff --git a/MAINTAINERS b/MAINTAINERS
index 9d771d9825cf..b41a9fce3211 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1165,15 +1165,6 @@ L: linux-media@vger.kernel.org
1165S: Maintained 1165S: Maintained
1166F: drivers/media/platform/s5p-g2d/ 1166F: drivers/media/platform/s5p-g2d/
1167 1167
1168ARM/SAMSUNG S5P SERIES FIMC SUPPORT
1169M: Kyungmin Park <kyungmin.park@samsung.com>
1170M: Sylwester Nawrocki <s.nawrocki@samsung.com>
1171L: linux-arm-kernel@lists.infradead.org
1172L: linux-media@vger.kernel.org
1173S: Maintained
1174F: arch/arm/plat-samsung/include/plat/*fimc*
1175F: drivers/media/platform/s5p-fimc/
1176
1177ARM/SAMSUNG S5P SERIES Multi Format Codec (MFC) SUPPORT 1168ARM/SAMSUNG S5P SERIES Multi Format Codec (MFC) SUPPORT
1178M: Kyungmin Park <kyungmin.park@samsung.com> 1169M: Kyungmin Park <kyungmin.park@samsung.com>
1179M: Kamil Debski <k.debski@samsung.com> 1170M: Kamil Debski <k.debski@samsung.com>
@@ -1595,7 +1586,7 @@ F: include/net/ax25.h
1595F: net/ax25/ 1586F: net/ax25/
1596 1587
1597AZ6007 DVB DRIVER 1588AZ6007 DVB DRIVER
1598M: Mauro Carvalho Chehab <mchehab@redhat.com> 1589M: Mauro Carvalho Chehab <m.chehab@samsung.com>
1599L: linux-media@vger.kernel.org 1590L: linux-media@vger.kernel.org
1600W: http://linuxtv.org 1591W: http://linuxtv.org
1601T: git git://linuxtv.org/media_tree.git 1592T: git git://linuxtv.org/media_tree.git
@@ -1880,7 +1871,7 @@ F: Documentation/filesystems/btrfs.txt
1880F: fs/btrfs/ 1871F: fs/btrfs/
1881 1872
1882BTTV VIDEO4LINUX DRIVER 1873BTTV VIDEO4LINUX DRIVER
1883M: Mauro Carvalho Chehab <mchehab@redhat.com> 1874M: Mauro Carvalho Chehab <m.chehab@samsung.com>
1884L: linux-media@vger.kernel.org 1875L: linux-media@vger.kernel.org
1885W: http://linuxtv.org 1876W: http://linuxtv.org
1886T: git git://linuxtv.org/media_tree.git 1877T: git git://linuxtv.org/media_tree.git
@@ -2368,7 +2359,7 @@ F: drivers/media/common/cx2341x*
2368F: include/media/cx2341x* 2359F: include/media/cx2341x*
2369 2360
2370CX88 VIDEO4LINUX DRIVER 2361CX88 VIDEO4LINUX DRIVER
2371M: Mauro Carvalho Chehab <mchehab@redhat.com> 2362M: Mauro Carvalho Chehab <m.chehab@samsung.com>
2372L: linux-media@vger.kernel.org 2363L: linux-media@vger.kernel.org
2373W: http://linuxtv.org 2364W: http://linuxtv.org
2374T: git git://linuxtv.org/media_tree.git 2365T: git git://linuxtv.org/media_tree.git
@@ -2990,7 +2981,7 @@ S: Maintained
2990F: drivers/edac/e7xxx_edac.c 2981F: drivers/edac/e7xxx_edac.c
2991 2982
2992EDAC-GHES 2983EDAC-GHES
2993M: Mauro Carvalho Chehab <mchehab@redhat.com> 2984M: Mauro Carvalho Chehab <m.chehab@samsung.com>
2994L: linux-edac@vger.kernel.org 2985L: linux-edac@vger.kernel.org
2995W: bluesmoke.sourceforge.net 2986W: bluesmoke.sourceforge.net
2996S: Maintained 2987S: Maintained
@@ -3018,21 +3009,21 @@ S: Maintained
3018F: drivers/edac/i5000_edac.c 3009F: drivers/edac/i5000_edac.c
3019 3010
3020EDAC-I5400 3011EDAC-I5400
3021M: Mauro Carvalho Chehab <mchehab@redhat.com> 3012M: Mauro Carvalho Chehab <m.chehab@samsung.com>
3022L: linux-edac@vger.kernel.org 3013L: linux-edac@vger.kernel.org
3023W: bluesmoke.sourceforge.net 3014W: bluesmoke.sourceforge.net
3024S: Maintained 3015S: Maintained
3025F: drivers/edac/i5400_edac.c 3016F: drivers/edac/i5400_edac.c
3026 3017
3027EDAC-I7300 3018EDAC-I7300
3028M: Mauro Carvalho Chehab <mchehab@redhat.com> 3019M: Mauro Carvalho Chehab <m.chehab@samsung.com>
3029L: linux-edac@vger.kernel.org 3020L: linux-edac@vger.kernel.org
3030W: bluesmoke.sourceforge.net 3021W: bluesmoke.sourceforge.net
3031S: Maintained 3022S: Maintained
3032F: drivers/edac/i7300_edac.c 3023F: drivers/edac/i7300_edac.c
3033 3024
3034EDAC-I7CORE 3025EDAC-I7CORE
3035M: Mauro Carvalho Chehab <mchehab@redhat.com> 3026M: Mauro Carvalho Chehab <m.chehab@samsung.com>
3036L: linux-edac@vger.kernel.org 3027L: linux-edac@vger.kernel.org
3037W: bluesmoke.sourceforge.net 3028W: bluesmoke.sourceforge.net
3038S: Maintained 3029S: Maintained
@@ -3061,7 +3052,7 @@ S: Maintained
3061F: drivers/edac/r82600_edac.c 3052F: drivers/edac/r82600_edac.c
3062 3053
3063EDAC-SBRIDGE 3054EDAC-SBRIDGE
3064M: Mauro Carvalho Chehab <mchehab@redhat.com> 3055M: Mauro Carvalho Chehab <m.chehab@samsung.com>
3065L: linux-edac@vger.kernel.org 3056L: linux-edac@vger.kernel.org
3066W: bluesmoke.sourceforge.net 3057W: bluesmoke.sourceforge.net
3067S: Maintained 3058S: Maintained
@@ -3121,7 +3112,7 @@ S: Maintained
3121F: drivers/net/ethernet/ibm/ehea/ 3112F: drivers/net/ethernet/ibm/ehea/
3122 3113
3123EM28XX VIDEO4LINUX DRIVER 3114EM28XX VIDEO4LINUX DRIVER
3124M: Mauro Carvalho Chehab <mchehab@redhat.com> 3115M: Mauro Carvalho Chehab <m.chehab@samsung.com>
3125L: linux-media@vger.kernel.org 3116L: linux-media@vger.kernel.org
3126W: http://linuxtv.org 3117W: http://linuxtv.org
3127T: git git://linuxtv.org/media_tree.git 3118T: git git://linuxtv.org/media_tree.git
@@ -5317,7 +5308,7 @@ S: Maintained
5317F: drivers/media/radio/radio-maxiradio* 5308F: drivers/media/radio/radio-maxiradio*
5318 5309
5319MEDIA INPUT INFRASTRUCTURE (V4L/DVB) 5310MEDIA INPUT INFRASTRUCTURE (V4L/DVB)
5320M: Mauro Carvalho Chehab <mchehab@redhat.com> 5311M: Mauro Carvalho Chehab <m.chehab@samsung.com>
5321P: LinuxTV.org Project 5312P: LinuxTV.org Project
5322L: linux-media@vger.kernel.org 5313L: linux-media@vger.kernel.org
5323W: http://linuxtv.org 5314W: http://linuxtv.org
@@ -7013,7 +7004,7 @@ S: Odd Fixes
7013F: drivers/media/i2c/saa6588* 7004F: drivers/media/i2c/saa6588*
7014 7005
7015SAA7134 VIDEO4LINUX DRIVER 7006SAA7134 VIDEO4LINUX DRIVER
7016M: Mauro Carvalho Chehab <mchehab@redhat.com> 7007M: Mauro Carvalho Chehab <m.chehab@samsung.com>
7017L: linux-media@vger.kernel.org 7008L: linux-media@vger.kernel.org
7018W: http://linuxtv.org 7009W: http://linuxtv.org
7019T: git git://linuxtv.org/media_tree.git 7010T: git git://linuxtv.org/media_tree.git
@@ -7058,6 +7049,15 @@ F: drivers/regulator/s5m*.c
7058F: drivers/rtc/rtc-sec.c 7049F: drivers/rtc/rtc-sec.c
7059F: include/linux/mfd/samsung/ 7050F: include/linux/mfd/samsung/
7060 7051
7052SAMSUNG S5P/EXYNOS4 SOC SERIES CAMERA SUBSYSTEM DRIVERS
7053M: Kyungmin Park <kyungmin.park@samsung.com>
7054M: Sylwester Nawrocki <s.nawrocki@samsung.com>
7055L: linux-media@vger.kernel.org
7056Q: https://patchwork.linuxtv.org/project/linux-media/list/
7057S: Supported
7058F: drivers/media/platform/exynos4-is/
7059F: include/media/s5p_fimc.h
7060
7061SAMSUNG S3C24XX/S3C64XX SOC SERIES CAMIF DRIVER 7061SAMSUNG S3C24XX/S3C64XX SOC SERIES CAMIF DRIVER
7062M: Sylwester Nawrocki <sylvester.nawrocki@gmail.com> 7062M: Sylwester Nawrocki <sylvester.nawrocki@gmail.com>
7063L: linux-media@vger.kernel.org 7063L: linux-media@vger.kernel.org
@@ -7375,7 +7375,7 @@ S: Odd Fixes
7375F: drivers/media/radio/radio-si4713.h 7375F: drivers/media/radio/radio-si4713.h
7376 7376
7377SIANO DVB DRIVER 7377SIANO DVB DRIVER
7378M: Mauro Carvalho Chehab <mchehab@redhat.com> 7378M: Mauro Carvalho Chehab <m.chehab@samsung.com>
7379L: linux-media@vger.kernel.org 7379L: linux-media@vger.kernel.org
7380W: http://linuxtv.org 7380W: http://linuxtv.org
7381T: git git://linuxtv.org/media_tree.git 7381T: git git://linuxtv.org/media_tree.git
@@ -8080,7 +8080,7 @@ S: Maintained
8080F: drivers/media/i2c/tda9840* 8080F: drivers/media/i2c/tda9840*
8081 8081
8082TEA5761 TUNER DRIVER 8082TEA5761 TUNER DRIVER
8083M: Mauro Carvalho Chehab <mchehab@redhat.com> 8083M: Mauro Carvalho Chehab <m.chehab@samsung.com>
8084L: linux-media@vger.kernel.org 8084L: linux-media@vger.kernel.org
8085W: http://linuxtv.org 8085W: http://linuxtv.org
8086T: git git://linuxtv.org/media_tree.git 8086T: git git://linuxtv.org/media_tree.git
@@ -8088,7 +8088,7 @@ S: Odd fixes
8088F: drivers/media/tuners/tea5761.* 8088F: drivers/media/tuners/tea5761.*
8089 8089
8090TEA5767 TUNER DRIVER 8090TEA5767 TUNER DRIVER
8091M: Mauro Carvalho Chehab <mchehab@redhat.com> 8091M: Mauro Carvalho Chehab <m.chehab@samsung.com>
8092L: linux-media@vger.kernel.org 8092L: linux-media@vger.kernel.org
8093W: http://linuxtv.org 8093W: http://linuxtv.org
8094T: git git://linuxtv.org/media_tree.git 8094T: git git://linuxtv.org/media_tree.git
@@ -8327,7 +8327,7 @@ F: include/linux/shmem_fs.h
8327F: mm/shmem.c 8327F: mm/shmem.c
8328 8328
8329TM6000 VIDEO4LINUX DRIVER 8329TM6000 VIDEO4LINUX DRIVER
8330M: Mauro Carvalho Chehab <mchehab@redhat.com> 8330M: Mauro Carvalho Chehab <m.chehab@samsung.com>
8331L: linux-media@vger.kernel.org 8331L: linux-media@vger.kernel.org
8332W: http://linuxtv.org 8332W: http://linuxtv.org
8333T: git git://linuxtv.org/media_tree.git 8333T: git git://linuxtv.org/media_tree.git
@@ -9184,7 +9184,7 @@ S: Maintained
9184F: arch/x86/kernel/cpu/mcheck/* 9184F: arch/x86/kernel/cpu/mcheck/*
9185 9185
9186XC2028/3028 TUNER DRIVER 9186XC2028/3028 TUNER DRIVER
9187M: Mauro Carvalho Chehab <mchehab@redhat.com> 9187M: Mauro Carvalho Chehab <m.chehab@samsung.com>
9188L: linux-media@vger.kernel.org 9188L: linux-media@vger.kernel.org
9189W: http://linuxtv.org 9189W: http://linuxtv.org
9190T: git git://linuxtv.org/media_tree.git 9190T: git git://linuxtv.org/media_tree.git
diff --git a/arch/arm/mach-davinci/board-dm365-evm.c b/arch/arm/mach-davinci/board-dm365-evm.c
index fd38c8d22e3c..afbc439f11d4 100644
--- a/arch/arm/mach-davinci/board-dm365-evm.c
+++ b/arch/arm/mach-davinci/board-dm365-evm.c
@@ -509,7 +509,6 @@ struct ths7303_platform_data ths7303_pdata = {
509 .ch_1 = 3, 509 .ch_1 = 3,
510 .ch_2 = 3, 510 .ch_2 = 3,
511 .ch_3 = 3, 511 .ch_3 = 3,
512 .init_enable = 1,
513}; 512};
514 513
515static struct amp_config_info vpbe_amp = { 514static struct amp_config_info vpbe_amp = {
diff --git a/drivers/base/dma-buf.c b/drivers/base/dma-buf.c
index 08fe897c0b4c..6687ba741879 100644
--- a/drivers/base/dma-buf.c
+++ b/drivers/base/dma-buf.c
@@ -680,10 +680,7 @@ int dma_buf_debugfs_create_file(const char *name,
680 d = debugfs_create_file(name, S_IRUGO, dma_buf_debugfs_dir, 680 d = debugfs_create_file(name, S_IRUGO, dma_buf_debugfs_dir,
681 write, &dma_buf_debug_fops); 681 write, &dma_buf_debug_fops);
682 682
683 if (IS_ERR(d)) 683 return PTR_RET(d);
684 return PTR_ERR(d);
685
686 return 0;
687} 684}
688#else 685#else
689static inline int dma_buf_init_debugfs(void) 686static inline int dma_buf_init_debugfs(void)
diff --git a/drivers/media/common/saa7146/saa7146_video.c b/drivers/media/common/saa7146/saa7146_video.c
index fe907f2e8f59..30779498c173 100644
--- a/drivers/media/common/saa7146/saa7146_video.c
+++ b/drivers/media/common/saa7146/saa7146_video.c
@@ -1,7 +1,6 @@
1#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 1#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
2 2
3#include <media/saa7146_vv.h> 3#include <media/saa7146_vv.h>
4#include <media/v4l2-chip-ident.h>
5#include <media/v4l2-event.h> 4#include <media/v4l2-event.h>
6#include <media/v4l2-ctrls.h> 5#include <media/v4l2-ctrls.h>
7#include <linux/module.h> 6#include <linux/module.h>
@@ -988,26 +987,6 @@ static int vidioc_streamoff(struct file *file, void *__fh, enum v4l2_buf_type ty
988 return err; 987 return err;
989} 988}
990 989
991static int vidioc_g_chip_ident(struct file *file, void *__fh,
992 struct v4l2_dbg_chip_ident *chip)
993{
994 struct saa7146_fh *fh = __fh;
995 struct saa7146_dev *dev = fh->dev;
996
997 chip->ident = V4L2_IDENT_NONE;
998 chip->revision = 0;
999 if (chip->match.type == V4L2_CHIP_MATCH_HOST) {
1000 if (v4l2_chip_match_host(&chip->match))
1001 chip->ident = V4L2_IDENT_SAA7146;
1002 return 0;
1003 }
1004 if (chip->match.type != V4L2_CHIP_MATCH_I2C_DRIVER &&
1005 chip->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
1006 return -EINVAL;
1007 return v4l2_device_call_until_err(&dev->v4l2_dev, 0,
1008 core, g_chip_ident, chip);
1009}
1010
1011const struct v4l2_ioctl_ops saa7146_video_ioctl_ops = { 990const struct v4l2_ioctl_ops saa7146_video_ioctl_ops = {
1012 .vidioc_querycap = vidioc_querycap, 991 .vidioc_querycap = vidioc_querycap,
1013 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, 992 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
@@ -1018,7 +997,6 @@ const struct v4l2_ioctl_ops saa7146_video_ioctl_ops = {
1018 .vidioc_g_fmt_vid_overlay = vidioc_g_fmt_vid_overlay, 997 .vidioc_g_fmt_vid_overlay = vidioc_g_fmt_vid_overlay,
1019 .vidioc_try_fmt_vid_overlay = vidioc_try_fmt_vid_overlay, 998 .vidioc_try_fmt_vid_overlay = vidioc_try_fmt_vid_overlay,
1020 .vidioc_s_fmt_vid_overlay = vidioc_s_fmt_vid_overlay, 999 .vidioc_s_fmt_vid_overlay = vidioc_s_fmt_vid_overlay,
1021 .vidioc_g_chip_ident = vidioc_g_chip_ident,
1022 1000
1023 .vidioc_overlay = vidioc_overlay, 1001 .vidioc_overlay = vidioc_overlay,
1024 .vidioc_g_fbuf = vidioc_g_fbuf, 1002 .vidioc_g_fbuf = vidioc_g_fbuf,
@@ -1039,7 +1017,6 @@ const struct v4l2_ioctl_ops saa7146_video_ioctl_ops = {
1039const struct v4l2_ioctl_ops saa7146_vbi_ioctl_ops = { 1017const struct v4l2_ioctl_ops saa7146_vbi_ioctl_ops = {
1040 .vidioc_querycap = vidioc_querycap, 1018 .vidioc_querycap = vidioc_querycap,
1041 .vidioc_g_fmt_vbi_cap = vidioc_g_fmt_vbi_cap, 1019 .vidioc_g_fmt_vbi_cap = vidioc_g_fmt_vbi_cap,
1042 .vidioc_g_chip_ident = vidioc_g_chip_ident,
1043 1020
1044 .vidioc_reqbufs = vidioc_reqbufs, 1021 .vidioc_reqbufs = vidioc_reqbufs,
1045 .vidioc_querybuf = vidioc_querybuf, 1022 .vidioc_querybuf = vidioc_querybuf,
diff --git a/drivers/media/common/siano/smscoreapi.c b/drivers/media/common/siano/smscoreapi.c
index 45ac9eea4882..a142f7942a01 100644
--- a/drivers/media/common/siano/smscoreapi.c
+++ b/drivers/media/common/siano/smscoreapi.c
@@ -1154,7 +1154,7 @@ static int smscore_load_firmware_from_file(struct smscore_device_t *coredev,
1154 1154
1155 char *fw_filename = smscore_get_fw_filename(coredev, mode); 1155 char *fw_filename = smscore_get_fw_filename(coredev, mode);
1156 if (!fw_filename) { 1156 if (!fw_filename) {
1157 sms_info("mode %d not supported on this device", mode); 1157 sms_err("mode %d not supported on this device", mode);
1158 return -ENOENT; 1158 return -ENOENT;
1159 } 1159 }
1160 sms_debug("Firmware name: %s", fw_filename); 1160 sms_debug("Firmware name: %s", fw_filename);
@@ -1165,23 +1165,24 @@ static int smscore_load_firmware_from_file(struct smscore_device_t *coredev,
1165 1165
1166 rc = request_firmware(&fw, fw_filename, coredev->device); 1166 rc = request_firmware(&fw, fw_filename, coredev->device);
1167 if (rc < 0) { 1167 if (rc < 0) {
1168 sms_info("failed to open \"%s\"", fw_filename); 1168 sms_err("failed to open firmware file \"%s\"", fw_filename);
1169 return rc; 1169 return rc;
1170 } 1170 }
1171 sms_info("read fw %s, buffer size=0x%zx", fw_filename, fw->size); 1171 sms_info("read fw %s, buffer size=0x%zx", fw_filename, fw->size);
1172 fw_buf = kmalloc(ALIGN(fw->size, SMS_ALLOC_ALIGNMENT), 1172 fw_buf = kmalloc(ALIGN(fw->size, SMS_ALLOC_ALIGNMENT),
1173 GFP_KERNEL | GFP_DMA); 1173 GFP_KERNEL | GFP_DMA);
1174 if (!fw_buf) { 1174 if (!fw_buf) {
1175 sms_info("failed to allocate firmware buffer"); 1175 sms_err("failed to allocate firmware buffer");
1176 return -ENOMEM; 1176 rc = -ENOMEM;
1177 } 1177 } else {
1178 memcpy(fw_buf, fw->data, fw->size); 1178 memcpy(fw_buf, fw->data, fw->size);
1179 fw_buf_size = fw->size; 1179 fw_buf_size = fw->size;
1180 1180
1181 rc = (coredev->device_flags & SMS_DEVICE_FAMILY2) ? 1181 rc = (coredev->device_flags & SMS_DEVICE_FAMILY2) ?
1182 smscore_load_firmware_family2(coredev, fw_buf, fw_buf_size) 1182 smscore_load_firmware_family2(coredev, fw_buf, fw_buf_size)
1183 : loadfirmware_handler(coredev->context, fw_buf, 1183 : loadfirmware_handler(coredev->context, fw_buf,
1184 fw_buf_size); 1184 fw_buf_size);
1185 }
1185 1186
1186 kfree(fw_buf); 1187 kfree(fw_buf);
1187 release_firmware(fw); 1188 release_firmware(fw);
diff --git a/drivers/media/common/siano/smsdvb-main.c b/drivers/media/common/siano/smsdvb-main.c
index 297f1b2f9a32..086262252230 100644
--- a/drivers/media/common/siano/smsdvb-main.c
+++ b/drivers/media/common/siano/smsdvb-main.c
@@ -140,6 +140,7 @@ static void smsdvb_stats_not_ready(struct dvb_frontend *fe)
140 case DEVICE_MODE_ISDBT: 140 case DEVICE_MODE_ISDBT:
141 case DEVICE_MODE_ISDBT_BDA: 141 case DEVICE_MODE_ISDBT_BDA:
142 n_layers = 4; 142 n_layers = 4;
143 break;
143 default: 144 default:
144 n_layers = 1; 145 n_layers = 1;
145 } 146 }
diff --git a/drivers/media/common/tveeprom.c b/drivers/media/common/tveeprom.c
index cc1e172dfece..c7dace671a9d 100644
--- a/drivers/media/common/tveeprom.c
+++ b/drivers/media/common/tveeprom.c
@@ -40,7 +40,6 @@
40#include <media/tuner.h> 40#include <media/tuner.h>
41#include <media/tveeprom.h> 41#include <media/tveeprom.h>
42#include <media/v4l2-common.h> 42#include <media/v4l2-common.h>
43#include <media/v4l2-chip-ident.h>
44 43
45MODULE_DESCRIPTION("i2c Hauppauge eeprom decoder driver"); 44MODULE_DESCRIPTION("i2c Hauppauge eeprom decoder driver");
46MODULE_AUTHOR("John Klar"); 45MODULE_AUTHOR("John Klar");
@@ -67,13 +66,10 @@ MODULE_PARM_DESC(debug, "Debug level (0-1)");
67 * The Hauppauge eeprom uses an 8bit field to determine which 66 * The Hauppauge eeprom uses an 8bit field to determine which
68 * tuner formats the tuner supports. 67 * tuner formats the tuner supports.
69 */ 68 */
70static struct HAUPPAUGE_TUNER_FMT 69static const struct {
71{
72 int id; 70 int id;
73 char *name; 71 const char * const name;
74} 72} hauppauge_tuner_fmt[] = {
75hauppauge_tuner_fmt[] =
76{
77 { V4L2_STD_UNKNOWN, " UNKNOWN" }, 73 { V4L2_STD_UNKNOWN, " UNKNOWN" },
78 { V4L2_STD_UNKNOWN, " FM" }, 74 { V4L2_STD_UNKNOWN, " FM" },
79 { V4L2_STD_B|V4L2_STD_GH, " PAL(B/G)" }, 75 { V4L2_STD_B|V4L2_STD_GH, " PAL(B/G)" },
@@ -88,13 +84,10 @@ hauppauge_tuner_fmt[] =
88 supplying this information. Note that many tuners where only used for 84 supplying this information. Note that many tuners where only used for
89 testing and never made it to the outside world. So you will only see 85 testing and never made it to the outside world. So you will only see
90 a subset in actual produced cards. */ 86 a subset in actual produced cards. */
91static struct HAUPPAUGE_TUNER 87static const struct {
92{
93 int id; 88 int id;
94 char *name; 89 const char * const name;
95} 90} hauppauge_tuner[] = {
96hauppauge_tuner[] =
97{
98 /* 0-9 */ 91 /* 0-9 */
99 { TUNER_ABSENT, "None" }, 92 { TUNER_ABSENT, "None" },
100 { TUNER_ABSENT, "External" }, 93 { TUNER_ABSENT, "External" },
@@ -298,69 +291,66 @@ hauppauge_tuner[] =
298 { TUNER_ABSENT, "NXP 18272S"}, 291 { TUNER_ABSENT, "NXP 18272S"},
299}; 292};
300 293
301/* Use V4L2_IDENT_AMBIGUOUS for those audio 'chips' that are 294/* Use TVEEPROM_AUDPROC_INTERNAL for those audio 'chips' that are
302 * internal to a video chip, i.e. not a separate audio chip. */ 295 * internal to a video chip, i.e. not a separate audio chip. */
303static struct HAUPPAUGE_AUDIOIC 296static const struct {
304{
305 u32 id; 297 u32 id;
306 char *name; 298 const char * const name;
307} 299} audio_ic[] = {
308audioIC[] =
309{
310 /* 0-4 */ 300 /* 0-4 */
311 { V4L2_IDENT_NONE, "None" }, 301 { TVEEPROM_AUDPROC_NONE, "None" },
312 { V4L2_IDENT_UNKNOWN, "TEA6300" }, 302 { TVEEPROM_AUDPROC_OTHER, "TEA6300" },
313 { V4L2_IDENT_UNKNOWN, "TEA6320" }, 303 { TVEEPROM_AUDPROC_OTHER, "TEA6320" },
314 { V4L2_IDENT_UNKNOWN, "TDA9850" }, 304 { TVEEPROM_AUDPROC_OTHER, "TDA9850" },
315 { V4L2_IDENT_MSPX4XX, "MSP3400C" }, 305 { TVEEPROM_AUDPROC_MSP, "MSP3400C" },
316 /* 5-9 */ 306 /* 5-9 */
317 { V4L2_IDENT_MSPX4XX, "MSP3410D" }, 307 { TVEEPROM_AUDPROC_MSP, "MSP3410D" },
318 { V4L2_IDENT_MSPX4XX, "MSP3415" }, 308 { TVEEPROM_AUDPROC_MSP, "MSP3415" },
319 { V4L2_IDENT_MSPX4XX, "MSP3430" }, 309 { TVEEPROM_AUDPROC_MSP, "MSP3430" },
320 { V4L2_IDENT_MSPX4XX, "MSP3438" }, 310 { TVEEPROM_AUDPROC_MSP, "MSP3438" },
321 { V4L2_IDENT_UNKNOWN, "CS5331" }, 311 { TVEEPROM_AUDPROC_OTHER, "CS5331" },
322 /* 10-14 */ 312 /* 10-14 */
323 { V4L2_IDENT_MSPX4XX, "MSP3435" }, 313 { TVEEPROM_AUDPROC_MSP, "MSP3435" },
324 { V4L2_IDENT_MSPX4XX, "MSP3440" }, 314 { TVEEPROM_AUDPROC_MSP, "MSP3440" },
325 { V4L2_IDENT_MSPX4XX, "MSP3445" }, 315 { TVEEPROM_AUDPROC_MSP, "MSP3445" },
326 { V4L2_IDENT_MSPX4XX, "MSP3411" }, 316 { TVEEPROM_AUDPROC_MSP, "MSP3411" },
327 { V4L2_IDENT_MSPX4XX, "MSP3416" }, 317 { TVEEPROM_AUDPROC_MSP, "MSP3416" },
328 /* 15-19 */ 318 /* 15-19 */
329 { V4L2_IDENT_MSPX4XX, "MSP3425" }, 319 { TVEEPROM_AUDPROC_MSP, "MSP3425" },
330 { V4L2_IDENT_MSPX4XX, "MSP3451" }, 320 { TVEEPROM_AUDPROC_MSP, "MSP3451" },
331 { V4L2_IDENT_MSPX4XX, "MSP3418" }, 321 { TVEEPROM_AUDPROC_MSP, "MSP3418" },
332 { V4L2_IDENT_UNKNOWN, "Type 0x12" }, 322 { TVEEPROM_AUDPROC_OTHER, "Type 0x12" },
333 { V4L2_IDENT_UNKNOWN, "OKI7716" }, 323 { TVEEPROM_AUDPROC_OTHER, "OKI7716" },
334 /* 20-24 */ 324 /* 20-24 */
335 { V4L2_IDENT_MSPX4XX, "MSP4410" }, 325 { TVEEPROM_AUDPROC_MSP, "MSP4410" },
336 { V4L2_IDENT_MSPX4XX, "MSP4420" }, 326 { TVEEPROM_AUDPROC_MSP, "MSP4420" },
337 { V4L2_IDENT_MSPX4XX, "MSP4440" }, 327 { TVEEPROM_AUDPROC_MSP, "MSP4440" },
338 { V4L2_IDENT_MSPX4XX, "MSP4450" }, 328 { TVEEPROM_AUDPROC_MSP, "MSP4450" },
339 { V4L2_IDENT_MSPX4XX, "MSP4408" }, 329 { TVEEPROM_AUDPROC_MSP, "MSP4408" },
340 /* 25-29 */ 330 /* 25-29 */
341 { V4L2_IDENT_MSPX4XX, "MSP4418" }, 331 { TVEEPROM_AUDPROC_MSP, "MSP4418" },
342 { V4L2_IDENT_MSPX4XX, "MSP4428" }, 332 { TVEEPROM_AUDPROC_MSP, "MSP4428" },
343 { V4L2_IDENT_MSPX4XX, "MSP4448" }, 333 { TVEEPROM_AUDPROC_MSP, "MSP4448" },
344 { V4L2_IDENT_MSPX4XX, "MSP4458" }, 334 { TVEEPROM_AUDPROC_MSP, "MSP4458" },
345 { V4L2_IDENT_MSPX4XX, "Type 0x1d" }, 335 { TVEEPROM_AUDPROC_MSP, "Type 0x1d" },
346 /* 30-34 */ 336 /* 30-34 */
347 { V4L2_IDENT_AMBIGUOUS, "CX880" }, 337 { TVEEPROM_AUDPROC_INTERNAL, "CX880" },
348 { V4L2_IDENT_AMBIGUOUS, "CX881" }, 338 { TVEEPROM_AUDPROC_INTERNAL, "CX881" },
349 { V4L2_IDENT_AMBIGUOUS, "CX883" }, 339 { TVEEPROM_AUDPROC_INTERNAL, "CX883" },
350 { V4L2_IDENT_AMBIGUOUS, "CX882" }, 340 { TVEEPROM_AUDPROC_INTERNAL, "CX882" },
351 { V4L2_IDENT_AMBIGUOUS, "CX25840" }, 341 { TVEEPROM_AUDPROC_INTERNAL, "CX25840" },
352 /* 35-39 */ 342 /* 35-39 */
353 { V4L2_IDENT_AMBIGUOUS, "CX25841" }, 343 { TVEEPROM_AUDPROC_INTERNAL, "CX25841" },
354 { V4L2_IDENT_AMBIGUOUS, "CX25842" }, 344 { TVEEPROM_AUDPROC_INTERNAL, "CX25842" },
355 { V4L2_IDENT_AMBIGUOUS, "CX25843" }, 345 { TVEEPROM_AUDPROC_INTERNAL, "CX25843" },
356 { V4L2_IDENT_AMBIGUOUS, "CX23418" }, 346 { TVEEPROM_AUDPROC_INTERNAL, "CX23418" },
357 { V4L2_IDENT_AMBIGUOUS, "CX23885" }, 347 { TVEEPROM_AUDPROC_INTERNAL, "CX23885" },
358 /* 40-44 */ 348 /* 40-44 */
359 { V4L2_IDENT_AMBIGUOUS, "CX23888" }, 349 { TVEEPROM_AUDPROC_INTERNAL, "CX23888" },
360 { V4L2_IDENT_AMBIGUOUS, "SAA7131" }, 350 { TVEEPROM_AUDPROC_INTERNAL, "SAA7131" },
361 { V4L2_IDENT_AMBIGUOUS, "CX23887" }, 351 { TVEEPROM_AUDPROC_INTERNAL, "CX23887" },
362 { V4L2_IDENT_AMBIGUOUS, "SAA7164" }, 352 { TVEEPROM_AUDPROC_INTERNAL, "SAA7164" },
363 { V4L2_IDENT_AMBIGUOUS, "AU8522" }, 353 { TVEEPROM_AUDPROC_INTERNAL, "AU8522" },
364}; 354};
365 355
366/* This list is supplied by Hauppauge. Thanks! */ 356/* This list is supplied by Hauppauge. Thanks! */
@@ -453,11 +443,11 @@ void tveeprom_hauppauge_analog(struct i2c_client *c, struct tveeprom *tvee,
453 int i, j, len, done, beenhere, tag, start; 443 int i, j, len, done, beenhere, tag, start;
454 444
455 int tuner1 = 0, t_format1 = 0, audioic = -1; 445 int tuner1 = 0, t_format1 = 0, audioic = -1;
456 char *t_name1 = NULL; 446 const char *t_name1 = NULL;
457 const char *t_fmt_name1[8] = { " none", "", "", "", "", "", "", "" }; 447 const char *t_fmt_name1[8] = { " none", "", "", "", "", "", "", "" };
458 448
459 int tuner2 = 0, t_format2 = 0; 449 int tuner2 = 0, t_format2 = 0;
460 char *t_name2 = NULL; 450 const char *t_name2 = NULL;
461 const char *t_fmt_name2[8] = { " none", "", "", "", "", "", "", "" }; 451 const char *t_fmt_name2[8] = { " none", "", "", "", "", "", "", "" };
462 452
463 memset(tvee, 0, sizeof(*tvee)); 453 memset(tvee, 0, sizeof(*tvee));
@@ -545,10 +535,10 @@ void tveeprom_hauppauge_analog(struct i2c_client *c, struct tveeprom *tvee,
545 to indicate 4052 mux was removed in favor of using MSP 535 to indicate 4052 mux was removed in favor of using MSP
546 inputs directly. */ 536 inputs directly. */
547 audioic = eeprom_data[i+2] & 0x7f; 537 audioic = eeprom_data[i+2] & 0x7f;
548 if (audioic < ARRAY_SIZE(audioIC)) 538 if (audioic < ARRAY_SIZE(audio_ic))
549 tvee->audio_processor = audioIC[audioic].id; 539 tvee->audio_processor = audio_ic[audioic].id;
550 else 540 else
551 tvee->audio_processor = V4L2_IDENT_UNKNOWN; 541 tvee->audio_processor = TVEEPROM_AUDPROC_OTHER;
552 break; 542 break;
553 543
554 /* case 0x03: tag 'EEInfo' */ 544 /* case 0x03: tag 'EEInfo' */
@@ -578,10 +568,10 @@ void tveeprom_hauppauge_analog(struct i2c_client *c, struct tveeprom *tvee,
578 to indicate 4052 mux was removed in favor of using MSP 568 to indicate 4052 mux was removed in favor of using MSP
579 inputs directly. */ 569 inputs directly. */
580 audioic = eeprom_data[i+1] & 0x7f; 570 audioic = eeprom_data[i+1] & 0x7f;
581 if (audioic < ARRAY_SIZE(audioIC)) 571 if (audioic < ARRAY_SIZE(audio_ic))
582 tvee->audio_processor = audioIC[audioic].id; 572 tvee->audio_processor = audio_ic[audioic].id;
583 else 573 else
584 tvee->audio_processor = V4L2_IDENT_UNKNOWN; 574 tvee->audio_processor = TVEEPROM_AUDPROC_OTHER;
585 575
586 break; 576 break;
587 577
@@ -726,11 +716,11 @@ void tveeprom_hauppauge_analog(struct i2c_client *c, struct tveeprom *tvee,
726 t_fmt_name2[6], t_fmt_name2[7], t_format2); 716 t_fmt_name2[6], t_fmt_name2[7], t_format2);
727 if (audioic < 0) { 717 if (audioic < 0) {
728 tveeprom_info("audio processor is unknown (no idx)\n"); 718 tveeprom_info("audio processor is unknown (no idx)\n");
729 tvee->audio_processor = V4L2_IDENT_UNKNOWN; 719 tvee->audio_processor = TVEEPROM_AUDPROC_OTHER;
730 } else { 720 } else {
731 if (audioic < ARRAY_SIZE(audioIC)) 721 if (audioic < ARRAY_SIZE(audio_ic))
732 tveeprom_info("audio processor is %s (idx %d)\n", 722 tveeprom_info("audio processor is %s (idx %d)\n",
733 audioIC[audioic].name, audioic); 723 audio_ic[audioic].name, audioic);
734 else 724 else
735 tveeprom_info("audio processor is unknown (idx %d)\n", 725 tveeprom_info("audio processor is unknown (idx %d)\n",
736 audioic); 726 audioic);
diff --git a/drivers/media/dvb-core/dmxdev.c b/drivers/media/dvb-core/dmxdev.c
index a1a3a5159d71..0b4616b87195 100644
--- a/drivers/media/dvb-core/dmxdev.c
+++ b/drivers/media/dvb-core/dmxdev.c
@@ -377,10 +377,8 @@ static int dvb_dmxdev_section_callback(const u8 *buffer1, size_t buffer1_len,
377 ret = dvb_dmxdev_buffer_write(&dmxdevfilter->buffer, buffer2, 377 ret = dvb_dmxdev_buffer_write(&dmxdevfilter->buffer, buffer2,
378 buffer2_len); 378 buffer2_len);
379 } 379 }
380 if (ret < 0) { 380 if (ret < 0)
381 dvb_ringbuffer_flush(&dmxdevfilter->buffer);
382 dmxdevfilter->buffer.error = ret; 381 dmxdevfilter->buffer.error = ret;
383 }
384 if (dmxdevfilter->params.sec.flags & DMX_ONESHOT) 382 if (dmxdevfilter->params.sec.flags & DMX_ONESHOT)
385 dmxdevfilter->state = DMXDEV_STATE_DONE; 383 dmxdevfilter->state = DMXDEV_STATE_DONE;
386 spin_unlock(&dmxdevfilter->dev->lock); 384 spin_unlock(&dmxdevfilter->dev->lock);
@@ -416,10 +414,8 @@ static int dvb_dmxdev_ts_callback(const u8 *buffer1, size_t buffer1_len,
416 ret = dvb_dmxdev_buffer_write(buffer, buffer1, buffer1_len); 414 ret = dvb_dmxdev_buffer_write(buffer, buffer1, buffer1_len);
417 if (ret == buffer1_len) 415 if (ret == buffer1_len)
418 ret = dvb_dmxdev_buffer_write(buffer, buffer2, buffer2_len); 416 ret = dvb_dmxdev_buffer_write(buffer, buffer2, buffer2_len);
419 if (ret < 0) { 417 if (ret < 0)
420 dvb_ringbuffer_flush(buffer);
421 buffer->error = ret; 418 buffer->error = ret;
422 }
423 spin_unlock(&dmxdevfilter->dev->lock); 419 spin_unlock(&dmxdevfilter->dev->lock);
424 wake_up(&buffer->queue); 420 wake_up(&buffer->queue);
425 return 0; 421 return 0;
diff --git a/drivers/media/dvb-core/dvb-usb-ids.h b/drivers/media/dvb-core/dvb-usb-ids.h
index 335a8f4695b4..886da16e14f2 100644
--- a/drivers/media/dvb-core/dvb-usb-ids.h
+++ b/drivers/media/dvb-core/dvb-usb-ids.h
@@ -367,4 +367,6 @@
367#define USB_PID_TECHNISAT_USB2_HDCI_V2 0x0002 367#define USB_PID_TECHNISAT_USB2_HDCI_V2 0x0002
368#define USB_PID_TECHNISAT_AIRSTAR_TELESTICK_2 0x0004 368#define USB_PID_TECHNISAT_AIRSTAR_TELESTICK_2 0x0004
369#define USB_PID_TECHNISAT_USB2_DVB_S2 0x0500 369#define USB_PID_TECHNISAT_USB2_DVB_S2 0x0500
370#define USB_PID_CPYTO_REDI_PC50A 0xa803
371#define USB_PID_CTVDIGDUAL_V2 0xe410
370#endif 372#endif
diff --git a/drivers/media/dvb-frontends/au8522_decoder.c b/drivers/media/dvb-frontends/au8522_decoder.c
index 2099f21e374d..23a0d05ba426 100644
--- a/drivers/media/dvb-frontends/au8522_decoder.c
+++ b/drivers/media/dvb-frontends/au8522_decoder.c
@@ -35,7 +35,6 @@
35#include <linux/i2c.h> 35#include <linux/i2c.h>
36#include <linux/delay.h> 36#include <linux/delay.h>
37#include <media/v4l2-common.h> 37#include <media/v4l2-common.h>
38#include <media/v4l2-chip-ident.h>
39#include <media/v4l2-device.h> 38#include <media/v4l2-device.h>
40#include "au8522.h" 39#include "au8522.h"
41#include "au8522_priv.h" 40#include "au8522_priv.h"
@@ -524,13 +523,8 @@ static int au8522_s_ctrl(struct v4l2_ctrl *ctrl)
524static int au8522_g_register(struct v4l2_subdev *sd, 523static int au8522_g_register(struct v4l2_subdev *sd,
525 struct v4l2_dbg_register *reg) 524 struct v4l2_dbg_register *reg)
526{ 525{
527 struct i2c_client *client = v4l2_get_subdevdata(sd);
528 struct au8522_state *state = to_state(sd); 526 struct au8522_state *state = to_state(sd);
529 527
530 if (!v4l2_chip_match_i2c_client(client, &reg->match))
531 return -EINVAL;
532 if (!capable(CAP_SYS_ADMIN))
533 return -EPERM;
534 reg->val = au8522_readreg(state, reg->reg & 0xffff); 528 reg->val = au8522_readreg(state, reg->reg & 0xffff);
535 return 0; 529 return 0;
536} 530}
@@ -538,13 +532,8 @@ static int au8522_g_register(struct v4l2_subdev *sd,
538static int au8522_s_register(struct v4l2_subdev *sd, 532static int au8522_s_register(struct v4l2_subdev *sd,
539 const struct v4l2_dbg_register *reg) 533 const struct v4l2_dbg_register *reg)
540{ 534{
541 struct i2c_client *client = v4l2_get_subdevdata(sd);
542 struct au8522_state *state = to_state(sd); 535 struct au8522_state *state = to_state(sd);
543 536
544 if (!v4l2_chip_match_i2c_client(client, &reg->match))
545 return -EINVAL;
546 if (!capable(CAP_SYS_ADMIN))
547 return -EPERM;
548 au8522_writereg(state, reg->reg, reg->val & 0xff); 537 au8522_writereg(state, reg->reg, reg->val & 0xff);
549 return 0; 538 return 0;
550} 539}
@@ -636,20 +625,10 @@ static int au8522_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
636 return 0; 625 return 0;
637} 626}
638 627
639static int au8522_g_chip_ident(struct v4l2_subdev *sd,
640 struct v4l2_dbg_chip_ident *chip)
641{
642 struct au8522_state *state = to_state(sd);
643 struct i2c_client *client = v4l2_get_subdevdata(sd);
644
645 return v4l2_chip_ident_i2c_client(client, chip, state->id, state->rev);
646}
647
648/* ----------------------------------------------------------------------- */ 628/* ----------------------------------------------------------------------- */
649 629
650static const struct v4l2_subdev_core_ops au8522_core_ops = { 630static const struct v4l2_subdev_core_ops au8522_core_ops = {
651 .log_status = v4l2_ctrl_subdev_log_status, 631 .log_status = v4l2_ctrl_subdev_log_status,
652 .g_chip_ident = au8522_g_chip_ident,
653 .reset = au8522_reset, 632 .reset = au8522_reset,
654#ifdef CONFIG_VIDEO_ADV_DEBUG 633#ifdef CONFIG_VIDEO_ADV_DEBUG
655 .g_register = au8522_g_register, 634 .g_register = au8522_g_register,
diff --git a/drivers/media/dvb-frontends/dib8000.c b/drivers/media/dvb-frontends/dib8000.c
index a54182dd0e91..90536147bf04 100644
--- a/drivers/media/dvb-frontends/dib8000.c
+++ b/drivers/media/dvb-frontends/dib8000.c
@@ -3406,7 +3406,7 @@ static int dib8000_set_frontend(struct dvb_frontend *fe)
3406{ 3406{
3407 struct dib8000_state *state = fe->demodulator_priv; 3407 struct dib8000_state *state = fe->demodulator_priv;
3408 struct dtv_frontend_properties *c = &state->fe[0]->dtv_property_cache; 3408 struct dtv_frontend_properties *c = &state->fe[0]->dtv_property_cache;
3409 int l, i, active, time, ret, time_slave = FE_CALLBACK_TIME_NEVER; 3409 int l, i, active, time, time_slave = FE_CALLBACK_TIME_NEVER;
3410 u8 exit_condition, index_frontend; 3410 u8 exit_condition, index_frontend;
3411 u32 delay, callback_time; 3411 u32 delay, callback_time;
3412 3412
@@ -3553,7 +3553,7 @@ static int dib8000_set_frontend(struct dvb_frontend *fe)
3553 } 3553 }
3554 } 3554 }
3555 3555
3556 return ret; 3556 return 0;
3557} 3557}
3558 3558
3559static int dib8000_read_status(struct dvb_frontend *fe, fe_status_t * stat) 3559static int dib8000_read_status(struct dvb_frontend *fe, fe_status_t * stat)
diff --git a/drivers/media/dvb-frontends/drxk.h b/drivers/media/dvb-frontends/drxk.h
index e6667189ddce..f22eb9f13ad5 100644
--- a/drivers/media/dvb-frontends/drxk.h
+++ b/drivers/media/dvb-frontends/drxk.h
@@ -8,7 +8,7 @@
8/** 8/**
9 * struct drxk_config - Configure the initial parameters for DRX-K 9 * struct drxk_config - Configure the initial parameters for DRX-K
10 * 10 *
11 * @adr: I2C Address of the DRX-K 11 * @adr: I2C address of the DRX-K
12 * @parallel_ts: True means that the device uses parallel TS, 12 * @parallel_ts: True means that the device uses parallel TS,
13 * Serial otherwise. 13 * Serial otherwise.
14 * @dynamic_clk: True means that the clock will be dynamically 14 * @dynamic_clk: True means that the clock will be dynamically
diff --git a/drivers/media/dvb-frontends/drxk_hard.c b/drivers/media/dvb-frontends/drxk_hard.c
index ec24d71e153d..082014de6875 100644
--- a/drivers/media/dvb-frontends/drxk_hard.c
+++ b/drivers/media/dvb-frontends/drxk_hard.c
@@ -21,6 +21,8 @@
21 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html 21 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
22 */ 22 */
23 23
24#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
25
24#include <linux/kernel.h> 26#include <linux/kernel.h>
25#include <linux/module.h> 27#include <linux/module.h>
26#include <linux/moduleparam.h> 28#include <linux/moduleparam.h>
@@ -34,35 +36,36 @@
34#include "dvb_frontend.h" 36#include "dvb_frontend.h"
35#include "drxk.h" 37#include "drxk.h"
36#include "drxk_hard.h" 38#include "drxk_hard.h"
37 39#include "dvb_math.h"
38static int PowerDownDVBT(struct drxk_state *state, bool setPowerMode); 40
39static int PowerDownQAM(struct drxk_state *state); 41static int power_down_dvbt(struct drxk_state *state, bool set_power_mode);
40static int SetDVBTStandard(struct drxk_state *state, 42static int power_down_qam(struct drxk_state *state);
41 enum OperationMode oMode); 43static int set_dvbt_standard(struct drxk_state *state,
42static int SetQAMStandard(struct drxk_state *state, 44 enum operation_mode o_mode);
43 enum OperationMode oMode); 45static int set_qam_standard(struct drxk_state *state,
44static int SetQAM(struct drxk_state *state, u16 IntermediateFreqkHz, 46 enum operation_mode o_mode);
45 s32 tunerFreqOffset); 47static int set_qam(struct drxk_state *state, u16 intermediate_freqk_hz,
46static int SetDVBTStandard(struct drxk_state *state, 48 s32 tuner_freq_offset);
47 enum OperationMode oMode); 49static int set_dvbt_standard(struct drxk_state *state,
48static int DVBTStart(struct drxk_state *state); 50 enum operation_mode o_mode);
49static int SetDVBT(struct drxk_state *state, u16 IntermediateFreqkHz, 51static int dvbt_start(struct drxk_state *state);
50 s32 tunerFreqOffset); 52static int set_dvbt(struct drxk_state *state, u16 intermediate_freqk_hz,
51static int GetQAMLockStatus(struct drxk_state *state, u32 *pLockStatus); 53 s32 tuner_freq_offset);
52static int GetDVBTLockStatus(struct drxk_state *state, u32 *pLockStatus); 54static int get_qam_lock_status(struct drxk_state *state, u32 *p_lock_status);
53static int SwitchAntennaToQAM(struct drxk_state *state); 55static int get_dvbt_lock_status(struct drxk_state *state, u32 *p_lock_status);
54static int SwitchAntennaToDVBT(struct drxk_state *state); 56static int switch_antenna_to_qam(struct drxk_state *state);
55 57static int switch_antenna_to_dvbt(struct drxk_state *state);
56static bool IsDVBT(struct drxk_state *state) 58
59static bool is_dvbt(struct drxk_state *state)
57{ 60{
58 return state->m_OperationMode == OM_DVBT; 61 return state->m_operation_mode == OM_DVBT;
59} 62}
60 63
61static bool IsQAM(struct drxk_state *state) 64static bool is_qam(struct drxk_state *state)
62{ 65{
63 return state->m_OperationMode == OM_QAM_ITU_A || 66 return state->m_operation_mode == OM_QAM_ITU_A ||
64 state->m_OperationMode == OM_QAM_ITU_B || 67 state->m_operation_mode == OM_QAM_ITU_B ||
65 state->m_OperationMode == OM_QAM_ITU_C; 68 state->m_operation_mode == OM_QAM_ITU_C;
66} 69}
67 70
68#define NOA1ROM 0 71#define NOA1ROM 0
@@ -165,7 +168,7 @@ MODULE_PARM_DESC(debug, "enable debug messages");
165 168
166#define dprintk(level, fmt, arg...) do { \ 169#define dprintk(level, fmt, arg...) do { \
167if (debug >= level) \ 170if (debug >= level) \
168 printk(KERN_DEBUG "drxk: %s" fmt, __func__, ## arg); \ 171 pr_debug(fmt, ##arg); \
169} while (0) 172} while (0)
170 173
171 174
@@ -186,8 +189,10 @@ static inline u32 Frac28a(u32 a, u32 c)
186 u32 R0 = 0; 189 u32 R0 = 0;
187 190
188 R0 = (a % c) << 4; /* 32-28 == 4 shifts possible at max */ 191 R0 = (a % c) << 4; /* 32-28 == 4 shifts possible at max */
189 Q1 = a / c; /* integer part, only the 4 least significant bits 192 Q1 = a / c; /*
190 will be visible in the result */ 193 * integer part, only the 4 least significant
194 * bits will be visible in the result
195 */
191 196
192 /* division using radix 16, 7 nibbles in the result */ 197 /* division using radix 16, 7 nibbles in the result */
193 for (i = 0; i < 7; i++) { 198 for (i = 0; i < 7; i++) {
@@ -201,98 +206,9 @@ static inline u32 Frac28a(u32 a, u32 c)
201 return Q1; 206 return Q1;
202} 207}
203 208
204static u32 Log10Times100(u32 x) 209static inline u32 log10times100(u32 value)
205{ 210{
206 static const u8 scale = 15; 211 return (100L * intlog10(value)) >> 24;
207 static const u8 indexWidth = 5;
208 u8 i = 0;
209 u32 y = 0;
210 u32 d = 0;
211 u32 k = 0;
212 u32 r = 0;
213 /*
214 log2lut[n] = (1<<scale) * 200 * log2(1.0 + ((1.0/(1<<INDEXWIDTH)) * n))
215 0 <= n < ((1<<INDEXWIDTH)+1)
216 */
217
218 static const u32 log2lut[] = {
219 0, /* 0.000000 */
220 290941, /* 290941.300628 */
221 573196, /* 573196.476418 */
222 847269, /* 847269.179851 */
223 1113620, /* 1113620.489452 */
224 1372674, /* 1372673.576986 */
225 1624818, /* 1624817.752104 */
226 1870412, /* 1870411.981536 */
227 2109788, /* 2109787.962654 */
228 2343253, /* 2343252.817465 */
229 2571091, /* 2571091.461923 */
230 2793569, /* 2793568.696416 */
231 3010931, /* 3010931.055901 */
232 3223408, /* 3223408.452106 */
233 3431216, /* 3431215.635215 */
234 3634553, /* 3634553.498355 */
235 3833610, /* 3833610.244726 */
236 4028562, /* 4028562.434393 */
237 4219576, /* 4219575.925308 */
238 4406807, /* 4406806.721144 */
239 4590402, /* 4590401.736809 */
240 4770499, /* 4770499.491025 */
241 4947231, /* 4947230.734179 */
242 5120719, /* 5120719.018555 */
243 5291081, /* 5291081.217197 */
244 5458428, /* 5458427.996830 */
245 5622864, /* 5622864.249668 */
246 5784489, /* 5784489.488298 */
247 5943398, /* 5943398.207380 */
248 6099680, /* 6099680.215452 */
249 6253421, /* 6253420.939751 */
250 6404702, /* 6404701.706649 */
251 6553600, /* 6553600.000000 */
252 };
253
254
255 if (x == 0)
256 return 0;
257
258 /* Scale x (normalize) */
259 /* computing y in log(x/y) = log(x) - log(y) */
260 if ((x & ((0xffffffff) << (scale + 1))) == 0) {
261 for (k = scale; k > 0; k--) {
262 if (x & (((u32) 1) << scale))
263 break;
264 x <<= 1;
265 }
266 } else {
267 for (k = scale; k < 31; k++) {
268 if ((x & (((u32) (-1)) << (scale + 1))) == 0)
269 break;
270 x >>= 1;
271 }
272 }
273 /*
274 Now x has binary point between bit[scale] and bit[scale-1]
275 and 1.0 <= x < 2.0 */
276
277 /* correction for divison: log(x) = log(x/y)+log(y) */
278 y = k * ((((u32) 1) << scale) * 200);
279
280 /* remove integer part */
281 x &= ((((u32) 1) << scale) - 1);
282 /* get index */
283 i = (u8) (x >> (scale - indexWidth));
284 /* compute delta (x - a) */
285 d = x & ((((u32) 1) << (scale - indexWidth)) - 1);
286 /* compute log, multiplication (d* (..)) must be within range ! */
287 y += log2lut[i] +
288 ((d * (log2lut[i + 1] - log2lut[i])) >> (scale - indexWidth));
289 /* Conver to log10() */
290 y /= 108853; /* (log2(10) << scale) */
291 r = (y >> 1);
292 /* rounding */
293 if (y & ((u32) 1))
294 r++;
295 return r;
296} 212}
297 213
298/****************************************************************************/ 214/****************************************************************************/
@@ -344,15 +260,15 @@ static int i2c_write(struct drxk_state *state, u8 adr, u8 *data, int len)
344 if (debug > 2) { 260 if (debug > 2) {
345 int i; 261 int i;
346 for (i = 0; i < len; i++) 262 for (i = 0; i < len; i++)
347 printk(KERN_CONT " %02x", data[i]); 263 pr_cont(" %02x", data[i]);
348 printk(KERN_CONT "\n"); 264 pr_cont("\n");
349 } 265 }
350 status = drxk_i2c_transfer(state, &msg, 1); 266 status = drxk_i2c_transfer(state, &msg, 1);
351 if (status >= 0 && status != 1) 267 if (status >= 0 && status != 1)
352 status = -EIO; 268 status = -EIO;
353 269
354 if (status < 0) 270 if (status < 0)
355 printk(KERN_ERR "drxk: i2c write error at addr 0x%02x\n", adr); 271 pr_err("i2c write error at addr 0x%02x\n", adr);
356 272
357 return status; 273 return status;
358} 274}
@@ -371,22 +287,22 @@ static int i2c_read(struct drxk_state *state,
371 status = drxk_i2c_transfer(state, msgs, 2); 287 status = drxk_i2c_transfer(state, msgs, 2);
372 if (status != 2) { 288 if (status != 2) {
373 if (debug > 2) 289 if (debug > 2)
374 printk(KERN_CONT ": ERROR!\n"); 290 pr_cont(": ERROR!\n");
375 if (status >= 0) 291 if (status >= 0)
376 status = -EIO; 292 status = -EIO;
377 293
378 printk(KERN_ERR "drxk: i2c read error at addr 0x%02x\n", adr); 294 pr_err("i2c read error at addr 0x%02x\n", adr);
379 return status; 295 return status;
380 } 296 }
381 if (debug > 2) { 297 if (debug > 2) {
382 int i; 298 int i;
383 dprintk(2, ": read from"); 299 dprintk(2, ": read from");
384 for (i = 0; i < len; i++) 300 for (i = 0; i < len; i++)
385 printk(KERN_CONT " %02x", msg[i]); 301 pr_cont(" %02x", msg[i]);
386 printk(KERN_CONT ", value = "); 302 pr_cont(", value = ");
387 for (i = 0; i < alen; i++) 303 for (i = 0; i < alen; i++)
388 printk(KERN_CONT " %02x", answ[i]); 304 pr_cont(" %02x", answ[i]);
389 printk(KERN_CONT "\n"); 305 pr_cont("\n");
390 } 306 }
391 return 0; 307 return 0;
392} 308}
@@ -520,55 +436,55 @@ static int write32(struct drxk_state *state, u32 reg, u32 data)
520 return write32_flags(state, reg, data, 0); 436 return write32_flags(state, reg, data, 0);
521} 437}
522 438
523static int write_block(struct drxk_state *state, u32 Address, 439static int write_block(struct drxk_state *state, u32 address,
524 const int BlockSize, const u8 pBlock[]) 440 const int block_size, const u8 p_block[])
525{ 441{
526 int status = 0, BlkSize = BlockSize; 442 int status = 0, blk_size = block_size;
527 u8 Flags = 0; 443 u8 flags = 0;
528 444
529 if (state->single_master) 445 if (state->single_master)
530 Flags |= 0xC0; 446 flags |= 0xC0;
531 447
532 while (BlkSize > 0) { 448 while (blk_size > 0) {
533 int Chunk = BlkSize > state->m_ChunkSize ? 449 int chunk = blk_size > state->m_chunk_size ?
534 state->m_ChunkSize : BlkSize; 450 state->m_chunk_size : blk_size;
535 u8 *AdrBuf = &state->Chunk[0]; 451 u8 *adr_buf = &state->chunk[0];
536 u32 AdrLength = 0; 452 u32 adr_length = 0;
537 453
538 if (DRXDAP_FASI_LONG_FORMAT(Address) || (Flags != 0)) { 454 if (DRXDAP_FASI_LONG_FORMAT(address) || (flags != 0)) {
539 AdrBuf[0] = (((Address << 1) & 0xFF) | 0x01); 455 adr_buf[0] = (((address << 1) & 0xFF) | 0x01);
540 AdrBuf[1] = ((Address >> 16) & 0xFF); 456 adr_buf[1] = ((address >> 16) & 0xFF);
541 AdrBuf[2] = ((Address >> 24) & 0xFF); 457 adr_buf[2] = ((address >> 24) & 0xFF);
542 AdrBuf[3] = ((Address >> 7) & 0xFF); 458 adr_buf[3] = ((address >> 7) & 0xFF);
543 AdrBuf[2] |= Flags; 459 adr_buf[2] |= flags;
544 AdrLength = 4; 460 adr_length = 4;
545 if (Chunk == state->m_ChunkSize) 461 if (chunk == state->m_chunk_size)
546 Chunk -= 2; 462 chunk -= 2;
547 } else { 463 } else {
548 AdrBuf[0] = ((Address << 1) & 0xFF); 464 adr_buf[0] = ((address << 1) & 0xFF);
549 AdrBuf[1] = (((Address >> 16) & 0x0F) | 465 adr_buf[1] = (((address >> 16) & 0x0F) |
550 ((Address >> 18) & 0xF0)); 466 ((address >> 18) & 0xF0));
551 AdrLength = 2; 467 adr_length = 2;
552 } 468 }
553 memcpy(&state->Chunk[AdrLength], pBlock, Chunk); 469 memcpy(&state->chunk[adr_length], p_block, chunk);
554 dprintk(2, "(0x%08x, 0x%02x)\n", Address, Flags); 470 dprintk(2, "(0x%08x, 0x%02x)\n", address, flags);
555 if (debug > 1) { 471 if (debug > 1) {
556 int i; 472 int i;
557 if (pBlock) 473 if (p_block)
558 for (i = 0; i < Chunk; i++) 474 for (i = 0; i < chunk; i++)
559 printk(KERN_CONT " %02x", pBlock[i]); 475 pr_cont(" %02x", p_block[i]);
560 printk(KERN_CONT "\n"); 476 pr_cont("\n");
561 } 477 }
562 status = i2c_write(state, state->demod_address, 478 status = i2c_write(state, state->demod_address,
563 &state->Chunk[0], Chunk + AdrLength); 479 &state->chunk[0], chunk + adr_length);
564 if (status < 0) { 480 if (status < 0) {
565 printk(KERN_ERR "drxk: %s: i2c write error at addr 0x%02x\n", 481 pr_err("%s: i2c write error at addr 0x%02x\n",
566 __func__, Address); 482 __func__, address);
567 break; 483 break;
568 } 484 }
569 pBlock += Chunk; 485 p_block += chunk;
570 Address += (Chunk >> 1); 486 address += (chunk >> 1);
571 BlkSize -= Chunk; 487 blk_size -= chunk;
572 } 488 }
573 return status; 489 return status;
574} 490}
@@ -577,11 +493,11 @@ static int write_block(struct drxk_state *state, u32 Address,
577#define DRXK_MAX_RETRIES_POWERUP 20 493#define DRXK_MAX_RETRIES_POWERUP 20
578#endif 494#endif
579 495
580static int PowerUpDevice(struct drxk_state *state) 496static int power_up_device(struct drxk_state *state)
581{ 497{
582 int status; 498 int status;
583 u8 data = 0; 499 u8 data = 0;
584 u16 retryCount = 0; 500 u16 retry_count = 0;
585 501
586 dprintk(1, "\n"); 502 dprintk(1, "\n");
587 503
@@ -591,15 +507,15 @@ static int PowerUpDevice(struct drxk_state *state)
591 data = 0; 507 data = 0;
592 status = i2c_write(state, state->demod_address, 508 status = i2c_write(state, state->demod_address,
593 &data, 1); 509 &data, 1);
594 msleep(10); 510 usleep_range(10000, 11000);
595 retryCount++; 511 retry_count++;
596 if (status < 0) 512 if (status < 0)
597 continue; 513 continue;
598 status = i2c_read1(state, state->demod_address, 514 status = i2c_read1(state, state->demod_address,
599 &data); 515 &data);
600 } while (status < 0 && 516 } while (status < 0 &&
601 (retryCount < DRXK_MAX_RETRIES_POWERUP)); 517 (retry_count < DRXK_MAX_RETRIES_POWERUP));
602 if (status < 0 && retryCount >= DRXK_MAX_RETRIES_POWERUP) 518 if (status < 0 && retry_count >= DRXK_MAX_RETRIES_POWERUP)
603 goto error; 519 goto error;
604 } 520 }
605 521
@@ -615,11 +531,11 @@ static int PowerUpDevice(struct drxk_state *state)
615 if (status < 0) 531 if (status < 0)
616 goto error; 532 goto error;
617 533
618 state->m_currentPowerMode = DRX_POWER_UP; 534 state->m_current_power_mode = DRX_POWER_UP;
619 535
620error: 536error:
621 if (status < 0) 537 if (status < 0)
622 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 538 pr_err("Error %d on %s\n", status, __func__);
623 539
624 return status; 540 return status;
625} 541}
@@ -631,106 +547,106 @@ static int init_state(struct drxk_state *state)
631 * FIXME: most (all?) of the values bellow should be moved into 547 * FIXME: most (all?) of the values bellow should be moved into
632 * struct drxk_config, as they are probably board-specific 548 * struct drxk_config, as they are probably board-specific
633 */ 549 */
634 u32 ulVSBIfAgcMode = DRXK_AGC_CTRL_AUTO; 550 u32 ul_vsb_if_agc_mode = DRXK_AGC_CTRL_AUTO;
635 u32 ulVSBIfAgcOutputLevel = 0; 551 u32 ul_vsb_if_agc_output_level = 0;
636 u32 ulVSBIfAgcMinLevel = 0; 552 u32 ul_vsb_if_agc_min_level = 0;
637 u32 ulVSBIfAgcMaxLevel = 0x7FFF; 553 u32 ul_vsb_if_agc_max_level = 0x7FFF;
638 u32 ulVSBIfAgcSpeed = 3; 554 u32 ul_vsb_if_agc_speed = 3;
639 555
640 u32 ulVSBRfAgcMode = DRXK_AGC_CTRL_AUTO; 556 u32 ul_vsb_rf_agc_mode = DRXK_AGC_CTRL_AUTO;
641 u32 ulVSBRfAgcOutputLevel = 0; 557 u32 ul_vsb_rf_agc_output_level = 0;
642 u32 ulVSBRfAgcMinLevel = 0; 558 u32 ul_vsb_rf_agc_min_level = 0;
643 u32 ulVSBRfAgcMaxLevel = 0x7FFF; 559 u32 ul_vsb_rf_agc_max_level = 0x7FFF;
644 u32 ulVSBRfAgcSpeed = 3; 560 u32 ul_vsb_rf_agc_speed = 3;
645 u32 ulVSBRfAgcTop = 9500; 561 u32 ul_vsb_rf_agc_top = 9500;
646 u32 ulVSBRfAgcCutOffCurrent = 4000; 562 u32 ul_vsb_rf_agc_cut_off_current = 4000;
647 563
648 u32 ulATVIfAgcMode = DRXK_AGC_CTRL_AUTO; 564 u32 ul_atv_if_agc_mode = DRXK_AGC_CTRL_AUTO;
649 u32 ulATVIfAgcOutputLevel = 0; 565 u32 ul_atv_if_agc_output_level = 0;
650 u32 ulATVIfAgcMinLevel = 0; 566 u32 ul_atv_if_agc_min_level = 0;
651 u32 ulATVIfAgcMaxLevel = 0; 567 u32 ul_atv_if_agc_max_level = 0;
652 u32 ulATVIfAgcSpeed = 3; 568 u32 ul_atv_if_agc_speed = 3;
653 569
654 u32 ulATVRfAgcMode = DRXK_AGC_CTRL_OFF; 570 u32 ul_atv_rf_agc_mode = DRXK_AGC_CTRL_OFF;
655 u32 ulATVRfAgcOutputLevel = 0; 571 u32 ul_atv_rf_agc_output_level = 0;
656 u32 ulATVRfAgcMinLevel = 0; 572 u32 ul_atv_rf_agc_min_level = 0;
657 u32 ulATVRfAgcMaxLevel = 0; 573 u32 ul_atv_rf_agc_max_level = 0;
658 u32 ulATVRfAgcTop = 9500; 574 u32 ul_atv_rf_agc_top = 9500;
659 u32 ulATVRfAgcCutOffCurrent = 4000; 575 u32 ul_atv_rf_agc_cut_off_current = 4000;
660 u32 ulATVRfAgcSpeed = 3; 576 u32 ul_atv_rf_agc_speed = 3;
661 577
662 u32 ulQual83 = DEFAULT_MER_83; 578 u32 ulQual83 = DEFAULT_MER_83;
663 u32 ulQual93 = DEFAULT_MER_93; 579 u32 ulQual93 = DEFAULT_MER_93;
664 580
665 u32 ulMpegLockTimeOut = DEFAULT_DRXK_MPEG_LOCK_TIMEOUT; 581 u32 ul_mpeg_lock_time_out = DEFAULT_DRXK_MPEG_LOCK_TIMEOUT;
666 u32 ulDemodLockTimeOut = DEFAULT_DRXK_DEMOD_LOCK_TIMEOUT; 582 u32 ul_demod_lock_time_out = DEFAULT_DRXK_DEMOD_LOCK_TIMEOUT;
667 583
668 /* io_pad_cfg register (8 bit reg.) MSB bit is 1 (default value) */ 584 /* io_pad_cfg register (8 bit reg.) MSB bit is 1 (default value) */
669 /* io_pad_cfg_mode output mode is drive always */ 585 /* io_pad_cfg_mode output mode is drive always */
670 /* io_pad_cfg_drive is set to power 2 (23 mA) */ 586 /* io_pad_cfg_drive is set to power 2 (23 mA) */
671 u32 ulGPIOCfg = 0x0113; 587 u32 ul_gpio_cfg = 0x0113;
672 u32 ulInvertTSClock = 0; 588 u32 ul_invert_ts_clock = 0;
673 u32 ulTSDataStrength = DRXK_MPEG_SERIAL_OUTPUT_PIN_DRIVE_STRENGTH; 589 u32 ul_ts_data_strength = DRXK_MPEG_SERIAL_OUTPUT_PIN_DRIVE_STRENGTH;
674 u32 ulDVBTBitrate = 50000000; 590 u32 ul_dvbt_bitrate = 50000000;
675 u32 ulDVBCBitrate = DRXK_QAM_SYMBOLRATE_MAX * 8; 591 u32 ul_dvbc_bitrate = DRXK_QAM_SYMBOLRATE_MAX * 8;
676 592
677 u32 ulInsertRSByte = 0; 593 u32 ul_insert_rs_byte = 0;
678 594
679 u32 ulRfMirror = 1; 595 u32 ul_rf_mirror = 1;
680 u32 ulPowerDown = 0; 596 u32 ul_power_down = 0;
681 597
682 dprintk(1, "\n"); 598 dprintk(1, "\n");
683 599
684 state->m_hasLNA = false; 600 state->m_has_lna = false;
685 state->m_hasDVBT = false; 601 state->m_has_dvbt = false;
686 state->m_hasDVBC = false; 602 state->m_has_dvbc = false;
687 state->m_hasATV = false; 603 state->m_has_atv = false;
688 state->m_hasOOB = false; 604 state->m_has_oob = false;
689 state->m_hasAudio = false; 605 state->m_has_audio = false;
690 606
691 if (!state->m_ChunkSize) 607 if (!state->m_chunk_size)
692 state->m_ChunkSize = 124; 608 state->m_chunk_size = 124;
693 609
694 state->m_oscClockFreq = 0; 610 state->m_osc_clock_freq = 0;
695 state->m_smartAntInverted = false; 611 state->m_smart_ant_inverted = false;
696 state->m_bPDownOpenBridge = false; 612 state->m_b_p_down_open_bridge = false;
697 613
698 /* real system clock frequency in kHz */ 614 /* real system clock frequency in kHz */
699 state->m_sysClockFreq = 151875; 615 state->m_sys_clock_freq = 151875;
700 /* Timing div, 250ns/Psys */ 616 /* Timing div, 250ns/Psys */
701 /* Timing div, = (delay (nano seconds) * sysclk (kHz))/ 1000 */ 617 /* Timing div, = (delay (nano seconds) * sysclk (kHz))/ 1000 */
702 state->m_HICfgTimingDiv = ((state->m_sysClockFreq / 1000) * 618 state->m_hi_cfg_timing_div = ((state->m_sys_clock_freq / 1000) *
703 HI_I2C_DELAY) / 1000; 619 HI_I2C_DELAY) / 1000;
704 /* Clipping */ 620 /* Clipping */
705 if (state->m_HICfgTimingDiv > SIO_HI_RA_RAM_PAR_2_CFG_DIV__M) 621 if (state->m_hi_cfg_timing_div > SIO_HI_RA_RAM_PAR_2_CFG_DIV__M)
706 state->m_HICfgTimingDiv = SIO_HI_RA_RAM_PAR_2_CFG_DIV__M; 622 state->m_hi_cfg_timing_div = SIO_HI_RA_RAM_PAR_2_CFG_DIV__M;
707 state->m_HICfgWakeUpKey = (state->demod_address << 1); 623 state->m_hi_cfg_wake_up_key = (state->demod_address << 1);
708 /* port/bridge/power down ctrl */ 624 /* port/bridge/power down ctrl */
709 state->m_HICfgCtrl = SIO_HI_RA_RAM_PAR_5_CFG_SLV0_SLAVE; 625 state->m_hi_cfg_ctrl = SIO_HI_RA_RAM_PAR_5_CFG_SLV0_SLAVE;
710 626
711 state->m_bPowerDown = (ulPowerDown != 0); 627 state->m_b_power_down = (ul_power_down != 0);
712 628
713 state->m_DRXK_A3_PATCH_CODE = false; 629 state->m_drxk_a3_patch_code = false;
714 630
715 /* Init AGC and PGA parameters */ 631 /* Init AGC and PGA parameters */
716 /* VSB IF */ 632 /* VSB IF */
717 state->m_vsbIfAgcCfg.ctrlMode = (ulVSBIfAgcMode); 633 state->m_vsb_if_agc_cfg.ctrl_mode = ul_vsb_if_agc_mode;
718 state->m_vsbIfAgcCfg.outputLevel = (ulVSBIfAgcOutputLevel); 634 state->m_vsb_if_agc_cfg.output_level = ul_vsb_if_agc_output_level;
719 state->m_vsbIfAgcCfg.minOutputLevel = (ulVSBIfAgcMinLevel); 635 state->m_vsb_if_agc_cfg.min_output_level = ul_vsb_if_agc_min_level;
720 state->m_vsbIfAgcCfg.maxOutputLevel = (ulVSBIfAgcMaxLevel); 636 state->m_vsb_if_agc_cfg.max_output_level = ul_vsb_if_agc_max_level;
721 state->m_vsbIfAgcCfg.speed = (ulVSBIfAgcSpeed); 637 state->m_vsb_if_agc_cfg.speed = ul_vsb_if_agc_speed;
722 state->m_vsbPgaCfg = 140; 638 state->m_vsb_pga_cfg = 140;
723 639
724 /* VSB RF */ 640 /* VSB RF */
725 state->m_vsbRfAgcCfg.ctrlMode = (ulVSBRfAgcMode); 641 state->m_vsb_rf_agc_cfg.ctrl_mode = ul_vsb_rf_agc_mode;
726 state->m_vsbRfAgcCfg.outputLevel = (ulVSBRfAgcOutputLevel); 642 state->m_vsb_rf_agc_cfg.output_level = ul_vsb_rf_agc_output_level;
727 state->m_vsbRfAgcCfg.minOutputLevel = (ulVSBRfAgcMinLevel); 643 state->m_vsb_rf_agc_cfg.min_output_level = ul_vsb_rf_agc_min_level;
728 state->m_vsbRfAgcCfg.maxOutputLevel = (ulVSBRfAgcMaxLevel); 644 state->m_vsb_rf_agc_cfg.max_output_level = ul_vsb_rf_agc_max_level;
729 state->m_vsbRfAgcCfg.speed = (ulVSBRfAgcSpeed); 645 state->m_vsb_rf_agc_cfg.speed = ul_vsb_rf_agc_speed;
730 state->m_vsbRfAgcCfg.top = (ulVSBRfAgcTop); 646 state->m_vsb_rf_agc_cfg.top = ul_vsb_rf_agc_top;
731 state->m_vsbRfAgcCfg.cutOffCurrent = (ulVSBRfAgcCutOffCurrent); 647 state->m_vsb_rf_agc_cfg.cut_off_current = ul_vsb_rf_agc_cut_off_current;
732 state->m_vsbPreSawCfg.reference = 0x07; 648 state->m_vsb_pre_saw_cfg.reference = 0x07;
733 state->m_vsbPreSawCfg.usePreSaw = true; 649 state->m_vsb_pre_saw_cfg.use_pre_saw = true;
734 650
735 state->m_Quality83percent = DEFAULT_MER_83; 651 state->m_Quality83percent = DEFAULT_MER_83;
736 state->m_Quality93percent = DEFAULT_MER_93; 652 state->m_Quality93percent = DEFAULT_MER_93;
@@ -740,127 +656,127 @@ static int init_state(struct drxk_state *state)
740 } 656 }
741 657
742 /* ATV IF */ 658 /* ATV IF */
743 state->m_atvIfAgcCfg.ctrlMode = (ulATVIfAgcMode); 659 state->m_atv_if_agc_cfg.ctrl_mode = ul_atv_if_agc_mode;
744 state->m_atvIfAgcCfg.outputLevel = (ulATVIfAgcOutputLevel); 660 state->m_atv_if_agc_cfg.output_level = ul_atv_if_agc_output_level;
745 state->m_atvIfAgcCfg.minOutputLevel = (ulATVIfAgcMinLevel); 661 state->m_atv_if_agc_cfg.min_output_level = ul_atv_if_agc_min_level;
746 state->m_atvIfAgcCfg.maxOutputLevel = (ulATVIfAgcMaxLevel); 662 state->m_atv_if_agc_cfg.max_output_level = ul_atv_if_agc_max_level;
747 state->m_atvIfAgcCfg.speed = (ulATVIfAgcSpeed); 663 state->m_atv_if_agc_cfg.speed = ul_atv_if_agc_speed;
748 664
749 /* ATV RF */ 665 /* ATV RF */
750 state->m_atvRfAgcCfg.ctrlMode = (ulATVRfAgcMode); 666 state->m_atv_rf_agc_cfg.ctrl_mode = ul_atv_rf_agc_mode;
751 state->m_atvRfAgcCfg.outputLevel = (ulATVRfAgcOutputLevel); 667 state->m_atv_rf_agc_cfg.output_level = ul_atv_rf_agc_output_level;
752 state->m_atvRfAgcCfg.minOutputLevel = (ulATVRfAgcMinLevel); 668 state->m_atv_rf_agc_cfg.min_output_level = ul_atv_rf_agc_min_level;
753 state->m_atvRfAgcCfg.maxOutputLevel = (ulATVRfAgcMaxLevel); 669 state->m_atv_rf_agc_cfg.max_output_level = ul_atv_rf_agc_max_level;
754 state->m_atvRfAgcCfg.speed = (ulATVRfAgcSpeed); 670 state->m_atv_rf_agc_cfg.speed = ul_atv_rf_agc_speed;
755 state->m_atvRfAgcCfg.top = (ulATVRfAgcTop); 671 state->m_atv_rf_agc_cfg.top = ul_atv_rf_agc_top;
756 state->m_atvRfAgcCfg.cutOffCurrent = (ulATVRfAgcCutOffCurrent); 672 state->m_atv_rf_agc_cfg.cut_off_current = ul_atv_rf_agc_cut_off_current;
757 state->m_atvPreSawCfg.reference = 0x04; 673 state->m_atv_pre_saw_cfg.reference = 0x04;
758 state->m_atvPreSawCfg.usePreSaw = true; 674 state->m_atv_pre_saw_cfg.use_pre_saw = true;
759 675
760 676
761 /* DVBT RF */ 677 /* DVBT RF */
762 state->m_dvbtRfAgcCfg.ctrlMode = DRXK_AGC_CTRL_OFF; 678 state->m_dvbt_rf_agc_cfg.ctrl_mode = DRXK_AGC_CTRL_OFF;
763 state->m_dvbtRfAgcCfg.outputLevel = 0; 679 state->m_dvbt_rf_agc_cfg.output_level = 0;
764 state->m_dvbtRfAgcCfg.minOutputLevel = 0; 680 state->m_dvbt_rf_agc_cfg.min_output_level = 0;
765 state->m_dvbtRfAgcCfg.maxOutputLevel = 0xFFFF; 681 state->m_dvbt_rf_agc_cfg.max_output_level = 0xFFFF;
766 state->m_dvbtRfAgcCfg.top = 0x2100; 682 state->m_dvbt_rf_agc_cfg.top = 0x2100;
767 state->m_dvbtRfAgcCfg.cutOffCurrent = 4000; 683 state->m_dvbt_rf_agc_cfg.cut_off_current = 4000;
768 state->m_dvbtRfAgcCfg.speed = 1; 684 state->m_dvbt_rf_agc_cfg.speed = 1;
769 685
770 686
771 /* DVBT IF */ 687 /* DVBT IF */
772 state->m_dvbtIfAgcCfg.ctrlMode = DRXK_AGC_CTRL_AUTO; 688 state->m_dvbt_if_agc_cfg.ctrl_mode = DRXK_AGC_CTRL_AUTO;
773 state->m_dvbtIfAgcCfg.outputLevel = 0; 689 state->m_dvbt_if_agc_cfg.output_level = 0;
774 state->m_dvbtIfAgcCfg.minOutputLevel = 0; 690 state->m_dvbt_if_agc_cfg.min_output_level = 0;
775 state->m_dvbtIfAgcCfg.maxOutputLevel = 9000; 691 state->m_dvbt_if_agc_cfg.max_output_level = 9000;
776 state->m_dvbtIfAgcCfg.top = 13424; 692 state->m_dvbt_if_agc_cfg.top = 13424;
777 state->m_dvbtIfAgcCfg.cutOffCurrent = 0; 693 state->m_dvbt_if_agc_cfg.cut_off_current = 0;
778 state->m_dvbtIfAgcCfg.speed = 3; 694 state->m_dvbt_if_agc_cfg.speed = 3;
779 state->m_dvbtIfAgcCfg.FastClipCtrlDelay = 30; 695 state->m_dvbt_if_agc_cfg.fast_clip_ctrl_delay = 30;
780 state->m_dvbtIfAgcCfg.IngainTgtMax = 30000; 696 state->m_dvbt_if_agc_cfg.ingain_tgt_max = 30000;
781 /* state->m_dvbtPgaCfg = 140; */ 697 /* state->m_dvbtPgaCfg = 140; */
782 698
783 state->m_dvbtPreSawCfg.reference = 4; 699 state->m_dvbt_pre_saw_cfg.reference = 4;
784 state->m_dvbtPreSawCfg.usePreSaw = false; 700 state->m_dvbt_pre_saw_cfg.use_pre_saw = false;
785 701
786 /* QAM RF */ 702 /* QAM RF */
787 state->m_qamRfAgcCfg.ctrlMode = DRXK_AGC_CTRL_OFF; 703 state->m_qam_rf_agc_cfg.ctrl_mode = DRXK_AGC_CTRL_OFF;
788 state->m_qamRfAgcCfg.outputLevel = 0; 704 state->m_qam_rf_agc_cfg.output_level = 0;
789 state->m_qamRfAgcCfg.minOutputLevel = 6023; 705 state->m_qam_rf_agc_cfg.min_output_level = 6023;
790 state->m_qamRfAgcCfg.maxOutputLevel = 27000; 706 state->m_qam_rf_agc_cfg.max_output_level = 27000;
791 state->m_qamRfAgcCfg.top = 0x2380; 707 state->m_qam_rf_agc_cfg.top = 0x2380;
792 state->m_qamRfAgcCfg.cutOffCurrent = 4000; 708 state->m_qam_rf_agc_cfg.cut_off_current = 4000;
793 state->m_qamRfAgcCfg.speed = 3; 709 state->m_qam_rf_agc_cfg.speed = 3;
794 710
795 /* QAM IF */ 711 /* QAM IF */
796 state->m_qamIfAgcCfg.ctrlMode = DRXK_AGC_CTRL_AUTO; 712 state->m_qam_if_agc_cfg.ctrl_mode = DRXK_AGC_CTRL_AUTO;
797 state->m_qamIfAgcCfg.outputLevel = 0; 713 state->m_qam_if_agc_cfg.output_level = 0;
798 state->m_qamIfAgcCfg.minOutputLevel = 0; 714 state->m_qam_if_agc_cfg.min_output_level = 0;
799 state->m_qamIfAgcCfg.maxOutputLevel = 9000; 715 state->m_qam_if_agc_cfg.max_output_level = 9000;
800 state->m_qamIfAgcCfg.top = 0x0511; 716 state->m_qam_if_agc_cfg.top = 0x0511;
801 state->m_qamIfAgcCfg.cutOffCurrent = 0; 717 state->m_qam_if_agc_cfg.cut_off_current = 0;
802 state->m_qamIfAgcCfg.speed = 3; 718 state->m_qam_if_agc_cfg.speed = 3;
803 state->m_qamIfAgcCfg.IngainTgtMax = 5119; 719 state->m_qam_if_agc_cfg.ingain_tgt_max = 5119;
804 state->m_qamIfAgcCfg.FastClipCtrlDelay = 50; 720 state->m_qam_if_agc_cfg.fast_clip_ctrl_delay = 50;
805 721
806 state->m_qamPgaCfg = 140; 722 state->m_qam_pga_cfg = 140;
807 state->m_qamPreSawCfg.reference = 4; 723 state->m_qam_pre_saw_cfg.reference = 4;
808 state->m_qamPreSawCfg.usePreSaw = false; 724 state->m_qam_pre_saw_cfg.use_pre_saw = false;
809 725
810 state->m_OperationMode = OM_NONE; 726 state->m_operation_mode = OM_NONE;
811 state->m_DrxkState = DRXK_UNINITIALIZED; 727 state->m_drxk_state = DRXK_UNINITIALIZED;
812 728
813 /* MPEG output configuration */ 729 /* MPEG output configuration */
814 state->m_enableMPEGOutput = true; /* If TRUE; enable MPEG ouput */ 730 state->m_enable_mpeg_output = true; /* If TRUE; enable MPEG ouput */
815 state->m_insertRSByte = false; /* If TRUE; insert RS byte */ 731 state->m_insert_rs_byte = false; /* If TRUE; insert RS byte */
816 state->m_invertDATA = false; /* If TRUE; invert DATA signals */ 732 state->m_invert_data = false; /* If TRUE; invert DATA signals */
817 state->m_invertERR = false; /* If TRUE; invert ERR signal */ 733 state->m_invert_err = false; /* If TRUE; invert ERR signal */
818 state->m_invertSTR = false; /* If TRUE; invert STR signals */ 734 state->m_invert_str = false; /* If TRUE; invert STR signals */
819 state->m_invertVAL = false; /* If TRUE; invert VAL signals */ 735 state->m_invert_val = false; /* If TRUE; invert VAL signals */
820 state->m_invertCLK = (ulInvertTSClock != 0); /* If TRUE; invert CLK signals */ 736 state->m_invert_clk = (ul_invert_ts_clock != 0); /* If TRUE; invert CLK signals */
821 737
822 /* If TRUE; static MPEG clockrate will be used; 738 /* If TRUE; static MPEG clockrate will be used;
823 otherwise clockrate will adapt to the bitrate of the TS */ 739 otherwise clockrate will adapt to the bitrate of the TS */
824 740
825 state->m_DVBTBitrate = ulDVBTBitrate; 741 state->m_dvbt_bitrate = ul_dvbt_bitrate;
826 state->m_DVBCBitrate = ulDVBCBitrate; 742 state->m_dvbc_bitrate = ul_dvbc_bitrate;
827 743
828 state->m_TSDataStrength = (ulTSDataStrength & 0x07); 744 state->m_ts_data_strength = (ul_ts_data_strength & 0x07);
829 745
830 /* Maximum bitrate in b/s in case static clockrate is selected */ 746 /* Maximum bitrate in b/s in case static clockrate is selected */
831 state->m_mpegTsStaticBitrate = 19392658; 747 state->m_mpeg_ts_static_bitrate = 19392658;
832 state->m_disableTEIhandling = false; 748 state->m_disable_te_ihandling = false;
833 749
834 if (ulInsertRSByte) 750 if (ul_insert_rs_byte)
835 state->m_insertRSByte = true; 751 state->m_insert_rs_byte = true;
836 752
837 state->m_MpegLockTimeOut = DEFAULT_DRXK_MPEG_LOCK_TIMEOUT; 753 state->m_mpeg_lock_time_out = DEFAULT_DRXK_MPEG_LOCK_TIMEOUT;
838 if (ulMpegLockTimeOut < 10000) 754 if (ul_mpeg_lock_time_out < 10000)
839 state->m_MpegLockTimeOut = ulMpegLockTimeOut; 755 state->m_mpeg_lock_time_out = ul_mpeg_lock_time_out;
840 state->m_DemodLockTimeOut = DEFAULT_DRXK_DEMOD_LOCK_TIMEOUT; 756 state->m_demod_lock_time_out = DEFAULT_DRXK_DEMOD_LOCK_TIMEOUT;
841 if (ulDemodLockTimeOut < 10000) 757 if (ul_demod_lock_time_out < 10000)
842 state->m_DemodLockTimeOut = ulDemodLockTimeOut; 758 state->m_demod_lock_time_out = ul_demod_lock_time_out;
843 759
844 /* QAM defaults */ 760 /* QAM defaults */
845 state->m_Constellation = DRX_CONSTELLATION_AUTO; 761 state->m_constellation = DRX_CONSTELLATION_AUTO;
846 state->m_qamInterleaveMode = DRXK_QAM_I12_J17; 762 state->m_qam_interleave_mode = DRXK_QAM_I12_J17;
847 state->m_fecRsPlen = 204 * 8; /* fecRsPlen annex A */ 763 state->m_fec_rs_plen = 204 * 8; /* fecRsPlen annex A */
848 state->m_fecRsPrescale = 1; 764 state->m_fec_rs_prescale = 1;
849 765
850 state->m_sqiSpeed = DRXK_DVBT_SQI_SPEED_MEDIUM; 766 state->m_sqi_speed = DRXK_DVBT_SQI_SPEED_MEDIUM;
851 state->m_agcFastClipCtrlDelay = 0; 767 state->m_agcfast_clip_ctrl_delay = 0;
852 768
853 state->m_GPIOCfg = (ulGPIOCfg); 769 state->m_gpio_cfg = ul_gpio_cfg;
854 770
855 state->m_bPowerDown = false; 771 state->m_b_power_down = false;
856 state->m_currentPowerMode = DRX_POWER_DOWN; 772 state->m_current_power_mode = DRX_POWER_DOWN;
857 773
858 state->m_rfmirror = (ulRfMirror == 0); 774 state->m_rfmirror = (ul_rf_mirror == 0);
859 state->m_IfAgcPol = false; 775 state->m_if_agc_pol = false;
860 return 0; 776 return 0;
861} 777}
862 778
863static int DRXX_Open(struct drxk_state *state) 779static int drxx_open(struct drxk_state *state)
864{ 780{
865 int status = 0; 781 int status = 0;
866 u32 jtag = 0; 782 u32 jtag = 0;
@@ -869,7 +785,8 @@ static int DRXX_Open(struct drxk_state *state)
869 785
870 dprintk(1, "\n"); 786 dprintk(1, "\n");
871 /* stop lock indicator process */ 787 /* stop lock indicator process */
872 status = write16(state, SCU_RAM_GPIO__A, SCU_RAM_GPIO_HW_LOCK_IND_DISABLE); 788 status = write16(state, SCU_RAM_GPIO__A,
789 SCU_RAM_GPIO_HW_LOCK_IND_DISABLE);
873 if (status < 0) 790 if (status < 0)
874 goto error; 791 goto error;
875 /* Check device id */ 792 /* Check device id */
@@ -888,14 +805,14 @@ static int DRXX_Open(struct drxk_state *state)
888 status = write16(state, SIO_TOP_COMM_KEY__A, key); 805 status = write16(state, SIO_TOP_COMM_KEY__A, key);
889error: 806error:
890 if (status < 0) 807 if (status < 0)
891 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 808 pr_err("Error %d on %s\n", status, __func__);
892 return status; 809 return status;
893} 810}
894 811
895static int GetDeviceCapabilities(struct drxk_state *state) 812static int get_device_capabilities(struct drxk_state *state)
896{ 813{
897 u16 sioPdrOhwCfg = 0; 814 u16 sio_pdr_ohw_cfg = 0;
898 u32 sioTopJtagidLo = 0; 815 u32 sio_top_jtagid_lo = 0;
899 int status; 816 int status;
900 const char *spin = ""; 817 const char *spin = "";
901 818
@@ -903,197 +820,196 @@ static int GetDeviceCapabilities(struct drxk_state *state)
903 820
904 /* driver 0.9.0 */ 821 /* driver 0.9.0 */
905 /* stop lock indicator process */ 822 /* stop lock indicator process */
906 status = write16(state, SCU_RAM_GPIO__A, SCU_RAM_GPIO_HW_LOCK_IND_DISABLE); 823 status = write16(state, SCU_RAM_GPIO__A,
824 SCU_RAM_GPIO_HW_LOCK_IND_DISABLE);
907 if (status < 0) 825 if (status < 0)
908 goto error; 826 goto error;
909 status = write16(state, SIO_TOP_COMM_KEY__A, SIO_TOP_COMM_KEY_KEY); 827 status = write16(state, SIO_TOP_COMM_KEY__A, SIO_TOP_COMM_KEY_KEY);
910 if (status < 0) 828 if (status < 0)
911 goto error; 829 goto error;
912 status = read16(state, SIO_PDR_OHW_CFG__A, &sioPdrOhwCfg); 830 status = read16(state, SIO_PDR_OHW_CFG__A, &sio_pdr_ohw_cfg);
913 if (status < 0) 831 if (status < 0)
914 goto error; 832 goto error;
915 status = write16(state, SIO_TOP_COMM_KEY__A, 0x0000); 833 status = write16(state, SIO_TOP_COMM_KEY__A, 0x0000);
916 if (status < 0) 834 if (status < 0)
917 goto error; 835 goto error;
918 836
919 switch ((sioPdrOhwCfg & SIO_PDR_OHW_CFG_FREF_SEL__M)) { 837 switch ((sio_pdr_ohw_cfg & SIO_PDR_OHW_CFG_FREF_SEL__M)) {
920 case 0: 838 case 0:
921 /* ignore (bypass ?) */ 839 /* ignore (bypass ?) */
922 break; 840 break;
923 case 1: 841 case 1:
924 /* 27 MHz */ 842 /* 27 MHz */
925 state->m_oscClockFreq = 27000; 843 state->m_osc_clock_freq = 27000;
926 break; 844 break;
927 case 2: 845 case 2:
928 /* 20.25 MHz */ 846 /* 20.25 MHz */
929 state->m_oscClockFreq = 20250; 847 state->m_osc_clock_freq = 20250;
930 break; 848 break;
931 case 3: 849 case 3:
932 /* 4 MHz */ 850 /* 4 MHz */
933 state->m_oscClockFreq = 20250; 851 state->m_osc_clock_freq = 20250;
934 break; 852 break;
935 default: 853 default:
936 printk(KERN_ERR "drxk: Clock Frequency is unknown\n"); 854 pr_err("Clock Frequency is unknown\n");
937 return -EINVAL; 855 return -EINVAL;
938 } 856 }
939 /* 857 /*
940 Determine device capabilities 858 Determine device capabilities
941 Based on pinning v14 859 Based on pinning v14
942 */ 860 */
943 status = read32(state, SIO_TOP_JTAGID_LO__A, &sioTopJtagidLo); 861 status = read32(state, SIO_TOP_JTAGID_LO__A, &sio_top_jtagid_lo);
944 if (status < 0) 862 if (status < 0)
945 goto error; 863 goto error;
946 864
947 printk(KERN_INFO "drxk: status = 0x%08x\n", sioTopJtagidLo); 865 pr_info("status = 0x%08x\n", sio_top_jtagid_lo);
948 866
949 /* driver 0.9.0 */ 867 /* driver 0.9.0 */
950 switch ((sioTopJtagidLo >> 29) & 0xF) { 868 switch ((sio_top_jtagid_lo >> 29) & 0xF) {
951 case 0: 869 case 0:
952 state->m_deviceSpin = DRXK_SPIN_A1; 870 state->m_device_spin = DRXK_SPIN_A1;
953 spin = "A1"; 871 spin = "A1";
954 break; 872 break;
955 case 2: 873 case 2:
956 state->m_deviceSpin = DRXK_SPIN_A2; 874 state->m_device_spin = DRXK_SPIN_A2;
957 spin = "A2"; 875 spin = "A2";
958 break; 876 break;
959 case 3: 877 case 3:
960 state->m_deviceSpin = DRXK_SPIN_A3; 878 state->m_device_spin = DRXK_SPIN_A3;
961 spin = "A3"; 879 spin = "A3";
962 break; 880 break;
963 default: 881 default:
964 state->m_deviceSpin = DRXK_SPIN_UNKNOWN; 882 state->m_device_spin = DRXK_SPIN_UNKNOWN;
965 status = -EINVAL; 883 status = -EINVAL;
966 printk(KERN_ERR "drxk: Spin %d unknown\n", 884 pr_err("Spin %d unknown\n", (sio_top_jtagid_lo >> 29) & 0xF);
967 (sioTopJtagidLo >> 29) & 0xF);
968 goto error2; 885 goto error2;
969 } 886 }
970 switch ((sioTopJtagidLo >> 12) & 0xFF) { 887 switch ((sio_top_jtagid_lo >> 12) & 0xFF) {
971 case 0x13: 888 case 0x13:
972 /* typeId = DRX3913K_TYPE_ID */ 889 /* typeId = DRX3913K_TYPE_ID */
973 state->m_hasLNA = false; 890 state->m_has_lna = false;
974 state->m_hasOOB = false; 891 state->m_has_oob = false;
975 state->m_hasATV = false; 892 state->m_has_atv = false;
976 state->m_hasAudio = false; 893 state->m_has_audio = false;
977 state->m_hasDVBT = true; 894 state->m_has_dvbt = true;
978 state->m_hasDVBC = true; 895 state->m_has_dvbc = true;
979 state->m_hasSAWSW = true; 896 state->m_has_sawsw = true;
980 state->m_hasGPIO2 = false; 897 state->m_has_gpio2 = false;
981 state->m_hasGPIO1 = false; 898 state->m_has_gpio1 = false;
982 state->m_hasIRQN = false; 899 state->m_has_irqn = false;
983 break; 900 break;
984 case 0x15: 901 case 0x15:
985 /* typeId = DRX3915K_TYPE_ID */ 902 /* typeId = DRX3915K_TYPE_ID */
986 state->m_hasLNA = false; 903 state->m_has_lna = false;
987 state->m_hasOOB = false; 904 state->m_has_oob = false;
988 state->m_hasATV = true; 905 state->m_has_atv = true;
989 state->m_hasAudio = false; 906 state->m_has_audio = false;
990 state->m_hasDVBT = true; 907 state->m_has_dvbt = true;
991 state->m_hasDVBC = false; 908 state->m_has_dvbc = false;
992 state->m_hasSAWSW = true; 909 state->m_has_sawsw = true;
993 state->m_hasGPIO2 = true; 910 state->m_has_gpio2 = true;
994 state->m_hasGPIO1 = true; 911 state->m_has_gpio1 = true;
995 state->m_hasIRQN = false; 912 state->m_has_irqn = false;
996 break; 913 break;
997 case 0x16: 914 case 0x16:
998 /* typeId = DRX3916K_TYPE_ID */ 915 /* typeId = DRX3916K_TYPE_ID */
999 state->m_hasLNA = false; 916 state->m_has_lna = false;
1000 state->m_hasOOB = false; 917 state->m_has_oob = false;
1001 state->m_hasATV = true; 918 state->m_has_atv = true;
1002 state->m_hasAudio = false; 919 state->m_has_audio = false;
1003 state->m_hasDVBT = true; 920 state->m_has_dvbt = true;
1004 state->m_hasDVBC = false; 921 state->m_has_dvbc = false;
1005 state->m_hasSAWSW = true; 922 state->m_has_sawsw = true;
1006 state->m_hasGPIO2 = true; 923 state->m_has_gpio2 = true;
1007 state->m_hasGPIO1 = true; 924 state->m_has_gpio1 = true;
1008 state->m_hasIRQN = false; 925 state->m_has_irqn = false;
1009 break; 926 break;
1010 case 0x18: 927 case 0x18:
1011 /* typeId = DRX3918K_TYPE_ID */ 928 /* typeId = DRX3918K_TYPE_ID */
1012 state->m_hasLNA = false; 929 state->m_has_lna = false;
1013 state->m_hasOOB = false; 930 state->m_has_oob = false;
1014 state->m_hasATV = true; 931 state->m_has_atv = true;
1015 state->m_hasAudio = true; 932 state->m_has_audio = true;
1016 state->m_hasDVBT = true; 933 state->m_has_dvbt = true;
1017 state->m_hasDVBC = false; 934 state->m_has_dvbc = false;
1018 state->m_hasSAWSW = true; 935 state->m_has_sawsw = true;
1019 state->m_hasGPIO2 = true; 936 state->m_has_gpio2 = true;
1020 state->m_hasGPIO1 = true; 937 state->m_has_gpio1 = true;
1021 state->m_hasIRQN = false; 938 state->m_has_irqn = false;
1022 break; 939 break;
1023 case 0x21: 940 case 0x21:
1024 /* typeId = DRX3921K_TYPE_ID */ 941 /* typeId = DRX3921K_TYPE_ID */
1025 state->m_hasLNA = false; 942 state->m_has_lna = false;
1026 state->m_hasOOB = false; 943 state->m_has_oob = false;
1027 state->m_hasATV = true; 944 state->m_has_atv = true;
1028 state->m_hasAudio = true; 945 state->m_has_audio = true;
1029 state->m_hasDVBT = true; 946 state->m_has_dvbt = true;
1030 state->m_hasDVBC = true; 947 state->m_has_dvbc = true;
1031 state->m_hasSAWSW = true; 948 state->m_has_sawsw = true;
1032 state->m_hasGPIO2 = true; 949 state->m_has_gpio2 = true;
1033 state->m_hasGPIO1 = true; 950 state->m_has_gpio1 = true;
1034 state->m_hasIRQN = false; 951 state->m_has_irqn = false;
1035 break; 952 break;
1036 case 0x23: 953 case 0x23:
1037 /* typeId = DRX3923K_TYPE_ID */ 954 /* typeId = DRX3923K_TYPE_ID */
1038 state->m_hasLNA = false; 955 state->m_has_lna = false;
1039 state->m_hasOOB = false; 956 state->m_has_oob = false;
1040 state->m_hasATV = true; 957 state->m_has_atv = true;
1041 state->m_hasAudio = true; 958 state->m_has_audio = true;
1042 state->m_hasDVBT = true; 959 state->m_has_dvbt = true;
1043 state->m_hasDVBC = true; 960 state->m_has_dvbc = true;
1044 state->m_hasSAWSW = true; 961 state->m_has_sawsw = true;
1045 state->m_hasGPIO2 = true; 962 state->m_has_gpio2 = true;
1046 state->m_hasGPIO1 = true; 963 state->m_has_gpio1 = true;
1047 state->m_hasIRQN = false; 964 state->m_has_irqn = false;
1048 break; 965 break;
1049 case 0x25: 966 case 0x25:
1050 /* typeId = DRX3925K_TYPE_ID */ 967 /* typeId = DRX3925K_TYPE_ID */
1051 state->m_hasLNA = false; 968 state->m_has_lna = false;
1052 state->m_hasOOB = false; 969 state->m_has_oob = false;
1053 state->m_hasATV = true; 970 state->m_has_atv = true;
1054 state->m_hasAudio = true; 971 state->m_has_audio = true;
1055 state->m_hasDVBT = true; 972 state->m_has_dvbt = true;
1056 state->m_hasDVBC = true; 973 state->m_has_dvbc = true;
1057 state->m_hasSAWSW = true; 974 state->m_has_sawsw = true;
1058 state->m_hasGPIO2 = true; 975 state->m_has_gpio2 = true;
1059 state->m_hasGPIO1 = true; 976 state->m_has_gpio1 = true;
1060 state->m_hasIRQN = false; 977 state->m_has_irqn = false;
1061 break; 978 break;
1062 case 0x26: 979 case 0x26:
1063 /* typeId = DRX3926K_TYPE_ID */ 980 /* typeId = DRX3926K_TYPE_ID */
1064 state->m_hasLNA = false; 981 state->m_has_lna = false;
1065 state->m_hasOOB = false; 982 state->m_has_oob = false;
1066 state->m_hasATV = true; 983 state->m_has_atv = true;
1067 state->m_hasAudio = false; 984 state->m_has_audio = false;
1068 state->m_hasDVBT = true; 985 state->m_has_dvbt = true;
1069 state->m_hasDVBC = true; 986 state->m_has_dvbc = true;
1070 state->m_hasSAWSW = true; 987 state->m_has_sawsw = true;
1071 state->m_hasGPIO2 = true; 988 state->m_has_gpio2 = true;
1072 state->m_hasGPIO1 = true; 989 state->m_has_gpio1 = true;
1073 state->m_hasIRQN = false; 990 state->m_has_irqn = false;
1074 break; 991 break;
1075 default: 992 default:
1076 printk(KERN_ERR "drxk: DeviceID 0x%02x not supported\n", 993 pr_err("DeviceID 0x%02x not supported\n",
1077 ((sioTopJtagidLo >> 12) & 0xFF)); 994 ((sio_top_jtagid_lo >> 12) & 0xFF));
1078 status = -EINVAL; 995 status = -EINVAL;
1079 goto error2; 996 goto error2;
1080 } 997 }
1081 998
1082 printk(KERN_INFO 999 pr_info("detected a drx-39%02xk, spin %s, xtal %d.%03d MHz\n",
1083 "drxk: detected a drx-39%02xk, spin %s, xtal %d.%03d MHz\n", 1000 ((sio_top_jtagid_lo >> 12) & 0xFF), spin,
1084 ((sioTopJtagidLo >> 12) & 0xFF), spin, 1001 state->m_osc_clock_freq / 1000,
1085 state->m_oscClockFreq / 1000, 1002 state->m_osc_clock_freq % 1000);
1086 state->m_oscClockFreq % 1000);
1087 1003
1088error: 1004error:
1089 if (status < 0) 1005 if (status < 0)
1090 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 1006 pr_err("Error %d on %s\n", status, __func__);
1091 1007
1092error2: 1008error2:
1093 return status; 1009 return status;
1094} 1010}
1095 1011
1096static int HI_Command(struct drxk_state *state, u16 cmd, u16 *pResult) 1012static int hi_command(struct drxk_state *state, u16 cmd, u16 *p_result)
1097{ 1013{
1098 int status; 1014 int status;
1099 bool powerdown_cmd; 1015 bool powerdown_cmd;
@@ -1105,37 +1021,37 @@ static int HI_Command(struct drxk_state *state, u16 cmd, u16 *pResult)
1105 if (status < 0) 1021 if (status < 0)
1106 goto error; 1022 goto error;
1107 if (cmd == SIO_HI_RA_RAM_CMD_RESET) 1023 if (cmd == SIO_HI_RA_RAM_CMD_RESET)
1108 msleep(1); 1024 usleep_range(1000, 2000);
1109 1025
1110 powerdown_cmd = 1026 powerdown_cmd =
1111 (bool) ((cmd == SIO_HI_RA_RAM_CMD_CONFIG) && 1027 (bool) ((cmd == SIO_HI_RA_RAM_CMD_CONFIG) &&
1112 ((state->m_HICfgCtrl) & 1028 ((state->m_hi_cfg_ctrl) &
1113 SIO_HI_RA_RAM_PAR_5_CFG_SLEEP__M) == 1029 SIO_HI_RA_RAM_PAR_5_CFG_SLEEP__M) ==
1114 SIO_HI_RA_RAM_PAR_5_CFG_SLEEP_ZZZ); 1030 SIO_HI_RA_RAM_PAR_5_CFG_SLEEP_ZZZ);
1115 if (powerdown_cmd == false) { 1031 if (powerdown_cmd == false) {
1116 /* Wait until command rdy */ 1032 /* Wait until command rdy */
1117 u32 retryCount = 0; 1033 u32 retry_count = 0;
1118 u16 waitCmd; 1034 u16 wait_cmd;
1119 1035
1120 do { 1036 do {
1121 msleep(1); 1037 usleep_range(1000, 2000);
1122 retryCount += 1; 1038 retry_count += 1;
1123 status = read16(state, SIO_HI_RA_RAM_CMD__A, 1039 status = read16(state, SIO_HI_RA_RAM_CMD__A,
1124 &waitCmd); 1040 &wait_cmd);
1125 } while ((status < 0) && (retryCount < DRXK_MAX_RETRIES) 1041 } while ((status < 0) && (retry_count < DRXK_MAX_RETRIES)
1126 && (waitCmd != 0)); 1042 && (wait_cmd != 0));
1127 if (status < 0) 1043 if (status < 0)
1128 goto error; 1044 goto error;
1129 status = read16(state, SIO_HI_RA_RAM_RES__A, pResult); 1045 status = read16(state, SIO_HI_RA_RAM_RES__A, p_result);
1130 } 1046 }
1131error: 1047error:
1132 if (status < 0) 1048 if (status < 0)
1133 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 1049 pr_err("Error %d on %s\n", status, __func__);
1134 1050
1135 return status; 1051 return status;
1136} 1052}
1137 1053
1138static int HI_CfgCommand(struct drxk_state *state) 1054static int hi_cfg_command(struct drxk_state *state)
1139{ 1055{
1140 int status; 1056 int status;
1141 1057
@@ -1143,61 +1059,68 @@ static int HI_CfgCommand(struct drxk_state *state)
1143 1059
1144 mutex_lock(&state->mutex); 1060 mutex_lock(&state->mutex);
1145 1061
1146 status = write16(state, SIO_HI_RA_RAM_PAR_6__A, state->m_HICfgTimeout); 1062 status = write16(state, SIO_HI_RA_RAM_PAR_6__A,
1063 state->m_hi_cfg_timeout);
1147 if (status < 0) 1064 if (status < 0)
1148 goto error; 1065 goto error;
1149 status = write16(state, SIO_HI_RA_RAM_PAR_5__A, state->m_HICfgCtrl); 1066 status = write16(state, SIO_HI_RA_RAM_PAR_5__A,
1067 state->m_hi_cfg_ctrl);
1150 if (status < 0) 1068 if (status < 0)
1151 goto error; 1069 goto error;
1152 status = write16(state, SIO_HI_RA_RAM_PAR_4__A, state->m_HICfgWakeUpKey); 1070 status = write16(state, SIO_HI_RA_RAM_PAR_4__A,
1071 state->m_hi_cfg_wake_up_key);
1153 if (status < 0) 1072 if (status < 0)
1154 goto error; 1073 goto error;
1155 status = write16(state, SIO_HI_RA_RAM_PAR_3__A, state->m_HICfgBridgeDelay); 1074 status = write16(state, SIO_HI_RA_RAM_PAR_3__A,
1075 state->m_hi_cfg_bridge_delay);
1156 if (status < 0) 1076 if (status < 0)
1157 goto error; 1077 goto error;
1158 status = write16(state, SIO_HI_RA_RAM_PAR_2__A, state->m_HICfgTimingDiv); 1078 status = write16(state, SIO_HI_RA_RAM_PAR_2__A,
1079 state->m_hi_cfg_timing_div);
1159 if (status < 0) 1080 if (status < 0)
1160 goto error; 1081 goto error;
1161 status = write16(state, SIO_HI_RA_RAM_PAR_1__A, SIO_HI_RA_RAM_PAR_1_PAR1_SEC_KEY); 1082 status = write16(state, SIO_HI_RA_RAM_PAR_1__A,
1083 SIO_HI_RA_RAM_PAR_1_PAR1_SEC_KEY);
1162 if (status < 0) 1084 if (status < 0)
1163 goto error; 1085 goto error;
1164 status = HI_Command(state, SIO_HI_RA_RAM_CMD_CONFIG, 0); 1086 status = hi_command(state, SIO_HI_RA_RAM_CMD_CONFIG, 0);
1165 if (status < 0) 1087 if (status < 0)
1166 goto error; 1088 goto error;
1167 1089
1168 state->m_HICfgCtrl &= ~SIO_HI_RA_RAM_PAR_5_CFG_SLEEP_ZZZ; 1090 state->m_hi_cfg_ctrl &= ~SIO_HI_RA_RAM_PAR_5_CFG_SLEEP_ZZZ;
1169error: 1091error:
1170 mutex_unlock(&state->mutex); 1092 mutex_unlock(&state->mutex);
1171 if (status < 0) 1093 if (status < 0)
1172 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 1094 pr_err("Error %d on %s\n", status, __func__);
1173 return status; 1095 return status;
1174} 1096}
1175 1097
1176static int InitHI(struct drxk_state *state) 1098static int init_hi(struct drxk_state *state)
1177{ 1099{
1178 dprintk(1, "\n"); 1100 dprintk(1, "\n");
1179 1101
1180 state->m_HICfgWakeUpKey = (state->demod_address << 1); 1102 state->m_hi_cfg_wake_up_key = (state->demod_address << 1);
1181 state->m_HICfgTimeout = 0x96FF; 1103 state->m_hi_cfg_timeout = 0x96FF;
1182 /* port/bridge/power down ctrl */ 1104 /* port/bridge/power down ctrl */
1183 state->m_HICfgCtrl = SIO_HI_RA_RAM_PAR_5_CFG_SLV0_SLAVE; 1105 state->m_hi_cfg_ctrl = SIO_HI_RA_RAM_PAR_5_CFG_SLV0_SLAVE;
1184 1106
1185 return HI_CfgCommand(state); 1107 return hi_cfg_command(state);
1186} 1108}
1187 1109
1188static int MPEGTSConfigurePins(struct drxk_state *state, bool mpegEnable) 1110static int mpegts_configure_pins(struct drxk_state *state, bool mpeg_enable)
1189{ 1111{
1190 int status = -1; 1112 int status = -1;
1191 u16 sioPdrMclkCfg = 0; 1113 u16 sio_pdr_mclk_cfg = 0;
1192 u16 sioPdrMdxCfg = 0; 1114 u16 sio_pdr_mdx_cfg = 0;
1193 u16 err_cfg = 0; 1115 u16 err_cfg = 0;
1194 1116
1195 dprintk(1, ": mpeg %s, %s mode\n", 1117 dprintk(1, ": mpeg %s, %s mode\n",
1196 mpegEnable ? "enable" : "disable", 1118 mpeg_enable ? "enable" : "disable",
1197 state->m_enableParallel ? "parallel" : "serial"); 1119 state->m_enable_parallel ? "parallel" : "serial");
1198 1120
1199 /* stop lock indicator process */ 1121 /* stop lock indicator process */
1200 status = write16(state, SCU_RAM_GPIO__A, SCU_RAM_GPIO_HW_LOCK_IND_DISABLE); 1122 status = write16(state, SCU_RAM_GPIO__A,
1123 SCU_RAM_GPIO_HW_LOCK_IND_DISABLE);
1201 if (status < 0) 1124 if (status < 0)
1202 goto error; 1125 goto error;
1203 1126
@@ -1206,7 +1129,7 @@ static int MPEGTSConfigurePins(struct drxk_state *state, bool mpegEnable)
1206 if (status < 0) 1129 if (status < 0)
1207 goto error; 1130 goto error;
1208 1131
1209 if (mpegEnable == false) { 1132 if (mpeg_enable == false) {
1210 /* Set MPEG TS pads to inputmode */ 1133 /* Set MPEG TS pads to inputmode */
1211 status = write16(state, SIO_PDR_MSTRT_CFG__A, 0x0000); 1134 status = write16(state, SIO_PDR_MSTRT_CFG__A, 0x0000);
1212 if (status < 0) 1135 if (status < 0)
@@ -1246,19 +1169,19 @@ static int MPEGTSConfigurePins(struct drxk_state *state, bool mpegEnable)
1246 goto error; 1169 goto error;
1247 } else { 1170 } else {
1248 /* Enable MPEG output */ 1171 /* Enable MPEG output */
1249 sioPdrMdxCfg = 1172 sio_pdr_mdx_cfg =
1250 ((state->m_TSDataStrength << 1173 ((state->m_ts_data_strength <<
1251 SIO_PDR_MD0_CFG_DRIVE__B) | 0x0003); 1174 SIO_PDR_MD0_CFG_DRIVE__B) | 0x0003);
1252 sioPdrMclkCfg = ((state->m_TSClockkStrength << 1175 sio_pdr_mclk_cfg = ((state->m_ts_clockk_strength <<
1253 SIO_PDR_MCLK_CFG_DRIVE__B) | 1176 SIO_PDR_MCLK_CFG_DRIVE__B) |
1254 0x0003); 1177 0x0003);
1255 1178
1256 status = write16(state, SIO_PDR_MSTRT_CFG__A, sioPdrMdxCfg); 1179 status = write16(state, SIO_PDR_MSTRT_CFG__A, sio_pdr_mdx_cfg);
1257 if (status < 0) 1180 if (status < 0)
1258 goto error; 1181 goto error;
1259 1182
1260 if (state->enable_merr_cfg) 1183 if (state->enable_merr_cfg)
1261 err_cfg = sioPdrMdxCfg; 1184 err_cfg = sio_pdr_mdx_cfg;
1262 1185
1263 status = write16(state, SIO_PDR_MERR_CFG__A, err_cfg); 1186 status = write16(state, SIO_PDR_MERR_CFG__A, err_cfg);
1264 if (status < 0) 1187 if (status < 0)
@@ -1267,31 +1190,38 @@ static int MPEGTSConfigurePins(struct drxk_state *state, bool mpegEnable)
1267 if (status < 0) 1190 if (status < 0)
1268 goto error; 1191 goto error;
1269 1192
1270 if (state->m_enableParallel == true) { 1193 if (state->m_enable_parallel == true) {
1271 /* paralel -> enable MD1 to MD7 */ 1194 /* paralel -> enable MD1 to MD7 */
1272 status = write16(state, SIO_PDR_MD1_CFG__A, sioPdrMdxCfg); 1195 status = write16(state, SIO_PDR_MD1_CFG__A,
1196 sio_pdr_mdx_cfg);
1273 if (status < 0) 1197 if (status < 0)
1274 goto error; 1198 goto error;
1275 status = write16(state, SIO_PDR_MD2_CFG__A, sioPdrMdxCfg); 1199 status = write16(state, SIO_PDR_MD2_CFG__A,
1200 sio_pdr_mdx_cfg);
1276 if (status < 0) 1201 if (status < 0)
1277 goto error; 1202 goto error;
1278 status = write16(state, SIO_PDR_MD3_CFG__A, sioPdrMdxCfg); 1203 status = write16(state, SIO_PDR_MD3_CFG__A,
1204 sio_pdr_mdx_cfg);
1279 if (status < 0) 1205 if (status < 0)
1280 goto error; 1206 goto error;
1281 status = write16(state, SIO_PDR_MD4_CFG__A, sioPdrMdxCfg); 1207 status = write16(state, SIO_PDR_MD4_CFG__A,
1208 sio_pdr_mdx_cfg);
1282 if (status < 0) 1209 if (status < 0)
1283 goto error; 1210 goto error;
1284 status = write16(state, SIO_PDR_MD5_CFG__A, sioPdrMdxCfg); 1211 status = write16(state, SIO_PDR_MD5_CFG__A,
1212 sio_pdr_mdx_cfg);
1285 if (status < 0) 1213 if (status < 0)
1286 goto error; 1214 goto error;
1287 status = write16(state, SIO_PDR_MD6_CFG__A, sioPdrMdxCfg); 1215 status = write16(state, SIO_PDR_MD6_CFG__A,
1216 sio_pdr_mdx_cfg);
1288 if (status < 0) 1217 if (status < 0)
1289 goto error; 1218 goto error;
1290 status = write16(state, SIO_PDR_MD7_CFG__A, sioPdrMdxCfg); 1219 status = write16(state, SIO_PDR_MD7_CFG__A,
1220 sio_pdr_mdx_cfg);
1291 if (status < 0) 1221 if (status < 0)
1292 goto error; 1222 goto error;
1293 } else { 1223 } else {
1294 sioPdrMdxCfg = ((state->m_TSDataStrength << 1224 sio_pdr_mdx_cfg = ((state->m_ts_data_strength <<
1295 SIO_PDR_MD0_CFG_DRIVE__B) 1225 SIO_PDR_MD0_CFG_DRIVE__B)
1296 | 0x0003); 1226 | 0x0003);
1297 /* serial -> disable MD1 to MD7 */ 1227 /* serial -> disable MD1 to MD7 */
@@ -1317,10 +1247,10 @@ static int MPEGTSConfigurePins(struct drxk_state *state, bool mpegEnable)
1317 if (status < 0) 1247 if (status < 0)
1318 goto error; 1248 goto error;
1319 } 1249 }
1320 status = write16(state, SIO_PDR_MCLK_CFG__A, sioPdrMclkCfg); 1250 status = write16(state, SIO_PDR_MCLK_CFG__A, sio_pdr_mclk_cfg);
1321 if (status < 0) 1251 if (status < 0)
1322 goto error; 1252 goto error;
1323 status = write16(state, SIO_PDR_MD0_CFG__A, sioPdrMdxCfg); 1253 status = write16(state, SIO_PDR_MD0_CFG__A, sio_pdr_mdx_cfg);
1324 if (status < 0) 1254 if (status < 0)
1325 goto error; 1255 goto error;
1326 } 1256 }
@@ -1332,21 +1262,21 @@ static int MPEGTSConfigurePins(struct drxk_state *state, bool mpegEnable)
1332 status = write16(state, SIO_TOP_COMM_KEY__A, 0x0000); 1262 status = write16(state, SIO_TOP_COMM_KEY__A, 0x0000);
1333error: 1263error:
1334 if (status < 0) 1264 if (status < 0)
1335 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 1265 pr_err("Error %d on %s\n", status, __func__);
1336 return status; 1266 return status;
1337} 1267}
1338 1268
1339static int MPEGTSDisable(struct drxk_state *state) 1269static int mpegts_disable(struct drxk_state *state)
1340{ 1270{
1341 dprintk(1, "\n"); 1271 dprintk(1, "\n");
1342 1272
1343 return MPEGTSConfigurePins(state, false); 1273 return mpegts_configure_pins(state, false);
1344} 1274}
1345 1275
1346static int BLChainCmd(struct drxk_state *state, 1276static int bl_chain_cmd(struct drxk_state *state,
1347 u16 romOffset, u16 nrOfElements, u32 timeOut) 1277 u16 rom_offset, u16 nr_of_elements, u32 time_out)
1348{ 1278{
1349 u16 blStatus = 0; 1279 u16 bl_status = 0;
1350 int status; 1280 int status;
1351 unsigned long end; 1281 unsigned long end;
1352 1282
@@ -1355,46 +1285,46 @@ static int BLChainCmd(struct drxk_state *state,
1355 status = write16(state, SIO_BL_MODE__A, SIO_BL_MODE_CHAIN); 1285 status = write16(state, SIO_BL_MODE__A, SIO_BL_MODE_CHAIN);
1356 if (status < 0) 1286 if (status < 0)
1357 goto error; 1287 goto error;
1358 status = write16(state, SIO_BL_CHAIN_ADDR__A, romOffset); 1288 status = write16(state, SIO_BL_CHAIN_ADDR__A, rom_offset);
1359 if (status < 0) 1289 if (status < 0)
1360 goto error; 1290 goto error;
1361 status = write16(state, SIO_BL_CHAIN_LEN__A, nrOfElements); 1291 status = write16(state, SIO_BL_CHAIN_LEN__A, nr_of_elements);
1362 if (status < 0) 1292 if (status < 0)
1363 goto error; 1293 goto error;
1364 status = write16(state, SIO_BL_ENABLE__A, SIO_BL_ENABLE_ON); 1294 status = write16(state, SIO_BL_ENABLE__A, SIO_BL_ENABLE_ON);
1365 if (status < 0) 1295 if (status < 0)
1366 goto error; 1296 goto error;
1367 1297
1368 end = jiffies + msecs_to_jiffies(timeOut); 1298 end = jiffies + msecs_to_jiffies(time_out);
1369 do { 1299 do {
1370 msleep(1); 1300 usleep_range(1000, 2000);
1371 status = read16(state, SIO_BL_STATUS__A, &blStatus); 1301 status = read16(state, SIO_BL_STATUS__A, &bl_status);
1372 if (status < 0) 1302 if (status < 0)
1373 goto error; 1303 goto error;
1374 } while ((blStatus == 0x1) && 1304 } while ((bl_status == 0x1) &&
1375 ((time_is_after_jiffies(end)))); 1305 ((time_is_after_jiffies(end))));
1376 1306
1377 if (blStatus == 0x1) { 1307 if (bl_status == 0x1) {
1378 printk(KERN_ERR "drxk: SIO not ready\n"); 1308 pr_err("SIO not ready\n");
1379 status = -EINVAL; 1309 status = -EINVAL;
1380 goto error2; 1310 goto error2;
1381 } 1311 }
1382error: 1312error:
1383 if (status < 0) 1313 if (status < 0)
1384 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 1314 pr_err("Error %d on %s\n", status, __func__);
1385error2: 1315error2:
1386 mutex_unlock(&state->mutex); 1316 mutex_unlock(&state->mutex);
1387 return status; 1317 return status;
1388} 1318}
1389 1319
1390 1320
1391static int DownloadMicrocode(struct drxk_state *state, 1321static int download_microcode(struct drxk_state *state,
1392 const u8 pMCImage[], u32 Length) 1322 const u8 p_mc_image[], u32 length)
1393{ 1323{
1394 const u8 *pSrc = pMCImage; 1324 const u8 *p_src = p_mc_image;
1395 u32 Address; 1325 u32 address;
1396 u16 nBlocks; 1326 u16 n_blocks;
1397 u16 BlockSize; 1327 u16 block_size;
1398 u32 offset = 0; 1328 u32 offset = 0;
1399 u32 i; 1329 u32 i;
1400 int status = 0; 1330 int status = 0;
@@ -1404,130 +1334,131 @@ static int DownloadMicrocode(struct drxk_state *state,
1404 /* down the drain (we don't care about MAGIC_WORD) */ 1334 /* down the drain (we don't care about MAGIC_WORD) */
1405#if 0 1335#if 0
1406 /* For future reference */ 1336 /* For future reference */
1407 Drain = (pSrc[0] << 8) | pSrc[1]; 1337 drain = (p_src[0] << 8) | p_src[1];
1408#endif 1338#endif
1409 pSrc += sizeof(u16); 1339 p_src += sizeof(u16);
1410 offset += sizeof(u16); 1340 offset += sizeof(u16);
1411 nBlocks = (pSrc[0] << 8) | pSrc[1]; 1341 n_blocks = (p_src[0] << 8) | p_src[1];
1412 pSrc += sizeof(u16); 1342 p_src += sizeof(u16);
1413 offset += sizeof(u16); 1343 offset += sizeof(u16);
1414 1344
1415 for (i = 0; i < nBlocks; i += 1) { 1345 for (i = 0; i < n_blocks; i += 1) {
1416 Address = (pSrc[0] << 24) | (pSrc[1] << 16) | 1346 address = (p_src[0] << 24) | (p_src[1] << 16) |
1417 (pSrc[2] << 8) | pSrc[3]; 1347 (p_src[2] << 8) | p_src[3];
1418 pSrc += sizeof(u32); 1348 p_src += sizeof(u32);
1419 offset += sizeof(u32); 1349 offset += sizeof(u32);
1420 1350
1421 BlockSize = ((pSrc[0] << 8) | pSrc[1]) * sizeof(u16); 1351 block_size = ((p_src[0] << 8) | p_src[1]) * sizeof(u16);
1422 pSrc += sizeof(u16); 1352 p_src += sizeof(u16);
1423 offset += sizeof(u16); 1353 offset += sizeof(u16);
1424 1354
1425#if 0 1355#if 0
1426 /* For future reference */ 1356 /* For future reference */
1427 Flags = (pSrc[0] << 8) | pSrc[1]; 1357 flags = (p_src[0] << 8) | p_src[1];
1428#endif 1358#endif
1429 pSrc += sizeof(u16); 1359 p_src += sizeof(u16);
1430 offset += sizeof(u16); 1360 offset += sizeof(u16);
1431 1361
1432#if 0 1362#if 0
1433 /* For future reference */ 1363 /* For future reference */
1434 BlockCRC = (pSrc[0] << 8) | pSrc[1]; 1364 block_crc = (p_src[0] << 8) | p_src[1];
1435#endif 1365#endif
1436 pSrc += sizeof(u16); 1366 p_src += sizeof(u16);
1437 offset += sizeof(u16); 1367 offset += sizeof(u16);
1438 1368
1439 if (offset + BlockSize > Length) { 1369 if (offset + block_size > length) {
1440 printk(KERN_ERR "drxk: Firmware is corrupted.\n"); 1370 pr_err("Firmware is corrupted.\n");
1441 return -EINVAL; 1371 return -EINVAL;
1442 } 1372 }
1443 1373
1444 status = write_block(state, Address, BlockSize, pSrc); 1374 status = write_block(state, address, block_size, p_src);
1445 if (status < 0) { 1375 if (status < 0) {
1446 printk(KERN_ERR "drxk: Error %d while loading firmware\n", status); 1376 pr_err("Error %d while loading firmware\n", status);
1447 break; 1377 break;
1448 } 1378 }
1449 pSrc += BlockSize; 1379 p_src += block_size;
1450 offset += BlockSize; 1380 offset += block_size;
1451 } 1381 }
1452 return status; 1382 return status;
1453} 1383}
1454 1384
1455static int DVBTEnableOFDMTokenRing(struct drxk_state *state, bool enable) 1385static int dvbt_enable_ofdm_token_ring(struct drxk_state *state, bool enable)
1456{ 1386{
1457 int status; 1387 int status;
1458 u16 data = 0; 1388 u16 data = 0;
1459 u16 desiredCtrl = SIO_OFDM_SH_OFDM_RING_ENABLE_ON; 1389 u16 desired_ctrl = SIO_OFDM_SH_OFDM_RING_ENABLE_ON;
1460 u16 desiredStatus = SIO_OFDM_SH_OFDM_RING_STATUS_ENABLED; 1390 u16 desired_status = SIO_OFDM_SH_OFDM_RING_STATUS_ENABLED;
1461 unsigned long end; 1391 unsigned long end;
1462 1392
1463 dprintk(1, "\n"); 1393 dprintk(1, "\n");
1464 1394
1465 if (enable == false) { 1395 if (enable == false) {
1466 desiredCtrl = SIO_OFDM_SH_OFDM_RING_ENABLE_OFF; 1396 desired_ctrl = SIO_OFDM_SH_OFDM_RING_ENABLE_OFF;
1467 desiredStatus = SIO_OFDM_SH_OFDM_RING_STATUS_DOWN; 1397 desired_status = SIO_OFDM_SH_OFDM_RING_STATUS_DOWN;
1468 } 1398 }
1469 1399
1470 status = read16(state, SIO_OFDM_SH_OFDM_RING_STATUS__A, &data); 1400 status = read16(state, SIO_OFDM_SH_OFDM_RING_STATUS__A, &data);
1471 if (status >= 0 && data == desiredStatus) { 1401 if (status >= 0 && data == desired_status) {
1472 /* tokenring already has correct status */ 1402 /* tokenring already has correct status */
1473 return status; 1403 return status;
1474 } 1404 }
1475 /* Disable/enable dvbt tokenring bridge */ 1405 /* Disable/enable dvbt tokenring bridge */
1476 status = write16(state, SIO_OFDM_SH_OFDM_RING_ENABLE__A, desiredCtrl); 1406 status = write16(state, SIO_OFDM_SH_OFDM_RING_ENABLE__A, desired_ctrl);
1477 1407
1478 end = jiffies + msecs_to_jiffies(DRXK_OFDM_TR_SHUTDOWN_TIMEOUT); 1408 end = jiffies + msecs_to_jiffies(DRXK_OFDM_TR_SHUTDOWN_TIMEOUT);
1479 do { 1409 do {
1480 status = read16(state, SIO_OFDM_SH_OFDM_RING_STATUS__A, &data); 1410 status = read16(state, SIO_OFDM_SH_OFDM_RING_STATUS__A, &data);
1481 if ((status >= 0 && data == desiredStatus) || time_is_after_jiffies(end)) 1411 if ((status >= 0 && data == desired_status)
1412 || time_is_after_jiffies(end))
1482 break; 1413 break;
1483 msleep(1); 1414 usleep_range(1000, 2000);
1484 } while (1); 1415 } while (1);
1485 if (data != desiredStatus) { 1416 if (data != desired_status) {
1486 printk(KERN_ERR "drxk: SIO not ready\n"); 1417 pr_err("SIO not ready\n");
1487 return -EINVAL; 1418 return -EINVAL;
1488 } 1419 }
1489 return status; 1420 return status;
1490} 1421}
1491 1422
1492static int MPEGTSStop(struct drxk_state *state) 1423static int mpegts_stop(struct drxk_state *state)
1493{ 1424{
1494 int status = 0; 1425 int status = 0;
1495 u16 fecOcSncMode = 0; 1426 u16 fec_oc_snc_mode = 0;
1496 u16 fecOcIprMode = 0; 1427 u16 fec_oc_ipr_mode = 0;
1497 1428
1498 dprintk(1, "\n"); 1429 dprintk(1, "\n");
1499 1430
1500 /* Gracefull shutdown (byte boundaries) */ 1431 /* Gracefull shutdown (byte boundaries) */
1501 status = read16(state, FEC_OC_SNC_MODE__A, &fecOcSncMode); 1432 status = read16(state, FEC_OC_SNC_MODE__A, &fec_oc_snc_mode);
1502 if (status < 0) 1433 if (status < 0)
1503 goto error; 1434 goto error;
1504 fecOcSncMode |= FEC_OC_SNC_MODE_SHUTDOWN__M; 1435 fec_oc_snc_mode |= FEC_OC_SNC_MODE_SHUTDOWN__M;
1505 status = write16(state, FEC_OC_SNC_MODE__A, fecOcSncMode); 1436 status = write16(state, FEC_OC_SNC_MODE__A, fec_oc_snc_mode);
1506 if (status < 0) 1437 if (status < 0)
1507 goto error; 1438 goto error;
1508 1439
1509 /* Suppress MCLK during absence of data */ 1440 /* Suppress MCLK during absence of data */
1510 status = read16(state, FEC_OC_IPR_MODE__A, &fecOcIprMode); 1441 status = read16(state, FEC_OC_IPR_MODE__A, &fec_oc_ipr_mode);
1511 if (status < 0) 1442 if (status < 0)
1512 goto error; 1443 goto error;
1513 fecOcIprMode |= FEC_OC_IPR_MODE_MCLK_DIS_DAT_ABS__M; 1444 fec_oc_ipr_mode |= FEC_OC_IPR_MODE_MCLK_DIS_DAT_ABS__M;
1514 status = write16(state, FEC_OC_IPR_MODE__A, fecOcIprMode); 1445 status = write16(state, FEC_OC_IPR_MODE__A, fec_oc_ipr_mode);
1515 1446
1516error: 1447error:
1517 if (status < 0) 1448 if (status < 0)
1518 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 1449 pr_err("Error %d on %s\n", status, __func__);
1519 1450
1520 return status; 1451 return status;
1521} 1452}
1522 1453
1523static int scu_command(struct drxk_state *state, 1454static int scu_command(struct drxk_state *state,
1524 u16 cmd, u8 parameterLen, 1455 u16 cmd, u8 parameter_len,
1525 u16 *parameter, u8 resultLen, u16 *result) 1456 u16 *parameter, u8 result_len, u16 *result)
1526{ 1457{
1527#if (SCU_RAM_PARAM_0__A - SCU_RAM_PARAM_15__A) != 15 1458#if (SCU_RAM_PARAM_0__A - SCU_RAM_PARAM_15__A) != 15
1528#error DRXK register mapping no longer compatible with this routine! 1459#error DRXK register mapping no longer compatible with this routine!
1529#endif 1460#endif
1530 u16 curCmd = 0; 1461 u16 cur_cmd = 0;
1531 int status = -EINVAL; 1462 int status = -EINVAL;
1532 unsigned long end; 1463 unsigned long end;
1533 u8 buffer[34]; 1464 u8 buffer[34];
@@ -1537,9 +1468,9 @@ static int scu_command(struct drxk_state *state,
1537 1468
1538 dprintk(1, "\n"); 1469 dprintk(1, "\n");
1539 1470
1540 if ((cmd == 0) || ((parameterLen > 0) && (parameter == NULL)) || 1471 if ((cmd == 0) || ((parameter_len > 0) && (parameter == NULL)) ||
1541 ((resultLen > 0) && (result == NULL))) { 1472 ((result_len > 0) && (result == NULL))) {
1542 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 1473 pr_err("Error %d on %s\n", status, __func__);
1543 return status; 1474 return status;
1544 } 1475 }
1545 1476
@@ -1547,7 +1478,7 @@ static int scu_command(struct drxk_state *state,
1547 1478
1548 /* assume that the command register is ready 1479 /* assume that the command register is ready
1549 since it is checked afterwards */ 1480 since it is checked afterwards */
1550 for (ii = parameterLen - 1; ii >= 0; ii -= 1) { 1481 for (ii = parameter_len - 1; ii >= 0; ii -= 1) {
1551 buffer[cnt++] = (parameter[ii] & 0xFF); 1482 buffer[cnt++] = (parameter[ii] & 0xFF);
1552 buffer[cnt++] = ((parameter[ii] >> 8) & 0xFF); 1483 buffer[cnt++] = ((parameter[ii] >> 8) & 0xFF);
1553 } 1484 }
@@ -1555,27 +1486,28 @@ static int scu_command(struct drxk_state *state,
1555 buffer[cnt++] = ((cmd >> 8) & 0xFF); 1486 buffer[cnt++] = ((cmd >> 8) & 0xFF);
1556 1487
1557 write_block(state, SCU_RAM_PARAM_0__A - 1488 write_block(state, SCU_RAM_PARAM_0__A -
1558 (parameterLen - 1), cnt, buffer); 1489 (parameter_len - 1), cnt, buffer);
1559 /* Wait until SCU has processed command */ 1490 /* Wait until SCU has processed command */
1560 end = jiffies + msecs_to_jiffies(DRXK_MAX_WAITTIME); 1491 end = jiffies + msecs_to_jiffies(DRXK_MAX_WAITTIME);
1561 do { 1492 do {
1562 msleep(1); 1493 usleep_range(1000, 2000);
1563 status = read16(state, SCU_RAM_COMMAND__A, &curCmd); 1494 status = read16(state, SCU_RAM_COMMAND__A, &cur_cmd);
1564 if (status < 0) 1495 if (status < 0)
1565 goto error; 1496 goto error;
1566 } while (!(curCmd == DRX_SCU_READY) && (time_is_after_jiffies(end))); 1497 } while (!(cur_cmd == DRX_SCU_READY) && (time_is_after_jiffies(end)));
1567 if (curCmd != DRX_SCU_READY) { 1498 if (cur_cmd != DRX_SCU_READY) {
1568 printk(KERN_ERR "drxk: SCU not ready\n"); 1499 pr_err("SCU not ready\n");
1569 status = -EIO; 1500 status = -EIO;
1570 goto error2; 1501 goto error2;
1571 } 1502 }
1572 /* read results */ 1503 /* read results */
1573 if ((resultLen > 0) && (result != NULL)) { 1504 if ((result_len > 0) && (result != NULL)) {
1574 s16 err; 1505 s16 err;
1575 int ii; 1506 int ii;
1576 1507
1577 for (ii = resultLen - 1; ii >= 0; ii -= 1) { 1508 for (ii = result_len - 1; ii >= 0; ii -= 1) {
1578 status = read16(state, SCU_RAM_PARAM_0__A - ii, &result[ii]); 1509 status = read16(state, SCU_RAM_PARAM_0__A - ii,
1510 &result[ii]);
1579 if (status < 0) 1511 if (status < 0)
1580 goto error; 1512 goto error;
1581 } 1513 }
@@ -1603,7 +1535,7 @@ static int scu_command(struct drxk_state *state,
1603 sprintf(errname, "ERROR: %d\n", err); 1535 sprintf(errname, "ERROR: %d\n", err);
1604 p = errname; 1536 p = errname;
1605 } 1537 }
1606 printk(KERN_ERR "drxk: %s while sending cmd 0x%04x with params:", p, cmd); 1538 pr_err("%s while sending cmd 0x%04x with params:", p, cmd);
1607 print_hex_dump_bytes("drxk: ", DUMP_PREFIX_NONE, buffer, cnt); 1539 print_hex_dump_bytes("drxk: ", DUMP_PREFIX_NONE, buffer, cnt);
1608 status = -EINVAL; 1540 status = -EINVAL;
1609 goto error2; 1541 goto error2;
@@ -1611,13 +1543,13 @@ static int scu_command(struct drxk_state *state,
1611 1543
1612error: 1544error:
1613 if (status < 0) 1545 if (status < 0)
1614 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 1546 pr_err("Error %d on %s\n", status, __func__);
1615error2: 1547error2:
1616 mutex_unlock(&state->mutex); 1548 mutex_unlock(&state->mutex);
1617 return status; 1549 return status;
1618} 1550}
1619 1551
1620static int SetIqmAf(struct drxk_state *state, bool active) 1552static int set_iqm_af(struct drxk_state *state, bool active)
1621{ 1553{
1622 u16 data = 0; 1554 u16 data = 0;
1623 int status; 1555 int status;
@@ -1647,14 +1579,14 @@ static int SetIqmAf(struct drxk_state *state, bool active)
1647 1579
1648error: 1580error:
1649 if (status < 0) 1581 if (status < 0)
1650 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 1582 pr_err("Error %d on %s\n", status, __func__);
1651 return status; 1583 return status;
1652} 1584}
1653 1585
1654static int CtrlPowerMode(struct drxk_state *state, enum DRXPowerMode *mode) 1586static int ctrl_power_mode(struct drxk_state *state, enum drx_power_mode *mode)
1655{ 1587{
1656 int status = 0; 1588 int status = 0;
1657 u16 sioCcPwdMode = 0; 1589 u16 sio_cc_pwd_mode = 0;
1658 1590
1659 dprintk(1, "\n"); 1591 dprintk(1, "\n");
1660 1592
@@ -1664,19 +1596,19 @@ static int CtrlPowerMode(struct drxk_state *state, enum DRXPowerMode *mode)
1664 1596
1665 switch (*mode) { 1597 switch (*mode) {
1666 case DRX_POWER_UP: 1598 case DRX_POWER_UP:
1667 sioCcPwdMode = SIO_CC_PWD_MODE_LEVEL_NONE; 1599 sio_cc_pwd_mode = SIO_CC_PWD_MODE_LEVEL_NONE;
1668 break; 1600 break;
1669 case DRXK_POWER_DOWN_OFDM: 1601 case DRXK_POWER_DOWN_OFDM:
1670 sioCcPwdMode = SIO_CC_PWD_MODE_LEVEL_OFDM; 1602 sio_cc_pwd_mode = SIO_CC_PWD_MODE_LEVEL_OFDM;
1671 break; 1603 break;
1672 case DRXK_POWER_DOWN_CORE: 1604 case DRXK_POWER_DOWN_CORE:
1673 sioCcPwdMode = SIO_CC_PWD_MODE_LEVEL_CLOCK; 1605 sio_cc_pwd_mode = SIO_CC_PWD_MODE_LEVEL_CLOCK;
1674 break; 1606 break;
1675 case DRXK_POWER_DOWN_PLL: 1607 case DRXK_POWER_DOWN_PLL:
1676 sioCcPwdMode = SIO_CC_PWD_MODE_LEVEL_PLL; 1608 sio_cc_pwd_mode = SIO_CC_PWD_MODE_LEVEL_PLL;
1677 break; 1609 break;
1678 case DRX_POWER_DOWN: 1610 case DRX_POWER_DOWN:
1679 sioCcPwdMode = SIO_CC_PWD_MODE_LEVEL_OSC; 1611 sio_cc_pwd_mode = SIO_CC_PWD_MODE_LEVEL_OSC;
1680 break; 1612 break;
1681 default: 1613 default:
1682 /* Unknow sleep mode */ 1614 /* Unknow sleep mode */
@@ -1684,15 +1616,15 @@ static int CtrlPowerMode(struct drxk_state *state, enum DRXPowerMode *mode)
1684 } 1616 }
1685 1617
1686 /* If already in requested power mode, do nothing */ 1618 /* If already in requested power mode, do nothing */
1687 if (state->m_currentPowerMode == *mode) 1619 if (state->m_current_power_mode == *mode)
1688 return 0; 1620 return 0;
1689 1621
1690 /* For next steps make sure to start from DRX_POWER_UP mode */ 1622 /* For next steps make sure to start from DRX_POWER_UP mode */
1691 if (state->m_currentPowerMode != DRX_POWER_UP) { 1623 if (state->m_current_power_mode != DRX_POWER_UP) {
1692 status = PowerUpDevice(state); 1624 status = power_up_device(state);
1693 if (status < 0) 1625 if (status < 0)
1694 goto error; 1626 goto error;
1695 status = DVBTEnableOFDMTokenRing(state, true); 1627 status = dvbt_enable_ofdm_token_ring(state, true);
1696 if (status < 0) 1628 if (status < 0)
1697 goto error; 1629 goto error;
1698 } 1630 }
@@ -1709,31 +1641,31 @@ static int CtrlPowerMode(struct drxk_state *state, enum DRXPowerMode *mode)
1709 /* Power down device */ 1641 /* Power down device */
1710 /* stop all comm_exec */ 1642 /* stop all comm_exec */
1711 /* Stop and power down previous standard */ 1643 /* Stop and power down previous standard */
1712 switch (state->m_OperationMode) { 1644 switch (state->m_operation_mode) {
1713 case OM_DVBT: 1645 case OM_DVBT:
1714 status = MPEGTSStop(state); 1646 status = mpegts_stop(state);
1715 if (status < 0) 1647 if (status < 0)
1716 goto error; 1648 goto error;
1717 status = PowerDownDVBT(state, false); 1649 status = power_down_dvbt(state, false);
1718 if (status < 0) 1650 if (status < 0)
1719 goto error; 1651 goto error;
1720 break; 1652 break;
1721 case OM_QAM_ITU_A: 1653 case OM_QAM_ITU_A:
1722 case OM_QAM_ITU_C: 1654 case OM_QAM_ITU_C:
1723 status = MPEGTSStop(state); 1655 status = mpegts_stop(state);
1724 if (status < 0) 1656 if (status < 0)
1725 goto error; 1657 goto error;
1726 status = PowerDownQAM(state); 1658 status = power_down_qam(state);
1727 if (status < 0) 1659 if (status < 0)
1728 goto error; 1660 goto error;
1729 break; 1661 break;
1730 default: 1662 default:
1731 break; 1663 break;
1732 } 1664 }
1733 status = DVBTEnableOFDMTokenRing(state, false); 1665 status = dvbt_enable_ofdm_token_ring(state, false);
1734 if (status < 0) 1666 if (status < 0)
1735 goto error; 1667 goto error;
1736 status = write16(state, SIO_CC_PWD_MODE__A, sioCcPwdMode); 1668 status = write16(state, SIO_CC_PWD_MODE__A, sio_cc_pwd_mode);
1737 if (status < 0) 1669 if (status < 0)
1738 goto error; 1670 goto error;
1739 status = write16(state, SIO_CC_UPDATE__A, SIO_CC_UPDATE_KEY); 1671 status = write16(state, SIO_CC_UPDATE__A, SIO_CC_UPDATE_KEY);
@@ -1741,26 +1673,26 @@ static int CtrlPowerMode(struct drxk_state *state, enum DRXPowerMode *mode)
1741 goto error; 1673 goto error;
1742 1674
1743 if (*mode != DRXK_POWER_DOWN_OFDM) { 1675 if (*mode != DRXK_POWER_DOWN_OFDM) {
1744 state->m_HICfgCtrl |= 1676 state->m_hi_cfg_ctrl |=
1745 SIO_HI_RA_RAM_PAR_5_CFG_SLEEP_ZZZ; 1677 SIO_HI_RA_RAM_PAR_5_CFG_SLEEP_ZZZ;
1746 status = HI_CfgCommand(state); 1678 status = hi_cfg_command(state);
1747 if (status < 0) 1679 if (status < 0)
1748 goto error; 1680 goto error;
1749 } 1681 }
1750 } 1682 }
1751 state->m_currentPowerMode = *mode; 1683 state->m_current_power_mode = *mode;
1752 1684
1753error: 1685error:
1754 if (status < 0) 1686 if (status < 0)
1755 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 1687 pr_err("Error %d on %s\n", status, __func__);
1756 1688
1757 return status; 1689 return status;
1758} 1690}
1759 1691
1760static int PowerDownDVBT(struct drxk_state *state, bool setPowerMode) 1692static int power_down_dvbt(struct drxk_state *state, bool set_power_mode)
1761{ 1693{
1762 enum DRXPowerMode powerMode = DRXK_POWER_DOWN_OFDM; 1694 enum drx_power_mode power_mode = DRXK_POWER_DOWN_OFDM;
1763 u16 cmdResult = 0; 1695 u16 cmd_result = 0;
1764 u16 data = 0; 1696 u16 data = 0;
1765 int status; 1697 int status;
1766 1698
@@ -1771,11 +1703,17 @@ static int PowerDownDVBT(struct drxk_state *state, bool setPowerMode)
1771 goto error; 1703 goto error;
1772 if (data == SCU_COMM_EXEC_ACTIVE) { 1704 if (data == SCU_COMM_EXEC_ACTIVE) {
1773 /* Send OFDM stop command */ 1705 /* Send OFDM stop command */
1774 status = scu_command(state, SCU_RAM_COMMAND_STANDARD_OFDM | SCU_RAM_COMMAND_CMD_DEMOD_STOP, 0, NULL, 1, &cmdResult); 1706 status = scu_command(state,
1707 SCU_RAM_COMMAND_STANDARD_OFDM
1708 | SCU_RAM_COMMAND_CMD_DEMOD_STOP,
1709 0, NULL, 1, &cmd_result);
1775 if (status < 0) 1710 if (status < 0)
1776 goto error; 1711 goto error;
1777 /* Send OFDM reset command */ 1712 /* Send OFDM reset command */
1778 status = scu_command(state, SCU_RAM_COMMAND_STANDARD_OFDM | SCU_RAM_COMMAND_CMD_DEMOD_RESET, 0, NULL, 1, &cmdResult); 1713 status = scu_command(state,
1714 SCU_RAM_COMMAND_STANDARD_OFDM
1715 | SCU_RAM_COMMAND_CMD_DEMOD_RESET,
1716 0, NULL, 1, &cmd_result);
1779 if (status < 0) 1717 if (status < 0)
1780 goto error; 1718 goto error;
1781 } 1719 }
@@ -1792,24 +1730,24 @@ static int PowerDownDVBT(struct drxk_state *state, bool setPowerMode)
1792 goto error; 1730 goto error;
1793 1731
1794 /* powerdown AFE */ 1732 /* powerdown AFE */
1795 status = SetIqmAf(state, false); 1733 status = set_iqm_af(state, false);
1796 if (status < 0) 1734 if (status < 0)
1797 goto error; 1735 goto error;
1798 1736
1799 /* powerdown to OFDM mode */ 1737 /* powerdown to OFDM mode */
1800 if (setPowerMode) { 1738 if (set_power_mode) {
1801 status = CtrlPowerMode(state, &powerMode); 1739 status = ctrl_power_mode(state, &power_mode);
1802 if (status < 0) 1740 if (status < 0)
1803 goto error; 1741 goto error;
1804 } 1742 }
1805error: 1743error:
1806 if (status < 0) 1744 if (status < 0)
1807 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 1745 pr_err("Error %d on %s\n", status, __func__);
1808 return status; 1746 return status;
1809} 1747}
1810 1748
1811static int SetOperationMode(struct drxk_state *state, 1749static int setoperation_mode(struct drxk_state *state,
1812 enum OperationMode oMode) 1750 enum operation_mode o_mode)
1813{ 1751{
1814 int status = 0; 1752 int status = 0;
1815 1753
@@ -1821,36 +1759,37 @@ static int SetOperationMode(struct drxk_state *state,
1821 */ 1759 */
1822 1760
1823 /* disable HW lock indicator */ 1761 /* disable HW lock indicator */
1824 status = write16(state, SCU_RAM_GPIO__A, SCU_RAM_GPIO_HW_LOCK_IND_DISABLE); 1762 status = write16(state, SCU_RAM_GPIO__A,
1763 SCU_RAM_GPIO_HW_LOCK_IND_DISABLE);
1825 if (status < 0) 1764 if (status < 0)
1826 goto error; 1765 goto error;
1827 1766
1828 /* Device is already at the required mode */ 1767 /* Device is already at the required mode */
1829 if (state->m_OperationMode == oMode) 1768 if (state->m_operation_mode == o_mode)
1830 return 0; 1769 return 0;
1831 1770
1832 switch (state->m_OperationMode) { 1771 switch (state->m_operation_mode) {
1833 /* OM_NONE was added for start up */ 1772 /* OM_NONE was added for start up */
1834 case OM_NONE: 1773 case OM_NONE:
1835 break; 1774 break;
1836 case OM_DVBT: 1775 case OM_DVBT:
1837 status = MPEGTSStop(state); 1776 status = mpegts_stop(state);
1838 if (status < 0) 1777 if (status < 0)
1839 goto error; 1778 goto error;
1840 status = PowerDownDVBT(state, true); 1779 status = power_down_dvbt(state, true);
1841 if (status < 0) 1780 if (status < 0)
1842 goto error; 1781 goto error;
1843 state->m_OperationMode = OM_NONE; 1782 state->m_operation_mode = OM_NONE;
1844 break; 1783 break;
1845 case OM_QAM_ITU_A: /* fallthrough */ 1784 case OM_QAM_ITU_A: /* fallthrough */
1846 case OM_QAM_ITU_C: 1785 case OM_QAM_ITU_C:
1847 status = MPEGTSStop(state); 1786 status = mpegts_stop(state);
1848 if (status < 0) 1787 if (status < 0)
1849 goto error; 1788 goto error;
1850 status = PowerDownQAM(state); 1789 status = power_down_qam(state);
1851 if (status < 0) 1790 if (status < 0)
1852 goto error; 1791 goto error;
1853 state->m_OperationMode = OM_NONE; 1792 state->m_operation_mode = OM_NONE;
1854 break; 1793 break;
1855 case OM_QAM_ITU_B: 1794 case OM_QAM_ITU_B:
1856 default: 1795 default:
@@ -1861,20 +1800,20 @@ static int SetOperationMode(struct drxk_state *state,
1861 /* 1800 /*
1862 Power up new standard 1801 Power up new standard
1863 */ 1802 */
1864 switch (oMode) { 1803 switch (o_mode) {
1865 case OM_DVBT: 1804 case OM_DVBT:
1866 dprintk(1, ": DVB-T\n"); 1805 dprintk(1, ": DVB-T\n");
1867 state->m_OperationMode = oMode; 1806 state->m_operation_mode = o_mode;
1868 status = SetDVBTStandard(state, oMode); 1807 status = set_dvbt_standard(state, o_mode);
1869 if (status < 0) 1808 if (status < 0)
1870 goto error; 1809 goto error;
1871 break; 1810 break;
1872 case OM_QAM_ITU_A: /* fallthrough */ 1811 case OM_QAM_ITU_A: /* fallthrough */
1873 case OM_QAM_ITU_C: 1812 case OM_QAM_ITU_C:
1874 dprintk(1, ": DVB-C Annex %c\n", 1813 dprintk(1, ": DVB-C Annex %c\n",
1875 (state->m_OperationMode == OM_QAM_ITU_A) ? 'A' : 'C'); 1814 (state->m_operation_mode == OM_QAM_ITU_A) ? 'A' : 'C');
1876 state->m_OperationMode = oMode; 1815 state->m_operation_mode = o_mode;
1877 status = SetQAMStandard(state, oMode); 1816 status = set_qam_standard(state, o_mode);
1878 if (status < 0) 1817 if (status < 0)
1879 goto error; 1818 goto error;
1880 break; 1819 break;
@@ -1884,121 +1823,121 @@ static int SetOperationMode(struct drxk_state *state,
1884 } 1823 }
1885error: 1824error:
1886 if (status < 0) 1825 if (status < 0)
1887 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 1826 pr_err("Error %d on %s\n", status, __func__);
1888 return status; 1827 return status;
1889} 1828}
1890 1829
1891static int Start(struct drxk_state *state, s32 offsetFreq, 1830static int start(struct drxk_state *state, s32 offset_freq,
1892 s32 IntermediateFrequency) 1831 s32 intermediate_frequency)
1893{ 1832{
1894 int status = -EINVAL; 1833 int status = -EINVAL;
1895 1834
1896 u16 IFreqkHz; 1835 u16 i_freqk_hz;
1897 s32 OffsetkHz = offsetFreq / 1000; 1836 s32 offsetk_hz = offset_freq / 1000;
1898 1837
1899 dprintk(1, "\n"); 1838 dprintk(1, "\n");
1900 if (state->m_DrxkState != DRXK_STOPPED && 1839 if (state->m_drxk_state != DRXK_STOPPED &&
1901 state->m_DrxkState != DRXK_DTV_STARTED) 1840 state->m_drxk_state != DRXK_DTV_STARTED)
1902 goto error; 1841 goto error;
1903 1842
1904 state->m_bMirrorFreqSpect = (state->props.inversion == INVERSION_ON); 1843 state->m_b_mirror_freq_spect = (state->props.inversion == INVERSION_ON);
1905 1844
1906 if (IntermediateFrequency < 0) { 1845 if (intermediate_frequency < 0) {
1907 state->m_bMirrorFreqSpect = !state->m_bMirrorFreqSpect; 1846 state->m_b_mirror_freq_spect = !state->m_b_mirror_freq_spect;
1908 IntermediateFrequency = -IntermediateFrequency; 1847 intermediate_frequency = -intermediate_frequency;
1909 } 1848 }
1910 1849
1911 switch (state->m_OperationMode) { 1850 switch (state->m_operation_mode) {
1912 case OM_QAM_ITU_A: 1851 case OM_QAM_ITU_A:
1913 case OM_QAM_ITU_C: 1852 case OM_QAM_ITU_C:
1914 IFreqkHz = (IntermediateFrequency / 1000); 1853 i_freqk_hz = (intermediate_frequency / 1000);
1915 status = SetQAM(state, IFreqkHz, OffsetkHz); 1854 status = set_qam(state, i_freqk_hz, offsetk_hz);
1916 if (status < 0) 1855 if (status < 0)
1917 goto error; 1856 goto error;
1918 state->m_DrxkState = DRXK_DTV_STARTED; 1857 state->m_drxk_state = DRXK_DTV_STARTED;
1919 break; 1858 break;
1920 case OM_DVBT: 1859 case OM_DVBT:
1921 IFreqkHz = (IntermediateFrequency / 1000); 1860 i_freqk_hz = (intermediate_frequency / 1000);
1922 status = MPEGTSStop(state); 1861 status = mpegts_stop(state);
1923 if (status < 0) 1862 if (status < 0)
1924 goto error; 1863 goto error;
1925 status = SetDVBT(state, IFreqkHz, OffsetkHz); 1864 status = set_dvbt(state, i_freqk_hz, offsetk_hz);
1926 if (status < 0) 1865 if (status < 0)
1927 goto error; 1866 goto error;
1928 status = DVBTStart(state); 1867 status = dvbt_start(state);
1929 if (status < 0) 1868 if (status < 0)
1930 goto error; 1869 goto error;
1931 state->m_DrxkState = DRXK_DTV_STARTED; 1870 state->m_drxk_state = DRXK_DTV_STARTED;
1932 break; 1871 break;
1933 default: 1872 default:
1934 break; 1873 break;
1935 } 1874 }
1936error: 1875error:
1937 if (status < 0) 1876 if (status < 0)
1938 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 1877 pr_err("Error %d on %s\n", status, __func__);
1939 return status; 1878 return status;
1940} 1879}
1941 1880
1942static int ShutDown(struct drxk_state *state) 1881static int shut_down(struct drxk_state *state)
1943{ 1882{
1944 dprintk(1, "\n"); 1883 dprintk(1, "\n");
1945 1884
1946 MPEGTSStop(state); 1885 mpegts_stop(state);
1947 return 0; 1886 return 0;
1948} 1887}
1949 1888
1950static int GetLockStatus(struct drxk_state *state, u32 *pLockStatus) 1889static int get_lock_status(struct drxk_state *state, u32 *p_lock_status)
1951{ 1890{
1952 int status = -EINVAL; 1891 int status = -EINVAL;
1953 1892
1954 dprintk(1, "\n"); 1893 dprintk(1, "\n");
1955 1894
1956 if (pLockStatus == NULL) 1895 if (p_lock_status == NULL)
1957 goto error; 1896 goto error;
1958 1897
1959 *pLockStatus = NOT_LOCKED; 1898 *p_lock_status = NOT_LOCKED;
1960 1899
1961 /* define the SCU command code */ 1900 /* define the SCU command code */
1962 switch (state->m_OperationMode) { 1901 switch (state->m_operation_mode) {
1963 case OM_QAM_ITU_A: 1902 case OM_QAM_ITU_A:
1964 case OM_QAM_ITU_B: 1903 case OM_QAM_ITU_B:
1965 case OM_QAM_ITU_C: 1904 case OM_QAM_ITU_C:
1966 status = GetQAMLockStatus(state, pLockStatus); 1905 status = get_qam_lock_status(state, p_lock_status);
1967 break; 1906 break;
1968 case OM_DVBT: 1907 case OM_DVBT:
1969 status = GetDVBTLockStatus(state, pLockStatus); 1908 status = get_dvbt_lock_status(state, p_lock_status);
1970 break; 1909 break;
1971 default: 1910 default:
1972 break; 1911 break;
1973 } 1912 }
1974error: 1913error:
1975 if (status < 0) 1914 if (status < 0)
1976 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 1915 pr_err("Error %d on %s\n", status, __func__);
1977 return status; 1916 return status;
1978} 1917}
1979 1918
1980static int MPEGTSStart(struct drxk_state *state) 1919static int mpegts_start(struct drxk_state *state)
1981{ 1920{
1982 int status; 1921 int status;
1983 1922
1984 u16 fecOcSncMode = 0; 1923 u16 fec_oc_snc_mode = 0;
1985 1924
1986 /* Allow OC to sync again */ 1925 /* Allow OC to sync again */
1987 status = read16(state, FEC_OC_SNC_MODE__A, &fecOcSncMode); 1926 status = read16(state, FEC_OC_SNC_MODE__A, &fec_oc_snc_mode);
1988 if (status < 0) 1927 if (status < 0)
1989 goto error; 1928 goto error;
1990 fecOcSncMode &= ~FEC_OC_SNC_MODE_SHUTDOWN__M; 1929 fec_oc_snc_mode &= ~FEC_OC_SNC_MODE_SHUTDOWN__M;
1991 status = write16(state, FEC_OC_SNC_MODE__A, fecOcSncMode); 1930 status = write16(state, FEC_OC_SNC_MODE__A, fec_oc_snc_mode);
1992 if (status < 0) 1931 if (status < 0)
1993 goto error; 1932 goto error;
1994 status = write16(state, FEC_OC_SNC_UNLOCK__A, 1); 1933 status = write16(state, FEC_OC_SNC_UNLOCK__A, 1);
1995error: 1934error:
1996 if (status < 0) 1935 if (status < 0)
1997 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 1936 pr_err("Error %d on %s\n", status, __func__);
1998 return status; 1937 return status;
1999} 1938}
2000 1939
2001static int MPEGTSDtoInit(struct drxk_state *state) 1940static int mpegts_dto_init(struct drxk_state *state)
2002{ 1941{
2003 int status; 1942 int status;
2004 1943
@@ -2040,68 +1979,68 @@ static int MPEGTSDtoInit(struct drxk_state *state)
2040 status = write16(state, FEC_OC_SNC_HWM__A, 12); 1979 status = write16(state, FEC_OC_SNC_HWM__A, 12);
2041error: 1980error:
2042 if (status < 0) 1981 if (status < 0)
2043 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 1982 pr_err("Error %d on %s\n", status, __func__);
2044 1983
2045 return status; 1984 return status;
2046} 1985}
2047 1986
2048static int MPEGTSDtoSetup(struct drxk_state *state, 1987static int mpegts_dto_setup(struct drxk_state *state,
2049 enum OperationMode oMode) 1988 enum operation_mode o_mode)
2050{ 1989{
2051 int status; 1990 int status;
2052 1991
2053 u16 fecOcRegMode = 0; /* FEC_OC_MODE register value */ 1992 u16 fec_oc_reg_mode = 0; /* FEC_OC_MODE register value */
2054 u16 fecOcRegIprMode = 0; /* FEC_OC_IPR_MODE register value */ 1993 u16 fec_oc_reg_ipr_mode = 0; /* FEC_OC_IPR_MODE register value */
2055 u16 fecOcDtoMode = 0; /* FEC_OC_IPR_INVERT register value */ 1994 u16 fec_oc_dto_mode = 0; /* FEC_OC_IPR_INVERT register value */
2056 u16 fecOcFctMode = 0; /* FEC_OC_IPR_INVERT register value */ 1995 u16 fec_oc_fct_mode = 0; /* FEC_OC_IPR_INVERT register value */
2057 u16 fecOcDtoPeriod = 2; /* FEC_OC_IPR_INVERT register value */ 1996 u16 fec_oc_dto_period = 2; /* FEC_OC_IPR_INVERT register value */
2058 u16 fecOcDtoBurstLen = 188; /* FEC_OC_IPR_INVERT register value */ 1997 u16 fec_oc_dto_burst_len = 188; /* FEC_OC_IPR_INVERT register value */
2059 u32 fecOcRcnCtlRate = 0; /* FEC_OC_IPR_INVERT register value */ 1998 u32 fec_oc_rcn_ctl_rate = 0; /* FEC_OC_IPR_INVERT register value */
2060 u16 fecOcTmdMode = 0; 1999 u16 fec_oc_tmd_mode = 0;
2061 u16 fecOcTmdIntUpdRate = 0; 2000 u16 fec_oc_tmd_int_upd_rate = 0;
2062 u32 maxBitRate = 0; 2001 u32 max_bit_rate = 0;
2063 bool staticCLK = false; 2002 bool static_clk = false;
2064 2003
2065 dprintk(1, "\n"); 2004 dprintk(1, "\n");
2066 2005
2067 /* Check insertion of the Reed-Solomon parity bytes */ 2006 /* Check insertion of the Reed-Solomon parity bytes */
2068 status = read16(state, FEC_OC_MODE__A, &fecOcRegMode); 2007 status = read16(state, FEC_OC_MODE__A, &fec_oc_reg_mode);
2069 if (status < 0) 2008 if (status < 0)
2070 goto error; 2009 goto error;
2071 status = read16(state, FEC_OC_IPR_MODE__A, &fecOcRegIprMode); 2010 status = read16(state, FEC_OC_IPR_MODE__A, &fec_oc_reg_ipr_mode);
2072 if (status < 0) 2011 if (status < 0)
2073 goto error; 2012 goto error;
2074 fecOcRegMode &= (~FEC_OC_MODE_PARITY__M); 2013 fec_oc_reg_mode &= (~FEC_OC_MODE_PARITY__M);
2075 fecOcRegIprMode &= (~FEC_OC_IPR_MODE_MVAL_DIS_PAR__M); 2014 fec_oc_reg_ipr_mode &= (~FEC_OC_IPR_MODE_MVAL_DIS_PAR__M);
2076 if (state->m_insertRSByte == true) { 2015 if (state->m_insert_rs_byte == true) {
2077 /* enable parity symbol forward */ 2016 /* enable parity symbol forward */
2078 fecOcRegMode |= FEC_OC_MODE_PARITY__M; 2017 fec_oc_reg_mode |= FEC_OC_MODE_PARITY__M;
2079 /* MVAL disable during parity bytes */ 2018 /* MVAL disable during parity bytes */
2080 fecOcRegIprMode |= FEC_OC_IPR_MODE_MVAL_DIS_PAR__M; 2019 fec_oc_reg_ipr_mode |= FEC_OC_IPR_MODE_MVAL_DIS_PAR__M;
2081 /* TS burst length to 204 */ 2020 /* TS burst length to 204 */
2082 fecOcDtoBurstLen = 204; 2021 fec_oc_dto_burst_len = 204;
2083 } 2022 }
2084 2023
2085 /* Check serial or parrallel output */ 2024 /* Check serial or parrallel output */
2086 fecOcRegIprMode &= (~(FEC_OC_IPR_MODE_SERIAL__M)); 2025 fec_oc_reg_ipr_mode &= (~(FEC_OC_IPR_MODE_SERIAL__M));
2087 if (state->m_enableParallel == false) { 2026 if (state->m_enable_parallel == false) {
2088 /* MPEG data output is serial -> set ipr_mode[0] */ 2027 /* MPEG data output is serial -> set ipr_mode[0] */
2089 fecOcRegIprMode |= FEC_OC_IPR_MODE_SERIAL__M; 2028 fec_oc_reg_ipr_mode |= FEC_OC_IPR_MODE_SERIAL__M;
2090 } 2029 }
2091 2030
2092 switch (oMode) { 2031 switch (o_mode) {
2093 case OM_DVBT: 2032 case OM_DVBT:
2094 maxBitRate = state->m_DVBTBitrate; 2033 max_bit_rate = state->m_dvbt_bitrate;
2095 fecOcTmdMode = 3; 2034 fec_oc_tmd_mode = 3;
2096 fecOcRcnCtlRate = 0xC00000; 2035 fec_oc_rcn_ctl_rate = 0xC00000;
2097 staticCLK = state->m_DVBTStaticCLK; 2036 static_clk = state->m_dvbt_static_clk;
2098 break; 2037 break;
2099 case OM_QAM_ITU_A: /* fallthrough */ 2038 case OM_QAM_ITU_A: /* fallthrough */
2100 case OM_QAM_ITU_C: 2039 case OM_QAM_ITU_C:
2101 fecOcTmdMode = 0x0004; 2040 fec_oc_tmd_mode = 0x0004;
2102 fecOcRcnCtlRate = 0xD2B4EE; /* good for >63 Mb/s */ 2041 fec_oc_rcn_ctl_rate = 0xD2B4EE; /* good for >63 Mb/s */
2103 maxBitRate = state->m_DVBCBitrate; 2042 max_bit_rate = state->m_dvbc_bitrate;
2104 staticCLK = state->m_DVBCStaticCLK; 2043 static_clk = state->m_dvbc_static_clk;
2105 break; 2044 break;
2106 default: 2045 default:
2107 status = -EINVAL; 2046 status = -EINVAL;
@@ -2110,83 +2049,84 @@ static int MPEGTSDtoSetup(struct drxk_state *state,
2110 goto error; 2049 goto error;
2111 2050
2112 /* Configure DTO's */ 2051 /* Configure DTO's */
2113 if (staticCLK) { 2052 if (static_clk) {
2114 u32 bitRate = 0; 2053 u32 bit_rate = 0;
2115 2054
2116 /* Rational DTO for MCLK source (static MCLK rate), 2055 /* Rational DTO for MCLK source (static MCLK rate),
2117 Dynamic DTO for optimal grouping 2056 Dynamic DTO for optimal grouping
2118 (avoid intra-packet gaps), 2057 (avoid intra-packet gaps),
2119 DTO offset enable to sync TS burst with MSTRT */ 2058 DTO offset enable to sync TS burst with MSTRT */
2120 fecOcDtoMode = (FEC_OC_DTO_MODE_DYNAMIC__M | 2059 fec_oc_dto_mode = (FEC_OC_DTO_MODE_DYNAMIC__M |
2121 FEC_OC_DTO_MODE_OFFSET_ENABLE__M); 2060 FEC_OC_DTO_MODE_OFFSET_ENABLE__M);
2122 fecOcFctMode = (FEC_OC_FCT_MODE_RAT_ENA__M | 2061 fec_oc_fct_mode = (FEC_OC_FCT_MODE_RAT_ENA__M |
2123 FEC_OC_FCT_MODE_VIRT_ENA__M); 2062 FEC_OC_FCT_MODE_VIRT_ENA__M);
2124 2063
2125 /* Check user defined bitrate */ 2064 /* Check user defined bitrate */
2126 bitRate = maxBitRate; 2065 bit_rate = max_bit_rate;
2127 if (bitRate > 75900000UL) { /* max is 75.9 Mb/s */ 2066 if (bit_rate > 75900000UL) { /* max is 75.9 Mb/s */
2128 bitRate = 75900000UL; 2067 bit_rate = 75900000UL;
2129 } 2068 }
2130 /* Rational DTO period: 2069 /* Rational DTO period:
2131 dto_period = (Fsys / bitrate) - 2 2070 dto_period = (Fsys / bitrate) - 2
2132 2071
2133 Result should be floored, 2072 result should be floored,
2134 to make sure >= requested bitrate 2073 to make sure >= requested bitrate
2135 */ 2074 */
2136 fecOcDtoPeriod = (u16) (((state->m_sysClockFreq) 2075 fec_oc_dto_period = (u16) (((state->m_sys_clock_freq)
2137 * 1000) / bitRate); 2076 * 1000) / bit_rate);
2138 if (fecOcDtoPeriod <= 2) 2077 if (fec_oc_dto_period <= 2)
2139 fecOcDtoPeriod = 0; 2078 fec_oc_dto_period = 0;
2140 else 2079 else
2141 fecOcDtoPeriod -= 2; 2080 fec_oc_dto_period -= 2;
2142 fecOcTmdIntUpdRate = 8; 2081 fec_oc_tmd_int_upd_rate = 8;
2143 } else { 2082 } else {
2144 /* (commonAttr->staticCLK == false) => dynamic mode */ 2083 /* (commonAttr->static_clk == false) => dynamic mode */
2145 fecOcDtoMode = FEC_OC_DTO_MODE_DYNAMIC__M; 2084 fec_oc_dto_mode = FEC_OC_DTO_MODE_DYNAMIC__M;
2146 fecOcFctMode = FEC_OC_FCT_MODE__PRE; 2085 fec_oc_fct_mode = FEC_OC_FCT_MODE__PRE;
2147 fecOcTmdIntUpdRate = 5; 2086 fec_oc_tmd_int_upd_rate = 5;
2148 } 2087 }
2149 2088
2150 /* Write appropriate registers with requested configuration */ 2089 /* Write appropriate registers with requested configuration */
2151 status = write16(state, FEC_OC_DTO_BURST_LEN__A, fecOcDtoBurstLen); 2090 status = write16(state, FEC_OC_DTO_BURST_LEN__A, fec_oc_dto_burst_len);
2152 if (status < 0) 2091 if (status < 0)
2153 goto error; 2092 goto error;
2154 status = write16(state, FEC_OC_DTO_PERIOD__A, fecOcDtoPeriod); 2093 status = write16(state, FEC_OC_DTO_PERIOD__A, fec_oc_dto_period);
2155 if (status < 0) 2094 if (status < 0)
2156 goto error; 2095 goto error;
2157 status = write16(state, FEC_OC_DTO_MODE__A, fecOcDtoMode); 2096 status = write16(state, FEC_OC_DTO_MODE__A, fec_oc_dto_mode);
2158 if (status < 0) 2097 if (status < 0)
2159 goto error; 2098 goto error;
2160 status = write16(state, FEC_OC_FCT_MODE__A, fecOcFctMode); 2099 status = write16(state, FEC_OC_FCT_MODE__A, fec_oc_fct_mode);
2161 if (status < 0) 2100 if (status < 0)
2162 goto error; 2101 goto error;
2163 status = write16(state, FEC_OC_MODE__A, fecOcRegMode); 2102 status = write16(state, FEC_OC_MODE__A, fec_oc_reg_mode);
2164 if (status < 0) 2103 if (status < 0)
2165 goto error; 2104 goto error;
2166 status = write16(state, FEC_OC_IPR_MODE__A, fecOcRegIprMode); 2105 status = write16(state, FEC_OC_IPR_MODE__A, fec_oc_reg_ipr_mode);
2167 if (status < 0) 2106 if (status < 0)
2168 goto error; 2107 goto error;
2169 2108
2170 /* Rate integration settings */ 2109 /* Rate integration settings */
2171 status = write32(state, FEC_OC_RCN_CTL_RATE_LO__A, fecOcRcnCtlRate); 2110 status = write32(state, FEC_OC_RCN_CTL_RATE_LO__A, fec_oc_rcn_ctl_rate);
2172 if (status < 0) 2111 if (status < 0)
2173 goto error; 2112 goto error;
2174 status = write16(state, FEC_OC_TMD_INT_UPD_RATE__A, fecOcTmdIntUpdRate); 2113 status = write16(state, FEC_OC_TMD_INT_UPD_RATE__A,
2114 fec_oc_tmd_int_upd_rate);
2175 if (status < 0) 2115 if (status < 0)
2176 goto error; 2116 goto error;
2177 status = write16(state, FEC_OC_TMD_MODE__A, fecOcTmdMode); 2117 status = write16(state, FEC_OC_TMD_MODE__A, fec_oc_tmd_mode);
2178error: 2118error:
2179 if (status < 0) 2119 if (status < 0)
2180 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 2120 pr_err("Error %d on %s\n", status, __func__);
2181 return status; 2121 return status;
2182} 2122}
2183 2123
2184static int MPEGTSConfigurePolarity(struct drxk_state *state) 2124static int mpegts_configure_polarity(struct drxk_state *state)
2185{ 2125{
2186 u16 fecOcRegIprInvert = 0; 2126 u16 fec_oc_reg_ipr_invert = 0;
2187 2127
2188 /* Data mask for the output data byte */ 2128 /* Data mask for the output data byte */
2189 u16 InvertDataMask = 2129 u16 invert_data_mask =
2190 FEC_OC_IPR_INVERT_MD7__M | FEC_OC_IPR_INVERT_MD6__M | 2130 FEC_OC_IPR_INVERT_MD7__M | FEC_OC_IPR_INVERT_MD6__M |
2191 FEC_OC_IPR_INVERT_MD5__M | FEC_OC_IPR_INVERT_MD4__M | 2131 FEC_OC_IPR_INVERT_MD5__M | FEC_OC_IPR_INVERT_MD4__M |
2192 FEC_OC_IPR_INVERT_MD3__M | FEC_OC_IPR_INVERT_MD2__M | 2132 FEC_OC_IPR_INVERT_MD3__M | FEC_OC_IPR_INVERT_MD2__M |
@@ -2195,40 +2135,40 @@ static int MPEGTSConfigurePolarity(struct drxk_state *state)
2195 dprintk(1, "\n"); 2135 dprintk(1, "\n");
2196 2136
2197 /* Control selective inversion of output bits */ 2137 /* Control selective inversion of output bits */
2198 fecOcRegIprInvert &= (~(InvertDataMask)); 2138 fec_oc_reg_ipr_invert &= (~(invert_data_mask));
2199 if (state->m_invertDATA == true) 2139 if (state->m_invert_data == true)
2200 fecOcRegIprInvert |= InvertDataMask; 2140 fec_oc_reg_ipr_invert |= invert_data_mask;
2201 fecOcRegIprInvert &= (~(FEC_OC_IPR_INVERT_MERR__M)); 2141 fec_oc_reg_ipr_invert &= (~(FEC_OC_IPR_INVERT_MERR__M));
2202 if (state->m_invertERR == true) 2142 if (state->m_invert_err == true)
2203 fecOcRegIprInvert |= FEC_OC_IPR_INVERT_MERR__M; 2143 fec_oc_reg_ipr_invert |= FEC_OC_IPR_INVERT_MERR__M;
2204 fecOcRegIprInvert &= (~(FEC_OC_IPR_INVERT_MSTRT__M)); 2144 fec_oc_reg_ipr_invert &= (~(FEC_OC_IPR_INVERT_MSTRT__M));
2205 if (state->m_invertSTR == true) 2145 if (state->m_invert_str == true)
2206 fecOcRegIprInvert |= FEC_OC_IPR_INVERT_MSTRT__M; 2146 fec_oc_reg_ipr_invert |= FEC_OC_IPR_INVERT_MSTRT__M;
2207 fecOcRegIprInvert &= (~(FEC_OC_IPR_INVERT_MVAL__M)); 2147 fec_oc_reg_ipr_invert &= (~(FEC_OC_IPR_INVERT_MVAL__M));
2208 if (state->m_invertVAL == true) 2148 if (state->m_invert_val == true)
2209 fecOcRegIprInvert |= FEC_OC_IPR_INVERT_MVAL__M; 2149 fec_oc_reg_ipr_invert |= FEC_OC_IPR_INVERT_MVAL__M;
2210 fecOcRegIprInvert &= (~(FEC_OC_IPR_INVERT_MCLK__M)); 2150 fec_oc_reg_ipr_invert &= (~(FEC_OC_IPR_INVERT_MCLK__M));
2211 if (state->m_invertCLK == true) 2151 if (state->m_invert_clk == true)
2212 fecOcRegIprInvert |= FEC_OC_IPR_INVERT_MCLK__M; 2152 fec_oc_reg_ipr_invert |= FEC_OC_IPR_INVERT_MCLK__M;
2213 2153
2214 return write16(state, FEC_OC_IPR_INVERT__A, fecOcRegIprInvert); 2154 return write16(state, FEC_OC_IPR_INVERT__A, fec_oc_reg_ipr_invert);
2215} 2155}
2216 2156
2217#define SCU_RAM_AGC_KI_INV_RF_POL__M 0x4000 2157#define SCU_RAM_AGC_KI_INV_RF_POL__M 0x4000
2218 2158
2219static int SetAgcRf(struct drxk_state *state, 2159static int set_agc_rf(struct drxk_state *state,
2220 struct SCfgAgc *pAgcCfg, bool isDTV) 2160 struct s_cfg_agc *p_agc_cfg, bool is_dtv)
2221{ 2161{
2222 int status = -EINVAL; 2162 int status = -EINVAL;
2223 u16 data = 0; 2163 u16 data = 0;
2224 struct SCfgAgc *pIfAgcSettings; 2164 struct s_cfg_agc *p_if_agc_settings;
2225 2165
2226 dprintk(1, "\n"); 2166 dprintk(1, "\n");
2227 2167
2228 if (pAgcCfg == NULL) 2168 if (p_agc_cfg == NULL)
2229 goto error; 2169 goto error;
2230 2170
2231 switch (pAgcCfg->ctrlMode) { 2171 switch (p_agc_cfg->ctrl_mode) {
2232 case DRXK_AGC_CTRL_AUTO: 2172 case DRXK_AGC_CTRL_AUTO:
2233 /* Enable RF AGC DAC */ 2173 /* Enable RF AGC DAC */
2234 status = read16(state, IQM_AF_STDBY__A, &data); 2174 status = read16(state, IQM_AF_STDBY__A, &data);
@@ -2246,7 +2186,7 @@ static int SetAgcRf(struct drxk_state *state,
2246 data &= ~SCU_RAM_AGC_CONFIG_DISABLE_RF_AGC__M; 2186 data &= ~SCU_RAM_AGC_CONFIG_DISABLE_RF_AGC__M;
2247 2187
2248 /* Polarity */ 2188 /* Polarity */
2249 if (state->m_RfAgcPol) 2189 if (state->m_rf_agc_pol)
2250 data |= SCU_RAM_AGC_CONFIG_INV_RF_POL__M; 2190 data |= SCU_RAM_AGC_CONFIG_INV_RF_POL__M;
2251 else 2191 else
2252 data &= ~SCU_RAM_AGC_CONFIG_INV_RF_POL__M; 2192 data &= ~SCU_RAM_AGC_CONFIG_INV_RF_POL__M;
@@ -2260,7 +2200,7 @@ static int SetAgcRf(struct drxk_state *state,
2260 goto error; 2200 goto error;
2261 2201
2262 data &= ~SCU_RAM_AGC_KI_RED_RAGC_RED__M; 2202 data &= ~SCU_RAM_AGC_KI_RED_RAGC_RED__M;
2263 data |= (~(pAgcCfg->speed << 2203 data |= (~(p_agc_cfg->speed <<
2264 SCU_RAM_AGC_KI_RED_RAGC_RED__B) 2204 SCU_RAM_AGC_KI_RED_RAGC_RED__B)
2265 & SCU_RAM_AGC_KI_RED_RAGC_RED__M); 2205 & SCU_RAM_AGC_KI_RED_RAGC_RED__M);
2266 2206
@@ -2268,30 +2208,34 @@ static int SetAgcRf(struct drxk_state *state,
2268 if (status < 0) 2208 if (status < 0)
2269 goto error; 2209 goto error;
2270 2210
2271 if (IsDVBT(state)) 2211 if (is_dvbt(state))
2272 pIfAgcSettings = &state->m_dvbtIfAgcCfg; 2212 p_if_agc_settings = &state->m_dvbt_if_agc_cfg;
2273 else if (IsQAM(state)) 2213 else if (is_qam(state))
2274 pIfAgcSettings = &state->m_qamIfAgcCfg; 2214 p_if_agc_settings = &state->m_qam_if_agc_cfg;
2275 else 2215 else
2276 pIfAgcSettings = &state->m_atvIfAgcCfg; 2216 p_if_agc_settings = &state->m_atv_if_agc_cfg;
2277 if (pIfAgcSettings == NULL) { 2217 if (p_if_agc_settings == NULL) {
2278 status = -EINVAL; 2218 status = -EINVAL;
2279 goto error; 2219 goto error;
2280 } 2220 }
2281 2221
2282 /* Set TOP, only if IF-AGC is in AUTO mode */ 2222 /* Set TOP, only if IF-AGC is in AUTO mode */
2283 if (pIfAgcSettings->ctrlMode == DRXK_AGC_CTRL_AUTO) 2223 if (p_if_agc_settings->ctrl_mode == DRXK_AGC_CTRL_AUTO)
2284 status = write16(state, SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A, pAgcCfg->top); 2224 status = write16(state,
2225 SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A,
2226 p_agc_cfg->top);
2285 if (status < 0) 2227 if (status < 0)
2286 goto error; 2228 goto error;
2287 2229
2288 /* Cut-Off current */ 2230 /* Cut-Off current */
2289 status = write16(state, SCU_RAM_AGC_RF_IACCU_HI_CO__A, pAgcCfg->cutOffCurrent); 2231 status = write16(state, SCU_RAM_AGC_RF_IACCU_HI_CO__A,
2232 p_agc_cfg->cut_off_current);
2290 if (status < 0) 2233 if (status < 0)
2291 goto error; 2234 goto error;
2292 2235
2293 /* Max. output level */ 2236 /* Max. output level */
2294 status = write16(state, SCU_RAM_AGC_RF_MAX__A, pAgcCfg->maxOutputLevel); 2237 status = write16(state, SCU_RAM_AGC_RF_MAX__A,
2238 p_agc_cfg->max_output_level);
2295 if (status < 0) 2239 if (status < 0)
2296 goto error; 2240 goto error;
2297 2241
@@ -2312,7 +2256,7 @@ static int SetAgcRf(struct drxk_state *state,
2312 if (status < 0) 2256 if (status < 0)
2313 goto error; 2257 goto error;
2314 data |= SCU_RAM_AGC_CONFIG_DISABLE_RF_AGC__M; 2258 data |= SCU_RAM_AGC_CONFIG_DISABLE_RF_AGC__M;
2315 if (state->m_RfAgcPol) 2259 if (state->m_rf_agc_pol)
2316 data |= SCU_RAM_AGC_CONFIG_INV_RF_POL__M; 2260 data |= SCU_RAM_AGC_CONFIG_INV_RF_POL__M;
2317 else 2261 else
2318 data &= ~SCU_RAM_AGC_CONFIG_INV_RF_POL__M; 2262 data &= ~SCU_RAM_AGC_CONFIG_INV_RF_POL__M;
@@ -2326,7 +2270,8 @@ static int SetAgcRf(struct drxk_state *state,
2326 goto error; 2270 goto error;
2327 2271
2328 /* Write value to output pin */ 2272 /* Write value to output pin */
2329 status = write16(state, SCU_RAM_AGC_RF_IACCU_HI__A, pAgcCfg->outputLevel); 2273 status = write16(state, SCU_RAM_AGC_RF_IACCU_HI__A,
2274 p_agc_cfg->output_level);
2330 if (status < 0) 2275 if (status < 0)
2331 goto error; 2276 goto error;
2332 break; 2277 break;
@@ -2357,22 +2302,22 @@ static int SetAgcRf(struct drxk_state *state,
2357 } 2302 }
2358error: 2303error:
2359 if (status < 0) 2304 if (status < 0)
2360 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 2305 pr_err("Error %d on %s\n", status, __func__);
2361 return status; 2306 return status;
2362} 2307}
2363 2308
2364#define SCU_RAM_AGC_KI_INV_IF_POL__M 0x2000 2309#define SCU_RAM_AGC_KI_INV_IF_POL__M 0x2000
2365 2310
2366static int SetAgcIf(struct drxk_state *state, 2311static int set_agc_if(struct drxk_state *state,
2367 struct SCfgAgc *pAgcCfg, bool isDTV) 2312 struct s_cfg_agc *p_agc_cfg, bool is_dtv)
2368{ 2313{
2369 u16 data = 0; 2314 u16 data = 0;
2370 int status = 0; 2315 int status = 0;
2371 struct SCfgAgc *pRfAgcSettings; 2316 struct s_cfg_agc *p_rf_agc_settings;
2372 2317
2373 dprintk(1, "\n"); 2318 dprintk(1, "\n");
2374 2319
2375 switch (pAgcCfg->ctrlMode) { 2320 switch (p_agc_cfg->ctrl_mode) {
2376 case DRXK_AGC_CTRL_AUTO: 2321 case DRXK_AGC_CTRL_AUTO:
2377 2322
2378 /* Enable IF AGC DAC */ 2323 /* Enable IF AGC DAC */
@@ -2392,7 +2337,7 @@ static int SetAgcIf(struct drxk_state *state,
2392 data &= ~SCU_RAM_AGC_CONFIG_DISABLE_IF_AGC__M; 2337 data &= ~SCU_RAM_AGC_CONFIG_DISABLE_IF_AGC__M;
2393 2338
2394 /* Polarity */ 2339 /* Polarity */
2395 if (state->m_IfAgcPol) 2340 if (state->m_if_agc_pol)
2396 data |= SCU_RAM_AGC_CONFIG_INV_IF_POL__M; 2341 data |= SCU_RAM_AGC_CONFIG_INV_IF_POL__M;
2397 else 2342 else
2398 data &= ~SCU_RAM_AGC_CONFIG_INV_IF_POL__M; 2343 data &= ~SCU_RAM_AGC_CONFIG_INV_IF_POL__M;
@@ -2405,7 +2350,7 @@ static int SetAgcIf(struct drxk_state *state,
2405 if (status < 0) 2350 if (status < 0)
2406 goto error; 2351 goto error;
2407 data &= ~SCU_RAM_AGC_KI_RED_IAGC_RED__M; 2352 data &= ~SCU_RAM_AGC_KI_RED_IAGC_RED__M;
2408 data |= (~(pAgcCfg->speed << 2353 data |= (~(p_agc_cfg->speed <<
2409 SCU_RAM_AGC_KI_RED_IAGC_RED__B) 2354 SCU_RAM_AGC_KI_RED_IAGC_RED__B)
2410 & SCU_RAM_AGC_KI_RED_IAGC_RED__M); 2355 & SCU_RAM_AGC_KI_RED_IAGC_RED__M);
2411 2356
@@ -2413,14 +2358,15 @@ static int SetAgcIf(struct drxk_state *state,
2413 if (status < 0) 2358 if (status < 0)
2414 goto error; 2359 goto error;
2415 2360
2416 if (IsQAM(state)) 2361 if (is_qam(state))
2417 pRfAgcSettings = &state->m_qamRfAgcCfg; 2362 p_rf_agc_settings = &state->m_qam_rf_agc_cfg;
2418 else 2363 else
2419 pRfAgcSettings = &state->m_atvRfAgcCfg; 2364 p_rf_agc_settings = &state->m_atv_rf_agc_cfg;
2420 if (pRfAgcSettings == NULL) 2365 if (p_rf_agc_settings == NULL)
2421 return -1; 2366 return -1;
2422 /* Restore TOP */ 2367 /* Restore TOP */
2423 status = write16(state, SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A, pRfAgcSettings->top); 2368 status = write16(state, SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A,
2369 p_rf_agc_settings->top);
2424 if (status < 0) 2370 if (status < 0)
2425 goto error; 2371 goto error;
2426 break; 2372 break;
@@ -2444,7 +2390,7 @@ static int SetAgcIf(struct drxk_state *state,
2444 data |= SCU_RAM_AGC_CONFIG_DISABLE_IF_AGC__M; 2390 data |= SCU_RAM_AGC_CONFIG_DISABLE_IF_AGC__M;
2445 2391
2446 /* Polarity */ 2392 /* Polarity */
2447 if (state->m_IfAgcPol) 2393 if (state->m_if_agc_pol)
2448 data |= SCU_RAM_AGC_CONFIG_INV_IF_POL__M; 2394 data |= SCU_RAM_AGC_CONFIG_INV_IF_POL__M;
2449 else 2395 else
2450 data &= ~SCU_RAM_AGC_CONFIG_INV_IF_POL__M; 2396 data &= ~SCU_RAM_AGC_CONFIG_INV_IF_POL__M;
@@ -2453,7 +2399,8 @@ static int SetAgcIf(struct drxk_state *state,
2453 goto error; 2399 goto error;
2454 2400
2455 /* Write value to output pin */ 2401 /* Write value to output pin */
2456 status = write16(state, SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A, pAgcCfg->outputLevel); 2402 status = write16(state, SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A,
2403 p_agc_cfg->output_level);
2457 if (status < 0) 2404 if (status < 0)
2458 goto error; 2405 goto error;
2459 break; 2406 break;
@@ -2478,176 +2425,181 @@ static int SetAgcIf(struct drxk_state *state,
2478 if (status < 0) 2425 if (status < 0)
2479 goto error; 2426 goto error;
2480 break; 2427 break;
2481 } /* switch (agcSettingsIf->ctrlMode) */ 2428 } /* switch (agcSettingsIf->ctrl_mode) */
2482 2429
2483 /* always set the top to support 2430 /* always set the top to support
2484 configurations without if-loop */ 2431 configurations without if-loop */
2485 status = write16(state, SCU_RAM_AGC_INGAIN_TGT_MIN__A, pAgcCfg->top); 2432 status = write16(state, SCU_RAM_AGC_INGAIN_TGT_MIN__A, p_agc_cfg->top);
2486error: 2433error:
2487 if (status < 0) 2434 if (status < 0)
2488 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 2435 pr_err("Error %d on %s\n", status, __func__);
2489 return status; 2436 return status;
2490} 2437}
2491 2438
2492static int GetQAMSignalToNoise(struct drxk_state *state, 2439static int get_qam_signal_to_noise(struct drxk_state *state,
2493 s32 *pSignalToNoise) 2440 s32 *p_signal_to_noise)
2494{ 2441{
2495 int status = 0; 2442 int status = 0;
2496 u16 qamSlErrPower = 0; /* accum. error between 2443 u16 qam_sl_err_power = 0; /* accum. error between
2497 raw and sliced symbols */ 2444 raw and sliced symbols */
2498 u32 qamSlSigPower = 0; /* used for MER, depends of 2445 u32 qam_sl_sig_power = 0; /* used for MER, depends of
2499 QAM modulation */ 2446 QAM modulation */
2500 u32 qamSlMer = 0; /* QAM MER */ 2447 u32 qam_sl_mer = 0; /* QAM MER */
2501 2448
2502 dprintk(1, "\n"); 2449 dprintk(1, "\n");
2503 2450
2504 /* MER calculation */ 2451 /* MER calculation */
2505 2452
2506 /* get the register value needed for MER */ 2453 /* get the register value needed for MER */
2507 status = read16(state, QAM_SL_ERR_POWER__A, &qamSlErrPower); 2454 status = read16(state, QAM_SL_ERR_POWER__A, &qam_sl_err_power);
2508 if (status < 0) { 2455 if (status < 0) {
2509 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 2456 pr_err("Error %d on %s\n", status, __func__);
2510 return -EINVAL; 2457 return -EINVAL;
2511 } 2458 }
2512 2459
2513 switch (state->props.modulation) { 2460 switch (state->props.modulation) {
2514 case QAM_16: 2461 case QAM_16:
2515 qamSlSigPower = DRXK_QAM_SL_SIG_POWER_QAM16 << 2; 2462 qam_sl_sig_power = DRXK_QAM_SL_SIG_POWER_QAM16 << 2;
2516 break; 2463 break;
2517 case QAM_32: 2464 case QAM_32:
2518 qamSlSigPower = DRXK_QAM_SL_SIG_POWER_QAM32 << 2; 2465 qam_sl_sig_power = DRXK_QAM_SL_SIG_POWER_QAM32 << 2;
2519 break; 2466 break;
2520 case QAM_64: 2467 case QAM_64:
2521 qamSlSigPower = DRXK_QAM_SL_SIG_POWER_QAM64 << 2; 2468 qam_sl_sig_power = DRXK_QAM_SL_SIG_POWER_QAM64 << 2;
2522 break; 2469 break;
2523 case QAM_128: 2470 case QAM_128:
2524 qamSlSigPower = DRXK_QAM_SL_SIG_POWER_QAM128 << 2; 2471 qam_sl_sig_power = DRXK_QAM_SL_SIG_POWER_QAM128 << 2;
2525 break; 2472 break;
2526 default: 2473 default:
2527 case QAM_256: 2474 case QAM_256:
2528 qamSlSigPower = DRXK_QAM_SL_SIG_POWER_QAM256 << 2; 2475 qam_sl_sig_power = DRXK_QAM_SL_SIG_POWER_QAM256 << 2;
2529 break; 2476 break;
2530 } 2477 }
2531 2478
2532 if (qamSlErrPower > 0) { 2479 if (qam_sl_err_power > 0) {
2533 qamSlMer = Log10Times100(qamSlSigPower) - 2480 qam_sl_mer = log10times100(qam_sl_sig_power) -
2534 Log10Times100((u32) qamSlErrPower); 2481 log10times100((u32) qam_sl_err_power);
2535 } 2482 }
2536 *pSignalToNoise = qamSlMer; 2483 *p_signal_to_noise = qam_sl_mer;
2537 2484
2538 return status; 2485 return status;
2539} 2486}
2540 2487
2541static int GetDVBTSignalToNoise(struct drxk_state *state, 2488static int get_dvbt_signal_to_noise(struct drxk_state *state,
2542 s32 *pSignalToNoise) 2489 s32 *p_signal_to_noise)
2543{ 2490{
2544 int status; 2491 int status;
2545 u16 regData = 0; 2492 u16 reg_data = 0;
2546 u32 EqRegTdSqrErrI = 0; 2493 u32 eq_reg_td_sqr_err_i = 0;
2547 u32 EqRegTdSqrErrQ = 0; 2494 u32 eq_reg_td_sqr_err_q = 0;
2548 u16 EqRegTdSqrErrExp = 0; 2495 u16 eq_reg_td_sqr_err_exp = 0;
2549 u16 EqRegTdTpsPwrOfs = 0; 2496 u16 eq_reg_td_tps_pwr_ofs = 0;
2550 u16 EqRegTdReqSmbCnt = 0; 2497 u16 eq_reg_td_req_smb_cnt = 0;
2551 u32 tpsCnt = 0; 2498 u32 tps_cnt = 0;
2552 u32 SqrErrIQ = 0; 2499 u32 sqr_err_iq = 0;
2553 u32 a = 0; 2500 u32 a = 0;
2554 u32 b = 0; 2501 u32 b = 0;
2555 u32 c = 0; 2502 u32 c = 0;
2556 u32 iMER = 0; 2503 u32 i_mer = 0;
2557 u16 transmissionParams = 0; 2504 u16 transmission_params = 0;
2558 2505
2559 dprintk(1, "\n"); 2506 dprintk(1, "\n");
2560 2507
2561 status = read16(state, OFDM_EQ_TOP_TD_TPS_PWR_OFS__A, &EqRegTdTpsPwrOfs); 2508 status = read16(state, OFDM_EQ_TOP_TD_TPS_PWR_OFS__A,
2509 &eq_reg_td_tps_pwr_ofs);
2562 if (status < 0) 2510 if (status < 0)
2563 goto error; 2511 goto error;
2564 status = read16(state, OFDM_EQ_TOP_TD_REQ_SMB_CNT__A, &EqRegTdReqSmbCnt); 2512 status = read16(state, OFDM_EQ_TOP_TD_REQ_SMB_CNT__A,
2513 &eq_reg_td_req_smb_cnt);
2565 if (status < 0) 2514 if (status < 0)
2566 goto error; 2515 goto error;
2567 status = read16(state, OFDM_EQ_TOP_TD_SQR_ERR_EXP__A, &EqRegTdSqrErrExp); 2516 status = read16(state, OFDM_EQ_TOP_TD_SQR_ERR_EXP__A,
2517 &eq_reg_td_sqr_err_exp);
2568 if (status < 0) 2518 if (status < 0)
2569 goto error; 2519 goto error;
2570 status = read16(state, OFDM_EQ_TOP_TD_SQR_ERR_I__A, &regData); 2520 status = read16(state, OFDM_EQ_TOP_TD_SQR_ERR_I__A,
2521 &reg_data);
2571 if (status < 0) 2522 if (status < 0)
2572 goto error; 2523 goto error;
2573 /* Extend SQR_ERR_I operational range */ 2524 /* Extend SQR_ERR_I operational range */
2574 EqRegTdSqrErrI = (u32) regData; 2525 eq_reg_td_sqr_err_i = (u32) reg_data;
2575 if ((EqRegTdSqrErrExp > 11) && 2526 if ((eq_reg_td_sqr_err_exp > 11) &&
2576 (EqRegTdSqrErrI < 0x00000FFFUL)) { 2527 (eq_reg_td_sqr_err_i < 0x00000FFFUL)) {
2577 EqRegTdSqrErrI += 0x00010000UL; 2528 eq_reg_td_sqr_err_i += 0x00010000UL;
2578 } 2529 }
2579 status = read16(state, OFDM_EQ_TOP_TD_SQR_ERR_Q__A, &regData); 2530 status = read16(state, OFDM_EQ_TOP_TD_SQR_ERR_Q__A, &reg_data);
2580 if (status < 0) 2531 if (status < 0)
2581 goto error; 2532 goto error;
2582 /* Extend SQR_ERR_Q operational range */ 2533 /* Extend SQR_ERR_Q operational range */
2583 EqRegTdSqrErrQ = (u32) regData; 2534 eq_reg_td_sqr_err_q = (u32) reg_data;
2584 if ((EqRegTdSqrErrExp > 11) && 2535 if ((eq_reg_td_sqr_err_exp > 11) &&
2585 (EqRegTdSqrErrQ < 0x00000FFFUL)) 2536 (eq_reg_td_sqr_err_q < 0x00000FFFUL))
2586 EqRegTdSqrErrQ += 0x00010000UL; 2537 eq_reg_td_sqr_err_q += 0x00010000UL;
2587 2538
2588 status = read16(state, OFDM_SC_RA_RAM_OP_PARAM__A, &transmissionParams); 2539 status = read16(state, OFDM_SC_RA_RAM_OP_PARAM__A,
2540 &transmission_params);
2589 if (status < 0) 2541 if (status < 0)
2590 goto error; 2542 goto error;
2591 2543
2592 /* Check input data for MER */ 2544 /* Check input data for MER */
2593 2545
2594 /* MER calculation (in 0.1 dB) without math.h */ 2546 /* MER calculation (in 0.1 dB) without math.h */
2595 if ((EqRegTdTpsPwrOfs == 0) || (EqRegTdReqSmbCnt == 0)) 2547 if ((eq_reg_td_tps_pwr_ofs == 0) || (eq_reg_td_req_smb_cnt == 0))
2596 iMER = 0; 2548 i_mer = 0;
2597 else if ((EqRegTdSqrErrI + EqRegTdSqrErrQ) == 0) { 2549 else if ((eq_reg_td_sqr_err_i + eq_reg_td_sqr_err_q) == 0) {
2598 /* No error at all, this must be the HW reset value 2550 /* No error at all, this must be the HW reset value
2599 * Apparently no first measurement yet 2551 * Apparently no first measurement yet
2600 * Set MER to 0.0 */ 2552 * Set MER to 0.0 */
2601 iMER = 0; 2553 i_mer = 0;
2602 } else { 2554 } else {
2603 SqrErrIQ = (EqRegTdSqrErrI + EqRegTdSqrErrQ) << 2555 sqr_err_iq = (eq_reg_td_sqr_err_i + eq_reg_td_sqr_err_q) <<
2604 EqRegTdSqrErrExp; 2556 eq_reg_td_sqr_err_exp;
2605 if ((transmissionParams & 2557 if ((transmission_params &
2606 OFDM_SC_RA_RAM_OP_PARAM_MODE__M) 2558 OFDM_SC_RA_RAM_OP_PARAM_MODE__M)
2607 == OFDM_SC_RA_RAM_OP_PARAM_MODE_2K) 2559 == OFDM_SC_RA_RAM_OP_PARAM_MODE_2K)
2608 tpsCnt = 17; 2560 tps_cnt = 17;
2609 else 2561 else
2610 tpsCnt = 68; 2562 tps_cnt = 68;
2611 2563
2612 /* IMER = 100 * log10 (x) 2564 /* IMER = 100 * log10 (x)
2613 where x = (EqRegTdTpsPwrOfs^2 * 2565 where x = (eq_reg_td_tps_pwr_ofs^2 *
2614 EqRegTdReqSmbCnt * tpsCnt)/SqrErrIQ 2566 eq_reg_td_req_smb_cnt * tps_cnt)/sqr_err_iq
2615 2567
2616 => IMER = a + b -c 2568 => IMER = a + b -c
2617 where a = 100 * log10 (EqRegTdTpsPwrOfs^2) 2569 where a = 100 * log10 (eq_reg_td_tps_pwr_ofs^2)
2618 b = 100 * log10 (EqRegTdReqSmbCnt * tpsCnt) 2570 b = 100 * log10 (eq_reg_td_req_smb_cnt * tps_cnt)
2619 c = 100 * log10 (SqrErrIQ) 2571 c = 100 * log10 (sqr_err_iq)
2620 */ 2572 */
2621 2573
2622 /* log(x) x = 9bits * 9bits->18 bits */ 2574 /* log(x) x = 9bits * 9bits->18 bits */
2623 a = Log10Times100(EqRegTdTpsPwrOfs * 2575 a = log10times100(eq_reg_td_tps_pwr_ofs *
2624 EqRegTdTpsPwrOfs); 2576 eq_reg_td_tps_pwr_ofs);
2625 /* log(x) x = 16bits * 7bits->23 bits */ 2577 /* log(x) x = 16bits * 7bits->23 bits */
2626 b = Log10Times100(EqRegTdReqSmbCnt * tpsCnt); 2578 b = log10times100(eq_reg_td_req_smb_cnt * tps_cnt);
2627 /* log(x) x = (16bits + 16bits) << 15 ->32 bits */ 2579 /* log(x) x = (16bits + 16bits) << 15 ->32 bits */
2628 c = Log10Times100(SqrErrIQ); 2580 c = log10times100(sqr_err_iq);
2629 2581
2630 iMER = a + b - c; 2582 i_mer = a + b - c;
2631 } 2583 }
2632 *pSignalToNoise = iMER; 2584 *p_signal_to_noise = i_mer;
2633 2585
2634error: 2586error:
2635 if (status < 0) 2587 if (status < 0)
2636 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 2588 pr_err("Error %d on %s\n", status, __func__);
2637 return status; 2589 return status;
2638} 2590}
2639 2591
2640static int GetSignalToNoise(struct drxk_state *state, s32 *pSignalToNoise) 2592static int get_signal_to_noise(struct drxk_state *state, s32 *p_signal_to_noise)
2641{ 2593{
2642 dprintk(1, "\n"); 2594 dprintk(1, "\n");
2643 2595
2644 *pSignalToNoise = 0; 2596 *p_signal_to_noise = 0;
2645 switch (state->m_OperationMode) { 2597 switch (state->m_operation_mode) {
2646 case OM_DVBT: 2598 case OM_DVBT:
2647 return GetDVBTSignalToNoise(state, pSignalToNoise); 2599 return get_dvbt_signal_to_noise(state, p_signal_to_noise);
2648 case OM_QAM_ITU_A: 2600 case OM_QAM_ITU_A:
2649 case OM_QAM_ITU_C: 2601 case OM_QAM_ITU_C:
2650 return GetQAMSignalToNoise(state, pSignalToNoise); 2602 return get_qam_signal_to_noise(state, p_signal_to_noise);
2651 default: 2603 default:
2652 break; 2604 break;
2653 } 2605 }
@@ -2655,7 +2607,7 @@ static int GetSignalToNoise(struct drxk_state *state, s32 *pSignalToNoise)
2655} 2607}
2656 2608
2657#if 0 2609#if 0
2658static int GetDVBTQuality(struct drxk_state *state, s32 *pQuality) 2610static int get_dvbt_quality(struct drxk_state *state, s32 *p_quality)
2659{ 2611{
2660 /* SNR Values for quasi errorfree reception rom Nordig 2.2 */ 2612 /* SNR Values for quasi errorfree reception rom Nordig 2.2 */
2661 int status = 0; 2613 int status = 0;
@@ -2680,102 +2632,104 @@ static int GetDVBTQuality(struct drxk_state *state, s32 *pQuality)
2680 225, /* 64-QAM 7/8 */ 2632 225, /* 64-QAM 7/8 */
2681 }; 2633 };
2682 2634
2683 *pQuality = 0; 2635 *p_quality = 0;
2684 2636
2685 do { 2637 do {
2686 s32 SignalToNoise = 0; 2638 s32 signal_to_noise = 0;
2687 u16 Constellation = 0; 2639 u16 constellation = 0;
2688 u16 CodeRate = 0; 2640 u16 code_rate = 0;
2689 u32 SignalToNoiseRel; 2641 u32 signal_to_noise_rel;
2690 u32 BERQuality; 2642 u32 ber_quality;
2691 2643
2692 status = GetDVBTSignalToNoise(state, &SignalToNoise); 2644 status = get_dvbt_signal_to_noise(state, &signal_to_noise);
2693 if (status < 0) 2645 if (status < 0)
2694 break; 2646 break;
2695 status = read16(state, OFDM_EQ_TOP_TD_TPS_CONST__A, &Constellation); 2647 status = read16(state, OFDM_EQ_TOP_TD_TPS_CONST__A,
2648 &constellation);
2696 if (status < 0) 2649 if (status < 0)
2697 break; 2650 break;
2698 Constellation &= OFDM_EQ_TOP_TD_TPS_CONST__M; 2651 constellation &= OFDM_EQ_TOP_TD_TPS_CONST__M;
2699 2652
2700 status = read16(state, OFDM_EQ_TOP_TD_TPS_CODE_HP__A, &CodeRate); 2653 status = read16(state, OFDM_EQ_TOP_TD_TPS_CODE_HP__A,
2654 &code_rate);
2701 if (status < 0) 2655 if (status < 0)
2702 break; 2656 break;
2703 CodeRate &= OFDM_EQ_TOP_TD_TPS_CODE_HP__M; 2657 code_rate &= OFDM_EQ_TOP_TD_TPS_CODE_HP__M;
2704 2658
2705 if (Constellation > OFDM_EQ_TOP_TD_TPS_CONST_64QAM || 2659 if (constellation > OFDM_EQ_TOP_TD_TPS_CONST_64QAM ||
2706 CodeRate > OFDM_EQ_TOP_TD_TPS_CODE_LP_7_8) 2660 code_rate > OFDM_EQ_TOP_TD_TPS_CODE_LP_7_8)
2707 break; 2661 break;
2708 SignalToNoiseRel = SignalToNoise - 2662 signal_to_noise_rel = signal_to_noise -
2709 QE_SN[Constellation * 5 + CodeRate]; 2663 QE_SN[constellation * 5 + code_rate];
2710 BERQuality = 100; 2664 ber_quality = 100;
2711 2665
2712 if (SignalToNoiseRel < -70) 2666 if (signal_to_noise_rel < -70)
2713 *pQuality = 0; 2667 *p_quality = 0;
2714 else if (SignalToNoiseRel < 30) 2668 else if (signal_to_noise_rel < 30)
2715 *pQuality = ((SignalToNoiseRel + 70) * 2669 *p_quality = ((signal_to_noise_rel + 70) *
2716 BERQuality) / 100; 2670 ber_quality) / 100;
2717 else 2671 else
2718 *pQuality = BERQuality; 2672 *p_quality = ber_quality;
2719 } while (0); 2673 } while (0);
2720 return 0; 2674 return 0;
2721}; 2675};
2722 2676
2723static int GetDVBCQuality(struct drxk_state *state, s32 *pQuality) 2677static int get_dvbc_quality(struct drxk_state *state, s32 *p_quality)
2724{ 2678{
2725 int status = 0; 2679 int status = 0;
2726 *pQuality = 0; 2680 *p_quality = 0;
2727 2681
2728 dprintk(1, "\n"); 2682 dprintk(1, "\n");
2729 2683
2730 do { 2684 do {
2731 u32 SignalToNoise = 0; 2685 u32 signal_to_noise = 0;
2732 u32 BERQuality = 100; 2686 u32 ber_quality = 100;
2733 u32 SignalToNoiseRel = 0; 2687 u32 signal_to_noise_rel = 0;
2734 2688
2735 status = GetQAMSignalToNoise(state, &SignalToNoise); 2689 status = get_qam_signal_to_noise(state, &signal_to_noise);
2736 if (status < 0) 2690 if (status < 0)
2737 break; 2691 break;
2738 2692
2739 switch (state->props.modulation) { 2693 switch (state->props.modulation) {
2740 case QAM_16: 2694 case QAM_16:
2741 SignalToNoiseRel = SignalToNoise - 200; 2695 signal_to_noise_rel = signal_to_noise - 200;
2742 break; 2696 break;
2743 case QAM_32: 2697 case QAM_32:
2744 SignalToNoiseRel = SignalToNoise - 230; 2698 signal_to_noise_rel = signal_to_noise - 230;
2745 break; /* Not in NorDig */ 2699 break; /* Not in NorDig */
2746 case QAM_64: 2700 case QAM_64:
2747 SignalToNoiseRel = SignalToNoise - 260; 2701 signal_to_noise_rel = signal_to_noise - 260;
2748 break; 2702 break;
2749 case QAM_128: 2703 case QAM_128:
2750 SignalToNoiseRel = SignalToNoise - 290; 2704 signal_to_noise_rel = signal_to_noise - 290;
2751 break; 2705 break;
2752 default: 2706 default:
2753 case QAM_256: 2707 case QAM_256:
2754 SignalToNoiseRel = SignalToNoise - 320; 2708 signal_to_noise_rel = signal_to_noise - 320;
2755 break; 2709 break;
2756 } 2710 }
2757 2711
2758 if (SignalToNoiseRel < -70) 2712 if (signal_to_noise_rel < -70)
2759 *pQuality = 0; 2713 *p_quality = 0;
2760 else if (SignalToNoiseRel < 30) 2714 else if (signal_to_noise_rel < 30)
2761 *pQuality = ((SignalToNoiseRel + 70) * 2715 *p_quality = ((signal_to_noise_rel + 70) *
2762 BERQuality) / 100; 2716 ber_quality) / 100;
2763 else 2717 else
2764 *pQuality = BERQuality; 2718 *p_quality = ber_quality;
2765 } while (0); 2719 } while (0);
2766 2720
2767 return status; 2721 return status;
2768} 2722}
2769 2723
2770static int GetQuality(struct drxk_state *state, s32 *pQuality) 2724static int get_quality(struct drxk_state *state, s32 *p_quality)
2771{ 2725{
2772 dprintk(1, "\n"); 2726 dprintk(1, "\n");
2773 2727
2774 switch (state->m_OperationMode) { 2728 switch (state->m_operation_mode) {
2775 case OM_DVBT: 2729 case OM_DVBT:
2776 return GetDVBTQuality(state, pQuality); 2730 return get_dvbt_quality(state, p_quality);
2777 case OM_QAM_ITU_A: 2731 case OM_QAM_ITU_A:
2778 return GetDVBCQuality(state, pQuality); 2732 return get_dvbc_quality(state, p_quality);
2779 default: 2733 default:
2780 break; 2734 break;
2781 } 2735 }
@@ -2797,65 +2751,68 @@ static int GetQuality(struct drxk_state *state, s32 *pQuality)
2797#define DRXDAP_FASI_ADDR2BANK(addr) (((addr) >> 16) & 0x3F) 2751#define DRXDAP_FASI_ADDR2BANK(addr) (((addr) >> 16) & 0x3F)
2798#define DRXDAP_FASI_ADDR2OFFSET(addr) ((addr) & 0x7FFF) 2752#define DRXDAP_FASI_ADDR2OFFSET(addr) ((addr) & 0x7FFF)
2799 2753
2800static int ConfigureI2CBridge(struct drxk_state *state, bool bEnableBridge) 2754static int ConfigureI2CBridge(struct drxk_state *state, bool b_enable_bridge)
2801{ 2755{
2802 int status = -EINVAL; 2756 int status = -EINVAL;
2803 2757
2804 dprintk(1, "\n"); 2758 dprintk(1, "\n");
2805 2759
2806 if (state->m_DrxkState == DRXK_UNINITIALIZED) 2760 if (state->m_drxk_state == DRXK_UNINITIALIZED)
2807 return 0; 2761 return 0;
2808 if (state->m_DrxkState == DRXK_POWERED_DOWN) 2762 if (state->m_drxk_state == DRXK_POWERED_DOWN)
2809 goto error; 2763 goto error;
2810 2764
2811 if (state->no_i2c_bridge) 2765 if (state->no_i2c_bridge)
2812 return 0; 2766 return 0;
2813 2767
2814 status = write16(state, SIO_HI_RA_RAM_PAR_1__A, SIO_HI_RA_RAM_PAR_1_PAR1_SEC_KEY); 2768 status = write16(state, SIO_HI_RA_RAM_PAR_1__A,
2769 SIO_HI_RA_RAM_PAR_1_PAR1_SEC_KEY);
2815 if (status < 0) 2770 if (status < 0)
2816 goto error; 2771 goto error;
2817 if (bEnableBridge) { 2772 if (b_enable_bridge) {
2818 status = write16(state, SIO_HI_RA_RAM_PAR_2__A, SIO_HI_RA_RAM_PAR_2_BRD_CFG_CLOSED); 2773 status = write16(state, SIO_HI_RA_RAM_PAR_2__A,
2774 SIO_HI_RA_RAM_PAR_2_BRD_CFG_CLOSED);
2819 if (status < 0) 2775 if (status < 0)
2820 goto error; 2776 goto error;
2821 } else { 2777 } else {
2822 status = write16(state, SIO_HI_RA_RAM_PAR_2__A, SIO_HI_RA_RAM_PAR_2_BRD_CFG_OPEN); 2778 status = write16(state, SIO_HI_RA_RAM_PAR_2__A,
2779 SIO_HI_RA_RAM_PAR_2_BRD_CFG_OPEN);
2823 if (status < 0) 2780 if (status < 0)
2824 goto error; 2781 goto error;
2825 } 2782 }
2826 2783
2827 status = HI_Command(state, SIO_HI_RA_RAM_CMD_BRDCTRL, 0); 2784 status = hi_command(state, SIO_HI_RA_RAM_CMD_BRDCTRL, 0);
2828 2785
2829error: 2786error:
2830 if (status < 0) 2787 if (status < 0)
2831 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 2788 pr_err("Error %d on %s\n", status, __func__);
2832 return status; 2789 return status;
2833} 2790}
2834 2791
2835static int SetPreSaw(struct drxk_state *state, 2792static int set_pre_saw(struct drxk_state *state,
2836 struct SCfgPreSaw *pPreSawCfg) 2793 struct s_cfg_pre_saw *p_pre_saw_cfg)
2837{ 2794{
2838 int status = -EINVAL; 2795 int status = -EINVAL;
2839 2796
2840 dprintk(1, "\n"); 2797 dprintk(1, "\n");
2841 2798
2842 if ((pPreSawCfg == NULL) 2799 if ((p_pre_saw_cfg == NULL)
2843 || (pPreSawCfg->reference > IQM_AF_PDREF__M)) 2800 || (p_pre_saw_cfg->reference > IQM_AF_PDREF__M))
2844 goto error; 2801 goto error;
2845 2802
2846 status = write16(state, IQM_AF_PDREF__A, pPreSawCfg->reference); 2803 status = write16(state, IQM_AF_PDREF__A, p_pre_saw_cfg->reference);
2847error: 2804error:
2848 if (status < 0) 2805 if (status < 0)
2849 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 2806 pr_err("Error %d on %s\n", status, __func__);
2850 return status; 2807 return status;
2851} 2808}
2852 2809
2853static int BLDirectCmd(struct drxk_state *state, u32 targetAddr, 2810static int bl_direct_cmd(struct drxk_state *state, u32 target_addr,
2854 u16 romOffset, u16 nrOfElements, u32 timeOut) 2811 u16 rom_offset, u16 nr_of_elements, u32 time_out)
2855{ 2812{
2856 u16 blStatus = 0; 2813 u16 bl_status = 0;
2857 u16 offset = (u16) ((targetAddr >> 0) & 0x00FFFF); 2814 u16 offset = (u16) ((target_addr >> 0) & 0x00FFFF);
2858 u16 blockbank = (u16) ((targetAddr >> 16) & 0x000FFF); 2815 u16 blockbank = (u16) ((target_addr >> 16) & 0x000FFF);
2859 int status; 2816 int status;
2860 unsigned long end; 2817 unsigned long end;
2861 2818
@@ -2871,44 +2828,44 @@ static int BLDirectCmd(struct drxk_state *state, u32 targetAddr,
2871 status = write16(state, SIO_BL_TGT_ADDR__A, offset); 2828 status = write16(state, SIO_BL_TGT_ADDR__A, offset);
2872 if (status < 0) 2829 if (status < 0)
2873 goto error; 2830 goto error;
2874 status = write16(state, SIO_BL_SRC_ADDR__A, romOffset); 2831 status = write16(state, SIO_BL_SRC_ADDR__A, rom_offset);
2875 if (status < 0) 2832 if (status < 0)
2876 goto error; 2833 goto error;
2877 status = write16(state, SIO_BL_SRC_LEN__A, nrOfElements); 2834 status = write16(state, SIO_BL_SRC_LEN__A, nr_of_elements);
2878 if (status < 0) 2835 if (status < 0)
2879 goto error; 2836 goto error;
2880 status = write16(state, SIO_BL_ENABLE__A, SIO_BL_ENABLE_ON); 2837 status = write16(state, SIO_BL_ENABLE__A, SIO_BL_ENABLE_ON);
2881 if (status < 0) 2838 if (status < 0)
2882 goto error; 2839 goto error;
2883 2840
2884 end = jiffies + msecs_to_jiffies(timeOut); 2841 end = jiffies + msecs_to_jiffies(time_out);
2885 do { 2842 do {
2886 status = read16(state, SIO_BL_STATUS__A, &blStatus); 2843 status = read16(state, SIO_BL_STATUS__A, &bl_status);
2887 if (status < 0) 2844 if (status < 0)
2888 goto error; 2845 goto error;
2889 } while ((blStatus == 0x1) && time_is_after_jiffies(end)); 2846 } while ((bl_status == 0x1) && time_is_after_jiffies(end));
2890 if (blStatus == 0x1) { 2847 if (bl_status == 0x1) {
2891 printk(KERN_ERR "drxk: SIO not ready\n"); 2848 pr_err("SIO not ready\n");
2892 status = -EINVAL; 2849 status = -EINVAL;
2893 goto error2; 2850 goto error2;
2894 } 2851 }
2895error: 2852error:
2896 if (status < 0) 2853 if (status < 0)
2897 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 2854 pr_err("Error %d on %s\n", status, __func__);
2898error2: 2855error2:
2899 mutex_unlock(&state->mutex); 2856 mutex_unlock(&state->mutex);
2900 return status; 2857 return status;
2901 2858
2902} 2859}
2903 2860
2904static int ADCSyncMeasurement(struct drxk_state *state, u16 *count) 2861static int adc_sync_measurement(struct drxk_state *state, u16 *count)
2905{ 2862{
2906 u16 data = 0; 2863 u16 data = 0;
2907 int status; 2864 int status;
2908 2865
2909 dprintk(1, "\n"); 2866 dprintk(1, "\n");
2910 2867
2911 /* Start measurement */ 2868 /* start measurement */
2912 status = write16(state, IQM_AF_COMM_EXEC__A, IQM_AF_COMM_EXEC_ACTIVE); 2869 status = write16(state, IQM_AF_COMM_EXEC__A, IQM_AF_COMM_EXEC_ACTIVE);
2913 if (status < 0) 2870 if (status < 0)
2914 goto error; 2871 goto error;
@@ -2935,42 +2892,42 @@ static int ADCSyncMeasurement(struct drxk_state *state, u16 *count)
2935 2892
2936error: 2893error:
2937 if (status < 0) 2894 if (status < 0)
2938 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 2895 pr_err("Error %d on %s\n", status, __func__);
2939 return status; 2896 return status;
2940} 2897}
2941 2898
2942static int ADCSynchronization(struct drxk_state *state) 2899static int adc_synchronization(struct drxk_state *state)
2943{ 2900{
2944 u16 count = 0; 2901 u16 count = 0;
2945 int status; 2902 int status;
2946 2903
2947 dprintk(1, "\n"); 2904 dprintk(1, "\n");
2948 2905
2949 status = ADCSyncMeasurement(state, &count); 2906 status = adc_sync_measurement(state, &count);
2950 if (status < 0) 2907 if (status < 0)
2951 goto error; 2908 goto error;
2952 2909
2953 if (count == 1) { 2910 if (count == 1) {
2954 /* Try sampling on a diffrent edge */ 2911 /* Try sampling on a diffrent edge */
2955 u16 clkNeg = 0; 2912 u16 clk_neg = 0;
2956 2913
2957 status = read16(state, IQM_AF_CLKNEG__A, &clkNeg); 2914 status = read16(state, IQM_AF_CLKNEG__A, &clk_neg);
2958 if (status < 0) 2915 if (status < 0)
2959 goto error; 2916 goto error;
2960 if ((clkNeg & IQM_AF_CLKNEG_CLKNEGDATA__M) == 2917 if ((clk_neg & IQM_AF_CLKNEG_CLKNEGDATA__M) ==
2961 IQM_AF_CLKNEG_CLKNEGDATA_CLK_ADC_DATA_POS) { 2918 IQM_AF_CLKNEG_CLKNEGDATA_CLK_ADC_DATA_POS) {
2962 clkNeg &= (~(IQM_AF_CLKNEG_CLKNEGDATA__M)); 2919 clk_neg &= (~(IQM_AF_CLKNEG_CLKNEGDATA__M));
2963 clkNeg |= 2920 clk_neg |=
2964 IQM_AF_CLKNEG_CLKNEGDATA_CLK_ADC_DATA_NEG; 2921 IQM_AF_CLKNEG_CLKNEGDATA_CLK_ADC_DATA_NEG;
2965 } else { 2922 } else {
2966 clkNeg &= (~(IQM_AF_CLKNEG_CLKNEGDATA__M)); 2923 clk_neg &= (~(IQM_AF_CLKNEG_CLKNEGDATA__M));
2967 clkNeg |= 2924 clk_neg |=
2968 IQM_AF_CLKNEG_CLKNEGDATA_CLK_ADC_DATA_POS; 2925 IQM_AF_CLKNEG_CLKNEGDATA_CLK_ADC_DATA_POS;
2969 } 2926 }
2970 status = write16(state, IQM_AF_CLKNEG__A, clkNeg); 2927 status = write16(state, IQM_AF_CLKNEG__A, clk_neg);
2971 if (status < 0) 2928 if (status < 0)
2972 goto error; 2929 goto error;
2973 status = ADCSyncMeasurement(state, &count); 2930 status = adc_sync_measurement(state, &count);
2974 if (status < 0) 2931 if (status < 0)
2975 goto error; 2932 goto error;
2976 } 2933 }
@@ -2979,25 +2936,25 @@ static int ADCSynchronization(struct drxk_state *state)
2979 status = -EINVAL; 2936 status = -EINVAL;
2980error: 2937error:
2981 if (status < 0) 2938 if (status < 0)
2982 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 2939 pr_err("Error %d on %s\n", status, __func__);
2983 return status; 2940 return status;
2984} 2941}
2985 2942
2986static int SetFrequencyShifter(struct drxk_state *state, 2943static int set_frequency_shifter(struct drxk_state *state,
2987 u16 intermediateFreqkHz, 2944 u16 intermediate_freqk_hz,
2988 s32 tunerFreqOffset, bool isDTV) 2945 s32 tuner_freq_offset, bool is_dtv)
2989{ 2946{
2990 bool selectPosImage = false; 2947 bool select_pos_image = false;
2991 u32 rfFreqResidual = tunerFreqOffset; 2948 u32 rf_freq_residual = tuner_freq_offset;
2992 u32 fmFrequencyShift = 0; 2949 u32 fm_frequency_shift = 0;
2993 bool tunerMirror = !state->m_bMirrorFreqSpect; 2950 bool tuner_mirror = !state->m_b_mirror_freq_spect;
2994 u32 adcFreq; 2951 u32 adc_freq;
2995 bool adcFlip; 2952 bool adc_flip;
2996 int status; 2953 int status;
2997 u32 ifFreqActual; 2954 u32 if_freq_actual;
2998 u32 samplingFrequency = (u32) (state->m_sysClockFreq / 3); 2955 u32 sampling_frequency = (u32) (state->m_sys_clock_freq / 3);
2999 u32 frequencyShift; 2956 u32 frequency_shift;
3000 bool imageToSelect; 2957 bool image_to_select;
3001 2958
3002 dprintk(1, "\n"); 2959 dprintk(1, "\n");
3003 2960
@@ -3005,121 +2962,125 @@ static int SetFrequencyShifter(struct drxk_state *state,
3005 Program frequency shifter 2962 Program frequency shifter
3006 No need to account for mirroring on RF 2963 No need to account for mirroring on RF
3007 */ 2964 */
3008 if (isDTV) { 2965 if (is_dtv) {
3009 if ((state->m_OperationMode == OM_QAM_ITU_A) || 2966 if ((state->m_operation_mode == OM_QAM_ITU_A) ||
3010 (state->m_OperationMode == OM_QAM_ITU_C) || 2967 (state->m_operation_mode == OM_QAM_ITU_C) ||
3011 (state->m_OperationMode == OM_DVBT)) 2968 (state->m_operation_mode == OM_DVBT))
3012 selectPosImage = true; 2969 select_pos_image = true;
3013 else 2970 else
3014 selectPosImage = false; 2971 select_pos_image = false;
3015 } 2972 }
3016 if (tunerMirror) 2973 if (tuner_mirror)
3017 /* tuner doesn't mirror */ 2974 /* tuner doesn't mirror */
3018 ifFreqActual = intermediateFreqkHz + 2975 if_freq_actual = intermediate_freqk_hz +
3019 rfFreqResidual + fmFrequencyShift; 2976 rf_freq_residual + fm_frequency_shift;
3020 else 2977 else
3021 /* tuner mirrors */ 2978 /* tuner mirrors */
3022 ifFreqActual = intermediateFreqkHz - 2979 if_freq_actual = intermediate_freqk_hz -
3023 rfFreqResidual - fmFrequencyShift; 2980 rf_freq_residual - fm_frequency_shift;
3024 if (ifFreqActual > samplingFrequency / 2) { 2981 if (if_freq_actual > sampling_frequency / 2) {
3025 /* adc mirrors */ 2982 /* adc mirrors */
3026 adcFreq = samplingFrequency - ifFreqActual; 2983 adc_freq = sampling_frequency - if_freq_actual;
3027 adcFlip = true; 2984 adc_flip = true;
3028 } else { 2985 } else {
3029 /* adc doesn't mirror */ 2986 /* adc doesn't mirror */
3030 adcFreq = ifFreqActual; 2987 adc_freq = if_freq_actual;
3031 adcFlip = false; 2988 adc_flip = false;
3032 } 2989 }
3033 2990
3034 frequencyShift = adcFreq; 2991 frequency_shift = adc_freq;
3035 imageToSelect = state->m_rfmirror ^ tunerMirror ^ 2992 image_to_select = state->m_rfmirror ^ tuner_mirror ^
3036 adcFlip ^ selectPosImage; 2993 adc_flip ^ select_pos_image;
3037 state->m_IqmFsRateOfs = 2994 state->m_iqm_fs_rate_ofs =
3038 Frac28a((frequencyShift), samplingFrequency); 2995 Frac28a((frequency_shift), sampling_frequency);
3039 2996
3040 if (imageToSelect) 2997 if (image_to_select)
3041 state->m_IqmFsRateOfs = ~state->m_IqmFsRateOfs + 1; 2998 state->m_iqm_fs_rate_ofs = ~state->m_iqm_fs_rate_ofs + 1;
3042 2999
3043 /* Program frequency shifter with tuner offset compensation */ 3000 /* Program frequency shifter with tuner offset compensation */
3044 /* frequencyShift += tunerFreqOffset; TODO */ 3001 /* frequency_shift += tuner_freq_offset; TODO */
3045 status = write32(state, IQM_FS_RATE_OFS_LO__A, 3002 status = write32(state, IQM_FS_RATE_OFS_LO__A,
3046 state->m_IqmFsRateOfs); 3003 state->m_iqm_fs_rate_ofs);
3047 if (status < 0) 3004 if (status < 0)
3048 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 3005 pr_err("Error %d on %s\n", status, __func__);
3049 return status; 3006 return status;
3050} 3007}
3051 3008
3052static int InitAGC(struct drxk_state *state, bool isDTV) 3009static int init_agc(struct drxk_state *state, bool is_dtv)
3053{ 3010{
3054 u16 ingainTgt = 0; 3011 u16 ingain_tgt = 0;
3055 u16 ingainTgtMin = 0; 3012 u16 ingain_tgt_min = 0;
3056 u16 ingainTgtMax = 0; 3013 u16 ingain_tgt_max = 0;
3057 u16 clpCyclen = 0; 3014 u16 clp_cyclen = 0;
3058 u16 clpSumMin = 0; 3015 u16 clp_sum_min = 0;
3059 u16 clpDirTo = 0; 3016 u16 clp_dir_to = 0;
3060 u16 snsSumMin = 0; 3017 u16 sns_sum_min = 0;
3061 u16 snsSumMax = 0; 3018 u16 sns_sum_max = 0;
3062 u16 clpSumMax = 0; 3019 u16 clp_sum_max = 0;
3063 u16 snsDirTo = 0; 3020 u16 sns_dir_to = 0;
3064 u16 kiInnergainMin = 0; 3021 u16 ki_innergain_min = 0;
3065 u16 ifIaccuHiTgt = 0; 3022 u16 if_iaccu_hi_tgt = 0;
3066 u16 ifIaccuHiTgtMin = 0; 3023 u16 if_iaccu_hi_tgt_min = 0;
3067 u16 ifIaccuHiTgtMax = 0; 3024 u16 if_iaccu_hi_tgt_max = 0;
3068 u16 data = 0; 3025 u16 data = 0;
3069 u16 fastClpCtrlDelay = 0; 3026 u16 fast_clp_ctrl_delay = 0;
3070 u16 clpCtrlMode = 0; 3027 u16 clp_ctrl_mode = 0;
3071 int status = 0; 3028 int status = 0;
3072 3029
3073 dprintk(1, "\n"); 3030 dprintk(1, "\n");
3074 3031
3075 /* Common settings */ 3032 /* Common settings */
3076 snsSumMax = 1023; 3033 sns_sum_max = 1023;
3077 ifIaccuHiTgtMin = 2047; 3034 if_iaccu_hi_tgt_min = 2047;
3078 clpCyclen = 500; 3035 clp_cyclen = 500;
3079 clpSumMax = 1023; 3036 clp_sum_max = 1023;
3080 3037
3081 /* AGCInit() not available for DVBT; init done in microcode */ 3038 /* AGCInit() not available for DVBT; init done in microcode */
3082 if (!IsQAM(state)) { 3039 if (!is_qam(state)) {
3083 printk(KERN_ERR "drxk: %s: mode %d is not DVB-C\n", __func__, state->m_OperationMode); 3040 pr_err("%s: mode %d is not DVB-C\n",
3041 __func__, state->m_operation_mode);
3084 return -EINVAL; 3042 return -EINVAL;
3085 } 3043 }
3086 3044
3087 /* FIXME: Analog TV AGC require different settings */ 3045 /* FIXME: Analog TV AGC require different settings */
3088 3046
3089 /* Standard specific settings */ 3047 /* Standard specific settings */
3090 clpSumMin = 8; 3048 clp_sum_min = 8;
3091 clpDirTo = (u16) -9; 3049 clp_dir_to = (u16) -9;
3092 clpCtrlMode = 0; 3050 clp_ctrl_mode = 0;
3093 snsSumMin = 8; 3051 sns_sum_min = 8;
3094 snsDirTo = (u16) -9; 3052 sns_dir_to = (u16) -9;
3095 kiInnergainMin = (u16) -1030; 3053 ki_innergain_min = (u16) -1030;
3096 ifIaccuHiTgtMax = 0x2380; 3054 if_iaccu_hi_tgt_max = 0x2380;
3097 ifIaccuHiTgt = 0x2380; 3055 if_iaccu_hi_tgt = 0x2380;
3098 ingainTgtMin = 0x0511; 3056 ingain_tgt_min = 0x0511;
3099 ingainTgt = 0x0511; 3057 ingain_tgt = 0x0511;
3100 ingainTgtMax = 5119; 3058 ingain_tgt_max = 5119;
3101 fastClpCtrlDelay = state->m_qamIfAgcCfg.FastClipCtrlDelay; 3059 fast_clp_ctrl_delay = state->m_qam_if_agc_cfg.fast_clip_ctrl_delay;
3102 3060
3103 status = write16(state, SCU_RAM_AGC_FAST_CLP_CTRL_DELAY__A, fastClpCtrlDelay); 3061 status = write16(state, SCU_RAM_AGC_FAST_CLP_CTRL_DELAY__A,
3062 fast_clp_ctrl_delay);
3104 if (status < 0) 3063 if (status < 0)
3105 goto error; 3064 goto error;
3106 3065
3107 status = write16(state, SCU_RAM_AGC_CLP_CTRL_MODE__A, clpCtrlMode); 3066 status = write16(state, SCU_RAM_AGC_CLP_CTRL_MODE__A, clp_ctrl_mode);
3108 if (status < 0) 3067 if (status < 0)
3109 goto error; 3068 goto error;
3110 status = write16(state, SCU_RAM_AGC_INGAIN_TGT__A, ingainTgt); 3069 status = write16(state, SCU_RAM_AGC_INGAIN_TGT__A, ingain_tgt);
3111 if (status < 0) 3070 if (status < 0)
3112 goto error; 3071 goto error;
3113 status = write16(state, SCU_RAM_AGC_INGAIN_TGT_MIN__A, ingainTgtMin); 3072 status = write16(state, SCU_RAM_AGC_INGAIN_TGT_MIN__A, ingain_tgt_min);
3114 if (status < 0) 3073 if (status < 0)
3115 goto error; 3074 goto error;
3116 status = write16(state, SCU_RAM_AGC_INGAIN_TGT_MAX__A, ingainTgtMax); 3075 status = write16(state, SCU_RAM_AGC_INGAIN_TGT_MAX__A, ingain_tgt_max);
3117 if (status < 0) 3076 if (status < 0)
3118 goto error; 3077 goto error;
3119 status = write16(state, SCU_RAM_AGC_IF_IACCU_HI_TGT_MIN__A, ifIaccuHiTgtMin); 3078 status = write16(state, SCU_RAM_AGC_IF_IACCU_HI_TGT_MIN__A,
3079 if_iaccu_hi_tgt_min);
3120 if (status < 0) 3080 if (status < 0)
3121 goto error; 3081 goto error;
3122 status = write16(state, SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A, ifIaccuHiTgtMax); 3082 status = write16(state, SCU_RAM_AGC_IF_IACCU_HI_TGT_MAX__A,
3083 if_iaccu_hi_tgt_max);
3123 if (status < 0) 3084 if (status < 0)
3124 goto error; 3085 goto error;
3125 status = write16(state, SCU_RAM_AGC_IF_IACCU_HI__A, 0); 3086 status = write16(state, SCU_RAM_AGC_IF_IACCU_HI__A, 0);
@@ -3134,20 +3095,22 @@ static int InitAGC(struct drxk_state *state, bool isDTV)
3134 status = write16(state, SCU_RAM_AGC_RF_IACCU_LO__A, 0); 3095 status = write16(state, SCU_RAM_AGC_RF_IACCU_LO__A, 0);
3135 if (status < 0) 3096 if (status < 0)
3136 goto error; 3097 goto error;
3137 status = write16(state, SCU_RAM_AGC_CLP_SUM_MAX__A, clpSumMax); 3098 status = write16(state, SCU_RAM_AGC_CLP_SUM_MAX__A, clp_sum_max);
3138 if (status < 0) 3099 if (status < 0)
3139 goto error; 3100 goto error;
3140 status = write16(state, SCU_RAM_AGC_SNS_SUM_MAX__A, snsSumMax); 3101 status = write16(state, SCU_RAM_AGC_SNS_SUM_MAX__A, sns_sum_max);
3141 if (status < 0) 3102 if (status < 0)
3142 goto error; 3103 goto error;
3143 3104
3144 status = write16(state, SCU_RAM_AGC_KI_INNERGAIN_MIN__A, kiInnergainMin); 3105 status = write16(state, SCU_RAM_AGC_KI_INNERGAIN_MIN__A,
3106 ki_innergain_min);
3145 if (status < 0) 3107 if (status < 0)
3146 goto error; 3108 goto error;
3147 status = write16(state, SCU_RAM_AGC_IF_IACCU_HI_TGT__A, ifIaccuHiTgt); 3109 status = write16(state, SCU_RAM_AGC_IF_IACCU_HI_TGT__A,
3110 if_iaccu_hi_tgt);
3148 if (status < 0) 3111 if (status < 0)
3149 goto error; 3112 goto error;
3150 status = write16(state, SCU_RAM_AGC_CLP_CYCLEN__A, clpCyclen); 3113 status = write16(state, SCU_RAM_AGC_CLP_CYCLEN__A, clp_cyclen);
3151 if (status < 0) 3114 if (status < 0)
3152 goto error; 3115 goto error;
3153 3116
@@ -3164,16 +3127,16 @@ static int InitAGC(struct drxk_state *state, bool isDTV)
3164 status = write16(state, SCU_RAM_AGC_KI_MAXMINGAIN_TH__A, 20); 3127 status = write16(state, SCU_RAM_AGC_KI_MAXMINGAIN_TH__A, 20);
3165 if (status < 0) 3128 if (status < 0)
3166 goto error; 3129 goto error;
3167 status = write16(state, SCU_RAM_AGC_CLP_SUM_MIN__A, clpSumMin); 3130 status = write16(state, SCU_RAM_AGC_CLP_SUM_MIN__A, clp_sum_min);
3168 if (status < 0) 3131 if (status < 0)
3169 goto error; 3132 goto error;
3170 status = write16(state, SCU_RAM_AGC_SNS_SUM_MIN__A, snsSumMin); 3133 status = write16(state, SCU_RAM_AGC_SNS_SUM_MIN__A, sns_sum_min);
3171 if (status < 0) 3134 if (status < 0)
3172 goto error; 3135 goto error;
3173 status = write16(state, SCU_RAM_AGC_CLP_DIR_TO__A, clpDirTo); 3136 status = write16(state, SCU_RAM_AGC_CLP_DIR_TO__A, clp_dir_to);
3174 if (status < 0) 3137 if (status < 0)
3175 goto error; 3138 goto error;
3176 status = write16(state, SCU_RAM_AGC_SNS_DIR_TO__A, snsDirTo); 3139 status = write16(state, SCU_RAM_AGC_SNS_DIR_TO__A, sns_dir_to);
3177 if (status < 0) 3140 if (status < 0)
3178 goto error; 3141 goto error;
3179 status = write16(state, SCU_RAM_AGC_KI_MINGAIN__A, 0x7fff); 3142 status = write16(state, SCU_RAM_AGC_KI_MINGAIN__A, 0x7fff);
@@ -3233,38 +3196,39 @@ static int InitAGC(struct drxk_state *state, bool isDTV)
3233 status = write16(state, SCU_RAM_AGC_KI__A, data); 3196 status = write16(state, SCU_RAM_AGC_KI__A, data);
3234error: 3197error:
3235 if (status < 0) 3198 if (status < 0)
3236 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 3199 pr_err("Error %d on %s\n", status, __func__);
3237 return status; 3200 return status;
3238} 3201}
3239 3202
3240static int DVBTQAMGetAccPktErr(struct drxk_state *state, u16 *packetErr) 3203static int dvbtqam_get_acc_pkt_err(struct drxk_state *state, u16 *packet_err)
3241{ 3204{
3242 int status; 3205 int status;
3243 3206
3244 dprintk(1, "\n"); 3207 dprintk(1, "\n");
3245 if (packetErr == NULL) 3208 if (packet_err == NULL)
3246 status = write16(state, SCU_RAM_FEC_ACCUM_PKT_FAILURES__A, 0); 3209 status = write16(state, SCU_RAM_FEC_ACCUM_PKT_FAILURES__A, 0);
3247 else 3210 else
3248 status = read16(state, SCU_RAM_FEC_ACCUM_PKT_FAILURES__A, packetErr); 3211 status = read16(state, SCU_RAM_FEC_ACCUM_PKT_FAILURES__A,
3212 packet_err);
3249 if (status < 0) 3213 if (status < 0)
3250 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 3214 pr_err("Error %d on %s\n", status, __func__);
3251 return status; 3215 return status;
3252} 3216}
3253 3217
3254static int DVBTScCommand(struct drxk_state *state, 3218static int dvbt_sc_command(struct drxk_state *state,
3255 u16 cmd, u16 subcmd, 3219 u16 cmd, u16 subcmd,
3256 u16 param0, u16 param1, u16 param2, 3220 u16 param0, u16 param1, u16 param2,
3257 u16 param3, u16 param4) 3221 u16 param3, u16 param4)
3258{ 3222{
3259 u16 curCmd = 0; 3223 u16 cur_cmd = 0;
3260 u16 errCode = 0; 3224 u16 err_code = 0;
3261 u16 retryCnt = 0; 3225 u16 retry_cnt = 0;
3262 u16 scExec = 0; 3226 u16 sc_exec = 0;
3263 int status; 3227 int status;
3264 3228
3265 dprintk(1, "\n"); 3229 dprintk(1, "\n");
3266 status = read16(state, OFDM_SC_COMM_EXEC__A, &scExec); 3230 status = read16(state, OFDM_SC_COMM_EXEC__A, &sc_exec);
3267 if (scExec != 1) { 3231 if (sc_exec != 1) {
3268 /* SC is not running */ 3232 /* SC is not running */
3269 status = -EINVAL; 3233 status = -EINVAL;
3270 } 3234 }
@@ -3272,13 +3236,13 @@ static int DVBTScCommand(struct drxk_state *state,
3272 goto error; 3236 goto error;
3273 3237
3274 /* Wait until sc is ready to receive command */ 3238 /* Wait until sc is ready to receive command */
3275 retryCnt = 0; 3239 retry_cnt = 0;
3276 do { 3240 do {
3277 msleep(1); 3241 usleep_range(1000, 2000);
3278 status = read16(state, OFDM_SC_RA_RAM_CMD__A, &curCmd); 3242 status = read16(state, OFDM_SC_RA_RAM_CMD__A, &cur_cmd);
3279 retryCnt++; 3243 retry_cnt++;
3280 } while ((curCmd != 0) && (retryCnt < DRXK_MAX_RETRIES)); 3244 } while ((cur_cmd != 0) && (retry_cnt < DRXK_MAX_RETRIES));
3281 if (retryCnt >= DRXK_MAX_RETRIES && (status < 0)) 3245 if (retry_cnt >= DRXK_MAX_RETRIES && (status < 0))
3282 goto error; 3246 goto error;
3283 3247
3284 /* Write sub-command */ 3248 /* Write sub-command */
@@ -3324,18 +3288,18 @@ static int DVBTScCommand(struct drxk_state *state,
3324 goto error; 3288 goto error;
3325 3289
3326 /* Wait until sc is ready processing command */ 3290 /* Wait until sc is ready processing command */
3327 retryCnt = 0; 3291 retry_cnt = 0;
3328 do { 3292 do {
3329 msleep(1); 3293 usleep_range(1000, 2000);
3330 status = read16(state, OFDM_SC_RA_RAM_CMD__A, &curCmd); 3294 status = read16(state, OFDM_SC_RA_RAM_CMD__A, &cur_cmd);
3331 retryCnt++; 3295 retry_cnt++;
3332 } while ((curCmd != 0) && (retryCnt < DRXK_MAX_RETRIES)); 3296 } while ((cur_cmd != 0) && (retry_cnt < DRXK_MAX_RETRIES));
3333 if (retryCnt >= DRXK_MAX_RETRIES && (status < 0)) 3297 if (retry_cnt >= DRXK_MAX_RETRIES && (status < 0))
3334 goto error; 3298 goto error;
3335 3299
3336 /* Check for illegal cmd */ 3300 /* Check for illegal cmd */
3337 status = read16(state, OFDM_SC_RA_RAM_CMD_ADDR__A, &errCode); 3301 status = read16(state, OFDM_SC_RA_RAM_CMD_ADDR__A, &err_code);
3338 if (errCode == 0xFFFF) { 3302 if (err_code == 0xFFFF) {
3339 /* illegal command */ 3303 /* illegal command */
3340 status = -EINVAL; 3304 status = -EINVAL;
3341 } 3305 }
@@ -3367,23 +3331,23 @@ static int DVBTScCommand(struct drxk_state *state,
3367 } /* switch (cmd->cmd) */ 3331 } /* switch (cmd->cmd) */
3368error: 3332error:
3369 if (status < 0) 3333 if (status < 0)
3370 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 3334 pr_err("Error %d on %s\n", status, __func__);
3371 return status; 3335 return status;
3372} 3336}
3373 3337
3374static int PowerUpDVBT(struct drxk_state *state) 3338static int power_up_dvbt(struct drxk_state *state)
3375{ 3339{
3376 enum DRXPowerMode powerMode = DRX_POWER_UP; 3340 enum drx_power_mode power_mode = DRX_POWER_UP;
3377 int status; 3341 int status;
3378 3342
3379 dprintk(1, "\n"); 3343 dprintk(1, "\n");
3380 status = CtrlPowerMode(state, &powerMode); 3344 status = ctrl_power_mode(state, &power_mode);
3381 if (status < 0) 3345 if (status < 0)
3382 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 3346 pr_err("Error %d on %s\n", status, __func__);
3383 return status; 3347 return status;
3384} 3348}
3385 3349
3386static int DVBTCtrlSetIncEnable(struct drxk_state *state, bool *enabled) 3350static int dvbt_ctrl_set_inc_enable(struct drxk_state *state, bool *enabled)
3387{ 3351{
3388 int status; 3352 int status;
3389 3353
@@ -3393,12 +3357,12 @@ static int DVBTCtrlSetIncEnable(struct drxk_state *state, bool *enabled)
3393 else 3357 else
3394 status = write16(state, IQM_CF_BYPASSDET__A, 1); 3358 status = write16(state, IQM_CF_BYPASSDET__A, 1);
3395 if (status < 0) 3359 if (status < 0)
3396 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 3360 pr_err("Error %d on %s\n", status, __func__);
3397 return status; 3361 return status;
3398} 3362}
3399 3363
3400#define DEFAULT_FR_THRES_8K 4000 3364#define DEFAULT_FR_THRES_8K 4000
3401static int DVBTCtrlSetFrEnable(struct drxk_state *state, bool *enabled) 3365static int dvbt_ctrl_set_fr_enable(struct drxk_state *state, bool *enabled)
3402{ 3366{
3403 3367
3404 int status; 3368 int status;
@@ -3413,13 +3377,13 @@ static int DVBTCtrlSetFrEnable(struct drxk_state *state, bool *enabled)
3413 status = write16(state, OFDM_SC_RA_RAM_FR_THRES_8K__A, 0); 3377 status = write16(state, OFDM_SC_RA_RAM_FR_THRES_8K__A, 0);
3414 } 3378 }
3415 if (status < 0) 3379 if (status < 0)
3416 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 3380 pr_err("Error %d on %s\n", status, __func__);
3417 3381
3418 return status; 3382 return status;
3419} 3383}
3420 3384
3421static int DVBTCtrlSetEchoThreshold(struct drxk_state *state, 3385static int dvbt_ctrl_set_echo_threshold(struct drxk_state *state,
3422 struct DRXKCfgDvbtEchoThres_t *echoThres) 3386 struct drxk_cfg_dvbt_echo_thres_t *echo_thres)
3423{ 3387{
3424 u16 data = 0; 3388 u16 data = 0;
3425 int status; 3389 int status;
@@ -3429,16 +3393,16 @@ static int DVBTCtrlSetEchoThreshold(struct drxk_state *state,
3429 if (status < 0) 3393 if (status < 0)
3430 goto error; 3394 goto error;
3431 3395
3432 switch (echoThres->fftMode) { 3396 switch (echo_thres->fft_mode) {
3433 case DRX_FFTMODE_2K: 3397 case DRX_FFTMODE_2K:
3434 data &= ~OFDM_SC_RA_RAM_ECHO_THRES_2K__M; 3398 data &= ~OFDM_SC_RA_RAM_ECHO_THRES_2K__M;
3435 data |= ((echoThres->threshold << 3399 data |= ((echo_thres->threshold <<
3436 OFDM_SC_RA_RAM_ECHO_THRES_2K__B) 3400 OFDM_SC_RA_RAM_ECHO_THRES_2K__B)
3437 & (OFDM_SC_RA_RAM_ECHO_THRES_2K__M)); 3401 & (OFDM_SC_RA_RAM_ECHO_THRES_2K__M));
3438 break; 3402 break;
3439 case DRX_FFTMODE_8K: 3403 case DRX_FFTMODE_8K:
3440 data &= ~OFDM_SC_RA_RAM_ECHO_THRES_8K__M; 3404 data &= ~OFDM_SC_RA_RAM_ECHO_THRES_8K__M;
3441 data |= ((echoThres->threshold << 3405 data |= ((echo_thres->threshold <<
3442 OFDM_SC_RA_RAM_ECHO_THRES_8K__B) 3406 OFDM_SC_RA_RAM_ECHO_THRES_8K__B)
3443 & (OFDM_SC_RA_RAM_ECHO_THRES_8K__M)); 3407 & (OFDM_SC_RA_RAM_ECHO_THRES_8K__M));
3444 break; 3408 break;
@@ -3449,12 +3413,12 @@ static int DVBTCtrlSetEchoThreshold(struct drxk_state *state,
3449 status = write16(state, OFDM_SC_RA_RAM_ECHO_THRES__A, data); 3413 status = write16(state, OFDM_SC_RA_RAM_ECHO_THRES__A, data);
3450error: 3414error:
3451 if (status < 0) 3415 if (status < 0)
3452 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 3416 pr_err("Error %d on %s\n", status, __func__);
3453 return status; 3417 return status;
3454} 3418}
3455 3419
3456static int DVBTCtrlSetSqiSpeed(struct drxk_state *state, 3420static int dvbt_ctrl_set_sqi_speed(struct drxk_state *state,
3457 enum DRXKCfgDvbtSqiSpeed *speed) 3421 enum drxk_cfg_dvbt_sqi_speed *speed)
3458{ 3422{
3459 int status = -EINVAL; 3423 int status = -EINVAL;
3460 3424
@@ -3472,7 +3436,7 @@ static int DVBTCtrlSetSqiSpeed(struct drxk_state *state,
3472 (u16) *speed); 3436 (u16) *speed);
3473error: 3437error:
3474 if (status < 0) 3438 if (status < 0)
3475 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 3439 pr_err("Error %d on %s\n", status, __func__);
3476 return status; 3440 return status;
3477} 3441}
3478 3442
@@ -3486,32 +3450,33 @@ error:
3486* Called in DVBTSetStandard 3450* Called in DVBTSetStandard
3487* 3451*
3488*/ 3452*/
3489static int DVBTActivatePresets(struct drxk_state *state) 3453static int dvbt_activate_presets(struct drxk_state *state)
3490{ 3454{
3491 int status; 3455 int status;
3492 bool setincenable = false; 3456 bool setincenable = false;
3493 bool setfrenable = true; 3457 bool setfrenable = true;
3494 3458
3495 struct DRXKCfgDvbtEchoThres_t echoThres2k = { 0, DRX_FFTMODE_2K }; 3459 struct drxk_cfg_dvbt_echo_thres_t echo_thres2k = { 0, DRX_FFTMODE_2K };
3496 struct DRXKCfgDvbtEchoThres_t echoThres8k = { 0, DRX_FFTMODE_8K }; 3460 struct drxk_cfg_dvbt_echo_thres_t echo_thres8k = { 0, DRX_FFTMODE_8K };
3497 3461
3498 dprintk(1, "\n"); 3462 dprintk(1, "\n");
3499 status = DVBTCtrlSetIncEnable(state, &setincenable); 3463 status = dvbt_ctrl_set_inc_enable(state, &setincenable);
3500 if (status < 0) 3464 if (status < 0)
3501 goto error; 3465 goto error;
3502 status = DVBTCtrlSetFrEnable(state, &setfrenable); 3466 status = dvbt_ctrl_set_fr_enable(state, &setfrenable);
3503 if (status < 0) 3467 if (status < 0)
3504 goto error; 3468 goto error;
3505 status = DVBTCtrlSetEchoThreshold(state, &echoThres2k); 3469 status = dvbt_ctrl_set_echo_threshold(state, &echo_thres2k);
3506 if (status < 0) 3470 if (status < 0)
3507 goto error; 3471 goto error;
3508 status = DVBTCtrlSetEchoThreshold(state, &echoThres8k); 3472 status = dvbt_ctrl_set_echo_threshold(state, &echo_thres8k);
3509 if (status < 0) 3473 if (status < 0)
3510 goto error; 3474 goto error;
3511 status = write16(state, SCU_RAM_AGC_INGAIN_TGT_MAX__A, state->m_dvbtIfAgcCfg.IngainTgtMax); 3475 status = write16(state, SCU_RAM_AGC_INGAIN_TGT_MAX__A,
3476 state->m_dvbt_if_agc_cfg.ingain_tgt_max);
3512error: 3477error:
3513 if (status < 0) 3478 if (status < 0)
3514 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 3479 pr_err("Error %d on %s\n", status, __func__);
3515 return status; 3480 return status;
3516} 3481}
3517 3482
@@ -3525,25 +3490,30 @@ error:
3525* For ROM code channel filter taps are loaded from the bootloader. For microcode 3490* For ROM code channel filter taps are loaded from the bootloader. For microcode
3526* the DVB-T taps from the drxk_filters.h are used. 3491* the DVB-T taps from the drxk_filters.h are used.
3527*/ 3492*/
3528static int SetDVBTStandard(struct drxk_state *state, 3493static int set_dvbt_standard(struct drxk_state *state,
3529 enum OperationMode oMode) 3494 enum operation_mode o_mode)
3530{ 3495{
3531 u16 cmdResult = 0; 3496 u16 cmd_result = 0;
3532 u16 data = 0; 3497 u16 data = 0;
3533 int status; 3498 int status;
3534 3499
3535 dprintk(1, "\n"); 3500 dprintk(1, "\n");
3536 3501
3537 PowerUpDVBT(state); 3502 power_up_dvbt(state);
3538 /* added antenna switch */ 3503 /* added antenna switch */
3539 SwitchAntennaToDVBT(state); 3504 switch_antenna_to_dvbt(state);
3540 /* send OFDM reset command */ 3505 /* send OFDM reset command */
3541 status = scu_command(state, SCU_RAM_COMMAND_STANDARD_OFDM | SCU_RAM_COMMAND_CMD_DEMOD_RESET, 0, NULL, 1, &cmdResult); 3506 status = scu_command(state,
3507 SCU_RAM_COMMAND_STANDARD_OFDM
3508 | SCU_RAM_COMMAND_CMD_DEMOD_RESET,
3509 0, NULL, 1, &cmd_result);
3542 if (status < 0) 3510 if (status < 0)
3543 goto error; 3511 goto error;
3544 3512
3545 /* send OFDM setenv command */ 3513 /* send OFDM setenv command */
3546 status = scu_command(state, SCU_RAM_COMMAND_STANDARD_OFDM | SCU_RAM_COMMAND_CMD_DEMOD_SET_ENV, 0, NULL, 1, &cmdResult); 3514 status = scu_command(state, SCU_RAM_COMMAND_STANDARD_OFDM
3515 | SCU_RAM_COMMAND_CMD_DEMOD_SET_ENV,
3516 0, NULL, 1, &cmd_result);
3547 if (status < 0) 3517 if (status < 0)
3548 goto error; 3518 goto error;
3549 3519
@@ -3575,7 +3545,7 @@ static int SetDVBTStandard(struct drxk_state *state,
3575 status = write16(state, IQM_AF_AMUX__A, IQM_AF_AMUX_SIGNAL2ADC); 3545 status = write16(state, IQM_AF_AMUX__A, IQM_AF_AMUX_SIGNAL2ADC);
3576 if (status < 0) 3546 if (status < 0)
3577 goto error; 3547 goto error;
3578 status = SetIqmAf(state, true); 3548 status = set_iqm_af(state, true);
3579 if (status < 0) 3549 if (status < 0)
3580 goto error; 3550 goto error;
3581 3551
@@ -3597,7 +3567,7 @@ static int SetDVBTStandard(struct drxk_state *state,
3597 status = write16(state, IQM_RC_STRETCH__A, 16); 3567 status = write16(state, IQM_RC_STRETCH__A, 16);
3598 if (status < 0) 3568 if (status < 0)
3599 goto error; 3569 goto error;
3600 status = write16(state, IQM_CF_OUT_ENA__A, 0x4); /* enable output 2 */ 3570 status = write16(state, IQM_CF_OUT_ENA__A, 0x4); /* enable output 2 */
3601 if (status < 0) 3571 if (status < 0)
3602 goto error; 3572 goto error;
3603 status = write16(state, IQM_CF_DS_ENA__A, 0x4); /* decimate output 2 */ 3573 status = write16(state, IQM_CF_DS_ENA__A, 0x4); /* decimate output 2 */
@@ -3618,7 +3588,8 @@ static int SetDVBTStandard(struct drxk_state *state,
3618 if (status < 0) 3588 if (status < 0)
3619 goto error; 3589 goto error;
3620 3590
3621 status = BLChainCmd(state, DRXK_BL_ROM_OFFSET_TAPS_DVBT, DRXK_BLCC_NR_ELEMENTS_TAPS, DRXK_BLC_TIMEOUT); 3591 status = bl_chain_cmd(state, DRXK_BL_ROM_OFFSET_TAPS_DVBT,
3592 DRXK_BLCC_NR_ELEMENTS_TAPS, DRXK_BLC_TIMEOUT);
3622 if (status < 0) 3593 if (status < 0)
3623 goto error; 3594 goto error;
3624 3595
@@ -3637,10 +3608,10 @@ static int SetDVBTStandard(struct drxk_state *state,
3637 goto error; 3608 goto error;
3638 3609
3639 /* IQM will not be reset from here, sync ADC and update/init AGC */ 3610 /* IQM will not be reset from here, sync ADC and update/init AGC */
3640 status = ADCSynchronization(state); 3611 status = adc_synchronization(state);
3641 if (status < 0) 3612 if (status < 0)
3642 goto error; 3613 goto error;
3643 status = SetPreSaw(state, &state->m_dvbtPreSawCfg); 3614 status = set_pre_saw(state, &state->m_dvbt_pre_saw_cfg);
3644 if (status < 0) 3615 if (status < 0)
3645 goto error; 3616 goto error;
3646 3617
@@ -3649,10 +3620,10 @@ static int SetDVBTStandard(struct drxk_state *state,
3649 if (status < 0) 3620 if (status < 0)
3650 goto error; 3621 goto error;
3651 3622
3652 status = SetAgcRf(state, &state->m_dvbtRfAgcCfg, true); 3623 status = set_agc_rf(state, &state->m_dvbt_rf_agc_cfg, true);
3653 if (status < 0) 3624 if (status < 0)
3654 goto error; 3625 goto error;
3655 status = SetAgcIf(state, &state->m_dvbtIfAgcCfg, true); 3626 status = set_agc_if(state, &state->m_dvbt_if_agc_cfg, true);
3656 if (status < 0) 3627 if (status < 0)
3657 goto error; 3628 goto error;
3658 3629
@@ -3670,9 +3641,10 @@ static int SetDVBTStandard(struct drxk_state *state,
3670 if (status < 0) 3641 if (status < 0)
3671 goto error; 3642 goto error;
3672 3643
3673 if (!state->m_DRXK_A3_ROM_CODE) { 3644 if (!state->m_drxk_a3_rom_code) {
3674 /* AGCInit() is not done for DVBT, so set agcFastClipCtrlDelay */ 3645 /* AGCInit() is not done for DVBT, so set agcfast_clip_ctrl_delay */
3675 status = write16(state, SCU_RAM_AGC_FAST_CLP_CTRL_DELAY__A, state->m_dvbtIfAgcCfg.FastClipCtrlDelay); 3646 status = write16(state, SCU_RAM_AGC_FAST_CLP_CTRL_DELAY__A,
3647 state->m_dvbt_if_agc_cfg.fast_clip_ctrl_delay);
3676 if (status < 0) 3648 if (status < 0)
3677 goto error; 3649 goto error;
3678 } 3650 }
@@ -3707,41 +3679,43 @@ static int SetDVBTStandard(struct drxk_state *state,
3707 goto error; 3679 goto error;
3708 3680
3709 /* Setup MPEG bus */ 3681 /* Setup MPEG bus */
3710 status = MPEGTSDtoSetup(state, OM_DVBT); 3682 status = mpegts_dto_setup(state, OM_DVBT);
3711 if (status < 0) 3683 if (status < 0)
3712 goto error; 3684 goto error;
3713 /* Set DVBT Presets */ 3685 /* Set DVBT Presets */
3714 status = DVBTActivatePresets(state); 3686 status = dvbt_activate_presets(state);
3715 if (status < 0) 3687 if (status < 0)
3716 goto error; 3688 goto error;
3717 3689
3718error: 3690error:
3719 if (status < 0) 3691 if (status < 0)
3720 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 3692 pr_err("Error %d on %s\n", status, __func__);
3721 return status; 3693 return status;
3722} 3694}
3723 3695
3724/*============================================================================*/ 3696/*============================================================================*/
3725/** 3697/**
3726* \brief Start dvbt demodulating for channel. 3698* \brief start dvbt demodulating for channel.
3727* \param demod instance of demodulator. 3699* \param demod instance of demodulator.
3728* \return DRXStatus_t. 3700* \return DRXStatus_t.
3729*/ 3701*/
3730static int DVBTStart(struct drxk_state *state) 3702static int dvbt_start(struct drxk_state *state)
3731{ 3703{
3732 u16 param1; 3704 u16 param1;
3733 int status; 3705 int status;
3734 /* DRXKOfdmScCmd_t scCmd; */ 3706 /* drxk_ofdm_sc_cmd_t scCmd; */
3735 3707
3736 dprintk(1, "\n"); 3708 dprintk(1, "\n");
3737 /* Start correct processes to get in lock */ 3709 /* start correct processes to get in lock */
3738 /* DRXK: OFDM_SC_RA_RAM_PROC_LOCKTRACK is no longer in mapfile! */ 3710 /* DRXK: OFDM_SC_RA_RAM_PROC_LOCKTRACK is no longer in mapfile! */
3739 param1 = OFDM_SC_RA_RAM_LOCKTRACK_MIN; 3711 param1 = OFDM_SC_RA_RAM_LOCKTRACK_MIN;
3740 status = DVBTScCommand(state, OFDM_SC_RA_RAM_CMD_PROC_START, 0, OFDM_SC_RA_RAM_SW_EVENT_RUN_NMASK__M, param1, 0, 0, 0); 3712 status = dvbt_sc_command(state, OFDM_SC_RA_RAM_CMD_PROC_START, 0,
3713 OFDM_SC_RA_RAM_SW_EVENT_RUN_NMASK__M, param1,
3714 0, 0, 0);
3741 if (status < 0) 3715 if (status < 0)
3742 goto error; 3716 goto error;
3743 /* Start FEC OC */ 3717 /* start FEC OC */
3744 status = MPEGTSStart(state); 3718 status = mpegts_start(state);
3745 if (status < 0) 3719 if (status < 0)
3746 goto error; 3720 goto error;
3747 status = write16(state, FEC_COMM_EXEC__A, FEC_COMM_EXEC_ACTIVE); 3721 status = write16(state, FEC_COMM_EXEC__A, FEC_COMM_EXEC_ACTIVE);
@@ -3749,7 +3723,7 @@ static int DVBTStart(struct drxk_state *state)
3749 goto error; 3723 goto error;
3750error: 3724error:
3751 if (status < 0) 3725 if (status < 0)
3752 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 3726 pr_err("Error %d on %s\n", status, __func__);
3753 return status; 3727 return status;
3754} 3728}
3755 3729
@@ -3762,20 +3736,23 @@ error:
3762* \return DRXStatus_t. 3736* \return DRXStatus_t.
3763* // original DVBTSetChannel() 3737* // original DVBTSetChannel()
3764*/ 3738*/
3765static int SetDVBT(struct drxk_state *state, u16 IntermediateFreqkHz, 3739static int set_dvbt(struct drxk_state *state, u16 intermediate_freqk_hz,
3766 s32 tunerFreqOffset) 3740 s32 tuner_freq_offset)
3767{ 3741{
3768 u16 cmdResult = 0; 3742 u16 cmd_result = 0;
3769 u16 transmissionParams = 0; 3743 u16 transmission_params = 0;
3770 u16 operationMode = 0; 3744 u16 operation_mode = 0;
3771 u32 iqmRcRateOfs = 0; 3745 u32 iqm_rc_rate_ofs = 0;
3772 u32 bandwidth = 0; 3746 u32 bandwidth = 0;
3773 u16 param1; 3747 u16 param1;
3774 int status; 3748 int status;
3775 3749
3776 dprintk(1, "IF =%d, TFO = %d\n", IntermediateFreqkHz, tunerFreqOffset); 3750 dprintk(1, "IF =%d, TFO = %d\n",
3751 intermediate_freqk_hz, tuner_freq_offset);
3777 3752
3778 status = scu_command(state, SCU_RAM_COMMAND_STANDARD_OFDM | SCU_RAM_COMMAND_CMD_DEMOD_STOP, 0, NULL, 1, &cmdResult); 3753 status = scu_command(state, SCU_RAM_COMMAND_STANDARD_OFDM
3754 | SCU_RAM_COMMAND_CMD_DEMOD_STOP,
3755 0, NULL, 1, &cmd_result);
3779 if (status < 0) 3756 if (status < 0)
3780 goto error; 3757 goto error;
3781 3758
@@ -3798,19 +3775,19 @@ static int SetDVBT(struct drxk_state *state, u16 IntermediateFreqkHz,
3798 if (status < 0) 3775 if (status < 0)
3799 goto error; 3776 goto error;
3800 3777
3801 /*== Write channel settings to device =====================================*/ 3778 /*== Write channel settings to device ================================*/
3802 3779
3803 /* mode */ 3780 /* mode */
3804 switch (state->props.transmission_mode) { 3781 switch (state->props.transmission_mode) {
3805 case TRANSMISSION_MODE_AUTO: 3782 case TRANSMISSION_MODE_AUTO:
3806 default: 3783 default:
3807 operationMode |= OFDM_SC_RA_RAM_OP_AUTO_MODE__M; 3784 operation_mode |= OFDM_SC_RA_RAM_OP_AUTO_MODE__M;
3808 /* fall through , try first guess DRX_FFTMODE_8K */ 3785 /* fall through , try first guess DRX_FFTMODE_8K */
3809 case TRANSMISSION_MODE_8K: 3786 case TRANSMISSION_MODE_8K:
3810 transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_MODE_8K; 3787 transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_MODE_8K;
3811 break; 3788 break;
3812 case TRANSMISSION_MODE_2K: 3789 case TRANSMISSION_MODE_2K:
3813 transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_MODE_2K; 3790 transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_MODE_2K;
3814 break; 3791 break;
3815 } 3792 }
3816 3793
@@ -3818,19 +3795,19 @@ static int SetDVBT(struct drxk_state *state, u16 IntermediateFreqkHz,
3818 switch (state->props.guard_interval) { 3795 switch (state->props.guard_interval) {
3819 default: 3796 default:
3820 case GUARD_INTERVAL_AUTO: 3797 case GUARD_INTERVAL_AUTO:
3821 operationMode |= OFDM_SC_RA_RAM_OP_AUTO_GUARD__M; 3798 operation_mode |= OFDM_SC_RA_RAM_OP_AUTO_GUARD__M;
3822 /* fall through , try first guess DRX_GUARD_1DIV4 */ 3799 /* fall through , try first guess DRX_GUARD_1DIV4 */
3823 case GUARD_INTERVAL_1_4: 3800 case GUARD_INTERVAL_1_4:
3824 transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_GUARD_4; 3801 transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_GUARD_4;
3825 break; 3802 break;
3826 case GUARD_INTERVAL_1_32: 3803 case GUARD_INTERVAL_1_32:
3827 transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_GUARD_32; 3804 transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_GUARD_32;
3828 break; 3805 break;
3829 case GUARD_INTERVAL_1_16: 3806 case GUARD_INTERVAL_1_16:
3830 transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_GUARD_16; 3807 transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_GUARD_16;
3831 break; 3808 break;
3832 case GUARD_INTERVAL_1_8: 3809 case GUARD_INTERVAL_1_8:
3833 transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_GUARD_8; 3810 transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_GUARD_8;
3834 break; 3811 break;
3835 } 3812 }
3836 3813
@@ -3839,18 +3816,18 @@ static int SetDVBT(struct drxk_state *state, u16 IntermediateFreqkHz,
3839 case HIERARCHY_AUTO: 3816 case HIERARCHY_AUTO:
3840 case HIERARCHY_NONE: 3817 case HIERARCHY_NONE:
3841 default: 3818 default:
3842 operationMode |= OFDM_SC_RA_RAM_OP_AUTO_HIER__M; 3819 operation_mode |= OFDM_SC_RA_RAM_OP_AUTO_HIER__M;
3843 /* fall through , try first guess SC_RA_RAM_OP_PARAM_HIER_NO */ 3820 /* fall through , try first guess SC_RA_RAM_OP_PARAM_HIER_NO */
3844 /* transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_HIER_NO; */ 3821 /* transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_HIER_NO; */
3845 /* break; */ 3822 /* break; */
3846 case HIERARCHY_1: 3823 case HIERARCHY_1:
3847 transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_HIER_A1; 3824 transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_HIER_A1;
3848 break; 3825 break;
3849 case HIERARCHY_2: 3826 case HIERARCHY_2:
3850 transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_HIER_A2; 3827 transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_HIER_A2;
3851 break; 3828 break;
3852 case HIERARCHY_4: 3829 case HIERARCHY_4:
3853 transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_HIER_A4; 3830 transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_HIER_A4;
3854 break; 3831 break;
3855 } 3832 }
3856 3833
@@ -3859,16 +3836,16 @@ static int SetDVBT(struct drxk_state *state, u16 IntermediateFreqkHz,
3859 switch (state->props.modulation) { 3836 switch (state->props.modulation) {
3860 case QAM_AUTO: 3837 case QAM_AUTO:
3861 default: 3838 default:
3862 operationMode |= OFDM_SC_RA_RAM_OP_AUTO_CONST__M; 3839 operation_mode |= OFDM_SC_RA_RAM_OP_AUTO_CONST__M;
3863 /* fall through , try first guess DRX_CONSTELLATION_QAM64 */ 3840 /* fall through , try first guess DRX_CONSTELLATION_QAM64 */
3864 case QAM_64: 3841 case QAM_64:
3865 transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_CONST_QAM64; 3842 transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_CONST_QAM64;
3866 break; 3843 break;
3867 case QPSK: 3844 case QPSK:
3868 transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_CONST_QPSK; 3845 transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_CONST_QPSK;
3869 break; 3846 break;
3870 case QAM_16: 3847 case QAM_16:
3871 transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_CONST_QAM16; 3848 transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_CONST_QAM16;
3872 break; 3849 break;
3873 } 3850 }
3874#if 0 3851#if 0
@@ -3876,13 +3853,13 @@ static int SetDVBT(struct drxk_state *state, u16 IntermediateFreqkHz,
3876 /* Priority (only for hierarchical channels) */ 3853 /* Priority (only for hierarchical channels) */
3877 switch (channel->priority) { 3854 switch (channel->priority) {
3878 case DRX_PRIORITY_LOW: 3855 case DRX_PRIORITY_LOW:
3879 transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_PRIO_LO; 3856 transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_PRIO_LO;
3880 WR16(devAddr, OFDM_EC_SB_PRIOR__A, 3857 WR16(dev_addr, OFDM_EC_SB_PRIOR__A,
3881 OFDM_EC_SB_PRIOR_LO); 3858 OFDM_EC_SB_PRIOR_LO);
3882 break; 3859 break;
3883 case DRX_PRIORITY_HIGH: 3860 case DRX_PRIORITY_HIGH:
3884 transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_PRIO_HI; 3861 transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_PRIO_HI;
3885 WR16(devAddr, OFDM_EC_SB_PRIOR__A, 3862 WR16(dev_addr, OFDM_EC_SB_PRIOR__A,
3886 OFDM_EC_SB_PRIOR_HI)); 3863 OFDM_EC_SB_PRIOR_HI));
3887 break; 3864 break;
3888 case DRX_PRIORITY_UNKNOWN: /* fall through */ 3865 case DRX_PRIORITY_UNKNOWN: /* fall through */
@@ -3892,7 +3869,7 @@ static int SetDVBT(struct drxk_state *state, u16 IntermediateFreqkHz,
3892 } 3869 }
3893#else 3870#else
3894 /* Set Priorty high */ 3871 /* Set Priorty high */
3895 transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_PRIO_HI; 3872 transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_PRIO_HI;
3896 status = write16(state, OFDM_EC_SB_PRIOR__A, OFDM_EC_SB_PRIOR_HI); 3873 status = write16(state, OFDM_EC_SB_PRIOR__A, OFDM_EC_SB_PRIOR_HI);
3897 if (status < 0) 3874 if (status < 0)
3898 goto error; 3875 goto error;
@@ -3902,90 +3879,111 @@ static int SetDVBT(struct drxk_state *state, u16 IntermediateFreqkHz,
3902 switch (state->props.code_rate_HP) { 3879 switch (state->props.code_rate_HP) {
3903 case FEC_AUTO: 3880 case FEC_AUTO:
3904 default: 3881 default:
3905 operationMode |= OFDM_SC_RA_RAM_OP_AUTO_RATE__M; 3882 operation_mode |= OFDM_SC_RA_RAM_OP_AUTO_RATE__M;
3906 /* fall through , try first guess DRX_CODERATE_2DIV3 */ 3883 /* fall through , try first guess DRX_CODERATE_2DIV3 */
3907 case FEC_2_3: 3884 case FEC_2_3:
3908 transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_RATE_2_3; 3885 transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_RATE_2_3;
3909 break; 3886 break;
3910 case FEC_1_2: 3887 case FEC_1_2:
3911 transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_RATE_1_2; 3888 transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_RATE_1_2;
3912 break; 3889 break;
3913 case FEC_3_4: 3890 case FEC_3_4:
3914 transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_RATE_3_4; 3891 transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_RATE_3_4;
3915 break; 3892 break;
3916 case FEC_5_6: 3893 case FEC_5_6:
3917 transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_RATE_5_6; 3894 transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_RATE_5_6;
3918 break; 3895 break;
3919 case FEC_7_8: 3896 case FEC_7_8:
3920 transmissionParams |= OFDM_SC_RA_RAM_OP_PARAM_RATE_7_8; 3897 transmission_params |= OFDM_SC_RA_RAM_OP_PARAM_RATE_7_8;
3921 break; 3898 break;
3922 } 3899 }
3923 3900
3924 /* SAW filter selection: normaly not necesarry, but if wanted 3901 /*
3925 the application can select a SAW filter via the driver by using UIOs */ 3902 * SAW filter selection: normaly not necesarry, but if wanted
3903 * the application can select a SAW filter via the driver by
3904 * using UIOs
3905 */
3906
3926 /* First determine real bandwidth (Hz) */ 3907 /* First determine real bandwidth (Hz) */
3927 /* Also set delay for impulse noise cruncher */ 3908 /* Also set delay for impulse noise cruncher */
3928 /* Also set parameters for EC_OC fix, note EC_OC_REG_TMD_HIL_MAR is changed 3909 /*
3929 by SC for fix for some 8K,1/8 guard but is restored by InitEC and ResetEC 3910 * Also set parameters for EC_OC fix, note EC_OC_REG_TMD_HIL_MAR is
3930 functions */ 3911 * changed by SC for fix for some 8K,1/8 guard but is restored by
3912 * InitEC and ResetEC functions
3913 */
3931 switch (state->props.bandwidth_hz) { 3914 switch (state->props.bandwidth_hz) {
3932 case 0: 3915 case 0:
3933 state->props.bandwidth_hz = 8000000; 3916 state->props.bandwidth_hz = 8000000;
3934 /* fall though */ 3917 /* fall though */
3935 case 8000000: 3918 case 8000000:
3936 bandwidth = DRXK_BANDWIDTH_8MHZ_IN_HZ; 3919 bandwidth = DRXK_BANDWIDTH_8MHZ_IN_HZ;
3937 status = write16(state, OFDM_SC_RA_RAM_SRMM_FIX_FACT_8K__A, 3052); 3920 status = write16(state, OFDM_SC_RA_RAM_SRMM_FIX_FACT_8K__A,
3921 3052);
3938 if (status < 0) 3922 if (status < 0)
3939 goto error; 3923 goto error;
3940 /* cochannel protection for PAL 8 MHz */ 3924 /* cochannel protection for PAL 8 MHz */
3941 status = write16(state, OFDM_SC_RA_RAM_NI_INIT_8K_PER_LEFT__A, 7); 3925 status = write16(state, OFDM_SC_RA_RAM_NI_INIT_8K_PER_LEFT__A,
3926 7);
3942 if (status < 0) 3927 if (status < 0)
3943 goto error; 3928 goto error;
3944 status = write16(state, OFDM_SC_RA_RAM_NI_INIT_8K_PER_RIGHT__A, 7); 3929 status = write16(state, OFDM_SC_RA_RAM_NI_INIT_8K_PER_RIGHT__A,
3930 7);
3945 if (status < 0) 3931 if (status < 0)
3946 goto error; 3932 goto error;
3947 status = write16(state, OFDM_SC_RA_RAM_NI_INIT_2K_PER_LEFT__A, 7); 3933 status = write16(state, OFDM_SC_RA_RAM_NI_INIT_2K_PER_LEFT__A,
3934 7);
3948 if (status < 0) 3935 if (status < 0)
3949 goto error; 3936 goto error;
3950 status = write16(state, OFDM_SC_RA_RAM_NI_INIT_2K_PER_RIGHT__A, 1); 3937 status = write16(state, OFDM_SC_RA_RAM_NI_INIT_2K_PER_RIGHT__A,
3938 1);
3951 if (status < 0) 3939 if (status < 0)
3952 goto error; 3940 goto error;
3953 break; 3941 break;
3954 case 7000000: 3942 case 7000000:
3955 bandwidth = DRXK_BANDWIDTH_7MHZ_IN_HZ; 3943 bandwidth = DRXK_BANDWIDTH_7MHZ_IN_HZ;
3956 status = write16(state, OFDM_SC_RA_RAM_SRMM_FIX_FACT_8K__A, 3491); 3944 status = write16(state, OFDM_SC_RA_RAM_SRMM_FIX_FACT_8K__A,
3945 3491);
3957 if (status < 0) 3946 if (status < 0)
3958 goto error; 3947 goto error;
3959 /* cochannel protection for PAL 7 MHz */ 3948 /* cochannel protection for PAL 7 MHz */
3960 status = write16(state, OFDM_SC_RA_RAM_NI_INIT_8K_PER_LEFT__A, 8); 3949 status = write16(state, OFDM_SC_RA_RAM_NI_INIT_8K_PER_LEFT__A,
3950 8);
3961 if (status < 0) 3951 if (status < 0)
3962 goto error; 3952 goto error;
3963 status = write16(state, OFDM_SC_RA_RAM_NI_INIT_8K_PER_RIGHT__A, 8); 3953 status = write16(state, OFDM_SC_RA_RAM_NI_INIT_8K_PER_RIGHT__A,
3954 8);
3964 if (status < 0) 3955 if (status < 0)
3965 goto error; 3956 goto error;
3966 status = write16(state, OFDM_SC_RA_RAM_NI_INIT_2K_PER_LEFT__A, 4); 3957 status = write16(state, OFDM_SC_RA_RAM_NI_INIT_2K_PER_LEFT__A,
3958 4);
3967 if (status < 0) 3959 if (status < 0)
3968 goto error; 3960 goto error;
3969 status = write16(state, OFDM_SC_RA_RAM_NI_INIT_2K_PER_RIGHT__A, 1); 3961 status = write16(state, OFDM_SC_RA_RAM_NI_INIT_2K_PER_RIGHT__A,
3962 1);
3970 if (status < 0) 3963 if (status < 0)
3971 goto error; 3964 goto error;
3972 break; 3965 break;
3973 case 6000000: 3966 case 6000000:
3974 bandwidth = DRXK_BANDWIDTH_6MHZ_IN_HZ; 3967 bandwidth = DRXK_BANDWIDTH_6MHZ_IN_HZ;
3975 status = write16(state, OFDM_SC_RA_RAM_SRMM_FIX_FACT_8K__A, 4073); 3968 status = write16(state, OFDM_SC_RA_RAM_SRMM_FIX_FACT_8K__A,
3969 4073);
3976 if (status < 0) 3970 if (status < 0)
3977 goto error; 3971 goto error;
3978 /* cochannel protection for NTSC 6 MHz */ 3972 /* cochannel protection for NTSC 6 MHz */
3979 status = write16(state, OFDM_SC_RA_RAM_NI_INIT_8K_PER_LEFT__A, 19); 3973 status = write16(state, OFDM_SC_RA_RAM_NI_INIT_8K_PER_LEFT__A,
3974 19);
3980 if (status < 0) 3975 if (status < 0)
3981 goto error; 3976 goto error;
3982 status = write16(state, OFDM_SC_RA_RAM_NI_INIT_8K_PER_RIGHT__A, 19); 3977 status = write16(state, OFDM_SC_RA_RAM_NI_INIT_8K_PER_RIGHT__A,
3978 19);
3983 if (status < 0) 3979 if (status < 0)
3984 goto error; 3980 goto error;
3985 status = write16(state, OFDM_SC_RA_RAM_NI_INIT_2K_PER_LEFT__A, 14); 3981 status = write16(state, OFDM_SC_RA_RAM_NI_INIT_2K_PER_LEFT__A,
3982 14);
3986 if (status < 0) 3983 if (status < 0)
3987 goto error; 3984 goto error;
3988 status = write16(state, OFDM_SC_RA_RAM_NI_INIT_2K_PER_RIGHT__A, 1); 3985 status = write16(state, OFDM_SC_RA_RAM_NI_INIT_2K_PER_RIGHT__A,
3986 1);
3989 if (status < 0) 3987 if (status < 0)
3990 goto error; 3988 goto error;
3991 break; 3989 break;
@@ -3994,46 +3992,50 @@ static int SetDVBT(struct drxk_state *state, u16 IntermediateFreqkHz,
3994 goto error; 3992 goto error;
3995 } 3993 }
3996 3994
3997 if (iqmRcRateOfs == 0) { 3995 if (iqm_rc_rate_ofs == 0) {
3998 /* Now compute IQM_RC_RATE_OFS 3996 /* Now compute IQM_RC_RATE_OFS
3999 (((SysFreq/BandWidth)/2)/2) -1) * 2^23) 3997 (((SysFreq/BandWidth)/2)/2) -1) * 2^23)
4000 => 3998 =>
4001 ((SysFreq / BandWidth) * (2^21)) - (2^23) 3999 ((SysFreq / BandWidth) * (2^21)) - (2^23)
4002 */ 4000 */
4003 /* (SysFreq / BandWidth) * (2^28) */ 4001 /* (SysFreq / BandWidth) * (2^28) */
4004 /* assert (MAX(sysClk)/MIN(bandwidth) < 16) 4002 /*
4005 => assert(MAX(sysClk) < 16*MIN(bandwidth)) 4003 * assert (MAX(sysClk)/MIN(bandwidth) < 16)
4006 => assert(109714272 > 48000000) = true so Frac 28 can be used */ 4004 * => assert(MAX(sysClk) < 16*MIN(bandwidth))
4007 iqmRcRateOfs = Frac28a((u32) 4005 * => assert(109714272 > 48000000) = true
4008 ((state->m_sysClockFreq * 4006 * so Frac 28 can be used
4007 */
4008 iqm_rc_rate_ofs = Frac28a((u32)
4009 ((state->m_sys_clock_freq *
4009 1000) / 3), bandwidth); 4010 1000) / 3), bandwidth);
4010 /* (SysFreq / BandWidth) * (2^21), rounding before truncating */ 4011 /* (SysFreq / BandWidth) * (2^21), rounding before truncating */
4011 if ((iqmRcRateOfs & 0x7fL) >= 0x40) 4012 if ((iqm_rc_rate_ofs & 0x7fL) >= 0x40)
4012 iqmRcRateOfs += 0x80L; 4013 iqm_rc_rate_ofs += 0x80L;
4013 iqmRcRateOfs = iqmRcRateOfs >> 7; 4014 iqm_rc_rate_ofs = iqm_rc_rate_ofs >> 7;
4014 /* ((SysFreq / BandWidth) * (2^21)) - (2^23) */ 4015 /* ((SysFreq / BandWidth) * (2^21)) - (2^23) */
4015 iqmRcRateOfs = iqmRcRateOfs - (1 << 23); 4016 iqm_rc_rate_ofs = iqm_rc_rate_ofs - (1 << 23);
4016 } 4017 }
4017 4018
4018 iqmRcRateOfs &= 4019 iqm_rc_rate_ofs &=
4019 ((((u32) IQM_RC_RATE_OFS_HI__M) << 4020 ((((u32) IQM_RC_RATE_OFS_HI__M) <<
4020 IQM_RC_RATE_OFS_LO__W) | IQM_RC_RATE_OFS_LO__M); 4021 IQM_RC_RATE_OFS_LO__W) | IQM_RC_RATE_OFS_LO__M);
4021 status = write32(state, IQM_RC_RATE_OFS_LO__A, iqmRcRateOfs); 4022 status = write32(state, IQM_RC_RATE_OFS_LO__A, iqm_rc_rate_ofs);
4022 if (status < 0) 4023 if (status < 0)
4023 goto error; 4024 goto error;
4024 4025
4025 /* Bandwidth setting done */ 4026 /* Bandwidth setting done */
4026 4027
4027#if 0 4028#if 0
4028 status = DVBTSetFrequencyShift(demod, channel, tunerOffset); 4029 status = dvbt_set_frequency_shift(demod, channel, tuner_offset);
4029 if (status < 0) 4030 if (status < 0)
4030 goto error; 4031 goto error;
4031#endif 4032#endif
4032 status = SetFrequencyShifter(state, IntermediateFreqkHz, tunerFreqOffset, true); 4033 status = set_frequency_shifter(state, intermediate_freqk_hz,
4034 tuner_freq_offset, true);
4033 if (status < 0) 4035 if (status < 0)
4034 goto error; 4036 goto error;
4035 4037
4036 /*== Start SC, write channel settings to SC ===============================*/ 4038 /*== start SC, write channel settings to SC ==========================*/
4037 4039
4038 /* Activate SCU to enable SCU commands */ 4040 /* Activate SCU to enable SCU commands */
4039 status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_ACTIVE); 4041 status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_ACTIVE);
@@ -4049,7 +4051,9 @@ static int SetDVBT(struct drxk_state *state, u16 IntermediateFreqkHz,
4049 goto error; 4051 goto error;
4050 4052
4051 4053
4052 status = scu_command(state, SCU_RAM_COMMAND_STANDARD_OFDM | SCU_RAM_COMMAND_CMD_DEMOD_START, 0, NULL, 1, &cmdResult); 4054 status = scu_command(state, SCU_RAM_COMMAND_STANDARD_OFDM
4055 | SCU_RAM_COMMAND_CMD_DEMOD_START,
4056 0, NULL, 1, &cmd_result);
4053 if (status < 0) 4057 if (status < 0)
4054 goto error; 4058 goto error;
4055 4059
@@ -4059,16 +4063,16 @@ static int SetDVBT(struct drxk_state *state, u16 IntermediateFreqkHz,
4059 OFDM_SC_RA_RAM_OP_AUTO_CONST__M | 4063 OFDM_SC_RA_RAM_OP_AUTO_CONST__M |
4060 OFDM_SC_RA_RAM_OP_AUTO_HIER__M | 4064 OFDM_SC_RA_RAM_OP_AUTO_HIER__M |
4061 OFDM_SC_RA_RAM_OP_AUTO_RATE__M); 4065 OFDM_SC_RA_RAM_OP_AUTO_RATE__M);
4062 status = DVBTScCommand(state, OFDM_SC_RA_RAM_CMD_SET_PREF_PARAM, 4066 status = dvbt_sc_command(state, OFDM_SC_RA_RAM_CMD_SET_PREF_PARAM,
4063 0, transmissionParams, param1, 0, 0, 0); 4067 0, transmission_params, param1, 0, 0, 0);
4064 if (status < 0) 4068 if (status < 0)
4065 goto error; 4069 goto error;
4066 4070
4067 if (!state->m_DRXK_A3_ROM_CODE) 4071 if (!state->m_drxk_a3_rom_code)
4068 status = DVBTCtrlSetSqiSpeed(state, &state->m_sqiSpeed); 4072 status = dvbt_ctrl_set_sqi_speed(state, &state->m_sqi_speed);
4069error: 4073error:
4070 if (status < 0) 4074 if (status < 0)
4071 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 4075 pr_err("Error %d on %s\n", status, __func__);
4072 4076
4073 return status; 4077 return status;
4074} 4078}
@@ -4083,7 +4087,7 @@ error:
4083* \return DRXStatus_t. 4087* \return DRXStatus_t.
4084* 4088*
4085*/ 4089*/
4086static int GetDVBTLockStatus(struct drxk_state *state, u32 *pLockStatus) 4090static int get_dvbt_lock_status(struct drxk_state *state, u32 *p_lock_status)
4087{ 4091{
4088 int status; 4092 int status;
4089 const u16 mpeg_lock_mask = (OFDM_SC_RA_RAM_LOCK_MPEG__M | 4093 const u16 mpeg_lock_mask = (OFDM_SC_RA_RAM_LOCK_MPEG__M |
@@ -4091,58 +4095,58 @@ static int GetDVBTLockStatus(struct drxk_state *state, u32 *pLockStatus)
4091 const u16 fec_lock_mask = (OFDM_SC_RA_RAM_LOCK_FEC__M); 4095 const u16 fec_lock_mask = (OFDM_SC_RA_RAM_LOCK_FEC__M);
4092 const u16 demod_lock_mask = OFDM_SC_RA_RAM_LOCK_DEMOD__M; 4096 const u16 demod_lock_mask = OFDM_SC_RA_RAM_LOCK_DEMOD__M;
4093 4097
4094 u16 ScRaRamLock = 0; 4098 u16 sc_ra_ram_lock = 0;
4095 u16 ScCommExec = 0; 4099 u16 sc_comm_exec = 0;
4096 4100
4097 dprintk(1, "\n"); 4101 dprintk(1, "\n");
4098 4102
4099 *pLockStatus = NOT_LOCKED; 4103 *p_lock_status = NOT_LOCKED;
4100 /* driver 0.9.0 */ 4104 /* driver 0.9.0 */
4101 /* Check if SC is running */ 4105 /* Check if SC is running */
4102 status = read16(state, OFDM_SC_COMM_EXEC__A, &ScCommExec); 4106 status = read16(state, OFDM_SC_COMM_EXEC__A, &sc_comm_exec);
4103 if (status < 0) 4107 if (status < 0)
4104 goto end; 4108 goto end;
4105 if (ScCommExec == OFDM_SC_COMM_EXEC_STOP) 4109 if (sc_comm_exec == OFDM_SC_COMM_EXEC_STOP)
4106 goto end; 4110 goto end;
4107 4111
4108 status = read16(state, OFDM_SC_RA_RAM_LOCK__A, &ScRaRamLock); 4112 status = read16(state, OFDM_SC_RA_RAM_LOCK__A, &sc_ra_ram_lock);
4109 if (status < 0) 4113 if (status < 0)
4110 goto end; 4114 goto end;
4111 4115
4112 if ((ScRaRamLock & mpeg_lock_mask) == mpeg_lock_mask) 4116 if ((sc_ra_ram_lock & mpeg_lock_mask) == mpeg_lock_mask)
4113 *pLockStatus = MPEG_LOCK; 4117 *p_lock_status = MPEG_LOCK;
4114 else if ((ScRaRamLock & fec_lock_mask) == fec_lock_mask) 4118 else if ((sc_ra_ram_lock & fec_lock_mask) == fec_lock_mask)
4115 *pLockStatus = FEC_LOCK; 4119 *p_lock_status = FEC_LOCK;
4116 else if ((ScRaRamLock & demod_lock_mask) == demod_lock_mask) 4120 else if ((sc_ra_ram_lock & demod_lock_mask) == demod_lock_mask)
4117 *pLockStatus = DEMOD_LOCK; 4121 *p_lock_status = DEMOD_LOCK;
4118 else if (ScRaRamLock & OFDM_SC_RA_RAM_LOCK_NODVBT__M) 4122 else if (sc_ra_ram_lock & OFDM_SC_RA_RAM_LOCK_NODVBT__M)
4119 *pLockStatus = NEVER_LOCK; 4123 *p_lock_status = NEVER_LOCK;
4120end: 4124end:
4121 if (status < 0) 4125 if (status < 0)
4122 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 4126 pr_err("Error %d on %s\n", status, __func__);
4123 4127
4124 return status; 4128 return status;
4125} 4129}
4126 4130
4127static int PowerUpQAM(struct drxk_state *state) 4131static int power_up_qam(struct drxk_state *state)
4128{ 4132{
4129 enum DRXPowerMode powerMode = DRXK_POWER_DOWN_OFDM; 4133 enum drx_power_mode power_mode = DRXK_POWER_DOWN_OFDM;
4130 int status; 4134 int status;
4131 4135
4132 dprintk(1, "\n"); 4136 dprintk(1, "\n");
4133 status = CtrlPowerMode(state, &powerMode); 4137 status = ctrl_power_mode(state, &power_mode);
4134 if (status < 0) 4138 if (status < 0)
4135 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 4139 pr_err("Error %d on %s\n", status, __func__);
4136 4140
4137 return status; 4141 return status;
4138} 4142}
4139 4143
4140 4144
4141/** Power Down QAM */ 4145/** Power Down QAM */
4142static int PowerDownQAM(struct drxk_state *state) 4146static int power_down_qam(struct drxk_state *state)
4143{ 4147{
4144 u16 data = 0; 4148 u16 data = 0;
4145 u16 cmdResult; 4149 u16 cmd_result;
4146 int status = 0; 4150 int status = 0;
4147 4151
4148 dprintk(1, "\n"); 4152 dprintk(1, "\n");
@@ -4158,16 +4162,18 @@ static int PowerDownQAM(struct drxk_state *state)
4158 status = write16(state, QAM_COMM_EXEC__A, QAM_COMM_EXEC_STOP); 4162 status = write16(state, QAM_COMM_EXEC__A, QAM_COMM_EXEC_STOP);
4159 if (status < 0) 4163 if (status < 0)
4160 goto error; 4164 goto error;
4161 status = scu_command(state, SCU_RAM_COMMAND_STANDARD_QAM | SCU_RAM_COMMAND_CMD_DEMOD_STOP, 0, NULL, 1, &cmdResult); 4165 status = scu_command(state, SCU_RAM_COMMAND_STANDARD_QAM
4166 | SCU_RAM_COMMAND_CMD_DEMOD_STOP,
4167 0, NULL, 1, &cmd_result);
4162 if (status < 0) 4168 if (status < 0)
4163 goto error; 4169 goto error;
4164 } 4170 }
4165 /* powerdown AFE */ 4171 /* powerdown AFE */
4166 status = SetIqmAf(state, false); 4172 status = set_iqm_af(state, false);
4167 4173
4168error: 4174error:
4169 if (status < 0) 4175 if (status < 0)
4170 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 4176 pr_err("Error %d on %s\n", status, __func__);
4171 4177
4172 return status; 4178 return status;
4173} 4179}
@@ -4185,20 +4191,20 @@ error:
4185* The implementation does not check this. 4191* The implementation does not check this.
4186* 4192*
4187*/ 4193*/
4188static int SetQAMMeasurement(struct drxk_state *state, 4194static int set_qam_measurement(struct drxk_state *state,
4189 enum EDrxkConstellation modulation, 4195 enum e_drxk_constellation modulation,
4190 u32 symbolRate) 4196 u32 symbol_rate)
4191{ 4197{
4192 u32 fecBitsDesired = 0; /* BER accounting period */ 4198 u32 fec_bits_desired = 0; /* BER accounting period */
4193 u32 fecRsPeriodTotal = 0; /* Total period */ 4199 u32 fec_rs_period_total = 0; /* Total period */
4194 u16 fecRsPrescale = 0; /* ReedSolomon Measurement Prescale */ 4200 u16 fec_rs_prescale = 0; /* ReedSolomon Measurement Prescale */
4195 u16 fecRsPeriod = 0; /* Value for corresponding I2C register */ 4201 u16 fec_rs_period = 0; /* Value for corresponding I2C register */
4196 int status = 0; 4202 int status = 0;
4197 4203
4198 dprintk(1, "\n"); 4204 dprintk(1, "\n");
4199 4205
4200 fecRsPrescale = 1; 4206 fec_rs_prescale = 1;
4201 /* fecBitsDesired = symbolRate [kHz] * 4207 /* fec_bits_desired = symbol_rate [kHz] *
4202 FrameLenght [ms] * 4208 FrameLenght [ms] *
4203 (modulation + 1) * 4209 (modulation + 1) *
4204 SyncLoss (== 1) * 4210 SyncLoss (== 1) *
@@ -4206,19 +4212,19 @@ static int SetQAMMeasurement(struct drxk_state *state,
4206 */ 4212 */
4207 switch (modulation) { 4213 switch (modulation) {
4208 case DRX_CONSTELLATION_QAM16: 4214 case DRX_CONSTELLATION_QAM16:
4209 fecBitsDesired = 4 * symbolRate; 4215 fec_bits_desired = 4 * symbol_rate;
4210 break; 4216 break;
4211 case DRX_CONSTELLATION_QAM32: 4217 case DRX_CONSTELLATION_QAM32:
4212 fecBitsDesired = 5 * symbolRate; 4218 fec_bits_desired = 5 * symbol_rate;
4213 break; 4219 break;
4214 case DRX_CONSTELLATION_QAM64: 4220 case DRX_CONSTELLATION_QAM64:
4215 fecBitsDesired = 6 * symbolRate; 4221 fec_bits_desired = 6 * symbol_rate;
4216 break; 4222 break;
4217 case DRX_CONSTELLATION_QAM128: 4223 case DRX_CONSTELLATION_QAM128:
4218 fecBitsDesired = 7 * symbolRate; 4224 fec_bits_desired = 7 * symbol_rate;
4219 break; 4225 break;
4220 case DRX_CONSTELLATION_QAM256: 4226 case DRX_CONSTELLATION_QAM256:
4221 fecBitsDesired = 8 * symbolRate; 4227 fec_bits_desired = 8 * symbol_rate;
4222 break; 4228 break;
4223 default: 4229 default:
4224 status = -EINVAL; 4230 status = -EINVAL;
@@ -4226,40 +4232,41 @@ static int SetQAMMeasurement(struct drxk_state *state,
4226 if (status < 0) 4232 if (status < 0)
4227 goto error; 4233 goto error;
4228 4234
4229 fecBitsDesired /= 1000; /* symbolRate [Hz] -> symbolRate [kHz] */ 4235 fec_bits_desired /= 1000; /* symbol_rate [Hz] -> symbol_rate [kHz] */
4230 fecBitsDesired *= 500; /* meas. period [ms] */ 4236 fec_bits_desired *= 500; /* meas. period [ms] */
4231 4237
4232 /* Annex A/C: bits/RsPeriod = 204 * 8 = 1632 */ 4238 /* Annex A/C: bits/RsPeriod = 204 * 8 = 1632 */
4233 /* fecRsPeriodTotal = fecBitsDesired / 1632 */ 4239 /* fec_rs_period_total = fec_bits_desired / 1632 */
4234 fecRsPeriodTotal = (fecBitsDesired / 1632UL) + 1; /* roughly ceil */ 4240 fec_rs_period_total = (fec_bits_desired / 1632UL) + 1; /* roughly ceil */
4235 4241
4236 /* fecRsPeriodTotal = fecRsPrescale * fecRsPeriod */ 4242 /* fec_rs_period_total = fec_rs_prescale * fec_rs_period */
4237 fecRsPrescale = 1 + (u16) (fecRsPeriodTotal >> 16); 4243 fec_rs_prescale = 1 + (u16) (fec_rs_period_total >> 16);
4238 if (fecRsPrescale == 0) { 4244 if (fec_rs_prescale == 0) {
4239 /* Divide by zero (though impossible) */ 4245 /* Divide by zero (though impossible) */
4240 status = -EINVAL; 4246 status = -EINVAL;
4241 if (status < 0) 4247 if (status < 0)
4242 goto error; 4248 goto error;
4243 } 4249 }
4244 fecRsPeriod = 4250 fec_rs_period =
4245 ((u16) fecRsPeriodTotal + 4251 ((u16) fec_rs_period_total +
4246 (fecRsPrescale >> 1)) / fecRsPrescale; 4252 (fec_rs_prescale >> 1)) / fec_rs_prescale;
4247 4253
4248 /* write corresponding registers */ 4254 /* write corresponding registers */
4249 status = write16(state, FEC_RS_MEASUREMENT_PERIOD__A, fecRsPeriod); 4255 status = write16(state, FEC_RS_MEASUREMENT_PERIOD__A, fec_rs_period);
4250 if (status < 0) 4256 if (status < 0)
4251 goto error; 4257 goto error;
4252 status = write16(state, FEC_RS_MEASUREMENT_PRESCALE__A, fecRsPrescale); 4258 status = write16(state, FEC_RS_MEASUREMENT_PRESCALE__A,
4259 fec_rs_prescale);
4253 if (status < 0) 4260 if (status < 0)
4254 goto error; 4261 goto error;
4255 status = write16(state, FEC_OC_SNC_FAIL_PERIOD__A, fecRsPeriod); 4262 status = write16(state, FEC_OC_SNC_FAIL_PERIOD__A, fec_rs_period);
4256error: 4263error:
4257 if (status < 0) 4264 if (status < 0)
4258 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 4265 pr_err("Error %d on %s\n", status, __func__);
4259 return status; 4266 return status;
4260} 4267}
4261 4268
4262static int SetQAM16(struct drxk_state *state) 4269static int set_qam16(struct drxk_state *state)
4263{ 4270{
4264 int status = 0; 4271 int status = 0;
4265 4272
@@ -4315,7 +4322,8 @@ static int SetQAM16(struct drxk_state *state)
4315 goto error; 4322 goto error;
4316 4323
4317 /* QAM Slicer Settings */ 4324 /* QAM Slicer Settings */
4318 status = write16(state, SCU_RAM_QAM_SL_SIG_POWER__A, DRXK_QAM_SL_SIG_POWER_QAM16); 4325 status = write16(state, SCU_RAM_QAM_SL_SIG_POWER__A,
4326 DRXK_QAM_SL_SIG_POWER_QAM16);
4319 if (status < 0) 4327 if (status < 0)
4320 goto error; 4328 goto error;
4321 4329
@@ -4441,7 +4449,7 @@ static int SetQAM16(struct drxk_state *state)
4441 4449
4442error: 4450error:
4443 if (status < 0) 4451 if (status < 0)
4444 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 4452 pr_err("Error %d on %s\n", status, __func__);
4445 return status; 4453 return status;
4446} 4454}
4447 4455
@@ -4452,7 +4460,7 @@ error:
4452* \param demod instance of demod. 4460* \param demod instance of demod.
4453* \return DRXStatus_t. 4461* \return DRXStatus_t.
4454*/ 4462*/
4455static int SetQAM32(struct drxk_state *state) 4463static int set_qam32(struct drxk_state *state)
4456{ 4464{
4457 int status = 0; 4465 int status = 0;
4458 4466
@@ -4511,7 +4519,8 @@ static int SetQAM32(struct drxk_state *state)
4511 4519
4512 /* QAM Slicer Settings */ 4520 /* QAM Slicer Settings */
4513 4521
4514 status = write16(state, SCU_RAM_QAM_SL_SIG_POWER__A, DRXK_QAM_SL_SIG_POWER_QAM32); 4522 status = write16(state, SCU_RAM_QAM_SL_SIG_POWER__A,
4523 DRXK_QAM_SL_SIG_POWER_QAM32);
4515 if (status < 0) 4524 if (status < 0)
4516 goto error; 4525 goto error;
4517 4526
@@ -4636,7 +4645,7 @@ static int SetQAM32(struct drxk_state *state)
4636 status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A, (u16) -86); 4645 status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A, (u16) -86);
4637error: 4646error:
4638 if (status < 0) 4647 if (status < 0)
4639 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 4648 pr_err("Error %d on %s\n", status, __func__);
4640 return status; 4649 return status;
4641} 4650}
4642 4651
@@ -4647,7 +4656,7 @@ error:
4647* \param demod instance of demod. 4656* \param demod instance of demod.
4648* \return DRXStatus_t. 4657* \return DRXStatus_t.
4649*/ 4658*/
4650static int SetQAM64(struct drxk_state *state) 4659static int set_qam64(struct drxk_state *state)
4651{ 4660{
4652 int status = 0; 4661 int status = 0;
4653 4662
@@ -4704,7 +4713,8 @@ static int SetQAM64(struct drxk_state *state)
4704 goto error; 4713 goto error;
4705 4714
4706 /* QAM Slicer Settings */ 4715 /* QAM Slicer Settings */
4707 status = write16(state, SCU_RAM_QAM_SL_SIG_POWER__A, DRXK_QAM_SL_SIG_POWER_QAM64); 4716 status = write16(state, SCU_RAM_QAM_SL_SIG_POWER__A,
4717 DRXK_QAM_SL_SIG_POWER_QAM64);
4708 if (status < 0) 4718 if (status < 0)
4709 goto error; 4719 goto error;
4710 4720
@@ -4829,7 +4839,7 @@ static int SetQAM64(struct drxk_state *state)
4829 status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A, (u16) -80); 4839 status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A, (u16) -80);
4830error: 4840error:
4831 if (status < 0) 4841 if (status < 0)
4832 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 4842 pr_err("Error %d on %s\n", status, __func__);
4833 4843
4834 return status; 4844 return status;
4835} 4845}
@@ -4841,7 +4851,7 @@ error:
4841* \param demod: instance of demod. 4851* \param demod: instance of demod.
4842* \return DRXStatus_t. 4852* \return DRXStatus_t.
4843*/ 4853*/
4844static int SetQAM128(struct drxk_state *state) 4854static int set_qam128(struct drxk_state *state)
4845{ 4855{
4846 int status = 0; 4856 int status = 0;
4847 4857
@@ -4900,7 +4910,8 @@ static int SetQAM128(struct drxk_state *state)
4900 4910
4901 /* QAM Slicer Settings */ 4911 /* QAM Slicer Settings */
4902 4912
4903 status = write16(state, SCU_RAM_QAM_SL_SIG_POWER__A, DRXK_QAM_SL_SIG_POWER_QAM128); 4913 status = write16(state, SCU_RAM_QAM_SL_SIG_POWER__A,
4914 DRXK_QAM_SL_SIG_POWER_QAM128);
4904 if (status < 0) 4915 if (status < 0)
4905 goto error; 4916 goto error;
4906 4917
@@ -5025,7 +5036,7 @@ static int SetQAM128(struct drxk_state *state)
5025 status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A, (u16) -23); 5036 status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A, (u16) -23);
5026error: 5037error:
5027 if (status < 0) 5038 if (status < 0)
5028 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 5039 pr_err("Error %d on %s\n", status, __func__);
5029 5040
5030 return status; 5041 return status;
5031} 5042}
@@ -5037,7 +5048,7 @@ error:
5037* \param demod: instance of demod. 5048* \param demod: instance of demod.
5038* \return DRXStatus_t. 5049* \return DRXStatus_t.
5039*/ 5050*/
5040static int SetQAM256(struct drxk_state *state) 5051static int set_qam256(struct drxk_state *state)
5041{ 5052{
5042 int status = 0; 5053 int status = 0;
5043 5054
@@ -5095,7 +5106,8 @@ static int SetQAM256(struct drxk_state *state)
5095 5106
5096 /* QAM Slicer Settings */ 5107 /* QAM Slicer Settings */
5097 5108
5098 status = write16(state, SCU_RAM_QAM_SL_SIG_POWER__A, DRXK_QAM_SL_SIG_POWER_QAM256); 5109 status = write16(state, SCU_RAM_QAM_SL_SIG_POWER__A,
5110 DRXK_QAM_SL_SIG_POWER_QAM256);
5099 if (status < 0) 5111 if (status < 0)
5100 goto error; 5112 goto error;
5101 5113
@@ -5220,7 +5232,7 @@ static int SetQAM256(struct drxk_state *state)
5220 status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A, (u16) -8); 5232 status = write16(state, SCU_RAM_QAM_FSM_LCAVG_OFFSET5__A, (u16) -8);
5221error: 5233error:
5222 if (status < 0) 5234 if (status < 0)
5223 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 5235 pr_err("Error %d on %s\n", status, __func__);
5224 return status; 5236 return status;
5225} 5237}
5226 5238
@@ -5232,10 +5244,10 @@ error:
5232* \param channel: pointer to channel data. 5244* \param channel: pointer to channel data.
5233* \return DRXStatus_t. 5245* \return DRXStatus_t.
5234*/ 5246*/
5235static int QAMResetQAM(struct drxk_state *state) 5247static int qam_reset_qam(struct drxk_state *state)
5236{ 5248{
5237 int status; 5249 int status;
5238 u16 cmdResult; 5250 u16 cmd_result;
5239 5251
5240 dprintk(1, "\n"); 5252 dprintk(1, "\n");
5241 /* Stop QAM comstate->m_exec */ 5253 /* Stop QAM comstate->m_exec */
@@ -5243,10 +5255,12 @@ static int QAMResetQAM(struct drxk_state *state)
5243 if (status < 0) 5255 if (status < 0)
5244 goto error; 5256 goto error;
5245 5257
5246 status = scu_command(state, SCU_RAM_COMMAND_STANDARD_QAM | SCU_RAM_COMMAND_CMD_DEMOD_RESET, 0, NULL, 1, &cmdResult); 5258 status = scu_command(state, SCU_RAM_COMMAND_STANDARD_QAM
5259 | SCU_RAM_COMMAND_CMD_DEMOD_RESET,
5260 0, NULL, 1, &cmd_result);
5247error: 5261error:
5248 if (status < 0) 5262 if (status < 0)
5249 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 5263 pr_err("Error %d on %s\n", status, __func__);
5250 return status; 5264 return status;
5251} 5265}
5252 5266
@@ -5258,18 +5272,18 @@ error:
5258* \param channel: pointer to channel data. 5272* \param channel: pointer to channel data.
5259* \return DRXStatus_t. 5273* \return DRXStatus_t.
5260*/ 5274*/
5261static int QAMSetSymbolrate(struct drxk_state *state) 5275static int qam_set_symbolrate(struct drxk_state *state)
5262{ 5276{
5263 u32 adcFrequency = 0; 5277 u32 adc_frequency = 0;
5264 u32 symbFreq = 0; 5278 u32 symb_freq = 0;
5265 u32 iqmRcRate = 0; 5279 u32 iqm_rc_rate = 0;
5266 u16 ratesel = 0; 5280 u16 ratesel = 0;
5267 u32 lcSymbRate = 0; 5281 u32 lc_symb_rate = 0;
5268 int status; 5282 int status;
5269 5283
5270 dprintk(1, "\n"); 5284 dprintk(1, "\n");
5271 /* Select & calculate correct IQM rate */ 5285 /* Select & calculate correct IQM rate */
5272 adcFrequency = (state->m_sysClockFreq * 1000) / 3; 5286 adc_frequency = (state->m_sys_clock_freq * 1000) / 3;
5273 ratesel = 0; 5287 ratesel = 0;
5274 /* printk(KERN_DEBUG "drxk: SR %d\n", state->props.symbol_rate); */ 5288 /* printk(KERN_DEBUG "drxk: SR %d\n", state->props.symbol_rate); */
5275 if (state->props.symbol_rate <= 1188750) 5289 if (state->props.symbol_rate <= 1188750)
@@ -5285,38 +5299,38 @@ static int QAMSetSymbolrate(struct drxk_state *state)
5285 /* 5299 /*
5286 IqmRcRate = ((Fadc / (symbolrate * (4<<ratesel))) - 1) * (1<<23) 5300 IqmRcRate = ((Fadc / (symbolrate * (4<<ratesel))) - 1) * (1<<23)
5287 */ 5301 */
5288 symbFreq = state->props.symbol_rate * (1 << ratesel); 5302 symb_freq = state->props.symbol_rate * (1 << ratesel);
5289 if (symbFreq == 0) { 5303 if (symb_freq == 0) {
5290 /* Divide by zero */ 5304 /* Divide by zero */
5291 status = -EINVAL; 5305 status = -EINVAL;
5292 goto error; 5306 goto error;
5293 } 5307 }
5294 iqmRcRate = (adcFrequency / symbFreq) * (1 << 21) + 5308 iqm_rc_rate = (adc_frequency / symb_freq) * (1 << 21) +
5295 (Frac28a((adcFrequency % symbFreq), symbFreq) >> 7) - 5309 (Frac28a((adc_frequency % symb_freq), symb_freq) >> 7) -
5296 (1 << 23); 5310 (1 << 23);
5297 status = write32(state, IQM_RC_RATE_OFS_LO__A, iqmRcRate); 5311 status = write32(state, IQM_RC_RATE_OFS_LO__A, iqm_rc_rate);
5298 if (status < 0) 5312 if (status < 0)
5299 goto error; 5313 goto error;
5300 state->m_iqmRcRate = iqmRcRate; 5314 state->m_iqm_rc_rate = iqm_rc_rate;
5301 /* 5315 /*
5302 LcSymbFreq = round (.125 * symbolrate / adcFreq * (1<<15)) 5316 LcSymbFreq = round (.125 * symbolrate / adc_freq * (1<<15))
5303 */ 5317 */
5304 symbFreq = state->props.symbol_rate; 5318 symb_freq = state->props.symbol_rate;
5305 if (adcFrequency == 0) { 5319 if (adc_frequency == 0) {
5306 /* Divide by zero */ 5320 /* Divide by zero */
5307 status = -EINVAL; 5321 status = -EINVAL;
5308 goto error; 5322 goto error;
5309 } 5323 }
5310 lcSymbRate = (symbFreq / adcFrequency) * (1 << 12) + 5324 lc_symb_rate = (symb_freq / adc_frequency) * (1 << 12) +
5311 (Frac28a((symbFreq % adcFrequency), adcFrequency) >> 5325 (Frac28a((symb_freq % adc_frequency), adc_frequency) >>
5312 16); 5326 16);
5313 if (lcSymbRate > 511) 5327 if (lc_symb_rate > 511)
5314 lcSymbRate = 511; 5328 lc_symb_rate = 511;
5315 status = write16(state, QAM_LC_SYMBOL_FREQ__A, (u16) lcSymbRate); 5329 status = write16(state, QAM_LC_SYMBOL_FREQ__A, (u16) lc_symb_rate);
5316 5330
5317error: 5331error:
5318 if (status < 0) 5332 if (status < 0)
5319 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 5333 pr_err("Error %d on %s\n", status, __func__);
5320 return status; 5334 return status;
5321} 5335}
5322 5336
@@ -5329,34 +5343,36 @@ error:
5329* \return DRXStatus_t. 5343* \return DRXStatus_t.
5330*/ 5344*/
5331 5345
5332static int GetQAMLockStatus(struct drxk_state *state, u32 *pLockStatus) 5346static int get_qam_lock_status(struct drxk_state *state, u32 *p_lock_status)
5333{ 5347{
5334 int status; 5348 int status;
5335 u16 Result[2] = { 0, 0 }; 5349 u16 result[2] = { 0, 0 };
5336 5350
5337 dprintk(1, "\n"); 5351 dprintk(1, "\n");
5338 *pLockStatus = NOT_LOCKED; 5352 *p_lock_status = NOT_LOCKED;
5339 status = scu_command(state, 5353 status = scu_command(state,
5340 SCU_RAM_COMMAND_STANDARD_QAM | 5354 SCU_RAM_COMMAND_STANDARD_QAM |
5341 SCU_RAM_COMMAND_CMD_DEMOD_GET_LOCK, 0, NULL, 2, 5355 SCU_RAM_COMMAND_CMD_DEMOD_GET_LOCK, 0, NULL, 2,
5342 Result); 5356 result);
5343 if (status < 0) 5357 if (status < 0)
5344 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 5358 pr_err("Error %d on %s\n", status, __func__);
5345 5359
5346 if (Result[1] < SCU_RAM_QAM_LOCKED_LOCKED_DEMOD_LOCKED) { 5360 if (result[1] < SCU_RAM_QAM_LOCKED_LOCKED_DEMOD_LOCKED) {
5347 /* 0x0000 NOT LOCKED */ 5361 /* 0x0000 NOT LOCKED */
5348 } else if (Result[1] < SCU_RAM_QAM_LOCKED_LOCKED_LOCKED) { 5362 } else if (result[1] < SCU_RAM_QAM_LOCKED_LOCKED_LOCKED) {
5349 /* 0x4000 DEMOD LOCKED */ 5363 /* 0x4000 DEMOD LOCKED */
5350 *pLockStatus = DEMOD_LOCK; 5364 *p_lock_status = DEMOD_LOCK;
5351 } else if (Result[1] < SCU_RAM_QAM_LOCKED_LOCKED_NEVER_LOCK) { 5365 } else if (result[1] < SCU_RAM_QAM_LOCKED_LOCKED_NEVER_LOCK) {
5352 /* 0x8000 DEMOD + FEC LOCKED (system lock) */ 5366 /* 0x8000 DEMOD + FEC LOCKED (system lock) */
5353 *pLockStatus = MPEG_LOCK; 5367 *p_lock_status = MPEG_LOCK;
5354 } else { 5368 } else {
5355 /* 0xC000 NEVER LOCKED */ 5369 /* 0xC000 NEVER LOCKED */
5356 /* (system will never be able to lock to the signal) */ 5370 /* (system will never be able to lock to the signal) */
5357 /* TODO: check this, intermediate & standard specific lock states are not 5371 /*
5358 taken into account here */ 5372 * TODO: check this, intermediate & standard specific lock
5359 *pLockStatus = NEVER_LOCK; 5373 * states are not taken into account here
5374 */
5375 *p_lock_status = NEVER_LOCK;
5360 } 5376 }
5361 return status; 5377 return status;
5362} 5378}
@@ -5368,68 +5384,70 @@ static int GetQAMLockStatus(struct drxk_state *state, u32 *pLockStatus)
5368#define QAM_LOCKRANGE__M 0x10 5384#define QAM_LOCKRANGE__M 0x10
5369#define QAM_LOCKRANGE_NORMAL 0x10 5385#define QAM_LOCKRANGE_NORMAL 0x10
5370 5386
5371static int QAMDemodulatorCommand(struct drxk_state *state, 5387static int qam_demodulator_command(struct drxk_state *state,
5372 int numberOfParameters) 5388 int number_of_parameters)
5373{ 5389{
5374 int status; 5390 int status;
5375 u16 cmdResult; 5391 u16 cmd_result;
5376 u16 setParamParameters[4] = { 0, 0, 0, 0 }; 5392 u16 set_param_parameters[4] = { 0, 0, 0, 0 };
5377 5393
5378 setParamParameters[0] = state->m_Constellation; /* modulation */ 5394 set_param_parameters[0] = state->m_constellation; /* modulation */
5379 setParamParameters[1] = DRXK_QAM_I12_J17; /* interleave mode */ 5395 set_param_parameters[1] = DRXK_QAM_I12_J17; /* interleave mode */
5380 5396
5381 if (numberOfParameters == 2) { 5397 if (number_of_parameters == 2) {
5382 u16 setEnvParameters[1] = { 0 }; 5398 u16 set_env_parameters[1] = { 0 };
5383 5399
5384 if (state->m_OperationMode == OM_QAM_ITU_C) 5400 if (state->m_operation_mode == OM_QAM_ITU_C)
5385 setEnvParameters[0] = QAM_TOP_ANNEX_C; 5401 set_env_parameters[0] = QAM_TOP_ANNEX_C;
5386 else 5402 else
5387 setEnvParameters[0] = QAM_TOP_ANNEX_A; 5403 set_env_parameters[0] = QAM_TOP_ANNEX_A;
5388 5404
5389 status = scu_command(state, 5405 status = scu_command(state,
5390 SCU_RAM_COMMAND_STANDARD_QAM | SCU_RAM_COMMAND_CMD_DEMOD_SET_ENV, 5406 SCU_RAM_COMMAND_STANDARD_QAM
5391 1, setEnvParameters, 1, &cmdResult); 5407 | SCU_RAM_COMMAND_CMD_DEMOD_SET_ENV,
5408 1, set_env_parameters, 1, &cmd_result);
5392 if (status < 0) 5409 if (status < 0)
5393 goto error; 5410 goto error;
5394 5411
5395 status = scu_command(state, 5412 status = scu_command(state,
5396 SCU_RAM_COMMAND_STANDARD_QAM | SCU_RAM_COMMAND_CMD_DEMOD_SET_PARAM, 5413 SCU_RAM_COMMAND_STANDARD_QAM
5397 numberOfParameters, setParamParameters, 5414 | SCU_RAM_COMMAND_CMD_DEMOD_SET_PARAM,
5398 1, &cmdResult); 5415 number_of_parameters, set_param_parameters,
5399 } else if (numberOfParameters == 4) { 5416 1, &cmd_result);
5400 if (state->m_OperationMode == OM_QAM_ITU_C) 5417 } else if (number_of_parameters == 4) {
5401 setParamParameters[2] = QAM_TOP_ANNEX_C; 5418 if (state->m_operation_mode == OM_QAM_ITU_C)
5419 set_param_parameters[2] = QAM_TOP_ANNEX_C;
5402 else 5420 else
5403 setParamParameters[2] = QAM_TOP_ANNEX_A; 5421 set_param_parameters[2] = QAM_TOP_ANNEX_A;
5404 5422
5405 setParamParameters[3] |= (QAM_MIRROR_AUTO_ON); 5423 set_param_parameters[3] |= (QAM_MIRROR_AUTO_ON);
5406 /* Env parameters */ 5424 /* Env parameters */
5407 /* check for LOCKRANGE Extented */ 5425 /* check for LOCKRANGE Extented */
5408 /* setParamParameters[3] |= QAM_LOCKRANGE_NORMAL; */ 5426 /* set_param_parameters[3] |= QAM_LOCKRANGE_NORMAL; */
5409 5427
5410 status = scu_command(state, 5428 status = scu_command(state,
5411 SCU_RAM_COMMAND_STANDARD_QAM | SCU_RAM_COMMAND_CMD_DEMOD_SET_PARAM, 5429 SCU_RAM_COMMAND_STANDARD_QAM
5412 numberOfParameters, setParamParameters, 5430 | SCU_RAM_COMMAND_CMD_DEMOD_SET_PARAM,
5413 1, &cmdResult); 5431 number_of_parameters, set_param_parameters,
5432 1, &cmd_result);
5414 } else { 5433 } else {
5415 printk(KERN_WARNING "drxk: Unknown QAM demodulator parameter " 5434 pr_warn("Unknown QAM demodulator parameter count %d\n",
5416 "count %d\n", numberOfParameters); 5435 number_of_parameters);
5417 status = -EINVAL; 5436 status = -EINVAL;
5418 } 5437 }
5419 5438
5420error: 5439error:
5421 if (status < 0) 5440 if (status < 0)
5422 printk(KERN_WARNING "drxk: Warning %d on %s\n", 5441 pr_warn("Warning %d on %s\n", status, __func__);
5423 status, __func__);
5424 return status; 5442 return status;
5425} 5443}
5426 5444
5427static int SetQAM(struct drxk_state *state, u16 IntermediateFreqkHz, 5445static int set_qam(struct drxk_state *state, u16 intermediate_freqk_hz,
5428 s32 tunerFreqOffset) 5446 s32 tuner_freq_offset)
5429{ 5447{
5430 int status; 5448 int status;
5431 u16 cmdResult; 5449 u16 cmd_result;
5432 int qamDemodParamCount = state->qam_demod_parameter_count; 5450 int qam_demod_param_count = state->qam_demod_parameter_count;
5433 5451
5434 dprintk(1, "\n"); 5452 dprintk(1, "\n");
5435 /* 5453 /*
@@ -5444,7 +5462,7 @@ static int SetQAM(struct drxk_state *state, u16 IntermediateFreqkHz,
5444 status = write16(state, FEC_RS_COMM_EXEC__A, FEC_RS_COMM_EXEC_STOP); 5462 status = write16(state, FEC_RS_COMM_EXEC__A, FEC_RS_COMM_EXEC_STOP);
5445 if (status < 0) 5463 if (status < 0)
5446 goto error; 5464 goto error;
5447 status = QAMResetQAM(state); 5465 status = qam_reset_qam(state);
5448 if (status < 0) 5466 if (status < 0)
5449 goto error; 5467 goto error;
5450 5468
@@ -5453,27 +5471,27 @@ static int SetQAM(struct drxk_state *state, u16 IntermediateFreqkHz,
5453 * -set params; resets IQM,QAM,FEC HW; initializes some 5471 * -set params; resets IQM,QAM,FEC HW; initializes some
5454 * SCU variables 5472 * SCU variables
5455 */ 5473 */
5456 status = QAMSetSymbolrate(state); 5474 status = qam_set_symbolrate(state);
5457 if (status < 0) 5475 if (status < 0)
5458 goto error; 5476 goto error;
5459 5477
5460 /* Set params */ 5478 /* Set params */
5461 switch (state->props.modulation) { 5479 switch (state->props.modulation) {
5462 case QAM_256: 5480 case QAM_256:
5463 state->m_Constellation = DRX_CONSTELLATION_QAM256; 5481 state->m_constellation = DRX_CONSTELLATION_QAM256;
5464 break; 5482 break;
5465 case QAM_AUTO: 5483 case QAM_AUTO:
5466 case QAM_64: 5484 case QAM_64:
5467 state->m_Constellation = DRX_CONSTELLATION_QAM64; 5485 state->m_constellation = DRX_CONSTELLATION_QAM64;
5468 break; 5486 break;
5469 case QAM_16: 5487 case QAM_16:
5470 state->m_Constellation = DRX_CONSTELLATION_QAM16; 5488 state->m_constellation = DRX_CONSTELLATION_QAM16;
5471 break; 5489 break;
5472 case QAM_32: 5490 case QAM_32:
5473 state->m_Constellation = DRX_CONSTELLATION_QAM32; 5491 state->m_constellation = DRX_CONSTELLATION_QAM32;
5474 break; 5492 break;
5475 case QAM_128: 5493 case QAM_128:
5476 state->m_Constellation = DRX_CONSTELLATION_QAM128; 5494 state->m_constellation = DRX_CONSTELLATION_QAM128;
5477 break; 5495 break;
5478 default: 5496 default:
5479 status = -EINVAL; 5497 status = -EINVAL;
@@ -5486,8 +5504,8 @@ static int SetQAM(struct drxk_state *state, u16 IntermediateFreqkHz,
5486 * the correct command. */ 5504 * the correct command. */
5487 if (state->qam_demod_parameter_count == 4 5505 if (state->qam_demod_parameter_count == 4
5488 || !state->qam_demod_parameter_count) { 5506 || !state->qam_demod_parameter_count) {
5489 qamDemodParamCount = 4; 5507 qam_demod_param_count = 4;
5490 status = QAMDemodulatorCommand(state, qamDemodParamCount); 5508 status = qam_demodulator_command(state, qam_demod_param_count);
5491 } 5509 }
5492 5510
5493 /* Use the 2-parameter command if it was requested or if we're 5511 /* Use the 2-parameter command if it was requested or if we're
@@ -5495,27 +5513,27 @@ static int SetQAM(struct drxk_state *state, u16 IntermediateFreqkHz,
5495 * failed. */ 5513 * failed. */
5496 if (state->qam_demod_parameter_count == 2 5514 if (state->qam_demod_parameter_count == 2
5497 || (!state->qam_demod_parameter_count && status < 0)) { 5515 || (!state->qam_demod_parameter_count && status < 0)) {
5498 qamDemodParamCount = 2; 5516 qam_demod_param_count = 2;
5499 status = QAMDemodulatorCommand(state, qamDemodParamCount); 5517 status = qam_demodulator_command(state, qam_demod_param_count);
5500 } 5518 }
5501 5519
5502 if (status < 0) { 5520 if (status < 0) {
5503 dprintk(1, "Could not set demodulator parameters. Make " 5521 dprintk(1, "Could not set demodulator parameters.\n");
5504 "sure qam_demod_parameter_count (%d) is correct for " 5522 dprintk(1,
5505 "your firmware (%s).\n", 5523 "Make sure qam_demod_parameter_count (%d) is correct for your firmware (%s).\n",
5506 state->qam_demod_parameter_count, 5524 state->qam_demod_parameter_count,
5507 state->microcode_name); 5525 state->microcode_name);
5508 goto error; 5526 goto error;
5509 } else if (!state->qam_demod_parameter_count) { 5527 } else if (!state->qam_demod_parameter_count) {
5510 dprintk(1, "Auto-probing the correct QAM demodulator command " 5528 dprintk(1,
5511 "parameters was successful - using %d parameters.\n", 5529 "Auto-probing the QAM command parameters was successful - using %d parameters.\n",
5512 qamDemodParamCount); 5530 qam_demod_param_count);
5513 5531
5514 /* 5532 /*
5515 * One of our commands was successful. We don't need to 5533 * One of our commands was successful. We don't need to
5516 * auto-probe anymore, now that we got the correct command. 5534 * auto-probe anymore, now that we got the correct command.
5517 */ 5535 */
5518 state->qam_demod_parameter_count = qamDemodParamCount; 5536 state->qam_demod_parameter_count = qam_demod_param_count;
5519 } 5537 }
5520 5538
5521 /* 5539 /*
@@ -5523,16 +5541,18 @@ static int SetQAM(struct drxk_state *state, u16 IntermediateFreqkHz,
5523 * signal setup modulation independent registers 5541 * signal setup modulation independent registers
5524 */ 5542 */
5525#if 0 5543#if 0
5526 status = SetFrequency(channel, tunerFreqOffset)); 5544 status = set_frequency(channel, tuner_freq_offset));
5527 if (status < 0) 5545 if (status < 0)
5528 goto error; 5546 goto error;
5529#endif 5547#endif
5530 status = SetFrequencyShifter(state, IntermediateFreqkHz, tunerFreqOffset, true); 5548 status = set_frequency_shifter(state, intermediate_freqk_hz,
5549 tuner_freq_offset, true);
5531 if (status < 0) 5550 if (status < 0)
5532 goto error; 5551 goto error;
5533 5552
5534 /* Setup BER measurement */ 5553 /* Setup BER measurement */
5535 status = SetQAMMeasurement(state, state->m_Constellation, state->props.symbol_rate); 5554 status = set_qam_measurement(state, state->m_constellation,
5555 state->props.symbol_rate);
5536 if (status < 0) 5556 if (status < 0)
5537 goto error; 5557 goto error;
5538 5558
@@ -5605,7 +5625,8 @@ static int SetQAM(struct drxk_state *state, u16 IntermediateFreqkHz,
5605 goto error; 5625 goto error;
5606 5626
5607 /* Mirroring, QAM-block starting point not inverted */ 5627 /* Mirroring, QAM-block starting point not inverted */
5608 status = write16(state, QAM_SY_SP_INV__A, QAM_SY_SP_INV_SPECTRUM_INV_DIS); 5628 status = write16(state, QAM_SY_SP_INV__A,
5629 QAM_SY_SP_INV_SPECTRUM_INV_DIS);
5609 if (status < 0) 5630 if (status < 0)
5610 goto error; 5631 goto error;
5611 5632
@@ -5617,20 +5638,20 @@ static int SetQAM(struct drxk_state *state, u16 IntermediateFreqkHz,
5617 /* STEP 4: modulation specific setup */ 5638 /* STEP 4: modulation specific setup */
5618 switch (state->props.modulation) { 5639 switch (state->props.modulation) {
5619 case QAM_16: 5640 case QAM_16:
5620 status = SetQAM16(state); 5641 status = set_qam16(state);
5621 break; 5642 break;
5622 case QAM_32: 5643 case QAM_32:
5623 status = SetQAM32(state); 5644 status = set_qam32(state);
5624 break; 5645 break;
5625 case QAM_AUTO: 5646 case QAM_AUTO:
5626 case QAM_64: 5647 case QAM_64:
5627 status = SetQAM64(state); 5648 status = set_qam64(state);
5628 break; 5649 break;
5629 case QAM_128: 5650 case QAM_128:
5630 status = SetQAM128(state); 5651 status = set_qam128(state);
5631 break; 5652 break;
5632 case QAM_256: 5653 case QAM_256:
5633 status = SetQAM256(state); 5654 status = set_qam256(state);
5634 break; 5655 break;
5635 default: 5656 default:
5636 status = -EINVAL; 5657 status = -EINVAL;
@@ -5647,12 +5668,12 @@ static int SetQAM(struct drxk_state *state, u16 IntermediateFreqkHz,
5647 /* Re-configure MPEG output, requires knowledge of channel bitrate */ 5668 /* Re-configure MPEG output, requires knowledge of channel bitrate */
5648 /* extAttr->currentChannel.modulation = channel->modulation; */ 5669 /* extAttr->currentChannel.modulation = channel->modulation; */
5649 /* extAttr->currentChannel.symbolrate = channel->symbolrate; */ 5670 /* extAttr->currentChannel.symbolrate = channel->symbolrate; */
5650 status = MPEGTSDtoSetup(state, state->m_OperationMode); 5671 status = mpegts_dto_setup(state, state->m_operation_mode);
5651 if (status < 0) 5672 if (status < 0)
5652 goto error; 5673 goto error;
5653 5674
5654 /* Start processes */ 5675 /* start processes */
5655 status = MPEGTSStart(state); 5676 status = mpegts_start(state);
5656 if (status < 0) 5677 if (status < 0)
5657 goto error; 5678 goto error;
5658 status = write16(state, FEC_COMM_EXEC__A, FEC_COMM_EXEC_ACTIVE); 5679 status = write16(state, FEC_COMM_EXEC__A, FEC_COMM_EXEC_ACTIVE);
@@ -5666,7 +5687,9 @@ static int SetQAM(struct drxk_state *state, u16 IntermediateFreqkHz,
5666 goto error; 5687 goto error;
5667 5688
5668 /* STEP 5: start QAM demodulator (starts FEC, QAM and IQM HW) */ 5689 /* STEP 5: start QAM demodulator (starts FEC, QAM and IQM HW) */
5669 status = scu_command(state, SCU_RAM_COMMAND_STANDARD_QAM | SCU_RAM_COMMAND_CMD_DEMOD_START, 0, NULL, 1, &cmdResult); 5690 status = scu_command(state, SCU_RAM_COMMAND_STANDARD_QAM
5691 | SCU_RAM_COMMAND_CMD_DEMOD_START,
5692 0, NULL, 1, &cmd_result);
5670 if (status < 0) 5693 if (status < 0)
5671 goto error; 5694 goto error;
5672 5695
@@ -5675,12 +5698,12 @@ static int SetQAM(struct drxk_state *state, u16 IntermediateFreqkHz,
5675 5698
5676error: 5699error:
5677 if (status < 0) 5700 if (status < 0)
5678 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 5701 pr_err("Error %d on %s\n", status, __func__);
5679 return status; 5702 return status;
5680} 5703}
5681 5704
5682static int SetQAMStandard(struct drxk_state *state, 5705static int set_qam_standard(struct drxk_state *state,
5683 enum OperationMode oMode) 5706 enum operation_mode o_mode)
5684{ 5707{
5685 int status; 5708 int status;
5686#ifdef DRXK_QAM_TAPS 5709#ifdef DRXK_QAM_TAPS
@@ -5692,14 +5715,14 @@ static int SetQAMStandard(struct drxk_state *state,
5692 dprintk(1, "\n"); 5715 dprintk(1, "\n");
5693 5716
5694 /* added antenna switch */ 5717 /* added antenna switch */
5695 SwitchAntennaToQAM(state); 5718 switch_antenna_to_qam(state);
5696 5719
5697 /* Ensure correct power-up mode */ 5720 /* Ensure correct power-up mode */
5698 status = PowerUpQAM(state); 5721 status = power_up_qam(state);
5699 if (status < 0) 5722 if (status < 0)
5700 goto error; 5723 goto error;
5701 /* Reset QAM block */ 5724 /* Reset QAM block */
5702 status = QAMResetQAM(state); 5725 status = qam_reset_qam(state);
5703 if (status < 0) 5726 if (status < 0)
5704 goto error; 5727 goto error;
5705 5728
@@ -5714,15 +5737,24 @@ static int SetQAMStandard(struct drxk_state *state,
5714 5737
5715 /* Upload IQM Channel Filter settings by 5738 /* Upload IQM Channel Filter settings by
5716 boot loader from ROM table */ 5739 boot loader from ROM table */
5717 switch (oMode) { 5740 switch (o_mode) {
5718 case OM_QAM_ITU_A: 5741 case OM_QAM_ITU_A:
5719 status = BLChainCmd(state, DRXK_BL_ROM_OFFSET_TAPS_ITU_A, DRXK_BLCC_NR_ELEMENTS_TAPS, DRXK_BLC_TIMEOUT); 5742 status = bl_chain_cmd(state, DRXK_BL_ROM_OFFSET_TAPS_ITU_A,
5743 DRXK_BLCC_NR_ELEMENTS_TAPS,
5744 DRXK_BLC_TIMEOUT);
5720 break; 5745 break;
5721 case OM_QAM_ITU_C: 5746 case OM_QAM_ITU_C:
5722 status = BLDirectCmd(state, IQM_CF_TAP_RE0__A, DRXK_BL_ROM_OFFSET_TAPS_ITU_C, DRXK_BLDC_NR_ELEMENTS_TAPS, DRXK_BLC_TIMEOUT); 5747 status = bl_direct_cmd(state, IQM_CF_TAP_RE0__A,
5748 DRXK_BL_ROM_OFFSET_TAPS_ITU_C,
5749 DRXK_BLDC_NR_ELEMENTS_TAPS,
5750 DRXK_BLC_TIMEOUT);
5723 if (status < 0) 5751 if (status < 0)
5724 goto error; 5752 goto error;
5725 status = BLDirectCmd(state, IQM_CF_TAP_IM0__A, DRXK_BL_ROM_OFFSET_TAPS_ITU_C, DRXK_BLDC_NR_ELEMENTS_TAPS, DRXK_BLC_TIMEOUT); 5753 status = bl_direct_cmd(state,
5754 IQM_CF_TAP_IM0__A,
5755 DRXK_BL_ROM_OFFSET_TAPS_ITU_C,
5756 DRXK_BLDC_NR_ELEMENTS_TAPS,
5757 DRXK_BLC_TIMEOUT);
5726 break; 5758 break;
5727 default: 5759 default:
5728 status = -EINVAL; 5760 status = -EINVAL;
@@ -5730,13 +5762,14 @@ static int SetQAMStandard(struct drxk_state *state,
5730 if (status < 0) 5762 if (status < 0)
5731 goto error; 5763 goto error;
5732 5764
5733 status = write16(state, IQM_CF_OUT_ENA__A, (1 << IQM_CF_OUT_ENA_QAM__B)); 5765 status = write16(state, IQM_CF_OUT_ENA__A, 1 << IQM_CF_OUT_ENA_QAM__B);
5734 if (status < 0) 5766 if (status < 0)
5735 goto error; 5767 goto error;
5736 status = write16(state, IQM_CF_SYMMETRIC__A, 0); 5768 status = write16(state, IQM_CF_SYMMETRIC__A, 0);
5737 if (status < 0) 5769 if (status < 0)
5738 goto error; 5770 goto error;
5739 status = write16(state, IQM_CF_MIDTAP__A, ((1 << IQM_CF_MIDTAP_RE__B) | (1 << IQM_CF_MIDTAP_IM__B))); 5771 status = write16(state, IQM_CF_MIDTAP__A,
5772 ((1 << IQM_CF_MIDTAP_RE__B) | (1 << IQM_CF_MIDTAP_IM__B)));
5740 if (status < 0) 5773 if (status < 0)
5741 goto error; 5774 goto error;
5742 5775
@@ -5793,7 +5826,7 @@ static int SetQAMStandard(struct drxk_state *state,
5793 goto error; 5826 goto error;
5794 5827
5795 /* turn on IQMAF. Must be done before setAgc**() */ 5828 /* turn on IQMAF. Must be done before setAgc**() */
5796 status = SetIqmAf(state, true); 5829 status = set_iqm_af(state, true);
5797 if (status < 0) 5830 if (status < 0)
5798 goto error; 5831 goto error;
5799 status = write16(state, IQM_AF_START_LOCK__A, 0x01); 5832 status = write16(state, IQM_AF_START_LOCK__A, 0x01);
@@ -5801,7 +5834,7 @@ static int SetQAMStandard(struct drxk_state *state,
5801 goto error; 5834 goto error;
5802 5835
5803 /* IQM will not be reset from here, sync ADC and update/init AGC */ 5836 /* IQM will not be reset from here, sync ADC and update/init AGC */
5804 status = ADCSynchronization(state); 5837 status = adc_synchronization(state);
5805 if (status < 0) 5838 if (status < 0)
5806 goto error; 5839 goto error;
5807 5840
@@ -5818,18 +5851,18 @@ static int SetQAMStandard(struct drxk_state *state,
5818 /* No more resets of the IQM, current standard correctly set => 5851 /* No more resets of the IQM, current standard correctly set =>
5819 now AGCs can be configured. */ 5852 now AGCs can be configured. */
5820 5853
5821 status = InitAGC(state, true); 5854 status = init_agc(state, true);
5822 if (status < 0) 5855 if (status < 0)
5823 goto error; 5856 goto error;
5824 status = SetPreSaw(state, &(state->m_qamPreSawCfg)); 5857 status = set_pre_saw(state, &(state->m_qam_pre_saw_cfg));
5825 if (status < 0) 5858 if (status < 0)
5826 goto error; 5859 goto error;
5827 5860
5828 /* Configure AGC's */ 5861 /* Configure AGC's */
5829 status = SetAgcRf(state, &(state->m_qamRfAgcCfg), true); 5862 status = set_agc_rf(state, &(state->m_qam_rf_agc_cfg), true);
5830 if (status < 0) 5863 if (status < 0)
5831 goto error; 5864 goto error;
5832 status = SetAgcIf(state, &(state->m_qamIfAgcCfg), true); 5865 status = set_agc_if(state, &(state->m_qam_if_agc_cfg), true);
5833 if (status < 0) 5866 if (status < 0)
5834 goto error; 5867 goto error;
5835 5868
@@ -5837,18 +5870,19 @@ static int SetQAMStandard(struct drxk_state *state,
5837 status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_ACTIVE); 5870 status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_ACTIVE);
5838error: 5871error:
5839 if (status < 0) 5872 if (status < 0)
5840 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 5873 pr_err("Error %d on %s\n", status, __func__);
5841 return status; 5874 return status;
5842} 5875}
5843 5876
5844static int WriteGPIO(struct drxk_state *state) 5877static int write_gpio(struct drxk_state *state)
5845{ 5878{
5846 int status; 5879 int status;
5847 u16 value = 0; 5880 u16 value = 0;
5848 5881
5849 dprintk(1, "\n"); 5882 dprintk(1, "\n");
5850 /* stop lock indicator process */ 5883 /* stop lock indicator process */
5851 status = write16(state, SCU_RAM_GPIO__A, SCU_RAM_GPIO_HW_LOCK_IND_DISABLE); 5884 status = write16(state, SCU_RAM_GPIO__A,
5885 SCU_RAM_GPIO_HW_LOCK_IND_DISABLE);
5852 if (status < 0) 5886 if (status < 0)
5853 goto error; 5887 goto error;
5854 5888
@@ -5857,10 +5891,11 @@ static int WriteGPIO(struct drxk_state *state)
5857 if (status < 0) 5891 if (status < 0)
5858 goto error; 5892 goto error;
5859 5893
5860 if (state->m_hasSAWSW) { 5894 if (state->m_has_sawsw) {
5861 if (state->UIO_mask & 0x0001) { /* UIO-1 */ 5895 if (state->uio_mask & 0x0001) { /* UIO-1 */
5862 /* write to io pad configuration register - output mode */ 5896 /* write to io pad configuration register - output mode */
5863 status = write16(state, SIO_PDR_SMA_TX_CFG__A, state->m_GPIOCfg); 5897 status = write16(state, SIO_PDR_SMA_TX_CFG__A,
5898 state->m_gpio_cfg);
5864 if (status < 0) 5899 if (status < 0)
5865 goto error; 5900 goto error;
5866 5901
@@ -5868,7 +5903,7 @@ static int WriteGPIO(struct drxk_state *state)
5868 status = read16(state, SIO_PDR_UIO_OUT_LO__A, &value); 5903 status = read16(state, SIO_PDR_UIO_OUT_LO__A, &value);
5869 if (status < 0) 5904 if (status < 0)
5870 goto error; 5905 goto error;
5871 if ((state->m_GPIO & 0x0001) == 0) 5906 if ((state->m_gpio & 0x0001) == 0)
5872 value &= 0x7FFF; /* write zero to 15th bit - 1st UIO */ 5907 value &= 0x7FFF; /* write zero to 15th bit - 1st UIO */
5873 else 5908 else
5874 value |= 0x8000; /* write one to 15th bit - 1st UIO */ 5909 value |= 0x8000; /* write one to 15th bit - 1st UIO */
@@ -5877,9 +5912,10 @@ static int WriteGPIO(struct drxk_state *state)
5877 if (status < 0) 5912 if (status < 0)
5878 goto error; 5913 goto error;
5879 } 5914 }
5880 if (state->UIO_mask & 0x0002) { /* UIO-2 */ 5915 if (state->uio_mask & 0x0002) { /* UIO-2 */
5881 /* write to io pad configuration register - output mode */ 5916 /* write to io pad configuration register - output mode */
5882 status = write16(state, SIO_PDR_SMA_RX_CFG__A, state->m_GPIOCfg); 5917 status = write16(state, SIO_PDR_SMA_RX_CFG__A,
5918 state->m_gpio_cfg);
5883 if (status < 0) 5919 if (status < 0)
5884 goto error; 5920 goto error;
5885 5921
@@ -5887,7 +5923,7 @@ static int WriteGPIO(struct drxk_state *state)
5887 status = read16(state, SIO_PDR_UIO_OUT_LO__A, &value); 5923 status = read16(state, SIO_PDR_UIO_OUT_LO__A, &value);
5888 if (status < 0) 5924 if (status < 0)
5889 goto error; 5925 goto error;
5890 if ((state->m_GPIO & 0x0002) == 0) 5926 if ((state->m_gpio & 0x0002) == 0)
5891 value &= 0xBFFF; /* write zero to 14th bit - 2st UIO */ 5927 value &= 0xBFFF; /* write zero to 14th bit - 2st UIO */
5892 else 5928 else
5893 value |= 0x4000; /* write one to 14th bit - 2st UIO */ 5929 value |= 0x4000; /* write one to 14th bit - 2st UIO */
@@ -5896,9 +5932,10 @@ static int WriteGPIO(struct drxk_state *state)
5896 if (status < 0) 5932 if (status < 0)
5897 goto error; 5933 goto error;
5898 } 5934 }
5899 if (state->UIO_mask & 0x0004) { /* UIO-3 */ 5935 if (state->uio_mask & 0x0004) { /* UIO-3 */
5900 /* write to io pad configuration register - output mode */ 5936 /* write to io pad configuration register - output mode */
5901 status = write16(state, SIO_PDR_GPIO_CFG__A, state->m_GPIOCfg); 5937 status = write16(state, SIO_PDR_GPIO_CFG__A,
5938 state->m_gpio_cfg);
5902 if (status < 0) 5939 if (status < 0)
5903 goto error; 5940 goto error;
5904 5941
@@ -5906,7 +5943,7 @@ static int WriteGPIO(struct drxk_state *state)
5906 status = read16(state, SIO_PDR_UIO_OUT_LO__A, &value); 5943 status = read16(state, SIO_PDR_UIO_OUT_LO__A, &value);
5907 if (status < 0) 5944 if (status < 0)
5908 goto error; 5945 goto error;
5909 if ((state->m_GPIO & 0x0004) == 0) 5946 if ((state->m_gpio & 0x0004) == 0)
5910 value &= 0xFFFB; /* write zero to 2nd bit - 3rd UIO */ 5947 value &= 0xFFFB; /* write zero to 2nd bit - 3rd UIO */
5911 else 5948 else
5912 value |= 0x0004; /* write one to 2nd bit - 3rd UIO */ 5949 value |= 0x0004; /* write one to 2nd bit - 3rd UIO */
@@ -5920,11 +5957,11 @@ static int WriteGPIO(struct drxk_state *state)
5920 status = write16(state, SIO_TOP_COMM_KEY__A, 0x0000); 5957 status = write16(state, SIO_TOP_COMM_KEY__A, 0x0000);
5921error: 5958error:
5922 if (status < 0) 5959 if (status < 0)
5923 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 5960 pr_err("Error %d on %s\n", status, __func__);
5924 return status; 5961 return status;
5925} 5962}
5926 5963
5927static int SwitchAntennaToQAM(struct drxk_state *state) 5964static int switch_antenna_to_qam(struct drxk_state *state)
5928{ 5965{
5929 int status = 0; 5966 int status = 0;
5930 bool gpio_state; 5967 bool gpio_state;
@@ -5934,22 +5971,22 @@ static int SwitchAntennaToQAM(struct drxk_state *state)
5934 if (!state->antenna_gpio) 5971 if (!state->antenna_gpio)
5935 return 0; 5972 return 0;
5936 5973
5937 gpio_state = state->m_GPIO & state->antenna_gpio; 5974 gpio_state = state->m_gpio & state->antenna_gpio;
5938 5975
5939 if (state->antenna_dvbt ^ gpio_state) { 5976 if (state->antenna_dvbt ^ gpio_state) {
5940 /* Antenna is on DVB-T mode. Switch */ 5977 /* Antenna is on DVB-T mode. Switch */
5941 if (state->antenna_dvbt) 5978 if (state->antenna_dvbt)
5942 state->m_GPIO &= ~state->antenna_gpio; 5979 state->m_gpio &= ~state->antenna_gpio;
5943 else 5980 else
5944 state->m_GPIO |= state->antenna_gpio; 5981 state->m_gpio |= state->antenna_gpio;
5945 status = WriteGPIO(state); 5982 status = write_gpio(state);
5946 } 5983 }
5947 if (status < 0) 5984 if (status < 0)
5948 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 5985 pr_err("Error %d on %s\n", status, __func__);
5949 return status; 5986 return status;
5950} 5987}
5951 5988
5952static int SwitchAntennaToDVBT(struct drxk_state *state) 5989static int switch_antenna_to_dvbt(struct drxk_state *state)
5953{ 5990{
5954 int status = 0; 5991 int status = 0;
5955 bool gpio_state; 5992 bool gpio_state;
@@ -5959,23 +5996,23 @@ static int SwitchAntennaToDVBT(struct drxk_state *state)
5959 if (!state->antenna_gpio) 5996 if (!state->antenna_gpio)
5960 return 0; 5997 return 0;
5961 5998
5962 gpio_state = state->m_GPIO & state->antenna_gpio; 5999 gpio_state = state->m_gpio & state->antenna_gpio;
5963 6000
5964 if (!(state->antenna_dvbt ^ gpio_state)) { 6001 if (!(state->antenna_dvbt ^ gpio_state)) {
5965 /* Antenna is on DVB-C mode. Switch */ 6002 /* Antenna is on DVB-C mode. Switch */
5966 if (state->antenna_dvbt) 6003 if (state->antenna_dvbt)
5967 state->m_GPIO |= state->antenna_gpio; 6004 state->m_gpio |= state->antenna_gpio;
5968 else 6005 else
5969 state->m_GPIO &= ~state->antenna_gpio; 6006 state->m_gpio &= ~state->antenna_gpio;
5970 status = WriteGPIO(state); 6007 status = write_gpio(state);
5971 } 6008 }
5972 if (status < 0) 6009 if (status < 0)
5973 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 6010 pr_err("Error %d on %s\n", status, __func__);
5974 return status; 6011 return status;
5975} 6012}
5976 6013
5977 6014
5978static int PowerDownDevice(struct drxk_state *state) 6015static int power_down_device(struct drxk_state *state)
5979{ 6016{
5980 /* Power down to requested mode */ 6017 /* Power down to requested mode */
5981 /* Backup some register settings */ 6018 /* Backup some register settings */
@@ -5986,28 +6023,29 @@ static int PowerDownDevice(struct drxk_state *state)
5986 int status; 6023 int status;
5987 6024
5988 dprintk(1, "\n"); 6025 dprintk(1, "\n");
5989 if (state->m_bPDownOpenBridge) { 6026 if (state->m_b_p_down_open_bridge) {
5990 /* Open I2C bridge before power down of DRXK */ 6027 /* Open I2C bridge before power down of DRXK */
5991 status = ConfigureI2CBridge(state, true); 6028 status = ConfigureI2CBridge(state, true);
5992 if (status < 0) 6029 if (status < 0)
5993 goto error; 6030 goto error;
5994 } 6031 }
5995 /* driver 0.9.0 */ 6032 /* driver 0.9.0 */
5996 status = DVBTEnableOFDMTokenRing(state, false); 6033 status = dvbt_enable_ofdm_token_ring(state, false);
5997 if (status < 0) 6034 if (status < 0)
5998 goto error; 6035 goto error;
5999 6036
6000 status = write16(state, SIO_CC_PWD_MODE__A, SIO_CC_PWD_MODE_LEVEL_CLOCK); 6037 status = write16(state, SIO_CC_PWD_MODE__A,
6038 SIO_CC_PWD_MODE_LEVEL_CLOCK);
6001 if (status < 0) 6039 if (status < 0)
6002 goto error; 6040 goto error;
6003 status = write16(state, SIO_CC_UPDATE__A, SIO_CC_UPDATE_KEY); 6041 status = write16(state, SIO_CC_UPDATE__A, SIO_CC_UPDATE_KEY);
6004 if (status < 0) 6042 if (status < 0)
6005 goto error; 6043 goto error;
6006 state->m_HICfgCtrl |= SIO_HI_RA_RAM_PAR_5_CFG_SLEEP_ZZZ; 6044 state->m_hi_cfg_ctrl |= SIO_HI_RA_RAM_PAR_5_CFG_SLEEP_ZZZ;
6007 status = HI_CfgCommand(state); 6045 status = hi_cfg_command(state);
6008error: 6046error:
6009 if (status < 0) 6047 if (status < 0)
6010 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 6048 pr_err("Error %d on %s\n", status, __func__);
6011 6049
6012 return status; 6050 return status;
6013} 6051}
@@ -6015,50 +6053,56 @@ error:
6015static int init_drxk(struct drxk_state *state) 6053static int init_drxk(struct drxk_state *state)
6016{ 6054{
6017 int status = 0, n = 0; 6055 int status = 0, n = 0;
6018 enum DRXPowerMode powerMode = DRXK_POWER_DOWN_OFDM; 6056 enum drx_power_mode power_mode = DRXK_POWER_DOWN_OFDM;
6019 u16 driverVersion; 6057 u16 driver_version;
6020 6058
6021 dprintk(1, "\n"); 6059 dprintk(1, "\n");
6022 if ((state->m_DrxkState == DRXK_UNINITIALIZED)) { 6060 if ((state->m_drxk_state == DRXK_UNINITIALIZED)) {
6023 drxk_i2c_lock(state); 6061 drxk_i2c_lock(state);
6024 status = PowerUpDevice(state); 6062 status = power_up_device(state);
6025 if (status < 0) 6063 if (status < 0)
6026 goto error; 6064 goto error;
6027 status = DRXX_Open(state); 6065 status = drxx_open(state);
6028 if (status < 0) 6066 if (status < 0)
6029 goto error; 6067 goto error;
6030 /* Soft reset of OFDM-, sys- and osc-clockdomain */ 6068 /* Soft reset of OFDM-, sys- and osc-clockdomain */
6031 status = write16(state, SIO_CC_SOFT_RST__A, SIO_CC_SOFT_RST_OFDM__M | SIO_CC_SOFT_RST_SYS__M | SIO_CC_SOFT_RST_OSC__M); 6069 status = write16(state, SIO_CC_SOFT_RST__A,
6070 SIO_CC_SOFT_RST_OFDM__M
6071 | SIO_CC_SOFT_RST_SYS__M
6072 | SIO_CC_SOFT_RST_OSC__M);
6032 if (status < 0) 6073 if (status < 0)
6033 goto error; 6074 goto error;
6034 status = write16(state, SIO_CC_UPDATE__A, SIO_CC_UPDATE_KEY); 6075 status = write16(state, SIO_CC_UPDATE__A, SIO_CC_UPDATE_KEY);
6035 if (status < 0) 6076 if (status < 0)
6036 goto error; 6077 goto error;
6037 /* TODO is this needed, if yes how much delay in worst case scenario */ 6078 /*
6038 msleep(1); 6079 * TODO is this needed? If yes, how much delay in
6039 state->m_DRXK_A3_PATCH_CODE = true; 6080 * worst case scenario
6040 status = GetDeviceCapabilities(state); 6081 */
6082 usleep_range(1000, 2000);
6083 state->m_drxk_a3_patch_code = true;
6084 status = get_device_capabilities(state);
6041 if (status < 0) 6085 if (status < 0)
6042 goto error; 6086 goto error;
6043 6087
6044 /* Bridge delay, uses oscilator clock */ 6088 /* Bridge delay, uses oscilator clock */
6045 /* Delay = (delay (nano seconds) * oscclk (kHz))/ 1000 */ 6089 /* Delay = (delay (nano seconds) * oscclk (kHz))/ 1000 */
6046 /* SDA brdige delay */ 6090 /* SDA brdige delay */
6047 state->m_HICfgBridgeDelay = 6091 state->m_hi_cfg_bridge_delay =
6048 (u16) ((state->m_oscClockFreq / 1000) * 6092 (u16) ((state->m_osc_clock_freq / 1000) *
6049 HI_I2C_BRIDGE_DELAY) / 1000; 6093 HI_I2C_BRIDGE_DELAY) / 1000;
6050 /* Clipping */ 6094 /* Clipping */
6051 if (state->m_HICfgBridgeDelay > 6095 if (state->m_hi_cfg_bridge_delay >
6052 SIO_HI_RA_RAM_PAR_3_CFG_DBL_SDA__M) { 6096 SIO_HI_RA_RAM_PAR_3_CFG_DBL_SDA__M) {
6053 state->m_HICfgBridgeDelay = 6097 state->m_hi_cfg_bridge_delay =
6054 SIO_HI_RA_RAM_PAR_3_CFG_DBL_SDA__M; 6098 SIO_HI_RA_RAM_PAR_3_CFG_DBL_SDA__M;
6055 } 6099 }
6056 /* SCL bridge delay, same as SDA for now */ 6100 /* SCL bridge delay, same as SDA for now */
6057 state->m_HICfgBridgeDelay += 6101 state->m_hi_cfg_bridge_delay +=
6058 state->m_HICfgBridgeDelay << 6102 state->m_hi_cfg_bridge_delay <<
6059 SIO_HI_RA_RAM_PAR_3_CFG_DBL_SCL__B; 6103 SIO_HI_RA_RAM_PAR_3_CFG_DBL_SCL__B;
6060 6104
6061 status = InitHI(state); 6105 status = init_hi(state);
6062 if (status < 0) 6106 if (status < 0)
6063 goto error; 6107 goto error;
6064 /* disable various processes */ 6108 /* disable various processes */
@@ -6067,13 +6111,14 @@ static int init_drxk(struct drxk_state *state)
6067 && !(state->m_DRXK_A2_ROM_CODE)) 6111 && !(state->m_DRXK_A2_ROM_CODE))
6068#endif 6112#endif
6069 { 6113 {
6070 status = write16(state, SCU_RAM_GPIO__A, SCU_RAM_GPIO_HW_LOCK_IND_DISABLE); 6114 status = write16(state, SCU_RAM_GPIO__A,
6115 SCU_RAM_GPIO_HW_LOCK_IND_DISABLE);
6071 if (status < 0) 6116 if (status < 0)
6072 goto error; 6117 goto error;
6073 } 6118 }
6074 6119
6075 /* disable MPEG port */ 6120 /* disable MPEG port */
6076 status = MPEGTSDisable(state); 6121 status = mpegts_disable(state);
6077 if (status < 0) 6122 if (status < 0)
6078 goto error; 6123 goto error;
6079 6124
@@ -6086,27 +6131,30 @@ static int init_drxk(struct drxk_state *state)
6086 goto error; 6131 goto error;
6087 6132
6088 /* enable token-ring bus through OFDM block for possible ucode upload */ 6133 /* enable token-ring bus through OFDM block for possible ucode upload */
6089 status = write16(state, SIO_OFDM_SH_OFDM_RING_ENABLE__A, SIO_OFDM_SH_OFDM_RING_ENABLE_ON); 6134 status = write16(state, SIO_OFDM_SH_OFDM_RING_ENABLE__A,
6135 SIO_OFDM_SH_OFDM_RING_ENABLE_ON);
6090 if (status < 0) 6136 if (status < 0)
6091 goto error; 6137 goto error;
6092 6138
6093 /* include boot loader section */ 6139 /* include boot loader section */
6094 status = write16(state, SIO_BL_COMM_EXEC__A, SIO_BL_COMM_EXEC_ACTIVE); 6140 status = write16(state, SIO_BL_COMM_EXEC__A,
6141 SIO_BL_COMM_EXEC_ACTIVE);
6095 if (status < 0) 6142 if (status < 0)
6096 goto error; 6143 goto error;
6097 status = BLChainCmd(state, 0, 6, 100); 6144 status = bl_chain_cmd(state, 0, 6, 100);
6098 if (status < 0) 6145 if (status < 0)
6099 goto error; 6146 goto error;
6100 6147
6101 if (state->fw) { 6148 if (state->fw) {
6102 status = DownloadMicrocode(state, state->fw->data, 6149 status = download_microcode(state, state->fw->data,
6103 state->fw->size); 6150 state->fw->size);
6104 if (status < 0) 6151 if (status < 0)
6105 goto error; 6152 goto error;
6106 } 6153 }
6107 6154
6108 /* disable token-ring bus through OFDM block for possible ucode upload */ 6155 /* disable token-ring bus through OFDM block for possible ucode upload */
6109 status = write16(state, SIO_OFDM_SH_OFDM_RING_ENABLE__A, SIO_OFDM_SH_OFDM_RING_ENABLE_OFF); 6156 status = write16(state, SIO_OFDM_SH_OFDM_RING_ENABLE__A,
6157 SIO_OFDM_SH_OFDM_RING_ENABLE_OFF);
6110 if (status < 0) 6158 if (status < 0)
6111 goto error; 6159 goto error;
6112 6160
@@ -6114,14 +6162,14 @@ static int init_drxk(struct drxk_state *state)
6114 status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_ACTIVE); 6162 status = write16(state, SCU_COMM_EXEC__A, SCU_COMM_EXEC_ACTIVE);
6115 if (status < 0) 6163 if (status < 0)
6116 goto error; 6164 goto error;
6117 status = DRXX_Open(state); 6165 status = drxx_open(state);
6118 if (status < 0) 6166 if (status < 0)
6119 goto error; 6167 goto error;
6120 /* added for test */ 6168 /* added for test */
6121 msleep(30); 6169 msleep(30);
6122 6170
6123 powerMode = DRXK_POWER_DOWN_OFDM; 6171 power_mode = DRXK_POWER_DOWN_OFDM;
6124 status = CtrlPowerMode(state, &powerMode); 6172 status = ctrl_power_mode(state, &power_mode);
6125 if (status < 0) 6173 if (status < 0)
6126 goto error; 6174 goto error;
6127 6175
@@ -6131,33 +6179,38 @@ static int init_drxk(struct drxk_state *state)
6131 Not using SCU command interface for SCU register access since no 6179 Not using SCU command interface for SCU register access since no
6132 microcode may be present. 6180 microcode may be present.
6133 */ 6181 */
6134 driverVersion = 6182 driver_version =
6135 (((DRXK_VERSION_MAJOR / 100) % 10) << 12) + 6183 (((DRXK_VERSION_MAJOR / 100) % 10) << 12) +
6136 (((DRXK_VERSION_MAJOR / 10) % 10) << 8) + 6184 (((DRXK_VERSION_MAJOR / 10) % 10) << 8) +
6137 ((DRXK_VERSION_MAJOR % 10) << 4) + 6185 ((DRXK_VERSION_MAJOR % 10) << 4) +
6138 (DRXK_VERSION_MINOR % 10); 6186 (DRXK_VERSION_MINOR % 10);
6139 status = write16(state, SCU_RAM_DRIVER_VER_HI__A, driverVersion); 6187 status = write16(state, SCU_RAM_DRIVER_VER_HI__A,
6188 driver_version);
6140 if (status < 0) 6189 if (status < 0)
6141 goto error; 6190 goto error;
6142 driverVersion = 6191 driver_version =
6143 (((DRXK_VERSION_PATCH / 1000) % 10) << 12) + 6192 (((DRXK_VERSION_PATCH / 1000) % 10) << 12) +
6144 (((DRXK_VERSION_PATCH / 100) % 10) << 8) + 6193 (((DRXK_VERSION_PATCH / 100) % 10) << 8) +
6145 (((DRXK_VERSION_PATCH / 10) % 10) << 4) + 6194 (((DRXK_VERSION_PATCH / 10) % 10) << 4) +
6146 (DRXK_VERSION_PATCH % 10); 6195 (DRXK_VERSION_PATCH % 10);
6147 status = write16(state, SCU_RAM_DRIVER_VER_LO__A, driverVersion); 6196 status = write16(state, SCU_RAM_DRIVER_VER_LO__A,
6197 driver_version);
6148 if (status < 0) 6198 if (status < 0)
6149 goto error; 6199 goto error;
6150 6200
6151 printk(KERN_INFO "DRXK driver version %d.%d.%d\n", 6201 pr_info("DRXK driver version %d.%d.%d\n",
6152 DRXK_VERSION_MAJOR, DRXK_VERSION_MINOR, 6202 DRXK_VERSION_MAJOR, DRXK_VERSION_MINOR,
6153 DRXK_VERSION_PATCH); 6203 DRXK_VERSION_PATCH);
6154 6204
6155 /* Dirty fix of default values for ROM/PATCH microcode 6205 /*
6156 Dirty because this fix makes it impossible to setup suitable values 6206 * Dirty fix of default values for ROM/PATCH microcode
6157 before calling DRX_Open. This solution requires changes to RF AGC speed 6207 * Dirty because this fix makes it impossible to setup
6158 to be done via the CTRL function after calling DRX_Open */ 6208 * suitable values before calling DRX_Open. This solution
6209 * requires changes to RF AGC speed to be done via the CTRL
6210 * function after calling DRX_Open
6211 */
6159 6212
6160 /* m_dvbtRfAgcCfg.speed = 3; */ 6213 /* m_dvbt_rf_agc_cfg.speed = 3; */
6161 6214
6162 /* Reset driver debug flags to 0 */ 6215 /* Reset driver debug flags to 0 */
6163 status = write16(state, SCU_RAM_DRIVER_DEBUG__A, 0); 6216 status = write16(state, SCU_RAM_DRIVER_DEBUG__A, 0);
@@ -6170,42 +6223,42 @@ static int init_drxk(struct drxk_state *state)
6170 if (status < 0) 6223 if (status < 0)
6171 goto error; 6224 goto error;
6172 /* MPEGTS functions are still the same */ 6225 /* MPEGTS functions are still the same */
6173 status = MPEGTSDtoInit(state); 6226 status = mpegts_dto_init(state);
6174 if (status < 0) 6227 if (status < 0)
6175 goto error; 6228 goto error;
6176 status = MPEGTSStop(state); 6229 status = mpegts_stop(state);
6177 if (status < 0) 6230 if (status < 0)
6178 goto error; 6231 goto error;
6179 status = MPEGTSConfigurePolarity(state); 6232 status = mpegts_configure_polarity(state);
6180 if (status < 0) 6233 if (status < 0)
6181 goto error; 6234 goto error;
6182 status = MPEGTSConfigurePins(state, state->m_enableMPEGOutput); 6235 status = mpegts_configure_pins(state, state->m_enable_mpeg_output);
6183 if (status < 0) 6236 if (status < 0)
6184 goto error; 6237 goto error;
6185 /* added: configure GPIO */ 6238 /* added: configure GPIO */
6186 status = WriteGPIO(state); 6239 status = write_gpio(state);
6187 if (status < 0) 6240 if (status < 0)
6188 goto error; 6241 goto error;
6189 6242
6190 state->m_DrxkState = DRXK_STOPPED; 6243 state->m_drxk_state = DRXK_STOPPED;
6191 6244
6192 if (state->m_bPowerDown) { 6245 if (state->m_b_power_down) {
6193 status = PowerDownDevice(state); 6246 status = power_down_device(state);
6194 if (status < 0) 6247 if (status < 0)
6195 goto error; 6248 goto error;
6196 state->m_DrxkState = DRXK_POWERED_DOWN; 6249 state->m_drxk_state = DRXK_POWERED_DOWN;
6197 } else 6250 } else
6198 state->m_DrxkState = DRXK_STOPPED; 6251 state->m_drxk_state = DRXK_STOPPED;
6199 6252
6200 /* Initialize the supported delivery systems */ 6253 /* Initialize the supported delivery systems */
6201 n = 0; 6254 n = 0;
6202 if (state->m_hasDVBC) { 6255 if (state->m_has_dvbc) {
6203 state->frontend.ops.delsys[n++] = SYS_DVBC_ANNEX_A; 6256 state->frontend.ops.delsys[n++] = SYS_DVBC_ANNEX_A;
6204 state->frontend.ops.delsys[n++] = SYS_DVBC_ANNEX_C; 6257 state->frontend.ops.delsys[n++] = SYS_DVBC_ANNEX_C;
6205 strlcat(state->frontend.ops.info.name, " DVB-C", 6258 strlcat(state->frontend.ops.info.name, " DVB-C",
6206 sizeof(state->frontend.ops.info.name)); 6259 sizeof(state->frontend.ops.info.name));
6207 } 6260 }
6208 if (state->m_hasDVBT) { 6261 if (state->m_has_dvbt) {
6209 state->frontend.ops.delsys[n++] = SYS_DVBT; 6262 state->frontend.ops.delsys[n++] = SYS_DVBT;
6210 strlcat(state->frontend.ops.info.name, " DVB-T", 6263 strlcat(state->frontend.ops.info.name, " DVB-T",
6211 sizeof(state->frontend.ops.info.name)); 6264 sizeof(state->frontend.ops.info.name));
@@ -6214,9 +6267,9 @@ static int init_drxk(struct drxk_state *state)
6214 } 6267 }
6215error: 6268error:
6216 if (status < 0) { 6269 if (status < 0) {
6217 state->m_DrxkState = DRXK_NO_DEV; 6270 state->m_drxk_state = DRXK_NO_DEV;
6218 drxk_i2c_unlock(state); 6271 drxk_i2c_unlock(state);
6219 printk(KERN_ERR "drxk: Error %d on %s\n", status, __func__); 6272 pr_err("Error %d on %s\n", status, __func__);
6220 } 6273 }
6221 6274
6222 return status; 6275 return status;
@@ -6229,11 +6282,9 @@ static void load_firmware_cb(const struct firmware *fw,
6229 6282
6230 dprintk(1, ": %s\n", fw ? "firmware loaded" : "firmware not loaded"); 6283 dprintk(1, ": %s\n", fw ? "firmware loaded" : "firmware not loaded");
6231 if (!fw) { 6284 if (!fw) {
6232 printk(KERN_ERR 6285 pr_err("Could not load firmware file %s.\n",
6233 "drxk: Could not load firmware file %s.\n",
6234 state->microcode_name); 6286 state->microcode_name);
6235 printk(KERN_INFO 6287 pr_info("Copy %s to your hotplug directory!\n",
6236 "drxk: Copy %s to your hotplug directory!\n",
6237 state->microcode_name); 6288 state->microcode_name);
6238 state->microcode_name = NULL; 6289 state->microcode_name = NULL;
6239 6290
@@ -6270,12 +6321,12 @@ static int drxk_sleep(struct dvb_frontend *fe)
6270 6321
6271 dprintk(1, "\n"); 6322 dprintk(1, "\n");
6272 6323
6273 if (state->m_DrxkState == DRXK_NO_DEV) 6324 if (state->m_drxk_state == DRXK_NO_DEV)
6274 return -ENODEV; 6325 return -ENODEV;
6275 if (state->m_DrxkState == DRXK_UNINITIALIZED) 6326 if (state->m_drxk_state == DRXK_UNINITIALIZED)
6276 return 0; 6327 return 0;
6277 6328
6278 ShutDown(state); 6329 shut_down(state);
6279 return 0; 6330 return 0;
6280} 6331}
6281 6332
@@ -6285,7 +6336,7 @@ static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable)
6285 6336
6286 dprintk(1, ": %s\n", enable ? "enable" : "disable"); 6337 dprintk(1, ": %s\n", enable ? "enable" : "disable");
6287 6338
6288 if (state->m_DrxkState == DRXK_NO_DEV) 6339 if (state->m_drxk_state == DRXK_NO_DEV)
6289 return -ENODEV; 6340 return -ENODEV;
6290 6341
6291 return ConfigureI2CBridge(state, enable ? true : false); 6342 return ConfigureI2CBridge(state, enable ? true : false);
@@ -6300,15 +6351,14 @@ static int drxk_set_parameters(struct dvb_frontend *fe)
6300 6351
6301 dprintk(1, "\n"); 6352 dprintk(1, "\n");
6302 6353
6303 if (state->m_DrxkState == DRXK_NO_DEV) 6354 if (state->m_drxk_state == DRXK_NO_DEV)
6304 return -ENODEV; 6355 return -ENODEV;
6305 6356
6306 if (state->m_DrxkState == DRXK_UNINITIALIZED) 6357 if (state->m_drxk_state == DRXK_UNINITIALIZED)
6307 return -EAGAIN; 6358 return -EAGAIN;
6308 6359
6309 if (!fe->ops.tuner_ops.get_if_frequency) { 6360 if (!fe->ops.tuner_ops.get_if_frequency) {
6310 printk(KERN_ERR 6361 pr_err("Error: get_if_frequency() not defined at tuner. Can't work without it!\n");
6311 "drxk: Error: get_if_frequency() not defined at tuner. Can't work without it!\n");
6312 return -EINVAL; 6362 return -EINVAL;
6313 } 6363 }
6314 6364
@@ -6323,22 +6373,23 @@ static int drxk_set_parameters(struct dvb_frontend *fe)
6323 state->props = *p; 6373 state->props = *p;
6324 6374
6325 if (old_delsys != delsys) { 6375 if (old_delsys != delsys) {
6326 ShutDown(state); 6376 shut_down(state);
6327 switch (delsys) { 6377 switch (delsys) {
6328 case SYS_DVBC_ANNEX_A: 6378 case SYS_DVBC_ANNEX_A:
6329 case SYS_DVBC_ANNEX_C: 6379 case SYS_DVBC_ANNEX_C:
6330 if (!state->m_hasDVBC) 6380 if (!state->m_has_dvbc)
6331 return -EINVAL; 6381 return -EINVAL;
6332 state->m_itut_annex_c = (delsys == SYS_DVBC_ANNEX_C) ? true : false; 6382 state->m_itut_annex_c = (delsys == SYS_DVBC_ANNEX_C) ?
6383 true : false;
6333 if (state->m_itut_annex_c) 6384 if (state->m_itut_annex_c)
6334 SetOperationMode(state, OM_QAM_ITU_C); 6385 setoperation_mode(state, OM_QAM_ITU_C);
6335 else 6386 else
6336 SetOperationMode(state, OM_QAM_ITU_A); 6387 setoperation_mode(state, OM_QAM_ITU_A);
6337 break; 6388 break;
6338 case SYS_DVBT: 6389 case SYS_DVBT:
6339 if (!state->m_hasDVBT) 6390 if (!state->m_has_dvbt)
6340 return -EINVAL; 6391 return -EINVAL;
6341 SetOperationMode(state, OM_DVBT); 6392 setoperation_mode(state, OM_DVBT);
6342 break; 6393 break;
6343 default: 6394 default:
6344 return -EINVAL; 6395 return -EINVAL;
@@ -6346,7 +6397,7 @@ static int drxk_set_parameters(struct dvb_frontend *fe)
6346 } 6397 }
6347 6398
6348 fe->ops.tuner_ops.get_if_frequency(fe, &IF); 6399 fe->ops.tuner_ops.get_if_frequency(fe, &IF);
6349 Start(state, 0, IF); 6400 start(state, 0, IF);
6350 6401
6351 /* After set_frontend, stats aren't avaliable */ 6402 /* After set_frontend, stats aren't avaliable */
6352 p->strength.stat[0].scale = FE_SCALE_RELATIVE; 6403 p->strength.stat[0].scale = FE_SCALE_RELATIVE;
@@ -6366,31 +6417,31 @@ static int drxk_set_parameters(struct dvb_frontend *fe)
6366static int get_strength(struct drxk_state *state, u64 *strength) 6417static int get_strength(struct drxk_state *state, u64 *strength)
6367{ 6418{
6368 int status; 6419 int status;
6369 struct SCfgAgc rfAgc, ifAgc; 6420 struct s_cfg_agc rf_agc, if_agc;
6370 u32 totalGain = 0; 6421 u32 total_gain = 0;
6371 u32 atten = 0; 6422 u32 atten = 0;
6372 u32 agcRange = 0; 6423 u32 agc_range = 0;
6373 u16 scu_lvl = 0; 6424 u16 scu_lvl = 0;
6374 u16 scu_coc = 0; 6425 u16 scu_coc = 0;
6375 /* FIXME: those are part of the tuner presets */ 6426 /* FIXME: those are part of the tuner presets */
6376 u16 tunerRfGain = 50; /* Default value on az6007 driver */ 6427 u16 tuner_rf_gain = 50; /* Default value on az6007 driver */
6377 u16 tunerIfGain = 40; /* Default value on az6007 driver */ 6428 u16 tuner_if_gain = 40; /* Default value on az6007 driver */
6378 6429
6379 *strength = 0; 6430 *strength = 0;
6380 6431
6381 if (IsDVBT(state)) { 6432 if (is_dvbt(state)) {
6382 rfAgc = state->m_dvbtRfAgcCfg; 6433 rf_agc = state->m_dvbt_rf_agc_cfg;
6383 ifAgc = state->m_dvbtIfAgcCfg; 6434 if_agc = state->m_dvbt_if_agc_cfg;
6384 } else if (IsQAM(state)) { 6435 } else if (is_qam(state)) {
6385 rfAgc = state->m_qamRfAgcCfg; 6436 rf_agc = state->m_qam_rf_agc_cfg;
6386 ifAgc = state->m_qamIfAgcCfg; 6437 if_agc = state->m_qam_if_agc_cfg;
6387 } else { 6438 } else {
6388 rfAgc = state->m_atvRfAgcCfg; 6439 rf_agc = state->m_atv_rf_agc_cfg;
6389 ifAgc = state->m_atvIfAgcCfg; 6440 if_agc = state->m_atv_if_agc_cfg;
6390 } 6441 }
6391 6442
6392 if (rfAgc.ctrlMode == DRXK_AGC_CTRL_AUTO) { 6443 if (rf_agc.ctrl_mode == DRXK_AGC_CTRL_AUTO) {
6393 /* SCU outputLevel */ 6444 /* SCU output_level */
6394 status = read16(state, SCU_RAM_AGC_RF_IACCU_HI__A, &scu_lvl); 6445 status = read16(state, SCU_RAM_AGC_RF_IACCU_HI__A, &scu_lvl);
6395 if (status < 0) 6446 if (status < 0)
6396 return status; 6447 return status;
@@ -6401,54 +6452,54 @@ static int get_strength(struct drxk_state *state, u64 *strength)
6401 return status; 6452 return status;
6402 6453
6403 if (((u32) scu_lvl + (u32) scu_coc) < 0xffff) 6454 if (((u32) scu_lvl + (u32) scu_coc) < 0xffff)
6404 rfAgc.outputLevel = scu_lvl + scu_coc; 6455 rf_agc.output_level = scu_lvl + scu_coc;
6405 else 6456 else
6406 rfAgc.outputLevel = 0xffff; 6457 rf_agc.output_level = 0xffff;
6407 6458
6408 /* Take RF gain into account */ 6459 /* Take RF gain into account */
6409 totalGain += tunerRfGain; 6460 total_gain += tuner_rf_gain;
6410 6461
6411 /* clip output value */ 6462 /* clip output value */
6412 if (rfAgc.outputLevel < rfAgc.minOutputLevel) 6463 if (rf_agc.output_level < rf_agc.min_output_level)
6413 rfAgc.outputLevel = rfAgc.minOutputLevel; 6464 rf_agc.output_level = rf_agc.min_output_level;
6414 if (rfAgc.outputLevel > rfAgc.maxOutputLevel) 6465 if (rf_agc.output_level > rf_agc.max_output_level)
6415 rfAgc.outputLevel = rfAgc.maxOutputLevel; 6466 rf_agc.output_level = rf_agc.max_output_level;
6416 6467
6417 agcRange = (u32) (rfAgc.maxOutputLevel - rfAgc.minOutputLevel); 6468 agc_range = (u32) (rf_agc.max_output_level - rf_agc.min_output_level);
6418 if (agcRange > 0) { 6469 if (agc_range > 0) {
6419 atten += 100UL * 6470 atten += 100UL *
6420 ((u32)(tunerRfGain)) * 6471 ((u32)(tuner_rf_gain)) *
6421 ((u32)(rfAgc.outputLevel - rfAgc.minOutputLevel)) 6472 ((u32)(rf_agc.output_level - rf_agc.min_output_level))
6422 / agcRange; 6473 / agc_range;
6423 } 6474 }
6424 } 6475 }
6425 6476
6426 if (ifAgc.ctrlMode == DRXK_AGC_CTRL_AUTO) { 6477 if (if_agc.ctrl_mode == DRXK_AGC_CTRL_AUTO) {
6427 status = read16(state, SCU_RAM_AGC_IF_IACCU_HI__A, 6478 status = read16(state, SCU_RAM_AGC_IF_IACCU_HI__A,
6428 &ifAgc.outputLevel); 6479 &if_agc.output_level);
6429 if (status < 0) 6480 if (status < 0)
6430 return status; 6481 return status;
6431 6482
6432 status = read16(state, SCU_RAM_AGC_INGAIN_TGT_MIN__A, 6483 status = read16(state, SCU_RAM_AGC_INGAIN_TGT_MIN__A,
6433 &ifAgc.top); 6484 &if_agc.top);
6434 if (status < 0) 6485 if (status < 0)
6435 return status; 6486 return status;
6436 6487
6437 /* Take IF gain into account */ 6488 /* Take IF gain into account */
6438 totalGain += (u32) tunerIfGain; 6489 total_gain += (u32) tuner_if_gain;
6439 6490
6440 /* clip output value */ 6491 /* clip output value */
6441 if (ifAgc.outputLevel < ifAgc.minOutputLevel) 6492 if (if_agc.output_level < if_agc.min_output_level)
6442 ifAgc.outputLevel = ifAgc.minOutputLevel; 6493 if_agc.output_level = if_agc.min_output_level;
6443 if (ifAgc.outputLevel > ifAgc.maxOutputLevel) 6494 if (if_agc.output_level > if_agc.max_output_level)
6444 ifAgc.outputLevel = ifAgc.maxOutputLevel; 6495 if_agc.output_level = if_agc.max_output_level;
6445 6496
6446 agcRange = (u32) (ifAgc.maxOutputLevel - ifAgc.minOutputLevel); 6497 agc_range = (u32)(if_agc.max_output_level - if_agc.min_output_level);
6447 if (agcRange > 0) { 6498 if (agc_range > 0) {
6448 atten += 100UL * 6499 atten += 100UL *
6449 ((u32)(tunerIfGain)) * 6500 ((u32)(tuner_if_gain)) *
6450 ((u32)(ifAgc.outputLevel - ifAgc.minOutputLevel)) 6501 ((u32)(if_agc.output_level - if_agc.min_output_level))
6451 / agcRange; 6502 / agc_range;
6452 } 6503 }
6453 } 6504 }
6454 6505
@@ -6456,8 +6507,8 @@ static int get_strength(struct drxk_state *state, u64 *strength)
6456 * Convert to 0..65535 scale. 6507 * Convert to 0..65535 scale.
6457 * If it can't be measured (AGC is disabled), just show 100%. 6508 * If it can't be measured (AGC is disabled), just show 100%.
6458 */ 6509 */
6459 if (totalGain > 0) 6510 if (total_gain > 0)
6460 *strength = (65535UL * atten / totalGain / 100); 6511 *strength = (65535UL * atten / total_gain / 100);
6461 else 6512 else
6462 *strength = 65535; 6513 *strength = 65535;
6463 6514
@@ -6480,14 +6531,14 @@ static int drxk_get_stats(struct dvb_frontend *fe)
6480 u32 pkt_error_count; 6531 u32 pkt_error_count;
6481 s32 cnr; 6532 s32 cnr;
6482 6533
6483 if (state->m_DrxkState == DRXK_NO_DEV) 6534 if (state->m_drxk_state == DRXK_NO_DEV)
6484 return -ENODEV; 6535 return -ENODEV;
6485 if (state->m_DrxkState == DRXK_UNINITIALIZED) 6536 if (state->m_drxk_state == DRXK_UNINITIALIZED)
6486 return -EAGAIN; 6537 return -EAGAIN;
6487 6538
6488 /* get status */ 6539 /* get status */
6489 state->fe_status = 0; 6540 state->fe_status = 0;
6490 GetLockStatus(state, &stat); 6541 get_lock_status(state, &stat);
6491 if (stat == MPEG_LOCK) 6542 if (stat == MPEG_LOCK)
6492 state->fe_status |= 0x1f; 6543 state->fe_status |= 0x1f;
6493 if (stat == FEC_LOCK) 6544 if (stat == FEC_LOCK)
@@ -6503,7 +6554,7 @@ static int drxk_get_stats(struct dvb_frontend *fe)
6503 6554
6504 6555
6505 if (stat >= DEMOD_LOCK) { 6556 if (stat >= DEMOD_LOCK) {
6506 GetSignalToNoise(state, &cnr); 6557 get_signal_to_noise(state, &cnr);
6507 c->cnr.stat[0].svalue = cnr * 100; 6558 c->cnr.stat[0].svalue = cnr * 100;
6508 c->cnr.stat[0].scale = FE_SCALE_DECIBEL; 6559 c->cnr.stat[0].scale = FE_SCALE_DECIBEL;
6509 } else { 6560 } else {
@@ -6524,9 +6575,11 @@ static int drxk_get_stats(struct dvb_frontend *fe)
6524 6575
6525 /* BER measurement is valid if at least FEC lock is achieved */ 6576 /* BER measurement is valid if at least FEC lock is achieved */
6526 6577
6527 /* OFDM_EC_VD_REQ_SMB_CNT__A and/or OFDM_EC_VD_REQ_BIT_CNT can be written 6578 /*
6528 to set nr of symbols or bits over which 6579 * OFDM_EC_VD_REQ_SMB_CNT__A and/or OFDM_EC_VD_REQ_BIT_CNT can be
6529 to measure EC_VD_REG_ERR_BIT_CNT__A . See CtrlSetCfg(). */ 6580 * written to set nr of symbols or bits over which to measure
6581 * EC_VD_REG_ERR_BIT_CNT__A . See CtrlSetCfg().
6582 */
6530 6583
6531 /* Read registers for post/preViterbi BER calculation */ 6584 /* Read registers for post/preViterbi BER calculation */
6532 status = read16(state, OFDM_EC_VD_ERR_BIT_CNT__A, &reg16); 6585 status = read16(state, OFDM_EC_VD_ERR_BIT_CNT__A, &reg16);
@@ -6610,9 +6663,9 @@ static int drxk_read_signal_strength(struct dvb_frontend *fe,
6610 6663
6611 dprintk(1, "\n"); 6664 dprintk(1, "\n");
6612 6665
6613 if (state->m_DrxkState == DRXK_NO_DEV) 6666 if (state->m_drxk_state == DRXK_NO_DEV)
6614 return -ENODEV; 6667 return -ENODEV;
6615 if (state->m_DrxkState == DRXK_UNINITIALIZED) 6668 if (state->m_drxk_state == DRXK_UNINITIALIZED)
6616 return -EAGAIN; 6669 return -EAGAIN;
6617 6670
6618 *strength = c->strength.stat[0].uvalue; 6671 *strength = c->strength.stat[0].uvalue;
@@ -6626,12 +6679,12 @@ static int drxk_read_snr(struct dvb_frontend *fe, u16 *snr)
6626 6679
6627 dprintk(1, "\n"); 6680 dprintk(1, "\n");
6628 6681
6629 if (state->m_DrxkState == DRXK_NO_DEV) 6682 if (state->m_drxk_state == DRXK_NO_DEV)
6630 return -ENODEV; 6683 return -ENODEV;
6631 if (state->m_DrxkState == DRXK_UNINITIALIZED) 6684 if (state->m_drxk_state == DRXK_UNINITIALIZED)
6632 return -EAGAIN; 6685 return -EAGAIN;
6633 6686
6634 GetSignalToNoise(state, &snr2); 6687 get_signal_to_noise(state, &snr2);
6635 6688
6636 /* No negative SNR, clip to zero */ 6689 /* No negative SNR, clip to zero */
6637 if (snr2 < 0) 6690 if (snr2 < 0)
@@ -6647,27 +6700,27 @@ static int drxk_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
6647 6700
6648 dprintk(1, "\n"); 6701 dprintk(1, "\n");
6649 6702
6650 if (state->m_DrxkState == DRXK_NO_DEV) 6703 if (state->m_drxk_state == DRXK_NO_DEV)
6651 return -ENODEV; 6704 return -ENODEV;
6652 if (state->m_DrxkState == DRXK_UNINITIALIZED) 6705 if (state->m_drxk_state == DRXK_UNINITIALIZED)
6653 return -EAGAIN; 6706 return -EAGAIN;
6654 6707
6655 DVBTQAMGetAccPktErr(state, &err); 6708 dvbtqam_get_acc_pkt_err(state, &err);
6656 *ucblocks = (u32) err; 6709 *ucblocks = (u32) err;
6657 return 0; 6710 return 0;
6658} 6711}
6659 6712
6660static int drxk_get_tune_settings(struct dvb_frontend *fe, struct dvb_frontend_tune_settings 6713static int drxk_get_tune_settings(struct dvb_frontend *fe,
6661 *sets) 6714 struct dvb_frontend_tune_settings *sets)
6662{ 6715{
6663 struct drxk_state *state = fe->demodulator_priv; 6716 struct drxk_state *state = fe->demodulator_priv;
6664 struct dtv_frontend_properties *p = &fe->dtv_property_cache; 6717 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
6665 6718
6666 dprintk(1, "\n"); 6719 dprintk(1, "\n");
6667 6720
6668 if (state->m_DrxkState == DRXK_NO_DEV) 6721 if (state->m_drxk_state == DRXK_NO_DEV)
6669 return -ENODEV; 6722 return -ENODEV;
6670 if (state->m_DrxkState == DRXK_UNINITIALIZED) 6723 if (state->m_drxk_state == DRXK_UNINITIALIZED)
6671 return -EAGAIN; 6724 return -EAGAIN;
6672 6725
6673 switch (p->delivery_system) { 6726 switch (p->delivery_system) {
@@ -6737,36 +6790,36 @@ struct dvb_frontend *drxk_attach(const struct drxk_config *config,
6737 state->no_i2c_bridge = config->no_i2c_bridge; 6790 state->no_i2c_bridge = config->no_i2c_bridge;
6738 state->antenna_gpio = config->antenna_gpio; 6791 state->antenna_gpio = config->antenna_gpio;
6739 state->antenna_dvbt = config->antenna_dvbt; 6792 state->antenna_dvbt = config->antenna_dvbt;
6740 state->m_ChunkSize = config->chunk_size; 6793 state->m_chunk_size = config->chunk_size;
6741 state->enable_merr_cfg = config->enable_merr_cfg; 6794 state->enable_merr_cfg = config->enable_merr_cfg;
6742 6795
6743 if (config->dynamic_clk) { 6796 if (config->dynamic_clk) {
6744 state->m_DVBTStaticCLK = 0; 6797 state->m_dvbt_static_clk = 0;
6745 state->m_DVBCStaticCLK = 0; 6798 state->m_dvbc_static_clk = 0;
6746 } else { 6799 } else {
6747 state->m_DVBTStaticCLK = 1; 6800 state->m_dvbt_static_clk = 1;
6748 state->m_DVBCStaticCLK = 1; 6801 state->m_dvbc_static_clk = 1;
6749 } 6802 }
6750 6803
6751 6804
6752 if (config->mpeg_out_clk_strength) 6805 if (config->mpeg_out_clk_strength)
6753 state->m_TSClockkStrength = config->mpeg_out_clk_strength & 0x07; 6806 state->m_ts_clockk_strength = config->mpeg_out_clk_strength & 0x07;
6754 else 6807 else
6755 state->m_TSClockkStrength = 0x06; 6808 state->m_ts_clockk_strength = 0x06;
6756 6809
6757 if (config->parallel_ts) 6810 if (config->parallel_ts)
6758 state->m_enableParallel = true; 6811 state->m_enable_parallel = true;
6759 else 6812 else
6760 state->m_enableParallel = false; 6813 state->m_enable_parallel = false;
6761 6814
6762 /* NOTE: as more UIO bits will be used, add them to the mask */ 6815 /* NOTE: as more UIO bits will be used, add them to the mask */
6763 state->UIO_mask = config->antenna_gpio; 6816 state->uio_mask = config->antenna_gpio;
6764 6817
6765 /* Default gpio to DVB-C */ 6818 /* Default gpio to DVB-C */
6766 if (!state->antenna_dvbt && state->antenna_gpio) 6819 if (!state->antenna_dvbt && state->antenna_gpio)
6767 state->m_GPIO |= state->antenna_gpio; 6820 state->m_gpio |= state->antenna_gpio;
6768 else 6821 else
6769 state->m_GPIO &= ~state->antenna_gpio; 6822 state->m_gpio &= ~state->antenna_gpio;
6770 6823
6771 mutex_init(&state->mutex); 6824 mutex_init(&state->mutex);
6772 6825
@@ -6792,8 +6845,7 @@ struct dvb_frontend *drxk_attach(const struct drxk_config *config,
6792 GFP_KERNEL, 6845 GFP_KERNEL,
6793 state, load_firmware_cb); 6846 state, load_firmware_cb);
6794 if (status < 0) { 6847 if (status < 0) {
6795 printk(KERN_ERR 6848 pr_err("failed to request a firmware\n");
6796 "drxk: failed to request a firmware\n");
6797 return NULL; 6849 return NULL;
6798 } 6850 }
6799 } 6851 }
@@ -6821,11 +6873,11 @@ struct dvb_frontend *drxk_attach(const struct drxk_config *config,
6821 p->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 6873 p->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
6822 p->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 6874 p->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
6823 6875
6824 printk(KERN_INFO "drxk: frontend initialized.\n"); 6876 pr_info("frontend initialized.\n");
6825 return &state->frontend; 6877 return &state->frontend;
6826 6878
6827error: 6879error:
6828 printk(KERN_ERR "drxk: not found\n"); 6880 pr_err("not found\n");
6829 kfree(state); 6881 kfree(state);
6830 return NULL; 6882 return NULL;
6831} 6883}
diff --git a/drivers/media/dvb-frontends/drxk_hard.h b/drivers/media/dvb-frontends/drxk_hard.h
index b8424f15f9a6..bae9c71dc3e9 100644
--- a/drivers/media/dvb-frontends/drxk_hard.h
+++ b/drivers/media/dvb-frontends/drxk_hard.h
@@ -46,7 +46,7 @@
46#define IQM_RC_ADJ_SEL_B_QAM 0x1 46#define IQM_RC_ADJ_SEL_B_QAM 0x1
47#define IQM_RC_ADJ_SEL_B_VSB 0x2 47#define IQM_RC_ADJ_SEL_B_VSB 0x2
48 48
49enum OperationMode { 49enum operation_mode {
50 OM_NONE, 50 OM_NONE,
51 OM_QAM_ITU_A, 51 OM_QAM_ITU_A,
52 OM_QAM_ITU_B, 52 OM_QAM_ITU_B,
@@ -54,7 +54,7 @@ enum OperationMode {
54 OM_DVBT 54 OM_DVBT
55}; 55};
56 56
57enum DRXPowerMode { 57enum drx_power_mode {
58 DRX_POWER_UP = 0, 58 DRX_POWER_UP = 0,
59 DRX_POWER_MODE_1, 59 DRX_POWER_MODE_1,
60 DRX_POWER_MODE_2, 60 DRX_POWER_MODE_2,
@@ -77,24 +77,29 @@ enum DRXPowerMode {
77}; 77};
78 78
79 79
80/** /brief Intermediate power mode for DRXK, power down OFDM clock domain */ 80/* Intermediate power mode for DRXK, power down OFDM clock domain */
81#ifndef DRXK_POWER_DOWN_OFDM 81#ifndef DRXK_POWER_DOWN_OFDM
82#define DRXK_POWER_DOWN_OFDM DRX_POWER_MODE_1 82#define DRXK_POWER_DOWN_OFDM DRX_POWER_MODE_1
83#endif 83#endif
84 84
85/** /brief Intermediate power mode for DRXK, power down core (sysclk) */ 85/* Intermediate power mode for DRXK, power down core (sysclk) */
86#ifndef DRXK_POWER_DOWN_CORE 86#ifndef DRXK_POWER_DOWN_CORE
87#define DRXK_POWER_DOWN_CORE DRX_POWER_MODE_9 87#define DRXK_POWER_DOWN_CORE DRX_POWER_MODE_9
88#endif 88#endif
89 89
90/** /brief Intermediate power mode for DRXK, power down pll (only osc runs) */ 90/* Intermediate power mode for DRXK, power down pll (only osc runs) */
91#ifndef DRXK_POWER_DOWN_PLL 91#ifndef DRXK_POWER_DOWN_PLL
92#define DRXK_POWER_DOWN_PLL DRX_POWER_MODE_10 92#define DRXK_POWER_DOWN_PLL DRX_POWER_MODE_10
93#endif 93#endif
94 94
95 95
96enum AGC_CTRL_MODE { DRXK_AGC_CTRL_AUTO = 0, DRXK_AGC_CTRL_USER, DRXK_AGC_CTRL_OFF }; 96enum agc_ctrl_mode {
97enum EDrxkState { 97 DRXK_AGC_CTRL_AUTO = 0,
98 DRXK_AGC_CTRL_USER,
99 DRXK_AGC_CTRL_OFF
100};
101
102enum e_drxk_state {
98 DRXK_UNINITIALIZED = 0, 103 DRXK_UNINITIALIZED = 0,
99 DRXK_STOPPED, 104 DRXK_STOPPED,
100 DRXK_DTV_STARTED, 105 DRXK_DTV_STARTED,
@@ -103,7 +108,7 @@ enum EDrxkState {
103 DRXK_NO_DEV /* If drxk init failed */ 108 DRXK_NO_DEV /* If drxk init failed */
104}; 109};
105 110
106enum EDrxkCoefArrayIndex { 111enum e_drxk_coef_array_index {
107 DRXK_COEF_IDX_MN = 0, 112 DRXK_COEF_IDX_MN = 0,
108 DRXK_COEF_IDX_FM , 113 DRXK_COEF_IDX_FM ,
109 DRXK_COEF_IDX_L , 114 DRXK_COEF_IDX_L ,
@@ -113,13 +118,13 @@ enum EDrxkCoefArrayIndex {
113 DRXK_COEF_IDX_I , 118 DRXK_COEF_IDX_I ,
114 DRXK_COEF_IDX_MAX 119 DRXK_COEF_IDX_MAX
115}; 120};
116enum EDrxkSifAttenuation { 121enum e_drxk_sif_attenuation {
117 DRXK_SIF_ATTENUATION_0DB, 122 DRXK_SIF_ATTENUATION_0DB,
118 DRXK_SIF_ATTENUATION_3DB, 123 DRXK_SIF_ATTENUATION_3DB,
119 DRXK_SIF_ATTENUATION_6DB, 124 DRXK_SIF_ATTENUATION_6DB,
120 DRXK_SIF_ATTENUATION_9DB 125 DRXK_SIF_ATTENUATION_9DB
121}; 126};
122enum EDrxkConstellation { 127enum e_drxk_constellation {
123 DRX_CONSTELLATION_BPSK = 0, 128 DRX_CONSTELLATION_BPSK = 0,
124 DRX_CONSTELLATION_QPSK, 129 DRX_CONSTELLATION_QPSK,
125 DRX_CONSTELLATION_PSK8, 130 DRX_CONSTELLATION_PSK8,
@@ -133,7 +138,7 @@ enum EDrxkConstellation {
133 DRX_CONSTELLATION_UNKNOWN = DRX_UNKNOWN, 138 DRX_CONSTELLATION_UNKNOWN = DRX_UNKNOWN,
134 DRX_CONSTELLATION_AUTO = DRX_AUTO 139 DRX_CONSTELLATION_AUTO = DRX_AUTO
135}; 140};
136enum EDrxkInterleaveMode { 141enum e_drxk_interleave_mode {
137 DRXK_QAM_I12_J17 = 16, 142 DRXK_QAM_I12_J17 = 16,
138 DRXK_QAM_I_UNKNOWN = DRX_UNKNOWN 143 DRXK_QAM_I_UNKNOWN = DRX_UNKNOWN
139}; 144};
@@ -144,14 +149,14 @@ enum {
144 DRXK_SPIN_UNKNOWN 149 DRXK_SPIN_UNKNOWN
145}; 150};
146 151
147enum DRXKCfgDvbtSqiSpeed { 152enum drxk_cfg_dvbt_sqi_speed {
148 DRXK_DVBT_SQI_SPEED_FAST = 0, 153 DRXK_DVBT_SQI_SPEED_FAST = 0,
149 DRXK_DVBT_SQI_SPEED_MEDIUM, 154 DRXK_DVBT_SQI_SPEED_MEDIUM,
150 DRXK_DVBT_SQI_SPEED_SLOW, 155 DRXK_DVBT_SQI_SPEED_SLOW,
151 DRXK_DVBT_SQI_SPEED_UNKNOWN = DRX_UNKNOWN 156 DRXK_DVBT_SQI_SPEED_UNKNOWN = DRX_UNKNOWN
152} ; 157} ;
153 158
154enum DRXFftmode_t { 159enum drx_fftmode_t {
155 DRX_FFTMODE_2K = 0, 160 DRX_FFTMODE_2K = 0,
156 DRX_FFTMODE_4K, 161 DRX_FFTMODE_4K,
157 DRX_FFTMODE_8K, 162 DRX_FFTMODE_8K,
@@ -159,47 +164,47 @@ enum DRXFftmode_t {
159 DRX_FFTMODE_AUTO = DRX_AUTO 164 DRX_FFTMODE_AUTO = DRX_AUTO
160}; 165};
161 166
162enum DRXMPEGStrWidth_t { 167enum drxmpeg_str_width_t {
163 DRX_MPEG_STR_WIDTH_1, 168 DRX_MPEG_STR_WIDTH_1,
164 DRX_MPEG_STR_WIDTH_8 169 DRX_MPEG_STR_WIDTH_8
165}; 170};
166 171
167enum DRXQamLockRange_t { 172enum drx_qam_lock_range_t {
168 DRX_QAM_LOCKRANGE_NORMAL, 173 DRX_QAM_LOCKRANGE_NORMAL,
169 DRX_QAM_LOCKRANGE_EXTENDED 174 DRX_QAM_LOCKRANGE_EXTENDED
170}; 175};
171 176
172struct DRXKCfgDvbtEchoThres_t { 177struct drxk_cfg_dvbt_echo_thres_t {
173 u16 threshold; 178 u16 threshold;
174 enum DRXFftmode_t fftMode; 179 enum drx_fftmode_t fft_mode;
175} ; 180} ;
176 181
177struct SCfgAgc { 182struct s_cfg_agc {
178 enum AGC_CTRL_MODE ctrlMode; /* off, user, auto */ 183 enum agc_ctrl_mode ctrl_mode; /* off, user, auto */
179 u16 outputLevel; /* range dependent on AGC */ 184 u16 output_level; /* range dependent on AGC */
180 u16 minOutputLevel; /* range dependent on AGC */ 185 u16 min_output_level; /* range dependent on AGC */
181 u16 maxOutputLevel; /* range dependent on AGC */ 186 u16 max_output_level; /* range dependent on AGC */
182 u16 speed; /* range dependent on AGC */ 187 u16 speed; /* range dependent on AGC */
183 u16 top; /* rf-agc take over point */ 188 u16 top; /* rf-agc take over point */
184 u16 cutOffCurrent; /* rf-agc is accelerated if output current 189 u16 cut_off_current; /* rf-agc is accelerated if output current
185 is below cut-off current */ 190 is below cut-off current */
186 u16 IngainTgtMax; 191 u16 ingain_tgt_max;
187 u16 FastClipCtrlDelay; 192 u16 fast_clip_ctrl_delay;
188}; 193};
189 194
190struct SCfgPreSaw { 195struct s_cfg_pre_saw {
191 u16 reference; /* pre SAW reference value, range 0 .. 31 */ 196 u16 reference; /* pre SAW reference value, range 0 .. 31 */
192 bool usePreSaw; /* TRUE algorithms must use pre SAW sense */ 197 bool use_pre_saw; /* TRUE algorithms must use pre SAW sense */
193}; 198};
194 199
195struct DRXKOfdmScCmd_t { 200struct drxk_ofdm_sc_cmd_t {
196 u16 cmd; /**< Command number */ 201 u16 cmd; /* Command number */
197 u16 subcmd; /**< Sub-command parameter*/ 202 u16 subcmd; /* Sub-command parameter*/
198 u16 param0; /**< General purpous param */ 203 u16 param0; /* General purpous param */
199 u16 param1; /**< General purpous param */ 204 u16 param1; /* General purpous param */
200 u16 param2; /**< General purpous param */ 205 u16 param2; /* General purpous param */
201 u16 param3; /**< General purpous param */ 206 u16 param3; /* General purpous param */
202 u16 param4; /**< General purpous param */ 207 u16 param4; /* General purpous param */
203}; 208};
204 209
205struct drxk_state { 210struct drxk_state {
@@ -213,121 +218,121 @@ struct drxk_state {
213 218
214 struct mutex mutex; 219 struct mutex mutex;
215 220
216 u32 m_Instance; /**< Channel 1,2,3 or 4 */ 221 u32 m_instance; /* Channel 1,2,3 or 4 */
217 222
218 int m_ChunkSize; 223 int m_chunk_size;
219 u8 Chunk[256]; 224 u8 chunk[256];
220 225
221 bool m_hasLNA; 226 bool m_has_lna;
222 bool m_hasDVBT; 227 bool m_has_dvbt;
223 bool m_hasDVBC; 228 bool m_has_dvbc;
224 bool m_hasAudio; 229 bool m_has_audio;
225 bool m_hasATV; 230 bool m_has_atv;
226 bool m_hasOOB; 231 bool m_has_oob;
227 bool m_hasSAWSW; /**< TRUE if mat_tx is available */ 232 bool m_has_sawsw; /* TRUE if mat_tx is available */
228 bool m_hasGPIO1; /**< TRUE if mat_rx is available */ 233 bool m_has_gpio1; /* TRUE if mat_rx is available */
229 bool m_hasGPIO2; /**< TRUE if GPIO is available */ 234 bool m_has_gpio2; /* TRUE if GPIO is available */
230 bool m_hasIRQN; /**< TRUE if IRQN is available */ 235 bool m_has_irqn; /* TRUE if IRQN is available */
231 u16 m_oscClockFreq; 236 u16 m_osc_clock_freq;
232 u16 m_HICfgTimingDiv; 237 u16 m_hi_cfg_timing_div;
233 u16 m_HICfgBridgeDelay; 238 u16 m_hi_cfg_bridge_delay;
234 u16 m_HICfgWakeUpKey; 239 u16 m_hi_cfg_wake_up_key;
235 u16 m_HICfgTimeout; 240 u16 m_hi_cfg_timeout;
236 u16 m_HICfgCtrl; 241 u16 m_hi_cfg_ctrl;
237 s32 m_sysClockFreq; /**< system clock frequency in kHz */ 242 s32 m_sys_clock_freq; /* system clock frequency in kHz */
238 243
239 enum EDrxkState m_DrxkState; /**< State of Drxk (init,stopped,started) */ 244 enum e_drxk_state m_drxk_state; /* State of Drxk (init,stopped,started) */
240 enum OperationMode m_OperationMode; /**< digital standards */ 245 enum operation_mode m_operation_mode; /* digital standards */
241 struct SCfgAgc m_vsbRfAgcCfg; /**< settings for VSB RF-AGC */ 246 struct s_cfg_agc m_vsb_rf_agc_cfg; /* settings for VSB RF-AGC */
242 struct SCfgAgc m_vsbIfAgcCfg; /**< settings for VSB IF-AGC */ 247 struct s_cfg_agc m_vsb_if_agc_cfg; /* settings for VSB IF-AGC */
243 u16 m_vsbPgaCfg; /**< settings for VSB PGA */ 248 u16 m_vsb_pga_cfg; /* settings for VSB PGA */
244 struct SCfgPreSaw m_vsbPreSawCfg; /**< settings for pre SAW sense */ 249 struct s_cfg_pre_saw m_vsb_pre_saw_cfg; /* settings for pre SAW sense */
245 s32 m_Quality83percent; /**< MER level (*0.1 dB) for 83% quality indication */ 250 s32 m_Quality83percent; /* MER level (*0.1 dB) for 83% quality indication */
246 s32 m_Quality93percent; /**< MER level (*0.1 dB) for 93% quality indication */ 251 s32 m_Quality93percent; /* MER level (*0.1 dB) for 93% quality indication */
247 bool m_smartAntInverted; 252 bool m_smart_ant_inverted;
248 bool m_bDebugEnableBridge; 253 bool m_b_debug_enable_bridge;
249 bool m_bPDownOpenBridge; /**< only open DRXK bridge before power-down once it has been accessed */ 254 bool m_b_p_down_open_bridge; /* only open DRXK bridge before power-down once it has been accessed */
250 bool m_bPowerDown; /**< Power down when not used */ 255 bool m_b_power_down; /* Power down when not used */
251 256
252 u32 m_IqmFsRateOfs; /**< frequency shift as written to DRXK register (28bit fixpoint) */ 257 u32 m_iqm_fs_rate_ofs; /* frequency shift as written to DRXK register (28bit fixpoint) */
253 258
254 bool m_enableMPEGOutput; /**< If TRUE, enable MPEG output */ 259 bool m_enable_mpeg_output; /* If TRUE, enable MPEG output */
255 bool m_insertRSByte; /**< If TRUE, insert RS byte */ 260 bool m_insert_rs_byte; /* If TRUE, insert RS byte */
256 bool m_enableParallel; /**< If TRUE, parallel out otherwise serial */ 261 bool m_enable_parallel; /* If TRUE, parallel out otherwise serial */
257 bool m_invertDATA; /**< If TRUE, invert DATA signals */ 262 bool m_invert_data; /* If TRUE, invert DATA signals */
258 bool m_invertERR; /**< If TRUE, invert ERR signal */ 263 bool m_invert_err; /* If TRUE, invert ERR signal */
259 bool m_invertSTR; /**< If TRUE, invert STR signals */ 264 bool m_invert_str; /* If TRUE, invert STR signals */
260 bool m_invertVAL; /**< If TRUE, invert VAL signals */ 265 bool m_invert_val; /* If TRUE, invert VAL signals */
261 bool m_invertCLK; /**< If TRUE, invert CLK signals */ 266 bool m_invert_clk; /* If TRUE, invert CLK signals */
262 bool m_DVBCStaticCLK; 267 bool m_dvbc_static_clk;
263 bool m_DVBTStaticCLK; /**< If TRUE, static MPEG clockrate will 268 bool m_dvbt_static_clk; /* If TRUE, static MPEG clockrate will
264 be used, otherwise clockrate will 269 be used, otherwise clockrate will
265 adapt to the bitrate of the TS */ 270 adapt to the bitrate of the TS */
266 u32 m_DVBTBitrate; 271 u32 m_dvbt_bitrate;
267 u32 m_DVBCBitrate; 272 u32 m_dvbc_bitrate;
268 273
269 u8 m_TSDataStrength; 274 u8 m_ts_data_strength;
270 u8 m_TSClockkStrength; 275 u8 m_ts_clockk_strength;
271 276
272 bool m_itut_annex_c; /* If true, uses ITU-T DVB-C Annex C, instead of Annex A */ 277 bool m_itut_annex_c; /* If true, uses ITU-T DVB-C Annex C, instead of Annex A */
273 278
274 enum DRXMPEGStrWidth_t m_widthSTR; /**< MPEG start width */ 279 enum drxmpeg_str_width_t m_width_str; /* MPEG start width */
275 u32 m_mpegTsStaticBitrate; /**< Maximum bitrate in b/s in case 280 u32 m_mpeg_ts_static_bitrate; /* Maximum bitrate in b/s in case
276 static clockrate is selected */ 281 static clockrate is selected */
277 282
278 /* LARGE_INTEGER m_StartTime; */ /**< Contains the time of the last demod start */ 283 /* LARGE_INTEGER m_startTime; */ /* Contains the time of the last demod start */
279 s32 m_MpegLockTimeOut; /**< WaitForLockStatus Timeout (counts from start time) */ 284 s32 m_mpeg_lock_time_out; /* WaitForLockStatus Timeout (counts from start time) */
280 s32 m_DemodLockTimeOut; /**< WaitForLockStatus Timeout (counts from start time) */ 285 s32 m_demod_lock_time_out; /* WaitForLockStatus Timeout (counts from start time) */
281 286
282 bool m_disableTEIhandling; 287 bool m_disable_te_ihandling;
283 288
284 bool m_RfAgcPol; 289 bool m_rf_agc_pol;
285 bool m_IfAgcPol; 290 bool m_if_agc_pol;
286 291
287 struct SCfgAgc m_atvRfAgcCfg; /**< settings for ATV RF-AGC */ 292 struct s_cfg_agc m_atv_rf_agc_cfg; /* settings for ATV RF-AGC */
288 struct SCfgAgc m_atvIfAgcCfg; /**< settings for ATV IF-AGC */ 293 struct s_cfg_agc m_atv_if_agc_cfg; /* settings for ATV IF-AGC */
289 struct SCfgPreSaw m_atvPreSawCfg; /**< settings for ATV pre SAW sense */ 294 struct s_cfg_pre_saw m_atv_pre_saw_cfg; /* settings for ATV pre SAW sense */
290 bool m_phaseCorrectionBypass; 295 bool m_phase_correction_bypass;
291 s16 m_atvTopVidPeak; 296 s16 m_atv_top_vid_peak;
292 u16 m_atvTopNoiseTh; 297 u16 m_atv_top_noise_th;
293 enum EDrxkSifAttenuation m_sifAttenuation; 298 enum e_drxk_sif_attenuation m_sif_attenuation;
294 bool m_enableCVBSOutput; 299 bool m_enable_cvbs_output;
295 bool m_enableSIFOutput; 300 bool m_enable_sif_output;
296 bool m_bMirrorFreqSpect; 301 bool m_b_mirror_freq_spect;
297 enum EDrxkConstellation m_Constellation; /**< Constellation type of the channel */ 302 enum e_drxk_constellation m_constellation; /* constellation type of the channel */
298 u32 m_CurrSymbolRate; /**< Current QAM symbol rate */ 303 u32 m_curr_symbol_rate; /* Current QAM symbol rate */
299 struct SCfgAgc m_qamRfAgcCfg; /**< settings for QAM RF-AGC */ 304 struct s_cfg_agc m_qam_rf_agc_cfg; /* settings for QAM RF-AGC */
300 struct SCfgAgc m_qamIfAgcCfg; /**< settings for QAM IF-AGC */ 305 struct s_cfg_agc m_qam_if_agc_cfg; /* settings for QAM IF-AGC */
301 u16 m_qamPgaCfg; /**< settings for QAM PGA */ 306 u16 m_qam_pga_cfg; /* settings for QAM PGA */
302 struct SCfgPreSaw m_qamPreSawCfg; /**< settings for QAM pre SAW sense */ 307 struct s_cfg_pre_saw m_qam_pre_saw_cfg; /* settings for QAM pre SAW sense */
303 enum EDrxkInterleaveMode m_qamInterleaveMode; /**< QAM Interleave mode */ 308 enum e_drxk_interleave_mode m_qam_interleave_mode; /* QAM Interleave mode */
304 u16 m_fecRsPlen; 309 u16 m_fec_rs_plen;
305 u16 m_fecRsPrescale; 310 u16 m_fec_rs_prescale;
306 311
307 enum DRXKCfgDvbtSqiSpeed m_sqiSpeed; 312 enum drxk_cfg_dvbt_sqi_speed m_sqi_speed;
308 313
309 u16 m_GPIO; 314 u16 m_gpio;
310 u16 m_GPIOCfg; 315 u16 m_gpio_cfg;
311 316
312 struct SCfgAgc m_dvbtRfAgcCfg; /**< settings for QAM RF-AGC */ 317 struct s_cfg_agc m_dvbt_rf_agc_cfg; /* settings for QAM RF-AGC */
313 struct SCfgAgc m_dvbtIfAgcCfg; /**< settings for QAM IF-AGC */ 318 struct s_cfg_agc m_dvbt_if_agc_cfg; /* settings for QAM IF-AGC */
314 struct SCfgPreSaw m_dvbtPreSawCfg; /**< settings for QAM pre SAW sense */ 319 struct s_cfg_pre_saw m_dvbt_pre_saw_cfg; /* settings for QAM pre SAW sense */
315 320
316 u16 m_agcFastClipCtrlDelay; 321 u16 m_agcfast_clip_ctrl_delay;
317 bool m_adcCompPassed; 322 bool m_adc_comp_passed;
318 u16 m_adcCompCoef[64]; 323 u16 m_adcCompCoef[64];
319 u16 m_adcState; 324 u16 m_adc_state;
320 325
321 u8 *m_microcode; 326 u8 *m_microcode;
322 int m_microcode_length; 327 int m_microcode_length;
323 bool m_DRXK_A3_ROM_CODE; 328 bool m_drxk_a3_rom_code;
324 bool m_DRXK_A3_PATCH_CODE; 329 bool m_drxk_a3_patch_code;
325 330
326 bool m_rfmirror; 331 bool m_rfmirror;
327 u8 m_deviceSpin; 332 u8 m_device_spin;
328 u32 m_iqmRcRate; 333 u32 m_iqm_rc_rate;
329 334
330 enum DRXPowerMode m_currentPowerMode; 335 enum drx_power_mode m_current_power_mode;
331 336
332 /* when true, avoids other devices to use the I2C bus */ 337 /* when true, avoids other devices to use the I2C bus */
333 bool drxk_i2c_exclusive_lock; 338 bool drxk_i2c_exclusive_lock;
@@ -337,7 +342,7 @@ struct drxk_state {
337 * at struct drxk_config. 342 * at struct drxk_config.
338 */ 343 */
339 344
340 u16 UIO_mask; /* Bits used by UIO */ 345 u16 uio_mask; /* Bits used by UIO */
341 346
342 bool enable_merr_cfg; 347 bool enable_merr_cfg;
343 bool single_master; 348 bool single_master;
diff --git a/drivers/media/dvb-frontends/stb0899_algo.c b/drivers/media/dvb-frontends/stb0899_algo.c
index 117a56926dca..93596e0e640b 100644
--- a/drivers/media/dvb-frontends/stb0899_algo.c
+++ b/drivers/media/dvb-frontends/stb0899_algo.c
@@ -226,8 +226,8 @@ static enum stb0899_status stb0899_search_tmg(struct stb0899_state *state)
226 next_loop--; 226 next_loop--;
227 227
228 if (next_loop) { 228 if (next_loop) {
229 STB0899_SETFIELD_VAL(CFRM, cfr[0], MSB(state->config->inversion * derot_freq)); 229 STB0899_SETFIELD_VAL(CFRM, cfr[0], MSB(internal->inversion * derot_freq));
230 STB0899_SETFIELD_VAL(CFRL, cfr[1], LSB(state->config->inversion * derot_freq)); 230 STB0899_SETFIELD_VAL(CFRL, cfr[1], LSB(internal->inversion * derot_freq));
231 stb0899_write_regs(state, STB0899_CFRM, cfr, 2); /* derotator frequency */ 231 stb0899_write_regs(state, STB0899_CFRM, cfr, 2); /* derotator frequency */
232 } 232 }
233 internal->direction = -internal->direction; /* Change zigzag direction */ 233 internal->direction = -internal->direction; /* Change zigzag direction */
@@ -235,7 +235,7 @@ static enum stb0899_status stb0899_search_tmg(struct stb0899_state *state)
235 235
236 if (internal->status == TIMINGOK) { 236 if (internal->status == TIMINGOK) {
237 stb0899_read_regs(state, STB0899_CFRM, cfr, 2); /* get derotator frequency */ 237 stb0899_read_regs(state, STB0899_CFRM, cfr, 2); /* get derotator frequency */
238 internal->derot_freq = state->config->inversion * MAKEWORD16(cfr[0], cfr[1]); 238 internal->derot_freq = internal->inversion * MAKEWORD16(cfr[0], cfr[1]);
239 dprintk(state->verbose, FE_DEBUG, 1, "------->TIMING OK ! Derot Freq = %d", internal->derot_freq); 239 dprintk(state->verbose, FE_DEBUG, 1, "------->TIMING OK ! Derot Freq = %d", internal->derot_freq);
240 } 240 }
241 241
@@ -306,8 +306,8 @@ static enum stb0899_status stb0899_search_carrier(struct stb0899_state *state)
306 STB0899_SETFIELD_VAL(CFD_ON, reg, 1); 306 STB0899_SETFIELD_VAL(CFD_ON, reg, 1);
307 stb0899_write_reg(state, STB0899_CFD, reg); 307 stb0899_write_reg(state, STB0899_CFD, reg);
308 308
309 STB0899_SETFIELD_VAL(CFRM, cfr[0], MSB(state->config->inversion * derot_freq)); 309 STB0899_SETFIELD_VAL(CFRM, cfr[0], MSB(internal->inversion * derot_freq));
310 STB0899_SETFIELD_VAL(CFRL, cfr[1], LSB(state->config->inversion * derot_freq)); 310 STB0899_SETFIELD_VAL(CFRL, cfr[1], LSB(internal->inversion * derot_freq));
311 stb0899_write_regs(state, STB0899_CFRM, cfr, 2); /* derotator frequency */ 311 stb0899_write_regs(state, STB0899_CFRM, cfr, 2); /* derotator frequency */
312 } 312 }
313 } 313 }
@@ -317,7 +317,7 @@ static enum stb0899_status stb0899_search_carrier(struct stb0899_state *state)
317 317
318 if (internal->status == CARRIEROK) { 318 if (internal->status == CARRIEROK) {
319 stb0899_read_regs(state, STB0899_CFRM, cfr, 2); /* get derotator frequency */ 319 stb0899_read_regs(state, STB0899_CFRM, cfr, 2); /* get derotator frequency */
320 internal->derot_freq = state->config->inversion * MAKEWORD16(cfr[0], cfr[1]); 320 internal->derot_freq = internal->inversion * MAKEWORD16(cfr[0], cfr[1]);
321 dprintk(state->verbose, FE_DEBUG, 1, "----> CARRIER OK !, Derot Freq=%d", internal->derot_freq); 321 dprintk(state->verbose, FE_DEBUG, 1, "----> CARRIER OK !, Derot Freq=%d", internal->derot_freq);
322 } else { 322 } else {
323 internal->derot_freq = last_derot_freq; 323 internal->derot_freq = last_derot_freq;
@@ -412,8 +412,8 @@ static enum stb0899_status stb0899_search_data(struct stb0899_state *state)
412 STB0899_SETFIELD_VAL(CFD_ON, reg, 1); 412 STB0899_SETFIELD_VAL(CFD_ON, reg, 1);
413 stb0899_write_reg(state, STB0899_CFD, reg); 413 stb0899_write_reg(state, STB0899_CFD, reg);
414 414
415 STB0899_SETFIELD_VAL(CFRM, cfr[0], MSB(state->config->inversion * derot_freq)); 415 STB0899_SETFIELD_VAL(CFRM, cfr[0], MSB(internal->inversion * derot_freq));
416 STB0899_SETFIELD_VAL(CFRL, cfr[1], LSB(state->config->inversion * derot_freq)); 416 STB0899_SETFIELD_VAL(CFRL, cfr[1], LSB(internal->inversion * derot_freq));
417 stb0899_write_regs(state, STB0899_CFRM, cfr, 2); /* derotator frequency */ 417 stb0899_write_regs(state, STB0899_CFRM, cfr, 2); /* derotator frequency */
418 418
419 stb0899_check_carrier(state); 419 stb0899_check_carrier(state);
@@ -425,7 +425,15 @@ static enum stb0899_status stb0899_search_data(struct stb0899_state *state)
425 425
426 if (internal->status == DATAOK) { 426 if (internal->status == DATAOK) {
427 stb0899_read_regs(state, STB0899_CFRM, cfr, 2); /* get derotator frequency */ 427 stb0899_read_regs(state, STB0899_CFRM, cfr, 2); /* get derotator frequency */
428 internal->derot_freq = state->config->inversion * MAKEWORD16(cfr[0], cfr[1]); 428
429 /* store autodetected IQ swapping as default for DVB-S2 tuning */
430 reg = stb0899_read_reg(state, STB0899_IQSWAP);
431 if (STB0899_GETFIELD(SYM, reg))
432 internal->inversion = IQ_SWAP_ON;
433 else
434 internal->inversion = IQ_SWAP_OFF;
435
436 internal->derot_freq = internal->inversion * MAKEWORD16(cfr[0], cfr[1]);
429 dprintk(state->verbose, FE_DEBUG, 1, "------> DATAOK ! Derot Freq=%d", internal->derot_freq); 437 dprintk(state->verbose, FE_DEBUG, 1, "------> DATAOK ! Derot Freq=%d", internal->derot_freq);
430 } 438 }
431 439
@@ -444,7 +452,7 @@ static enum stb0899_status stb0899_check_range(struct stb0899_state *state)
444 int range_offst, tp_freq; 452 int range_offst, tp_freq;
445 453
446 range_offst = internal->srch_range / 2000; 454 range_offst = internal->srch_range / 2000;
447 tp_freq = internal->freq + (internal->derot_freq * internal->mclk) / 1000; 455 tp_freq = internal->freq - (internal->derot_freq * internal->mclk) / 1000;
448 456
449 if ((tp_freq >= params->freq - range_offst) && (tp_freq <= params->freq + range_offst)) { 457 if ((tp_freq >= params->freq - range_offst) && (tp_freq <= params->freq + range_offst)) {
450 internal->status = RANGEOK; 458 internal->status = RANGEOK;
@@ -638,7 +646,7 @@ enum stb0899_status stb0899_dvbs_algo(struct stb0899_state *state)
638 "RANGE OK ! derot freq=%d, mclk=%d", 646 "RANGE OK ! derot freq=%d, mclk=%d",
639 internal->derot_freq, internal->mclk); 647 internal->derot_freq, internal->mclk);
640 648
641 internal->freq = params->freq + ((internal->derot_freq * internal->mclk) / 1000); 649 internal->freq = params->freq - ((internal->derot_freq * internal->mclk) / 1000);
642 reg = stb0899_read_reg(state, STB0899_PLPARM); 650 reg = stb0899_read_reg(state, STB0899_PLPARM);
643 internal->fecrate = STB0899_GETFIELD(VITCURPUN, reg); 651 internal->fecrate = STB0899_GETFIELD(VITCURPUN, reg);
644 dprintk(state->verbose, FE_DEBUG, 1, 652 dprintk(state->verbose, FE_DEBUG, 1,
@@ -1373,9 +1381,6 @@ enum stb0899_status stb0899_dvbs2_algo(struct stb0899_state *state)
1373 case IQ_SWAP_ON: 1381 case IQ_SWAP_ON:
1374 STB0899_SETFIELD_VAL(SPECTRUM_INVERT, reg, 1); 1382 STB0899_SETFIELD_VAL(SPECTRUM_INVERT, reg, 1);
1375 break; 1383 break;
1376 case IQ_SWAP_AUTO: /* use last successful search first */
1377 STB0899_SETFIELD_VAL(SPECTRUM_INVERT, reg, 1);
1378 break;
1379 } 1384 }
1380 stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_DMD_CNTRL2, STB0899_OFF0_DMD_CNTRL2, reg); 1385 stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_DMD_CNTRL2, STB0899_OFF0_DMD_CNTRL2, reg);
1381 stb0899_dvbs2_reacquire(state); 1386 stb0899_dvbs2_reacquire(state);
@@ -1405,41 +1410,39 @@ enum stb0899_status stb0899_dvbs2_algo(struct stb0899_state *state)
1405 } 1410 }
1406 1411
1407 if (internal->status != DVBS2_FEC_LOCK) { 1412 if (internal->status != DVBS2_FEC_LOCK) {
1408 if (internal->inversion == IQ_SWAP_AUTO) { 1413 reg = STB0899_READ_S2REG(STB0899_S2DEMOD, DMD_CNTRL2);
1409 reg = STB0899_READ_S2REG(STB0899_S2DEMOD, DMD_CNTRL2); 1414 iqSpectrum = STB0899_GETFIELD(SPECTRUM_INVERT, reg);
1410 iqSpectrum = STB0899_GETFIELD(SPECTRUM_INVERT, reg); 1415 /* IQ Spectrum Inversion */
1411 /* IQ Spectrum Inversion */ 1416 STB0899_SETFIELD_VAL(SPECTRUM_INVERT, reg, !iqSpectrum);
1412 STB0899_SETFIELD_VAL(SPECTRUM_INVERT, reg, !iqSpectrum); 1417 stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_DMD_CNTRL2, STB0899_OFF0_DMD_CNTRL2, reg);
1413 stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_DMD_CNTRL2, STB0899_OFF0_DMD_CNTRL2, reg); 1418 /* start acquistion process */
1414 /* start acquistion process */ 1419 stb0899_dvbs2_reacquire(state);
1415 stb0899_dvbs2_reacquire(state); 1420
1421 /* Wait for demod lock (UWP and CSM) */
1422 internal->status = stb0899_dvbs2_get_dmd_status(state, searchTime);
1423 if (internal->status == DVBS2_DEMOD_LOCK) {
1424 i = 0;
1425 /* Demod Locked, check FEC */
1426 internal->status = stb0899_dvbs2_get_fec_status(state, FecLockTime);
1427 /*try thrice for false locks, (UWP and CSM Locked but no FEC) */
1428 while ((internal->status != DVBS2_FEC_LOCK) && (i < 3)) {
1429 /* Read the frequency offset*/
1430 offsetfreq = STB0899_READ_S2REG(STB0899_S2DEMOD, CRL_FREQ);
1416 1431
1417 /* Wait for demod lock (UWP and CSM) */ 1432 /* Set the Nominal frequency to the found frequency offset for the next reacquire*/
1418 internal->status = stb0899_dvbs2_get_dmd_status(state, searchTime); 1433 reg = STB0899_READ_S2REG(STB0899_S2DEMOD, CRL_NOM_FREQ);
1419 if (internal->status == DVBS2_DEMOD_LOCK) { 1434 STB0899_SETFIELD_VAL(CRL_NOM_FREQ, reg, offsetfreq);
1420 i = 0; 1435 stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_CRL_NOM_FREQ, STB0899_OFF0_CRL_NOM_FREQ, reg);
1421 /* Demod Locked, check FEC */ 1436
1422 internal->status = stb0899_dvbs2_get_fec_status(state, FecLockTime); 1437 stb0899_dvbs2_reacquire(state);
1423 /*try thrice for false locks, (UWP and CSM Locked but no FEC) */ 1438 internal->status = stb0899_dvbs2_get_fec_status(state, searchTime);
1424 while ((internal->status != DVBS2_FEC_LOCK) && (i < 3)) { 1439 i++;
1425 /* Read the frequency offset*/
1426 offsetfreq = STB0899_READ_S2REG(STB0899_S2DEMOD, CRL_FREQ);
1427
1428 /* Set the Nominal frequency to the found frequency offset for the next reacquire*/
1429 reg = STB0899_READ_S2REG(STB0899_S2DEMOD, CRL_NOM_FREQ);
1430 STB0899_SETFIELD_VAL(CRL_NOM_FREQ, reg, offsetfreq);
1431 stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_CRL_NOM_FREQ, STB0899_OFF0_CRL_NOM_FREQ, reg);
1432
1433 stb0899_dvbs2_reacquire(state);
1434 internal->status = stb0899_dvbs2_get_fec_status(state, searchTime);
1435 i++;
1436 }
1437 } 1440 }
1441 }
1438/* 1442/*
1439 if (pParams->DVBS2State == FE_DVBS2_FEC_LOCKED) 1443 if (pParams->DVBS2State == FE_DVBS2_FEC_LOCKED)
1440 pParams->IQLocked = !iqSpectrum; 1444 pParams->IQLocked = !iqSpectrum;
1441*/ 1445*/
1442 }
1443 } 1446 }
1444 if (internal->status == DVBS2_FEC_LOCK) { 1447 if (internal->status == DVBS2_FEC_LOCK) {
1445 dprintk(state->verbose, FE_DEBUG, 1, "----------------> DVB-S2 FEC Lock !"); 1448 dprintk(state->verbose, FE_DEBUG, 1, "----------------> DVB-S2 FEC Lock !");
@@ -1487,13 +1490,21 @@ enum stb0899_status stb0899_dvbs2_algo(struct stb0899_state *state)
1487 /* Store signal parameters */ 1490 /* Store signal parameters */
1488 offsetfreq = STB0899_READ_S2REG(STB0899_S2DEMOD, CRL_FREQ); 1491 offsetfreq = STB0899_READ_S2REG(STB0899_S2DEMOD, CRL_FREQ);
1489 1492
1493 /* sign extend 30 bit value before using it in calculations */
1494 if (offsetfreq & (1 << 29))
1495 offsetfreq |= -1 << 30;
1496
1490 offsetfreq = offsetfreq / ((1 << 30) / 1000); 1497 offsetfreq = offsetfreq / ((1 << 30) / 1000);
1491 offsetfreq *= (internal->master_clk / 1000000); 1498 offsetfreq *= (internal->master_clk / 1000000);
1499
1500 /* store current inversion for next run */
1492 reg = STB0899_READ_S2REG(STB0899_S2DEMOD, DMD_CNTRL2); 1501 reg = STB0899_READ_S2REG(STB0899_S2DEMOD, DMD_CNTRL2);
1493 if (STB0899_GETFIELD(SPECTRUM_INVERT, reg)) 1502 if (STB0899_GETFIELD(SPECTRUM_INVERT, reg))
1494 offsetfreq *= -1; 1503 internal->inversion = IQ_SWAP_ON;
1504 else
1505 internal->inversion = IQ_SWAP_OFF;
1495 1506
1496 internal->freq = internal->freq - offsetfreq; 1507 internal->freq = internal->freq + offsetfreq;
1497 internal->srate = stb0899_dvbs2_get_srate(state); 1508 internal->srate = stb0899_dvbs2_get_srate(state);
1498 1509
1499 reg = STB0899_READ_S2REG(STB0899_S2DEMOD, UWP_STAT2); 1510 reg = STB0899_READ_S2REG(STB0899_S2DEMOD, UWP_STAT2);
diff --git a/drivers/media/dvb-frontends/stb0899_drv.c b/drivers/media/dvb-frontends/stb0899_drv.c
index cc278b3d6d5a..3dd5714eadba 100644
--- a/drivers/media/dvb-frontends/stb0899_drv.c
+++ b/drivers/media/dvb-frontends/stb0899_drv.c
@@ -1618,19 +1618,18 @@ static struct dvb_frontend_ops stb0899_ops = {
1618struct dvb_frontend *stb0899_attach(struct stb0899_config *config, struct i2c_adapter *i2c) 1618struct dvb_frontend *stb0899_attach(struct stb0899_config *config, struct i2c_adapter *i2c)
1619{ 1619{
1620 struct stb0899_state *state = NULL; 1620 struct stb0899_state *state = NULL;
1621 enum stb0899_inversion inversion;
1622 1621
1623 state = kzalloc(sizeof (struct stb0899_state), GFP_KERNEL); 1622 state = kzalloc(sizeof (struct stb0899_state), GFP_KERNEL);
1624 if (state == NULL) 1623 if (state == NULL)
1625 goto error; 1624 goto error;
1626 1625
1627 inversion = config->inversion;
1628 state->verbose = &verbose; 1626 state->verbose = &verbose;
1629 state->config = config; 1627 state->config = config;
1630 state->i2c = i2c; 1628 state->i2c = i2c;
1631 state->frontend.ops = stb0899_ops; 1629 state->frontend.ops = stb0899_ops;
1632 state->frontend.demodulator_priv = state; 1630 state->frontend.demodulator_priv = state;
1633 state->internal.inversion = inversion; 1631 /* use configured inversion as default -- we'll later autodetect inversion */
1632 state->internal.inversion = config->inversion;
1634 1633
1635 stb0899_wakeup(&state->frontend); 1634 stb0899_wakeup(&state->frontend);
1636 if (stb0899_get_dev_id(state) == -ENODEV) { 1635 if (stb0899_get_dev_id(state) == -ENODEV) {
diff --git a/drivers/media/dvb-frontends/stb0899_drv.h b/drivers/media/dvb-frontends/stb0899_drv.h
index 8d26ff6eb1db..139264d19263 100644
--- a/drivers/media/dvb-frontends/stb0899_drv.h
+++ b/drivers/media/dvb-frontends/stb0899_drv.h
@@ -45,9 +45,8 @@ struct stb0899_s2_reg {
45}; 45};
46 46
47enum stb0899_inversion { 47enum stb0899_inversion {
48 IQ_SWAP_OFF = 0, 48 IQ_SWAP_OFF = +1, /* inversion affects the sign of e. g. */
49 IQ_SWAP_ON, 49 IQ_SWAP_ON = -1, /* the derotator frequency register */
50 IQ_SWAP_AUTO
51}; 50};
52 51
53#define STB0899_GPIO00 0xf140 52#define STB0899_GPIO00 0xf140
diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index f981d50a2a8c..b2cd8ca51af7 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -245,6 +245,15 @@ config VIDEO_KS0127
245 To compile this driver as a module, choose M here: the 245 To compile this driver as a module, choose M here: the
246 module will be called ks0127. 246 module will be called ks0127.
247 247
248config VIDEO_ML86V7667
249 tristate "OKI ML86V7667 video decoder"
250 depends on VIDEO_V4L2 && I2C
251 ---help---
252 Support for the OKI Semiconductor ML86V7667 video decoder.
253
254 To compile this driver as a module, choose M here: the
255 module will be called ml86v7667.
256
248config VIDEO_SAA7110 257config VIDEO_SAA7110
249 tristate "Philips SAA7110 video decoder" 258 tristate "Philips SAA7110 video decoder"
250 depends on VIDEO_V4L2 && I2C 259 depends on VIDEO_V4L2 && I2C
@@ -425,6 +434,15 @@ config VIDEO_AK881X
425 help 434 help
426 Video output driver for AKM AK8813 and AK8814 TV encoders 435 Video output driver for AKM AK8813 and AK8814 TV encoders
427 436
437config VIDEO_THS8200
438 tristate "Texas Instruments THS8200 video encoder"
439 depends on VIDEO_V4L2 && I2C
440 ---help---
441 Support for the Texas Instruments THS8200 video encoder.
442
443 To compile this driver as a module, choose M here: the
444 module will be called ths8200.
445
428comment "Camera sensor devices" 446comment "Camera sensor devices"
429 447
430config VIDEO_APTINA_PLL 448config VIDEO_APTINA_PLL
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index 720f42d9d9f4..dc20653bb5ad 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -34,6 +34,7 @@ obj-$(CONFIG_VIDEO_BT856) += bt856.o
34obj-$(CONFIG_VIDEO_BT866) += bt866.o 34obj-$(CONFIG_VIDEO_BT866) += bt866.o
35obj-$(CONFIG_VIDEO_KS0127) += ks0127.o 35obj-$(CONFIG_VIDEO_KS0127) += ks0127.o
36obj-$(CONFIG_VIDEO_THS7303) += ths7303.o 36obj-$(CONFIG_VIDEO_THS7303) += ths7303.o
37obj-$(CONFIG_VIDEO_THS8200) += ths8200.o
37obj-$(CONFIG_VIDEO_TVP5150) += tvp5150.o 38obj-$(CONFIG_VIDEO_TVP5150) += tvp5150.o
38obj-$(CONFIG_VIDEO_TVP514X) += tvp514x.o 39obj-$(CONFIG_VIDEO_TVP514X) += tvp514x.o
39obj-$(CONFIG_VIDEO_TVP7002) += tvp7002.o 40obj-$(CONFIG_VIDEO_TVP7002) += tvp7002.o
@@ -70,3 +71,4 @@ obj-$(CONFIG_VIDEO_AS3645A) += as3645a.o
70obj-$(CONFIG_VIDEO_SMIAPP_PLL) += smiapp-pll.o 71obj-$(CONFIG_VIDEO_SMIAPP_PLL) += smiapp-pll.o
71obj-$(CONFIG_VIDEO_AK881X) += ak881x.o 72obj-$(CONFIG_VIDEO_AK881X) += ak881x.o
72obj-$(CONFIG_VIDEO_IR_I2C) += ir-kbd-i2c.o 73obj-$(CONFIG_VIDEO_IR_I2C) += ir-kbd-i2c.o
74obj-$(CONFIG_VIDEO_ML86V7667) += ml86v7667.o
diff --git a/drivers/media/i2c/ad9389b.c b/drivers/media/i2c/ad9389b.c
index 58344b6c3a55..ba4364dfae66 100644
--- a/drivers/media/i2c/ad9389b.c
+++ b/drivers/media/i2c/ad9389b.c
@@ -32,7 +32,6 @@
32#include <linux/workqueue.h> 32#include <linux/workqueue.h>
33#include <linux/v4l2-dv-timings.h> 33#include <linux/v4l2-dv-timings.h>
34#include <media/v4l2-device.h> 34#include <media/v4l2-device.h>
35#include <media/v4l2-chip-ident.h>
36#include <media/v4l2-common.h> 35#include <media/v4l2-common.h>
37#include <media/v4l2-ctrls.h> 36#include <media/v4l2-ctrls.h>
38#include <media/ad9389b.h> 37#include <media/ad9389b.h>
@@ -343,12 +342,6 @@ static const struct v4l2_ctrl_ops ad9389b_ctrl_ops = {
343#ifdef CONFIG_VIDEO_ADV_DEBUG 342#ifdef CONFIG_VIDEO_ADV_DEBUG
344static int ad9389b_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 343static int ad9389b_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
345{ 344{
346 struct i2c_client *client = v4l2_get_subdevdata(sd);
347
348 if (!v4l2_chip_match_i2c_client(client, &reg->match))
349 return -EINVAL;
350 if (!capable(CAP_SYS_ADMIN))
351 return -EPERM;
352 reg->val = ad9389b_rd(sd, reg->reg & 0xff); 345 reg->val = ad9389b_rd(sd, reg->reg & 0xff);
353 reg->size = 1; 346 reg->size = 1;
354 return 0; 347 return 0;
@@ -356,24 +349,11 @@ static int ad9389b_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *
356 349
357static int ad9389b_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg) 350static int ad9389b_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
358{ 351{
359 struct i2c_client *client = v4l2_get_subdevdata(sd);
360
361 if (!v4l2_chip_match_i2c_client(client, &reg->match))
362 return -EINVAL;
363 if (!capable(CAP_SYS_ADMIN))
364 return -EPERM;
365 ad9389b_wr(sd, reg->reg & 0xff, reg->val & 0xff); 352 ad9389b_wr(sd, reg->reg & 0xff, reg->val & 0xff);
366 return 0; 353 return 0;
367} 354}
368#endif 355#endif
369 356
370static int ad9389b_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
371{
372 struct i2c_client *client = v4l2_get_subdevdata(sd);
373
374 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_AD9389B, 0);
375}
376
377static int ad9389b_log_status(struct v4l2_subdev *sd) 357static int ad9389b_log_status(struct v4l2_subdev *sd)
378{ 358{
379 struct ad9389b_state *state = get_ad9389b_state(sd); 359 struct ad9389b_state *state = get_ad9389b_state(sd);
@@ -600,7 +580,6 @@ static int ad9389b_isr(struct v4l2_subdev *sd, u32 status, bool *handled)
600 580
601static const struct v4l2_subdev_core_ops ad9389b_core_ops = { 581static const struct v4l2_subdev_core_ops ad9389b_core_ops = {
602 .log_status = ad9389b_log_status, 582 .log_status = ad9389b_log_status,
603 .g_chip_ident = ad9389b_g_chip_ident,
604#ifdef CONFIG_VIDEO_ADV_DEBUG 583#ifdef CONFIG_VIDEO_ADV_DEBUG
605 .g_register = ad9389b_g_register, 584 .g_register = ad9389b_g_register,
606 .s_register = ad9389b_s_register, 585 .s_register = ad9389b_s_register,
@@ -1188,15 +1167,14 @@ static int ad9389b_probe(struct i2c_client *client, const struct i2c_device_id *
1188 v4l_dbg(1, debug, client, "detecting ad9389b client on address 0x%x\n", 1167 v4l_dbg(1, debug, client, "detecting ad9389b client on address 0x%x\n",
1189 client->addr << 1); 1168 client->addr << 1);
1190 1169
1191 state = kzalloc(sizeof(struct ad9389b_state), GFP_KERNEL); 1170 state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL);
1192 if (!state) 1171 if (!state)
1193 return -ENOMEM; 1172 return -ENOMEM;
1194 1173
1195 /* Platform data */ 1174 /* Platform data */
1196 if (pdata == NULL) { 1175 if (pdata == NULL) {
1197 v4l_err(client, "No platform data!\n"); 1176 v4l_err(client, "No platform data!\n");
1198 err = -ENODEV; 1177 return -ENODEV;
1199 goto err_free;
1200 } 1178 }
1201 memcpy(&state->pdata, pdata, sizeof(state->pdata)); 1179 memcpy(&state->pdata, pdata, sizeof(state->pdata));
1202 1180
@@ -1251,12 +1229,14 @@ static int ad9389b_probe(struct i2c_client *client, const struct i2c_device_id *
1251 state->edid_i2c_client = i2c_new_dummy(client->adapter, (0x7e>>1)); 1229 state->edid_i2c_client = i2c_new_dummy(client->adapter, (0x7e>>1));
1252 if (state->edid_i2c_client == NULL) { 1230 if (state->edid_i2c_client == NULL) {
1253 v4l2_err(sd, "failed to register edid i2c client\n"); 1231 v4l2_err(sd, "failed to register edid i2c client\n");
1232 err = -ENOMEM;
1254 goto err_entity; 1233 goto err_entity;
1255 } 1234 }
1256 1235
1257 state->work_queue = create_singlethread_workqueue(sd->name); 1236 state->work_queue = create_singlethread_workqueue(sd->name);
1258 if (state->work_queue == NULL) { 1237 if (state->work_queue == NULL) {
1259 v4l2_err(sd, "could not create workqueue\n"); 1238 v4l2_err(sd, "could not create workqueue\n");
1239 err = -ENOMEM;
1260 goto err_unreg; 1240 goto err_unreg;
1261 } 1241 }
1262 1242
@@ -1276,8 +1256,6 @@ err_entity:
1276 media_entity_cleanup(&sd->entity); 1256 media_entity_cleanup(&sd->entity);
1277err_hdl: 1257err_hdl:
1278 v4l2_ctrl_handler_free(&state->hdl); 1258 v4l2_ctrl_handler_free(&state->hdl);
1279err_free:
1280 kfree(state);
1281 return err; 1259 return err;
1282} 1260}
1283 1261
@@ -1302,15 +1280,14 @@ static int ad9389b_remove(struct i2c_client *client)
1302 v4l2_device_unregister_subdev(sd); 1280 v4l2_device_unregister_subdev(sd);
1303 media_entity_cleanup(&sd->entity); 1281 media_entity_cleanup(&sd->entity);
1304 v4l2_ctrl_handler_free(sd->ctrl_handler); 1282 v4l2_ctrl_handler_free(sd->ctrl_handler);
1305 kfree(get_ad9389b_state(sd));
1306 return 0; 1283 return 0;
1307} 1284}
1308 1285
1309/* ----------------------------------------------------------------------- */ 1286/* ----------------------------------------------------------------------- */
1310 1287
1311static struct i2c_device_id ad9389b_id[] = { 1288static struct i2c_device_id ad9389b_id[] = {
1312 { "ad9389b", V4L2_IDENT_AD9389B }, 1289 { "ad9389b", 0 },
1313 { "ad9889b", V4L2_IDENT_AD9389B }, 1290 { "ad9889b", 0 },
1314 { } 1291 { }
1315}; 1292};
1316MODULE_DEVICE_TABLE(i2c, ad9389b_id); 1293MODULE_DEVICE_TABLE(i2c, ad9389b_id);
diff --git a/drivers/media/i2c/adp1653.c b/drivers/media/i2c/adp1653.c
index ef75abe5984c..873fe1949e98 100644
--- a/drivers/media/i2c/adp1653.c
+++ b/drivers/media/i2c/adp1653.c
@@ -417,7 +417,7 @@ static int adp1653_probe(struct i2c_client *client,
417 if (client->dev.platform_data == NULL) 417 if (client->dev.platform_data == NULL)
418 return -ENODEV; 418 return -ENODEV;
419 419
420 flash = kzalloc(sizeof(*flash), GFP_KERNEL); 420 flash = devm_kzalloc(&client->dev, sizeof(*flash), GFP_KERNEL);
421 if (flash == NULL) 421 if (flash == NULL)
422 return -ENOMEM; 422 return -ENOMEM;
423 423
@@ -443,7 +443,6 @@ static int adp1653_probe(struct i2c_client *client,
443 443
444free_and_quit: 444free_and_quit:
445 v4l2_ctrl_handler_free(&flash->ctrls); 445 v4l2_ctrl_handler_free(&flash->ctrls);
446 kfree(flash);
447 return ret; 446 return ret;
448} 447}
449 448
@@ -455,7 +454,7 @@ static int adp1653_remove(struct i2c_client *client)
455 v4l2_device_unregister_subdev(&flash->subdev); 454 v4l2_device_unregister_subdev(&flash->subdev);
456 v4l2_ctrl_handler_free(&flash->ctrls); 455 v4l2_ctrl_handler_free(&flash->ctrls);
457 media_entity_cleanup(&flash->subdev.entity); 456 media_entity_cleanup(&flash->subdev.entity);
458 kfree(flash); 457
459 return 0; 458 return 0;
460} 459}
461 460
diff --git a/drivers/media/i2c/adv7170.c b/drivers/media/i2c/adv7170.c
index 6bc01fb98ff8..04bb29720aaf 100644
--- a/drivers/media/i2c/adv7170.c
+++ b/drivers/media/i2c/adv7170.c
@@ -36,7 +36,6 @@
36#include <linux/i2c.h> 36#include <linux/i2c.h>
37#include <linux/videodev2.h> 37#include <linux/videodev2.h>
38#include <media/v4l2-device.h> 38#include <media/v4l2-device.h>
39#include <media/v4l2-chip-ident.h>
40 39
41MODULE_DESCRIPTION("Analog Devices ADV7170 video encoder driver"); 40MODULE_DESCRIPTION("Analog Devices ADV7170 video encoder driver");
42MODULE_AUTHOR("Maxim Yevtyushkin"); 41MODULE_AUTHOR("Maxim Yevtyushkin");
@@ -317,19 +316,8 @@ static int adv7170_s_fmt(struct v4l2_subdev *sd,
317 return ret; 316 return ret;
318} 317}
319 318
320static int adv7170_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
321{
322 struct i2c_client *client = v4l2_get_subdevdata(sd);
323
324 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_ADV7170, 0);
325}
326
327/* ----------------------------------------------------------------------- */ 319/* ----------------------------------------------------------------------- */
328 320
329static const struct v4l2_subdev_core_ops adv7170_core_ops = {
330 .g_chip_ident = adv7170_g_chip_ident,
331};
332
333static const struct v4l2_subdev_video_ops adv7170_video_ops = { 321static const struct v4l2_subdev_video_ops adv7170_video_ops = {
334 .s_std_output = adv7170_s_std_output, 322 .s_std_output = adv7170_s_std_output,
335 .s_routing = adv7170_s_routing, 323 .s_routing = adv7170_s_routing,
@@ -339,7 +327,6 @@ static const struct v4l2_subdev_video_ops adv7170_video_ops = {
339}; 327};
340 328
341static const struct v4l2_subdev_ops adv7170_ops = { 329static const struct v4l2_subdev_ops adv7170_ops = {
342 .core = &adv7170_core_ops,
343 .video = &adv7170_video_ops, 330 .video = &adv7170_video_ops,
344}; 331};
345 332
@@ -359,7 +346,7 @@ static int adv7170_probe(struct i2c_client *client,
359 v4l_info(client, "chip found @ 0x%x (%s)\n", 346 v4l_info(client, "chip found @ 0x%x (%s)\n",
360 client->addr << 1, client->adapter->name); 347 client->addr << 1, client->adapter->name);
361 348
362 encoder = kzalloc(sizeof(struct adv7170), GFP_KERNEL); 349 encoder = devm_kzalloc(&client->dev, sizeof(*encoder), GFP_KERNEL);
363 if (encoder == NULL) 350 if (encoder == NULL)
364 return -ENOMEM; 351 return -ENOMEM;
365 sd = &encoder->sd; 352 sd = &encoder->sd;
@@ -384,7 +371,6 @@ static int adv7170_remove(struct i2c_client *client)
384 struct v4l2_subdev *sd = i2c_get_clientdata(client); 371 struct v4l2_subdev *sd = i2c_get_clientdata(client);
385 372
386 v4l2_device_unregister_subdev(sd); 373 v4l2_device_unregister_subdev(sd);
387 kfree(to_adv7170(sd));
388 return 0; 374 return 0;
389} 375}
390 376
diff --git a/drivers/media/i2c/adv7175.c b/drivers/media/i2c/adv7175.c
index c7640fab5730..b88f3b3d5ed9 100644
--- a/drivers/media/i2c/adv7175.c
+++ b/drivers/media/i2c/adv7175.c
@@ -32,7 +32,6 @@
32#include <linux/i2c.h> 32#include <linux/i2c.h>
33#include <linux/videodev2.h> 33#include <linux/videodev2.h>
34#include <media/v4l2-device.h> 34#include <media/v4l2-device.h>
35#include <media/v4l2-chip-ident.h>
36 35
37MODULE_DESCRIPTION("Analog Devices ADV7175 video encoder driver"); 36MODULE_DESCRIPTION("Analog Devices ADV7175 video encoder driver");
38MODULE_AUTHOR("Dave Perks"); 37MODULE_AUTHOR("Dave Perks");
@@ -355,13 +354,6 @@ static int adv7175_s_fmt(struct v4l2_subdev *sd,
355 return ret; 354 return ret;
356} 355}
357 356
358static int adv7175_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
359{
360 struct i2c_client *client = v4l2_get_subdevdata(sd);
361
362 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_ADV7175, 0);
363}
364
365static int adv7175_s_power(struct v4l2_subdev *sd, int on) 357static int adv7175_s_power(struct v4l2_subdev *sd, int on)
366{ 358{
367 if (on) 359 if (on)
@@ -375,7 +367,6 @@ static int adv7175_s_power(struct v4l2_subdev *sd, int on)
375/* ----------------------------------------------------------------------- */ 367/* ----------------------------------------------------------------------- */
376 368
377static const struct v4l2_subdev_core_ops adv7175_core_ops = { 369static const struct v4l2_subdev_core_ops adv7175_core_ops = {
378 .g_chip_ident = adv7175_g_chip_ident,
379 .init = adv7175_init, 370 .init = adv7175_init,
380 .s_power = adv7175_s_power, 371 .s_power = adv7175_s_power,
381}; 372};
@@ -409,7 +400,7 @@ static int adv7175_probe(struct i2c_client *client,
409 v4l_info(client, "chip found @ 0x%x (%s)\n", 400 v4l_info(client, "chip found @ 0x%x (%s)\n",
410 client->addr << 1, client->adapter->name); 401 client->addr << 1, client->adapter->name);
411 402
412 encoder = kzalloc(sizeof(struct adv7175), GFP_KERNEL); 403 encoder = devm_kzalloc(&client->dev, sizeof(*encoder), GFP_KERNEL);
413 if (encoder == NULL) 404 if (encoder == NULL)
414 return -ENOMEM; 405 return -ENOMEM;
415 sd = &encoder->sd; 406 sd = &encoder->sd;
@@ -434,7 +425,6 @@ static int adv7175_remove(struct i2c_client *client)
434 struct v4l2_subdev *sd = i2c_get_clientdata(client); 425 struct v4l2_subdev *sd = i2c_get_clientdata(client);
435 426
436 v4l2_device_unregister_subdev(sd); 427 v4l2_device_unregister_subdev(sd);
437 kfree(to_adv7175(sd));
438 return 0; 428 return 0;
439} 429}
440 430
diff --git a/drivers/media/i2c/adv7180.c b/drivers/media/i2c/adv7180.c
index afd561ab190d..d7d99f1c69e4 100644
--- a/drivers/media/i2c/adv7180.c
+++ b/drivers/media/i2c/adv7180.c
@@ -1,6 +1,8 @@
1/* 1/*
2 * adv7180.c Analog Devices ADV7180 video decoder driver 2 * adv7180.c Analog Devices ADV7180 video decoder driver
3 * Copyright (c) 2009 Intel Corporation 3 * Copyright (c) 2009 Intel Corporation
4 * Copyright (C) 2013 Cogent Embedded, Inc.
5 * Copyright (C) 2013 Renesas Solutions Corp.
4 * 6 *
5 * 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
6 * it under the terms of the GNU General Public License version 2 as 8 * it under the terms of the GNU General Public License version 2 as
@@ -27,7 +29,6 @@
27#include <linux/videodev2.h> 29#include <linux/videodev2.h>
28#include <media/v4l2-device.h> 30#include <media/v4l2-device.h>
29#include <media/v4l2-ctrls.h> 31#include <media/v4l2-ctrls.h>
30#include <media/v4l2-chip-ident.h>
31#include <linux/mutex.h> 32#include <linux/mutex.h>
32 33
33#define ADV7180_INPUT_CONTROL_REG 0x00 34#define ADV7180_INPUT_CONTROL_REG 0x00
@@ -272,14 +273,6 @@ static int adv7180_g_input_status(struct v4l2_subdev *sd, u32 *status)
272 return ret; 273 return ret;
273} 274}
274 275
275static int adv7180_g_chip_ident(struct v4l2_subdev *sd,
276 struct v4l2_dbg_chip_ident *chip)
277{
278 struct i2c_client *client = v4l2_get_subdevdata(sd);
279
280 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_ADV7180, 0);
281}
282
283static int adv7180_s_std(struct v4l2_subdev *sd, v4l2_std_id std) 276static int adv7180_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
284{ 277{
285 struct adv7180_state *state = to_state(sd); 278 struct adv7180_state *state = to_state(sd);
@@ -397,14 +390,57 @@ static void adv7180_exit_controls(struct adv7180_state *state)
397 v4l2_ctrl_handler_free(&state->ctrl_hdl); 390 v4l2_ctrl_handler_free(&state->ctrl_hdl);
398} 391}
399 392
393static int adv7180_enum_mbus_fmt(struct v4l2_subdev *sd, unsigned int index,
394 enum v4l2_mbus_pixelcode *code)
395{
396 if (index > 0)
397 return -EINVAL;
398
399 *code = V4L2_MBUS_FMT_YUYV8_2X8;
400
401 return 0;
402}
403
404static int adv7180_mbus_fmt(struct v4l2_subdev *sd,
405 struct v4l2_mbus_framefmt *fmt)
406{
407 struct adv7180_state *state = to_state(sd);
408
409 fmt->code = V4L2_MBUS_FMT_YUYV8_2X8;
410 fmt->colorspace = V4L2_COLORSPACE_SMPTE170M;
411 fmt->field = V4L2_FIELD_INTERLACED;
412 fmt->width = 720;
413 fmt->height = state->curr_norm & V4L2_STD_525_60 ? 480 : 576;
414
415 return 0;
416}
417
418static int adv7180_g_mbus_config(struct v4l2_subdev *sd,
419 struct v4l2_mbus_config *cfg)
420{
421 /*
422 * The ADV7180 sensor supports BT.601/656 output modes.
423 * The BT.656 is default and not yet configurable by s/w.
424 */
425 cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_PCLK_SAMPLE_RISING |
426 V4L2_MBUS_DATA_ACTIVE_HIGH;
427 cfg->type = V4L2_MBUS_BT656;
428
429 return 0;
430}
431
400static const struct v4l2_subdev_video_ops adv7180_video_ops = { 432static const struct v4l2_subdev_video_ops adv7180_video_ops = {
401 .querystd = adv7180_querystd, 433 .querystd = adv7180_querystd,
402 .g_input_status = adv7180_g_input_status, 434 .g_input_status = adv7180_g_input_status,
403 .s_routing = adv7180_s_routing, 435 .s_routing = adv7180_s_routing,
436 .enum_mbus_fmt = adv7180_enum_mbus_fmt,
437 .try_mbus_fmt = adv7180_mbus_fmt,
438 .g_mbus_fmt = adv7180_mbus_fmt,
439 .s_mbus_fmt = adv7180_mbus_fmt,
440 .g_mbus_config = adv7180_g_mbus_config,
404}; 441};
405 442
406static const struct v4l2_subdev_core_ops adv7180_core_ops = { 443static const struct v4l2_subdev_core_ops adv7180_core_ops = {
407 .g_chip_ident = adv7180_g_chip_ident,
408 .s_std = adv7180_s_std, 444 .s_std = adv7180_s_std,
409}; 445};
410 446
@@ -555,7 +591,7 @@ static int adv7180_probe(struct i2c_client *client,
555 v4l_info(client, "chip found @ 0x%02x (%s)\n", 591 v4l_info(client, "chip found @ 0x%02x (%s)\n",
556 client->addr, client->adapter->name); 592 client->addr, client->adapter->name);
557 593
558 state = kzalloc(sizeof(struct adv7180_state), GFP_KERNEL); 594 state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL);
559 if (state == NULL) { 595 if (state == NULL) {
560 ret = -ENOMEM; 596 ret = -ENOMEM;
561 goto err; 597 goto err;
@@ -582,7 +618,6 @@ err_free_ctrl:
582err_unreg_subdev: 618err_unreg_subdev:
583 mutex_destroy(&state->mutex); 619 mutex_destroy(&state->mutex);
584 v4l2_device_unregister_subdev(sd); 620 v4l2_device_unregister_subdev(sd);
585 kfree(state);
586err: 621err:
587 printk(KERN_ERR KBUILD_MODNAME ": Failed to probe: %d\n", ret); 622 printk(KERN_ERR KBUILD_MODNAME ": Failed to probe: %d\n", ret);
588 return ret; 623 return ret;
@@ -607,7 +642,6 @@ static int adv7180_remove(struct i2c_client *client)
607 642
608 mutex_destroy(&state->mutex); 643 mutex_destroy(&state->mutex);
609 v4l2_device_unregister_subdev(sd); 644 v4l2_device_unregister_subdev(sd);
610 kfree(to_state(sd));
611 return 0; 645 return 0;
612} 646}
613 647
@@ -616,9 +650,10 @@ static const struct i2c_device_id adv7180_id[] = {
616 {}, 650 {},
617}; 651};
618 652
619#ifdef CONFIG_PM 653#ifdef CONFIG_PM_SLEEP
620static int adv7180_suspend(struct i2c_client *client, pm_message_t state) 654static int adv7180_suspend(struct device *dev)
621{ 655{
656 struct i2c_client *client = to_i2c_client(dev);
622 int ret; 657 int ret;
623 658
624 ret = i2c_smbus_write_byte_data(client, ADV7180_PWR_MAN_REG, 659 ret = i2c_smbus_write_byte_data(client, ADV7180_PWR_MAN_REG,
@@ -628,8 +663,9 @@ static int adv7180_suspend(struct i2c_client *client, pm_message_t state)
628 return 0; 663 return 0;
629} 664}
630 665
631static int adv7180_resume(struct i2c_client *client) 666static int adv7180_resume(struct device *dev)
632{ 667{
668 struct i2c_client *client = to_i2c_client(dev);
633 struct v4l2_subdev *sd = i2c_get_clientdata(client); 669 struct v4l2_subdev *sd = i2c_get_clientdata(client);
634 struct adv7180_state *state = to_state(sd); 670 struct adv7180_state *state = to_state(sd);
635 int ret; 671 int ret;
@@ -643,6 +679,12 @@ static int adv7180_resume(struct i2c_client *client)
643 return ret; 679 return ret;
644 return 0; 680 return 0;
645} 681}
682
683static SIMPLE_DEV_PM_OPS(adv7180_pm_ops, adv7180_suspend, adv7180_resume);
684#define ADV7180_PM_OPS (&adv7180_pm_ops)
685
686#else
687#define ADV7180_PM_OPS NULL
646#endif 688#endif
647 689
648MODULE_DEVICE_TABLE(i2c, adv7180_id); 690MODULE_DEVICE_TABLE(i2c, adv7180_id);
@@ -651,13 +693,10 @@ static struct i2c_driver adv7180_driver = {
651 .driver = { 693 .driver = {
652 .owner = THIS_MODULE, 694 .owner = THIS_MODULE,
653 .name = KBUILD_MODNAME, 695 .name = KBUILD_MODNAME,
696 .pm = ADV7180_PM_OPS,
654 }, 697 },
655 .probe = adv7180_probe, 698 .probe = adv7180_probe,
656 .remove = adv7180_remove, 699 .remove = adv7180_remove,
657#ifdef CONFIG_PM
658 .suspend = adv7180_suspend,
659 .resume = adv7180_resume,
660#endif
661 .id_table = adv7180_id, 700 .id_table = adv7180_id,
662}; 701};
663 702
diff --git a/drivers/media/i2c/adv7183.c b/drivers/media/i2c/adv7183.c
index 56a1fa4af0fe..6f738d8e3a8f 100644
--- a/drivers/media/i2c/adv7183.c
+++ b/drivers/media/i2c/adv7183.c
@@ -28,7 +28,6 @@
28#include <linux/videodev2.h> 28#include <linux/videodev2.h>
29 29
30#include <media/adv7183.h> 30#include <media/adv7183.h>
31#include <media/v4l2-chip-ident.h>
32#include <media/v4l2-ctrls.h> 31#include <media/v4l2-ctrls.h>
33#include <media/v4l2-device.h> 32#include <media/v4l2-device.h>
34 33
@@ -375,28 +374,28 @@ static int adv7183_querystd(struct v4l2_subdev *sd, v4l2_std_id *std)
375 reg = adv7183_read(sd, ADV7183_STATUS_1); 374 reg = adv7183_read(sd, ADV7183_STATUS_1);
376 switch ((reg >> 0x4) & 0x7) { 375 switch ((reg >> 0x4) & 0x7) {
377 case 0: 376 case 0:
378 *std = V4L2_STD_NTSC; 377 *std &= V4L2_STD_NTSC;
379 break; 378 break;
380 case 1: 379 case 1:
381 *std = V4L2_STD_NTSC_443; 380 *std &= V4L2_STD_NTSC_443;
382 break; 381 break;
383 case 2: 382 case 2:
384 *std = V4L2_STD_PAL_M; 383 *std &= V4L2_STD_PAL_M;
385 break; 384 break;
386 case 3: 385 case 3:
387 *std = V4L2_STD_PAL_60; 386 *std &= V4L2_STD_PAL_60;
388 break; 387 break;
389 case 4: 388 case 4:
390 *std = V4L2_STD_PAL; 389 *std &= V4L2_STD_PAL;
391 break; 390 break;
392 case 5: 391 case 5:
393 *std = V4L2_STD_SECAM; 392 *std &= V4L2_STD_SECAM;
394 break; 393 break;
395 case 6: 394 case 6:
396 *std = V4L2_STD_PAL_Nc; 395 *std &= V4L2_STD_PAL_Nc;
397 break; 396 break;
398 case 7: 397 case 7:
399 *std = V4L2_STD_SECAM; 398 *std &= V4L2_STD_SECAM;
400 break; 399 break;
401 default: 400 default:
402 *std = V4L2_STD_UNKNOWN; 401 *std = V4L2_STD_UNKNOWN;
@@ -474,34 +473,16 @@ static int adv7183_s_stream(struct v4l2_subdev *sd, int enable)
474 struct adv7183 *decoder = to_adv7183(sd); 473 struct adv7183 *decoder = to_adv7183(sd);
475 474
476 if (enable) 475 if (enable)
477 gpio_direction_output(decoder->oe_pin, 0); 476 gpio_set_value(decoder->oe_pin, 0);
478 else 477 else
479 gpio_direction_output(decoder->oe_pin, 1); 478 gpio_set_value(decoder->oe_pin, 1);
480 udelay(1); 479 udelay(1);
481 return 0; 480 return 0;
482} 481}
483 482
484static int adv7183_g_chip_ident(struct v4l2_subdev *sd,
485 struct v4l2_dbg_chip_ident *chip)
486{
487 int rev;
488 struct i2c_client *client = v4l2_get_subdevdata(sd);
489
490 /* 0x11 for adv7183, 0x13 for adv7183b */
491 rev = adv7183_read(sd, ADV7183_IDENT);
492
493 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_ADV7183, rev);
494}
495
496#ifdef CONFIG_VIDEO_ADV_DEBUG 483#ifdef CONFIG_VIDEO_ADV_DEBUG
497static int adv7183_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 484static int adv7183_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
498{ 485{
499 struct i2c_client *client = v4l2_get_subdevdata(sd);
500
501 if (!v4l2_chip_match_i2c_client(client, &reg->match))
502 return -EINVAL;
503 if (!capable(CAP_SYS_ADMIN))
504 return -EPERM;
505 reg->val = adv7183_read(sd, reg->reg & 0xff); 486 reg->val = adv7183_read(sd, reg->reg & 0xff);
506 reg->size = 1; 487 reg->size = 1;
507 return 0; 488 return 0;
@@ -509,12 +490,6 @@ static int adv7183_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *
509 490
510static int adv7183_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg) 491static int adv7183_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
511{ 492{
512 struct i2c_client *client = v4l2_get_subdevdata(sd);
513
514 if (!v4l2_chip_match_i2c_client(client, &reg->match))
515 return -EINVAL;
516 if (!capable(CAP_SYS_ADMIN))
517 return -EPERM;
518 adv7183_write(sd, reg->reg & 0xff, reg->val & 0xff); 493 adv7183_write(sd, reg->reg & 0xff, reg->val & 0xff);
519 return 0; 494 return 0;
520} 495}
@@ -529,7 +504,6 @@ static const struct v4l2_subdev_core_ops adv7183_core_ops = {
529 .g_std = adv7183_g_std, 504 .g_std = adv7183_g_std,
530 .s_std = adv7183_s_std, 505 .s_std = adv7183_s_std,
531 .reset = adv7183_reset, 506 .reset = adv7183_reset,
532 .g_chip_ident = adv7183_g_chip_ident,
533#ifdef CONFIG_VIDEO_ADV_DEBUG 507#ifdef CONFIG_VIDEO_ADV_DEBUG
534 .g_register = adv7183_g_register, 508 .g_register = adv7183_g_register,
535 .s_register = adv7183_s_register, 509 .s_register = adv7183_s_register,
@@ -573,23 +547,24 @@ static int adv7183_probe(struct i2c_client *client,
573 if (pin_array == NULL) 547 if (pin_array == NULL)
574 return -EINVAL; 548 return -EINVAL;
575 549
576 decoder = kzalloc(sizeof(struct adv7183), GFP_KERNEL); 550 decoder = devm_kzalloc(&client->dev, sizeof(*decoder), GFP_KERNEL);
577 if (decoder == NULL) 551 if (decoder == NULL)
578 return -ENOMEM; 552 return -ENOMEM;
579 553
580 decoder->reset_pin = pin_array[0]; 554 decoder->reset_pin = pin_array[0];
581 decoder->oe_pin = pin_array[1]; 555 decoder->oe_pin = pin_array[1];
582 556
583 if (gpio_request(decoder->reset_pin, "ADV7183 Reset")) { 557 if (devm_gpio_request_one(&client->dev, decoder->reset_pin,
558 GPIOF_OUT_INIT_LOW, "ADV7183 Reset")) {
584 v4l_err(client, "failed to request GPIO %d\n", decoder->reset_pin); 559 v4l_err(client, "failed to request GPIO %d\n", decoder->reset_pin);
585 ret = -EBUSY; 560 return -EBUSY;
586 goto err_free_decoder;
587 } 561 }
588 562
589 if (gpio_request(decoder->oe_pin, "ADV7183 Output Enable")) { 563 if (devm_gpio_request_one(&client->dev, decoder->oe_pin,
564 GPIOF_OUT_INIT_HIGH,
565 "ADV7183 Output Enable")) {
590 v4l_err(client, "failed to request GPIO %d\n", decoder->oe_pin); 566 v4l_err(client, "failed to request GPIO %d\n", decoder->oe_pin);
591 ret = -EBUSY; 567 return -EBUSY;
592 goto err_free_reset;
593 } 568 }
594 569
595 sd = &decoder->sd; 570 sd = &decoder->sd;
@@ -611,7 +586,7 @@ static int adv7183_probe(struct i2c_client *client,
611 ret = hdl->error; 586 ret = hdl->error;
612 587
613 v4l2_ctrl_handler_free(hdl); 588 v4l2_ctrl_handler_free(hdl);
614 goto err_free_oe; 589 return ret;
615 } 590 }
616 591
617 /* v4l2 doesn't support an autodetect standard, pick PAL as default */ 592 /* v4l2 doesn't support an autodetect standard, pick PAL as default */
@@ -619,12 +594,10 @@ static int adv7183_probe(struct i2c_client *client,
619 decoder->input = ADV7183_COMPOSITE4; 594 decoder->input = ADV7183_COMPOSITE4;
620 decoder->output = ADV7183_8BIT_OUT; 595 decoder->output = ADV7183_8BIT_OUT;
621 596
622 gpio_direction_output(decoder->oe_pin, 1);
623 /* reset chip */ 597 /* reset chip */
624 gpio_direction_output(decoder->reset_pin, 0);
625 /* reset pulse width at least 5ms */ 598 /* reset pulse width at least 5ms */
626 mdelay(10); 599 mdelay(10);
627 gpio_direction_output(decoder->reset_pin, 1); 600 gpio_set_value(decoder->reset_pin, 1);
628 /* wait 5ms before any further i2c writes are performed */ 601 /* wait 5ms before any further i2c writes are performed */
629 mdelay(5); 602 mdelay(5);
630 603
@@ -638,29 +611,18 @@ static int adv7183_probe(struct i2c_client *client,
638 ret = v4l2_ctrl_handler_setup(hdl); 611 ret = v4l2_ctrl_handler_setup(hdl);
639 if (ret) { 612 if (ret) {
640 v4l2_ctrl_handler_free(hdl); 613 v4l2_ctrl_handler_free(hdl);
641 goto err_free_oe; 614 return ret;
642 } 615 }
643 616
644 return 0; 617 return 0;
645err_free_oe:
646 gpio_free(decoder->oe_pin);
647err_free_reset:
648 gpio_free(decoder->reset_pin);
649err_free_decoder:
650 kfree(decoder);
651 return ret;
652} 618}
653 619
654static int adv7183_remove(struct i2c_client *client) 620static int adv7183_remove(struct i2c_client *client)
655{ 621{
656 struct v4l2_subdev *sd = i2c_get_clientdata(client); 622 struct v4l2_subdev *sd = i2c_get_clientdata(client);
657 struct adv7183 *decoder = to_adv7183(sd);
658 623
659 v4l2_device_unregister_subdev(sd); 624 v4l2_device_unregister_subdev(sd);
660 v4l2_ctrl_handler_free(sd->ctrl_handler); 625 v4l2_ctrl_handler_free(sd->ctrl_handler);
661 gpio_free(decoder->oe_pin);
662 gpio_free(decoder->reset_pin);
663 kfree(decoder);
664 return 0; 626 return 0;
665} 627}
666 628
diff --git a/drivers/media/i2c/adv7343.c b/drivers/media/i2c/adv7343.c
index 9fc2b985df0e..7606218ec4a7 100644
--- a/drivers/media/i2c/adv7343.c
+++ b/drivers/media/i2c/adv7343.c
@@ -28,7 +28,6 @@
28 28
29#include <media/adv7343.h> 29#include <media/adv7343.h>
30#include <media/v4l2-device.h> 30#include <media/v4l2-device.h>
31#include <media/v4l2-chip-ident.h>
32#include <media/v4l2-ctrls.h> 31#include <media/v4l2-ctrls.h>
33 32
34#include "adv7343_regs.h" 33#include "adv7343_regs.h"
@@ -311,21 +310,12 @@ static int adv7343_s_ctrl(struct v4l2_ctrl *ctrl)
311 return -EINVAL; 310 return -EINVAL;
312} 311}
313 312
314static int adv7343_g_chip_ident(struct v4l2_subdev *sd,
315 struct v4l2_dbg_chip_ident *chip)
316{
317 struct i2c_client *client = v4l2_get_subdevdata(sd);
318
319 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_ADV7343, 0);
320}
321
322static const struct v4l2_ctrl_ops adv7343_ctrl_ops = { 313static const struct v4l2_ctrl_ops adv7343_ctrl_ops = {
323 .s_ctrl = adv7343_s_ctrl, 314 .s_ctrl = adv7343_s_ctrl,
324}; 315};
325 316
326static const struct v4l2_subdev_core_ops adv7343_core_ops = { 317static const struct v4l2_subdev_core_ops adv7343_core_ops = {
327 .log_status = adv7343_log_status, 318 .log_status = adv7343_log_status,
328 .g_chip_ident = adv7343_g_chip_ident,
329 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls, 319 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls,
330 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, 320 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls,
331 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls, 321 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls,
diff --git a/drivers/media/i2c/adv7393.c b/drivers/media/i2c/adv7393.c
index 3dc6098c7267..558f19154eb9 100644
--- a/drivers/media/i2c/adv7393.c
+++ b/drivers/media/i2c/adv7393.c
@@ -33,7 +33,6 @@
33 33
34#include <media/adv7393.h> 34#include <media/adv7393.h>
35#include <media/v4l2-device.h> 35#include <media/v4l2-device.h>
36#include <media/v4l2-chip-ident.h>
37#include <media/v4l2-ctrls.h> 36#include <media/v4l2-ctrls.h>
38 37
39#include "adv7393_regs.h" 38#include "adv7393_regs.h"
@@ -301,21 +300,12 @@ static int adv7393_s_ctrl(struct v4l2_ctrl *ctrl)
301 return -EINVAL; 300 return -EINVAL;
302} 301}
303 302
304static int adv7393_g_chip_ident(struct v4l2_subdev *sd,
305 struct v4l2_dbg_chip_ident *chip)
306{
307 struct i2c_client *client = v4l2_get_subdevdata(sd);
308
309 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_ADV7393, 0);
310}
311
312static const struct v4l2_ctrl_ops adv7393_ctrl_ops = { 303static const struct v4l2_ctrl_ops adv7393_ctrl_ops = {
313 .s_ctrl = adv7393_s_ctrl, 304 .s_ctrl = adv7393_s_ctrl,
314}; 305};
315 306
316static const struct v4l2_subdev_core_ops adv7393_core_ops = { 307static const struct v4l2_subdev_core_ops adv7393_core_ops = {
317 .log_status = adv7393_log_status, 308 .log_status = adv7393_log_status,
318 .g_chip_ident = adv7393_g_chip_ident,
319 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls, 309 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls,
320 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, 310 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls,
321 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls, 311 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls,
@@ -410,7 +400,7 @@ static int adv7393_probe(struct i2c_client *client,
410 v4l_info(client, "chip found @ 0x%x (%s)\n", 400 v4l_info(client, "chip found @ 0x%x (%s)\n",
411 client->addr << 1, client->adapter->name); 401 client->addr << 1, client->adapter->name);
412 402
413 state = kzalloc(sizeof(struct adv7393_state), GFP_KERNEL); 403 state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL);
414 if (state == NULL) 404 if (state == NULL)
415 return -ENOMEM; 405 return -ENOMEM;
416 406
@@ -444,16 +434,13 @@ static int adv7393_probe(struct i2c_client *client,
444 int err = state->hdl.error; 434 int err = state->hdl.error;
445 435
446 v4l2_ctrl_handler_free(&state->hdl); 436 v4l2_ctrl_handler_free(&state->hdl);
447 kfree(state);
448 return err; 437 return err;
449 } 438 }
450 v4l2_ctrl_handler_setup(&state->hdl); 439 v4l2_ctrl_handler_setup(&state->hdl);
451 440
452 err = adv7393_initialize(&state->sd); 441 err = adv7393_initialize(&state->sd);
453 if (err) { 442 if (err)
454 v4l2_ctrl_handler_free(&state->hdl); 443 v4l2_ctrl_handler_free(&state->hdl);
455 kfree(state);
456 }
457 return err; 444 return err;
458} 445}
459 446
@@ -464,7 +451,6 @@ static int adv7393_remove(struct i2c_client *client)
464 451
465 v4l2_device_unregister_subdev(sd); 452 v4l2_device_unregister_subdev(sd);
466 v4l2_ctrl_handler_free(&state->hdl); 453 v4l2_ctrl_handler_free(&state->hdl);
467 kfree(state);
468 454
469 return 0; 455 return 0;
470} 456}
diff --git a/drivers/media/i2c/adv7604.c b/drivers/media/i2c/adv7604.c
index 31a63c9324fe..1d675b58fd71 100644
--- a/drivers/media/i2c/adv7604.c
+++ b/drivers/media/i2c/adv7604.c
@@ -38,7 +38,6 @@
38#include <linux/v4l2-dv-timings.h> 38#include <linux/v4l2-dv-timings.h>
39#include <media/v4l2-device.h> 39#include <media/v4l2-device.h>
40#include <media/v4l2-ctrls.h> 40#include <media/v4l2-ctrls.h>
41#include <media/v4l2-chip-ident.h>
42#include <media/adv7604.h> 41#include <media/adv7604.h>
43 42
44static int debug; 43static int debug;
@@ -643,12 +642,6 @@ static void adv7604_inv_register(struct v4l2_subdev *sd)
643static int adv7604_g_register(struct v4l2_subdev *sd, 642static int adv7604_g_register(struct v4l2_subdev *sd,
644 struct v4l2_dbg_register *reg) 643 struct v4l2_dbg_register *reg)
645{ 644{
646 struct i2c_client *client = v4l2_get_subdevdata(sd);
647
648 if (!v4l2_chip_match_i2c_client(client, &reg->match))
649 return -EINVAL;
650 if (!capable(CAP_SYS_ADMIN))
651 return -EPERM;
652 reg->size = 1; 645 reg->size = 1;
653 switch (reg->reg >> 8) { 646 switch (reg->reg >> 8) {
654 case 0: 647 case 0:
@@ -701,12 +694,6 @@ static int adv7604_g_register(struct v4l2_subdev *sd,
701static int adv7604_s_register(struct v4l2_subdev *sd, 694static int adv7604_s_register(struct v4l2_subdev *sd,
702 const struct v4l2_dbg_register *reg) 695 const struct v4l2_dbg_register *reg)
703{ 696{
704 struct i2c_client *client = v4l2_get_subdevdata(sd);
705
706 if (!v4l2_chip_match_i2c_client(client, &reg->match))
707 return -EINVAL;
708 if (!capable(CAP_SYS_ADMIN))
709 return -EPERM;
710 switch (reg->reg >> 8) { 697 switch (reg->reg >> 8) {
711 case 0: 698 case 0:
712 io_write(sd, reg->reg & 0xff, reg->val & 0xff); 699 io_write(sd, reg->reg & 0xff, reg->val & 0xff);
@@ -984,14 +971,6 @@ static int adv7604_s_ctrl(struct v4l2_ctrl *ctrl)
984 return -EINVAL; 971 return -EINVAL;
985} 972}
986 973
987static int adv7604_g_chip_ident(struct v4l2_subdev *sd,
988 struct v4l2_dbg_chip_ident *chip)
989{
990 struct i2c_client *client = v4l2_get_subdevdata(sd);
991
992 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_ADV7604, 0);
993}
994
995/* ----------------------------------------------------------------------- */ 974/* ----------------------------------------------------------------------- */
996 975
997static inline bool no_power(struct v4l2_subdev *sd) 976static inline bool no_power(struct v4l2_subdev *sd)
@@ -1787,7 +1766,6 @@ static const struct v4l2_subdev_core_ops adv7604_core_ops = {
1787 .s_ctrl = v4l2_subdev_s_ctrl, 1766 .s_ctrl = v4l2_subdev_s_ctrl,
1788 .queryctrl = v4l2_subdev_queryctrl, 1767 .queryctrl = v4l2_subdev_queryctrl,
1789 .querymenu = v4l2_subdev_querymenu, 1768 .querymenu = v4l2_subdev_querymenu,
1790 .g_chip_ident = adv7604_g_chip_ident,
1791 .interrupt_service_routine = adv7604_isr, 1769 .interrupt_service_routine = adv7604_isr,
1792#ifdef CONFIG_VIDEO_ADV_DEBUG 1770#ifdef CONFIG_VIDEO_ADV_DEBUG
1793 .g_register = adv7604_g_register, 1771 .g_register = adv7604_g_register,
@@ -1968,7 +1946,7 @@ static int adv7604_probe(struct i2c_client *client,
1968 v4l_dbg(1, debug, client, "detecting adv7604 client on address 0x%x\n", 1946 v4l_dbg(1, debug, client, "detecting adv7604 client on address 0x%x\n",
1969 client->addr << 1); 1947 client->addr << 1);
1970 1948
1971 state = kzalloc(sizeof(struct adv7604_state), GFP_KERNEL); 1949 state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL);
1972 if (!state) { 1950 if (!state) {
1973 v4l_err(client, "Could not allocate adv7604_state memory!\n"); 1951 v4l_err(client, "Could not allocate adv7604_state memory!\n");
1974 return -ENOMEM; 1952 return -ENOMEM;
@@ -1977,8 +1955,7 @@ static int adv7604_probe(struct i2c_client *client,
1977 /* platform data */ 1955 /* platform data */
1978 if (!pdata) { 1956 if (!pdata) {
1979 v4l_err(client, "No platform data!\n"); 1957 v4l_err(client, "No platform data!\n");
1980 err = -ENODEV; 1958 return -ENODEV;
1981 goto err_state;
1982 } 1959 }
1983 memcpy(&state->pdata, pdata, sizeof(state->pdata)); 1960 memcpy(&state->pdata, pdata, sizeof(state->pdata));
1984 1961
@@ -1991,8 +1968,7 @@ static int adv7604_probe(struct i2c_client *client,
1991 if (adv_smbus_read_byte_data_check(client, 0xfb, false) != 0x68) { 1968 if (adv_smbus_read_byte_data_check(client, 0xfb, false) != 0x68) {
1992 v4l2_info(sd, "not an adv7604 on address 0x%x\n", 1969 v4l2_info(sd, "not an adv7604 on address 0x%x\n",
1993 client->addr << 1); 1970 client->addr << 1);
1994 err = -ENODEV; 1971 return -ENODEV;
1995 goto err_state;
1996 } 1972 }
1997 1973
1998 /* control handlers */ 1974 /* control handlers */
@@ -2093,8 +2069,6 @@ err_i2c:
2093 adv7604_unregister_clients(state); 2069 adv7604_unregister_clients(state);
2094err_hdl: 2070err_hdl:
2095 v4l2_ctrl_handler_free(hdl); 2071 v4l2_ctrl_handler_free(hdl);
2096err_state:
2097 kfree(state);
2098 return err; 2072 return err;
2099} 2073}
2100 2074
@@ -2111,7 +2085,6 @@ static int adv7604_remove(struct i2c_client *client)
2111 media_entity_cleanup(&sd->entity); 2085 media_entity_cleanup(&sd->entity);
2112 adv7604_unregister_clients(to_state(sd)); 2086 adv7604_unregister_clients(to_state(sd));
2113 v4l2_ctrl_handler_free(sd->ctrl_handler); 2087 v4l2_ctrl_handler_free(sd->ctrl_handler);
2114 kfree(to_state(sd));
2115 return 0; 2088 return 0;
2116} 2089}
2117 2090
diff --git a/drivers/media/i2c/ak881x.c b/drivers/media/i2c/ak881x.c
index fd47465e4f6a..c14e66756b98 100644
--- a/drivers/media/i2c/ak881x.c
+++ b/drivers/media/i2c/ak881x.c
@@ -16,7 +16,6 @@
16#include <linux/module.h> 16#include <linux/module.h>
17 17
18#include <media/ak881x.h> 18#include <media/ak881x.h>
19#include <media/v4l2-chip-ident.h>
20#include <media/v4l2-common.h> 19#include <media/v4l2-common.h>
21#include <media/v4l2-device.h> 20#include <media/v4l2-device.h>
22 21
@@ -33,7 +32,6 @@ struct ak881x {
33 struct v4l2_subdev subdev; 32 struct v4l2_subdev subdev;
34 struct ak881x_pdata *pdata; 33 struct ak881x_pdata *pdata;
35 unsigned int lines; 34 unsigned int lines;
36 int id; /* DEVICE_ID code V4L2_IDENT_AK881X code from v4l2-chip-ident.h */
37 char revision; /* DEVICE_REVISION content */ 35 char revision; /* DEVICE_REVISION content */
38}; 36};
39 37
@@ -62,36 +60,16 @@ static struct ak881x *to_ak881x(const struct i2c_client *client)
62 return container_of(i2c_get_clientdata(client), struct ak881x, subdev); 60 return container_of(i2c_get_clientdata(client), struct ak881x, subdev);
63} 61}
64 62
65static int ak881x_g_chip_ident(struct v4l2_subdev *sd,
66 struct v4l2_dbg_chip_ident *id)
67{
68 struct i2c_client *client = v4l2_get_subdevdata(sd);
69 struct ak881x *ak881x = to_ak881x(client);
70
71 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
72 return -EINVAL;
73
74 if (id->match.addr != client->addr)
75 return -ENODEV;
76
77 id->ident = ak881x->id;
78 id->revision = ak881x->revision;
79
80 return 0;
81}
82
83#ifdef CONFIG_VIDEO_ADV_DEBUG 63#ifdef CONFIG_VIDEO_ADV_DEBUG
84static int ak881x_g_register(struct v4l2_subdev *sd, 64static int ak881x_g_register(struct v4l2_subdev *sd,
85 struct v4l2_dbg_register *reg) 65 struct v4l2_dbg_register *reg)
86{ 66{
87 struct i2c_client *client = v4l2_get_subdevdata(sd); 67 struct i2c_client *client = v4l2_get_subdevdata(sd);
88 68
89 if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0x26) 69 if (reg->reg > 0x26)
90 return -EINVAL; 70 return -EINVAL;
91 71
92 if (reg->match.addr != client->addr) 72 reg->size = 1;
93 return -ENODEV;
94
95 reg->val = reg_read(client, reg->reg); 73 reg->val = reg_read(client, reg->reg);
96 74
97 if (reg->val > 0xffff) 75 if (reg->val > 0xffff)
@@ -105,12 +83,9 @@ static int ak881x_s_register(struct v4l2_subdev *sd,
105{ 83{
106 struct i2c_client *client = v4l2_get_subdevdata(sd); 84 struct i2c_client *client = v4l2_get_subdevdata(sd);
107 85
108 if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0x26) 86 if (reg->reg > 0x26)
109 return -EINVAL; 87 return -EINVAL;
110 88
111 if (reg->match.addr != client->addr)
112 return -ENODEV;
113
114 if (reg_write(client, reg->reg, reg->val) < 0) 89 if (reg_write(client, reg->reg, reg->val) < 0)
115 return -EIO; 90 return -EIO;
116 91
@@ -229,7 +204,6 @@ static int ak881x_s_stream(struct v4l2_subdev *sd, int enable)
229} 204}
230 205
231static struct v4l2_subdev_core_ops ak881x_subdev_core_ops = { 206static struct v4l2_subdev_core_ops ak881x_subdev_core_ops = {
232 .g_chip_ident = ak881x_g_chip_ident,
233#ifdef CONFIG_VIDEO_ADV_DEBUG 207#ifdef CONFIG_VIDEO_ADV_DEBUG
234 .g_register = ak881x_g_register, 208 .g_register = ak881x_g_register,
235 .s_register = ak881x_s_register, 209 .s_register = ak881x_s_register,
@@ -264,7 +238,7 @@ static int ak881x_probe(struct i2c_client *client,
264 return -EIO; 238 return -EIO;
265 } 239 }
266 240
267 ak881x = kzalloc(sizeof(struct ak881x), GFP_KERNEL); 241 ak881x = devm_kzalloc(&client->dev, sizeof(*ak881x), GFP_KERNEL);
268 if (!ak881x) 242 if (!ak881x)
269 return -ENOMEM; 243 return -ENOMEM;
270 244
@@ -274,15 +248,11 @@ static int ak881x_probe(struct i2c_client *client,
274 248
275 switch (data) { 249 switch (data) {
276 case 0x13: 250 case 0x13:
277 ak881x->id = V4L2_IDENT_AK8813;
278 break;
279 case 0x14: 251 case 0x14:
280 ak881x->id = V4L2_IDENT_AK8814;
281 break; 252 break;
282 default: 253 default:
283 dev_err(&client->dev, 254 dev_err(&client->dev,
284 "No ak881x chip detected, register read %x\n", data); 255 "No ak881x chip detected, register read %x\n", data);
285 kfree(ak881x);
286 return -ENODEV; 256 return -ENODEV;
287 } 257 }
288 258
@@ -331,7 +301,6 @@ static int ak881x_remove(struct i2c_client *client)
331 struct ak881x *ak881x = to_ak881x(client); 301 struct ak881x *ak881x = to_ak881x(client);
332 302
333 v4l2_device_unregister_subdev(&ak881x->subdev); 303 v4l2_device_unregister_subdev(&ak881x->subdev);
334 kfree(ak881x);
335 304
336 return 0; 305 return 0;
337} 306}
diff --git a/drivers/media/i2c/as3645a.c b/drivers/media/i2c/as3645a.c
index 58d523f2648f..301084b07887 100644
--- a/drivers/media/i2c/as3645a.c
+++ b/drivers/media/i2c/as3645a.c
@@ -813,7 +813,7 @@ static int as3645a_probe(struct i2c_client *client,
813 if (client->dev.platform_data == NULL) 813 if (client->dev.platform_data == NULL)
814 return -ENODEV; 814 return -ENODEV;
815 815
816 flash = kzalloc(sizeof(*flash), GFP_KERNEL); 816 flash = devm_kzalloc(&client->dev, sizeof(*flash), GFP_KERNEL);
817 if (flash == NULL) 817 if (flash == NULL)
818 return -ENOMEM; 818 return -ENOMEM;
819 819
@@ -838,10 +838,8 @@ static int as3645a_probe(struct i2c_client *client,
838 flash->led_mode = V4L2_FLASH_LED_MODE_NONE; 838 flash->led_mode = V4L2_FLASH_LED_MODE_NONE;
839 839
840done: 840done:
841 if (ret < 0) { 841 if (ret < 0)
842 v4l2_ctrl_handler_free(&flash->ctrls); 842 v4l2_ctrl_handler_free(&flash->ctrls);
843 kfree(flash);
844 }
845 843
846 return ret; 844 return ret;
847} 845}
@@ -855,7 +853,6 @@ static int as3645a_remove(struct i2c_client *client)
855 v4l2_ctrl_handler_free(&flash->ctrls); 853 v4l2_ctrl_handler_free(&flash->ctrls);
856 media_entity_cleanup(&flash->subdev.entity); 854 media_entity_cleanup(&flash->subdev.entity);
857 mutex_destroy(&flash->power_lock); 855 mutex_destroy(&flash->power_lock);
858 kfree(flash);
859 856
860 return 0; 857 return 0;
861} 858}
diff --git a/drivers/media/i2c/bt819.c b/drivers/media/i2c/bt819.c
index 377bf05b1efd..369cf6ff88f7 100644
--- a/drivers/media/i2c/bt819.c
+++ b/drivers/media/i2c/bt819.c
@@ -36,7 +36,6 @@
36#include <linux/videodev2.h> 36#include <linux/videodev2.h>
37#include <linux/slab.h> 37#include <linux/slab.h>
38#include <media/v4l2-device.h> 38#include <media/v4l2-device.h>
39#include <media/v4l2-chip-ident.h>
40#include <media/v4l2-ctrls.h> 39#include <media/v4l2-ctrls.h>
41#include <media/bt819.h> 40#include <media/bt819.h>
42 41
@@ -57,7 +56,6 @@ struct bt819 {
57 unsigned char reg[32]; 56 unsigned char reg[32];
58 57
59 v4l2_std_id norm; 58 v4l2_std_id norm;
60 int ident;
61 int input; 59 int input;
62 int enable; 60 int enable;
63}; 61};
@@ -217,15 +215,17 @@ static int bt819_status(struct v4l2_subdev *sd, u32 *pstatus, v4l2_std_id *pstd)
217 struct bt819 *decoder = to_bt819(sd); 215 struct bt819 *decoder = to_bt819(sd);
218 int status = bt819_read(decoder, 0x00); 216 int status = bt819_read(decoder, 0x00);
219 int res = V4L2_IN_ST_NO_SIGNAL; 217 int res = V4L2_IN_ST_NO_SIGNAL;
220 v4l2_std_id std; 218 v4l2_std_id std = pstd ? *pstd : V4L2_STD_ALL;
221 219
222 if ((status & 0x80)) 220 if ((status & 0x80))
223 res = 0; 221 res = 0;
222 else
223 std = V4L2_STD_UNKNOWN;
224 224
225 if ((status & 0x10)) 225 if ((status & 0x10))
226 std = V4L2_STD_PAL; 226 std &= V4L2_STD_PAL;
227 else 227 else
228 std = V4L2_STD_NTSC; 228 std &= V4L2_STD_NTSC;
229 if (pstd) 229 if (pstd)
230 *pstd = std; 230 *pstd = std;
231 if (pstatus) 231 if (pstatus)
@@ -373,14 +373,6 @@ static int bt819_s_ctrl(struct v4l2_ctrl *ctrl)
373 return 0; 373 return 0;
374} 374}
375 375
376static int bt819_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
377{
378 struct bt819 *decoder = to_bt819(sd);
379 struct i2c_client *client = v4l2_get_subdevdata(sd);
380
381 return v4l2_chip_ident_i2c_client(client, chip, decoder->ident, 0);
382}
383
384/* ----------------------------------------------------------------------- */ 376/* ----------------------------------------------------------------------- */
385 377
386static const struct v4l2_ctrl_ops bt819_ctrl_ops = { 378static const struct v4l2_ctrl_ops bt819_ctrl_ops = {
@@ -388,7 +380,6 @@ static const struct v4l2_ctrl_ops bt819_ctrl_ops = {
388}; 380};
389 381
390static const struct v4l2_subdev_core_ops bt819_core_ops = { 382static const struct v4l2_subdev_core_ops bt819_core_ops = {
391 .g_chip_ident = bt819_g_chip_ident,
392 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls, 383 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls,
393 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, 384 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls,
394 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls, 385 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls,
@@ -425,7 +416,7 @@ static int bt819_probe(struct i2c_client *client,
425 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 416 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
426 return -ENODEV; 417 return -ENODEV;
427 418
428 decoder = kzalloc(sizeof(struct bt819), GFP_KERNEL); 419 decoder = devm_kzalloc(&client->dev, sizeof(*decoder), GFP_KERNEL);
429 if (decoder == NULL) 420 if (decoder == NULL)
430 return -ENOMEM; 421 return -ENOMEM;
431 sd = &decoder->sd; 422 sd = &decoder->sd;
@@ -435,15 +426,12 @@ static int bt819_probe(struct i2c_client *client,
435 switch (ver & 0xf0) { 426 switch (ver & 0xf0) {
436 case 0x70: 427 case 0x70:
437 name = "bt819a"; 428 name = "bt819a";
438 decoder->ident = V4L2_IDENT_BT819A;
439 break; 429 break;
440 case 0x60: 430 case 0x60:
441 name = "bt817a"; 431 name = "bt817a";
442 decoder->ident = V4L2_IDENT_BT817A;
443 break; 432 break;
444 case 0x20: 433 case 0x20:
445 name = "bt815a"; 434 name = "bt815a";
446 decoder->ident = V4L2_IDENT_BT815A;
447 break; 435 break;
448 default: 436 default:
449 v4l2_dbg(1, debug, sd, 437 v4l2_dbg(1, debug, sd,
@@ -476,7 +464,6 @@ static int bt819_probe(struct i2c_client *client,
476 int err = decoder->hdl.error; 464 int err = decoder->hdl.error;
477 465
478 v4l2_ctrl_handler_free(&decoder->hdl); 466 v4l2_ctrl_handler_free(&decoder->hdl);
479 kfree(decoder);
480 return err; 467 return err;
481 } 468 }
482 v4l2_ctrl_handler_setup(&decoder->hdl); 469 v4l2_ctrl_handler_setup(&decoder->hdl);
@@ -490,7 +477,6 @@ static int bt819_remove(struct i2c_client *client)
490 477
491 v4l2_device_unregister_subdev(sd); 478 v4l2_device_unregister_subdev(sd);
492 v4l2_ctrl_handler_free(&decoder->hdl); 479 v4l2_ctrl_handler_free(&decoder->hdl);
493 kfree(decoder);
494 return 0; 480 return 0;
495} 481}
496 482
diff --git a/drivers/media/i2c/bt856.c b/drivers/media/i2c/bt856.c
index 7e5bd365c239..7fc163d0253c 100644
--- a/drivers/media/i2c/bt856.c
+++ b/drivers/media/i2c/bt856.c
@@ -36,7 +36,6 @@
36#include <linux/i2c.h> 36#include <linux/i2c.h>
37#include <linux/videodev2.h> 37#include <linux/videodev2.h>
38#include <media/v4l2-device.h> 38#include <media/v4l2-device.h>
39#include <media/v4l2-chip-ident.h>
40 39
41MODULE_DESCRIPTION("Brooktree-856A video encoder driver"); 40MODULE_DESCRIPTION("Brooktree-856A video encoder driver");
42MODULE_AUTHOR("Mike Bernson & Dave Perks"); 41MODULE_AUTHOR("Mike Bernson & Dave Perks");
@@ -177,17 +176,9 @@ static int bt856_s_routing(struct v4l2_subdev *sd,
177 return 0; 176 return 0;
178} 177}
179 178
180static int bt856_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
181{
182 struct i2c_client *client = v4l2_get_subdevdata(sd);
183
184 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_BT856, 0);
185}
186
187/* ----------------------------------------------------------------------- */ 179/* ----------------------------------------------------------------------- */
188 180
189static const struct v4l2_subdev_core_ops bt856_core_ops = { 181static const struct v4l2_subdev_core_ops bt856_core_ops = {
190 .g_chip_ident = bt856_g_chip_ident,
191 .init = bt856_init, 182 .init = bt856_init,
192}; 183};
193 184
@@ -216,7 +207,7 @@ static int bt856_probe(struct i2c_client *client,
216 v4l_info(client, "chip found @ 0x%x (%s)\n", 207 v4l_info(client, "chip found @ 0x%x (%s)\n",
217 client->addr << 1, client->adapter->name); 208 client->addr << 1, client->adapter->name);
218 209
219 encoder = kzalloc(sizeof(struct bt856), GFP_KERNEL); 210 encoder = devm_kzalloc(&client->dev, sizeof(*encoder), GFP_KERNEL);
220 if (encoder == NULL) 211 if (encoder == NULL)
221 return -ENOMEM; 212 return -ENOMEM;
222 sd = &encoder->sd; 213 sd = &encoder->sd;
@@ -250,7 +241,6 @@ static int bt856_remove(struct i2c_client *client)
250 struct v4l2_subdev *sd = i2c_get_clientdata(client); 241 struct v4l2_subdev *sd = i2c_get_clientdata(client);
251 242
252 v4l2_device_unregister_subdev(sd); 243 v4l2_device_unregister_subdev(sd);
253 kfree(to_bt856(sd));
254 return 0; 244 return 0;
255} 245}
256 246
diff --git a/drivers/media/i2c/bt866.c b/drivers/media/i2c/bt866.c
index 905320b67a1c..a8bf10fc665d 100644
--- a/drivers/media/i2c/bt866.c
+++ b/drivers/media/i2c/bt866.c
@@ -36,7 +36,6 @@
36#include <linux/i2c.h> 36#include <linux/i2c.h>
37#include <linux/videodev2.h> 37#include <linux/videodev2.h>
38#include <media/v4l2-device.h> 38#include <media/v4l2-device.h>
39#include <media/v4l2-chip-ident.h>
40 39
41MODULE_DESCRIPTION("Brooktree-866 video encoder driver"); 40MODULE_DESCRIPTION("Brooktree-866 video encoder driver");
42MODULE_AUTHOR("Mike Bernson & Dave Perks"); 41MODULE_AUTHOR("Mike Bernson & Dave Perks");
@@ -175,26 +174,14 @@ static int bt866_s_routing(struct v4l2_subdev *sd,
175 bt866_write(client, 0xdc, val); 174 bt866_write(client, 0xdc, val);
176#endif 175#endif
177 176
178static int bt866_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
179{
180 struct i2c_client *client = v4l2_get_subdevdata(sd);
181
182 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_BT866, 0);
183}
184
185/* ----------------------------------------------------------------------- */ 177/* ----------------------------------------------------------------------- */
186 178
187static const struct v4l2_subdev_core_ops bt866_core_ops = {
188 .g_chip_ident = bt866_g_chip_ident,
189};
190
191static const struct v4l2_subdev_video_ops bt866_video_ops = { 179static const struct v4l2_subdev_video_ops bt866_video_ops = {
192 .s_std_output = bt866_s_std_output, 180 .s_std_output = bt866_s_std_output,
193 .s_routing = bt866_s_routing, 181 .s_routing = bt866_s_routing,
194}; 182};
195 183
196static const struct v4l2_subdev_ops bt866_ops = { 184static const struct v4l2_subdev_ops bt866_ops = {
197 .core = &bt866_core_ops,
198 .video = &bt866_video_ops, 185 .video = &bt866_video_ops,
199}; 186};
200 187
@@ -207,7 +194,7 @@ static int bt866_probe(struct i2c_client *client,
207 v4l_info(client, "chip found @ 0x%x (%s)\n", 194 v4l_info(client, "chip found @ 0x%x (%s)\n",
208 client->addr << 1, client->adapter->name); 195 client->addr << 1, client->adapter->name);
209 196
210 encoder = kzalloc(sizeof(*encoder), GFP_KERNEL); 197 encoder = devm_kzalloc(&client->dev, sizeof(*encoder), GFP_KERNEL);
211 if (encoder == NULL) 198 if (encoder == NULL)
212 return -ENOMEM; 199 return -ENOMEM;
213 sd = &encoder->sd; 200 sd = &encoder->sd;
@@ -220,7 +207,6 @@ static int bt866_remove(struct i2c_client *client)
220 struct v4l2_subdev *sd = i2c_get_clientdata(client); 207 struct v4l2_subdev *sd = i2c_get_clientdata(client);
221 208
222 v4l2_device_unregister_subdev(sd); 209 v4l2_device_unregister_subdev(sd);
223 kfree(to_bt866(sd));
224 return 0; 210 return 0;
225} 211}
226 212
diff --git a/drivers/media/i2c/cs5345.c b/drivers/media/i2c/cs5345.c
index 1d2f7c8512b5..34b76a9e7515 100644
--- a/drivers/media/i2c/cs5345.c
+++ b/drivers/media/i2c/cs5345.c
@@ -24,7 +24,6 @@
24#include <linux/videodev2.h> 24#include <linux/videodev2.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <media/v4l2-device.h> 26#include <media/v4l2-device.h>
27#include <media/v4l2-chip-ident.h>
28#include <media/v4l2-ctrls.h> 27#include <media/v4l2-ctrls.h>
29 28
30MODULE_DESCRIPTION("i2c device driver for cs5345 Audio ADC"); 29MODULE_DESCRIPTION("i2c device driver for cs5345 Audio ADC");
@@ -99,12 +98,6 @@ static int cs5345_s_ctrl(struct v4l2_ctrl *ctrl)
99#ifdef CONFIG_VIDEO_ADV_DEBUG 98#ifdef CONFIG_VIDEO_ADV_DEBUG
100static int cs5345_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 99static int cs5345_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
101{ 100{
102 struct i2c_client *client = v4l2_get_subdevdata(sd);
103
104 if (!v4l2_chip_match_i2c_client(client, &reg->match))
105 return -EINVAL;
106 if (!capable(CAP_SYS_ADMIN))
107 return -EPERM;
108 reg->size = 1; 101 reg->size = 1;
109 reg->val = cs5345_read(sd, reg->reg & 0x1f); 102 reg->val = cs5345_read(sd, reg->reg & 0x1f);
110 return 0; 103 return 0;
@@ -112,24 +105,11 @@ static int cs5345_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *r
112 105
113static int cs5345_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg) 106static int cs5345_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
114{ 107{
115 struct i2c_client *client = v4l2_get_subdevdata(sd);
116
117 if (!v4l2_chip_match_i2c_client(client, &reg->match))
118 return -EINVAL;
119 if (!capable(CAP_SYS_ADMIN))
120 return -EPERM;
121 cs5345_write(sd, reg->reg & 0x1f, reg->val & 0xff); 108 cs5345_write(sd, reg->reg & 0x1f, reg->val & 0xff);
122 return 0; 109 return 0;
123} 110}
124#endif 111#endif
125 112
126static int cs5345_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
127{
128 struct i2c_client *client = v4l2_get_subdevdata(sd);
129
130 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_CS5345, 0);
131}
132
133static int cs5345_log_status(struct v4l2_subdev *sd) 113static int cs5345_log_status(struct v4l2_subdev *sd)
134{ 114{
135 u8 v = cs5345_read(sd, 0x09) & 7; 115 u8 v = cs5345_read(sd, 0x09) & 7;
@@ -152,7 +132,6 @@ static const struct v4l2_ctrl_ops cs5345_ctrl_ops = {
152 132
153static const struct v4l2_subdev_core_ops cs5345_core_ops = { 133static const struct v4l2_subdev_core_ops cs5345_core_ops = {
154 .log_status = cs5345_log_status, 134 .log_status = cs5345_log_status,
155 .g_chip_ident = cs5345_g_chip_ident,
156 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls, 135 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls,
157 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, 136 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls,
158 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls, 137 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls,
@@ -190,7 +169,7 @@ static int cs5345_probe(struct i2c_client *client,
190 v4l_info(client, "chip found @ 0x%x (%s)\n", 169 v4l_info(client, "chip found @ 0x%x (%s)\n",
191 client->addr << 1, client->adapter->name); 170 client->addr << 1, client->adapter->name);
192 171
193 state = kzalloc(sizeof(struct cs5345_state), GFP_KERNEL); 172 state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL);
194 if (state == NULL) 173 if (state == NULL)
195 return -ENOMEM; 174 return -ENOMEM;
196 sd = &state->sd; 175 sd = &state->sd;
@@ -206,7 +185,6 @@ static int cs5345_probe(struct i2c_client *client,
206 int err = state->hdl.error; 185 int err = state->hdl.error;
207 186
208 v4l2_ctrl_handler_free(&state->hdl); 187 v4l2_ctrl_handler_free(&state->hdl);
209 kfree(state);
210 return err; 188 return err;
211 } 189 }
212 /* set volume/mute */ 190 /* set volume/mute */
@@ -227,7 +205,6 @@ static int cs5345_remove(struct i2c_client *client)
227 205
228 v4l2_device_unregister_subdev(sd); 206 v4l2_device_unregister_subdev(sd);
229 v4l2_ctrl_handler_free(&state->hdl); 207 v4l2_ctrl_handler_free(&state->hdl);
230 kfree(state);
231 return 0; 208 return 0;
232} 209}
233 210
diff --git a/drivers/media/i2c/cs53l32a.c b/drivers/media/i2c/cs53l32a.c
index b293912206eb..27400c16ef9a 100644
--- a/drivers/media/i2c/cs53l32a.c
+++ b/drivers/media/i2c/cs53l32a.c
@@ -28,7 +28,6 @@
28#include <linux/i2c.h> 28#include <linux/i2c.h>
29#include <linux/videodev2.h> 29#include <linux/videodev2.h>
30#include <media/v4l2-device.h> 30#include <media/v4l2-device.h>
31#include <media/v4l2-chip-ident.h>
32#include <media/v4l2-ctrls.h> 31#include <media/v4l2-ctrls.h>
33 32
34MODULE_DESCRIPTION("i2c device driver for cs53l32a Audio ADC"); 33MODULE_DESCRIPTION("i2c device driver for cs53l32a Audio ADC");
@@ -104,14 +103,6 @@ static int cs53l32a_s_ctrl(struct v4l2_ctrl *ctrl)
104 return -EINVAL; 103 return -EINVAL;
105} 104}
106 105
107static int cs53l32a_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
108{
109 struct i2c_client *client = v4l2_get_subdevdata(sd);
110
111 return v4l2_chip_ident_i2c_client(client,
112 chip, V4L2_IDENT_CS53l32A, 0);
113}
114
115static int cs53l32a_log_status(struct v4l2_subdev *sd) 106static int cs53l32a_log_status(struct v4l2_subdev *sd)
116{ 107{
117 struct cs53l32a_state *state = to_state(sd); 108 struct cs53l32a_state *state = to_state(sd);
@@ -130,7 +121,6 @@ static const struct v4l2_ctrl_ops cs53l32a_ctrl_ops = {
130 121
131static const struct v4l2_subdev_core_ops cs53l32a_core_ops = { 122static const struct v4l2_subdev_core_ops cs53l32a_core_ops = {
132 .log_status = cs53l32a_log_status, 123 .log_status = cs53l32a_log_status,
133 .g_chip_ident = cs53l32a_g_chip_ident,
134 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls, 124 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls,
135 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, 125 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls,
136 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls, 126 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls,
@@ -175,7 +165,7 @@ static int cs53l32a_probe(struct i2c_client *client,
175 v4l_info(client, "chip found @ 0x%x (%s)\n", 165 v4l_info(client, "chip found @ 0x%x (%s)\n",
176 client->addr << 1, client->adapter->name); 166 client->addr << 1, client->adapter->name);
177 167
178 state = kzalloc(sizeof(struct cs53l32a_state), GFP_KERNEL); 168 state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL);
179 if (state == NULL) 169 if (state == NULL)
180 return -ENOMEM; 170 return -ENOMEM;
181 sd = &state->sd; 171 sd = &state->sd;
@@ -197,7 +187,6 @@ static int cs53l32a_probe(struct i2c_client *client,
197 int err = state->hdl.error; 187 int err = state->hdl.error;
198 188
199 v4l2_ctrl_handler_free(&state->hdl); 189 v4l2_ctrl_handler_free(&state->hdl);
200 kfree(state);
201 return err; 190 return err;
202 } 191 }
203 192
@@ -228,7 +217,6 @@ static int cs53l32a_remove(struct i2c_client *client)
228 217
229 v4l2_device_unregister_subdev(sd); 218 v4l2_device_unregister_subdev(sd);
230 v4l2_ctrl_handler_free(&state->hdl); 219 v4l2_ctrl_handler_free(&state->hdl);
231 kfree(state);
232 return 0; 220 return 0;
233} 221}
234 222
diff --git a/drivers/media/i2c/cx25840/cx25840-core.c b/drivers/media/i2c/cx25840/cx25840-core.c
index 12fb9b2eb887..2e3771d57354 100644
--- a/drivers/media/i2c/cx25840/cx25840-core.c
+++ b/drivers/media/i2c/cx25840/cx25840-core.c
@@ -45,7 +45,6 @@
45#include <linux/delay.h> 45#include <linux/delay.h>
46#include <linux/math64.h> 46#include <linux/math64.h>
47#include <media/v4l2-common.h> 47#include <media/v4l2-common.h>
48#include <media/v4l2-chip-ident.h>
49#include <media/cx25840.h> 48#include <media/cx25840.h>
50 49
51#include "cx25840-core.h" 50#include "cx25840-core.h"
@@ -498,7 +497,7 @@ static void cx23885_initialize(struct i2c_client *client)
498 497
499 /* Sys PLL */ 498 /* Sys PLL */
500 switch (state->id) { 499 switch (state->id) {
501 case V4L2_IDENT_CX23888_AV: 500 case CX23888_AV:
502 /* 501 /*
503 * 50.0 MHz * (0xb + 0xe8ba26/0x2000000)/4 = 5 * 28.636363 MHz 502 * 50.0 MHz * (0xb + 0xe8ba26/0x2000000)/4 = 5 * 28.636363 MHz
504 * 572.73 MHz before post divide 503 * 572.73 MHz before post divide
@@ -511,7 +510,7 @@ static void cx23885_initialize(struct i2c_client *client)
511 cx25840_write4(client, 0x42c, 0x42600000); 510 cx25840_write4(client, 0x42c, 0x42600000);
512 cx25840_write4(client, 0x44c, 0x161f1000); 511 cx25840_write4(client, 0x44c, 0x161f1000);
513 break; 512 break;
514 case V4L2_IDENT_CX23887_AV: 513 case CX23887_AV:
515 /* 514 /*
516 * 25.0 MHz * (0x16 + 0x1d1744c/0x2000000)/4 = 5 * 28.636363 MHz 515 * 25.0 MHz * (0x16 + 0x1d1744c/0x2000000)/4 = 5 * 28.636363 MHz
517 * 572.73 MHz before post divide 516 * 572.73 MHz before post divide
@@ -519,7 +518,7 @@ static void cx23885_initialize(struct i2c_client *client)
519 cx25840_write4(client, 0x11c, 0x01d1744c); 518 cx25840_write4(client, 0x11c, 0x01d1744c);
520 cx25840_write4(client, 0x118, 0x00000416); 519 cx25840_write4(client, 0x118, 0x00000416);
521 break; 520 break;
522 case V4L2_IDENT_CX23885_AV: 521 case CX23885_AV:
523 default: 522 default:
524 /* 523 /*
525 * 28.636363 MHz * (0x14 + 0x0/0x2000000)/4 = 5 * 28.636363 MHz 524 * 28.636363 MHz * (0x14 + 0x0/0x2000000)/4 = 5 * 28.636363 MHz
@@ -546,7 +545,7 @@ static void cx23885_initialize(struct i2c_client *client)
546 545
547 /* HVR1850 */ 546 /* HVR1850 */
548 switch (state->id) { 547 switch (state->id) {
549 case V4L2_IDENT_CX23888_AV: 548 case CX23888_AV:
550 /* 888/HVR1250 specific */ 549 /* 888/HVR1250 specific */
551 cx25840_write4(client, 0x10c, 0x13333333); 550 cx25840_write4(client, 0x10c, 0x13333333);
552 cx25840_write4(client, 0x108, 0x00000515); 551 cx25840_write4(client, 0x108, 0x00000515);
@@ -570,7 +569,7 @@ static void cx23885_initialize(struct i2c_client *client)
570 * 48 ksps, 16 bits/sample, x16 multiplier = 12.288 MHz 569 * 48 ksps, 16 bits/sample, x16 multiplier = 12.288 MHz
571 */ 570 */
572 switch (state->id) { 571 switch (state->id) {
573 case V4L2_IDENT_CX23888_AV: 572 case CX23888_AV:
574 /* 573 /*
575 * 50.0 MHz * (0x7 + 0x0bedfa4/0x2000000)/3 = 122.88 MHz 574 * 50.0 MHz * (0x7 + 0x0bedfa4/0x2000000)/3 = 122.88 MHz
576 * 368.64 MHz before post divide 575 * 368.64 MHz before post divide
@@ -580,7 +579,7 @@ static void cx23885_initialize(struct i2c_client *client)
580 cx25840_write4(client, 0x114, 0x017dbf48); 579 cx25840_write4(client, 0x114, 0x017dbf48);
581 cx25840_write4(client, 0x110, 0x000a030e); 580 cx25840_write4(client, 0x110, 0x000a030e);
582 break; 581 break;
583 case V4L2_IDENT_CX23887_AV: 582 case CX23887_AV:
584 /* 583 /*
585 * 25.0 MHz * (0xe + 0x17dbf48/0x2000000)/3 = 122.88 MHz 584 * 25.0 MHz * (0xe + 0x17dbf48/0x2000000)/3 = 122.88 MHz
586 * 368.64 MHz before post divide 585 * 368.64 MHz before post divide
@@ -589,7 +588,7 @@ static void cx23885_initialize(struct i2c_client *client)
589 cx25840_write4(client, 0x114, 0x017dbf48); 588 cx25840_write4(client, 0x114, 0x017dbf48);
590 cx25840_write4(client, 0x110, 0x000a030e); 589 cx25840_write4(client, 0x110, 0x000a030e);
591 break; 590 break;
592 case V4L2_IDENT_CX23885_AV: 591 case CX23885_AV:
593 default: 592 default:
594 /* 593 /*
595 * 28.636363 MHz * (0xc + 0x1bf0c9e/0x2000000)/3 = 122.88 MHz 594 * 28.636363 MHz * (0xc + 0x1bf0c9e/0x2000000)/3 = 122.88 MHz
@@ -1662,10 +1661,6 @@ static int cx25840_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *
1662{ 1661{
1663 struct i2c_client *client = v4l2_get_subdevdata(sd); 1662 struct i2c_client *client = v4l2_get_subdevdata(sd);
1664 1663
1665 if (!v4l2_chip_match_i2c_client(client, &reg->match))
1666 return -EINVAL;
1667 if (!capable(CAP_SYS_ADMIN))
1668 return -EPERM;
1669 reg->size = 1; 1664 reg->size = 1;
1670 reg->val = cx25840_read(client, reg->reg & 0x0fff); 1665 reg->val = cx25840_read(client, reg->reg & 0x0fff);
1671 return 0; 1666 return 0;
@@ -1675,10 +1670,6 @@ static int cx25840_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_regi
1675{ 1670{
1676 struct i2c_client *client = v4l2_get_subdevdata(sd); 1671 struct i2c_client *client = v4l2_get_subdevdata(sd);
1677 1672
1678 if (!v4l2_chip_match_i2c_client(client, &reg->match))
1679 return -EINVAL;
1680 if (!capable(CAP_SYS_ADMIN))
1681 return -EPERM;
1682 cx25840_write(client, reg->reg & 0x0fff, reg->val & 0xff); 1673 cx25840_write(client, reg->reg & 0x0fff, reg->val & 0xff);
1683 return 0; 1674 return 0;
1684} 1675}
@@ -1938,14 +1929,6 @@ static int cx25840_reset(struct v4l2_subdev *sd, u32 val)
1938 return 0; 1929 return 0;
1939} 1930}
1940 1931
1941static int cx25840_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
1942{
1943 struct cx25840_state *state = to_state(sd);
1944 struct i2c_client *client = v4l2_get_subdevdata(sd);
1945
1946 return v4l2_chip_ident_i2c_client(client, chip, state->id, state->rev);
1947}
1948
1949static int cx25840_log_status(struct v4l2_subdev *sd) 1932static int cx25840_log_status(struct v4l2_subdev *sd)
1950{ 1933{
1951 struct cx25840_state *state = to_state(sd); 1934 struct cx25840_state *state = to_state(sd);
@@ -5051,7 +5034,6 @@ static const struct v4l2_ctrl_ops cx25840_ctrl_ops = {
5051 5034
5052static const struct v4l2_subdev_core_ops cx25840_core_ops = { 5035static const struct v4l2_subdev_core_ops cx25840_core_ops = {
5053 .log_status = cx25840_log_status, 5036 .log_status = cx25840_log_status,
5054 .g_chip_ident = cx25840_g_chip_ident,
5055 .g_ctrl = v4l2_subdev_g_ctrl, 5037 .g_ctrl = v4l2_subdev_g_ctrl,
5056 .s_ctrl = v4l2_subdev_s_ctrl, 5038 .s_ctrl = v4l2_subdev_s_ctrl,
5057 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls, 5039 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls,
@@ -5128,18 +5110,18 @@ static u32 get_cx2388x_ident(struct i2c_client *client)
5128 ret = cx25840_read4(client, 0x300); 5110 ret = cx25840_read4(client, 0x300);
5129 if (((ret & 0xffff0000) >> 16) == (ret & 0xffff)) { 5111 if (((ret & 0xffff0000) >> 16) == (ret & 0xffff)) {
5130 /* No DIF */ 5112 /* No DIF */
5131 ret = V4L2_IDENT_CX23885_AV; 5113 ret = CX23885_AV;
5132 } else { 5114 } else {
5133 /* CX23887 has a broken DIF, but the registers 5115 /* CX23887 has a broken DIF, but the registers
5134 * appear valid (but unused), good enough to detect. */ 5116 * appear valid (but unused), good enough to detect. */
5135 ret = V4L2_IDENT_CX23887_AV; 5117 ret = CX23887_AV;
5136 } 5118 }
5137 } else if (cx25840_read4(client, 0x300) & 0x0fffffff) { 5119 } else if (cx25840_read4(client, 0x300) & 0x0fffffff) {
5138 /* DIF PLL Freq Word reg exists; chip must be a CX23888 */ 5120 /* DIF PLL Freq Word reg exists; chip must be a CX23888 */
5139 ret = V4L2_IDENT_CX23888_AV; 5121 ret = CX23888_AV;
5140 } else { 5122 } else {
5141 v4l_err(client, "Unable to detect h/w, assuming cx23887\n"); 5123 v4l_err(client, "Unable to detect h/w, assuming cx23887\n");
5142 ret = V4L2_IDENT_CX23887_AV; 5124 ret = CX23887_AV;
5143 } 5125 }
5144 5126
5145 /* Back into digital power down */ 5127 /* Back into digital power down */
@@ -5153,7 +5135,7 @@ static int cx25840_probe(struct i2c_client *client,
5153 struct cx25840_state *state; 5135 struct cx25840_state *state;
5154 struct v4l2_subdev *sd; 5136 struct v4l2_subdev *sd;
5155 int default_volume; 5137 int default_volume;
5156 u32 id = V4L2_IDENT_NONE; 5138 u32 id;
5157 u16 device_id; 5139 u16 device_id;
5158 5140
5159 /* Check if the adapter supports the needed features */ 5141 /* Check if the adapter supports the needed features */
@@ -5169,14 +5151,14 @@ static int cx25840_probe(struct i2c_client *client,
5169 /* The high byte of the device ID should be 5151 /* The high byte of the device ID should be
5170 * 0x83 for the cx2583x and 0x84 for the cx2584x */ 5152 * 0x83 for the cx2583x and 0x84 for the cx2584x */
5171 if ((device_id & 0xff00) == 0x8300) { 5153 if ((device_id & 0xff00) == 0x8300) {
5172 id = V4L2_IDENT_CX25836 + ((device_id >> 4) & 0xf) - 6; 5154 id = CX25836 + ((device_id >> 4) & 0xf) - 6;
5173 } else if ((device_id & 0xff00) == 0x8400) { 5155 } else if ((device_id & 0xff00) == 0x8400) {
5174 id = V4L2_IDENT_CX25840 + ((device_id >> 4) & 0xf); 5156 id = CX25840 + ((device_id >> 4) & 0xf);
5175 } else if (device_id == 0x0000) { 5157 } else if (device_id == 0x0000) {
5176 id = get_cx2388x_ident(client); 5158 id = get_cx2388x_ident(client);
5177 } else if ((device_id & 0xfff0) == 0x5A30) { 5159 } else if ((device_id & 0xfff0) == 0x5A30) {
5178 /* The CX23100 (0x5A3C = 23100) doesn't have an A/V decoder */ 5160 /* The CX23100 (0x5A3C = 23100) doesn't have an A/V decoder */
5179 id = V4L2_IDENT_CX2310X_AV; 5161 id = CX2310X_AV;
5180 } else if ((device_id & 0xff) == (device_id >> 8)) { 5162 } else if ((device_id & 0xff) == (device_id >> 8)) {
5181 v4l_err(client, 5163 v4l_err(client,
5182 "likely a confused/unresponsive cx2388[578] A/V decoder" 5164 "likely a confused/unresponsive cx2388[578] A/V decoder"
@@ -5190,7 +5172,7 @@ static int cx25840_probe(struct i2c_client *client,
5190 return -ENODEV; 5172 return -ENODEV;
5191 } 5173 }
5192 5174
5193 state = kzalloc(sizeof(struct cx25840_state), GFP_KERNEL); 5175 state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL);
5194 if (state == NULL) 5176 if (state == NULL)
5195 return -ENOMEM; 5177 return -ENOMEM;
5196 5178
@@ -5198,26 +5180,26 @@ static int cx25840_probe(struct i2c_client *client,
5198 v4l2_i2c_subdev_init(sd, client, &cx25840_ops); 5180 v4l2_i2c_subdev_init(sd, client, &cx25840_ops);
5199 5181
5200 switch (id) { 5182 switch (id) {
5201 case V4L2_IDENT_CX23885_AV: 5183 case CX23885_AV:
5202 v4l_info(client, "cx23885 A/V decoder found @ 0x%x (%s)\n", 5184 v4l_info(client, "cx23885 A/V decoder found @ 0x%x (%s)\n",
5203 client->addr << 1, client->adapter->name); 5185 client->addr << 1, client->adapter->name);
5204 break; 5186 break;
5205 case V4L2_IDENT_CX23887_AV: 5187 case CX23887_AV:
5206 v4l_info(client, "cx23887 A/V decoder found @ 0x%x (%s)\n", 5188 v4l_info(client, "cx23887 A/V decoder found @ 0x%x (%s)\n",
5207 client->addr << 1, client->adapter->name); 5189 client->addr << 1, client->adapter->name);
5208 break; 5190 break;
5209 case V4L2_IDENT_CX23888_AV: 5191 case CX23888_AV:
5210 v4l_info(client, "cx23888 A/V decoder found @ 0x%x (%s)\n", 5192 v4l_info(client, "cx23888 A/V decoder found @ 0x%x (%s)\n",
5211 client->addr << 1, client->adapter->name); 5193 client->addr << 1, client->adapter->name);
5212 break; 5194 break;
5213 case V4L2_IDENT_CX2310X_AV: 5195 case CX2310X_AV:
5214 v4l_info(client, "cx%d A/V decoder found @ 0x%x (%s)\n", 5196 v4l_info(client, "cx%d A/V decoder found @ 0x%x (%s)\n",
5215 device_id, client->addr << 1, client->adapter->name); 5197 device_id, client->addr << 1, client->adapter->name);
5216 break; 5198 break;
5217 case V4L2_IDENT_CX25840: 5199 case CX25840:
5218 case V4L2_IDENT_CX25841: 5200 case CX25841:
5219 case V4L2_IDENT_CX25842: 5201 case CX25842:
5220 case V4L2_IDENT_CX25843: 5202 case CX25843:
5221 /* Note: revision '(device_id & 0x0f) == 2' was never built. The 5203 /* Note: revision '(device_id & 0x0f) == 2' was never built. The
5222 marking skips from 0x1 == 22 to 0x3 == 23. */ 5204 marking skips from 0x1 == 22 to 0x3 == 23. */
5223 v4l_info(client, "cx25%3x-2%x found @ 0x%x (%s)\n", 5205 v4l_info(client, "cx25%3x-2%x found @ 0x%x (%s)\n",
@@ -5226,8 +5208,8 @@ static int cx25840_probe(struct i2c_client *client,
5226 : (device_id & 0x0f), 5208 : (device_id & 0x0f),
5227 client->addr << 1, client->adapter->name); 5209 client->addr << 1, client->adapter->name);
5228 break; 5210 break;
5229 case V4L2_IDENT_CX25836: 5211 case CX25836:
5230 case V4L2_IDENT_CX25837: 5212 case CX25837:
5231 default: 5213 default:
5232 v4l_info(client, "cx25%3x-%x found @ 0x%x (%s)\n", 5214 v4l_info(client, "cx25%3x-%x found @ 0x%x (%s)\n",
5233 (device_id & 0xfff0) >> 4, device_id & 0x0f, 5215 (device_id & 0xfff0) >> 4, device_id & 0x0f,
@@ -5292,7 +5274,6 @@ static int cx25840_probe(struct i2c_client *client,
5292 int err = state->hdl.error; 5274 int err = state->hdl.error;
5293 5275
5294 v4l2_ctrl_handler_free(&state->hdl); 5276 v4l2_ctrl_handler_free(&state->hdl);
5295 kfree(state);
5296 return err; 5277 return err;
5297 } 5278 }
5298 if (!is_cx2583x(state)) 5279 if (!is_cx2583x(state))
@@ -5317,7 +5298,6 @@ static int cx25840_remove(struct i2c_client *client)
5317 cx25840_ir_remove(sd); 5298 cx25840_ir_remove(sd);
5318 v4l2_device_unregister_subdev(sd); 5299 v4l2_device_unregister_subdev(sd);
5319 v4l2_ctrl_handler_free(&state->hdl); 5300 v4l2_ctrl_handler_free(&state->hdl);
5320 kfree(state);
5321 return 0; 5301 return 0;
5322} 5302}
5323 5303
diff --git a/drivers/media/i2c/cx25840/cx25840-core.h b/drivers/media/i2c/cx25840/cx25840-core.h
index bd4ada28b490..37bc04217c44 100644
--- a/drivers/media/i2c/cx25840/cx25840-core.h
+++ b/drivers/media/i2c/cx25840/cx25840-core.h
@@ -23,12 +23,24 @@
23 23
24#include <linux/videodev2.h> 24#include <linux/videodev2.h>
25#include <media/v4l2-device.h> 25#include <media/v4l2-device.h>
26#include <media/v4l2-chip-ident.h>
27#include <media/v4l2-ctrls.h> 26#include <media/v4l2-ctrls.h>
28#include <linux/i2c.h> 27#include <linux/i2c.h>
29 28
30struct cx25840_ir_state; 29struct cx25840_ir_state;
31 30
31enum cx25840_model {
32 CX23885_AV,
33 CX23887_AV,
34 CX23888_AV,
35 CX2310X_AV,
36 CX25840,
37 CX25841,
38 CX25842,
39 CX25843,
40 CX25836,
41 CX25837,
42};
43
32struct cx25840_state { 44struct cx25840_state {
33 struct i2c_client *c; 45 struct i2c_client *c;
34 struct v4l2_subdev sd; 46 struct v4l2_subdev sd;
@@ -46,7 +58,7 @@ struct cx25840_state {
46 u32 audclk_freq; 58 u32 audclk_freq;
47 int audmode; 59 int audmode;
48 int vbi_line_offset; 60 int vbi_line_offset;
49 u32 id; 61 enum cx25840_model id;
50 u32 rev; 62 u32 rev;
51 int is_initialized; 63 int is_initialized;
52 wait_queue_head_t fw_wait; /* wake up when the fw load is finished */ 64 wait_queue_head_t fw_wait; /* wake up when the fw load is finished */
@@ -66,35 +78,35 @@ static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl)
66 78
67static inline bool is_cx2583x(struct cx25840_state *state) 79static inline bool is_cx2583x(struct cx25840_state *state)
68{ 80{
69 return state->id == V4L2_IDENT_CX25836 || 81 return state->id == CX25836 ||
70 state->id == V4L2_IDENT_CX25837; 82 state->id == CX25837;
71} 83}
72 84
73static inline bool is_cx231xx(struct cx25840_state *state) 85static inline bool is_cx231xx(struct cx25840_state *state)
74{ 86{
75 return state->id == V4L2_IDENT_CX2310X_AV; 87 return state->id == CX2310X_AV;
76} 88}
77 89
78static inline bool is_cx2388x(struct cx25840_state *state) 90static inline bool is_cx2388x(struct cx25840_state *state)
79{ 91{
80 return state->id == V4L2_IDENT_CX23885_AV || 92 return state->id == CX23885_AV ||
81 state->id == V4L2_IDENT_CX23887_AV || 93 state->id == CX23887_AV ||
82 state->id == V4L2_IDENT_CX23888_AV; 94 state->id == CX23888_AV;
83} 95}
84 96
85static inline bool is_cx23885(struct cx25840_state *state) 97static inline bool is_cx23885(struct cx25840_state *state)
86{ 98{
87 return state->id == V4L2_IDENT_CX23885_AV; 99 return state->id == CX23885_AV;
88} 100}
89 101
90static inline bool is_cx23887(struct cx25840_state *state) 102static inline bool is_cx23887(struct cx25840_state *state)
91{ 103{
92 return state->id == V4L2_IDENT_CX23887_AV; 104 return state->id == CX23887_AV;
93} 105}
94 106
95static inline bool is_cx23888(struct cx25840_state *state) 107static inline bool is_cx23888(struct cx25840_state *state)
96{ 108{
97 return state->id == V4L2_IDENT_CX23888_AV; 109 return state->id == CX23888_AV;
98} 110}
99 111
100/* ----------------------------------------------------------------------- */ 112/* ----------------------------------------------------------------------- */
diff --git a/drivers/media/i2c/cx25840/cx25840-ir.c b/drivers/media/i2c/cx25840/cx25840-ir.c
index 9ae977b5983a..e6588ee5bdb0 100644
--- a/drivers/media/i2c/cx25840/cx25840-ir.c
+++ b/drivers/media/i2c/cx25840/cx25840-ir.c
@@ -1230,16 +1230,14 @@ int cx25840_ir_probe(struct v4l2_subdev *sd)
1230 if (!(is_cx23885(state) || is_cx23887(state))) 1230 if (!(is_cx23885(state) || is_cx23887(state)))
1231 return 0; 1231 return 0;
1232 1232
1233 ir_state = kzalloc(sizeof(struct cx25840_ir_state), GFP_KERNEL); 1233 ir_state = devm_kzalloc(&state->c->dev, sizeof(*ir_state), GFP_KERNEL);
1234 if (ir_state == NULL) 1234 if (ir_state == NULL)
1235 return -ENOMEM; 1235 return -ENOMEM;
1236 1236
1237 spin_lock_init(&ir_state->rx_kfifo_lock); 1237 spin_lock_init(&ir_state->rx_kfifo_lock);
1238 if (kfifo_alloc(&ir_state->rx_kfifo, 1238 if (kfifo_alloc(&ir_state->rx_kfifo,
1239 CX25840_IR_RX_KFIFO_SIZE, GFP_KERNEL)) { 1239 CX25840_IR_RX_KFIFO_SIZE, GFP_KERNEL))
1240 kfree(ir_state);
1241 return -ENOMEM; 1240 return -ENOMEM;
1242 }
1243 1241
1244 ir_state->c = state->c; 1242 ir_state->c = state->c;
1245 state->ir_state = ir_state; 1243 state->ir_state = ir_state;
@@ -1273,7 +1271,6 @@ int cx25840_ir_remove(struct v4l2_subdev *sd)
1273 cx25840_ir_tx_shutdown(sd); 1271 cx25840_ir_tx_shutdown(sd);
1274 1272
1275 kfifo_free(&ir_state->rx_kfifo); 1273 kfifo_free(&ir_state->rx_kfifo);
1276 kfree(ir_state);
1277 state->ir_state = NULL; 1274 state->ir_state = NULL;
1278 return 0; 1275 return 0;
1279} 1276}
diff --git a/drivers/media/i2c/ir-kbd-i2c.c b/drivers/media/i2c/ir-kbd-i2c.c
index 8e2f79cb045e..82bf5679da30 100644
--- a/drivers/media/i2c/ir-kbd-i2c.c
+++ b/drivers/media/i2c/ir-kbd-i2c.c
@@ -295,7 +295,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
295 unsigned short addr = client->addr; 295 unsigned short addr = client->addr;
296 int err; 296 int err;
297 297
298 ir = kzalloc(sizeof(struct IR_i2c), GFP_KERNEL); 298 ir = devm_kzalloc(&client->dev, sizeof(*ir), GFP_KERNEL);
299 if (!ir) 299 if (!ir)
300 return -ENOMEM; 300 return -ENOMEM;
301 301
@@ -398,10 +398,8 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
398 * internally 398 * internally
399 */ 399 */
400 rc = rc_allocate_device(); 400 rc = rc_allocate_device();
401 if (!rc) { 401 if (!rc)
402 err = -ENOMEM; 402 return -ENOMEM;
403 goto err_out_free;
404 }
405 } 403 }
406 ir->rc = rc; 404 ir->rc = rc;
407 405
@@ -454,7 +452,6 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
454 err_out_free: 452 err_out_free:
455 /* Only frees rc if it were allocated internally */ 453 /* Only frees rc if it were allocated internally */
456 rc_free_device(rc); 454 rc_free_device(rc);
457 kfree(ir);
458 return err; 455 return err;
459} 456}
460 457
@@ -470,7 +467,6 @@ static int ir_remove(struct i2c_client *client)
470 rc_unregister_device(ir->rc); 467 rc_unregister_device(ir->rc);
471 468
472 /* free memory */ 469 /* free memory */
473 kfree(ir);
474 return 0; 470 return 0;
475} 471}
476 472
diff --git a/drivers/media/i2c/ks0127.c b/drivers/media/i2c/ks0127.c
index 04a6efa37cc3..c3e94ae82c03 100644
--- a/drivers/media/i2c/ks0127.c
+++ b/drivers/media/i2c/ks0127.c
@@ -42,7 +42,6 @@
42#include <linux/videodev2.h> 42#include <linux/videodev2.h>
43#include <linux/slab.h> 43#include <linux/slab.h>
44#include <media/v4l2-device.h> 44#include <media/v4l2-device.h>
45#include <media/v4l2-chip-ident.h>
46#include "ks0127.h" 45#include "ks0127.h"
47 46
48MODULE_DESCRIPTION("KS0127 video decoder driver"); 47MODULE_DESCRIPTION("KS0127 video decoder driver");
@@ -200,7 +199,6 @@ struct adjust {
200struct ks0127 { 199struct ks0127 {
201 struct v4l2_subdev sd; 200 struct v4l2_subdev sd;
202 v4l2_std_id norm; 201 v4l2_std_id norm;
203 int ident;
204 u8 regs[256]; 202 u8 regs[256];
205}; 203};
206 204
@@ -371,12 +369,9 @@ static void ks0127_and_or(struct v4l2_subdev *sd, u8 reg, u8 and_v, u8 or_v)
371****************************************************************************/ 369****************************************************************************/
372static void ks0127_init(struct v4l2_subdev *sd) 370static void ks0127_init(struct v4l2_subdev *sd)
373{ 371{
374 struct ks0127 *ks = to_ks0127(sd);
375 u8 *table = reg_defaults; 372 u8 *table = reg_defaults;
376 int i; 373 int i;
377 374
378 ks->ident = V4L2_IDENT_KS0127;
379
380 v4l2_dbg(1, debug, sd, "reset\n"); 375 v4l2_dbg(1, debug, sd, "reset\n");
381 msleep(1); 376 msleep(1);
382 377
@@ -397,7 +392,6 @@ static void ks0127_init(struct v4l2_subdev *sd)
397 392
398 393
399 if ((ks0127_read(sd, KS_STAT) & 0x80) == 0) { 394 if ((ks0127_read(sd, KS_STAT) & 0x80) == 0) {
400 ks->ident = V4L2_IDENT_KS0122S;
401 v4l2_dbg(1, debug, sd, "ks0122s found\n"); 395 v4l2_dbg(1, debug, sd, "ks0122s found\n");
402 return; 396 return;
403 } 397 }
@@ -408,7 +402,6 @@ static void ks0127_init(struct v4l2_subdev *sd)
408 break; 402 break;
409 403
410 case 9: 404 case 9:
411 ks->ident = V4L2_IDENT_KS0127B;
412 v4l2_dbg(1, debug, sd, "ks0127B Revision A found\n"); 405 v4l2_dbg(1, debug, sd, "ks0127B Revision A found\n");
413 break; 406 break;
414 407
@@ -616,17 +609,24 @@ static int ks0127_status(struct v4l2_subdev *sd, u32 *pstatus, v4l2_std_id *pstd
616{ 609{
617 int stat = V4L2_IN_ST_NO_SIGNAL; 610 int stat = V4L2_IN_ST_NO_SIGNAL;
618 u8 status; 611 u8 status;
619 v4l2_std_id std = V4L2_STD_ALL; 612 v4l2_std_id std = pstd ? *pstd : V4L2_STD_ALL;
620 613
621 status = ks0127_read(sd, KS_STAT); 614 status = ks0127_read(sd, KS_STAT);
622 if (!(status & 0x20)) /* NOVID not set */ 615 if (!(status & 0x20)) /* NOVID not set */
623 stat = 0; 616 stat = 0;
624 if (!(status & 0x01)) /* CLOCK set */ 617 if (!(status & 0x01)) { /* CLOCK set */
625 stat |= V4L2_IN_ST_NO_COLOR; 618 stat |= V4L2_IN_ST_NO_COLOR;
626 if ((status & 0x08)) /* PALDET set */ 619 std = V4L2_STD_UNKNOWN;
627 std = V4L2_STD_PAL; 620 } else {
621 if ((status & 0x08)) /* PALDET set */
622 std &= V4L2_STD_PAL;
623 else
624 std &= V4L2_STD_NTSC;
625 }
626 if ((status & 0x10)) /* PALDET set */
627 std &= V4L2_STD_525_60;
628 else 628 else
629 std = V4L2_STD_NTSC; 629 std &= V4L2_STD_625_50;
630 if (pstd) 630 if (pstd)
631 *pstd = std; 631 *pstd = std;
632 if (pstatus) 632 if (pstatus)
@@ -646,18 +646,9 @@ static int ks0127_g_input_status(struct v4l2_subdev *sd, u32 *status)
646 return ks0127_status(sd, status, NULL); 646 return ks0127_status(sd, status, NULL);
647} 647}
648 648
649static int ks0127_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
650{
651 struct i2c_client *client = v4l2_get_subdevdata(sd);
652 struct ks0127 *ks = to_ks0127(sd);
653
654 return v4l2_chip_ident_i2c_client(client, chip, ks->ident, 0);
655}
656
657/* ----------------------------------------------------------------------- */ 649/* ----------------------------------------------------------------------- */
658 650
659static const struct v4l2_subdev_core_ops ks0127_core_ops = { 651static const struct v4l2_subdev_core_ops ks0127_core_ops = {
660 .g_chip_ident = ks0127_g_chip_ident,
661 .s_std = ks0127_s_std, 652 .s_std = ks0127_s_std,
662}; 653};
663 654
@@ -685,7 +676,7 @@ static int ks0127_probe(struct i2c_client *client, const struct i2c_device_id *i
685 client->addr == (I2C_KS0127_ADDON >> 1) ? "addon" : "on-board", 676 client->addr == (I2C_KS0127_ADDON >> 1) ? "addon" : "on-board",
686 client->addr << 1, client->adapter->name); 677 client->addr << 1, client->adapter->name);
687 678
688 ks = kzalloc(sizeof(*ks), GFP_KERNEL); 679 ks = devm_kzalloc(&client->dev, sizeof(*ks), GFP_KERNEL);
689 if (ks == NULL) 680 if (ks == NULL)
690 return -ENOMEM; 681 return -ENOMEM;
691 sd = &ks->sd; 682 sd = &ks->sd;
@@ -708,7 +699,6 @@ static int ks0127_remove(struct i2c_client *client)
708 v4l2_device_unregister_subdev(sd); 699 v4l2_device_unregister_subdev(sd);
709 ks0127_write(sd, KS_OFMTA, 0x20); /* tristate */ 700 ks0127_write(sd, KS_OFMTA, 0x20); /* tristate */
710 ks0127_write(sd, KS_CMDA, 0x2c | 0x80); /* power down */ 701 ks0127_write(sd, KS_CMDA, 0x2c | 0x80); /* power down */
711 kfree(to_ks0127(sd));
712 return 0; 702 return 0;
713} 703}
714 704
diff --git a/drivers/media/i2c/m52790.c b/drivers/media/i2c/m52790.c
index 39f50fd2b8d2..bf476358704d 100644
--- a/drivers/media/i2c/m52790.c
+++ b/drivers/media/i2c/m52790.c
@@ -29,7 +29,6 @@
29#include <linux/videodev2.h> 29#include <linux/videodev2.h>
30#include <media/m52790.h> 30#include <media/m52790.h>
31#include <media/v4l2-device.h> 31#include <media/v4l2-device.h>
32#include <media/v4l2-chip-ident.h>
33 32
34MODULE_DESCRIPTION("i2c device driver for m52790 A/V switch"); 33MODULE_DESCRIPTION("i2c device driver for m52790 A/V switch");
35MODULE_AUTHOR("Hans Verkuil"); 34MODULE_AUTHOR("Hans Verkuil");
@@ -83,12 +82,7 @@ static int m52790_s_routing(struct v4l2_subdev *sd,
83static int m52790_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 82static int m52790_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
84{ 83{
85 struct m52790_state *state = to_state(sd); 84 struct m52790_state *state = to_state(sd);
86 struct i2c_client *client = v4l2_get_subdevdata(sd);
87 85
88 if (!v4l2_chip_match_i2c_client(client, &reg->match))
89 return -EINVAL;
90 if (!capable(CAP_SYS_ADMIN))
91 return -EPERM;
92 if (reg->reg != 0) 86 if (reg->reg != 0)
93 return -EINVAL; 87 return -EINVAL;
94 reg->size = 1; 88 reg->size = 1;
@@ -99,12 +93,7 @@ static int m52790_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *r
99static int m52790_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg) 93static int m52790_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
100{ 94{
101 struct m52790_state *state = to_state(sd); 95 struct m52790_state *state = to_state(sd);
102 struct i2c_client *client = v4l2_get_subdevdata(sd);
103 96
104 if (!v4l2_chip_match_i2c_client(client, &reg->match))
105 return -EINVAL;
106 if (!capable(CAP_SYS_ADMIN))
107 return -EPERM;
108 if (reg->reg != 0) 97 if (reg->reg != 0)
109 return -EINVAL; 98 return -EINVAL;
110 state->input = reg->val & 0x0303; 99 state->input = reg->val & 0x0303;
@@ -114,13 +103,6 @@ static int m52790_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_regis
114} 103}
115#endif 104#endif
116 105
117static int m52790_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
118{
119 struct i2c_client *client = v4l2_get_subdevdata(sd);
120
121 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_M52790, 0);
122}
123
124static int m52790_log_status(struct v4l2_subdev *sd) 106static int m52790_log_status(struct v4l2_subdev *sd)
125{ 107{
126 struct m52790_state *state = to_state(sd); 108 struct m52790_state *state = to_state(sd);
@@ -136,7 +118,6 @@ static int m52790_log_status(struct v4l2_subdev *sd)
136 118
137static const struct v4l2_subdev_core_ops m52790_core_ops = { 119static const struct v4l2_subdev_core_ops m52790_core_ops = {
138 .log_status = m52790_log_status, 120 .log_status = m52790_log_status,
139 .g_chip_ident = m52790_g_chip_ident,
140#ifdef CONFIG_VIDEO_ADV_DEBUG 121#ifdef CONFIG_VIDEO_ADV_DEBUG
141 .g_register = m52790_g_register, 122 .g_register = m52790_g_register,
142 .s_register = m52790_s_register, 123 .s_register = m52790_s_register,
@@ -174,7 +155,7 @@ static int m52790_probe(struct i2c_client *client,
174 v4l_info(client, "chip found @ 0x%x (%s)\n", 155 v4l_info(client, "chip found @ 0x%x (%s)\n",
175 client->addr << 1, client->adapter->name); 156 client->addr << 1, client->adapter->name);
176 157
177 state = kzalloc(sizeof(struct m52790_state), GFP_KERNEL); 158 state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL);
178 if (state == NULL) 159 if (state == NULL)
179 return -ENOMEM; 160 return -ENOMEM;
180 161
@@ -191,7 +172,6 @@ static int m52790_remove(struct i2c_client *client)
191 struct v4l2_subdev *sd = i2c_get_clientdata(client); 172 struct v4l2_subdev *sd = i2c_get_clientdata(client);
192 173
193 v4l2_device_unregister_subdev(sd); 174 v4l2_device_unregister_subdev(sd);
194 kfree(to_state(sd));
195 return 0; 175 return 0;
196} 176}
197 177
diff --git a/drivers/media/i2c/m5mols/m5mols_core.c b/drivers/media/i2c/m5mols/m5mols_core.c
index 0b899cb6cda1..8d870b7b43ff 100644
--- a/drivers/media/i2c/m5mols/m5mols_core.c
+++ b/drivers/media/i2c/m5mols/m5mols_core.c
@@ -930,6 +930,7 @@ static int m5mols_probe(struct i2c_client *client,
930 const struct i2c_device_id *id) 930 const struct i2c_device_id *id)
931{ 931{
932 const struct m5mols_platform_data *pdata = client->dev.platform_data; 932 const struct m5mols_platform_data *pdata = client->dev.platform_data;
933 unsigned long gpio_flags;
933 struct m5mols_info *info; 934 struct m5mols_info *info;
934 struct v4l2_subdev *sd; 935 struct v4l2_subdev *sd;
935 int ret; 936 int ret;
@@ -949,24 +950,27 @@ static int m5mols_probe(struct i2c_client *client,
949 return -EINVAL; 950 return -EINVAL;
950 } 951 }
951 952
952 info = kzalloc(sizeof(struct m5mols_info), GFP_KERNEL); 953 info = devm_kzalloc(&client->dev, sizeof(*info), GFP_KERNEL);
953 if (!info) 954 if (!info)
954 return -ENOMEM; 955 return -ENOMEM;
955 956
956 info->pdata = pdata; 957 info->pdata = pdata;
957 info->set_power = pdata->set_power; 958 info->set_power = pdata->set_power;
958 959
959 ret = gpio_request(pdata->gpio_reset, "M5MOLS_NRST"); 960 gpio_flags = pdata->reset_polarity
961 ? GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW;
962 ret = devm_gpio_request_one(&client->dev, pdata->gpio_reset, gpio_flags,
963 "M5MOLS_NRST");
960 if (ret) { 964 if (ret) {
961 dev_err(&client->dev, "Failed to request gpio: %d\n", ret); 965 dev_err(&client->dev, "Failed to request gpio: %d\n", ret);
962 goto out_free; 966 return ret;
963 } 967 }
964 gpio_direction_output(pdata->gpio_reset, pdata->reset_polarity);
965 968
966 ret = regulator_bulk_get(&client->dev, ARRAY_SIZE(supplies), supplies); 969 ret = devm_regulator_bulk_get(&client->dev, ARRAY_SIZE(supplies),
970 supplies);
967 if (ret) { 971 if (ret) {
968 dev_err(&client->dev, "Failed to get regulators: %d\n", ret); 972 dev_err(&client->dev, "Failed to get regulators: %d\n", ret);
969 goto out_gpio; 973 return ret;
970 } 974 }
971 975
972 sd = &info->sd; 976 sd = &info->sd;
@@ -978,17 +982,17 @@ static int m5mols_probe(struct i2c_client *client,
978 info->pad.flags = MEDIA_PAD_FL_SOURCE; 982 info->pad.flags = MEDIA_PAD_FL_SOURCE;
979 ret = media_entity_init(&sd->entity, 1, &info->pad, 0); 983 ret = media_entity_init(&sd->entity, 1, &info->pad, 0);
980 if (ret < 0) 984 if (ret < 0)
981 goto out_reg; 985 return ret;
982 sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV_SENSOR; 986 sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV_SENSOR;
983 987
984 init_waitqueue_head(&info->irq_waitq); 988 init_waitqueue_head(&info->irq_waitq);
985 mutex_init(&info->lock); 989 mutex_init(&info->lock);
986 990
987 ret = request_irq(client->irq, m5mols_irq_handler, 991 ret = devm_request_irq(&client->dev, client->irq, m5mols_irq_handler,
988 IRQF_TRIGGER_RISING, MODULE_NAME, sd); 992 IRQF_TRIGGER_RISING, MODULE_NAME, sd);
989 if (ret) { 993 if (ret) {
990 dev_err(&client->dev, "Interrupt request failed: %d\n", ret); 994 dev_err(&client->dev, "Interrupt request failed: %d\n", ret);
991 goto out_me; 995 goto error;
992 } 996 }
993 info->res_type = M5MOLS_RESTYPE_MONITOR; 997 info->res_type = M5MOLS_RESTYPE_MONITOR;
994 info->ffmt[0] = m5mols_default_ffmt[0]; 998 info->ffmt[0] = m5mols_default_ffmt[0];
@@ -996,7 +1000,7 @@ static int m5mols_probe(struct i2c_client *client,
996 1000
997 ret = m5mols_sensor_power(info, true); 1001 ret = m5mols_sensor_power(info, true);
998 if (ret) 1002 if (ret)
999 goto out_irq; 1003 goto error;
1000 1004
1001 ret = m5mols_fw_start(sd); 1005 ret = m5mols_fw_start(sd);
1002 if (!ret) 1006 if (!ret)
@@ -1005,32 +1009,19 @@ static int m5mols_probe(struct i2c_client *client,
1005 ret = m5mols_sensor_power(info, false); 1009 ret = m5mols_sensor_power(info, false);
1006 if (!ret) 1010 if (!ret)
1007 return 0; 1011 return 0;
1008out_irq: 1012error:
1009 free_irq(client->irq, sd);
1010out_me:
1011 media_entity_cleanup(&sd->entity); 1013 media_entity_cleanup(&sd->entity);
1012out_reg:
1013 regulator_bulk_free(ARRAY_SIZE(supplies), supplies);
1014out_gpio:
1015 gpio_free(pdata->gpio_reset);
1016out_free:
1017 kfree(info);
1018 return ret; 1014 return ret;
1019} 1015}
1020 1016
1021static int m5mols_remove(struct i2c_client *client) 1017static int m5mols_remove(struct i2c_client *client)
1022{ 1018{
1023 struct v4l2_subdev *sd = i2c_get_clientdata(client); 1019 struct v4l2_subdev *sd = i2c_get_clientdata(client);
1024 struct m5mols_info *info = to_m5mols(sd);
1025 1020
1026 v4l2_device_unregister_subdev(sd); 1021 v4l2_device_unregister_subdev(sd);
1027 v4l2_ctrl_handler_free(sd->ctrl_handler); 1022 v4l2_ctrl_handler_free(sd->ctrl_handler);
1028 free_irq(client->irq, sd);
1029
1030 regulator_bulk_free(ARRAY_SIZE(supplies), supplies);
1031 gpio_free(info->pdata->gpio_reset);
1032 media_entity_cleanup(&sd->entity); 1023 media_entity_cleanup(&sd->entity);
1033 kfree(info); 1024
1034 return 0; 1025 return 0;
1035} 1026}
1036 1027
diff --git a/drivers/media/i2c/ml86v7667.c b/drivers/media/i2c/ml86v7667.c
new file mode 100644
index 000000000000..efdc873e58d1
--- /dev/null
+++ b/drivers/media/i2c/ml86v7667.c
@@ -0,0 +1,431 @@
1/*
2 * OKI Semiconductor ML86V7667 video decoder driver
3 *
4 * Author: Vladimir Barinov <source@cogentembedded.com>
5 * Copyright (C) 2013 Cogent Embedded, Inc.
6 * Copyright (C) 2013 Renesas Solutions Corp.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 */
13
14#include <linux/init.h>
15#include <linux/module.h>
16#include <linux/i2c.h>
17#include <linux/slab.h>
18#include <linux/videodev2.h>
19#include <media/v4l2-subdev.h>
20#include <media/v4l2-device.h>
21#include <media/v4l2-ioctl.h>
22#include <media/v4l2-ctrls.h>
23
24#define DRV_NAME "ml86v7667"
25
26/* Subaddresses */
27#define MRA_REG 0x00 /* Mode Register A */
28#define MRC_REG 0x02 /* Mode Register C */
29#define LUMC_REG 0x0C /* Luminance Control */
30#define CLC_REG 0x10 /* Contrast level control */
31#define SSEPL_REG 0x11 /* Sync separation level */
32#define CHRCA_REG 0x12 /* Chrominance Control A */
33#define ACCC_REG 0x14 /* ACC Loop filter & Chrominance control */
34#define ACCRC_REG 0x15 /* ACC Reference level control */
35#define HUE_REG 0x16 /* Hue control */
36#define ADC2_REG 0x1F /* ADC Register 2 */
37#define PLLR1_REG 0x20 /* PLL Register 1 */
38#define STATUS_REG 0x2C /* STATUS Register */
39
40/* Mode Register A register bits */
41#define MRA_OUTPUT_MODE_MASK (3 << 6)
42#define MRA_ITUR_BT601 (1 << 6)
43#define MRA_ITUR_BT656 (0 << 6)
44#define MRA_INPUT_MODE_MASK (7 << 3)
45#define MRA_PAL_BT601 (4 << 3)
46#define MRA_NTSC_BT601 (0 << 3)
47#define MRA_REGISTER_MODE (1 << 0)
48
49/* Mode Register C register bits */
50#define MRC_AUTOSELECT (1 << 7)
51
52/* Luminance Control register bits */
53#define LUMC_ONOFF_SHIFT 7
54#define LUMC_ONOFF_MASK (1 << 7)
55
56/* Contrast level control register bits */
57#define CLC_CONTRAST_ONOFF (1 << 7)
58#define CLC_CONTRAST_MASK 0x0F
59
60/* Sync separation level register bits */
61#define SSEPL_LUMINANCE_ONOFF (1 << 7)
62#define SSEPL_LUMINANCE_MASK 0x7F
63
64/* Chrominance Control A register bits */
65#define CHRCA_MODE_SHIFT 6
66#define CHRCA_MODE_MASK (1 << 6)
67
68/* ACC Loop filter & Chrominance control register bits */
69#define ACCC_CHROMA_CR_SHIFT 3
70#define ACCC_CHROMA_CR_MASK (7 << 3)
71#define ACCC_CHROMA_CB_SHIFT 0
72#define ACCC_CHROMA_CB_MASK (7 << 0)
73
74/* ACC Reference level control register bits */
75#define ACCRC_CHROMA_MASK 0xfc
76#define ACCRC_CHROMA_SHIFT 2
77
78/* ADC Register 2 register bits */
79#define ADC2_CLAMP_VOLTAGE_MASK (7 << 1)
80#define ADC2_CLAMP_VOLTAGE(n) ((n & 7) << 1)
81
82/* PLL Register 1 register bits */
83#define PLLR1_FIXED_CLOCK (1 << 7)
84
85/* STATUS Register register bits */
86#define STATUS_HLOCK_DETECT (1 << 3)
87#define STATUS_NTSCPAL (1 << 2)
88
89struct ml86v7667_priv {
90 struct v4l2_subdev sd;
91 struct v4l2_ctrl_handler hdl;
92 v4l2_std_id std;
93};
94
95static inline struct ml86v7667_priv *to_ml86v7667(struct v4l2_subdev *subdev)
96{
97 return container_of(subdev, struct ml86v7667_priv, sd);
98}
99
100static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl)
101{
102 return &container_of(ctrl->handler, struct ml86v7667_priv, hdl)->sd;
103}
104
105static int ml86v7667_mask_set(struct i2c_client *client, const u8 reg,
106 const u8 mask, const u8 data)
107{
108 int val = i2c_smbus_read_byte_data(client, reg);
109 if (val < 0)
110 return val;
111
112 val = (val & ~mask) | (data & mask);
113 return i2c_smbus_write_byte_data(client, reg, val);
114}
115
116static int ml86v7667_s_ctrl(struct v4l2_ctrl *ctrl)
117{
118 struct v4l2_subdev *sd = to_sd(ctrl);
119 struct i2c_client *client = v4l2_get_subdevdata(sd);
120 int ret;
121
122 switch (ctrl->id) {
123 case V4L2_CID_BRIGHTNESS:
124 ret = ml86v7667_mask_set(client, SSEPL_REG,
125 SSEPL_LUMINANCE_MASK, ctrl->val);
126 break;
127 case V4L2_CID_CONTRAST:
128 ret = ml86v7667_mask_set(client, CLC_REG,
129 CLC_CONTRAST_MASK, ctrl->val);
130 break;
131 case V4L2_CID_CHROMA_GAIN:
132 ret = ml86v7667_mask_set(client, ACCRC_REG, ACCRC_CHROMA_MASK,
133 ctrl->val << ACCRC_CHROMA_SHIFT);
134 break;
135 case V4L2_CID_HUE:
136 ret = ml86v7667_mask_set(client, HUE_REG, ~0, ctrl->val);
137 break;
138 case V4L2_CID_RED_BALANCE:
139 ret = ml86v7667_mask_set(client, ACCC_REG,
140 ACCC_CHROMA_CR_MASK,
141 ctrl->val << ACCC_CHROMA_CR_SHIFT);
142 break;
143 case V4L2_CID_BLUE_BALANCE:
144 ret = ml86v7667_mask_set(client, ACCC_REG,
145 ACCC_CHROMA_CB_MASK,
146 ctrl->val << ACCC_CHROMA_CB_SHIFT);
147 break;
148 case V4L2_CID_SHARPNESS:
149 ret = ml86v7667_mask_set(client, LUMC_REG,
150 LUMC_ONOFF_MASK,
151 ctrl->val << LUMC_ONOFF_SHIFT);
152 break;
153 case V4L2_CID_COLOR_KILLER:
154 ret = ml86v7667_mask_set(client, CHRCA_REG,
155 CHRCA_MODE_MASK,
156 ctrl->val << CHRCA_MODE_SHIFT);
157 break;
158 }
159
160 return 0;
161}
162
163static int ml86v7667_querystd(struct v4l2_subdev *sd, v4l2_std_id *std)
164{
165 struct i2c_client *client = v4l2_get_subdevdata(sd);
166 int status;
167
168 status = i2c_smbus_read_byte_data(client, STATUS_REG);
169 if (status < 0)
170 return status;
171
172 if (status & STATUS_HLOCK_DETECT)
173 *std &= status & STATUS_NTSCPAL ? V4L2_STD_625_50 : V4L2_STD_525_60;
174 else
175 *std = V4L2_STD_UNKNOWN;
176
177 return 0;
178}
179
180static int ml86v7667_g_input_status(struct v4l2_subdev *sd, u32 *status)
181{
182 struct i2c_client *client = v4l2_get_subdevdata(sd);
183 int status_reg;
184
185 status_reg = i2c_smbus_read_byte_data(client, STATUS_REG);
186 if (status_reg < 0)
187 return status_reg;
188
189 *status = status_reg & STATUS_HLOCK_DETECT ? 0 : V4L2_IN_ST_NO_SIGNAL;
190
191 return 0;
192}
193
194static int ml86v7667_enum_mbus_fmt(struct v4l2_subdev *sd, unsigned int index,
195 enum v4l2_mbus_pixelcode *code)
196{
197 if (index > 0)
198 return -EINVAL;
199
200 *code = V4L2_MBUS_FMT_YUYV8_2X8;
201
202 return 0;
203}
204
205static int ml86v7667_mbus_fmt(struct v4l2_subdev *sd,
206 struct v4l2_mbus_framefmt *fmt)
207{
208 struct ml86v7667_priv *priv = to_ml86v7667(sd);
209
210 fmt->code = V4L2_MBUS_FMT_YUYV8_2X8;
211 fmt->colorspace = V4L2_COLORSPACE_SMPTE170M;
212 fmt->field = V4L2_FIELD_INTERLACED;
213 fmt->width = 720;
214 fmt->height = priv->std & V4L2_STD_525_60 ? 480 : 576;
215
216 return 0;
217}
218
219static int ml86v7667_g_mbus_config(struct v4l2_subdev *sd,
220 struct v4l2_mbus_config *cfg)
221{
222 cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_PCLK_SAMPLE_RISING |
223 V4L2_MBUS_DATA_ACTIVE_HIGH;
224 cfg->type = V4L2_MBUS_BT656;
225
226 return 0;
227}
228
229static int ml86v7667_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
230{
231 struct ml86v7667_priv *priv = to_ml86v7667(sd);
232 struct i2c_client *client = v4l2_get_subdevdata(&priv->sd);
233 int ret;
234 u8 mode;
235
236 /* PAL/NTSC ITU-R BT.601 input mode */
237 mode = std & V4L2_STD_525_60 ? MRA_NTSC_BT601 : MRA_PAL_BT601;
238 ret = ml86v7667_mask_set(client, MRA_REG, MRA_INPUT_MODE_MASK, mode);
239 if (ret < 0)
240 return ret;
241
242 priv->std = std;
243
244 return 0;
245}
246
247#ifdef CONFIG_VIDEO_ADV_DEBUG
248static int ml86v7667_g_register(struct v4l2_subdev *sd,
249 struct v4l2_dbg_register *reg)
250{
251 struct i2c_client *client = v4l2_get_subdevdata(sd);
252 int ret;
253
254 ret = i2c_smbus_read_byte_data(client, (u8)reg->reg);
255 if (ret < 0)
256 return ret;
257
258 reg->val = ret;
259 reg->size = sizeof(u8);
260
261 return 0;
262}
263
264static int ml86v7667_s_register(struct v4l2_subdev *sd,
265 const struct v4l2_dbg_register *reg)
266{
267 struct i2c_client *client = v4l2_get_subdevdata(sd);
268
269 return i2c_smbus_write_byte_data(client, (u8)reg->reg, (u8)reg->val);
270}
271#endif
272
273static const struct v4l2_ctrl_ops ml86v7667_ctrl_ops = {
274 .s_ctrl = ml86v7667_s_ctrl,
275};
276
277static struct v4l2_subdev_video_ops ml86v7667_subdev_video_ops = {
278 .querystd = ml86v7667_querystd,
279 .g_input_status = ml86v7667_g_input_status,
280 .enum_mbus_fmt = ml86v7667_enum_mbus_fmt,
281 .try_mbus_fmt = ml86v7667_mbus_fmt,
282 .g_mbus_fmt = ml86v7667_mbus_fmt,
283 .s_mbus_fmt = ml86v7667_mbus_fmt,
284 .g_mbus_config = ml86v7667_g_mbus_config,
285};
286
287static struct v4l2_subdev_core_ops ml86v7667_subdev_core_ops = {
288 .s_std = ml86v7667_s_std,
289#ifdef CONFIG_VIDEO_ADV_DEBUG
290 .g_register = ml86v7667_g_register,
291 .s_register = ml86v7667_s_register,
292#endif
293};
294
295static struct v4l2_subdev_ops ml86v7667_subdev_ops = {
296 .core = &ml86v7667_subdev_core_ops,
297 .video = &ml86v7667_subdev_video_ops,
298};
299
300static int ml86v7667_init(struct ml86v7667_priv *priv)
301{
302 struct i2c_client *client = v4l2_get_subdevdata(&priv->sd);
303 int val;
304 int ret;
305
306 /* BT.656-4 output mode, register mode */
307 ret = ml86v7667_mask_set(client, MRA_REG,
308 MRA_OUTPUT_MODE_MASK | MRA_REGISTER_MODE,
309 MRA_ITUR_BT656 | MRA_REGISTER_MODE);
310
311 /* PLL circuit fixed clock, 32MHz */
312 ret |= ml86v7667_mask_set(client, PLLR1_REG, PLLR1_FIXED_CLOCK,
313 PLLR1_FIXED_CLOCK);
314
315 /* ADC2 clamping voltage maximum */
316 ret |= ml86v7667_mask_set(client, ADC2_REG, ADC2_CLAMP_VOLTAGE_MASK,
317 ADC2_CLAMP_VOLTAGE(7));
318
319 /* enable luminance function */
320 ret |= ml86v7667_mask_set(client, SSEPL_REG, SSEPL_LUMINANCE_ONOFF,
321 SSEPL_LUMINANCE_ONOFF);
322
323 /* enable contrast function */
324 ret |= ml86v7667_mask_set(client, CLC_REG, CLC_CONTRAST_ONOFF, 0);
325
326 /*
327 * PAL/NTSC autodetection is enabled after reset,
328 * set the autodetected std in manual std mode and
329 * disable autodetection
330 */
331 val = i2c_smbus_read_byte_data(client, STATUS_REG);
332 if (val < 0)
333 return val;
334
335 priv->std = val & STATUS_NTSCPAL ? V4L2_STD_625_50 : V4L2_STD_525_60;
336 ret |= ml86v7667_mask_set(client, MRC_REG, MRC_AUTOSELECT, 0);
337
338 val = priv->std & V4L2_STD_525_60 ? MRA_NTSC_BT601 : MRA_PAL_BT601;
339 ret |= ml86v7667_mask_set(client, MRA_REG, MRA_INPUT_MODE_MASK, val);
340
341 return ret;
342}
343
344static int ml86v7667_probe(struct i2c_client *client,
345 const struct i2c_device_id *did)
346{
347 struct ml86v7667_priv *priv;
348 int ret;
349
350 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
351 return -EIO;
352
353 priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL);
354 if (!priv)
355 return -ENOMEM;
356
357 v4l2_i2c_subdev_init(&priv->sd, client, &ml86v7667_subdev_ops);
358
359 v4l2_ctrl_handler_init(&priv->hdl, 8);
360 v4l2_ctrl_new_std(&priv->hdl, &ml86v7667_ctrl_ops,
361 V4L2_CID_BRIGHTNESS, -64, 63, 1, 0);
362 v4l2_ctrl_new_std(&priv->hdl, &ml86v7667_ctrl_ops,
363 V4L2_CID_CONTRAST, -8, 7, 1, 0);
364 v4l2_ctrl_new_std(&priv->hdl, &ml86v7667_ctrl_ops,
365 V4L2_CID_CHROMA_GAIN, -32, 31, 1, 0);
366 v4l2_ctrl_new_std(&priv->hdl, &ml86v7667_ctrl_ops,
367 V4L2_CID_HUE, -128, 127, 1, 0);
368 v4l2_ctrl_new_std(&priv->hdl, &ml86v7667_ctrl_ops,
369 V4L2_CID_RED_BALANCE, -4, 3, 1, 0);
370 v4l2_ctrl_new_std(&priv->hdl, &ml86v7667_ctrl_ops,
371 V4L2_CID_BLUE_BALANCE, -4, 3, 1, 0);
372 v4l2_ctrl_new_std(&priv->hdl, &ml86v7667_ctrl_ops,
373 V4L2_CID_SHARPNESS, 0, 1, 1, 0);
374 v4l2_ctrl_new_std(&priv->hdl, &ml86v7667_ctrl_ops,
375 V4L2_CID_COLOR_KILLER, 0, 1, 1, 0);
376 priv->sd.ctrl_handler = &priv->hdl;
377
378 ret = priv->hdl.error;
379 if (ret)
380 goto cleanup;
381
382 v4l2_ctrl_handler_setup(&priv->hdl);
383
384 ret = ml86v7667_init(priv);
385 if (ret)
386 goto cleanup;
387
388 v4l_info(client, "chip found @ 0x%02x (%s)\n",
389 client->addr, client->adapter->name);
390 return 0;
391
392cleanup:
393 v4l2_ctrl_handler_free(&priv->hdl);
394 v4l2_device_unregister_subdev(&priv->sd);
395 v4l_err(client, "failed to probe @ 0x%02x (%s)\n",
396 client->addr, client->adapter->name);
397 return ret;
398}
399
400static int ml86v7667_remove(struct i2c_client *client)
401{
402 struct v4l2_subdev *sd = i2c_get_clientdata(client);
403 struct ml86v7667_priv *priv = to_ml86v7667(sd);
404
405 v4l2_ctrl_handler_free(&priv->hdl);
406 v4l2_device_unregister_subdev(&priv->sd);
407
408 return 0;
409}
410
411static const struct i2c_device_id ml86v7667_id[] = {
412 {DRV_NAME, 0},
413 {},
414};
415MODULE_DEVICE_TABLE(i2c, ml86v7667_id);
416
417static struct i2c_driver ml86v7667_i2c_driver = {
418 .driver = {
419 .name = DRV_NAME,
420 .owner = THIS_MODULE,
421 },
422 .probe = ml86v7667_probe,
423 .remove = ml86v7667_remove,
424 .id_table = ml86v7667_id,
425};
426
427module_i2c_driver(ml86v7667_i2c_driver);
428
429MODULE_DESCRIPTION("OKI Semiconductor ML86V7667 video decoder driver");
430MODULE_AUTHOR("Vladimir Barinov");
431MODULE_LICENSE("GPL");
diff --git a/drivers/media/i2c/msp3400-driver.c b/drivers/media/i2c/msp3400-driver.c
index 54a9dd394f45..8190fec68080 100644
--- a/drivers/media/i2c/msp3400-driver.c
+++ b/drivers/media/i2c/msp3400-driver.c
@@ -570,15 +570,6 @@ static int msp_s_i2s_clock_freq(struct v4l2_subdev *sd, u32 freq)
570 return 0; 570 return 0;
571} 571}
572 572
573static int msp_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
574{
575 struct msp_state *state = to_state(sd);
576 struct i2c_client *client = v4l2_get_subdevdata(sd);
577
578 return v4l2_chip_ident_i2c_client(client, chip, state->ident,
579 (state->rev1 << 16) | state->rev2);
580}
581
582static int msp_log_status(struct v4l2_subdev *sd) 573static int msp_log_status(struct v4l2_subdev *sd)
583{ 574{
584 struct msp_state *state = to_state(sd); 575 struct msp_state *state = to_state(sd);
@@ -651,7 +642,6 @@ static const struct v4l2_ctrl_ops msp_ctrl_ops = {
651 642
652static const struct v4l2_subdev_core_ops msp_core_ops = { 643static const struct v4l2_subdev_core_ops msp_core_ops = {
653 .log_status = msp_log_status, 644 .log_status = msp_log_status,
654 .g_chip_ident = msp_g_chip_ident,
655 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls, 645 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls,
656 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, 646 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls,
657 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls, 647 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls,
@@ -707,7 +697,7 @@ static int msp_probe(struct i2c_client *client, const struct i2c_device_id *id)
707 return -ENODEV; 697 return -ENODEV;
708 } 698 }
709 699
710 state = kzalloc(sizeof(*state), GFP_KERNEL); 700 state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL);
711 if (!state) 701 if (!state)
712 return -ENOMEM; 702 return -ENOMEM;
713 703
@@ -732,7 +722,6 @@ static int msp_probe(struct i2c_client *client, const struct i2c_device_id *id)
732 if (state->rev1 == -1 || (state->rev1 == 0 && state->rev2 == 0)) { 722 if (state->rev1 == -1 || (state->rev1 == 0 && state->rev2 == 0)) {
733 v4l_dbg(1, msp_debug, client, 723 v4l_dbg(1, msp_debug, client,
734 "not an msp3400 (cannot read chip version)\n"); 724 "not an msp3400 (cannot read chip version)\n");
735 kfree(state);
736 return -ENODEV; 725 return -ENODEV;
737 } 726 }
738 727
@@ -827,7 +816,6 @@ static int msp_probe(struct i2c_client *client, const struct i2c_device_id *id)
827 int err = hdl->error; 816 int err = hdl->error;
828 817
829 v4l2_ctrl_handler_free(hdl); 818 v4l2_ctrl_handler_free(hdl);
830 kfree(state);
831 return err; 819 return err;
832 } 820 }
833 821
@@ -889,7 +877,6 @@ static int msp_remove(struct i2c_client *client)
889 msp_reset(client); 877 msp_reset(client);
890 878
891 v4l2_ctrl_handler_free(&state->hdl); 879 v4l2_ctrl_handler_free(&state->hdl);
892 kfree(state);
893 return 0; 880 return 0;
894} 881}
895 882
diff --git a/drivers/media/i2c/mt9m032.c b/drivers/media/i2c/mt9m032.c
index 8edb3d8f7b90..846b15f0bf64 100644
--- a/drivers/media/i2c/mt9m032.c
+++ b/drivers/media/i2c/mt9m032.c
@@ -554,10 +554,8 @@ static int mt9m032_g_register(struct v4l2_subdev *sd,
554 struct i2c_client *client = v4l2_get_subdevdata(&sensor->subdev); 554 struct i2c_client *client = v4l2_get_subdevdata(&sensor->subdev);
555 int val; 555 int val;
556 556
557 if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff) 557 if (reg->reg > 0xff)
558 return -EINVAL; 558 return -EINVAL;
559 if (reg->match.addr != client->addr)
560 return -ENODEV;
561 559
562 val = mt9m032_read(client, reg->reg); 560 val = mt9m032_read(client, reg->reg);
563 if (val < 0) 561 if (val < 0)
@@ -575,12 +573,9 @@ static int mt9m032_s_register(struct v4l2_subdev *sd,
575 struct mt9m032 *sensor = to_mt9m032(sd); 573 struct mt9m032 *sensor = to_mt9m032(sd);
576 struct i2c_client *client = v4l2_get_subdevdata(&sensor->subdev); 574 struct i2c_client *client = v4l2_get_subdevdata(&sensor->subdev);
577 575
578 if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff) 576 if (reg->reg > 0xff)
579 return -EINVAL; 577 return -EINVAL;
580 578
581 if (reg->match.addr != client->addr)
582 return -ENODEV;
583
584 return mt9m032_write(client, reg->reg, reg->val); 579 return mt9m032_write(client, reg->reg, reg->val);
585} 580}
586#endif 581#endif
@@ -730,7 +725,7 @@ static int mt9m032_probe(struct i2c_client *client,
730 if (!client->dev.platform_data) 725 if (!client->dev.platform_data)
731 return -ENODEV; 726 return -ENODEV;
732 727
733 sensor = kzalloc(sizeof(*sensor), GFP_KERNEL); 728 sensor = devm_kzalloc(&client->dev, sizeof(*sensor), GFP_KERNEL);
734 if (sensor == NULL) 729 if (sensor == NULL)
735 return -ENOMEM; 730 return -ENOMEM;
736 731
@@ -860,7 +855,6 @@ error_ctrl:
860 v4l2_ctrl_handler_free(&sensor->ctrls); 855 v4l2_ctrl_handler_free(&sensor->ctrls);
861error_sensor: 856error_sensor:
862 mutex_destroy(&sensor->lock); 857 mutex_destroy(&sensor->lock);
863 kfree(sensor);
864 return ret; 858 return ret;
865} 859}
866 860
@@ -873,7 +867,6 @@ static int mt9m032_remove(struct i2c_client *client)
873 v4l2_ctrl_handler_free(&sensor->ctrls); 867 v4l2_ctrl_handler_free(&sensor->ctrls);
874 media_entity_cleanup(&subdev->entity); 868 media_entity_cleanup(&subdev->entity);
875 mutex_destroy(&sensor->lock); 869 mutex_destroy(&sensor->lock);
876 kfree(sensor);
877 return 0; 870 return 0;
878} 871}
879 872
diff --git a/drivers/media/i2c/mt9p031.c b/drivers/media/i2c/mt9p031.c
index 28cf95b37285..4734836fe5a4 100644
--- a/drivers/media/i2c/mt9p031.c
+++ b/drivers/media/i2c/mt9p031.c
@@ -16,18 +16,19 @@
16#include <linux/delay.h> 16#include <linux/delay.h>
17#include <linux/device.h> 17#include <linux/device.h>
18#include <linux/gpio.h> 18#include <linux/gpio.h>
19#include <linux/module.h>
20#include <linux/i2c.h> 19#include <linux/i2c.h>
21#include <linux/log2.h> 20#include <linux/log2.h>
21#include <linux/module.h>
22#include <linux/of_gpio.h>
22#include <linux/pm.h> 23#include <linux/pm.h>
23#include <linux/regulator/consumer.h> 24#include <linux/regulator/consumer.h>
24#include <linux/slab.h> 25#include <linux/slab.h>
25#include <linux/videodev2.h> 26#include <linux/videodev2.h>
26 27
27#include <media/mt9p031.h> 28#include <media/mt9p031.h>
28#include <media/v4l2-chip-ident.h>
29#include <media/v4l2-ctrls.h> 29#include <media/v4l2-ctrls.h>
30#include <media/v4l2-device.h> 30#include <media/v4l2-device.h>
31#include <media/v4l2-of.h>
31#include <media/v4l2-subdev.h> 32#include <media/v4l2-subdev.h>
32 33
33#include "aptina-pll.h" 34#include "aptina-pll.h"
@@ -124,9 +125,7 @@ struct mt9p031 {
124 int power_count; 125 int power_count;
125 126
126 struct clk *clk; 127 struct clk *clk;
127 struct regulator *vaa; 128 struct regulator_bulk_data regulators[3];
128 struct regulator *vdd;
129 struct regulator *vdd_io;
130 129
131 enum mt9p031_model model; 130 enum mt9p031_model model;
132 struct aptina_pll pll; 131 struct aptina_pll pll;
@@ -271,23 +270,26 @@ static inline int mt9p031_pll_disable(struct mt9p031 *mt9p031)
271 270
272static int mt9p031_power_on(struct mt9p031 *mt9p031) 271static int mt9p031_power_on(struct mt9p031 *mt9p031)
273{ 272{
273 int ret;
274
274 /* Ensure RESET_BAR is low */ 275 /* Ensure RESET_BAR is low */
275 if (mt9p031->reset != -1) { 276 if (gpio_is_valid(mt9p031->reset)) {
276 gpio_set_value(mt9p031->reset, 0); 277 gpio_set_value(mt9p031->reset, 0);
277 usleep_range(1000, 2000); 278 usleep_range(1000, 2000);
278 } 279 }
279 280
280 /* Bring up the supplies */ 281 /* Bring up the supplies */
281 regulator_enable(mt9p031->vdd); 282 ret = regulator_bulk_enable(ARRAY_SIZE(mt9p031->regulators),
282 regulator_enable(mt9p031->vdd_io); 283 mt9p031->regulators);
283 regulator_enable(mt9p031->vaa); 284 if (ret < 0)
285 return ret;
284 286
285 /* Emable clock */ 287 /* Emable clock */
286 if (mt9p031->clk) 288 if (mt9p031->clk)
287 clk_prepare_enable(mt9p031->clk); 289 clk_prepare_enable(mt9p031->clk);
288 290
289 /* Now RESET_BAR must be high */ 291 /* Now RESET_BAR must be high */
290 if (mt9p031->reset != -1) { 292 if (gpio_is_valid(mt9p031->reset)) {
291 gpio_set_value(mt9p031->reset, 1); 293 gpio_set_value(mt9p031->reset, 1);
292 usleep_range(1000, 2000); 294 usleep_range(1000, 2000);
293 } 295 }
@@ -297,14 +299,13 @@ static int mt9p031_power_on(struct mt9p031 *mt9p031)
297 299
298static void mt9p031_power_off(struct mt9p031 *mt9p031) 300static void mt9p031_power_off(struct mt9p031 *mt9p031)
299{ 301{
300 if (mt9p031->reset != -1) { 302 if (gpio_is_valid(mt9p031->reset)) {
301 gpio_set_value(mt9p031->reset, 0); 303 gpio_set_value(mt9p031->reset, 0);
302 usleep_range(1000, 2000); 304 usleep_range(1000, 2000);
303 } 305 }
304 306
305 regulator_disable(mt9p031->vaa); 307 regulator_bulk_disable(ARRAY_SIZE(mt9p031->regulators),
306 regulator_disable(mt9p031->vdd_io); 308 mt9p031->regulators);
307 regulator_disable(mt9p031->vdd);
308 309
309 if (mt9p031->clk) 310 if (mt9p031->clk)
310 clk_disable_unprepare(mt9p031->clk); 311 clk_disable_unprepare(mt9p031->clk);
@@ -849,18 +850,18 @@ static int mt9p031_registered(struct v4l2_subdev *subdev)
849 850
850 /* Read out the chip version register */ 851 /* Read out the chip version register */
851 data = mt9p031_read(client, MT9P031_CHIP_VERSION); 852 data = mt9p031_read(client, MT9P031_CHIP_VERSION);
853 mt9p031_power_off(mt9p031);
854
852 if (data != MT9P031_CHIP_VERSION_VALUE) { 855 if (data != MT9P031_CHIP_VERSION_VALUE) {
853 dev_err(&client->dev, "MT9P031 not detected, wrong version " 856 dev_err(&client->dev, "MT9P031 not detected, wrong version "
854 "0x%04x\n", data); 857 "0x%04x\n", data);
855 return -ENODEV; 858 return -ENODEV;
856 } 859 }
857 860
858 mt9p031_power_off(mt9p031);
859
860 dev_info(&client->dev, "MT9P031 detected at address 0x%02x\n", 861 dev_info(&client->dev, "MT9P031 detected at address 0x%02x\n",
861 client->addr); 862 client->addr);
862 863
863 return ret; 864 return 0;
864} 865}
865 866
866static int mt9p031_open(struct v4l2_subdev *subdev, struct v4l2_subdev_fh *fh) 867static int mt9p031_open(struct v4l2_subdev *subdev, struct v4l2_subdev_fh *fh)
@@ -928,10 +929,36 @@ static const struct v4l2_subdev_internal_ops mt9p031_subdev_internal_ops = {
928 * Driver initialization and probing 929 * Driver initialization and probing
929 */ 930 */
930 931
932static struct mt9p031_platform_data *
933mt9p031_get_pdata(struct i2c_client *client)
934{
935 struct mt9p031_platform_data *pdata;
936 struct device_node *np;
937
938 if (!IS_ENABLED(CONFIG_OF) || !client->dev.of_node)
939 return client->dev.platform_data;
940
941 np = v4l2_of_get_next_endpoint(client->dev.of_node, NULL);
942 if (!np)
943 return NULL;
944
945 pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL);
946 if (!pdata)
947 goto done;
948
949 pdata->reset = of_get_named_gpio(client->dev.of_node, "reset-gpios", 0);
950 of_property_read_u32(np, "input-clock-frequency", &pdata->ext_freq);
951 of_property_read_u32(np, "pixel-clock-frequency", &pdata->target_freq);
952
953done:
954 of_node_put(np);
955 return pdata;
956}
957
931static int mt9p031_probe(struct i2c_client *client, 958static int mt9p031_probe(struct i2c_client *client,
932 const struct i2c_device_id *did) 959 const struct i2c_device_id *did)
933{ 960{
934 struct mt9p031_platform_data *pdata = client->dev.platform_data; 961 struct mt9p031_platform_data *pdata = mt9p031_get_pdata(client);
935 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 962 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
936 struct mt9p031 *mt9p031; 963 struct mt9p031 *mt9p031;
937 unsigned int i; 964 unsigned int i;
@@ -958,14 +985,14 @@ static int mt9p031_probe(struct i2c_client *client,
958 mt9p031->model = did->driver_data; 985 mt9p031->model = did->driver_data;
959 mt9p031->reset = -1; 986 mt9p031->reset = -1;
960 987
961 mt9p031->vaa = devm_regulator_get(&client->dev, "vaa"); 988 mt9p031->regulators[0].supply = "vdd";
962 mt9p031->vdd = devm_regulator_get(&client->dev, "vdd"); 989 mt9p031->regulators[1].supply = "vdd_io";
963 mt9p031->vdd_io = devm_regulator_get(&client->dev, "vdd_io"); 990 mt9p031->regulators[2].supply = "vaa";
964 991
965 if (IS_ERR(mt9p031->vaa) || IS_ERR(mt9p031->vdd) || 992 ret = devm_regulator_bulk_get(&client->dev, 3, mt9p031->regulators);
966 IS_ERR(mt9p031->vdd_io)) { 993 if (ret < 0) {
967 dev_err(&client->dev, "Unable to get regulators\n"); 994 dev_err(&client->dev, "Unable to get regulators\n");
968 return -ENODEV; 995 return ret;
969 } 996 }
970 997
971 v4l2_ctrl_handler_init(&mt9p031->ctrls, ARRAY_SIZE(mt9p031_ctrls) + 6); 998 v4l2_ctrl_handler_init(&mt9p031->ctrls, ARRAY_SIZE(mt9p031_ctrls) + 6);
@@ -1031,7 +1058,7 @@ static int mt9p031_probe(struct i2c_client *client,
1031 mt9p031->format.field = V4L2_FIELD_NONE; 1058 mt9p031->format.field = V4L2_FIELD_NONE;
1032 mt9p031->format.colorspace = V4L2_COLORSPACE_SRGB; 1059 mt9p031->format.colorspace = V4L2_COLORSPACE_SRGB;
1033 1060
1034 if (pdata->reset != -1) { 1061 if (gpio_is_valid(pdata->reset)) {
1035 ret = devm_gpio_request_one(&client->dev, pdata->reset, 1062 ret = devm_gpio_request_one(&client->dev, pdata->reset,
1036 GPIOF_OUT_INIT_LOW, "mt9p031_rst"); 1063 GPIOF_OUT_INIT_LOW, "mt9p031_rst");
1037 if (ret < 0) 1064 if (ret < 0)
@@ -1070,8 +1097,18 @@ static const struct i2c_device_id mt9p031_id[] = {
1070}; 1097};
1071MODULE_DEVICE_TABLE(i2c, mt9p031_id); 1098MODULE_DEVICE_TABLE(i2c, mt9p031_id);
1072 1099
1100#if IS_ENABLED(CONFIG_OF)
1101static const struct of_device_id mt9p031_of_match[] = {
1102 { .compatible = "aptina,mt9p031", },
1103 { .compatible = "aptina,mt9p031m", },
1104 { /* sentinel */ },
1105};
1106MODULE_DEVICE_TABLE(of, mt9p031_of_match);
1107#endif
1108
1073static struct i2c_driver mt9p031_i2c_driver = { 1109static struct i2c_driver mt9p031_i2c_driver = {
1074 .driver = { 1110 .driver = {
1111 .of_match_table = of_match_ptr(mt9p031_of_match),
1075 .name = "mt9p031", 1112 .name = "mt9p031",
1076 }, 1113 },
1077 .probe = mt9p031_probe, 1114 .probe = mt9p031_probe,
diff --git a/drivers/media/i2c/mt9t001.c b/drivers/media/i2c/mt9t001.c
index 2e189d8b71bb..796463466ef0 100644
--- a/drivers/media/i2c/mt9t001.c
+++ b/drivers/media/i2c/mt9t001.c
@@ -740,7 +740,7 @@ static int mt9t001_probe(struct i2c_client *client,
740 if (ret < 0) 740 if (ret < 0)
741 return ret; 741 return ret;
742 742
743 mt9t001 = kzalloc(sizeof(*mt9t001), GFP_KERNEL); 743 mt9t001 = devm_kzalloc(&client->dev, sizeof(*mt9t001), GFP_KERNEL);
744 if (!mt9t001) 744 if (!mt9t001)
745 return -ENOMEM; 745 return -ENOMEM;
746 746
@@ -801,7 +801,6 @@ done:
801 if (ret < 0) { 801 if (ret < 0) {
802 v4l2_ctrl_handler_free(&mt9t001->ctrls); 802 v4l2_ctrl_handler_free(&mt9t001->ctrls);
803 media_entity_cleanup(&mt9t001->subdev.entity); 803 media_entity_cleanup(&mt9t001->subdev.entity);
804 kfree(mt9t001);
805 } 804 }
806 805
807 return ret; 806 return ret;
@@ -815,7 +814,6 @@ static int mt9t001_remove(struct i2c_client *client)
815 v4l2_ctrl_handler_free(&mt9t001->ctrls); 814 v4l2_ctrl_handler_free(&mt9t001->ctrls);
816 v4l2_device_unregister_subdev(subdev); 815 v4l2_device_unregister_subdev(subdev);
817 media_entity_cleanup(&subdev->entity); 816 media_entity_cleanup(&subdev->entity);
818 kfree(mt9t001);
819 return 0; 817 return 0;
820} 818}
821 819
diff --git a/drivers/media/i2c/mt9v011.c b/drivers/media/i2c/mt9v011.c
index 3f415fd12de3..f74698cf14c9 100644
--- a/drivers/media/i2c/mt9v011.c
+++ b/drivers/media/i2c/mt9v011.c
@@ -12,7 +12,6 @@
12#include <linux/module.h> 12#include <linux/module.h>
13#include <asm/div64.h> 13#include <asm/div64.h>
14#include <media/v4l2-device.h> 14#include <media/v4l2-device.h>
15#include <media/v4l2-chip-ident.h>
16#include <media/v4l2-ctrls.h> 15#include <media/v4l2-ctrls.h>
17#include <media/mt9v011.h> 16#include <media/mt9v011.h>
18 17
@@ -407,13 +406,6 @@ static int mt9v011_s_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt
407static int mt9v011_g_register(struct v4l2_subdev *sd, 406static int mt9v011_g_register(struct v4l2_subdev *sd,
408 struct v4l2_dbg_register *reg) 407 struct v4l2_dbg_register *reg)
409{ 408{
410 struct i2c_client *client = v4l2_get_subdevdata(sd);
411
412 if (!v4l2_chip_match_i2c_client(client, &reg->match))
413 return -EINVAL;
414 if (!capable(CAP_SYS_ADMIN))
415 return -EPERM;
416
417 reg->val = mt9v011_read(sd, reg->reg & 0xff); 409 reg->val = mt9v011_read(sd, reg->reg & 0xff);
418 reg->size = 2; 410 reg->size = 2;
419 411
@@ -423,31 +415,12 @@ static int mt9v011_g_register(struct v4l2_subdev *sd,
423static int mt9v011_s_register(struct v4l2_subdev *sd, 415static int mt9v011_s_register(struct v4l2_subdev *sd,
424 const struct v4l2_dbg_register *reg) 416 const struct v4l2_dbg_register *reg)
425{ 417{
426 struct i2c_client *client = v4l2_get_subdevdata(sd);
427
428 if (!v4l2_chip_match_i2c_client(client, &reg->match))
429 return -EINVAL;
430 if (!capable(CAP_SYS_ADMIN))
431 return -EPERM;
432
433 mt9v011_write(sd, reg->reg & 0xff, reg->val & 0xffff); 418 mt9v011_write(sd, reg->reg & 0xff, reg->val & 0xffff);
434 419
435 return 0; 420 return 0;
436} 421}
437#endif 422#endif
438 423
439static int mt9v011_g_chip_ident(struct v4l2_subdev *sd,
440 struct v4l2_dbg_chip_ident *chip)
441{
442 u16 version;
443 struct i2c_client *client = v4l2_get_subdevdata(sd);
444
445 version = mt9v011_read(sd, R00_MT9V011_CHIP_VERSION);
446
447 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_MT9V011,
448 version);
449}
450
451static int mt9v011_s_ctrl(struct v4l2_ctrl *ctrl) 424static int mt9v011_s_ctrl(struct v4l2_ctrl *ctrl)
452{ 425{
453 struct mt9v011 *core = 426 struct mt9v011 *core =
@@ -489,7 +462,6 @@ static struct v4l2_ctrl_ops mt9v011_ctrl_ops = {
489 462
490static const struct v4l2_subdev_core_ops mt9v011_core_ops = { 463static const struct v4l2_subdev_core_ops mt9v011_core_ops = {
491 .reset = mt9v011_reset, 464 .reset = mt9v011_reset,
492 .g_chip_ident = mt9v011_g_chip_ident,
493#ifdef CONFIG_VIDEO_ADV_DEBUG 465#ifdef CONFIG_VIDEO_ADV_DEBUG
494 .g_register = mt9v011_g_register, 466 .g_register = mt9v011_g_register,
495 .s_register = mt9v011_s_register, 467 .s_register = mt9v011_s_register,
@@ -526,7 +498,7 @@ static int mt9v011_probe(struct i2c_client *c,
526 I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) 498 I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
527 return -EIO; 499 return -EIO;
528 500
529 core = kzalloc(sizeof(struct mt9v011), GFP_KERNEL); 501 core = devm_kzalloc(&c->dev, sizeof(struct mt9v011), GFP_KERNEL);
530 if (!core) 502 if (!core)
531 return -ENOMEM; 503 return -ENOMEM;
532 504
@@ -539,7 +511,6 @@ static int mt9v011_probe(struct i2c_client *c,
539 (version != MT9V011_REV_B_VERSION)) { 511 (version != MT9V011_REV_B_VERSION)) {
540 v4l2_info(sd, "*** unknown micron chip detected (0x%04x).\n", 512 v4l2_info(sd, "*** unknown micron chip detected (0x%04x).\n",
541 version); 513 version);
542 kfree(core);
543 return -EINVAL; 514 return -EINVAL;
544 } 515 }
545 516
@@ -562,7 +533,6 @@ static int mt9v011_probe(struct i2c_client *c,
562 533
563 v4l2_err(sd, "control initialization error %d\n", ret); 534 v4l2_err(sd, "control initialization error %d\n", ret);
564 v4l2_ctrl_handler_free(&core->ctrls); 535 v4l2_ctrl_handler_free(&core->ctrls);
565 kfree(core);
566 return ret; 536 return ret;
567 } 537 }
568 core->sd.ctrl_handler = &core->ctrls; 538 core->sd.ctrl_handler = &core->ctrls;
@@ -598,7 +568,7 @@ static int mt9v011_remove(struct i2c_client *c)
598 568
599 v4l2_device_unregister_subdev(sd); 569 v4l2_device_unregister_subdev(sd);
600 v4l2_ctrl_handler_free(&core->ctrls); 570 v4l2_ctrl_handler_free(&core->ctrls);
601 kfree(to_mt9v011(sd)); 571
602 return 0; 572 return 0;
603} 573}
604 574
diff --git a/drivers/media/i2c/mt9v032.c b/drivers/media/i2c/mt9v032.c
index 3f356cb28256..60c6f6739560 100644
--- a/drivers/media/i2c/mt9v032.c
+++ b/drivers/media/i2c/mt9v032.c
@@ -744,7 +744,7 @@ static int mt9v032_probe(struct i2c_client *client,
744 return -EIO; 744 return -EIO;
745 } 745 }
746 746
747 mt9v032 = kzalloc(sizeof(*mt9v032), GFP_KERNEL); 747 mt9v032 = devm_kzalloc(&client->dev, sizeof(*mt9v032), GFP_KERNEL);
748 if (!mt9v032) 748 if (!mt9v032)
749 return -ENOMEM; 749 return -ENOMEM;
750 750
@@ -830,8 +830,9 @@ static int mt9v032_probe(struct i2c_client *client,
830 830
831 mt9v032->pad.flags = MEDIA_PAD_FL_SOURCE; 831 mt9v032->pad.flags = MEDIA_PAD_FL_SOURCE;
832 ret = media_entity_init(&mt9v032->subdev.entity, 1, &mt9v032->pad, 0); 832 ret = media_entity_init(&mt9v032->subdev.entity, 1, &mt9v032->pad, 0);
833
833 if (ret < 0) 834 if (ret < 0)
834 kfree(mt9v032); 835 v4l2_ctrl_handler_free(&mt9v032->ctrls);
835 836
836 return ret; 837 return ret;
837} 838}
@@ -841,9 +842,10 @@ static int mt9v032_remove(struct i2c_client *client)
841 struct v4l2_subdev *subdev = i2c_get_clientdata(client); 842 struct v4l2_subdev *subdev = i2c_get_clientdata(client);
842 struct mt9v032 *mt9v032 = to_mt9v032(subdev); 843 struct mt9v032 *mt9v032 = to_mt9v032(subdev);
843 844
845 v4l2_ctrl_handler_free(&mt9v032->ctrls);
844 v4l2_device_unregister_subdev(subdev); 846 v4l2_device_unregister_subdev(subdev);
845 media_entity_cleanup(&subdev->entity); 847 media_entity_cleanup(&subdev->entity);
846 kfree(mt9v032); 848
847 return 0; 849 return 0;
848} 850}
849 851
diff --git a/drivers/media/i2c/noon010pc30.c b/drivers/media/i2c/noon010pc30.c
index 8554b47f993a..271d0b7967a6 100644
--- a/drivers/media/i2c/noon010pc30.c
+++ b/drivers/media/i2c/noon010pc30.c
@@ -19,7 +19,6 @@
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/regulator/consumer.h> 20#include <linux/regulator/consumer.h>
21#include <media/noon010pc30.h> 21#include <media/noon010pc30.h>
22#include <media/v4l2-chip-ident.h>
23#include <linux/videodev2.h> 22#include <linux/videodev2.h>
24#include <linux/module.h> 23#include <linux/module.h>
25#include <media/v4l2-ctrls.h> 24#include <media/v4l2-ctrls.h>
@@ -712,7 +711,7 @@ static int noon010_probe(struct i2c_client *client,
712 return -EIO; 711 return -EIO;
713 } 712 }
714 713
715 info = kzalloc(sizeof(*info), GFP_KERNEL); 714 info = devm_kzalloc(&client->dev, sizeof(*info), GFP_KERNEL);
716 if (!info) 715 if (!info)
717 return -ENOMEM; 716 return -ENOMEM;
718 717
@@ -746,57 +745,50 @@ static int noon010_probe(struct i2c_client *client,
746 info->curr_win = &noon010_sizes[0]; 745 info->curr_win = &noon010_sizes[0];
747 746
748 if (gpio_is_valid(pdata->gpio_nreset)) { 747 if (gpio_is_valid(pdata->gpio_nreset)) {
749 ret = gpio_request(pdata->gpio_nreset, "NOON010PC30 NRST"); 748 ret = devm_gpio_request_one(&client->dev, pdata->gpio_nreset,
749 GPIOF_OUT_INIT_LOW,
750 "NOON010PC30 NRST");
750 if (ret) { 751 if (ret) {
751 dev_err(&client->dev, "GPIO request error: %d\n", ret); 752 dev_err(&client->dev, "GPIO request error: %d\n", ret);
752 goto np_err; 753 goto np_err;
753 } 754 }
754 info->gpio_nreset = pdata->gpio_nreset; 755 info->gpio_nreset = pdata->gpio_nreset;
755 gpio_direction_output(info->gpio_nreset, 0);
756 gpio_export(info->gpio_nreset, 0); 756 gpio_export(info->gpio_nreset, 0);
757 } 757 }
758 758
759 if (gpio_is_valid(pdata->gpio_nstby)) { 759 if (gpio_is_valid(pdata->gpio_nstby)) {
760 ret = gpio_request(pdata->gpio_nstby, "NOON010PC30 NSTBY"); 760 ret = devm_gpio_request_one(&client->dev, pdata->gpio_nstby,
761 GPIOF_OUT_INIT_LOW,
762 "NOON010PC30 NSTBY");
761 if (ret) { 763 if (ret) {
762 dev_err(&client->dev, "GPIO request error: %d\n", ret); 764 dev_err(&client->dev, "GPIO request error: %d\n", ret);
763 goto np_gpio_err; 765 goto np_err;
764 } 766 }
765 info->gpio_nstby = pdata->gpio_nstby; 767 info->gpio_nstby = pdata->gpio_nstby;
766 gpio_direction_output(info->gpio_nstby, 0);
767 gpio_export(info->gpio_nstby, 0); 768 gpio_export(info->gpio_nstby, 0);
768 } 769 }
769 770
770 for (i = 0; i < NOON010_NUM_SUPPLIES; i++) 771 for (i = 0; i < NOON010_NUM_SUPPLIES; i++)
771 info->supply[i].supply = noon010_supply_name[i]; 772 info->supply[i].supply = noon010_supply_name[i];
772 773
773 ret = regulator_bulk_get(&client->dev, NOON010_NUM_SUPPLIES, 774 ret = devm_regulator_bulk_get(&client->dev, NOON010_NUM_SUPPLIES,
774 info->supply); 775 info->supply);
775 if (ret) 776 if (ret)
776 goto np_reg_err; 777 goto np_err;
777 778
778 info->pad.flags = MEDIA_PAD_FL_SOURCE; 779 info->pad.flags = MEDIA_PAD_FL_SOURCE;
779 sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV_SENSOR; 780 sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV_SENSOR;
780 ret = media_entity_init(&sd->entity, 1, &info->pad, 0); 781 ret = media_entity_init(&sd->entity, 1, &info->pad, 0);
781 if (ret < 0) 782 if (ret < 0)
782 goto np_me_err; 783 goto np_err;
783 784
784 ret = noon010_detect(client, info); 785 ret = noon010_detect(client, info);
785 if (!ret) 786 if (!ret)
786 return 0; 787 return 0;
787 788
788np_me_err:
789 regulator_bulk_free(NOON010_NUM_SUPPLIES, info->supply);
790np_reg_err:
791 if (gpio_is_valid(info->gpio_nstby))
792 gpio_free(info->gpio_nstby);
793np_gpio_err:
794 if (gpio_is_valid(info->gpio_nreset))
795 gpio_free(info->gpio_nreset);
796np_err: 789np_err:
797 v4l2_ctrl_handler_free(&info->hdl); 790 v4l2_ctrl_handler_free(&info->hdl);
798 v4l2_device_unregister_subdev(sd); 791 v4l2_device_unregister_subdev(sd);
799 kfree(info);
800 return ret; 792 return ret;
801} 793}
802 794
@@ -807,17 +799,8 @@ static int noon010_remove(struct i2c_client *client)
807 799
808 v4l2_device_unregister_subdev(sd); 800 v4l2_device_unregister_subdev(sd);
809 v4l2_ctrl_handler_free(&info->hdl); 801 v4l2_ctrl_handler_free(&info->hdl);
810
811 regulator_bulk_free(NOON010_NUM_SUPPLIES, info->supply);
812
813 if (gpio_is_valid(info->gpio_nreset))
814 gpio_free(info->gpio_nreset);
815
816 if (gpio_is_valid(info->gpio_nstby))
817 gpio_free(info->gpio_nstby);
818
819 media_entity_cleanup(&sd->entity); 802 media_entity_cleanup(&sd->entity);
820 kfree(info); 803
821 return 0; 804 return 0;
822} 805}
823 806
diff --git a/drivers/media/i2c/ov7640.c b/drivers/media/i2c/ov7640.c
index b0cc927e8b19..faa64baf09e8 100644
--- a/drivers/media/i2c/ov7640.c
+++ b/drivers/media/i2c/ov7640.c
@@ -20,7 +20,6 @@
20#include <linux/i2c.h> 20#include <linux/i2c.h>
21#include <linux/videodev2.h> 21#include <linux/videodev2.h>
22#include <media/v4l2-device.h> 22#include <media/v4l2-device.h>
23#include <media/v4l2-chip-ident.h>
24#include <linux/slab.h> 23#include <linux/slab.h>
25 24
26MODULE_DESCRIPTION("OmniVision ov7640 sensor driver"); 25MODULE_DESCRIPTION("OmniVision ov7640 sensor driver");
@@ -59,7 +58,7 @@ static int ov7640_probe(struct i2c_client *client,
59 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 58 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
60 return -ENODEV; 59 return -ENODEV;
61 60
62 sd = kzalloc(sizeof(struct v4l2_subdev), GFP_KERNEL); 61 sd = devm_kzalloc(&client->dev, sizeof(*sd), GFP_KERNEL);
63 if (sd == NULL) 62 if (sd == NULL)
64 return -ENOMEM; 63 return -ENOMEM;
65 v4l2_i2c_subdev_init(sd, client, &ov7640_ops); 64 v4l2_i2c_subdev_init(sd, client, &ov7640_ops);
@@ -71,7 +70,6 @@ static int ov7640_probe(struct i2c_client *client,
71 70
72 if (write_regs(client, initial_registers) < 0) { 71 if (write_regs(client, initial_registers) < 0) {
73 v4l_err(client, "error initializing OV7640\n"); 72 v4l_err(client, "error initializing OV7640\n");
74 kfree(sd);
75 return -ENODEV; 73 return -ENODEV;
76 } 74 }
77 75
@@ -84,7 +82,7 @@ static int ov7640_remove(struct i2c_client *client)
84 struct v4l2_subdev *sd = i2c_get_clientdata(client); 82 struct v4l2_subdev *sd = i2c_get_clientdata(client);
85 83
86 v4l2_device_unregister_subdev(sd); 84 v4l2_device_unregister_subdev(sd);
87 kfree(sd); 85
88 return 0; 86 return 0;
89} 87}
90 88
diff --git a/drivers/media/i2c/ov7670.c b/drivers/media/i2c/ov7670.c
index 617ad3fff4aa..e8a1ce204036 100644
--- a/drivers/media/i2c/ov7670.c
+++ b/drivers/media/i2c/ov7670.c
@@ -17,7 +17,6 @@
17#include <linux/delay.h> 17#include <linux/delay.h>
18#include <linux/videodev2.h> 18#include <linux/videodev2.h>
19#include <media/v4l2-device.h> 19#include <media/v4l2-device.h>
20#include <media/v4l2-chip-ident.h>
21#include <media/v4l2-ctrls.h> 20#include <media/v4l2-ctrls.h>
22#include <media/v4l2-mediabus.h> 21#include <media/v4l2-mediabus.h>
23#include <media/ov7670.h> 22#include <media/ov7670.h>
@@ -1462,25 +1461,12 @@ static const struct v4l2_ctrl_ops ov7670_ctrl_ops = {
1462 .g_volatile_ctrl = ov7670_g_volatile_ctrl, 1461 .g_volatile_ctrl = ov7670_g_volatile_ctrl,
1463}; 1462};
1464 1463
1465static int ov7670_g_chip_ident(struct v4l2_subdev *sd,
1466 struct v4l2_dbg_chip_ident *chip)
1467{
1468 struct i2c_client *client = v4l2_get_subdevdata(sd);
1469
1470 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_OV7670, 0);
1471}
1472
1473#ifdef CONFIG_VIDEO_ADV_DEBUG 1464#ifdef CONFIG_VIDEO_ADV_DEBUG
1474static int ov7670_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 1465static int ov7670_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
1475{ 1466{
1476 struct i2c_client *client = v4l2_get_subdevdata(sd);
1477 unsigned char val = 0; 1467 unsigned char val = 0;
1478 int ret; 1468 int ret;
1479 1469
1480 if (!v4l2_chip_match_i2c_client(client, &reg->match))
1481 return -EINVAL;
1482 if (!capable(CAP_SYS_ADMIN))
1483 return -EPERM;
1484 ret = ov7670_read(sd, reg->reg & 0xff, &val); 1470 ret = ov7670_read(sd, reg->reg & 0xff, &val);
1485 reg->val = val; 1471 reg->val = val;
1486 reg->size = 1; 1472 reg->size = 1;
@@ -1489,12 +1475,6 @@ static int ov7670_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *r
1489 1475
1490static int ov7670_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg) 1476static int ov7670_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
1491{ 1477{
1492 struct i2c_client *client = v4l2_get_subdevdata(sd);
1493
1494 if (!v4l2_chip_match_i2c_client(client, &reg->match))
1495 return -EINVAL;
1496 if (!capable(CAP_SYS_ADMIN))
1497 return -EPERM;
1498 ov7670_write(sd, reg->reg & 0xff, reg->val & 0xff); 1478 ov7670_write(sd, reg->reg & 0xff, reg->val & 0xff);
1499 return 0; 1479 return 0;
1500} 1480}
@@ -1503,7 +1483,6 @@ static int ov7670_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_regis
1503/* ----------------------------------------------------------------------- */ 1483/* ----------------------------------------------------------------------- */
1504 1484
1505static const struct v4l2_subdev_core_ops ov7670_core_ops = { 1485static const struct v4l2_subdev_core_ops ov7670_core_ops = {
1506 .g_chip_ident = ov7670_g_chip_ident,
1507 .reset = ov7670_reset, 1486 .reset = ov7670_reset,
1508 .init = ov7670_init, 1487 .init = ov7670_init,
1509#ifdef CONFIG_VIDEO_ADV_DEBUG 1488#ifdef CONFIG_VIDEO_ADV_DEBUG
@@ -1552,7 +1531,7 @@ static int ov7670_probe(struct i2c_client *client,
1552 struct ov7670_info *info; 1531 struct ov7670_info *info;
1553 int ret; 1532 int ret;
1554 1533
1555 info = kzalloc(sizeof(struct ov7670_info), GFP_KERNEL); 1534 info = devm_kzalloc(&client->dev, sizeof(*info), GFP_KERNEL);
1556 if (info == NULL) 1535 if (info == NULL)
1557 return -ENOMEM; 1536 return -ENOMEM;
1558 sd = &info->sd; 1537 sd = &info->sd;
@@ -1590,7 +1569,6 @@ static int ov7670_probe(struct i2c_client *client,
1590 v4l_dbg(1, debug, client, 1569 v4l_dbg(1, debug, client,
1591 "chip found @ 0x%x (%s) is not an ov7670 chip.\n", 1570 "chip found @ 0x%x (%s) is not an ov7670 chip.\n",
1592 client->addr << 1, client->adapter->name); 1571 client->addr << 1, client->adapter->name);
1593 kfree(info);
1594 return ret; 1572 return ret;
1595 } 1573 }
1596 v4l_info(client, "chip found @ 0x%02x (%s)\n", 1574 v4l_info(client, "chip found @ 0x%02x (%s)\n",
@@ -1635,7 +1613,6 @@ static int ov7670_probe(struct i2c_client *client,
1635 int err = info->hdl.error; 1613 int err = info->hdl.error;
1636 1614
1637 v4l2_ctrl_handler_free(&info->hdl); 1615 v4l2_ctrl_handler_free(&info->hdl);
1638 kfree(info);
1639 return err; 1616 return err;
1640 } 1617 }
1641 /* 1618 /*
@@ -1659,7 +1636,6 @@ static int ov7670_remove(struct i2c_client *client)
1659 1636
1660 v4l2_device_unregister_subdev(sd); 1637 v4l2_device_unregister_subdev(sd);
1661 v4l2_ctrl_handler_free(&info->hdl); 1638 v4l2_ctrl_handler_free(&info->hdl);
1662 kfree(info);
1663 return 0; 1639 return 0;
1664} 1640}
1665 1641
diff --git a/drivers/media/i2c/s5c73m3/s5c73m3-core.c b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
index 9eac5310942f..825ea86d982d 100644
--- a/drivers/media/i2c/s5c73m3/s5c73m3-core.c
+++ b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
@@ -1385,9 +1385,12 @@ static int __s5c73m3_power_off(struct s5c73m3 *state)
1385 } 1385 }
1386 return 0; 1386 return 0;
1387err: 1387err:
1388 for (++i; i < S5C73M3_MAX_SUPPLIES; i++) 1388 for (++i; i < S5C73M3_MAX_SUPPLIES; i++) {
1389 regulator_enable(state->supplies[i].consumer); 1389 int r = regulator_enable(state->supplies[i].consumer);
1390 1390 if (r < 0)
1391 v4l2_err(&state->oif_sd, "Failed to reenable %s: %d\n",
1392 state->supplies[i].supply, r);
1393 }
1391 return ret; 1394 return ret;
1392} 1395}
1393 1396
@@ -1511,59 +1514,40 @@ static const struct v4l2_subdev_ops oif_subdev_ops = {
1511 .video = &s5c73m3_oif_video_ops, 1514 .video = &s5c73m3_oif_video_ops,
1512}; 1515};
1513 1516
1514static int s5c73m3_configure_gpio(int nr, int val, const char *name)
1515{
1516 unsigned long flags = val ? GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW;
1517 int ret;
1518
1519 if (!gpio_is_valid(nr))
1520 return 0;
1521 ret = gpio_request_one(nr, flags, name);
1522 if (!ret)
1523 gpio_export(nr, 0);
1524 return ret;
1525}
1526
1527static int s5c73m3_free_gpios(struct s5c73m3 *state)
1528{
1529 int i;
1530
1531 for (i = 0; i < ARRAY_SIZE(state->gpio); i++) {
1532 if (!gpio_is_valid(state->gpio[i].gpio))
1533 continue;
1534 gpio_free(state->gpio[i].gpio);
1535 state->gpio[i].gpio = -EINVAL;
1536 }
1537 return 0;
1538}
1539
1540static int s5c73m3_configure_gpios(struct s5c73m3 *state, 1517static int s5c73m3_configure_gpios(struct s5c73m3 *state,
1541 const struct s5c73m3_platform_data *pdata) 1518 const struct s5c73m3_platform_data *pdata)
1542{ 1519{
1543 const struct s5c73m3_gpio *gpio = &pdata->gpio_stby; 1520 struct device *dev = &state->i2c_client->dev;
1521 const struct s5c73m3_gpio *gpio;
1522 unsigned long flags;
1544 int ret; 1523 int ret;
1545 1524
1546 state->gpio[STBY].gpio = -EINVAL; 1525 state->gpio[STBY].gpio = -EINVAL;
1547 state->gpio[RST].gpio = -EINVAL; 1526 state->gpio[RST].gpio = -EINVAL;
1548 1527
1549 ret = s5c73m3_configure_gpio(gpio->gpio, gpio->level, "S5C73M3_STBY"); 1528 gpio = &pdata->gpio_stby;
1550 if (ret) { 1529 if (gpio_is_valid(gpio->gpio)) {
1551 s5c73m3_free_gpios(state); 1530 flags = (gpio->level ? GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW)
1552 return ret; 1531 | GPIOF_EXPORT;
1532 ret = devm_gpio_request_one(dev, gpio->gpio, flags,
1533 "S5C73M3_STBY");
1534 if (ret < 0)
1535 return ret;
1536
1537 state->gpio[STBY] = *gpio;
1553 } 1538 }
1554 state->gpio[STBY] = *gpio;
1555 if (gpio_is_valid(gpio->gpio))
1556 gpio_set_value(gpio->gpio, 0);
1557 1539
1558 gpio = &pdata->gpio_reset; 1540 gpio = &pdata->gpio_reset;
1559 ret = s5c73m3_configure_gpio(gpio->gpio, gpio->level, "S5C73M3_RST"); 1541 if (gpio_is_valid(gpio->gpio)) {
1560 if (ret) { 1542 flags = (gpio->level ? GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW)
1561 s5c73m3_free_gpios(state); 1543 | GPIOF_EXPORT;
1562 return ret; 1544 ret = devm_gpio_request_one(dev, gpio->gpio, flags,
1545 "S5C73M3_RST");
1546 if (ret < 0)
1547 return ret;
1548
1549 state->gpio[RST] = *gpio;
1563 } 1550 }
1564 state->gpio[RST] = *gpio;
1565 if (gpio_is_valid(gpio->gpio))
1566 gpio_set_value(gpio->gpio, 0);
1567 1551
1568 return 0; 1552 return 0;
1569} 1553}
@@ -1626,10 +1610,11 @@ static int s5c73m3_probe(struct i2c_client *client,
1626 1610
1627 state->mclk_frequency = pdata->mclk_frequency; 1611 state->mclk_frequency = pdata->mclk_frequency;
1628 state->bus_type = pdata->bus_type; 1612 state->bus_type = pdata->bus_type;
1613 state->i2c_client = client;
1629 1614
1630 ret = s5c73m3_configure_gpios(state, pdata); 1615 ret = s5c73m3_configure_gpios(state, pdata);
1631 if (ret) 1616 if (ret)
1632 goto out_err1; 1617 goto out_err;
1633 1618
1634 for (i = 0; i < S5C73M3_MAX_SUPPLIES; i++) 1619 for (i = 0; i < S5C73M3_MAX_SUPPLIES; i++)
1635 state->supplies[i].supply = s5c73m3_supply_names[i]; 1620 state->supplies[i].supply = s5c73m3_supply_names[i];
@@ -1638,12 +1623,12 @@ static int s5c73m3_probe(struct i2c_client *client,
1638 state->supplies); 1623 state->supplies);
1639 if (ret) { 1624 if (ret) {
1640 dev_err(dev, "failed to get regulators\n"); 1625 dev_err(dev, "failed to get regulators\n");
1641 goto out_err2; 1626 goto out_err;
1642 } 1627 }
1643 1628
1644 ret = s5c73m3_init_controls(state); 1629 ret = s5c73m3_init_controls(state);
1645 if (ret) 1630 if (ret)
1646 goto out_err2; 1631 goto out_err;
1647 1632
1648 state->sensor_pix_size[RES_ISP] = &s5c73m3_isp_resolutions[1]; 1633 state->sensor_pix_size[RES_ISP] = &s5c73m3_isp_resolutions[1];
1649 state->sensor_pix_size[RES_JPEG] = &s5c73m3_jpeg_resolutions[1]; 1634 state->sensor_pix_size[RES_JPEG] = &s5c73m3_jpeg_resolutions[1];
@@ -1659,16 +1644,12 @@ static int s5c73m3_probe(struct i2c_client *client,
1659 1644
1660 ret = s5c73m3_register_spi_driver(state); 1645 ret = s5c73m3_register_spi_driver(state);
1661 if (ret < 0) 1646 if (ret < 0)
1662 goto out_err2; 1647 goto out_err;
1663
1664 state->i2c_client = client;
1665 1648
1666 v4l2_info(sd, "%s: completed succesfully\n", __func__); 1649 v4l2_info(sd, "%s: completed succesfully\n", __func__);
1667 return 0; 1650 return 0;
1668 1651
1669out_err2: 1652out_err:
1670 s5c73m3_free_gpios(state);
1671out_err1:
1672 media_entity_cleanup(&sd->entity); 1653 media_entity_cleanup(&sd->entity);
1673 return ret; 1654 return ret;
1674} 1655}
@@ -1688,7 +1669,6 @@ static int s5c73m3_remove(struct i2c_client *client)
1688 media_entity_cleanup(&sensor_sd->entity); 1669 media_entity_cleanup(&sensor_sd->entity);
1689 1670
1690 s5c73m3_unregister_spi_driver(state); 1671 s5c73m3_unregister_spi_driver(state);
1691 s5c73m3_free_gpios(state);
1692 1672
1693 return 0; 1673 return 0;
1694} 1674}
diff --git a/drivers/media/i2c/s5c73m3/s5c73m3-spi.c b/drivers/media/i2c/s5c73m3/s5c73m3-spi.c
index 6f3a9c00fe65..8079e26eb5e2 100644
--- a/drivers/media/i2c/s5c73m3/s5c73m3-spi.c
+++ b/drivers/media/i2c/s5c73m3/s5c73m3-spi.c
@@ -73,7 +73,7 @@ int s5c73m3_spi_write(struct s5c73m3 *state, const void *addr,
73 73
74 memset(padding, 0, sizeof(padding)); 74 memset(padding, 0, sizeof(padding));
75 75
76 for (i = 0; i < count ; i++) { 76 for (i = 0; i < count; i++) {
77 r = spi_xmit(spi_dev, (void *)addr + j, tx_size, SPI_DIR_TX); 77 r = spi_xmit(spi_dev, (void *)addr + j, tx_size, SPI_DIR_TX);
78 if (r < 0) 78 if (r < 0)
79 return r; 79 return r;
@@ -98,7 +98,7 @@ int s5c73m3_spi_read(struct s5c73m3 *state, void *addr,
98 unsigned int i, j = 0; 98 unsigned int i, j = 0;
99 int r = 0; 99 int r = 0;
100 100
101 for (i = 0; i < count ; i++) { 101 for (i = 0; i < count; i++) {
102 r = spi_xmit(spi_dev, addr + j, tx_size, SPI_DIR_RX); 102 r = spi_xmit(spi_dev, addr + j, tx_size, SPI_DIR_RX);
103 if (r < 0) 103 if (r < 0)
104 return r; 104 return r;
diff --git a/drivers/media/i2c/s5k6aa.c b/drivers/media/i2c/s5k6aa.c
index bdf5e3db31d1..789c02a6ca1a 100644
--- a/drivers/media/i2c/s5k6aa.c
+++ b/drivers/media/i2c/s5k6aa.c
@@ -1491,58 +1491,41 @@ static const struct v4l2_subdev_ops s5k6aa_subdev_ops = {
1491/* 1491/*
1492 * GPIO setup 1492 * GPIO setup
1493 */ 1493 */
1494static int s5k6aa_configure_gpio(int nr, int val, const char *name)
1495{
1496 unsigned long flags = val ? GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW;
1497 int ret;
1498
1499 if (!gpio_is_valid(nr))
1500 return 0;
1501 ret = gpio_request_one(nr, flags, name);
1502 if (!ret)
1503 gpio_export(nr, 0);
1504 return ret;
1505}
1506
1507static void s5k6aa_free_gpios(struct s5k6aa *s5k6aa)
1508{
1509 int i;
1510
1511 for (i = 0; i < ARRAY_SIZE(s5k6aa->gpio); i++) {
1512 if (!gpio_is_valid(s5k6aa->gpio[i].gpio))
1513 continue;
1514 gpio_free(s5k6aa->gpio[i].gpio);
1515 s5k6aa->gpio[i].gpio = -EINVAL;
1516 }
1517}
1518 1494
1519static int s5k6aa_configure_gpios(struct s5k6aa *s5k6aa, 1495static int s5k6aa_configure_gpios(struct s5k6aa *s5k6aa,
1520 const struct s5k6aa_platform_data *pdata) 1496 const struct s5k6aa_platform_data *pdata)
1521{ 1497{
1522 const struct s5k6aa_gpio *gpio = &pdata->gpio_stby; 1498 struct i2c_client *client = v4l2_get_subdevdata(&s5k6aa->sd);
1499 const struct s5k6aa_gpio *gpio;
1500 unsigned long flags;
1523 int ret; 1501 int ret;
1524 1502
1525 s5k6aa->gpio[STBY].gpio = -EINVAL; 1503 s5k6aa->gpio[STBY].gpio = -EINVAL;
1526 s5k6aa->gpio[RST].gpio = -EINVAL; 1504 s5k6aa->gpio[RST].gpio = -EINVAL;
1527 1505
1528 ret = s5k6aa_configure_gpio(gpio->gpio, gpio->level, "S5K6AA_STBY"); 1506 gpio = &pdata->gpio_stby;
1529 if (ret) { 1507 if (gpio_is_valid(gpio->gpio)) {
1530 s5k6aa_free_gpios(s5k6aa); 1508 flags = (gpio->level ? GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW)
1531 return ret; 1509 | GPIOF_EXPORT;
1510 ret = devm_gpio_request_one(&client->dev, gpio->gpio, flags,
1511 "S5K6AA_STBY");
1512 if (ret < 0)
1513 return ret;
1514
1515 s5k6aa->gpio[STBY] = *gpio;
1532 } 1516 }
1533 s5k6aa->gpio[STBY] = *gpio;
1534 if (gpio_is_valid(gpio->gpio))
1535 gpio_set_value(gpio->gpio, 0);
1536 1517
1537 gpio = &pdata->gpio_reset; 1518 gpio = &pdata->gpio_reset;
1538 ret = s5k6aa_configure_gpio(gpio->gpio, gpio->level, "S5K6AA_RST"); 1519 if (gpio_is_valid(gpio->gpio)) {
1539 if (ret) { 1520 flags = (gpio->level ? GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW)
1540 s5k6aa_free_gpios(s5k6aa); 1521 | GPIOF_EXPORT;
1541 return ret; 1522 ret = devm_gpio_request_one(&client->dev, gpio->gpio, flags,
1523 "S5K6AA_RST");
1524 if (ret < 0)
1525 return ret;
1526
1527 s5k6aa->gpio[RST] = *gpio;
1542 } 1528 }
1543 s5k6aa->gpio[RST] = *gpio;
1544 if (gpio_is_valid(gpio->gpio))
1545 gpio_set_value(gpio->gpio, 0);
1546 1529
1547 return 0; 1530 return 0;
1548} 1531}
@@ -1593,7 +1576,7 @@ static int s5k6aa_probe(struct i2c_client *client,
1593 1576
1594 ret = s5k6aa_configure_gpios(s5k6aa, pdata); 1577 ret = s5k6aa_configure_gpios(s5k6aa, pdata);
1595 if (ret) 1578 if (ret)
1596 goto out_err2; 1579 goto out_err;
1597 1580
1598 for (i = 0; i < S5K6AA_NUM_SUPPLIES; i++) 1581 for (i = 0; i < S5K6AA_NUM_SUPPLIES; i++)
1599 s5k6aa->supplies[i].supply = s5k6aa_supply_names[i]; 1582 s5k6aa->supplies[i].supply = s5k6aa_supply_names[i];
@@ -1602,12 +1585,12 @@ static int s5k6aa_probe(struct i2c_client *client,
1602 s5k6aa->supplies); 1585 s5k6aa->supplies);
1603 if (ret) { 1586 if (ret) {
1604 dev_err(&client->dev, "Failed to get regulators\n"); 1587 dev_err(&client->dev, "Failed to get regulators\n");
1605 goto out_err3; 1588 goto out_err;
1606 } 1589 }
1607 1590
1608 ret = s5k6aa_initialize_ctrls(s5k6aa); 1591 ret = s5k6aa_initialize_ctrls(s5k6aa);
1609 if (ret) 1592 if (ret)
1610 goto out_err3; 1593 goto out_err;
1611 1594
1612 s5k6aa_presets_data_init(s5k6aa); 1595 s5k6aa_presets_data_init(s5k6aa);
1613 1596
@@ -1618,9 +1601,7 @@ static int s5k6aa_probe(struct i2c_client *client,
1618 1601
1619 return 0; 1602 return 0;
1620 1603
1621out_err3: 1604out_err:
1622 s5k6aa_free_gpios(s5k6aa);
1623out_err2:
1624 media_entity_cleanup(&s5k6aa->sd.entity); 1605 media_entity_cleanup(&s5k6aa->sd.entity);
1625 return ret; 1606 return ret;
1626} 1607}
@@ -1628,12 +1609,10 @@ out_err2:
1628static int s5k6aa_remove(struct i2c_client *client) 1609static int s5k6aa_remove(struct i2c_client *client)
1629{ 1610{
1630 struct v4l2_subdev *sd = i2c_get_clientdata(client); 1611 struct v4l2_subdev *sd = i2c_get_clientdata(client);
1631 struct s5k6aa *s5k6aa = to_s5k6aa(sd);
1632 1612
1633 v4l2_device_unregister_subdev(sd); 1613 v4l2_device_unregister_subdev(sd);
1634 v4l2_ctrl_handler_free(sd->ctrl_handler); 1614 v4l2_ctrl_handler_free(sd->ctrl_handler);
1635 media_entity_cleanup(&sd->entity); 1615 media_entity_cleanup(&sd->entity);
1636 s5k6aa_free_gpios(s5k6aa);
1637 1616
1638 return 0; 1617 return 0;
1639} 1618}
diff --git a/drivers/media/i2c/saa6588.c b/drivers/media/i2c/saa6588.c
index b4e1ccbd87ec..70bc72e795d0 100644
--- a/drivers/media/i2c/saa6588.c
+++ b/drivers/media/i2c/saa6588.c
@@ -33,7 +33,6 @@
33 33
34#include <media/saa6588.h> 34#include <media/saa6588.h>
35#include <media/v4l2-device.h> 35#include <media/v4l2-device.h>
36#include <media/v4l2-chip-ident.h>
37 36
38 37
39/* insmod options */ 38/* insmod options */
@@ -443,17 +442,9 @@ static int saa6588_s_tuner(struct v4l2_subdev *sd, const struct v4l2_tuner *vt)
443 return 0; 442 return 0;
444} 443}
445 444
446static int saa6588_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
447{
448 struct i2c_client *client = v4l2_get_subdevdata(sd);
449
450 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_SAA6588, 0);
451}
452
453/* ----------------------------------------------------------------------- */ 445/* ----------------------------------------------------------------------- */
454 446
455static const struct v4l2_subdev_core_ops saa6588_core_ops = { 447static const struct v4l2_subdev_core_ops saa6588_core_ops = {
456 .g_chip_ident = saa6588_g_chip_ident,
457 .ioctl = saa6588_ioctl, 448 .ioctl = saa6588_ioctl,
458}; 449};
459 450
@@ -478,17 +469,15 @@ static int saa6588_probe(struct i2c_client *client,
478 v4l_info(client, "saa6588 found @ 0x%x (%s)\n", 469 v4l_info(client, "saa6588 found @ 0x%x (%s)\n",
479 client->addr << 1, client->adapter->name); 470 client->addr << 1, client->adapter->name);
480 471
481 s = kzalloc(sizeof(*s), GFP_KERNEL); 472 s = devm_kzalloc(&client->dev, sizeof(*s), GFP_KERNEL);
482 if (s == NULL) 473 if (s == NULL)
483 return -ENOMEM; 474 return -ENOMEM;
484 475
485 s->buf_size = bufblocks * 3; 476 s->buf_size = bufblocks * 3;
486 477
487 s->buffer = kmalloc(s->buf_size, GFP_KERNEL); 478 s->buffer = devm_kzalloc(&client->dev, s->buf_size, GFP_KERNEL);
488 if (s->buffer == NULL) { 479 if (s->buffer == NULL)
489 kfree(s);
490 return -ENOMEM; 480 return -ENOMEM;
491 }
492 sd = &s->sd; 481 sd = &s->sd;
493 v4l2_i2c_subdev_init(sd, client, &saa6588_ops); 482 v4l2_i2c_subdev_init(sd, client, &saa6588_ops);
494 spin_lock_init(&s->lock); 483 spin_lock_init(&s->lock);
@@ -516,8 +505,6 @@ static int saa6588_remove(struct i2c_client *client)
516 505
517 cancel_delayed_work_sync(&s->work); 506 cancel_delayed_work_sync(&s->work);
518 507
519 kfree(s->buffer);
520 kfree(s);
521 return 0; 508 return 0;
522} 509}
523 510
diff --git a/drivers/media/i2c/saa7110.c b/drivers/media/i2c/saa7110.c
index 51cd4c8f0520..ac43e929a1d6 100644
--- a/drivers/media/i2c/saa7110.c
+++ b/drivers/media/i2c/saa7110.c
@@ -35,7 +35,6 @@
35#include <linux/i2c.h> 35#include <linux/i2c.h>
36#include <linux/videodev2.h> 36#include <linux/videodev2.h>
37#include <media/v4l2-device.h> 37#include <media/v4l2-device.h>
38#include <media/v4l2-chip-ident.h>
39#include <media/v4l2-ctrls.h> 38#include <media/v4l2-ctrls.h>
40 39
41MODULE_DESCRIPTION("Philips SAA7110 video decoder driver"); 40MODULE_DESCRIPTION("Philips SAA7110 video decoder driver");
@@ -203,7 +202,7 @@ static v4l2_std_id determine_norm(struct v4l2_subdev *sd)
203 status = saa7110_read(sd); 202 status = saa7110_read(sd);
204 if (status & 0x40) { 203 if (status & 0x40) {
205 v4l2_dbg(1, debug, sd, "status=0x%02x (no signal)\n", status); 204 v4l2_dbg(1, debug, sd, "status=0x%02x (no signal)\n", status);
206 return decoder->norm; /* no change*/ 205 return V4L2_STD_UNKNOWN;
207 } 206 }
208 if ((status & 3) == 0) { 207 if ((status & 3) == 0) {
209 saa7110_write(sd, 0x06, 0x83); 208 saa7110_write(sd, 0x06, 0x83);
@@ -265,7 +264,7 @@ static int saa7110_g_input_status(struct v4l2_subdev *sd, u32 *pstatus)
265 264
266static int saa7110_querystd(struct v4l2_subdev *sd, v4l2_std_id *std) 265static int saa7110_querystd(struct v4l2_subdev *sd, v4l2_std_id *std)
267{ 266{
268 *(v4l2_std_id *)std = determine_norm(sd); 267 *std &= determine_norm(sd);
269 return 0; 268 return 0;
270} 269}
271 270
@@ -352,13 +351,6 @@ static int saa7110_s_ctrl(struct v4l2_ctrl *ctrl)
352 return 0; 351 return 0;
353} 352}
354 353
355static int saa7110_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
356{
357 struct i2c_client *client = v4l2_get_subdevdata(sd);
358
359 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_SAA7110, 0);
360}
361
362/* ----------------------------------------------------------------------- */ 354/* ----------------------------------------------------------------------- */
363 355
364static const struct v4l2_ctrl_ops saa7110_ctrl_ops = { 356static const struct v4l2_ctrl_ops saa7110_ctrl_ops = {
@@ -366,7 +358,6 @@ static const struct v4l2_ctrl_ops saa7110_ctrl_ops = {
366}; 358};
367 359
368static const struct v4l2_subdev_core_ops saa7110_core_ops = { 360static const struct v4l2_subdev_core_ops saa7110_core_ops = {
369 .g_chip_ident = saa7110_g_chip_ident,
370 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls, 361 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls,
371 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, 362 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls,
372 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls, 363 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls,
@@ -406,7 +397,7 @@ static int saa7110_probe(struct i2c_client *client,
406 v4l_info(client, "chip found @ 0x%x (%s)\n", 397 v4l_info(client, "chip found @ 0x%x (%s)\n",
407 client->addr << 1, client->adapter->name); 398 client->addr << 1, client->adapter->name);
408 399
409 decoder = kzalloc(sizeof(struct saa7110), GFP_KERNEL); 400 decoder = devm_kzalloc(&client->dev, sizeof(*decoder), GFP_KERNEL);
410 if (!decoder) 401 if (!decoder)
411 return -ENOMEM; 402 return -ENOMEM;
412 sd = &decoder->sd; 403 sd = &decoder->sd;
@@ -428,7 +419,6 @@ static int saa7110_probe(struct i2c_client *client,
428 int err = decoder->hdl.error; 419 int err = decoder->hdl.error;
429 420
430 v4l2_ctrl_handler_free(&decoder->hdl); 421 v4l2_ctrl_handler_free(&decoder->hdl);
431 kfree(decoder);
432 return err; 422 return err;
433 } 423 }
434 v4l2_ctrl_handler_setup(&decoder->hdl); 424 v4l2_ctrl_handler_setup(&decoder->hdl);
@@ -469,7 +459,6 @@ static int saa7110_remove(struct i2c_client *client)
469 459
470 v4l2_device_unregister_subdev(sd); 460 v4l2_device_unregister_subdev(sd);
471 v4l2_ctrl_handler_free(&decoder->hdl); 461 v4l2_ctrl_handler_free(&decoder->hdl);
472 kfree(decoder);
473 return 0; 462 return 0;
474} 463}
475 464
diff --git a/drivers/media/i2c/saa7115.c b/drivers/media/i2c/saa7115.c
index 52c717d977c9..7fd766ec64c8 100644
--- a/drivers/media/i2c/saa7115.c
+++ b/drivers/media/i2c/saa7115.c
@@ -46,7 +46,6 @@
46#include <linux/videodev2.h> 46#include <linux/videodev2.h>
47#include <media/v4l2-device.h> 47#include <media/v4l2-device.h>
48#include <media/v4l2-ctrls.h> 48#include <media/v4l2-ctrls.h>
49#include <media/v4l2-chip-ident.h>
50#include <media/saa7115.h> 49#include <media/saa7115.h>
51#include <asm/div64.h> 50#include <asm/div64.h>
52 51
@@ -63,6 +62,16 @@ module_param(debug, bool, 0644);
63MODULE_PARM_DESC(debug, "Debug level (0-1)"); 62MODULE_PARM_DESC(debug, "Debug level (0-1)");
64 63
65 64
65enum saa711x_model {
66 SAA7111A,
67 SAA7111,
68 SAA7113,
69 GM7113C,
70 SAA7114,
71 SAA7115,
72 SAA7118,
73};
74
66struct saa711x_state { 75struct saa711x_state {
67 struct v4l2_subdev sd; 76 struct v4l2_subdev sd;
68 struct v4l2_ctrl_handler hdl; 77 struct v4l2_ctrl_handler hdl;
@@ -80,7 +89,7 @@ struct saa711x_state {
80 int radio; 89 int radio;
81 int width; 90 int width;
82 int height; 91 int height;
83 u32 ident; 92 enum saa711x_model ident;
84 u32 audclk_freq; 93 u32 audclk_freq;
85 u32 crystal_freq; 94 u32 crystal_freq;
86 bool ucgc; 95 bool ucgc;
@@ -111,10 +120,10 @@ static inline int saa711x_write(struct v4l2_subdev *sd, u8 reg, u8 value)
111/* Sanity routine to check if a register is present */ 120/* Sanity routine to check if a register is present */
112static int saa711x_has_reg(const int id, const u8 reg) 121static int saa711x_has_reg(const int id, const u8 reg)
113{ 122{
114 if (id == V4L2_IDENT_SAA7111) 123 if (id == SAA7111)
115 return reg < 0x20 && reg != 0x01 && reg != 0x0f && 124 return reg < 0x20 && reg != 0x01 && reg != 0x0f &&
116 (reg < 0x13 || reg > 0x19) && reg != 0x1d && reg != 0x1e; 125 (reg < 0x13 || reg > 0x19) && reg != 0x1d && reg != 0x1e;
117 if (id == V4L2_IDENT_SAA7111A) 126 if (id == SAA7111A)
118 return reg < 0x20 && reg != 0x01 && reg != 0x0f && 127 return reg < 0x20 && reg != 0x01 && reg != 0x0f &&
119 reg != 0x14 && reg != 0x18 && reg != 0x19 && 128 reg != 0x14 && reg != 0x18 && reg != 0x19 &&
120 reg != 0x1d && reg != 0x1e; 129 reg != 0x1d && reg != 0x1e;
@@ -127,16 +136,18 @@ static int saa711x_has_reg(const int id, const u8 reg)
127 return 0; 136 return 0;
128 137
129 switch (id) { 138 switch (id) {
130 case V4L2_IDENT_SAA7113: 139 case GM7113C:
140 return reg != 0x14 && (reg < 0x18 || reg > 0x1e) && reg < 0x20;
141 case SAA7113:
131 return reg != 0x14 && (reg < 0x18 || reg > 0x1e) && (reg < 0x20 || reg > 0x3f) && 142 return reg != 0x14 && (reg < 0x18 || reg > 0x1e) && (reg < 0x20 || reg > 0x3f) &&
132 reg != 0x5d && reg < 0x63; 143 reg != 0x5d && reg < 0x63;
133 case V4L2_IDENT_SAA7114: 144 case SAA7114:
134 return (reg < 0x1a || reg > 0x1e) && (reg < 0x20 || reg > 0x2f) && 145 return (reg < 0x1a || reg > 0x1e) && (reg < 0x20 || reg > 0x2f) &&
135 (reg < 0x63 || reg > 0x7f) && reg != 0x33 && reg != 0x37 && 146 (reg < 0x63 || reg > 0x7f) && reg != 0x33 && reg != 0x37 &&
136 reg != 0x81 && reg < 0xf0; 147 reg != 0x81 && reg < 0xf0;
137 case V4L2_IDENT_SAA7115: 148 case SAA7115:
138 return (reg < 0x20 || reg > 0x2f) && reg != 0x65 && (reg < 0xfc || reg > 0xfe); 149 return (reg < 0x20 || reg > 0x2f) && reg != 0x65 && (reg < 0xfc || reg > 0xfe);
139 case V4L2_IDENT_SAA7118: 150 case SAA7118:
140 return (reg < 0x1a || reg > 0x1d) && (reg < 0x20 || reg > 0x22) && 151 return (reg < 0x1a || reg > 0x1d) && (reg < 0x20 || reg > 0x22) &&
141 (reg < 0x26 || reg > 0x28) && reg != 0x33 && reg != 0x37 && 152 (reg < 0x26 || reg > 0x28) && reg != 0x33 && reg != 0x37 &&
142 (reg < 0x63 || reg > 0x7f) && reg != 0x81 && reg < 0xf0; 153 (reg < 0x63 || reg > 0x7f) && reg != 0x81 && reg < 0xf0;
@@ -214,7 +225,10 @@ static const unsigned char saa7111_init[] = {
214 0x00, 0x00 225 0x00, 0x00
215}; 226};
216 227
217/* SAA7113 init codes */ 228/* SAA7113/GM7113C init codes
229 * It's important that R_14... R_17 == 0x00
230 * for the gm7113c chip to deliver stable video
231 */
218static const unsigned char saa7113_init[] = { 232static const unsigned char saa7113_init[] = {
219 R_01_INC_DELAY, 0x08, 233 R_01_INC_DELAY, 0x08,
220 R_02_INPUT_CNTL_1, 0xc2, 234 R_02_INPUT_CNTL_1, 0xc2,
@@ -448,6 +462,24 @@ static const unsigned char saa7115_cfg_50hz_video[] = {
448 462
449/* ============== SAA7715 VIDEO templates (end) ======= */ 463/* ============== SAA7715 VIDEO templates (end) ======= */
450 464
465/* ============== GM7113C VIDEO templates ============= */
466static const unsigned char gm7113c_cfg_60hz_video[] = {
467 R_08_SYNC_CNTL, 0x68, /* 0xBO: auto detection, 0x68 = NTSC */
468 R_0E_CHROMA_CNTL_1, 0x07, /* video autodetection is on */
469
470 0x00, 0x00
471};
472
473static const unsigned char gm7113c_cfg_50hz_video[] = {
474 R_08_SYNC_CNTL, 0x28, /* 0x28 = PAL */
475 R_0E_CHROMA_CNTL_1, 0x07,
476
477 0x00, 0x00
478};
479
480/* ============== GM7113C VIDEO templates (end) ======= */
481
482
451static const unsigned char saa7115_cfg_vbi_on[] = { 483static const unsigned char saa7115_cfg_vbi_on[] = {
452 R_80_GLOBAL_CNTL_1, 0x00, /* reset tasks */ 484 R_80_GLOBAL_CNTL_1, 0x00, /* reset tasks */
453 R_88_POWER_SAVE_ADC_PORT_CNTL, 0xd0, /* reset scaler */ 485 R_88_POWER_SAVE_ADC_PORT_CNTL, 0xd0, /* reset scaler */
@@ -932,11 +964,17 @@ static void saa711x_set_v4lstd(struct v4l2_subdev *sd, v4l2_std_id std)
932 // This works for NTSC-M, SECAM-L and the 50Hz PAL variants. 964 // This works for NTSC-M, SECAM-L and the 50Hz PAL variants.
933 if (std & V4L2_STD_525_60) { 965 if (std & V4L2_STD_525_60) {
934 v4l2_dbg(1, debug, sd, "decoder set standard 60 Hz\n"); 966 v4l2_dbg(1, debug, sd, "decoder set standard 60 Hz\n");
935 saa711x_writeregs(sd, saa7115_cfg_60hz_video); 967 if (state->ident == GM7113C)
968 saa711x_writeregs(sd, gm7113c_cfg_60hz_video);
969 else
970 saa711x_writeregs(sd, saa7115_cfg_60hz_video);
936 saa711x_set_size(sd, 720, 480); 971 saa711x_set_size(sd, 720, 480);
937 } else { 972 } else {
938 v4l2_dbg(1, debug, sd, "decoder set standard 50 Hz\n"); 973 v4l2_dbg(1, debug, sd, "decoder set standard 50 Hz\n");
939 saa711x_writeregs(sd, saa7115_cfg_50hz_video); 974 if (state->ident == GM7113C)
975 saa711x_writeregs(sd, gm7113c_cfg_50hz_video);
976 else
977 saa711x_writeregs(sd, saa7115_cfg_50hz_video);
940 saa711x_set_size(sd, 720, 576); 978 saa711x_set_size(sd, 720, 576);
941 } 979 }
942 980
@@ -949,7 +987,8 @@ static void saa711x_set_v4lstd(struct v4l2_subdev *sd, v4l2_std_id std)
949 011 NTSC N (3.58MHz) PAL M (3.58MHz) 987 011 NTSC N (3.58MHz) PAL M (3.58MHz)
950 100 reserved NTSC-Japan (3.58MHz) 988 100 reserved NTSC-Japan (3.58MHz)
951 */ 989 */
952 if (state->ident <= V4L2_IDENT_SAA7113) { 990 if (state->ident <= SAA7113 ||
991 state->ident == GM7113C) {
953 u8 reg = saa711x_read(sd, R_0E_CHROMA_CNTL_1) & 0x8f; 992 u8 reg = saa711x_read(sd, R_0E_CHROMA_CNTL_1) & 0x8f;
954 993
955 if (std == V4L2_STD_PAL_M) { 994 if (std == V4L2_STD_PAL_M) {
@@ -968,9 +1007,8 @@ static void saa711x_set_v4lstd(struct v4l2_subdev *sd, v4l2_std_id std)
968 /* restart task B if needed */ 1007 /* restart task B if needed */
969 int taskb = saa711x_read(sd, R_80_GLOBAL_CNTL_1) & 0x10; 1008 int taskb = saa711x_read(sd, R_80_GLOBAL_CNTL_1) & 0x10;
970 1009
971 if (taskb && state->ident == V4L2_IDENT_SAA7114) { 1010 if (taskb && state->ident == SAA7114)
972 saa711x_writeregs(sd, saa7115_cfg_vbi_on); 1011 saa711x_writeregs(sd, saa7115_cfg_vbi_on);
973 }
974 1012
975 /* switch audio mode too! */ 1013 /* switch audio mode too! */
976 saa711x_s_clock_freq(sd, state->audclk_freq); 1014 saa711x_s_clock_freq(sd, state->audclk_freq);
@@ -992,7 +1030,7 @@ static void saa711x_set_lcr(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_forma
992 1030
993#else 1031#else
994 /* SAA7113 and SAA7118 also should support VBI - Need testing */ 1032 /* SAA7113 and SAA7118 also should support VBI - Need testing */
995 if (state->ident != V4L2_IDENT_SAA7115) 1033 if (state->ident != SAA7115)
996 return; 1034 return;
997#endif 1035#endif
998 1036
@@ -1214,13 +1252,14 @@ static int saa711x_s_routing(struct v4l2_subdev *sd,
1214 u32 input, u32 output, u32 config) 1252 u32 input, u32 output, u32 config)
1215{ 1253{
1216 struct saa711x_state *state = to_state(sd); 1254 struct saa711x_state *state = to_state(sd);
1217 u8 mask = (state->ident <= V4L2_IDENT_SAA7111A) ? 0xf8 : 0xf0; 1255 u8 mask = (state->ident <= SAA7111A) ? 0xf8 : 0xf0;
1218 1256
1219 v4l2_dbg(1, debug, sd, "decoder set input %d output %d\n", 1257 v4l2_dbg(1, debug, sd, "decoder set input %d output %d\n",
1220 input, output); 1258 input, output);
1221 1259
1222 /* saa7111/3 does not have these inputs */ 1260 /* saa7111/3 does not have these inputs */
1223 if (state->ident <= V4L2_IDENT_SAA7113 && 1261 if ((state->ident <= SAA7113 ||
1262 state->ident == GM7113C) &&
1224 (input == SAA7115_COMPOSITE4 || 1263 (input == SAA7115_COMPOSITE4 ||
1225 input == SAA7115_COMPOSITE5)) { 1264 input == SAA7115_COMPOSITE5)) {
1226 return -EINVAL; 1265 return -EINVAL;
@@ -1235,7 +1274,7 @@ static int saa711x_s_routing(struct v4l2_subdev *sd,
1235 state->input = input; 1274 state->input = input;
1236 1275
1237 /* saa7111 has slightly different input numbering */ 1276 /* saa7111 has slightly different input numbering */
1238 if (state->ident <= V4L2_IDENT_SAA7111A) { 1277 if (state->ident <= SAA7111A) {
1239 if (input >= SAA7115_COMPOSITE4) 1278 if (input >= SAA7115_COMPOSITE4)
1240 input -= 2; 1279 input -= 2;
1241 /* saa7111 specific */ 1280 /* saa7111 specific */
@@ -1258,13 +1297,13 @@ static int saa711x_s_routing(struct v4l2_subdev *sd,
1258 (state->input >= SAA7115_SVIDEO0 ? 0x80 : 0x0)); 1297 (state->input >= SAA7115_SVIDEO0 ? 0x80 : 0x0));
1259 1298
1260 state->output = output; 1299 state->output = output;
1261 if (state->ident == V4L2_IDENT_SAA7114 || 1300 if (state->ident == SAA7114 ||
1262 state->ident == V4L2_IDENT_SAA7115) { 1301 state->ident == SAA7115) {
1263 saa711x_write(sd, R_83_X_PORT_I_O_ENA_AND_OUT_CLK, 1302 saa711x_write(sd, R_83_X_PORT_I_O_ENA_AND_OUT_CLK,
1264 (saa711x_read(sd, R_83_X_PORT_I_O_ENA_AND_OUT_CLK) & 0xfe) | 1303 (saa711x_read(sd, R_83_X_PORT_I_O_ENA_AND_OUT_CLK) & 0xfe) |
1265 (state->output & 0x01)); 1304 (state->output & 0x01));
1266 } 1305 }
1267 if (state->ident > V4L2_IDENT_SAA7111A) { 1306 if (state->ident > SAA7111A) {
1268 if (config & SAA7115_IDQ_IS_DEFAULT) 1307 if (config & SAA7115_IDQ_IS_DEFAULT)
1269 saa711x_write(sd, R_85_I_PORT_SIGNAL_POLAR, 0x20); 1308 saa711x_write(sd, R_85_I_PORT_SIGNAL_POLAR, 0x20);
1270 else 1309 else
@@ -1277,7 +1316,7 @@ static int saa711x_s_gpio(struct v4l2_subdev *sd, u32 val)
1277{ 1316{
1278 struct saa711x_state *state = to_state(sd); 1317 struct saa711x_state *state = to_state(sd);
1279 1318
1280 if (state->ident > V4L2_IDENT_SAA7111A) 1319 if (state->ident > SAA7111A)
1281 return -EINVAL; 1320 return -EINVAL;
1282 saa711x_write(sd, 0x11, (saa711x_read(sd, 0x11) & 0x7f) | 1321 saa711x_write(sd, 0x11, (saa711x_read(sd, 0x11) & 0x7f) |
1283 (val ? 0x80 : 0)); 1322 (val ? 0x80 : 0));
@@ -1367,7 +1406,7 @@ static int saa711x_querystd(struct v4l2_subdev *sd, v4l2_std_id *std)
1367 1406
1368 reg1f = saa711x_read(sd, R_1F_STATUS_BYTE_2_VD_DEC); 1407 reg1f = saa711x_read(sd, R_1F_STATUS_BYTE_2_VD_DEC);
1369 1408
1370 if (state->ident == V4L2_IDENT_SAA7115) { 1409 if (state->ident == SAA7115) {
1371 reg1e = saa711x_read(sd, R_1E_STATUS_BYTE_1_VD_DEC); 1410 reg1e = saa711x_read(sd, R_1E_STATUS_BYTE_1_VD_DEC);
1372 1411
1373 v4l2_dbg(1, debug, sd, "Status byte 1 (0x1e)=0x%02x\n", reg1e); 1412 v4l2_dbg(1, debug, sd, "Status byte 1 (0x1e)=0x%02x\n", reg1e);
@@ -1389,6 +1428,7 @@ static int saa711x_querystd(struct v4l2_subdev *sd, v4l2_std_id *std)
1389 *std &= V4L2_STD_SECAM; 1428 *std &= V4L2_STD_SECAM;
1390 break; 1429 break;
1391 default: 1430 default:
1431 *std = V4L2_STD_UNKNOWN;
1392 /* Can't detect anything */ 1432 /* Can't detect anything */
1393 break; 1433 break;
1394 } 1434 }
@@ -1397,8 +1437,10 @@ static int saa711x_querystd(struct v4l2_subdev *sd, v4l2_std_id *std)
1397 v4l2_dbg(1, debug, sd, "Status byte 2 (0x1f)=0x%02x\n", reg1f); 1437 v4l2_dbg(1, debug, sd, "Status byte 2 (0x1f)=0x%02x\n", reg1f);
1398 1438
1399 /* horizontal/vertical not locked */ 1439 /* horizontal/vertical not locked */
1400 if (reg1f & 0x40) 1440 if (reg1f & 0x40) {
1441 *std = V4L2_STD_UNKNOWN;
1401 goto ret; 1442 goto ret;
1443 }
1402 1444
1403 if (reg1f & 0x20) 1445 if (reg1f & 0x20)
1404 *std &= V4L2_STD_525_60; 1446 *std &= V4L2_STD_525_60;
@@ -1418,7 +1460,7 @@ static int saa711x_g_input_status(struct v4l2_subdev *sd, u32 *status)
1418 int reg1f; 1460 int reg1f;
1419 1461
1420 *status = V4L2_IN_ST_NO_SIGNAL; 1462 *status = V4L2_IN_ST_NO_SIGNAL;
1421 if (state->ident == V4L2_IDENT_SAA7115) 1463 if (state->ident == SAA7115)
1422 reg1e = saa711x_read(sd, R_1E_STATUS_BYTE_1_VD_DEC); 1464 reg1e = saa711x_read(sd, R_1E_STATUS_BYTE_1_VD_DEC);
1423 reg1f = saa711x_read(sd, R_1F_STATUS_BYTE_2_VD_DEC); 1465 reg1f = saa711x_read(sd, R_1F_STATUS_BYTE_2_VD_DEC);
1424 if ((reg1f & 0xc1) == 0x81 && (reg1e & 0xc0) == 0x80) 1466 if ((reg1f & 0xc1) == 0x81 && (reg1e & 0xc0) == 0x80)
@@ -1429,12 +1471,6 @@ static int saa711x_g_input_status(struct v4l2_subdev *sd, u32 *status)
1429#ifdef CONFIG_VIDEO_ADV_DEBUG 1471#ifdef CONFIG_VIDEO_ADV_DEBUG
1430static int saa711x_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 1472static int saa711x_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
1431{ 1473{
1432 struct i2c_client *client = v4l2_get_subdevdata(sd);
1433
1434 if (!v4l2_chip_match_i2c_client(client, &reg->match))
1435 return -EINVAL;
1436 if (!capable(CAP_SYS_ADMIN))
1437 return -EPERM;
1438 reg->val = saa711x_read(sd, reg->reg & 0xff); 1474 reg->val = saa711x_read(sd, reg->reg & 0xff);
1439 reg->size = 1; 1475 reg->size = 1;
1440 return 0; 1476 return 0;
@@ -1442,25 +1478,11 @@ static int saa711x_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *
1442 1478
1443static int saa711x_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg) 1479static int saa711x_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
1444{ 1480{
1445 struct i2c_client *client = v4l2_get_subdevdata(sd);
1446
1447 if (!v4l2_chip_match_i2c_client(client, &reg->match))
1448 return -EINVAL;
1449 if (!capable(CAP_SYS_ADMIN))
1450 return -EPERM;
1451 saa711x_write(sd, reg->reg & 0xff, reg->val & 0xff); 1481 saa711x_write(sd, reg->reg & 0xff, reg->val & 0xff);
1452 return 0; 1482 return 0;
1453} 1483}
1454#endif 1484#endif
1455 1485
1456static int saa711x_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
1457{
1458 struct saa711x_state *state = to_state(sd);
1459 struct i2c_client *client = v4l2_get_subdevdata(sd);
1460
1461 return v4l2_chip_ident_i2c_client(client, chip, state->ident, 0);
1462}
1463
1464static int saa711x_log_status(struct v4l2_subdev *sd) 1486static int saa711x_log_status(struct v4l2_subdev *sd)
1465{ 1487{
1466 struct saa711x_state *state = to_state(sd); 1488 struct saa711x_state *state = to_state(sd);
@@ -1469,7 +1491,7 @@ static int saa711x_log_status(struct v4l2_subdev *sd)
1469 int vcr; 1491 int vcr;
1470 1492
1471 v4l2_info(sd, "Audio frequency: %d Hz\n", state->audclk_freq); 1493 v4l2_info(sd, "Audio frequency: %d Hz\n", state->audclk_freq);
1472 if (state->ident != V4L2_IDENT_SAA7115) { 1494 if (state->ident != SAA7115) {
1473 /* status for the saa7114 */ 1495 /* status for the saa7114 */
1474 reg1f = saa711x_read(sd, R_1F_STATUS_BYTE_2_VD_DEC); 1496 reg1f = saa711x_read(sd, R_1F_STATUS_BYTE_2_VD_DEC);
1475 signalOk = (reg1f & 0xc1) == 0x81; 1497 signalOk = (reg1f & 0xc1) == 0x81;
@@ -1520,7 +1542,6 @@ static const struct v4l2_ctrl_ops saa711x_ctrl_ops = {
1520 1542
1521static const struct v4l2_subdev_core_ops saa711x_core_ops = { 1543static const struct v4l2_subdev_core_ops saa711x_core_ops = {
1522 .log_status = saa711x_log_status, 1544 .log_status = saa711x_log_status,
1523 .g_chip_ident = saa711x_g_chip_ident,
1524 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls, 1545 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls,
1525 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, 1546 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls,
1526 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls, 1547 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls,
@@ -1571,55 +1592,145 @@ static const struct v4l2_subdev_ops saa711x_ops = {
1571 .vbi = &saa711x_vbi_ops, 1592 .vbi = &saa711x_vbi_ops,
1572}; 1593};
1573 1594
1595#define CHIP_VER_SIZE 16
1596
1574/* ----------------------------------------------------------------------- */ 1597/* ----------------------------------------------------------------------- */
1575 1598
1576static int saa711x_probe(struct i2c_client *client, 1599/**
1577 const struct i2c_device_id *id) 1600 * saa711x_detect_chip - Detects the saa711x (or clone) variant
1601 * @client: I2C client structure.
1602 * @id: I2C device ID structure.
1603 * @name: Name of the device to be filled.
1604 *
1605 * Detects the Philips/NXP saa711x chip, or some clone of it.
1606 * if 'id' is NULL or id->driver_data is equal to 1, it auto-probes
1607 * the analog demod.
1608 * If the tuner is not found, it returns -ENODEV.
1609 * If auto-detection is disabled and the tuner doesn't match what it was
1610 * requred, it returns -EINVAL and fills 'name'.
1611 * If the chip is found, it returns the chip ID and fills 'name'.
1612 */
1613static int saa711x_detect_chip(struct i2c_client *client,
1614 const struct i2c_device_id *id,
1615 char *name)
1578{ 1616{
1579 struct saa711x_state *state; 1617 char chip_ver[CHIP_VER_SIZE];
1580 struct v4l2_subdev *sd;
1581 struct v4l2_ctrl_handler *hdl;
1582 int i;
1583 char name[17];
1584 char chip_id; 1618 char chip_id;
1585 int autodetect = !id || id->driver_data == 1; 1619 int i;
1620 int autodetect;
1586 1621
1587 /* Check if the adapter supports the needed features */ 1622 autodetect = !id || id->driver_data == 1;
1588 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
1589 return -EIO;
1590 1623
1591 for (i = 0; i < 0x0f; i++) { 1624 /* Read the chip version register */
1625 for (i = 0; i < CHIP_VER_SIZE; i++) {
1592 i2c_smbus_write_byte_data(client, 0, i); 1626 i2c_smbus_write_byte_data(client, 0, i);
1593 name[i] = (i2c_smbus_read_byte_data(client, 0) & 0x0f) + '0'; 1627 chip_ver[i] = i2c_smbus_read_byte_data(client, 0);
1628 name[i] = (chip_ver[i] & 0x0f) + '0';
1594 if (name[i] > '9') 1629 if (name[i] > '9')
1595 name[i] += 'a' - '9' - 1; 1630 name[i] += 'a' - '9' - 1;
1596 } 1631 }
1597 name[i] = '\0'; 1632 name[i] = '\0';
1598 1633
1599 chip_id = name[5]; 1634 /* Check if it is a Philips/NXP chip */
1635 if (!memcmp(name + 1, "f711", 4)) {
1636 chip_id = name[5];
1637 snprintf(name, CHIP_VER_SIZE, "saa711%c", chip_id);
1600 1638
1601 /* Check whether this chip is part of the saa711x series */ 1639 if (!autodetect && strcmp(name, id->name))
1602 if (memcmp(name + 1, "f711", 4)) { 1640 return -EINVAL;
1603 v4l_dbg(1, debug, client, "chip found @ 0x%x (ID %s) does not match a known saa711x chip.\n", 1641
1604 client->addr << 1, name); 1642 switch (chip_id) {
1605 return -ENODEV; 1643 case '1':
1644 if (chip_ver[0] & 0xf0) {
1645 snprintf(name, CHIP_VER_SIZE, "saa711%ca", chip_id);
1646 v4l_info(client, "saa7111a variant found\n");
1647 return SAA7111A;
1648 }
1649 return SAA7111;
1650 case '3':
1651 return SAA7113;
1652 case '4':
1653 return SAA7114;
1654 case '5':
1655 return SAA7115;
1656 case '8':
1657 return SAA7118;
1658 default:
1659 v4l2_info(client,
1660 "WARNING: Philips/NXP chip unknown - Falling back to saa7111\n");
1661 return SAA7111;
1662 }
1606 } 1663 }
1607 1664
1608 /* Safety check */ 1665 /* Check if it is a gm7113c */
1609 if (!autodetect && id->name[6] != chip_id) { 1666 if (!memcmp(name, "0000", 4)) {
1610 v4l_warn(client, "found saa711%c while %s was expected\n", 1667 chip_id = 0;
1611 chip_id, id->name); 1668 for (i = 0; i < 4; i++) {
1669 chip_id = chip_id << 1;
1670 chip_id |= (chip_ver[i] & 0x80) ? 1 : 0;
1671 }
1672
1673 /*
1674 * Note: From the datasheet, only versions 1 and 2
1675 * exists. However, tests on a device labeled as:
1676 * "GM7113C 1145" returned "10" on all 16 chip
1677 * version (reg 0x00) reads. So, we need to also
1678 * accept at least verion 0. For now, let's just
1679 * assume that a device that returns "0000" for
1680 * the lower nibble is a gm7113c.
1681 */
1682
1683 strlcpy(name, "gm7113c", CHIP_VER_SIZE);
1684
1685 if (!autodetect && strcmp(name, id->name))
1686 return -EINVAL;
1687
1688 v4l_dbg(1, debug, client,
1689 "It seems to be a %s chip (%*ph) @ 0x%x.\n",
1690 name, 16, chip_ver, client->addr << 1);
1691
1692 return GM7113C;
1612 } 1693 }
1613 snprintf(client->name, sizeof(client->name), "saa711%c", chip_id);
1614 v4l_info(client, "saa711%c found (%s) @ 0x%x (%s)\n", chip_id, name,
1615 client->addr << 1, client->adapter->name);
1616 1694
1617 state = kzalloc(sizeof(struct saa711x_state), GFP_KERNEL); 1695 /* Chip was not discovered. Return its ID and don't bind */
1696 v4l_dbg(1, debug, client, "chip %*ph @ 0x%x is unknown.\n",
1697 16, chip_ver, client->addr << 1);
1698 return -ENODEV;
1699}
1700
1701static int saa711x_probe(struct i2c_client *client,
1702 const struct i2c_device_id *id)
1703{
1704 struct saa711x_state *state;
1705 struct v4l2_subdev *sd;
1706 struct v4l2_ctrl_handler *hdl;
1707 int ident;
1708 char name[CHIP_VER_SIZE + 1];
1709
1710 /* Check if the adapter supports the needed features */
1711 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
1712 return -EIO;
1713
1714 ident = saa711x_detect_chip(client, id, name);
1715 if (ident == -EINVAL) {
1716 /* Chip exists, but doesn't match */
1717 v4l_warn(client, "found %s while %s was expected\n",
1718 name, id->name);
1719 return -ENODEV;
1720 }
1721 if (ident < 0)
1722 return ident;
1723
1724 strlcpy(client->name, name, sizeof(client->name));
1725
1726 state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL);
1618 if (state == NULL) 1727 if (state == NULL)
1619 return -ENOMEM; 1728 return -ENOMEM;
1620 sd = &state->sd; 1729 sd = &state->sd;
1621 v4l2_i2c_subdev_init(sd, client, &saa711x_ops); 1730 v4l2_i2c_subdev_init(sd, client, &saa711x_ops);
1622 1731
1732 v4l_info(client, "%s found @ 0x%x (%s)\n", name,
1733 client->addr << 1, client->adapter->name);
1623 hdl = &state->hdl; 1734 hdl = &state->hdl;
1624 v4l2_ctrl_handler_init(hdl, 6); 1735 v4l2_ctrl_handler_init(hdl, 6);
1625 /* add in ascending ID order */ 1736 /* add in ascending ID order */
@@ -1640,7 +1751,6 @@ static int saa711x_probe(struct i2c_client *client,
1640 int err = hdl->error; 1751 int err = hdl->error;
1641 1752
1642 v4l2_ctrl_handler_free(hdl); 1753 v4l2_ctrl_handler_free(hdl);
1643 kfree(state);
1644 return err; 1754 return err;
1645 } 1755 }
1646 v4l2_ctrl_auto_cluster(2, &state->agc, 0, true); 1756 v4l2_ctrl_auto_cluster(2, &state->agc, 0, true);
@@ -1649,31 +1759,7 @@ static int saa711x_probe(struct i2c_client *client,
1649 state->output = SAA7115_IPORT_ON; 1759 state->output = SAA7115_IPORT_ON;
1650 state->enable = 1; 1760 state->enable = 1;
1651 state->radio = 0; 1761 state->radio = 0;
1652 switch (chip_id) { 1762 state->ident = ident;
1653 case '1':
1654 state->ident = V4L2_IDENT_SAA7111;
1655 if (saa711x_read(sd, R_00_CHIP_VERSION) & 0xf0) {
1656 v4l_info(client, "saa7111a variant found\n");
1657 state->ident = V4L2_IDENT_SAA7111A;
1658 }
1659 break;
1660 case '3':
1661 state->ident = V4L2_IDENT_SAA7113;
1662 break;
1663 case '4':
1664 state->ident = V4L2_IDENT_SAA7114;
1665 break;
1666 case '5':
1667 state->ident = V4L2_IDENT_SAA7115;
1668 break;
1669 case '8':
1670 state->ident = V4L2_IDENT_SAA7118;
1671 break;
1672 default:
1673 state->ident = V4L2_IDENT_SAA7111;
1674 v4l2_info(sd, "WARNING: Chip is not known - Falling back to saa7111\n");
1675 break;
1676 }
1677 1763
1678 state->audclk_freq = 48000; 1764 state->audclk_freq = 48000;
1679 1765
@@ -1682,18 +1768,19 @@ static int saa711x_probe(struct i2c_client *client,
1682 /* init to 60hz/48khz */ 1768 /* init to 60hz/48khz */
1683 state->crystal_freq = SAA7115_FREQ_24_576_MHZ; 1769 state->crystal_freq = SAA7115_FREQ_24_576_MHZ;
1684 switch (state->ident) { 1770 switch (state->ident) {
1685 case V4L2_IDENT_SAA7111: 1771 case SAA7111:
1686 case V4L2_IDENT_SAA7111A: 1772 case SAA7111A:
1687 saa711x_writeregs(sd, saa7111_init); 1773 saa711x_writeregs(sd, saa7111_init);
1688 break; 1774 break;
1689 case V4L2_IDENT_SAA7113: 1775 case GM7113C:
1776 case SAA7113:
1690 saa711x_writeregs(sd, saa7113_init); 1777 saa711x_writeregs(sd, saa7113_init);
1691 break; 1778 break;
1692 default: 1779 default:
1693 state->crystal_freq = SAA7115_FREQ_32_11_MHZ; 1780 state->crystal_freq = SAA7115_FREQ_32_11_MHZ;
1694 saa711x_writeregs(sd, saa7115_init_auto_input); 1781 saa711x_writeregs(sd, saa7115_init_auto_input);
1695 } 1782 }
1696 if (state->ident > V4L2_IDENT_SAA7111A) 1783 if (state->ident > SAA7111A)
1697 saa711x_writeregs(sd, saa7115_init_misc); 1784 saa711x_writeregs(sd, saa7115_init_misc);
1698 saa711x_set_v4lstd(sd, V4L2_STD_NTSC); 1785 saa711x_set_v4lstd(sd, V4L2_STD_NTSC);
1699 v4l2_ctrl_handler_setup(hdl); 1786 v4l2_ctrl_handler_setup(hdl);
@@ -1712,7 +1799,6 @@ static int saa711x_remove(struct i2c_client *client)
1712 1799
1713 v4l2_device_unregister_subdev(sd); 1800 v4l2_device_unregister_subdev(sd);
1714 v4l2_ctrl_handler_free(sd->ctrl_handler); 1801 v4l2_ctrl_handler_free(sd->ctrl_handler);
1715 kfree(to_state(sd));
1716 return 0; 1802 return 0;
1717} 1803}
1718 1804
@@ -1723,6 +1809,7 @@ static const struct i2c_device_id saa711x_id[] = {
1723 { "saa7114", 0 }, 1809 { "saa7114", 0 },
1724 { "saa7115", 0 }, 1810 { "saa7115", 0 },
1725 { "saa7118", 0 }, 1811 { "saa7118", 0 },
1812 { "gm7113c", 0 },
1726 { } 1813 { }
1727}; 1814};
1728MODULE_DEVICE_TABLE(i2c, saa711x_id); 1815MODULE_DEVICE_TABLE(i2c, saa711x_id);
diff --git a/drivers/media/i2c/saa7127.c b/drivers/media/i2c/saa7127.c
index 8a47ac10927f..264b755bedce 100644
--- a/drivers/media/i2c/saa7127.c
+++ b/drivers/media/i2c/saa7127.c
@@ -54,7 +54,6 @@
54#include <linux/i2c.h> 54#include <linux/i2c.h>
55#include <linux/videodev2.h> 55#include <linux/videodev2.h>
56#include <media/v4l2-device.h> 56#include <media/v4l2-device.h>
57#include <media/v4l2-chip-ident.h>
58#include <media/saa7127.h> 57#include <media/saa7127.h>
59 58
60static int debug; 59static int debug;
@@ -251,10 +250,15 @@ static struct i2c_reg_value saa7127_init_config_50hz_secam[] = {
251 ********************************************************************** 250 **********************************************************************
252 */ 251 */
253 252
253enum saa712x_model {
254 SAA7127,
255 SAA7129,
256};
257
254struct saa7127_state { 258struct saa7127_state {
255 struct v4l2_subdev sd; 259 struct v4l2_subdev sd;
256 v4l2_std_id std; 260 v4l2_std_id std;
257 u32 ident; 261 enum saa712x_model ident;
258 enum saa7127_input_type input_type; 262 enum saa7127_input_type input_type;
259 enum saa7127_output_type output_type; 263 enum saa7127_output_type output_type;
260 int video_enable; 264 int video_enable;
@@ -482,7 +486,7 @@ static int saa7127_set_std(struct v4l2_subdev *sd, v4l2_std_id std)
482 inittab = saa7127_init_config_60hz; 486 inittab = saa7127_init_config_60hz;
483 state->reg_61 = SAA7127_60HZ_DAC_CONTROL; 487 state->reg_61 = SAA7127_60HZ_DAC_CONTROL;
484 488
485 } else if (state->ident == V4L2_IDENT_SAA7129 && 489 } else if (state->ident == SAA7129 &&
486 (std & V4L2_STD_SECAM) && 490 (std & V4L2_STD_SECAM) &&
487 !(std & (V4L2_STD_625_50 & ~V4L2_STD_SECAM))) { 491 !(std & (V4L2_STD_625_50 & ~V4L2_STD_SECAM))) {
488 492
@@ -517,7 +521,7 @@ static int saa7127_set_output_type(struct v4l2_subdev *sd, int output)
517 break; 521 break;
518 522
519 case SAA7127_OUTPUT_TYPE_COMPOSITE: 523 case SAA7127_OUTPUT_TYPE_COMPOSITE:
520 if (state->ident == V4L2_IDENT_SAA7129) 524 if (state->ident == SAA7129)
521 state->reg_2d = 0x20; /* CVBS only */ 525 state->reg_2d = 0x20; /* CVBS only */
522 else 526 else
523 state->reg_2d = 0x08; /* 00001000 CVBS only, RGB DAC's off (high impedance mode) */ 527 state->reg_2d = 0x08; /* 00001000 CVBS only, RGB DAC's off (high impedance mode) */
@@ -525,7 +529,7 @@ static int saa7127_set_output_type(struct v4l2_subdev *sd, int output)
525 break; 529 break;
526 530
527 case SAA7127_OUTPUT_TYPE_SVIDEO: 531 case SAA7127_OUTPUT_TYPE_SVIDEO:
528 if (state->ident == V4L2_IDENT_SAA7129) 532 if (state->ident == SAA7129)
529 state->reg_2d = 0x18; /* Y + C */ 533 state->reg_2d = 0x18; /* Y + C */
530 else 534 else
531 state->reg_2d = 0xff; /*11111111 croma -> R, luma -> CVBS + G + B */ 535 state->reg_2d = 0xff; /*11111111 croma -> R, luma -> CVBS + G + B */
@@ -543,7 +547,7 @@ static int saa7127_set_output_type(struct v4l2_subdev *sd, int output)
543 break; 547 break;
544 548
545 case SAA7127_OUTPUT_TYPE_BOTH: 549 case SAA7127_OUTPUT_TYPE_BOTH:
546 if (state->ident == V4L2_IDENT_SAA7129) 550 if (state->ident == SAA7129)
547 state->reg_2d = 0x38; 551 state->reg_2d = 0x38;
548 else 552 else
549 state->reg_2d = 0xbf; 553 state->reg_2d = 0xbf;
@@ -661,12 +665,6 @@ static int saa7127_s_vbi_data(struct v4l2_subdev *sd, const struct v4l2_sliced_v
661#ifdef CONFIG_VIDEO_ADV_DEBUG 665#ifdef CONFIG_VIDEO_ADV_DEBUG
662static int saa7127_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 666static int saa7127_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
663{ 667{
664 struct i2c_client *client = v4l2_get_subdevdata(sd);
665
666 if (!v4l2_chip_match_i2c_client(client, &reg->match))
667 return -EINVAL;
668 if (!capable(CAP_SYS_ADMIN))
669 return -EPERM;
670 reg->val = saa7127_read(sd, reg->reg & 0xff); 668 reg->val = saa7127_read(sd, reg->reg & 0xff);
671 reg->size = 1; 669 reg->size = 1;
672 return 0; 670 return 0;
@@ -674,25 +672,11 @@ static int saa7127_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *
674 672
675static int saa7127_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg) 673static int saa7127_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
676{ 674{
677 struct i2c_client *client = v4l2_get_subdevdata(sd);
678
679 if (!v4l2_chip_match_i2c_client(client, &reg->match))
680 return -EINVAL;
681 if (!capable(CAP_SYS_ADMIN))
682 return -EPERM;
683 saa7127_write(sd, reg->reg & 0xff, reg->val & 0xff); 675 saa7127_write(sd, reg->reg & 0xff, reg->val & 0xff);
684 return 0; 676 return 0;
685} 677}
686#endif 678#endif
687 679
688static int saa7127_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
689{
690 struct saa7127_state *state = to_state(sd);
691 struct i2c_client *client = v4l2_get_subdevdata(sd);
692
693 return v4l2_chip_ident_i2c_client(client, chip, state->ident, 0);
694}
695
696static int saa7127_log_status(struct v4l2_subdev *sd) 680static int saa7127_log_status(struct v4l2_subdev *sd)
697{ 681{
698 struct saa7127_state *state = to_state(sd); 682 struct saa7127_state *state = to_state(sd);
@@ -712,7 +696,6 @@ static int saa7127_log_status(struct v4l2_subdev *sd)
712 696
713static const struct v4l2_subdev_core_ops saa7127_core_ops = { 697static const struct v4l2_subdev_core_ops saa7127_core_ops = {
714 .log_status = saa7127_log_status, 698 .log_status = saa7127_log_status,
715 .g_chip_ident = saa7127_g_chip_ident,
716#ifdef CONFIG_VIDEO_ADV_DEBUG 699#ifdef CONFIG_VIDEO_ADV_DEBUG
717 .g_register = saa7127_g_register, 700 .g_register = saa7127_g_register,
718 .s_register = saa7127_s_register, 701 .s_register = saa7127_s_register,
@@ -752,7 +735,7 @@ static int saa7127_probe(struct i2c_client *client,
752 v4l_dbg(1, debug, client, "detecting saa7127 client on address 0x%x\n", 735 v4l_dbg(1, debug, client, "detecting saa7127 client on address 0x%x\n",
753 client->addr << 1); 736 client->addr << 1);
754 737
755 state = kzalloc(sizeof(struct saa7127_state), GFP_KERNEL); 738 state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL);
756 if (state == NULL) 739 if (state == NULL)
757 return -ENOMEM; 740 return -ENOMEM;
758 741
@@ -767,7 +750,6 @@ static int saa7127_probe(struct i2c_client *client,
767 if ((saa7127_read(sd, 0) & 0xe4) != 0 || 750 if ((saa7127_read(sd, 0) & 0xe4) != 0 ||
768 (saa7127_read(sd, 0x29) & 0x3f) != 0x1d) { 751 (saa7127_read(sd, 0x29) & 0x3f) != 0x1d) {
769 v4l2_dbg(1, debug, sd, "saa7127 not found\n"); 752 v4l2_dbg(1, debug, sd, "saa7127 not found\n");
770 kfree(state);
771 return -ENODEV; 753 return -ENODEV;
772 } 754 }
773 755
@@ -782,10 +764,10 @@ static int saa7127_probe(struct i2c_client *client,
782 if (saa7127_read(sd, SAA7129_REG_FADE_KEY_COL2) == 0xaa) { 764 if (saa7127_read(sd, SAA7129_REG_FADE_KEY_COL2) == 0xaa) {
783 saa7127_write(sd, SAA7129_REG_FADE_KEY_COL2, 765 saa7127_write(sd, SAA7129_REG_FADE_KEY_COL2,
784 read_result); 766 read_result);
785 state->ident = V4L2_IDENT_SAA7129; 767 state->ident = SAA7129;
786 strlcpy(client->name, "saa7129", I2C_NAME_SIZE); 768 strlcpy(client->name, "saa7129", I2C_NAME_SIZE);
787 } else { 769 } else {
788 state->ident = V4L2_IDENT_SAA7127; 770 state->ident = SAA7127;
789 strlcpy(client->name, "saa7127", I2C_NAME_SIZE); 771 strlcpy(client->name, "saa7127", I2C_NAME_SIZE);
790 } 772 }
791 } 773 }
@@ -809,7 +791,7 @@ static int saa7127_probe(struct i2c_client *client,
809 saa7127_set_input_type(sd, SAA7127_INPUT_TYPE_NORMAL); 791 saa7127_set_input_type(sd, SAA7127_INPUT_TYPE_NORMAL);
810 saa7127_set_video_enable(sd, 1); 792 saa7127_set_video_enable(sd, 1);
811 793
812 if (state->ident == V4L2_IDENT_SAA7129) 794 if (state->ident == SAA7129)
813 saa7127_write_inittab(sd, saa7129_init_config_extra); 795 saa7127_write_inittab(sd, saa7129_init_config_extra);
814 return 0; 796 return 0;
815} 797}
@@ -823,7 +805,6 @@ static int saa7127_remove(struct i2c_client *client)
823 v4l2_device_unregister_subdev(sd); 805 v4l2_device_unregister_subdev(sd);
824 /* Turn off TV output */ 806 /* Turn off TV output */
825 saa7127_set_video_enable(sd, 0); 807 saa7127_set_video_enable(sd, 0);
826 kfree(to_state(sd));
827 return 0; 808 return 0;
828} 809}
829 810
@@ -831,10 +812,10 @@ static int saa7127_remove(struct i2c_client *client)
831 812
832static struct i2c_device_id saa7127_id[] = { 813static struct i2c_device_id saa7127_id[] = {
833 { "saa7127_auto", 0 }, /* auto-detection */ 814 { "saa7127_auto", 0 }, /* auto-detection */
834 { "saa7126", V4L2_IDENT_SAA7127 }, 815 { "saa7126", SAA7127 },
835 { "saa7127", V4L2_IDENT_SAA7127 }, 816 { "saa7127", SAA7127 },
836 { "saa7128", V4L2_IDENT_SAA7129 }, 817 { "saa7128", SAA7129 },
837 { "saa7129", V4L2_IDENT_SAA7129 }, 818 { "saa7129", SAA7129 },
838 { } 819 { }
839}; 820};
840MODULE_DEVICE_TABLE(i2c, saa7127_id); 821MODULE_DEVICE_TABLE(i2c, saa7127_id);
diff --git a/drivers/media/i2c/saa717x.c b/drivers/media/i2c/saa717x.c
index cf3a0aa7e45e..401ca114ab99 100644
--- a/drivers/media/i2c/saa717x.c
+++ b/drivers/media/i2c/saa717x.c
@@ -977,12 +977,6 @@ static int saa717x_s_video_routing(struct v4l2_subdev *sd,
977#ifdef CONFIG_VIDEO_ADV_DEBUG 977#ifdef CONFIG_VIDEO_ADV_DEBUG
978static int saa717x_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 978static int saa717x_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
979{ 979{
980 struct i2c_client *client = v4l2_get_subdevdata(sd);
981
982 if (!v4l2_chip_match_i2c_client(client, &reg->match))
983 return -EINVAL;
984 if (!capable(CAP_SYS_ADMIN))
985 return -EPERM;
986 reg->val = saa717x_read(sd, reg->reg); 980 reg->val = saa717x_read(sd, reg->reg);
987 reg->size = 1; 981 reg->size = 1;
988 return 0; 982 return 0;
@@ -990,14 +984,9 @@ static int saa717x_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *
990 984
991static int saa717x_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg) 985static int saa717x_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
992{ 986{
993 struct i2c_client *client = v4l2_get_subdevdata(sd);
994 u16 addr = reg->reg & 0xffff; 987 u16 addr = reg->reg & 0xffff;
995 u8 val = reg->val & 0xff; 988 u8 val = reg->val & 0xff;
996 989
997 if (!v4l2_chip_match_i2c_client(client, &reg->match))
998 return -EINVAL;
999 if (!capable(CAP_SYS_ADMIN))
1000 return -EPERM;
1001 saa717x_write(sd, addr, val); 990 saa717x_write(sd, addr, val);
1002 return 0; 991 return 0;
1003} 992}
@@ -1262,7 +1251,7 @@ static int saa717x_probe(struct i2c_client *client,
1262 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 1251 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
1263 return -EIO; 1252 return -EIO;
1264 1253
1265 decoder = kzalloc(sizeof(struct saa717x_state), GFP_KERNEL); 1254 decoder = devm_kzalloc(&client->dev, sizeof(*decoder), GFP_KERNEL);
1266 if (decoder == NULL) 1255 if (decoder == NULL)
1267 return -ENOMEM; 1256 return -ENOMEM;
1268 1257
@@ -1276,7 +1265,6 @@ static int saa717x_probe(struct i2c_client *client,
1276 id = saa717x_read(sd, 0x5a0); 1265 id = saa717x_read(sd, 0x5a0);
1277 if (id != 0xc2 && id != 0x32 && id != 0xf2 && id != 0x6c) { 1266 if (id != 0xc2 && id != 0x32 && id != 0xf2 && id != 0x6c) {
1278 v4l2_dbg(1, debug, sd, "saa717x not found (id=%02x)\n", id); 1267 v4l2_dbg(1, debug, sd, "saa717x not found (id=%02x)\n", id);
1279 kfree(decoder);
1280 return -ENODEV; 1268 return -ENODEV;
1281 } 1269 }
1282 if (id == 0xc2) 1270 if (id == 0xc2)
@@ -1316,7 +1304,6 @@ static int saa717x_probe(struct i2c_client *client,
1316 int err = hdl->error; 1304 int err = hdl->error;
1317 1305
1318 v4l2_ctrl_handler_free(hdl); 1306 v4l2_ctrl_handler_free(hdl);
1319 kfree(decoder);
1320 return err; 1307 return err;
1321 } 1308 }
1322 1309
@@ -1353,7 +1340,6 @@ static int saa717x_remove(struct i2c_client *client)
1353 1340
1354 v4l2_device_unregister_subdev(sd); 1341 v4l2_device_unregister_subdev(sd);
1355 v4l2_ctrl_handler_free(sd->ctrl_handler); 1342 v4l2_ctrl_handler_free(sd->ctrl_handler);
1356 kfree(to_state(sd));
1357 return 0; 1343 return 0;
1358} 1344}
1359 1345
diff --git a/drivers/media/i2c/saa7185.c b/drivers/media/i2c/saa7185.c
index 2c6b65c76e2b..f56c1c88b27d 100644
--- a/drivers/media/i2c/saa7185.c
+++ b/drivers/media/i2c/saa7185.c
@@ -32,7 +32,6 @@
32#include <linux/i2c.h> 32#include <linux/i2c.h>
33#include <linux/videodev2.h> 33#include <linux/videodev2.h>
34#include <media/v4l2-device.h> 34#include <media/v4l2-device.h>
35#include <media/v4l2-chip-ident.h>
36 35
37MODULE_DESCRIPTION("Philips SAA7185 video encoder driver"); 36MODULE_DESCRIPTION("Philips SAA7185 video encoder driver");
38MODULE_AUTHOR("Dave Perks"); 37MODULE_AUTHOR("Dave Perks");
@@ -285,17 +284,9 @@ static int saa7185_s_routing(struct v4l2_subdev *sd,
285 return 0; 284 return 0;
286} 285}
287 286
288static int saa7185_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
289{
290 struct i2c_client *client = v4l2_get_subdevdata(sd);
291
292 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_SAA7185, 0);
293}
294
295/* ----------------------------------------------------------------------- */ 287/* ----------------------------------------------------------------------- */
296 288
297static const struct v4l2_subdev_core_ops saa7185_core_ops = { 289static const struct v4l2_subdev_core_ops saa7185_core_ops = {
298 .g_chip_ident = saa7185_g_chip_ident,
299 .init = saa7185_init, 290 .init = saa7185_init,
300}; 291};
301 292
@@ -326,7 +317,7 @@ static int saa7185_probe(struct i2c_client *client,
326 v4l_info(client, "chip found @ 0x%x (%s)\n", 317 v4l_info(client, "chip found @ 0x%x (%s)\n",
327 client->addr << 1, client->adapter->name); 318 client->addr << 1, client->adapter->name);
328 319
329 encoder = kzalloc(sizeof(struct saa7185), GFP_KERNEL); 320 encoder = devm_kzalloc(&client->dev, sizeof(*encoder), GFP_KERNEL);
330 if (encoder == NULL) 321 if (encoder == NULL)
331 return -ENOMEM; 322 return -ENOMEM;
332 encoder->norm = V4L2_STD_NTSC; 323 encoder->norm = V4L2_STD_NTSC;
@@ -352,7 +343,6 @@ static int saa7185_remove(struct i2c_client *client)
352 v4l2_device_unregister_subdev(sd); 343 v4l2_device_unregister_subdev(sd);
353 /* SW: output off is active */ 344 /* SW: output off is active */
354 saa7185_write(sd, 0x61, (encoder->reg[0x61]) | 0x40); 345 saa7185_write(sd, 0x61, (encoder->reg[0x61]) | 0x40);
355 kfree(encoder);
356 return 0; 346 return 0;
357} 347}
358 348
diff --git a/drivers/media/i2c/saa7191.c b/drivers/media/i2c/saa7191.c
index d7d1670e0ca3..606a4baf944d 100644
--- a/drivers/media/i2c/saa7191.c
+++ b/drivers/media/i2c/saa7191.c
@@ -22,7 +22,6 @@
22#include <linux/videodev2.h> 22#include <linux/videodev2.h>
23#include <linux/i2c.h> 23#include <linux/i2c.h>
24#include <media/v4l2-device.h> 24#include <media/v4l2-device.h>
25#include <media/v4l2-chip-ident.h>
26 25
27#include "saa7191.h" 26#include "saa7191.h"
28 27
@@ -272,7 +271,7 @@ static int saa7191_querystd(struct v4l2_subdev *sd, v4l2_std_id *norm)
272 271
273 dprintk("SAA7191 extended signal auto-detection...\n"); 272 dprintk("SAA7191 extended signal auto-detection...\n");
274 273
275 *norm = V4L2_STD_NTSC | V4L2_STD_PAL | V4L2_STD_SECAM; 274 *norm &= V4L2_STD_NTSC | V4L2_STD_PAL | V4L2_STD_SECAM;
276 stdc &= ~SAA7191_STDC_SECS; 275 stdc &= ~SAA7191_STDC_SECS;
277 ctl3 &= ~(SAA7191_CTL3_FSEL); 276 ctl3 &= ~(SAA7191_CTL3_FSEL);
278 277
@@ -303,7 +302,7 @@ static int saa7191_querystd(struct v4l2_subdev *sd, v4l2_std_id *norm)
303 if (status & SAA7191_STATUS_FIDT) { 302 if (status & SAA7191_STATUS_FIDT) {
304 /* 60Hz signal -> NTSC */ 303 /* 60Hz signal -> NTSC */
305 dprintk("60Hz signal: NTSC\n"); 304 dprintk("60Hz signal: NTSC\n");
306 *norm = V4L2_STD_NTSC; 305 *norm &= V4L2_STD_NTSC;
307 return 0; 306 return 0;
308 } 307 }
309 308
@@ -325,12 +324,13 @@ static int saa7191_querystd(struct v4l2_subdev *sd, v4l2_std_id *norm)
325 if (status & SAA7191_STATUS_FIDT) { 324 if (status & SAA7191_STATUS_FIDT) {
326 dprintk("No 50Hz signal\n"); 325 dprintk("No 50Hz signal\n");
327 saa7191_s_std(sd, old_norm); 326 saa7191_s_std(sd, old_norm);
328 return -EAGAIN; 327 *norm = V4L2_STD_UNKNOWN;
328 return 0;
329 } 329 }
330 330
331 if (status & SAA7191_STATUS_CODE) { 331 if (status & SAA7191_STATUS_CODE) {
332 dprintk("PAL\n"); 332 dprintk("PAL\n");
333 *norm = V4L2_STD_PAL; 333 *norm &= V4L2_STD_PAL;
334 return saa7191_s_std(sd, old_norm); 334 return saa7191_s_std(sd, old_norm);
335 } 335 }
336 336
@@ -350,18 +350,19 @@ static int saa7191_querystd(struct v4l2_subdev *sd, v4l2_std_id *norm)
350 /* not 50Hz ? */ 350 /* not 50Hz ? */
351 if (status & SAA7191_STATUS_FIDT) { 351 if (status & SAA7191_STATUS_FIDT) {
352 dprintk("No 50Hz signal\n"); 352 dprintk("No 50Hz signal\n");
353 err = -EAGAIN; 353 *norm = V4L2_STD_UNKNOWN;
354 goto out; 354 goto out;
355 } 355 }
356 356
357 if (status & SAA7191_STATUS_CODE) { 357 if (status & SAA7191_STATUS_CODE) {
358 /* Color detected -> SECAM */ 358 /* Color detected -> SECAM */
359 dprintk("SECAM\n"); 359 dprintk("SECAM\n");
360 *norm = V4L2_STD_SECAM; 360 *norm &= V4L2_STD_SECAM;
361 return saa7191_s_std(sd, old_norm); 361 return saa7191_s_std(sd, old_norm);
362 } 362 }
363 363
364 dprintk("No color detected with SECAM - Going back to PAL.\n"); 364 dprintk("No color detected with SECAM - Going back to PAL.\n");
365 *norm = V4L2_STD_UNKNOWN;
365 366
366out: 367out:
367 return saa7191_s_std(sd, old_norm); 368 return saa7191_s_std(sd, old_norm);
@@ -567,18 +568,9 @@ static int saa7191_g_input_status(struct v4l2_subdev *sd, u32 *status)
567} 568}
568 569
569 570
570static int saa7191_g_chip_ident(struct v4l2_subdev *sd,
571 struct v4l2_dbg_chip_ident *chip)
572{
573 struct i2c_client *client = v4l2_get_subdevdata(sd);
574
575 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_SAA7191, 0);
576}
577
578/* ----------------------------------------------------------------------- */ 571/* ----------------------------------------------------------------------- */
579 572
580static const struct v4l2_subdev_core_ops saa7191_core_ops = { 573static const struct v4l2_subdev_core_ops saa7191_core_ops = {
581 .g_chip_ident = saa7191_g_chip_ident,
582 .g_ctrl = saa7191_g_ctrl, 574 .g_ctrl = saa7191_g_ctrl,
583 .s_ctrl = saa7191_s_ctrl, 575 .s_ctrl = saa7191_s_ctrl,
584 .s_std = saa7191_s_std, 576 .s_std = saa7191_s_std,
@@ -605,7 +597,7 @@ static int saa7191_probe(struct i2c_client *client,
605 v4l_info(client, "chip found @ 0x%x (%s)\n", 597 v4l_info(client, "chip found @ 0x%x (%s)\n",
606 client->addr << 1, client->adapter->name); 598 client->addr << 1, client->adapter->name);
607 599
608 decoder = kzalloc(sizeof(*decoder), GFP_KERNEL); 600 decoder = devm_kzalloc(&client->dev, sizeof(*decoder), GFP_KERNEL);
609 if (!decoder) 601 if (!decoder)
610 return -ENOMEM; 602 return -ENOMEM;
611 603
@@ -615,7 +607,6 @@ static int saa7191_probe(struct i2c_client *client,
615 err = saa7191_write_block(sd, sizeof(initseq), initseq); 607 err = saa7191_write_block(sd, sizeof(initseq), initseq);
616 if (err) { 608 if (err) {
617 printk(KERN_ERR "SAA7191 initialization failed\n"); 609 printk(KERN_ERR "SAA7191 initialization failed\n");
618 kfree(decoder);
619 return err; 610 return err;
620 } 611 }
621 612
@@ -636,7 +627,6 @@ static int saa7191_remove(struct i2c_client *client)
636 struct v4l2_subdev *sd = i2c_get_clientdata(client); 627 struct v4l2_subdev *sd = i2c_get_clientdata(client);
637 628
638 v4l2_device_unregister_subdev(sd); 629 v4l2_device_unregister_subdev(sd);
639 kfree(to_saa7191(sd));
640 return 0; 630 return 0;
641} 631}
642 632
diff --git a/drivers/media/i2c/smiapp/smiapp-core.c b/drivers/media/i2c/smiapp/smiapp-core.c
index cae4f4683851..7ac7580f85c9 100644
--- a/drivers/media/i2c/smiapp/smiapp-core.c
+++ b/drivers/media/i2c/smiapp/smiapp-core.c
@@ -2383,8 +2383,9 @@ static int smiapp_registered(struct v4l2_subdev *subdev)
2383 } 2383 }
2384 2384
2385 if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN) { 2385 if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN) {
2386 if (gpio_request_one(sensor->platform_data->xshutdown, 0, 2386 if (devm_gpio_request_one(&client->dev,
2387 "SMIA++ xshutdown") != 0) { 2387 sensor->platform_data->xshutdown, 0,
2388 "SMIA++ xshutdown") != 0) {
2388 dev_err(&client->dev, 2389 dev_err(&client->dev,
2389 "unable to acquire reset gpio %d\n", 2390 "unable to acquire reset gpio %d\n",
2390 sensor->platform_data->xshutdown); 2391 sensor->platform_data->xshutdown);
@@ -2393,10 +2394,8 @@ static int smiapp_registered(struct v4l2_subdev *subdev)
2393 } 2394 }
2394 2395
2395 rval = smiapp_power_on(sensor); 2396 rval = smiapp_power_on(sensor);
2396 if (rval) { 2397 if (rval)
2397 rval = -ENODEV; 2398 return -ENODEV;
2398 goto out_smiapp_power_on;
2399 }
2400 2399
2401 rval = smiapp_identify_module(subdev); 2400 rval = smiapp_identify_module(subdev);
2402 if (rval) { 2401 if (rval) {
@@ -2656,11 +2655,6 @@ out_ident_release:
2656 2655
2657out_power_off: 2656out_power_off:
2658 smiapp_power_off(sensor); 2657 smiapp_power_off(sensor);
2659
2660out_smiapp_power_on:
2661 if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN)
2662 gpio_free(sensor->platform_data->xshutdown);
2663
2664 return rval; 2658 return rval;
2665} 2659}
2666 2660
@@ -2854,12 +2848,10 @@ static int smiapp_remove(struct i2c_client *client)
2854 device_remove_file(&client->dev, &dev_attr_nvm); 2848 device_remove_file(&client->dev, &dev_attr_nvm);
2855 2849
2856 for (i = 0; i < sensor->ssds_used; i++) { 2850 for (i = 0; i < sensor->ssds_used; i++) {
2857 media_entity_cleanup(&sensor->ssds[i].sd.entity);
2858 v4l2_device_unregister_subdev(&sensor->ssds[i].sd); 2851 v4l2_device_unregister_subdev(&sensor->ssds[i].sd);
2852 media_entity_cleanup(&sensor->ssds[i].sd.entity);
2859 } 2853 }
2860 smiapp_free_controls(sensor); 2854 smiapp_free_controls(sensor);
2861 if (sensor->platform_data->xshutdown != SMIAPP_NO_XSHUTDOWN)
2862 gpio_free(sensor->platform_data->xshutdown);
2863 2855
2864 return 0; 2856 return 0;
2865} 2857}
diff --git a/drivers/media/i2c/soc_camera/imx074.c b/drivers/media/i2c/soc_camera/imx074.c
index a2a5cbbdbe28..1d384a371b41 100644
--- a/drivers/media/i2c/soc_camera/imx074.c
+++ b/drivers/media/i2c/soc_camera/imx074.c
@@ -18,8 +18,9 @@
18#include <linux/module.h> 18#include <linux/module.h>
19 19
20#include <media/soc_camera.h> 20#include <media/soc_camera.h>
21#include <media/v4l2-async.h>
22#include <media/v4l2-clk.h>
21#include <media/v4l2-subdev.h> 23#include <media/v4l2-subdev.h>
22#include <media/v4l2-chip-ident.h>
23 24
24/* IMX074 registers */ 25/* IMX074 registers */
25 26
@@ -77,6 +78,7 @@ struct imx074_datafmt {
77struct imx074 { 78struct imx074 {
78 struct v4l2_subdev subdev; 79 struct v4l2_subdev subdev;
79 const struct imx074_datafmt *fmt; 80 const struct imx074_datafmt *fmt;
81 struct v4l2_clk *clk;
80}; 82};
81 83
82static const struct imx074_datafmt imx074_colour_fmts[] = { 84static const struct imx074_datafmt imx074_colour_fmts[] = {
@@ -251,29 +253,13 @@ static int imx074_s_stream(struct v4l2_subdev *sd, int enable)
251 return reg_write(client, MODE_SELECT, !!enable); 253 return reg_write(client, MODE_SELECT, !!enable);
252} 254}
253 255
254static int imx074_g_chip_ident(struct v4l2_subdev *sd,
255 struct v4l2_dbg_chip_ident *id)
256{
257 struct i2c_client *client = v4l2_get_subdevdata(sd);
258
259 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
260 return -EINVAL;
261
262 if (id->match.addr != client->addr)
263 return -ENODEV;
264
265 id->ident = V4L2_IDENT_IMX074;
266 id->revision = 0;
267
268 return 0;
269}
270
271static int imx074_s_power(struct v4l2_subdev *sd, int on) 256static int imx074_s_power(struct v4l2_subdev *sd, int on)
272{ 257{
273 struct i2c_client *client = v4l2_get_subdevdata(sd); 258 struct i2c_client *client = v4l2_get_subdevdata(sd);
274 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client); 259 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
260 struct imx074 *priv = to_imx074(client);
275 261
276 return soc_camera_set_power(&client->dev, ssdd, on); 262 return soc_camera_set_power(&client->dev, ssdd, priv->clk, on);
277} 263}
278 264
279static int imx074_g_mbus_config(struct v4l2_subdev *sd, 265static int imx074_g_mbus_config(struct v4l2_subdev *sd,
@@ -299,7 +285,6 @@ static struct v4l2_subdev_video_ops imx074_subdev_video_ops = {
299}; 285};
300 286
301static struct v4l2_subdev_core_ops imx074_subdev_core_ops = { 287static struct v4l2_subdev_core_ops imx074_subdev_core_ops = {
302 .g_chip_ident = imx074_g_chip_ident,
303 .s_power = imx074_s_power, 288 .s_power = imx074_s_power,
304}; 289};
305 290
@@ -431,6 +416,7 @@ static int imx074_probe(struct i2c_client *client,
431 struct imx074 *priv; 416 struct imx074 *priv;
432 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 417 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
433 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client); 418 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
419 int ret;
434 420
435 if (!ssdd) { 421 if (!ssdd) {
436 dev_err(&client->dev, "IMX074: missing platform data!\n"); 422 dev_err(&client->dev, "IMX074: missing platform data!\n");
@@ -451,12 +437,35 @@ static int imx074_probe(struct i2c_client *client,
451 437
452 priv->fmt = &imx074_colour_fmts[0]; 438 priv->fmt = &imx074_colour_fmts[0];
453 439
454 return imx074_video_probe(client); 440 priv->clk = v4l2_clk_get(&client->dev, "mclk");
441 if (IS_ERR(priv->clk)) {
442 dev_info(&client->dev, "Error %ld getting clock\n", PTR_ERR(priv->clk));
443 return -EPROBE_DEFER;
444 }
445
446 ret = soc_camera_power_init(&client->dev, ssdd);
447 if (ret < 0)
448 goto epwrinit;
449
450 ret = imx074_video_probe(client);
451 if (ret < 0)
452 goto eprobe;
453
454 return v4l2_async_register_subdev(&priv->subdev);
455
456epwrinit:
457eprobe:
458 v4l2_clk_put(priv->clk);
459 return ret;
455} 460}
456 461
457static int imx074_remove(struct i2c_client *client) 462static int imx074_remove(struct i2c_client *client)
458{ 463{
459 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client); 464 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
465 struct imx074 *priv = to_imx074(client);
466
467 v4l2_async_unregister_subdev(&priv->subdev);
468 v4l2_clk_put(priv->clk);
460 469
461 if (ssdd->free_bus) 470 if (ssdd->free_bus)
462 ssdd->free_bus(ssdd); 471 ssdd->free_bus(ssdd);
diff --git a/drivers/media/i2c/soc_camera/mt9m001.c b/drivers/media/i2c/soc_camera/mt9m001.c
index dd9089805757..df97033fa6ef 100644
--- a/drivers/media/i2c/soc_camera/mt9m001.c
+++ b/drivers/media/i2c/soc_camera/mt9m001.c
@@ -16,8 +16,8 @@
16 16
17#include <media/soc_camera.h> 17#include <media/soc_camera.h>
18#include <media/soc_mediabus.h> 18#include <media/soc_mediabus.h>
19#include <media/v4l2-clk.h>
19#include <media/v4l2-subdev.h> 20#include <media/v4l2-subdev.h>
20#include <media/v4l2-chip-ident.h>
21#include <media/v4l2-ctrls.h> 21#include <media/v4l2-ctrls.h>
22 22
23/* 23/*
@@ -94,10 +94,10 @@ struct mt9m001 {
94 struct v4l2_ctrl *exposure; 94 struct v4l2_ctrl *exposure;
95 }; 95 };
96 struct v4l2_rect rect; /* Sensor window */ 96 struct v4l2_rect rect; /* Sensor window */
97 struct v4l2_clk *clk;
97 const struct mt9m001_datafmt *fmt; 98 const struct mt9m001_datafmt *fmt;
98 const struct mt9m001_datafmt *fmts; 99 const struct mt9m001_datafmt *fmts;
99 int num_fmts; 100 int num_fmts;
100 int model; /* V4L2_IDENT_MT9M001* codes from v4l2-chip-ident.h */
101 unsigned int total_h; 101 unsigned int total_h;
102 unsigned short y_skip_top; /* Lines to skip at the top */ 102 unsigned short y_skip_top; /* Lines to skip at the top */
103}; 103};
@@ -320,36 +320,15 @@ static int mt9m001_try_fmt(struct v4l2_subdev *sd,
320 return 0; 320 return 0;
321} 321}
322 322
323static int mt9m001_g_chip_ident(struct v4l2_subdev *sd,
324 struct v4l2_dbg_chip_ident *id)
325{
326 struct i2c_client *client = v4l2_get_subdevdata(sd);
327 struct mt9m001 *mt9m001 = to_mt9m001(client);
328
329 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
330 return -EINVAL;
331
332 if (id->match.addr != client->addr)
333 return -ENODEV;
334
335 id->ident = mt9m001->model;
336 id->revision = 0;
337
338 return 0;
339}
340
341#ifdef CONFIG_VIDEO_ADV_DEBUG 323#ifdef CONFIG_VIDEO_ADV_DEBUG
342static int mt9m001_g_register(struct v4l2_subdev *sd, 324static int mt9m001_g_register(struct v4l2_subdev *sd,
343 struct v4l2_dbg_register *reg) 325 struct v4l2_dbg_register *reg)
344{ 326{
345 struct i2c_client *client = v4l2_get_subdevdata(sd); 327 struct i2c_client *client = v4l2_get_subdevdata(sd);
346 328
347 if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff) 329 if (reg->reg > 0xff)
348 return -EINVAL; 330 return -EINVAL;
349 331
350 if (reg->match.addr != client->addr)
351 return -ENODEV;
352
353 reg->size = 2; 332 reg->size = 2;
354 reg->val = reg_read(client, reg->reg); 333 reg->val = reg_read(client, reg->reg);
355 334
@@ -364,12 +343,9 @@ static int mt9m001_s_register(struct v4l2_subdev *sd,
364{ 343{
365 struct i2c_client *client = v4l2_get_subdevdata(sd); 344 struct i2c_client *client = v4l2_get_subdevdata(sd);
366 345
367 if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff) 346 if (reg->reg > 0xff)
368 return -EINVAL; 347 return -EINVAL;
369 348
370 if (reg->match.addr != client->addr)
371 return -ENODEV;
372
373 if (reg_write(client, reg->reg, reg->val) < 0) 349 if (reg_write(client, reg->reg, reg->val) < 0)
374 return -EIO; 350 return -EIO;
375 351
@@ -381,8 +357,9 @@ static int mt9m001_s_power(struct v4l2_subdev *sd, int on)
381{ 357{
382 struct i2c_client *client = v4l2_get_subdevdata(sd); 358 struct i2c_client *client = v4l2_get_subdevdata(sd);
383 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client); 359 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
360 struct mt9m001 *mt9m001 = to_mt9m001(client);
384 361
385 return soc_camera_set_power(&client->dev, ssdd, on); 362 return soc_camera_set_power(&client->dev, ssdd, mt9m001->clk, on);
386} 363}
387 364
388static int mt9m001_g_volatile_ctrl(struct v4l2_ctrl *ctrl) 365static int mt9m001_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
@@ -505,11 +482,9 @@ static int mt9m001_video_probe(struct soc_camera_subdev_desc *ssdd,
505 switch (data) { 482 switch (data) {
506 case 0x8411: 483 case 0x8411:
507 case 0x8421: 484 case 0x8421:
508 mt9m001->model = V4L2_IDENT_MT9M001C12ST;
509 mt9m001->fmts = mt9m001_colour_fmts; 485 mt9m001->fmts = mt9m001_colour_fmts;
510 break; 486 break;
511 case 0x8431: 487 case 0x8431:
512 mt9m001->model = V4L2_IDENT_MT9M001C12STM;
513 mt9m001->fmts = mt9m001_monochrome_fmts; 488 mt9m001->fmts = mt9m001_monochrome_fmts;
514 break; 489 break;
515 default: 490 default:
@@ -580,7 +555,6 @@ static const struct v4l2_ctrl_ops mt9m001_ctrl_ops = {
580}; 555};
581 556
582static struct v4l2_subdev_core_ops mt9m001_subdev_core_ops = { 557static struct v4l2_subdev_core_ops mt9m001_subdev_core_ops = {
583 .g_chip_ident = mt9m001_g_chip_ident,
584#ifdef CONFIG_VIDEO_ADV_DEBUG 558#ifdef CONFIG_VIDEO_ADV_DEBUG
585 .g_register = mt9m001_g_register, 559 .g_register = mt9m001_g_register,
586 .s_register = mt9m001_s_register, 560 .s_register = mt9m001_s_register,
@@ -710,9 +684,18 @@ static int mt9m001_probe(struct i2c_client *client,
710 mt9m001->rect.width = MT9M001_MAX_WIDTH; 684 mt9m001->rect.width = MT9M001_MAX_WIDTH;
711 mt9m001->rect.height = MT9M001_MAX_HEIGHT; 685 mt9m001->rect.height = MT9M001_MAX_HEIGHT;
712 686
687 mt9m001->clk = v4l2_clk_get(&client->dev, "mclk");
688 if (IS_ERR(mt9m001->clk)) {
689 ret = PTR_ERR(mt9m001->clk);
690 goto eclkget;
691 }
692
713 ret = mt9m001_video_probe(ssdd, client); 693 ret = mt9m001_video_probe(ssdd, client);
714 if (ret) 694 if (ret) {
695 v4l2_clk_put(mt9m001->clk);
696eclkget:
715 v4l2_ctrl_handler_free(&mt9m001->hdl); 697 v4l2_ctrl_handler_free(&mt9m001->hdl);
698 }
716 699
717 return ret; 700 return ret;
718} 701}
@@ -722,6 +705,7 @@ static int mt9m001_remove(struct i2c_client *client)
722 struct mt9m001 *mt9m001 = to_mt9m001(client); 705 struct mt9m001 *mt9m001 = to_mt9m001(client);
723 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client); 706 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
724 707
708 v4l2_clk_put(mt9m001->clk);
725 v4l2_device_unregister_subdev(&mt9m001->subdev); 709 v4l2_device_unregister_subdev(&mt9m001->subdev);
726 v4l2_ctrl_handler_free(&mt9m001->hdl); 710 v4l2_ctrl_handler_free(&mt9m001->hdl);
727 mt9m001_video_remove(ssdd); 711 mt9m001_video_remove(ssdd);
diff --git a/drivers/media/i2c/soc_camera/mt9m111.c b/drivers/media/i2c/soc_camera/mt9m111.c
index 8bd4e0d2ea03..de3605df47c5 100644
--- a/drivers/media/i2c/soc_camera/mt9m111.c
+++ b/drivers/media/i2c/soc_camera/mt9m111.c
@@ -17,9 +17,9 @@
17#include <linux/module.h> 17#include <linux/module.h>
18 18
19#include <media/soc_camera.h> 19#include <media/soc_camera.h>
20#include <media/v4l2-clk.h>
20#include <media/v4l2-common.h> 21#include <media/v4l2-common.h>
21#include <media/v4l2-ctrls.h> 22#include <media/v4l2-ctrls.h>
22#include <media/v4l2-chip-ident.h>
23 23
24/* 24/*
25 * MT9M111, MT9M112 and MT9M131: 25 * MT9M111, MT9M112 and MT9M131:
@@ -205,10 +205,9 @@ struct mt9m111 {
205 struct v4l2_subdev subdev; 205 struct v4l2_subdev subdev;
206 struct v4l2_ctrl_handler hdl; 206 struct v4l2_ctrl_handler hdl;
207 struct v4l2_ctrl *gain; 207 struct v4l2_ctrl *gain;
208 int model; /* V4L2_IDENT_MT9M111 or V4L2_IDENT_MT9M112 code
209 * from v4l2-chip-ident.h */
210 struct mt9m111_context *ctx; 208 struct mt9m111_context *ctx;
211 struct v4l2_rect rect; /* cropping rectangle */ 209 struct v4l2_rect rect; /* cropping rectangle */
210 struct v4l2_clk *clk;
212 int width; /* output */ 211 int width; /* output */
213 int height; /* sizes */ 212 int height; /* sizes */
214 struct mutex power_lock; /* lock to protect power_count */ 213 struct mutex power_lock; /* lock to protect power_count */
@@ -600,24 +599,6 @@ static int mt9m111_s_fmt(struct v4l2_subdev *sd,
600 return ret; 599 return ret;
601} 600}
602 601
603static int mt9m111_g_chip_ident(struct v4l2_subdev *sd,
604 struct v4l2_dbg_chip_ident *id)
605{
606 struct i2c_client *client = v4l2_get_subdevdata(sd);
607 struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev);
608
609 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
610 return -EINVAL;
611
612 if (id->match.addr != client->addr)
613 return -ENODEV;
614
615 id->ident = mt9m111->model;
616 id->revision = 0;
617
618 return 0;
619}
620
621#ifdef CONFIG_VIDEO_ADV_DEBUG 602#ifdef CONFIG_VIDEO_ADV_DEBUG
622static int mt9m111_g_register(struct v4l2_subdev *sd, 603static int mt9m111_g_register(struct v4l2_subdev *sd,
623 struct v4l2_dbg_register *reg) 604 struct v4l2_dbg_register *reg)
@@ -625,10 +606,8 @@ static int mt9m111_g_register(struct v4l2_subdev *sd,
625 struct i2c_client *client = v4l2_get_subdevdata(sd); 606 struct i2c_client *client = v4l2_get_subdevdata(sd);
626 int val; 607 int val;
627 608
628 if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0x2ff) 609 if (reg->reg > 0x2ff)
629 return -EINVAL; 610 return -EINVAL;
630 if (reg->match.addr != client->addr)
631 return -ENODEV;
632 611
633 val = mt9m111_reg_read(client, reg->reg); 612 val = mt9m111_reg_read(client, reg->reg);
634 reg->size = 2; 613 reg->size = 2;
@@ -645,12 +624,9 @@ static int mt9m111_s_register(struct v4l2_subdev *sd,
645{ 624{
646 struct i2c_client *client = v4l2_get_subdevdata(sd); 625 struct i2c_client *client = v4l2_get_subdevdata(sd);
647 626
648 if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0x2ff) 627 if (reg->reg > 0x2ff)
649 return -EINVAL; 628 return -EINVAL;
650 629
651 if (reg->match.addr != client->addr)
652 return -ENODEV;
653
654 if (mt9m111_reg_write(client, reg->reg, reg->val) < 0) 630 if (mt9m111_reg_write(client, reg->reg, reg->val) < 0)
655 return -EIO; 631 return -EIO;
656 632
@@ -801,14 +777,14 @@ static int mt9m111_power_on(struct mt9m111 *mt9m111)
801 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client); 777 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
802 int ret; 778 int ret;
803 779
804 ret = soc_camera_power_on(&client->dev, ssdd); 780 ret = soc_camera_power_on(&client->dev, ssdd, mt9m111->clk);
805 if (ret < 0) 781 if (ret < 0)
806 return ret; 782 return ret;
807 783
808 ret = mt9m111_resume(mt9m111); 784 ret = mt9m111_resume(mt9m111);
809 if (ret < 0) { 785 if (ret < 0) {
810 dev_err(&client->dev, "Failed to resume the sensor: %d\n", ret); 786 dev_err(&client->dev, "Failed to resume the sensor: %d\n", ret);
811 soc_camera_power_off(&client->dev, ssdd); 787 soc_camera_power_off(&client->dev, ssdd, mt9m111->clk);
812 } 788 }
813 789
814 return ret; 790 return ret;
@@ -820,7 +796,7 @@ static void mt9m111_power_off(struct mt9m111 *mt9m111)
820 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client); 796 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
821 797
822 mt9m111_suspend(mt9m111); 798 mt9m111_suspend(mt9m111);
823 soc_camera_power_off(&client->dev, ssdd); 799 soc_camera_power_off(&client->dev, ssdd, mt9m111->clk);
824} 800}
825 801
826static int mt9m111_s_power(struct v4l2_subdev *sd, int on) 802static int mt9m111_s_power(struct v4l2_subdev *sd, int on)
@@ -856,7 +832,6 @@ static const struct v4l2_ctrl_ops mt9m111_ctrl_ops = {
856}; 832};
857 833
858static struct v4l2_subdev_core_ops mt9m111_subdev_core_ops = { 834static struct v4l2_subdev_core_ops mt9m111_subdev_core_ops = {
859 .g_chip_ident = mt9m111_g_chip_ident,
860 .s_power = mt9m111_s_power, 835 .s_power = mt9m111_s_power,
861#ifdef CONFIG_VIDEO_ADV_DEBUG 836#ifdef CONFIG_VIDEO_ADV_DEBUG
862 .g_register = mt9m111_g_register, 837 .g_register = mt9m111_g_register,
@@ -923,12 +898,10 @@ static int mt9m111_video_probe(struct i2c_client *client)
923 898
924 switch (data) { 899 switch (data) {
925 case 0x143a: /* MT9M111 or MT9M131 */ 900 case 0x143a: /* MT9M111 or MT9M131 */
926 mt9m111->model = V4L2_IDENT_MT9M111;
927 dev_info(&client->dev, 901 dev_info(&client->dev,
928 "Detected a MT9M111/MT9M131 chip ID %x\n", data); 902 "Detected a MT9M111/MT9M131 chip ID %x\n", data);
929 break; 903 break;
930 case 0x148c: /* MT9M112 */ 904 case 0x148c: /* MT9M112 */
931 mt9m111->model = V4L2_IDENT_MT9M112;
932 dev_info(&client->dev, "Detected a MT9M112 chip ID %x\n", data); 905 dev_info(&client->dev, "Detected a MT9M112 chip ID %x\n", data);
933 break; 906 break;
934 default: 907 default:
@@ -1002,9 +975,18 @@ static int mt9m111_probe(struct i2c_client *client,
1002 mt9m111->lastpage = -1; 975 mt9m111->lastpage = -1;
1003 mutex_init(&mt9m111->power_lock); 976 mutex_init(&mt9m111->power_lock);
1004 977
978 mt9m111->clk = v4l2_clk_get(&client->dev, "mclk");
979 if (IS_ERR(mt9m111->clk)) {
980 ret = PTR_ERR(mt9m111->clk);
981 goto eclkget;
982 }
983
1005 ret = mt9m111_video_probe(client); 984 ret = mt9m111_video_probe(client);
1006 if (ret) 985 if (ret) {
986 v4l2_clk_put(mt9m111->clk);
987eclkget:
1007 v4l2_ctrl_handler_free(&mt9m111->hdl); 988 v4l2_ctrl_handler_free(&mt9m111->hdl);
989 }
1008 990
1009 return ret; 991 return ret;
1010} 992}
@@ -1013,6 +995,7 @@ static int mt9m111_remove(struct i2c_client *client)
1013{ 995{
1014 struct mt9m111 *mt9m111 = to_mt9m111(client); 996 struct mt9m111 *mt9m111 = to_mt9m111(client);
1015 997
998 v4l2_clk_put(mt9m111->clk);
1016 v4l2_device_unregister_subdev(&mt9m111->subdev); 999 v4l2_device_unregister_subdev(&mt9m111->subdev);
1017 v4l2_ctrl_handler_free(&mt9m111->hdl); 1000 v4l2_ctrl_handler_free(&mt9m111->hdl);
1018 1001
diff --git a/drivers/media/i2c/soc_camera/mt9t031.c b/drivers/media/i2c/soc_camera/mt9t031.c
index 26a15b87a9a2..47d18d0bafe7 100644
--- a/drivers/media/i2c/soc_camera/mt9t031.c
+++ b/drivers/media/i2c/soc_camera/mt9t031.c
@@ -18,7 +18,7 @@
18#include <linux/module.h> 18#include <linux/module.h>
19 19
20#include <media/soc_camera.h> 20#include <media/soc_camera.h>
21#include <media/v4l2-chip-ident.h> 21#include <media/v4l2-clk.h>
22#include <media/v4l2-subdev.h> 22#include <media/v4l2-subdev.h>
23#include <media/v4l2-ctrls.h> 23#include <media/v4l2-ctrls.h>
24 24
@@ -76,7 +76,7 @@ struct mt9t031 {
76 struct v4l2_ctrl *exposure; 76 struct v4l2_ctrl *exposure;
77 }; 77 };
78 struct v4l2_rect rect; /* Sensor window */ 78 struct v4l2_rect rect; /* Sensor window */
79 int model; /* V4L2_IDENT_MT9T031* codes from v4l2-chip-ident.h */ 79 struct v4l2_clk *clk;
80 u16 xskip; 80 u16 xskip;
81 u16 yskip; 81 u16 yskip;
82 unsigned int total_h; 82 unsigned int total_h;
@@ -391,36 +391,16 @@ static int mt9t031_try_fmt(struct v4l2_subdev *sd,
391 return 0; 391 return 0;
392} 392}
393 393
394static int mt9t031_g_chip_ident(struct v4l2_subdev *sd,
395 struct v4l2_dbg_chip_ident *id)
396{
397 struct i2c_client *client = v4l2_get_subdevdata(sd);
398 struct mt9t031 *mt9t031 = to_mt9t031(client);
399
400 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
401 return -EINVAL;
402
403 if (id->match.addr != client->addr)
404 return -ENODEV;
405
406 id->ident = mt9t031->model;
407 id->revision = 0;
408
409 return 0;
410}
411
412#ifdef CONFIG_VIDEO_ADV_DEBUG 394#ifdef CONFIG_VIDEO_ADV_DEBUG
413static int mt9t031_g_register(struct v4l2_subdev *sd, 395static int mt9t031_g_register(struct v4l2_subdev *sd,
414 struct v4l2_dbg_register *reg) 396 struct v4l2_dbg_register *reg)
415{ 397{
416 struct i2c_client *client = v4l2_get_subdevdata(sd); 398 struct i2c_client *client = v4l2_get_subdevdata(sd);
417 399
418 if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff) 400 if (reg->reg > 0xff)
419 return -EINVAL; 401 return -EINVAL;
420 402
421 if (reg->match.addr != client->addr) 403 reg->size = 1;
422 return -ENODEV;
423
424 reg->val = reg_read(client, reg->reg); 404 reg->val = reg_read(client, reg->reg);
425 405
426 if (reg->val > 0xffff) 406 if (reg->val > 0xffff)
@@ -434,12 +414,9 @@ static int mt9t031_s_register(struct v4l2_subdev *sd,
434{ 414{
435 struct i2c_client *client = v4l2_get_subdevdata(sd); 415 struct i2c_client *client = v4l2_get_subdevdata(sd);
436 416
437 if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff) 417 if (reg->reg > 0xff)
438 return -EINVAL; 418 return -EINVAL;
439 419
440 if (reg->match.addr != client->addr)
441 return -ENODEV;
442
443 if (reg_write(client, reg->reg, reg->val) < 0) 420 if (reg_write(client, reg->reg, reg->val) < 0)
444 return -EIO; 421 return -EIO;
445 422
@@ -595,7 +572,7 @@ static int mt9t031_runtime_resume(struct device *dev)
595 return 0; 572 return 0;
596} 573}
597 574
598static struct dev_pm_ops mt9t031_dev_pm_ops = { 575static const struct dev_pm_ops mt9t031_dev_pm_ops = {
599 .runtime_suspend = mt9t031_runtime_suspend, 576 .runtime_suspend = mt9t031_runtime_suspend,
600 .runtime_resume = mt9t031_runtime_resume, 577 .runtime_resume = mt9t031_runtime_resume,
601}; 578};
@@ -610,16 +587,17 @@ static int mt9t031_s_power(struct v4l2_subdev *sd, int on)
610 struct i2c_client *client = v4l2_get_subdevdata(sd); 587 struct i2c_client *client = v4l2_get_subdevdata(sd);
611 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client); 588 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
612 struct video_device *vdev = soc_camera_i2c_to_vdev(client); 589 struct video_device *vdev = soc_camera_i2c_to_vdev(client);
590 struct mt9t031 *mt9t031 = to_mt9t031(client);
613 int ret; 591 int ret;
614 592
615 if (on) { 593 if (on) {
616 ret = soc_camera_power_on(&client->dev, ssdd); 594 ret = soc_camera_power_on(&client->dev, ssdd, mt9t031->clk);
617 if (ret < 0) 595 if (ret < 0)
618 return ret; 596 return ret;
619 vdev->dev.type = &mt9t031_dev_type; 597 vdev->dev.type = &mt9t031_dev_type;
620 } else { 598 } else {
621 vdev->dev.type = NULL; 599 vdev->dev.type = NULL;
622 soc_camera_power_off(&client->dev, ssdd); 600 soc_camera_power_off(&client->dev, ssdd, mt9t031->clk);
623 } 601 }
624 602
625 return 0; 603 return 0;
@@ -650,7 +628,6 @@ static int mt9t031_video_probe(struct i2c_client *client)
650 628
651 switch (data) { 629 switch (data) {
652 case 0x1621: 630 case 0x1621:
653 mt9t031->model = V4L2_IDENT_MT9T031;
654 break; 631 break;
655 default: 632 default:
656 dev_err(&client->dev, 633 dev_err(&client->dev,
@@ -685,7 +662,6 @@ static const struct v4l2_ctrl_ops mt9t031_ctrl_ops = {
685}; 662};
686 663
687static struct v4l2_subdev_core_ops mt9t031_subdev_core_ops = { 664static struct v4l2_subdev_core_ops mt9t031_subdev_core_ops = {
688 .g_chip_ident = mt9t031_g_chip_ident,
689 .s_power = mt9t031_s_power, 665 .s_power = mt9t031_s_power,
690#ifdef CONFIG_VIDEO_ADV_DEBUG 666#ifdef CONFIG_VIDEO_ADV_DEBUG
691 .g_register = mt9t031_g_register, 667 .g_register = mt9t031_g_register,
@@ -812,9 +788,18 @@ static int mt9t031_probe(struct i2c_client *client,
812 mt9t031->xskip = 1; 788 mt9t031->xskip = 1;
813 mt9t031->yskip = 1; 789 mt9t031->yskip = 1;
814 790
791 mt9t031->clk = v4l2_clk_get(&client->dev, "mclk");
792 if (IS_ERR(mt9t031->clk)) {
793 ret = PTR_ERR(mt9t031->clk);
794 goto eclkget;
795 }
796
815 ret = mt9t031_video_probe(client); 797 ret = mt9t031_video_probe(client);
816 if (ret) 798 if (ret) {
799 v4l2_clk_put(mt9t031->clk);
800eclkget:
817 v4l2_ctrl_handler_free(&mt9t031->hdl); 801 v4l2_ctrl_handler_free(&mt9t031->hdl);
802 }
818 803
819 return ret; 804 return ret;
820} 805}
@@ -823,6 +808,7 @@ static int mt9t031_remove(struct i2c_client *client)
823{ 808{
824 struct mt9t031 *mt9t031 = to_mt9t031(client); 809 struct mt9t031 *mt9t031 = to_mt9t031(client);
825 810
811 v4l2_clk_put(mt9t031->clk);
826 v4l2_device_unregister_subdev(&mt9t031->subdev); 812 v4l2_device_unregister_subdev(&mt9t031->subdev);
827 v4l2_ctrl_handler_free(&mt9t031->hdl); 813 v4l2_ctrl_handler_free(&mt9t031->hdl);
828 814
diff --git a/drivers/media/i2c/soc_camera/mt9t112.c b/drivers/media/i2c/soc_camera/mt9t112.c
index a7256b732804..46f431a13782 100644
--- a/drivers/media/i2c/soc_camera/mt9t112.c
+++ b/drivers/media/i2c/soc_camera/mt9t112.c
@@ -27,7 +27,7 @@
27 27
28#include <media/mt9t112.h> 28#include <media/mt9t112.h>
29#include <media/soc_camera.h> 29#include <media/soc_camera.h>
30#include <media/v4l2-chip-ident.h> 30#include <media/v4l2-clk.h>
31#include <media/v4l2-common.h> 31#include <media/v4l2-common.h>
32 32
33/* you can check PLL/clock info */ 33/* you can check PLL/clock info */
@@ -90,8 +90,8 @@ struct mt9t112_priv {
90 struct mt9t112_camera_info *info; 90 struct mt9t112_camera_info *info;
91 struct i2c_client *client; 91 struct i2c_client *client;
92 struct v4l2_rect frame; 92 struct v4l2_rect frame;
93 struct v4l2_clk *clk;
93 const struct mt9t112_format *format; 94 const struct mt9t112_format *format;
94 int model;
95 int num_formats; 95 int num_formats;
96 u32 flags; 96 u32 flags;
97/* for flags */ 97/* for flags */
@@ -738,17 +738,6 @@ static int mt9t112_init_camera(const struct i2c_client *client)
738/************************************************************************ 738/************************************************************************
739 v4l2_subdev_core_ops 739 v4l2_subdev_core_ops
740************************************************************************/ 740************************************************************************/
741static int mt9t112_g_chip_ident(struct v4l2_subdev *sd,
742 struct v4l2_dbg_chip_ident *id)
743{
744 struct i2c_client *client = v4l2_get_subdevdata(sd);
745 struct mt9t112_priv *priv = to_mt9t112(client);
746
747 id->ident = priv->model;
748 id->revision = 0;
749
750 return 0;
751}
752 741
753#ifdef CONFIG_VIDEO_ADV_DEBUG 742#ifdef CONFIG_VIDEO_ADV_DEBUG
754static int mt9t112_g_register(struct v4l2_subdev *sd, 743static int mt9t112_g_register(struct v4l2_subdev *sd,
@@ -781,12 +770,12 @@ static int mt9t112_s_power(struct v4l2_subdev *sd, int on)
781{ 770{
782 struct i2c_client *client = v4l2_get_subdevdata(sd); 771 struct i2c_client *client = v4l2_get_subdevdata(sd);
783 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client); 772 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
773 struct mt9t112_priv *priv = to_mt9t112(client);
784 774
785 return soc_camera_set_power(&client->dev, ssdd, on); 775 return soc_camera_set_power(&client->dev, ssdd, priv->clk, on);
786} 776}
787 777
788static struct v4l2_subdev_core_ops mt9t112_subdev_core_ops = { 778static struct v4l2_subdev_core_ops mt9t112_subdev_core_ops = {
789 .g_chip_ident = mt9t112_g_chip_ident,
790#ifdef CONFIG_VIDEO_ADV_DEBUG 779#ifdef CONFIG_VIDEO_ADV_DEBUG
791 .g_register = mt9t112_g_register, 780 .g_register = mt9t112_g_register,
792 .s_register = mt9t112_s_register, 781 .s_register = mt9t112_s_register,
@@ -1061,12 +1050,10 @@ static int mt9t112_camera_probe(struct i2c_client *client)
1061 switch (chipid) { 1050 switch (chipid) {
1062 case 0x2680: 1051 case 0x2680:
1063 devname = "mt9t111"; 1052 devname = "mt9t111";
1064 priv->model = V4L2_IDENT_MT9T111;
1065 priv->num_formats = 1; 1053 priv->num_formats = 1;
1066 break; 1054 break;
1067 case 0x2682: 1055 case 0x2682:
1068 devname = "mt9t112"; 1056 devname = "mt9t112";
1069 priv->model = V4L2_IDENT_MT9T112;
1070 priv->num_formats = ARRAY_SIZE(mt9t112_cfmts); 1057 priv->num_formats = ARRAY_SIZE(mt9t112_cfmts);
1071 break; 1058 break;
1072 default: 1059 default:
@@ -1108,18 +1095,26 @@ static int mt9t112_probe(struct i2c_client *client,
1108 1095
1109 v4l2_i2c_subdev_init(&priv->subdev, client, &mt9t112_subdev_ops); 1096 v4l2_i2c_subdev_init(&priv->subdev, client, &mt9t112_subdev_ops);
1110 1097
1098 priv->clk = v4l2_clk_get(&client->dev, "mclk");
1099 if (IS_ERR(priv->clk))
1100 return PTR_ERR(priv->clk);
1101
1111 ret = mt9t112_camera_probe(client); 1102 ret = mt9t112_camera_probe(client);
1112 if (ret)
1113 return ret;
1114 1103
1115 /* Cannot fail: using the default supported pixel code */ 1104 /* Cannot fail: using the default supported pixel code */
1116 mt9t112_set_params(priv, &rect, V4L2_MBUS_FMT_UYVY8_2X8); 1105 if (!ret)
1106 mt9t112_set_params(priv, &rect, V4L2_MBUS_FMT_UYVY8_2X8);
1107 else
1108 v4l2_clk_put(priv->clk);
1117 1109
1118 return ret; 1110 return ret;
1119} 1111}
1120 1112
1121static int mt9t112_remove(struct i2c_client *client) 1113static int mt9t112_remove(struct i2c_client *client)
1122{ 1114{
1115 struct mt9t112_priv *priv = to_mt9t112(client);
1116
1117 v4l2_clk_put(priv->clk);
1123 return 0; 1118 return 0;
1124} 1119}
1125 1120
diff --git a/drivers/media/i2c/soc_camera/mt9v022.c b/drivers/media/i2c/soc_camera/mt9v022.c
index a295e598486f..f9f95f815b1a 100644
--- a/drivers/media/i2c/soc_camera/mt9v022.c
+++ b/drivers/media/i2c/soc_camera/mt9v022.c
@@ -19,7 +19,7 @@
19#include <media/soc_camera.h> 19#include <media/soc_camera.h>
20#include <media/soc_mediabus.h> 20#include <media/soc_mediabus.h>
21#include <media/v4l2-subdev.h> 21#include <media/v4l2-subdev.h>
22#include <media/v4l2-chip-ident.h> 22#include <media/v4l2-clk.h>
23#include <media/v4l2-ctrls.h> 23#include <media/v4l2-ctrls.h>
24 24
25/* 25/*
@@ -133,6 +133,11 @@ static const struct mt9v02x_register mt9v024_register = {
133 .pixclk_fv_lv = MT9V024_PIXCLK_FV_LV, 133 .pixclk_fv_lv = MT9V024_PIXCLK_FV_LV,
134}; 134};
135 135
136enum mt9v022_model {
137 MT9V022IX7ATM,
138 MT9V022IX7ATC,
139};
140
136struct mt9v022 { 141struct mt9v022 {
137 struct v4l2_subdev subdev; 142 struct v4l2_subdev subdev;
138 struct v4l2_ctrl_handler hdl; 143 struct v4l2_ctrl_handler hdl;
@@ -149,11 +154,12 @@ struct mt9v022 {
149 struct v4l2_ctrl *hblank; 154 struct v4l2_ctrl *hblank;
150 struct v4l2_ctrl *vblank; 155 struct v4l2_ctrl *vblank;
151 struct v4l2_rect rect; /* Sensor window */ 156 struct v4l2_rect rect; /* Sensor window */
157 struct v4l2_clk *clk;
152 const struct mt9v022_datafmt *fmt; 158 const struct mt9v022_datafmt *fmt;
153 const struct mt9v022_datafmt *fmts; 159 const struct mt9v022_datafmt *fmts;
154 const struct mt9v02x_register *reg; 160 const struct mt9v02x_register *reg;
155 int num_fmts; 161 int num_fmts;
156 int model; /* V4L2_IDENT_MT9V022* codes from v4l2-chip-ident.h */ 162 enum mt9v022_model model;
157 u16 chip_control; 163 u16 chip_control;
158 u16 chip_version; 164 u16 chip_version;
159 unsigned short y_skip_top; /* Lines to skip at the top */ 165 unsigned short y_skip_top; /* Lines to skip at the top */
@@ -406,12 +412,12 @@ static int mt9v022_s_fmt(struct v4l2_subdev *sd,
406 switch (mf->code) { 412 switch (mf->code) {
407 case V4L2_MBUS_FMT_Y8_1X8: 413 case V4L2_MBUS_FMT_Y8_1X8:
408 case V4L2_MBUS_FMT_Y10_1X10: 414 case V4L2_MBUS_FMT_Y10_1X10:
409 if (mt9v022->model != V4L2_IDENT_MT9V022IX7ATM) 415 if (mt9v022->model != MT9V022IX7ATM)
410 return -EINVAL; 416 return -EINVAL;
411 break; 417 break;
412 case V4L2_MBUS_FMT_SBGGR8_1X8: 418 case V4L2_MBUS_FMT_SBGGR8_1X8:
413 case V4L2_MBUS_FMT_SBGGR10_1X10: 419 case V4L2_MBUS_FMT_SBGGR10_1X10:
414 if (mt9v022->model != V4L2_IDENT_MT9V022IX7ATC) 420 if (mt9v022->model != MT9V022IX7ATC)
415 return -EINVAL; 421 return -EINVAL;
416 break; 422 break;
417 default: 423 default:
@@ -457,36 +463,15 @@ static int mt9v022_try_fmt(struct v4l2_subdev *sd,
457 return 0; 463 return 0;
458} 464}
459 465
460static int mt9v022_g_chip_ident(struct v4l2_subdev *sd,
461 struct v4l2_dbg_chip_ident *id)
462{
463 struct i2c_client *client = v4l2_get_subdevdata(sd);
464 struct mt9v022 *mt9v022 = to_mt9v022(client);
465
466 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
467 return -EINVAL;
468
469 if (id->match.addr != client->addr)
470 return -ENODEV;
471
472 id->ident = mt9v022->model;
473 id->revision = 0;
474
475 return 0;
476}
477
478#ifdef CONFIG_VIDEO_ADV_DEBUG 466#ifdef CONFIG_VIDEO_ADV_DEBUG
479static int mt9v022_g_register(struct v4l2_subdev *sd, 467static int mt9v022_g_register(struct v4l2_subdev *sd,
480 struct v4l2_dbg_register *reg) 468 struct v4l2_dbg_register *reg)
481{ 469{
482 struct i2c_client *client = v4l2_get_subdevdata(sd); 470 struct i2c_client *client = v4l2_get_subdevdata(sd);
483 471
484 if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff) 472 if (reg->reg > 0xff)
485 return -EINVAL; 473 return -EINVAL;
486 474
487 if (reg->match.addr != client->addr)
488 return -ENODEV;
489
490 reg->size = 2; 475 reg->size = 2;
491 reg->val = reg_read(client, reg->reg); 476 reg->val = reg_read(client, reg->reg);
492 477
@@ -501,12 +486,9 @@ static int mt9v022_s_register(struct v4l2_subdev *sd,
501{ 486{
502 struct i2c_client *client = v4l2_get_subdevdata(sd); 487 struct i2c_client *client = v4l2_get_subdevdata(sd);
503 488
504 if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff) 489 if (reg->reg > 0xff)
505 return -EINVAL; 490 return -EINVAL;
506 491
507 if (reg->match.addr != client->addr)
508 return -ENODEV;
509
510 if (reg_write(client, reg->reg, reg->val) < 0) 492 if (reg_write(client, reg->reg, reg->val) < 0)
511 return -EIO; 493 return -EIO;
512 494
@@ -518,8 +500,9 @@ static int mt9v022_s_power(struct v4l2_subdev *sd, int on)
518{ 500{
519 struct i2c_client *client = v4l2_get_subdevdata(sd); 501 struct i2c_client *client = v4l2_get_subdevdata(sd);
520 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client); 502 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
503 struct mt9v022 *mt9v022 = to_mt9v022(client);
521 504
522 return soc_camera_set_power(&client->dev, ssdd, on); 505 return soc_camera_set_power(&client->dev, ssdd, mt9v022->clk, on);
523} 506}
524 507
525static int mt9v022_g_volatile_ctrl(struct v4l2_ctrl *ctrl) 508static int mt9v022_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
@@ -706,11 +689,11 @@ static int mt9v022_video_probe(struct i2c_client *client)
706 if (sensor_type && (!strcmp("colour", sensor_type) || 689 if (sensor_type && (!strcmp("colour", sensor_type) ||
707 !strcmp("color", sensor_type))) { 690 !strcmp("color", sensor_type))) {
708 ret = reg_write(client, MT9V022_PIXEL_OPERATION_MODE, 4 | 0x11); 691 ret = reg_write(client, MT9V022_PIXEL_OPERATION_MODE, 4 | 0x11);
709 mt9v022->model = V4L2_IDENT_MT9V022IX7ATC; 692 mt9v022->model = MT9V022IX7ATC;
710 mt9v022->fmts = mt9v022_colour_fmts; 693 mt9v022->fmts = mt9v022_colour_fmts;
711 } else { 694 } else {
712 ret = reg_write(client, MT9V022_PIXEL_OPERATION_MODE, 0x11); 695 ret = reg_write(client, MT9V022_PIXEL_OPERATION_MODE, 0x11);
713 mt9v022->model = V4L2_IDENT_MT9V022IX7ATM; 696 mt9v022->model = MT9V022IX7ATM;
714 mt9v022->fmts = mt9v022_monochrome_fmts; 697 mt9v022->fmts = mt9v022_monochrome_fmts;
715 } 698 }
716 699
@@ -740,7 +723,7 @@ static int mt9v022_video_probe(struct i2c_client *client)
740 mt9v022->fmt = &mt9v022->fmts[0]; 723 mt9v022->fmt = &mt9v022->fmts[0];
741 724
742 dev_info(&client->dev, "Detected a MT9V022 chip ID %x, %s sensor\n", 725 dev_info(&client->dev, "Detected a MT9V022 chip ID %x, %s sensor\n",
743 data, mt9v022->model == V4L2_IDENT_MT9V022IX7ATM ? 726 data, mt9v022->model == MT9V022IX7ATM ?
744 "monochrome" : "colour"); 727 "monochrome" : "colour");
745 728
746 ret = mt9v022_init(client); 729 ret = mt9v022_init(client);
@@ -768,7 +751,6 @@ static const struct v4l2_ctrl_ops mt9v022_ctrl_ops = {
768}; 751};
769 752
770static struct v4l2_subdev_core_ops mt9v022_subdev_core_ops = { 753static struct v4l2_subdev_core_ops mt9v022_subdev_core_ops = {
771 .g_chip_ident = mt9v022_g_chip_ident,
772#ifdef CONFIG_VIDEO_ADV_DEBUG 754#ifdef CONFIG_VIDEO_ADV_DEBUG
773 .g_register = mt9v022_g_register, 755 .g_register = mt9v022_g_register,
774 .s_register = mt9v022_s_register, 756 .s_register = mt9v022_s_register,
@@ -957,9 +939,18 @@ static int mt9v022_probe(struct i2c_client *client,
957 mt9v022->rect.width = MT9V022_MAX_WIDTH; 939 mt9v022->rect.width = MT9V022_MAX_WIDTH;
958 mt9v022->rect.height = MT9V022_MAX_HEIGHT; 940 mt9v022->rect.height = MT9V022_MAX_HEIGHT;
959 941
942 mt9v022->clk = v4l2_clk_get(&client->dev, "mclk");
943 if (IS_ERR(mt9v022->clk)) {
944 ret = PTR_ERR(mt9v022->clk);
945 goto eclkget;
946 }
947
960 ret = mt9v022_video_probe(client); 948 ret = mt9v022_video_probe(client);
961 if (ret) 949 if (ret) {
950 v4l2_clk_put(mt9v022->clk);
951eclkget:
962 v4l2_ctrl_handler_free(&mt9v022->hdl); 952 v4l2_ctrl_handler_free(&mt9v022->hdl);
953 }
963 954
964 return ret; 955 return ret;
965} 956}
@@ -969,6 +960,7 @@ static int mt9v022_remove(struct i2c_client *client)
969 struct mt9v022 *mt9v022 = to_mt9v022(client); 960 struct mt9v022 *mt9v022 = to_mt9v022(client);
970 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client); 961 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
971 962
963 v4l2_clk_put(mt9v022->clk);
972 v4l2_device_unregister_subdev(&mt9v022->subdev); 964 v4l2_device_unregister_subdev(&mt9v022->subdev);
973 if (ssdd->free_bus) 965 if (ssdd->free_bus)
974 ssdd->free_bus(ssdd); 966 ssdd->free_bus(ssdd);
diff --git a/drivers/media/i2c/soc_camera/ov2640.c b/drivers/media/i2c/soc_camera/ov2640.c
index e3168424f9ba..6c6b1c3b45e3 100644
--- a/drivers/media/i2c/soc_camera/ov2640.c
+++ b/drivers/media/i2c/soc_camera/ov2640.c
@@ -22,7 +22,7 @@
22#include <linux/videodev2.h> 22#include <linux/videodev2.h>
23 23
24#include <media/soc_camera.h> 24#include <media/soc_camera.h>
25#include <media/v4l2-chip-ident.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 28
@@ -303,8 +303,8 @@ struct ov2640_priv {
303 struct v4l2_subdev subdev; 303 struct v4l2_subdev subdev;
304 struct v4l2_ctrl_handler hdl; 304 struct v4l2_ctrl_handler hdl;
305 enum v4l2_mbus_pixelcode cfmt_code; 305 enum v4l2_mbus_pixelcode cfmt_code;
306 struct v4l2_clk *clk;
306 const struct ov2640_win_size *win; 307 const struct ov2640_win_size *win;
307 int model;
308}; 308};
309 309
310/* 310/*
@@ -723,18 +723,6 @@ static int ov2640_s_ctrl(struct v4l2_ctrl *ctrl)
723 return -EINVAL; 723 return -EINVAL;
724} 724}
725 725
726static int ov2640_g_chip_ident(struct v4l2_subdev *sd,
727 struct v4l2_dbg_chip_ident *id)
728{
729 struct i2c_client *client = v4l2_get_subdevdata(sd);
730 struct ov2640_priv *priv = to_ov2640(client);
731
732 id->ident = priv->model;
733 id->revision = 0;
734
735 return 0;
736}
737
738#ifdef CONFIG_VIDEO_ADV_DEBUG 726#ifdef CONFIG_VIDEO_ADV_DEBUG
739static int ov2640_g_register(struct v4l2_subdev *sd, 727static int ov2640_g_register(struct v4l2_subdev *sd,
740 struct v4l2_dbg_register *reg) 728 struct v4l2_dbg_register *reg)
@@ -772,8 +760,9 @@ static int ov2640_s_power(struct v4l2_subdev *sd, int on)
772{ 760{
773 struct i2c_client *client = v4l2_get_subdevdata(sd); 761 struct i2c_client *client = v4l2_get_subdevdata(sd);
774 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client); 762 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
763 struct ov2640_priv *priv = to_ov2640(client);
775 764
776 return soc_camera_set_power(&client->dev, ssdd, on); 765 return soc_camera_set_power(&client->dev, ssdd, priv->clk, on);
777} 766}
778 767
779/* Select the nearest higher resolution for capture */ 768/* Select the nearest higher resolution for capture */
@@ -1009,7 +998,6 @@ static int ov2640_video_probe(struct i2c_client *client)
1009 switch (VERSION(pid, ver)) { 998 switch (VERSION(pid, ver)) {
1010 case PID_OV2640: 999 case PID_OV2640:
1011 devname = "ov2640"; 1000 devname = "ov2640";
1012 priv->model = V4L2_IDENT_OV2640;
1013 break; 1001 break;
1014 default: 1002 default:
1015 dev_err(&client->dev, 1003 dev_err(&client->dev,
@@ -1034,7 +1022,6 @@ static const struct v4l2_ctrl_ops ov2640_ctrl_ops = {
1034}; 1022};
1035 1023
1036static struct v4l2_subdev_core_ops ov2640_subdev_core_ops = { 1024static struct v4l2_subdev_core_ops ov2640_subdev_core_ops = {
1037 .g_chip_ident = ov2640_g_chip_ident,
1038#ifdef CONFIG_VIDEO_ADV_DEBUG 1025#ifdef CONFIG_VIDEO_ADV_DEBUG
1039 .g_register = ov2640_g_register, 1026 .g_register = ov2640_g_register,
1040 .s_register = ov2640_s_register, 1027 .s_register = ov2640_s_register,
@@ -1113,11 +1100,20 @@ static int ov2640_probe(struct i2c_client *client,
1113 if (priv->hdl.error) 1100 if (priv->hdl.error)
1114 return priv->hdl.error; 1101 return priv->hdl.error;
1115 1102
1103 priv->clk = v4l2_clk_get(&client->dev, "mclk");
1104 if (IS_ERR(priv->clk)) {
1105 ret = PTR_ERR(priv->clk);
1106 goto eclkget;
1107 }
1108
1116 ret = ov2640_video_probe(client); 1109 ret = ov2640_video_probe(client);
1117 if (ret) 1110 if (ret) {
1111 v4l2_clk_put(priv->clk);
1112eclkget:
1118 v4l2_ctrl_handler_free(&priv->hdl); 1113 v4l2_ctrl_handler_free(&priv->hdl);
1119 else 1114 } else {
1120 dev_info(&adapter->dev, "OV2640 Probed\n"); 1115 dev_info(&adapter->dev, "OV2640 Probed\n");
1116 }
1121 1117
1122 return ret; 1118 return ret;
1123} 1119}
@@ -1126,6 +1122,7 @@ static int ov2640_remove(struct i2c_client *client)
1126{ 1122{
1127 struct ov2640_priv *priv = to_ov2640(client); 1123 struct ov2640_priv *priv = to_ov2640(client);
1128 1124
1125 v4l2_clk_put(priv->clk);
1129 v4l2_device_unregister_subdev(&priv->subdev); 1126 v4l2_device_unregister_subdev(&priv->subdev);
1130 v4l2_ctrl_handler_free(&priv->hdl); 1127 v4l2_ctrl_handler_free(&priv->hdl);
1131 return 0; 1128 return 0;
diff --git a/drivers/media/i2c/soc_camera/ov5642.c b/drivers/media/i2c/soc_camera/ov5642.c
index 9aa56de69eed..0a5c5d4fedd6 100644
--- a/drivers/media/i2c/soc_camera/ov5642.c
+++ b/drivers/media/i2c/soc_camera/ov5642.c
@@ -24,7 +24,7 @@
24#include <linux/v4l2-mediabus.h> 24#include <linux/v4l2-mediabus.h>
25 25
26#include <media/soc_camera.h> 26#include <media/soc_camera.h>
27#include <media/v4l2-chip-ident.h> 27#include <media/v4l2-clk.h>
28#include <media/v4l2-subdev.h> 28#include <media/v4l2-subdev.h>
29 29
30/* OV5642 registers */ 30/* OV5642 registers */
@@ -610,6 +610,7 @@ struct ov5642 {
610 struct v4l2_subdev subdev; 610 struct v4l2_subdev subdev;
611 const struct ov5642_datafmt *fmt; 611 const struct ov5642_datafmt *fmt;
612 struct v4l2_rect crop_rect; 612 struct v4l2_rect crop_rect;
613 struct v4l2_clk *clk;
613 614
614 /* blanking information */ 615 /* blanking information */
615 int total_width; 616 int total_width;
@@ -848,23 +849,6 @@ static int ov5642_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
848 return 0; 849 return 0;
849} 850}
850 851
851static int ov5642_g_chip_ident(struct v4l2_subdev *sd,
852 struct v4l2_dbg_chip_ident *id)
853{
854 struct i2c_client *client = v4l2_get_subdevdata(sd);
855
856 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
857 return -EINVAL;
858
859 if (id->match.addr != client->addr)
860 return -ENODEV;
861
862 id->ident = V4L2_IDENT_OV5642;
863 id->revision = 0;
864
865 return 0;
866}
867
868static int ov5642_s_crop(struct v4l2_subdev *sd, const struct v4l2_crop *a) 852static int ov5642_s_crop(struct v4l2_subdev *sd, const struct v4l2_crop *a)
869{ 853{
870 struct i2c_client *client = v4l2_get_subdevdata(sd); 854 struct i2c_client *client = v4l2_get_subdevdata(sd);
@@ -935,12 +919,13 @@ static int ov5642_s_power(struct v4l2_subdev *sd, int on)
935{ 919{
936 struct i2c_client *client = v4l2_get_subdevdata(sd); 920 struct i2c_client *client = v4l2_get_subdevdata(sd);
937 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client); 921 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
922 struct ov5642 *priv = to_ov5642(client);
938 int ret; 923 int ret;
939 924
940 if (!on) 925 if (!on)
941 return soc_camera_power_off(&client->dev, ssdd); 926 return soc_camera_power_off(&client->dev, ssdd, priv->clk);
942 927
943 ret = soc_camera_power_on(&client->dev, ssdd); 928 ret = soc_camera_power_on(&client->dev, ssdd, priv->clk);
944 if (ret < 0) 929 if (ret < 0)
945 return ret; 930 return ret;
946 931
@@ -966,7 +951,6 @@ static struct v4l2_subdev_video_ops ov5642_subdev_video_ops = {
966 951
967static struct v4l2_subdev_core_ops ov5642_subdev_core_ops = { 952static struct v4l2_subdev_core_ops ov5642_subdev_core_ops = {
968 .s_power = ov5642_s_power, 953 .s_power = ov5642_s_power,
969 .g_chip_ident = ov5642_g_chip_ident,
970#ifdef CONFIG_VIDEO_ADV_DEBUG 954#ifdef CONFIG_VIDEO_ADV_DEBUG
971 .g_register = ov5642_get_register, 955 .g_register = ov5642_get_register,
972 .s_register = ov5642_set_register, 956 .s_register = ov5642_set_register,
@@ -1021,6 +1005,7 @@ static int ov5642_probe(struct i2c_client *client,
1021{ 1005{
1022 struct ov5642 *priv; 1006 struct ov5642 *priv;
1023 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client); 1007 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
1008 int ret;
1024 1009
1025 if (!ssdd) { 1010 if (!ssdd) {
1026 dev_err(&client->dev, "OV5642: missing platform data!\n"); 1011 dev_err(&client->dev, "OV5642: missing platform data!\n");
@@ -1042,13 +1027,23 @@ static int ov5642_probe(struct i2c_client *client,
1042 priv->total_width = OV5642_DEFAULT_WIDTH + BLANKING_EXTRA_WIDTH; 1027 priv->total_width = OV5642_DEFAULT_WIDTH + BLANKING_EXTRA_WIDTH;
1043 priv->total_height = BLANKING_MIN_HEIGHT; 1028 priv->total_height = BLANKING_MIN_HEIGHT;
1044 1029
1045 return ov5642_video_probe(client); 1030 priv->clk = v4l2_clk_get(&client->dev, "mclk");
1031 if (IS_ERR(priv->clk))
1032 return PTR_ERR(priv->clk);
1033
1034 ret = ov5642_video_probe(client);
1035 if (ret < 0)
1036 v4l2_clk_put(priv->clk);
1037
1038 return ret;
1046} 1039}
1047 1040
1048static int ov5642_remove(struct i2c_client *client) 1041static int ov5642_remove(struct i2c_client *client)
1049{ 1042{
1050 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client); 1043 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
1044 struct ov5642 *priv = to_ov5642(client);
1051 1045
1046 v4l2_clk_put(priv->clk);
1052 if (ssdd->free_bus) 1047 if (ssdd->free_bus)
1053 ssdd->free_bus(ssdd); 1048 ssdd->free_bus(ssdd);
1054 1049
diff --git a/drivers/media/i2c/soc_camera/ov6650.c b/drivers/media/i2c/soc_camera/ov6650.c
index 991202d4bbae..ab01598ec83f 100644
--- a/drivers/media/i2c/soc_camera/ov6650.c
+++ b/drivers/media/i2c/soc_camera/ov6650.c
@@ -32,7 +32,7 @@
32#include <linux/module.h> 32#include <linux/module.h>
33 33
34#include <media/soc_camera.h> 34#include <media/soc_camera.h>
35#include <media/v4l2-chip-ident.h> 35#include <media/v4l2-clk.h>
36#include <media/v4l2-ctrls.h> 36#include <media/v4l2-ctrls.h>
37 37
38/* Register definitions */ 38/* Register definitions */
@@ -196,6 +196,7 @@ struct ov6650 {
196 struct v4l2_ctrl *blue; 196 struct v4l2_ctrl *blue;
197 struct v4l2_ctrl *red; 197 struct v4l2_ctrl *red;
198 }; 198 };
199 struct v4l2_clk *clk;
199 bool half_scale; /* scale down output by 2 */ 200 bool half_scale; /* scale down output by 2 */
200 struct v4l2_rect rect; /* sensor cropping window */ 201 struct v4l2_rect rect; /* sensor cropping window */
201 unsigned long pclk_limit; /* from host */ 202 unsigned long pclk_limit; /* from host */
@@ -390,16 +391,6 @@ static int ov6550_s_ctrl(struct v4l2_ctrl *ctrl)
390 return -EINVAL; 391 return -EINVAL;
391} 392}
392 393
393/* Get chip identification */
394static int ov6650_g_chip_ident(struct v4l2_subdev *sd,
395 struct v4l2_dbg_chip_ident *id)
396{
397 id->ident = V4L2_IDENT_OV6650;
398 id->revision = 0;
399
400 return 0;
401}
402
403#ifdef CONFIG_VIDEO_ADV_DEBUG 394#ifdef CONFIG_VIDEO_ADV_DEBUG
404static int ov6650_get_register(struct v4l2_subdev *sd, 395static int ov6650_get_register(struct v4l2_subdev *sd,
405 struct v4l2_dbg_register *reg) 396 struct v4l2_dbg_register *reg)
@@ -436,8 +427,9 @@ static int ov6650_s_power(struct v4l2_subdev *sd, int on)
436{ 427{
437 struct i2c_client *client = v4l2_get_subdevdata(sd); 428 struct i2c_client *client = v4l2_get_subdevdata(sd);
438 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client); 429 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
430 struct ov6650 *priv = to_ov6650(client);
439 431
440 return soc_camera_set_power(&client->dev, ssdd, on); 432 return soc_camera_set_power(&client->dev, ssdd, priv->clk, on);
441} 433}
442 434
443static int ov6650_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a) 435static int ov6650_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
@@ -879,7 +871,6 @@ static const struct v4l2_ctrl_ops ov6550_ctrl_ops = {
879}; 871};
880 872
881static struct v4l2_subdev_core_ops ov6650_core_ops = { 873static struct v4l2_subdev_core_ops ov6650_core_ops = {
882 .g_chip_ident = ov6650_g_chip_ident,
883#ifdef CONFIG_VIDEO_ADV_DEBUG 874#ifdef CONFIG_VIDEO_ADV_DEBUG
884 .g_register = ov6650_get_register, 875 .g_register = ov6650_get_register,
885 .s_register = ov6650_set_register, 876 .s_register = ov6650_set_register,
@@ -1025,9 +1016,18 @@ static int ov6650_probe(struct i2c_client *client,
1025 priv->code = V4L2_MBUS_FMT_YUYV8_2X8; 1016 priv->code = V4L2_MBUS_FMT_YUYV8_2X8;
1026 priv->colorspace = V4L2_COLORSPACE_JPEG; 1017 priv->colorspace = V4L2_COLORSPACE_JPEG;
1027 1018
1019 priv->clk = v4l2_clk_get(&client->dev, "mclk");
1020 if (IS_ERR(priv->clk)) {
1021 ret = PTR_ERR(priv->clk);
1022 goto eclkget;
1023 }
1024
1028 ret = ov6650_video_probe(client); 1025 ret = ov6650_video_probe(client);
1029 if (ret) 1026 if (ret) {
1027 v4l2_clk_put(priv->clk);
1028eclkget:
1030 v4l2_ctrl_handler_free(&priv->hdl); 1029 v4l2_ctrl_handler_free(&priv->hdl);
1030 }
1031 1031
1032 return ret; 1032 return ret;
1033} 1033}
@@ -1036,6 +1036,7 @@ static int ov6650_remove(struct i2c_client *client)
1036{ 1036{
1037 struct ov6650 *priv = to_ov6650(client); 1037 struct ov6650 *priv = to_ov6650(client);
1038 1038
1039 v4l2_clk_put(priv->clk);
1039 v4l2_device_unregister_subdev(&priv->subdev); 1040 v4l2_device_unregister_subdev(&priv->subdev);
1040 v4l2_ctrl_handler_free(&priv->hdl); 1041 v4l2_ctrl_handler_free(&priv->hdl);
1041 return 0; 1042 return 0;
diff --git a/drivers/media/i2c/soc_camera/ov772x.c b/drivers/media/i2c/soc_camera/ov772x.c
index 713d62e349f6..7f2b3c8926af 100644
--- a/drivers/media/i2c/soc_camera/ov772x.c
+++ b/drivers/media/i2c/soc_camera/ov772x.c
@@ -26,8 +26,8 @@
26 26
27#include <media/ov772x.h> 27#include <media/ov772x.h>
28#include <media/soc_camera.h> 28#include <media/soc_camera.h>
29#include <media/v4l2-clk.h>
29#include <media/v4l2-ctrls.h> 30#include <media/v4l2-ctrls.h>
30#include <media/v4l2-chip-ident.h>
31#include <media/v4l2-subdev.h> 31#include <media/v4l2-subdev.h>
32 32
33/* 33/*
@@ -396,10 +396,10 @@ struct ov772x_win_size {
396struct ov772x_priv { 396struct ov772x_priv {
397 struct v4l2_subdev subdev; 397 struct v4l2_subdev subdev;
398 struct v4l2_ctrl_handler hdl; 398 struct v4l2_ctrl_handler hdl;
399 struct v4l2_clk *clk;
399 struct ov772x_camera_info *info; 400 struct ov772x_camera_info *info;
400 const struct ov772x_color_format *cfmt; 401 const struct ov772x_color_format *cfmt;
401 const struct ov772x_win_size *win; 402 const struct ov772x_win_size *win;
402 int model;
403 unsigned short flag_vflip:1; 403 unsigned short flag_vflip:1;
404 unsigned short flag_hflip:1; 404 unsigned short flag_hflip:1;
405 /* band_filter = COM8[5] ? 256 - BDBASE : 0 */ 405 /* band_filter = COM8[5] ? 256 - BDBASE : 0 */
@@ -620,17 +620,6 @@ static int ov772x_s_ctrl(struct v4l2_ctrl *ctrl)
620 return -EINVAL; 620 return -EINVAL;
621} 621}
622 622
623static int ov772x_g_chip_ident(struct v4l2_subdev *sd,
624 struct v4l2_dbg_chip_ident *id)
625{
626 struct ov772x_priv *priv = to_ov772x(sd);
627
628 id->ident = priv->model;
629 id->revision = 0;
630
631 return 0;
632}
633
634#ifdef CONFIG_VIDEO_ADV_DEBUG 623#ifdef CONFIG_VIDEO_ADV_DEBUG
635static int ov772x_g_register(struct v4l2_subdev *sd, 624static int ov772x_g_register(struct v4l2_subdev *sd,
636 struct v4l2_dbg_register *reg) 625 struct v4l2_dbg_register *reg)
@@ -668,8 +657,9 @@ static int ov772x_s_power(struct v4l2_subdev *sd, int on)
668{ 657{
669 struct i2c_client *client = v4l2_get_subdevdata(sd); 658 struct i2c_client *client = v4l2_get_subdevdata(sd);
670 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client); 659 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
660 struct ov772x_priv *priv = to_ov772x(sd);
671 661
672 return soc_camera_set_power(&client->dev, ssdd, on); 662 return soc_camera_set_power(&client->dev, ssdd, priv->clk, on);
673} 663}
674 664
675static const struct ov772x_win_size *ov772x_select_win(u32 width, u32 height) 665static const struct ov772x_win_size *ov772x_select_win(u32 width, u32 height)
@@ -965,11 +955,9 @@ static int ov772x_video_probe(struct ov772x_priv *priv)
965 switch (VERSION(pid, ver)) { 955 switch (VERSION(pid, ver)) {
966 case OV7720: 956 case OV7720:
967 devname = "ov7720"; 957 devname = "ov7720";
968 priv->model = V4L2_IDENT_OV7720;
969 break; 958 break;
970 case OV7725: 959 case OV7725:
971 devname = "ov7725"; 960 devname = "ov7725";
972 priv->model = V4L2_IDENT_OV7725;
973 break; 961 break;
974 default: 962 default:
975 dev_err(&client->dev, 963 dev_err(&client->dev,
@@ -997,7 +985,6 @@ static const struct v4l2_ctrl_ops ov772x_ctrl_ops = {
997}; 985};
998 986
999static struct v4l2_subdev_core_ops ov772x_subdev_core_ops = { 987static struct v4l2_subdev_core_ops ov772x_subdev_core_ops = {
1000 .g_chip_ident = ov772x_g_chip_ident,
1001#ifdef CONFIG_VIDEO_ADV_DEBUG 988#ifdef CONFIG_VIDEO_ADV_DEBUG
1002 .g_register = ov772x_g_register, 989 .g_register = ov772x_g_register,
1003 .s_register = ov772x_s_register, 990 .s_register = ov772x_s_register,
@@ -1088,13 +1075,22 @@ static int ov772x_probe(struct i2c_client *client,
1088 if (priv->hdl.error) 1075 if (priv->hdl.error)
1089 return priv->hdl.error; 1076 return priv->hdl.error;
1090 1077
1078 priv->clk = v4l2_clk_get(&client->dev, "mclk");
1079 if (IS_ERR(priv->clk)) {
1080 ret = PTR_ERR(priv->clk);
1081 goto eclkget;
1082 }
1083
1091 ret = ov772x_video_probe(priv); 1084 ret = ov772x_video_probe(priv);
1092 if (ret < 0) { 1085 if (ret < 0) {
1086 v4l2_clk_put(priv->clk);
1087eclkget:
1093 v4l2_ctrl_handler_free(&priv->hdl); 1088 v4l2_ctrl_handler_free(&priv->hdl);
1094 } else { 1089 } else {
1095 priv->cfmt = &ov772x_cfmts[0]; 1090 priv->cfmt = &ov772x_cfmts[0];
1096 priv->win = &ov772x_win_sizes[0]; 1091 priv->win = &ov772x_win_sizes[0];
1097 } 1092 }
1093
1098 return ret; 1094 return ret;
1099} 1095}
1100 1096
@@ -1102,6 +1098,7 @@ static int ov772x_remove(struct i2c_client *client)
1102{ 1098{
1103 struct ov772x_priv *priv = to_ov772x(i2c_get_clientdata(client)); 1099 struct ov772x_priv *priv = to_ov772x(i2c_get_clientdata(client));
1104 1100
1101 v4l2_clk_put(priv->clk);
1105 v4l2_device_unregister_subdev(&priv->subdev); 1102 v4l2_device_unregister_subdev(&priv->subdev);
1106 v4l2_ctrl_handler_free(&priv->hdl); 1103 v4l2_ctrl_handler_free(&priv->hdl);
1107 return 0; 1104 return 0;
diff --git a/drivers/media/i2c/soc_camera/ov9640.c b/drivers/media/i2c/soc_camera/ov9640.c
index 20ca62d371c1..e968c3fdbd9e 100644
--- a/drivers/media/i2c/soc_camera/ov9640.c
+++ b/drivers/media/i2c/soc_camera/ov9640.c
@@ -28,7 +28,7 @@
28#include <linux/videodev2.h> 28#include <linux/videodev2.h>
29 29
30#include <media/soc_camera.h> 30#include <media/soc_camera.h>
31#include <media/v4l2-chip-ident.h> 31#include <media/v4l2-clk.h>
32#include <media/v4l2-common.h> 32#include <media/v4l2-common.h>
33#include <media/v4l2-ctrls.h> 33#include <media/v4l2-ctrls.h>
34 34
@@ -61,7 +61,7 @@ static const struct ov9640_reg ov9640_regs_dflt[] = {
61 61
62/* Configurations 62/* Configurations
63 * NOTE: for YUV, alter the following registers: 63 * NOTE: for YUV, alter the following registers:
64 * COM12 |= OV9640_COM12_YUV_AVG 64 * COM12 |= OV9640_COM12_YUV_AVG
65 * 65 *
66 * for RGB, alter the following registers: 66 * for RGB, alter the following registers:
67 * COM7 |= OV9640_COM7_RGB 67 * COM7 |= OV9640_COM7_RGB
@@ -287,18 +287,6 @@ static int ov9640_s_ctrl(struct v4l2_ctrl *ctrl)
287 return -EINVAL; 287 return -EINVAL;
288} 288}
289 289
290/* Get chip identification */
291static int ov9640_g_chip_ident(struct v4l2_subdev *sd,
292 struct v4l2_dbg_chip_ident *id)
293{
294 struct ov9640_priv *priv = to_ov9640_sensor(sd);
295
296 id->ident = priv->model;
297 id->revision = priv->revision;
298
299 return 0;
300}
301
302#ifdef CONFIG_VIDEO_ADV_DEBUG 290#ifdef CONFIG_VIDEO_ADV_DEBUG
303static int ov9640_get_register(struct v4l2_subdev *sd, 291static int ov9640_get_register(struct v4l2_subdev *sd,
304 struct v4l2_dbg_register *reg) 292 struct v4l2_dbg_register *reg)
@@ -337,8 +325,9 @@ static int ov9640_s_power(struct v4l2_subdev *sd, int on)
337{ 325{
338 struct i2c_client *client = v4l2_get_subdevdata(sd); 326 struct i2c_client *client = v4l2_get_subdevdata(sd);
339 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client); 327 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
328 struct ov9640_priv *priv = to_ov9640_sensor(sd);
340 329
341 return soc_camera_set_power(&client->dev, ssdd, on); 330 return soc_camera_set_power(&client->dev, ssdd, priv->clk, on);
342} 331}
343 332
344/* select nearest higher resolution for capture */ 333/* select nearest higher resolution for capture */
@@ -615,12 +604,10 @@ static int ov9640_video_probe(struct i2c_client *client)
615 switch (VERSION(pid, ver)) { 604 switch (VERSION(pid, ver)) {
616 case OV9640_V2: 605 case OV9640_V2:
617 devname = "ov9640"; 606 devname = "ov9640";
618 priv->model = V4L2_IDENT_OV9640;
619 priv->revision = 2; 607 priv->revision = 2;
620 break; 608 break;
621 case OV9640_V3: 609 case OV9640_V3:
622 devname = "ov9640"; 610 devname = "ov9640";
623 priv->model = V4L2_IDENT_OV9640;
624 priv->revision = 3; 611 priv->revision = 3;
625 break; 612 break;
626 default: 613 default:
@@ -644,7 +631,6 @@ static const struct v4l2_ctrl_ops ov9640_ctrl_ops = {
644}; 631};
645 632
646static struct v4l2_subdev_core_ops ov9640_core_ops = { 633static struct v4l2_subdev_core_ops ov9640_core_ops = {
647 .g_chip_ident = ov9640_g_chip_ident,
648#ifdef CONFIG_VIDEO_ADV_DEBUG 634#ifdef CONFIG_VIDEO_ADV_DEBUG
649 .g_register = ov9640_get_register, 635 .g_register = ov9640_get_register,
650 .s_register = ov9640_set_register, 636 .s_register = ov9640_set_register,
@@ -716,10 +702,18 @@ static int ov9640_probe(struct i2c_client *client,
716 if (priv->hdl.error) 702 if (priv->hdl.error)
717 return priv->hdl.error; 703 return priv->hdl.error;
718 704
719 ret = ov9640_video_probe(client); 705 priv->clk = v4l2_clk_get(&client->dev, "mclk");
706 if (IS_ERR(priv->clk)) {
707 ret = PTR_ERR(priv->clk);
708 goto eclkget;
709 }
720 710
721 if (ret) 711 ret = ov9640_video_probe(client);
712 if (ret) {
713 v4l2_clk_put(priv->clk);
714eclkget:
722 v4l2_ctrl_handler_free(&priv->hdl); 715 v4l2_ctrl_handler_free(&priv->hdl);
716 }
723 717
724 return ret; 718 return ret;
725} 719}
@@ -729,6 +723,7 @@ static int ov9640_remove(struct i2c_client *client)
729 struct v4l2_subdev *sd = i2c_get_clientdata(client); 723 struct v4l2_subdev *sd = i2c_get_clientdata(client);
730 struct ov9640_priv *priv = to_ov9640_sensor(sd); 724 struct ov9640_priv *priv = to_ov9640_sensor(sd);
731 725
726 v4l2_clk_put(priv->clk);
732 v4l2_device_unregister_subdev(&priv->subdev); 727 v4l2_device_unregister_subdev(&priv->subdev);
733 v4l2_ctrl_handler_free(&priv->hdl); 728 v4l2_ctrl_handler_free(&priv->hdl);
734 return 0; 729 return 0;
diff --git a/drivers/media/i2c/soc_camera/ov9640.h b/drivers/media/i2c/soc_camera/ov9640.h
index 6b33a972c83c..65d13ff17536 100644
--- a/drivers/media/i2c/soc_camera/ov9640.h
+++ b/drivers/media/i2c/soc_camera/ov9640.h
@@ -199,6 +199,7 @@ struct ov9640_reg {
199struct ov9640_priv { 199struct ov9640_priv {
200 struct v4l2_subdev subdev; 200 struct v4l2_subdev subdev;
201 struct v4l2_ctrl_handler hdl; 201 struct v4l2_ctrl_handler hdl;
202 struct v4l2_clk *clk;
202 203
203 int model; 204 int model;
204 int revision; 205 int revision;
diff --git a/drivers/media/i2c/soc_camera/ov9740.c b/drivers/media/i2c/soc_camera/ov9740.c
index 012bd6271124..ea76863dfdb4 100644
--- a/drivers/media/i2c/soc_camera/ov9740.c
+++ b/drivers/media/i2c/soc_camera/ov9740.c
@@ -17,7 +17,7 @@
17#include <linux/v4l2-mediabus.h> 17#include <linux/v4l2-mediabus.h>
18 18
19#include <media/soc_camera.h> 19#include <media/soc_camera.h>
20#include <media/v4l2-chip-ident.h> 20#include <media/v4l2-clk.h>
21#include <media/v4l2-ctrls.h> 21#include <media/v4l2-ctrls.h>
22 22
23#define to_ov9740(sd) container_of(sd, struct ov9740_priv, subdev) 23#define to_ov9740(sd) container_of(sd, struct ov9740_priv, subdev)
@@ -196,8 +196,8 @@ struct ov9740_reg {
196struct ov9740_priv { 196struct ov9740_priv {
197 struct v4l2_subdev subdev; 197 struct v4l2_subdev subdev;
198 struct v4l2_ctrl_handler hdl; 198 struct v4l2_ctrl_handler hdl;
199 struct v4l2_clk *clk;
199 200
200 int ident;
201 u16 model; 201 u16 model;
202 u8 revision; 202 u8 revision;
203 u8 manid; 203 u8 manid;
@@ -772,18 +772,6 @@ static int ov9740_s_ctrl(struct v4l2_ctrl *ctrl)
772 return 0; 772 return 0;
773} 773}
774 774
775/* Get chip identification */
776static int ov9740_g_chip_ident(struct v4l2_subdev *sd,
777 struct v4l2_dbg_chip_ident *id)
778{
779 struct ov9740_priv *priv = to_ov9740(sd);
780
781 id->ident = priv->ident;
782 id->revision = priv->revision;
783
784 return 0;
785}
786
787static int ov9740_s_power(struct v4l2_subdev *sd, int on) 775static int ov9740_s_power(struct v4l2_subdev *sd, int on)
788{ 776{
789 struct i2c_client *client = v4l2_get_subdevdata(sd); 777 struct i2c_client *client = v4l2_get_subdevdata(sd);
@@ -792,7 +780,7 @@ static int ov9740_s_power(struct v4l2_subdev *sd, int on)
792 int ret; 780 int ret;
793 781
794 if (on) { 782 if (on) {
795 ret = soc_camera_power_on(&client->dev, ssdd); 783 ret = soc_camera_power_on(&client->dev, ssdd, priv->clk);
796 if (ret < 0) 784 if (ret < 0)
797 return ret; 785 return ret;
798 786
@@ -806,7 +794,7 @@ static int ov9740_s_power(struct v4l2_subdev *sd, int on)
806 priv->current_enable = true; 794 priv->current_enable = true;
807 } 795 }
808 796
809 soc_camera_power_off(&client->dev, ssdd); 797 soc_camera_power_off(&client->dev, ssdd, priv->clk);
810 } 798 }
811 799
812 return 0; 800 return 0;
@@ -887,8 +875,6 @@ static int ov9740_video_probe(struct i2c_client *client)
887 goto done; 875 goto done;
888 } 876 }
889 877
890 priv->ident = V4L2_IDENT_OV9740;
891
892 dev_info(&client->dev, "ov9740 Model ID 0x%04x, Revision 0x%02x, " 878 dev_info(&client->dev, "ov9740 Model ID 0x%04x, Revision 0x%02x, "
893 "Manufacturer 0x%02x, SMIA Version 0x%02x\n", 879 "Manufacturer 0x%02x, SMIA Version 0x%02x\n",
894 priv->model, priv->revision, priv->manid, priv->smiaver); 880 priv->model, priv->revision, priv->manid, priv->smiaver);
@@ -927,7 +913,6 @@ static struct v4l2_subdev_video_ops ov9740_video_ops = {
927}; 913};
928 914
929static struct v4l2_subdev_core_ops ov9740_core_ops = { 915static struct v4l2_subdev_core_ops ov9740_core_ops = {
930 .g_chip_ident = ov9740_g_chip_ident,
931 .s_power = ov9740_s_power, 916 .s_power = ov9740_s_power,
932#ifdef CONFIG_VIDEO_ADV_DEBUG 917#ifdef CONFIG_VIDEO_ADV_DEBUG
933 .g_register = ov9740_get_register, 918 .g_register = ov9740_get_register,
@@ -975,9 +960,18 @@ static int ov9740_probe(struct i2c_client *client,
975 if (priv->hdl.error) 960 if (priv->hdl.error)
976 return priv->hdl.error; 961 return priv->hdl.error;
977 962
963 priv->clk = v4l2_clk_get(&client->dev, "mclk");
964 if (IS_ERR(priv->clk)) {
965 ret = PTR_ERR(priv->clk);
966 goto eclkget;
967 }
968
978 ret = ov9740_video_probe(client); 969 ret = ov9740_video_probe(client);
979 if (ret < 0) 970 if (ret < 0) {
971 v4l2_clk_put(priv->clk);
972eclkget:
980 v4l2_ctrl_handler_free(&priv->hdl); 973 v4l2_ctrl_handler_free(&priv->hdl);
974 }
981 975
982 return ret; 976 return ret;
983} 977}
@@ -986,6 +980,7 @@ static int ov9740_remove(struct i2c_client *client)
986{ 980{
987 struct ov9740_priv *priv = i2c_get_clientdata(client); 981 struct ov9740_priv *priv = i2c_get_clientdata(client);
988 982
983 v4l2_clk_put(priv->clk);
989 v4l2_device_unregister_subdev(&priv->subdev); 984 v4l2_device_unregister_subdev(&priv->subdev);
990 v4l2_ctrl_handler_free(&priv->hdl); 985 v4l2_ctrl_handler_free(&priv->hdl);
991 return 0; 986 return 0;
diff --git a/drivers/media/i2c/soc_camera/rj54n1cb0c.c b/drivers/media/i2c/soc_camera/rj54n1cb0c.c
index 1f9ec3b06b4e..7e6d97847874 100644
--- a/drivers/media/i2c/soc_camera/rj54n1cb0c.c
+++ b/drivers/media/i2c/soc_camera/rj54n1cb0c.c
@@ -17,8 +17,8 @@
17 17
18#include <media/rj54n1cb0c.h> 18#include <media/rj54n1cb0c.h>
19#include <media/soc_camera.h> 19#include <media/soc_camera.h>
20#include <media/v4l2-clk.h>
20#include <media/v4l2-subdev.h> 21#include <media/v4l2-subdev.h>
21#include <media/v4l2-chip-ident.h>
22#include <media/v4l2-ctrls.h> 22#include <media/v4l2-ctrls.h>
23 23
24#define RJ54N1_DEV_CODE 0x0400 24#define RJ54N1_DEV_CODE 0x0400
@@ -151,6 +151,7 @@ struct rj54n1_clock_div {
151struct rj54n1 { 151struct rj54n1 {
152 struct v4l2_subdev subdev; 152 struct v4l2_subdev subdev;
153 struct v4l2_ctrl_handler hdl; 153 struct v4l2_ctrl_handler hdl;
154 struct v4l2_clk *clk;
154 struct rj54n1_clock_div clk_div; 155 struct rj54n1_clock_div clk_div;
155 const struct rj54n1_datafmt *fmt; 156 const struct rj54n1_datafmt *fmt;
156 struct v4l2_rect rect; /* Sensor window */ 157 struct v4l2_rect rect; /* Sensor window */
@@ -1120,37 +1121,16 @@ static int rj54n1_s_fmt(struct v4l2_subdev *sd,
1120 return 0; 1121 return 0;
1121} 1122}
1122 1123
1123static int rj54n1_g_chip_ident(struct v4l2_subdev *sd,
1124 struct v4l2_dbg_chip_ident *id)
1125{
1126 struct i2c_client *client = v4l2_get_subdevdata(sd);
1127
1128 if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
1129 return -EINVAL;
1130
1131 if (id->match.addr != client->addr)
1132 return -ENODEV;
1133
1134 id->ident = V4L2_IDENT_RJ54N1CB0C;
1135 id->revision = 0;
1136
1137 return 0;
1138}
1139
1140#ifdef CONFIG_VIDEO_ADV_DEBUG 1124#ifdef CONFIG_VIDEO_ADV_DEBUG
1141static int rj54n1_g_register(struct v4l2_subdev *sd, 1125static int rj54n1_g_register(struct v4l2_subdev *sd,
1142 struct v4l2_dbg_register *reg) 1126 struct v4l2_dbg_register *reg)
1143{ 1127{
1144 struct i2c_client *client = v4l2_get_subdevdata(sd); 1128 struct i2c_client *client = v4l2_get_subdevdata(sd);
1145 1129
1146 if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || 1130 if (reg->reg < 0x400 || reg->reg > 0x1fff)
1147 reg->reg < 0x400 || reg->reg > 0x1fff)
1148 /* Registers > 0x0800 are only available from Sharp support */ 1131 /* Registers > 0x0800 are only available from Sharp support */
1149 return -EINVAL; 1132 return -EINVAL;
1150 1133
1151 if (reg->match.addr != client->addr)
1152 return -ENODEV;
1153
1154 reg->size = 1; 1134 reg->size = 1;
1155 reg->val = reg_read(client, reg->reg); 1135 reg->val = reg_read(client, reg->reg);
1156 1136
@@ -1165,14 +1145,10 @@ static int rj54n1_s_register(struct v4l2_subdev *sd,
1165{ 1145{
1166 struct i2c_client *client = v4l2_get_subdevdata(sd); 1146 struct i2c_client *client = v4l2_get_subdevdata(sd);
1167 1147
1168 if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || 1148 if (reg->reg < 0x400 || reg->reg > 0x1fff)
1169 reg->reg < 0x400 || reg->reg > 0x1fff)
1170 /* Registers >= 0x0800 are only available from Sharp support */ 1149 /* Registers >= 0x0800 are only available from Sharp support */
1171 return -EINVAL; 1150 return -EINVAL;
1172 1151
1173 if (reg->match.addr != client->addr)
1174 return -ENODEV;
1175
1176 if (reg_write(client, reg->reg, reg->val) < 0) 1152 if (reg_write(client, reg->reg, reg->val) < 0)
1177 return -EIO; 1153 return -EIO;
1178 1154
@@ -1184,8 +1160,9 @@ static int rj54n1_s_power(struct v4l2_subdev *sd, int on)
1184{ 1160{
1185 struct i2c_client *client = v4l2_get_subdevdata(sd); 1161 struct i2c_client *client = v4l2_get_subdevdata(sd);
1186 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client); 1162 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
1163 struct rj54n1 *rj54n1 = to_rj54n1(client);
1187 1164
1188 return soc_camera_set_power(&client->dev, ssdd, on); 1165 return soc_camera_set_power(&client->dev, ssdd, rj54n1->clk, on);
1189} 1166}
1190 1167
1191static int rj54n1_s_ctrl(struct v4l2_ctrl *ctrl) 1168static int rj54n1_s_ctrl(struct v4l2_ctrl *ctrl)
@@ -1233,7 +1210,6 @@ static const struct v4l2_ctrl_ops rj54n1_ctrl_ops = {
1233}; 1210};
1234 1211
1235static struct v4l2_subdev_core_ops rj54n1_subdev_core_ops = { 1212static struct v4l2_subdev_core_ops rj54n1_subdev_core_ops = {
1236 .g_chip_ident = rj54n1_g_chip_ident,
1237#ifdef CONFIG_VIDEO_ADV_DEBUG 1213#ifdef CONFIG_VIDEO_ADV_DEBUG
1238 .g_register = rj54n1_g_register, 1214 .g_register = rj54n1_g_register,
1239 .s_register = rj54n1_s_register, 1215 .s_register = rj54n1_s_register,
@@ -1382,9 +1358,18 @@ static int rj54n1_probe(struct i2c_client *client,
1382 rj54n1->tgclk_mhz = (rj54n1_priv->mclk_freq / PLL_L * PLL_N) / 1358 rj54n1->tgclk_mhz = (rj54n1_priv->mclk_freq / PLL_L * PLL_N) /
1383 (clk_div.ratio_tg + 1) / (clk_div.ratio_t + 1); 1359 (clk_div.ratio_tg + 1) / (clk_div.ratio_t + 1);
1384 1360
1361 rj54n1->clk = v4l2_clk_get(&client->dev, "mclk");
1362 if (IS_ERR(rj54n1->clk)) {
1363 ret = PTR_ERR(rj54n1->clk);
1364 goto eclkget;
1365 }
1366
1385 ret = rj54n1_video_probe(client, rj54n1_priv); 1367 ret = rj54n1_video_probe(client, rj54n1_priv);
1386 if (ret < 0) 1368 if (ret < 0) {
1369 v4l2_clk_put(rj54n1->clk);
1370eclkget:
1387 v4l2_ctrl_handler_free(&rj54n1->hdl); 1371 v4l2_ctrl_handler_free(&rj54n1->hdl);
1372 }
1388 1373
1389 return ret; 1374 return ret;
1390} 1375}
@@ -1394,6 +1379,7 @@ static int rj54n1_remove(struct i2c_client *client)
1394 struct rj54n1 *rj54n1 = to_rj54n1(client); 1379 struct rj54n1 *rj54n1 = to_rj54n1(client);
1395 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client); 1380 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
1396 1381
1382 v4l2_clk_put(rj54n1->clk);
1397 v4l2_device_unregister_subdev(&rj54n1->subdev); 1383 v4l2_device_unregister_subdev(&rj54n1->subdev);
1398 if (ssdd->free_bus) 1384 if (ssdd->free_bus)
1399 ssdd->free_bus(ssdd); 1385 ssdd->free_bus(ssdd);
diff --git a/drivers/media/i2c/soc_camera/tw9910.c b/drivers/media/i2c/soc_camera/tw9910.c
index bad90b16a6dd..ab54628d9411 100644
--- a/drivers/media/i2c/soc_camera/tw9910.c
+++ b/drivers/media/i2c/soc_camera/tw9910.c
@@ -27,7 +27,7 @@
27 27
28#include <media/soc_camera.h> 28#include <media/soc_camera.h>
29#include <media/tw9910.h> 29#include <media/tw9910.h>
30#include <media/v4l2-chip-ident.h> 30#include <media/v4l2-clk.h>
31#include <media/v4l2-subdev.h> 31#include <media/v4l2-subdev.h>
32 32
33#define GET_ID(val) ((val & 0xF8) >> 3) 33#define GET_ID(val) ((val & 0xF8) >> 3)
@@ -228,6 +228,7 @@ struct tw9910_scale_ctrl {
228 228
229struct tw9910_priv { 229struct tw9910_priv {
230 struct v4l2_subdev subdev; 230 struct v4l2_subdev subdev;
231 struct v4l2_clk *clk;
231 struct tw9910_video_info *info; 232 struct tw9910_video_info *info;
232 const struct tw9910_scale_ctrl *scale; 233 const struct tw9910_scale_ctrl *scale;
233 v4l2_std_id norm; 234 v4l2_std_id norm;
@@ -518,18 +519,6 @@ static int tw9910_s_std(struct v4l2_subdev *sd, v4l2_std_id norm)
518 return 0; 519 return 0;
519} 520}
520 521
521static int tw9910_g_chip_ident(struct v4l2_subdev *sd,
522 struct v4l2_dbg_chip_ident *id)
523{
524 struct i2c_client *client = v4l2_get_subdevdata(sd);
525 struct tw9910_priv *priv = to_tw9910(client);
526
527 id->ident = V4L2_IDENT_TW9910;
528 id->revision = priv->revision;
529
530 return 0;
531}
532
533#ifdef CONFIG_VIDEO_ADV_DEBUG 522#ifdef CONFIG_VIDEO_ADV_DEBUG
534static int tw9910_g_register(struct v4l2_subdev *sd, 523static int tw9910_g_register(struct v4l2_subdev *sd,
535 struct v4l2_dbg_register *reg) 524 struct v4l2_dbg_register *reg)
@@ -540,6 +529,7 @@ static int tw9910_g_register(struct v4l2_subdev *sd,
540 if (reg->reg > 0xff) 529 if (reg->reg > 0xff)
541 return -EINVAL; 530 return -EINVAL;
542 531
532 reg->size = 1;
543 ret = i2c_smbus_read_byte_data(client, reg->reg); 533 ret = i2c_smbus_read_byte_data(client, reg->reg);
544 if (ret < 0) 534 if (ret < 0)
545 return ret; 535 return ret;
@@ -570,8 +560,9 @@ static int tw9910_s_power(struct v4l2_subdev *sd, int on)
570{ 560{
571 struct i2c_client *client = v4l2_get_subdevdata(sd); 561 struct i2c_client *client = v4l2_get_subdevdata(sd);
572 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client); 562 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
563 struct tw9910_priv *priv = to_tw9910(client);
573 564
574 return soc_camera_set_power(&client->dev, ssdd, on); 565 return soc_camera_set_power(&client->dev, ssdd, priv->clk, on);
575} 566}
576 567
577static int tw9910_set_frame(struct v4l2_subdev *sd, u32 *width, u32 *height) 568static int tw9910_set_frame(struct v4l2_subdev *sd, u32 *width, u32 *height)
@@ -823,7 +814,6 @@ done:
823} 814}
824 815
825static struct v4l2_subdev_core_ops tw9910_subdev_core_ops = { 816static struct v4l2_subdev_core_ops tw9910_subdev_core_ops = {
826 .g_chip_ident = tw9910_g_chip_ident,
827 .s_std = tw9910_s_std, 817 .s_std = tw9910_s_std,
828 .g_std = tw9910_g_std, 818 .g_std = tw9910_g_std,
829#ifdef CONFIG_VIDEO_ADV_DEBUG 819#ifdef CONFIG_VIDEO_ADV_DEBUG
@@ -912,6 +902,7 @@ static int tw9910_probe(struct i2c_client *client,
912 struct i2c_adapter *adapter = 902 struct i2c_adapter *adapter =
913 to_i2c_adapter(client->dev.parent); 903 to_i2c_adapter(client->dev.parent);
914 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client); 904 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
905 int ret;
915 906
916 if (!ssdd || !ssdd->drv_priv) { 907 if (!ssdd || !ssdd->drv_priv) {
917 dev_err(&client->dev, "TW9910: missing platform data!\n"); 908 dev_err(&client->dev, "TW9910: missing platform data!\n");
@@ -935,11 +926,21 @@ static int tw9910_probe(struct i2c_client *client,
935 926
936 v4l2_i2c_subdev_init(&priv->subdev, client, &tw9910_subdev_ops); 927 v4l2_i2c_subdev_init(&priv->subdev, client, &tw9910_subdev_ops);
937 928
938 return tw9910_video_probe(client); 929 priv->clk = v4l2_clk_get(&client->dev, "mclk");
930 if (IS_ERR(priv->clk))
931 return PTR_ERR(priv->clk);
932
933 ret = tw9910_video_probe(client);
934 if (ret < 0)
935 v4l2_clk_put(priv->clk);
936
937 return ret;
939} 938}
940 939
941static int tw9910_remove(struct i2c_client *client) 940static int tw9910_remove(struct i2c_client *client)
942{ 941{
942 struct tw9910_priv *priv = to_tw9910(client);
943 v4l2_clk_put(priv->clk);
943 return 0; 944 return 0;
944} 945}
945 946
diff --git a/drivers/media/i2c/sony-btf-mpx.c b/drivers/media/i2c/sony-btf-mpx.c
index 38cbea98764c..32d82320b485 100644
--- a/drivers/media/i2c/sony-btf-mpx.c
+++ b/drivers/media/i2c/sony-btf-mpx.c
@@ -30,7 +30,7 @@ MODULE_LICENSE("GPL v2");
30 30
31static int debug; 31static int debug;
32module_param(debug, int, 0644); 32module_param(debug, int, 0644);
33MODULE_PARM_DESC(debug, "debug level 0=off(default) 1=on\n"); 33MODULE_PARM_DESC(debug, "debug level 0=off(default) 1=on");
34 34
35/* #define MPX_DEBUG */ 35/* #define MPX_DEBUG */
36 36
@@ -355,7 +355,7 @@ static int sony_btf_mpx_probe(struct i2c_client *client,
355 v4l_info(client, "chip found @ 0x%x (%s)\n", 355 v4l_info(client, "chip found @ 0x%x (%s)\n",
356 client->addr << 1, client->adapter->name); 356 client->addr << 1, client->adapter->name);
357 357
358 t = kzalloc(sizeof(struct sony_btf_mpx), GFP_KERNEL); 358 t = devm_kzalloc(&client->dev, sizeof(*t), GFP_KERNEL);
359 if (t == NULL) 359 if (t == NULL)
360 return -ENOMEM; 360 return -ENOMEM;
361 361
@@ -374,7 +374,6 @@ static int sony_btf_mpx_remove(struct i2c_client *client)
374 struct v4l2_subdev *sd = i2c_get_clientdata(client); 374 struct v4l2_subdev *sd = i2c_get_clientdata(client);
375 375
376 v4l2_device_unregister_subdev(sd); 376 v4l2_device_unregister_subdev(sd);
377 kfree(to_state(sd));
378 377
379 return 0; 378 return 0;
380} 379}
diff --git a/drivers/media/i2c/sr030pc30.c b/drivers/media/i2c/sr030pc30.c
index e9d95bda2ab1..ae9432637fcb 100644
--- a/drivers/media/i2c/sr030pc30.c
+++ b/drivers/media/i2c/sr030pc30.c
@@ -23,6 +23,7 @@
23#include <media/v4l2-device.h> 23#include <media/v4l2-device.h>
24#include <media/v4l2-subdev.h> 24#include <media/v4l2-subdev.h>
25#include <media/v4l2-mediabus.h> 25#include <media/v4l2-mediabus.h>
26#include <media/v4l2-ctrls.h>
26#include <media/sr030pc30.h> 27#include <media/sr030pc30.h>
27 28
28static int debug; 29static int debug;
@@ -142,17 +143,24 @@ module_param(debug, int, 0644);
142 143
143struct sr030pc30_info { 144struct sr030pc30_info {
144 struct v4l2_subdev sd; 145 struct v4l2_subdev sd;
146 struct v4l2_ctrl_handler hdl;
145 const struct sr030pc30_platform_data *pdata; 147 const struct sr030pc30_platform_data *pdata;
146 const struct sr030pc30_format *curr_fmt; 148 const struct sr030pc30_format *curr_fmt;
147 const struct sr030pc30_frmsize *curr_win; 149 const struct sr030pc30_frmsize *curr_win;
148 unsigned int auto_wb:1;
149 unsigned int auto_exp:1;
150 unsigned int hflip:1; 150 unsigned int hflip:1;
151 unsigned int vflip:1; 151 unsigned int vflip:1;
152 unsigned int sleep:1; 152 unsigned int sleep:1;
153 unsigned int exposure; 153 struct {
154 u8 blue_balance; 154 /* auto whitebalance control cluster */
155 u8 red_balance; 155 struct v4l2_ctrl *awb;
156 struct v4l2_ctrl *red;
157 struct v4l2_ctrl *blue;
158 };
159 struct {
160 /* auto exposure control cluster */
161 struct v4l2_ctrl *autoexp;
162 struct v4l2_ctrl *exp;
163 };
156 u8 i2c_reg_page; 164 u8 i2c_reg_page;
157}; 165};
158 166
@@ -173,52 +181,6 @@ struct i2c_regval {
173 u16 val; 181 u16 val;
174}; 182};
175 183
176static const struct v4l2_queryctrl sr030pc30_ctrl[] = {
177 {
178 .id = V4L2_CID_AUTO_WHITE_BALANCE,
179 .type = V4L2_CTRL_TYPE_BOOLEAN,
180 .name = "Auto White Balance",
181 .minimum = 0,
182 .maximum = 1,
183 .step = 1,
184 .default_value = 1,
185 }, {
186 .id = V4L2_CID_RED_BALANCE,
187 .type = V4L2_CTRL_TYPE_INTEGER,
188 .name = "Red Balance",
189 .minimum = 0,
190 .maximum = 127,
191 .step = 1,
192 .default_value = 64,
193 .flags = 0,
194 }, {
195 .id = V4L2_CID_BLUE_BALANCE,
196 .type = V4L2_CTRL_TYPE_INTEGER,
197 .name = "Blue Balance",
198 .minimum = 0,
199 .maximum = 127,
200 .step = 1,
201 .default_value = 64,
202 }, {
203 .id = V4L2_CID_EXPOSURE_AUTO,
204 .type = V4L2_CTRL_TYPE_INTEGER,
205 .name = "Auto Exposure",
206 .minimum = 0,
207 .maximum = 1,
208 .step = 1,
209 .default_value = 1,
210 }, {
211 .id = V4L2_CID_EXPOSURE,
212 .type = V4L2_CTRL_TYPE_INTEGER,
213 .name = "Exposure",
214 .minimum = EXPOS_MIN_MS,
215 .maximum = EXPOS_MAX_MS,
216 .step = 1,
217 .default_value = 1,
218 }, {
219 }
220};
221
222/* supported resolutions */ 184/* supported resolutions */
223static const struct sr030pc30_frmsize sr030pc30_sizes[] = { 185static const struct sr030pc30_frmsize sr030pc30_sizes[] = {
224 { 186 {
@@ -394,48 +356,6 @@ static int sr030pc30_pwr_ctrl(struct v4l2_subdev *sd,
394 return ret; 356 return ret;
395} 357}
396 358
397static inline int sr030pc30_enable_autoexposure(struct v4l2_subdev *sd, int on)
398{
399 struct sr030pc30_info *info = to_sr030pc30(sd);
400 /* auto anti-flicker is also enabled here */
401 int ret = cam_i2c_write(sd, AE_CTL1_REG, on ? 0xDC : 0x0C);
402 if (!ret)
403 info->auto_exp = on;
404 return ret;
405}
406
407static int sr030pc30_set_exposure(struct v4l2_subdev *sd, int value)
408{
409 struct sr030pc30_info *info = to_sr030pc30(sd);
410
411 unsigned long expos = value * info->pdata->clk_rate / (8 * 1000);
412
413 int ret = cam_i2c_write(sd, EXP_TIMEH_REG, expos >> 16 & 0xFF);
414 if (!ret)
415 ret = cam_i2c_write(sd, EXP_TIMEM_REG, expos >> 8 & 0xFF);
416 if (!ret)
417 ret = cam_i2c_write(sd, EXP_TIMEL_REG, expos & 0xFF);
418 if (!ret) { /* Turn off AE */
419 info->exposure = value;
420 ret = sr030pc30_enable_autoexposure(sd, 0);
421 }
422 return ret;
423}
424
425/* Automatic white balance control */
426static int sr030pc30_enable_autowhitebalance(struct v4l2_subdev *sd, int on)
427{
428 struct sr030pc30_info *info = to_sr030pc30(sd);
429
430 int ret = cam_i2c_write(sd, AWB_CTL2_REG, on ? 0x2E : 0x2F);
431 if (!ret)
432 ret = cam_i2c_write(sd, AWB_CTL1_REG, on ? 0xFB : 0x7B);
433 if (!ret)
434 info->auto_wb = on;
435
436 return ret;
437}
438
439static int sr030pc30_set_flip(struct v4l2_subdev *sd) 359static int sr030pc30_set_flip(struct v4l2_subdev *sd)
440{ 360{
441 struct sr030pc30_info *info = to_sr030pc30(sd); 361 struct sr030pc30_info *info = to_sr030pc30(sd);
@@ -498,107 +418,56 @@ static int sr030pc30_try_frame_size(struct v4l2_mbus_framefmt *mf)
498 return -EINVAL; 418 return -EINVAL;
499} 419}
500 420
501static int sr030pc30_queryctrl(struct v4l2_subdev *sd, 421static int sr030pc30_s_ctrl(struct v4l2_ctrl *ctrl)
502 struct v4l2_queryctrl *qc)
503{
504 int i;
505
506 for (i = 0; i < ARRAY_SIZE(sr030pc30_ctrl); i++)
507 if (qc->id == sr030pc30_ctrl[i].id) {
508 *qc = sr030pc30_ctrl[i];
509 v4l2_dbg(1, debug, sd, "%s id: %d\n",
510 __func__, qc->id);
511 return 0;
512 }
513
514 return -EINVAL;
515}
516
517static inline int sr030pc30_set_bluebalance(struct v4l2_subdev *sd, int value)
518{ 422{
519 int ret = cam_i2c_write(sd, MWB_BGAIN_REG, value); 423 struct sr030pc30_info *info =
520 if (!ret) 424 container_of(ctrl->handler, struct sr030pc30_info, hdl);
521 to_sr030pc30(sd)->blue_balance = value; 425 struct v4l2_subdev *sd = &info->sd;
522 return ret; 426 int ret = 0;
523}
524
525static inline int sr030pc30_set_redbalance(struct v4l2_subdev *sd, int value)
526{
527 int ret = cam_i2c_write(sd, MWB_RGAIN_REG, value);
528 if (!ret)
529 to_sr030pc30(sd)->red_balance = value;
530 return ret;
531}
532
533static int sr030pc30_s_ctrl(struct v4l2_subdev *sd,
534 struct v4l2_control *ctrl)
535{
536 int i, ret = 0;
537
538 for (i = 0; i < ARRAY_SIZE(sr030pc30_ctrl); i++)
539 if (ctrl->id == sr030pc30_ctrl[i].id)
540 break;
541
542 if (i == ARRAY_SIZE(sr030pc30_ctrl))
543 return -EINVAL;
544
545 if (ctrl->value < sr030pc30_ctrl[i].minimum ||
546 ctrl->value > sr030pc30_ctrl[i].maximum)
547 return -ERANGE;
548 427
549 v4l2_dbg(1, debug, sd, "%s: ctrl_id: %d, value: %d\n", 428 v4l2_dbg(1, debug, sd, "%s: ctrl_id: %d, value: %d\n",
550 __func__, ctrl->id, ctrl->value); 429 __func__, ctrl->id, ctrl->val);
551 430
552 switch (ctrl->id) { 431 switch (ctrl->id) {
553 case V4L2_CID_AUTO_WHITE_BALANCE: 432 case V4L2_CID_AUTO_WHITE_BALANCE:
554 sr030pc30_enable_autowhitebalance(sd, ctrl->value); 433 if (ctrl->is_new) {
555 break; 434 ret = cam_i2c_write(sd, AWB_CTL2_REG,
556 case V4L2_CID_BLUE_BALANCE: 435 ctrl->val ? 0x2E : 0x2F);
557 ret = sr030pc30_set_bluebalance(sd, ctrl->value); 436 if (!ret)
558 break; 437 ret = cam_i2c_write(sd, AWB_CTL1_REG,
559 case V4L2_CID_RED_BALANCE: 438 ctrl->val ? 0xFB : 0x7B);
560 ret = sr030pc30_set_redbalance(sd, ctrl->value); 439 }
561 break; 440 if (!ret && info->blue->is_new)
562 case V4L2_CID_EXPOSURE_AUTO: 441 ret = cam_i2c_write(sd, MWB_BGAIN_REG, info->blue->val);
563 sr030pc30_enable_autoexposure(sd, 442 if (!ret && info->red->is_new)
564 ctrl->value == V4L2_EXPOSURE_AUTO); 443 ret = cam_i2c_write(sd, MWB_RGAIN_REG, info->red->val);
565 break; 444 return ret;
566 case V4L2_CID_EXPOSURE:
567 ret = sr030pc30_set_exposure(sd, ctrl->value);
568 break;
569 default:
570 return -EINVAL;
571 }
572
573 return ret;
574}
575
576static int sr030pc30_g_ctrl(struct v4l2_subdev *sd,
577 struct v4l2_control *ctrl)
578{
579 struct sr030pc30_info *info = to_sr030pc30(sd);
580
581 v4l2_dbg(1, debug, sd, "%s: id: %d\n", __func__, ctrl->id);
582 445
583 switch (ctrl->id) {
584 case V4L2_CID_AUTO_WHITE_BALANCE:
585 ctrl->value = info->auto_wb;
586 break;
587 case V4L2_CID_BLUE_BALANCE:
588 ctrl->value = info->blue_balance;
589 break;
590 case V4L2_CID_RED_BALANCE:
591 ctrl->value = info->red_balance;
592 break;
593 case V4L2_CID_EXPOSURE_AUTO: 446 case V4L2_CID_EXPOSURE_AUTO:
594 ctrl->value = info->auto_exp; 447 /* auto anti-flicker is also enabled here */
595 break; 448 if (ctrl->is_new)
596 case V4L2_CID_EXPOSURE: 449 ret = cam_i2c_write(sd, AE_CTL1_REG,
597 ctrl->value = info->exposure; 450 ctrl->val == V4L2_EXPOSURE_AUTO ? 0xDC : 0x0C);
598 break; 451 if (info->exp->is_new) {
452 unsigned long expos = info->exp->val;
453
454 expos = expos * info->pdata->clk_rate / (8 * 1000);
455
456 if (!ret)
457 ret = cam_i2c_write(sd, EXP_TIMEH_REG,
458 expos >> 16 & 0xFF);
459 if (!ret)
460 ret = cam_i2c_write(sd, EXP_TIMEM_REG,
461 expos >> 8 & 0xFF);
462 if (!ret)
463 ret = cam_i2c_write(sd, EXP_TIMEL_REG,
464 expos & 0xFF);
465 }
466 return ret;
599 default: 467 default:
600 return -EINVAL; 468 return -EINVAL;
601 } 469 }
470
602 return 0; 471 return 0;
603} 472}
604 473
@@ -752,11 +621,19 @@ static int sr030pc30_s_power(struct v4l2_subdev *sd, int on)
752 return ret; 621 return ret;
753} 622}
754 623
624static const struct v4l2_ctrl_ops sr030pc30_ctrl_ops = {
625 .s_ctrl = sr030pc30_s_ctrl,
626};
627
755static const struct v4l2_subdev_core_ops sr030pc30_core_ops = { 628static const struct v4l2_subdev_core_ops sr030pc30_core_ops = {
756 .s_power = sr030pc30_s_power, 629 .s_power = sr030pc30_s_power,
757 .queryctrl = sr030pc30_queryctrl, 630 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls,
758 .s_ctrl = sr030pc30_s_ctrl, 631 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls,
759 .g_ctrl = sr030pc30_g_ctrl, 632 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls,
633 .g_ctrl = v4l2_subdev_g_ctrl,
634 .s_ctrl = v4l2_subdev_s_ctrl,
635 .queryctrl = v4l2_subdev_queryctrl,
636 .querymenu = v4l2_subdev_querymenu,
760}; 637};
761 638
762static const struct v4l2_subdev_video_ops sr030pc30_video_ops = { 639static const struct v4l2_subdev_video_ops sr030pc30_video_ops = {
@@ -807,6 +684,7 @@ static int sr030pc30_probe(struct i2c_client *client,
807{ 684{
808 struct sr030pc30_info *info; 685 struct sr030pc30_info *info;
809 struct v4l2_subdev *sd; 686 struct v4l2_subdev *sd;
687 struct v4l2_ctrl_handler *hdl;
810 const struct sr030pc30_platform_data *pdata 688 const struct sr030pc30_platform_data *pdata
811 = client->dev.platform_data; 689 = client->dev.platform_data;
812 int ret; 690 int ret;
@@ -820,7 +698,7 @@ static int sr030pc30_probe(struct i2c_client *client,
820 if (ret) 698 if (ret)
821 return ret; 699 return ret;
822 700
823 info = kzalloc(sizeof(*info), GFP_KERNEL); 701 info = devm_kzalloc(&client->dev, sizeof(*info), GFP_KERNEL);
824 if (!info) 702 if (!info)
825 return -ENOMEM; 703 return -ENOMEM;
826 704
@@ -830,10 +708,31 @@ static int sr030pc30_probe(struct i2c_client *client,
830 708
831 v4l2_i2c_subdev_init(sd, client, &sr030pc30_ops); 709 v4l2_i2c_subdev_init(sd, client, &sr030pc30_ops);
832 710
711 hdl = &info->hdl;
712 v4l2_ctrl_handler_init(hdl, 6);
713 info->awb = v4l2_ctrl_new_std(hdl, &sr030pc30_ctrl_ops,
714 V4L2_CID_AUTO_WHITE_BALANCE, 0, 1, 1, 1);
715 info->red = v4l2_ctrl_new_std(hdl, &sr030pc30_ctrl_ops,
716 V4L2_CID_RED_BALANCE, 0, 127, 1, 64);
717 info->blue = v4l2_ctrl_new_std(hdl, &sr030pc30_ctrl_ops,
718 V4L2_CID_BLUE_BALANCE, 0, 127, 1, 64);
719 info->autoexp = v4l2_ctrl_new_std(hdl, &sr030pc30_ctrl_ops,
720 V4L2_CID_EXPOSURE_AUTO, 0, 1, 1, 1);
721 info->exp = v4l2_ctrl_new_std(hdl, &sr030pc30_ctrl_ops,
722 V4L2_CID_EXPOSURE, EXPOS_MIN_MS, EXPOS_MAX_MS, 1, 30);
723 sd->ctrl_handler = hdl;
724 if (hdl->error) {
725 int err = hdl->error;
726
727 v4l2_ctrl_handler_free(hdl);
728 return err;
729 }
730 v4l2_ctrl_auto_cluster(3, &info->awb, 0, false);
731 v4l2_ctrl_auto_cluster(2, &info->autoexp, V4L2_EXPOSURE_MANUAL, false);
732 v4l2_ctrl_handler_setup(hdl);
733
833 info->i2c_reg_page = -1; 734 info->i2c_reg_page = -1;
834 info->hflip = 1; 735 info->hflip = 1;
835 info->auto_exp = 1;
836 info->exposure = 30;
837 736
838 return 0; 737 return 0;
839} 738}
@@ -841,10 +740,9 @@ static int sr030pc30_probe(struct i2c_client *client,
841static int sr030pc30_remove(struct i2c_client *client) 740static int sr030pc30_remove(struct i2c_client *client)
842{ 741{
843 struct v4l2_subdev *sd = i2c_get_clientdata(client); 742 struct v4l2_subdev *sd = i2c_get_clientdata(client);
844 struct sr030pc30_info *info = to_sr030pc30(sd);
845 743
846 v4l2_device_unregister_subdev(sd); 744 v4l2_device_unregister_subdev(sd);
847 kfree(info); 745 v4l2_ctrl_handler_free(sd->ctrl_handler);
848 return 0; 746 return 0;
849} 747}
850 748
diff --git a/drivers/media/i2c/tda7432.c b/drivers/media/i2c/tda7432.c
index 28b5121881f5..72af644fa051 100644
--- a/drivers/media/i2c/tda7432.c
+++ b/drivers/media/i2c/tda7432.c
@@ -359,7 +359,7 @@ static int tda7432_probe(struct i2c_client *client,
359 v4l_info(client, "chip found @ 0x%02x (%s)\n", 359 v4l_info(client, "chip found @ 0x%02x (%s)\n",
360 client->addr << 1, client->adapter->name); 360 client->addr << 1, client->adapter->name);
361 361
362 t = kzalloc(sizeof(*t), GFP_KERNEL); 362 t = devm_kzalloc(&client->dev, sizeof(*t), GFP_KERNEL);
363 if (!t) 363 if (!t)
364 return -ENOMEM; 364 return -ENOMEM;
365 sd = &t->sd; 365 sd = &t->sd;
@@ -380,7 +380,6 @@ static int tda7432_probe(struct i2c_client *client,
380 int err = t->hdl.error; 380 int err = t->hdl.error;
381 381
382 v4l2_ctrl_handler_free(&t->hdl); 382 v4l2_ctrl_handler_free(&t->hdl);
383 kfree(t);
384 return err; 383 return err;
385 } 384 }
386 v4l2_ctrl_cluster(2, &t->bass); 385 v4l2_ctrl_cluster(2, &t->bass);
@@ -406,7 +405,6 @@ static int tda7432_remove(struct i2c_client *client)
406 tda7432_set(sd); 405 tda7432_set(sd);
407 v4l2_device_unregister_subdev(sd); 406 v4l2_device_unregister_subdev(sd);
408 v4l2_ctrl_handler_free(&t->hdl); 407 v4l2_ctrl_handler_free(&t->hdl);
409 kfree(t);
410 return 0; 408 return 0;
411} 409}
412 410
diff --git a/drivers/media/i2c/tda9840.c b/drivers/media/i2c/tda9840.c
index 01441e35d88b..fbdff8b24eec 100644
--- a/drivers/media/i2c/tda9840.c
+++ b/drivers/media/i2c/tda9840.c
@@ -31,7 +31,6 @@
31#include <linux/slab.h> 31#include <linux/slab.h>
32#include <linux/i2c.h> 32#include <linux/i2c.h>
33#include <media/v4l2-device.h> 33#include <media/v4l2-device.h>
34#include <media/v4l2-chip-ident.h>
35 34
36MODULE_AUTHOR("Michael Hunold <michael@mihu.de>"); 35MODULE_AUTHOR("Michael Hunold <michael@mihu.de>");
37MODULE_DESCRIPTION("tda9840 driver"); 36MODULE_DESCRIPTION("tda9840 driver");
@@ -145,26 +144,14 @@ static int tda9840_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *t)
145 return 0; 144 return 0;
146} 145}
147 146
148static int tda9840_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
149{
150 struct i2c_client *client = v4l2_get_subdevdata(sd);
151
152 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_TDA9840, 0);
153}
154
155/* ----------------------------------------------------------------------- */ 147/* ----------------------------------------------------------------------- */
156 148
157static const struct v4l2_subdev_core_ops tda9840_core_ops = {
158 .g_chip_ident = tda9840_g_chip_ident,
159};
160
161static const struct v4l2_subdev_tuner_ops tda9840_tuner_ops = { 149static const struct v4l2_subdev_tuner_ops tda9840_tuner_ops = {
162 .s_tuner = tda9840_s_tuner, 150 .s_tuner = tda9840_s_tuner,
163 .g_tuner = tda9840_g_tuner, 151 .g_tuner = tda9840_g_tuner,
164}; 152};
165 153
166static const struct v4l2_subdev_ops tda9840_ops = { 154static const struct v4l2_subdev_ops tda9840_ops = {
167 .core = &tda9840_core_ops,
168 .tuner = &tda9840_tuner_ops, 155 .tuner = &tda9840_tuner_ops,
169}; 156};
170 157
@@ -184,7 +171,7 @@ static int tda9840_probe(struct i2c_client *client,
184 v4l_info(client, "chip found @ 0x%x (%s)\n", 171 v4l_info(client, "chip found @ 0x%x (%s)\n",
185 client->addr << 1, client->adapter->name); 172 client->addr << 1, client->adapter->name);
186 173
187 sd = kzalloc(sizeof(struct v4l2_subdev), GFP_KERNEL); 174 sd = devm_kzalloc(&client->dev, sizeof(*sd), GFP_KERNEL);
188 if (sd == NULL) 175 if (sd == NULL)
189 return -ENOMEM; 176 return -ENOMEM;
190 v4l2_i2c_subdev_init(sd, client, &tda9840_ops); 177 v4l2_i2c_subdev_init(sd, client, &tda9840_ops);
@@ -201,7 +188,6 @@ static int tda9840_remove(struct i2c_client *client)
201 struct v4l2_subdev *sd = i2c_get_clientdata(client); 188 struct v4l2_subdev *sd = i2c_get_clientdata(client);
202 189
203 v4l2_device_unregister_subdev(sd); 190 v4l2_device_unregister_subdev(sd);
204 kfree(sd);
205 return 0; 191 return 0;
206} 192}
207 193
diff --git a/drivers/media/i2c/tea6415c.c b/drivers/media/i2c/tea6415c.c
index 3d5b06a5c308..bbe1a99fda36 100644
--- a/drivers/media/i2c/tea6415c.c
+++ b/drivers/media/i2c/tea6415c.c
@@ -33,7 +33,6 @@
33#include <linux/slab.h> 33#include <linux/slab.h>
34#include <linux/i2c.h> 34#include <linux/i2c.h>
35#include <media/v4l2-device.h> 35#include <media/v4l2-device.h>
36#include <media/v4l2-chip-ident.h>
37#include "tea6415c.h" 36#include "tea6415c.h"
38 37
39MODULE_AUTHOR("Michael Hunold <michael@mihu.de>"); 38MODULE_AUTHOR("Michael Hunold <michael@mihu.de>");
@@ -119,25 +118,13 @@ static int tea6415c_s_routing(struct v4l2_subdev *sd,
119 return ret; 118 return ret;
120} 119}
121 120
122static int tea6415c_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
123{
124 struct i2c_client *client = v4l2_get_subdevdata(sd);
125
126 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_TEA6415C, 0);
127}
128
129/* ----------------------------------------------------------------------- */ 121/* ----------------------------------------------------------------------- */
130 122
131static const struct v4l2_subdev_core_ops tea6415c_core_ops = {
132 .g_chip_ident = tea6415c_g_chip_ident,
133};
134
135static const struct v4l2_subdev_video_ops tea6415c_video_ops = { 123static const struct v4l2_subdev_video_ops tea6415c_video_ops = {
136 .s_routing = tea6415c_s_routing, 124 .s_routing = tea6415c_s_routing,
137}; 125};
138 126
139static const struct v4l2_subdev_ops tea6415c_ops = { 127static const struct v4l2_subdev_ops tea6415c_ops = {
140 .core = &tea6415c_core_ops,
141 .video = &tea6415c_video_ops, 128 .video = &tea6415c_video_ops,
142}; 129};
143 130
@@ -152,7 +139,7 @@ static int tea6415c_probe(struct i2c_client *client,
152 139
153 v4l_info(client, "chip found @ 0x%x (%s)\n", 140 v4l_info(client, "chip found @ 0x%x (%s)\n",
154 client->addr << 1, client->adapter->name); 141 client->addr << 1, client->adapter->name);
155 sd = kzalloc(sizeof(struct v4l2_subdev), GFP_KERNEL); 142 sd = devm_kzalloc(&client->dev, sizeof(*sd), GFP_KERNEL);
156 if (sd == NULL) 143 if (sd == NULL)
157 return -ENOMEM; 144 return -ENOMEM;
158 v4l2_i2c_subdev_init(sd, client, &tea6415c_ops); 145 v4l2_i2c_subdev_init(sd, client, &tea6415c_ops);
@@ -164,7 +151,6 @@ static int tea6415c_remove(struct i2c_client *client)
164 struct v4l2_subdev *sd = i2c_get_clientdata(client); 151 struct v4l2_subdev *sd = i2c_get_clientdata(client);
165 152
166 v4l2_device_unregister_subdev(sd); 153 v4l2_device_unregister_subdev(sd);
167 kfree(sd);
168 return 0; 154 return 0;
169} 155}
170 156
diff --git a/drivers/media/i2c/tea6420.c b/drivers/media/i2c/tea6420.c
index 38757217a074..30a8d75771af 100644
--- a/drivers/media/i2c/tea6420.c
+++ b/drivers/media/i2c/tea6420.c
@@ -33,7 +33,6 @@
33#include <linux/slab.h> 33#include <linux/slab.h>
34#include <linux/i2c.h> 34#include <linux/i2c.h>
35#include <media/v4l2-device.h> 35#include <media/v4l2-device.h>
36#include <media/v4l2-chip-ident.h>
37#include "tea6420.h" 36#include "tea6420.h"
38 37
39MODULE_AUTHOR("Michael Hunold <michael@mihu.de>"); 38MODULE_AUTHOR("Michael Hunold <michael@mihu.de>");
@@ -90,25 +89,13 @@ static int tea6420_s_routing(struct v4l2_subdev *sd,
90 return 0; 89 return 0;
91} 90}
92 91
93static int tea6420_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
94{
95 struct i2c_client *client = v4l2_get_subdevdata(sd);
96
97 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_TEA6420, 0);
98}
99
100/* ----------------------------------------------------------------------- */ 92/* ----------------------------------------------------------------------- */
101 93
102static const struct v4l2_subdev_core_ops tea6420_core_ops = {
103 .g_chip_ident = tea6420_g_chip_ident,
104};
105
106static const struct v4l2_subdev_audio_ops tea6420_audio_ops = { 94static const struct v4l2_subdev_audio_ops tea6420_audio_ops = {
107 .s_routing = tea6420_s_routing, 95 .s_routing = tea6420_s_routing,
108}; 96};
109 97
110static const struct v4l2_subdev_ops tea6420_ops = { 98static const struct v4l2_subdev_ops tea6420_ops = {
111 .core = &tea6420_core_ops,
112 .audio = &tea6420_audio_ops, 99 .audio = &tea6420_audio_ops,
113}; 100};
114 101
@@ -125,7 +112,7 @@ static int tea6420_probe(struct i2c_client *client,
125 v4l_info(client, "chip found @ 0x%x (%s)\n", 112 v4l_info(client, "chip found @ 0x%x (%s)\n",
126 client->addr << 1, client->adapter->name); 113 client->addr << 1, client->adapter->name);
127 114
128 sd = kzalloc(sizeof(struct v4l2_subdev), GFP_KERNEL); 115 sd = devm_kzalloc(&client->dev, sizeof(*sd), GFP_KERNEL);
129 if (sd == NULL) 116 if (sd == NULL)
130 return -ENOMEM; 117 return -ENOMEM;
131 v4l2_i2c_subdev_init(sd, client, &tea6420_ops); 118 v4l2_i2c_subdev_init(sd, client, &tea6420_ops);
@@ -146,7 +133,6 @@ static int tea6420_remove(struct i2c_client *client)
146 struct v4l2_subdev *sd = i2c_get_clientdata(client); 133 struct v4l2_subdev *sd = i2c_get_clientdata(client);
147 134
148 v4l2_device_unregister_subdev(sd); 135 v4l2_device_unregister_subdev(sd);
149 kfree(sd);
150 return 0; 136 return 0;
151} 137}
152 138
diff --git a/drivers/media/i2c/ths7303.c b/drivers/media/i2c/ths7303.c
index c4339556a2ea..0a2dacbd7a63 100644
--- a/drivers/media/i2c/ths7303.c
+++ b/drivers/media/i2c/ths7303.c
@@ -26,7 +26,6 @@
26#include <linux/slab.h> 26#include <linux/slab.h>
27 27
28#include <media/ths7303.h> 28#include <media/ths7303.h>
29#include <media/v4l2-chip-ident.h>
30#include <media/v4l2-device.h> 29#include <media/v4l2-device.h>
31 30
32#define THS7303_CHANNEL_1 1 31#define THS7303_CHANNEL_1 1
@@ -35,11 +34,10 @@
35 34
36struct ths7303_state { 35struct ths7303_state {
37 struct v4l2_subdev sd; 36 struct v4l2_subdev sd;
38 struct ths7303_platform_data pdata; 37 const struct ths7303_platform_data *pdata;
39 struct v4l2_bt_timings bt; 38 struct v4l2_bt_timings bt;
40 int std_id; 39 int std_id;
41 int stream_on; 40 int stream_on;
42 int driver_data;
43}; 41};
44 42
45enum ths7303_filter_mode { 43enum ths7303_filter_mode {
@@ -89,7 +87,7 @@ int ths7303_setval(struct v4l2_subdev *sd, enum ths7303_filter_mode mode)
89{ 87{
90 struct i2c_client *client = v4l2_get_subdevdata(sd); 88 struct i2c_client *client = v4l2_get_subdevdata(sd);
91 struct ths7303_state *state = to_state(sd); 89 struct ths7303_state *state = to_state(sd);
92 struct ths7303_platform_data *pdata = &state->pdata; 90 const struct ths7303_platform_data *pdata = state->pdata;
93 u8 val, sel = 0; 91 u8 val, sel = 0;
94 int err, disable = 0; 92 int err, disable = 0;
95 93
@@ -212,15 +210,6 @@ static int ths7303_s_dv_timings(struct v4l2_subdev *sd,
212 return ths7303_config(sd); 210 return ths7303_config(sd);
213} 211}
214 212
215static int ths7303_g_chip_ident(struct v4l2_subdev *sd,
216 struct v4l2_dbg_chip_ident *chip)
217{
218 struct i2c_client *client = v4l2_get_subdevdata(sd);
219 struct ths7303_state *state = to_state(sd);
220
221 return v4l2_chip_ident_i2c_client(client, chip, state->driver_data, 0);
222}
223
224static const struct v4l2_subdev_video_ops ths7303_video_ops = { 213static const struct v4l2_subdev_video_ops ths7303_video_ops = {
225 .s_stream = ths7303_s_stream, 214 .s_stream = ths7303_s_stream,
226 .s_std_output = ths7303_s_std_output, 215 .s_std_output = ths7303_s_std_output,
@@ -232,13 +221,6 @@ static const struct v4l2_subdev_video_ops ths7303_video_ops = {
232static int ths7303_g_register(struct v4l2_subdev *sd, 221static int ths7303_g_register(struct v4l2_subdev *sd,
233 struct v4l2_dbg_register *reg) 222 struct v4l2_dbg_register *reg)
234{ 223{
235 struct i2c_client *client = v4l2_get_subdevdata(sd);
236
237 if (!v4l2_chip_match_i2c_client(client, &reg->match))
238 return -EINVAL;
239 if (!capable(CAP_SYS_ADMIN))
240 return -EPERM;
241
242 reg->size = 1; 224 reg->size = 1;
243 reg->val = ths7303_read(sd, reg->reg); 225 reg->val = ths7303_read(sd, reg->reg);
244 return 0; 226 return 0;
@@ -247,13 +229,6 @@ static int ths7303_g_register(struct v4l2_subdev *sd,
247static int ths7303_s_register(struct v4l2_subdev *sd, 229static int ths7303_s_register(struct v4l2_subdev *sd,
248 const struct v4l2_dbg_register *reg) 230 const struct v4l2_dbg_register *reg)
249{ 231{
250 struct i2c_client *client = v4l2_get_subdevdata(sd);
251
252 if (!v4l2_chip_match_i2c_client(client, &reg->match))
253 return -EINVAL;
254 if (!capable(CAP_SYS_ADMIN))
255 return -EPERM;
256
257 ths7303_write(sd, reg->reg, reg->val); 232 ths7303_write(sd, reg->reg, reg->val);
258 return 0; 233 return 0;
259} 234}
@@ -340,7 +315,6 @@ static int ths7303_log_status(struct v4l2_subdev *sd)
340} 315}
341 316
342static const struct v4l2_subdev_core_ops ths7303_core_ops = { 317static const struct v4l2_subdev_core_ops ths7303_core_ops = {
343 .g_chip_ident = ths7303_g_chip_ident,
344 .log_status = ths7303_log_status, 318 .log_status = ths7303_log_status,
345#ifdef CONFIG_VIDEO_ADV_DEBUG 319#ifdef CONFIG_VIDEO_ADV_DEBUG
346 .g_register = ths7303_g_register, 320 .g_register = ths7303_g_register,
@@ -353,32 +327,6 @@ static const struct v4l2_subdev_ops ths7303_ops = {
353 .video = &ths7303_video_ops, 327 .video = &ths7303_video_ops,
354}; 328};
355 329
356static int ths7303_setup(struct v4l2_subdev *sd)
357{
358 struct ths7303_state *state = to_state(sd);
359 struct ths7303_platform_data *pdata = &state->pdata;
360 int ret;
361 u8 mask;
362
363 state->stream_on = pdata->init_enable;
364
365 mask = state->stream_on ? 0xff : 0xf8;
366
367 ret = ths7303_write(sd, THS7303_CHANNEL_1, pdata->ch_1 & mask);
368 if (ret)
369 return ret;
370
371 ret = ths7303_write(sd, THS7303_CHANNEL_2, pdata->ch_2 & mask);
372 if (ret)
373 return ret;
374
375 ret = ths7303_write(sd, THS7303_CHANNEL_3, pdata->ch_3 & mask);
376 if (ret)
377 return ret;
378
379 return 0;
380}
381
382static int ths7303_probe(struct i2c_client *client, 330static int ths7303_probe(struct i2c_client *client,
383 const struct i2c_device_id *id) 331 const struct i2c_device_id *id)
384{ 332{
@@ -386,6 +334,11 @@ static int ths7303_probe(struct i2c_client *client,
386 struct ths7303_state *state; 334 struct ths7303_state *state;
387 struct v4l2_subdev *sd; 335 struct v4l2_subdev *sd;
388 336
337 if (pdata == NULL) {
338 dev_err(&client->dev, "No platform data\n");
339 return -EINVAL;
340 }
341
389 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 342 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
390 return -ENODEV; 343 return -ENODEV;
391 344
@@ -397,20 +350,14 @@ static int ths7303_probe(struct i2c_client *client,
397 if (!state) 350 if (!state)
398 return -ENOMEM; 351 return -ENOMEM;
399 352
400 if (!pdata) 353 state->pdata = pdata;
401 v4l_warn(client, "No platform data, using default data!\n");
402 else
403 state->pdata = *pdata;
404
405 sd = &state->sd; 354 sd = &state->sd;
406 v4l2_i2c_subdev_init(sd, client, &ths7303_ops); 355 v4l2_i2c_subdev_init(sd, client, &ths7303_ops);
407 356
408 /* store the driver data to differntiate the chip */ 357 /* set to default 480I_576I filter mode */
409 state->driver_data = (int)id->driver_data; 358 if (ths7303_setval(sd, THS7303_FILTER_MODE_480I_576I) < 0) {
410 359 v4l_err(client, "Setting to 480I_576I filter mode failed!\n");
411 if (ths7303_setup(sd) < 0) { 360 return -EINVAL;
412 v4l_err(client, "init failed\n");
413 return -EIO;
414 } 361 }
415 362
416 return 0; 363 return 0;
@@ -426,8 +373,8 @@ static int ths7303_remove(struct i2c_client *client)
426} 373}
427 374
428static const struct i2c_device_id ths7303_id[] = { 375static const struct i2c_device_id ths7303_id[] = {
429 {"ths7303", V4L2_IDENT_THS7303}, 376 {"ths7303", 0},
430 {"ths7353", V4L2_IDENT_THS7353}, 377 {"ths7353", 0},
431 {}, 378 {},
432}; 379};
433 380
diff --git a/drivers/media/i2c/ths8200.c b/drivers/media/i2c/ths8200.c
new file mode 100644
index 000000000000..a24f90c5261c
--- /dev/null
+++ b/drivers/media/i2c/ths8200.c
@@ -0,0 +1,556 @@
1/*
2 * ths8200 - Texas Instruments THS8200 video encoder driver
3 *
4 * Copyright 2013 Cisco Systems, Inc. and/or its affiliates.
5 *
6 * This program is free software; you may redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation version 2.
13 *
14 * This program is distributed .as is. WITHOUT ANY WARRANTY of any
15 * kind, whether express or implied; without even the implied warranty
16 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */
19
20#include <linux/i2c.h>
21#include <linux/module.h>
22#include <linux/v4l2-dv-timings.h>
23
24#include <media/v4l2-device.h>
25
26#include "ths8200_regs.h"
27
28static int debug;
29module_param(debug, int, 0644);
30MODULE_PARM_DESC(debug, "debug level (0-2)");
31
32MODULE_DESCRIPTION("Texas Instruments THS8200 video encoder driver");
33MODULE_AUTHOR("Mats Randgaard <mats.randgaard@cisco.com>");
34MODULE_AUTHOR("Martin Bugge <martin.bugge@cisco.com>");
35MODULE_LICENSE("GPL v2");
36
37struct ths8200_state {
38 struct v4l2_subdev sd;
39 uint8_t chip_version;
40 /* Is the ths8200 powered on? */
41 bool power_on;
42 struct v4l2_dv_timings dv_timings;
43};
44
45static const struct v4l2_dv_timings ths8200_timings[] = {
46 V4L2_DV_BT_CEA_720X480P59_94,
47 V4L2_DV_BT_CEA_1280X720P24,
48 V4L2_DV_BT_CEA_1280X720P25,
49 V4L2_DV_BT_CEA_1280X720P30,
50 V4L2_DV_BT_CEA_1280X720P50,
51 V4L2_DV_BT_CEA_1280X720P60,
52 V4L2_DV_BT_CEA_1920X1080P24,
53 V4L2_DV_BT_CEA_1920X1080P25,
54 V4L2_DV_BT_CEA_1920X1080P30,
55 V4L2_DV_BT_CEA_1920X1080P50,
56 V4L2_DV_BT_CEA_1920X1080P60,
57};
58
59static inline struct ths8200_state *to_state(struct v4l2_subdev *sd)
60{
61 return container_of(sd, struct ths8200_state, sd);
62}
63
64static inline unsigned hblanking(const struct v4l2_bt_timings *t)
65{
66 return t->hfrontporch + t->hsync + t->hbackporch;
67}
68
69static inline unsigned htotal(const struct v4l2_bt_timings *t)
70{
71 return t->width + t->hfrontporch + t->hsync + t->hbackporch;
72}
73
74static inline unsigned vblanking(const struct v4l2_bt_timings *t)
75{
76 return t->vfrontporch + t->vsync + t->vbackporch;
77}
78
79static inline unsigned vtotal(const struct v4l2_bt_timings *t)
80{
81 return t->height + t->vfrontporch + t->vsync + t->vbackporch;
82}
83
84static int ths8200_read(struct v4l2_subdev *sd, u8 reg)
85{
86 struct i2c_client *client = v4l2_get_subdevdata(sd);
87
88 return i2c_smbus_read_byte_data(client, reg);
89}
90
91static int ths8200_write(struct v4l2_subdev *sd, u8 reg, u8 val)
92{
93 struct i2c_client *client = v4l2_get_subdevdata(sd);
94 int ret;
95 int i;
96
97 for (i = 0; i < 3; i++) {
98 ret = i2c_smbus_write_byte_data(client, reg, val);
99 if (ret == 0)
100 return 0;
101 }
102 v4l2_err(sd, "I2C Write Problem\n");
103 return ret;
104}
105
106/* To set specific bits in the register, a clear-mask is given (to be AND-ed),
107 * and then the value-mask (to be OR-ed).
108 */
109static inline void
110ths8200_write_and_or(struct v4l2_subdev *sd, u8 reg,
111 uint8_t clr_mask, uint8_t val_mask)
112{
113 ths8200_write(sd, reg, (ths8200_read(sd, reg) & clr_mask) | val_mask);
114}
115
116#ifdef CONFIG_VIDEO_ADV_DEBUG
117
118static int ths8200_g_register(struct v4l2_subdev *sd,
119 struct v4l2_dbg_register *reg)
120{
121 reg->val = ths8200_read(sd, reg->reg & 0xff);
122 reg->size = 1;
123
124 return 0;
125}
126
127static int ths8200_s_register(struct v4l2_subdev *sd,
128 const struct v4l2_dbg_register *reg)
129{
130 ths8200_write(sd, reg->reg & 0xff, reg->val & 0xff);
131
132 return 0;
133}
134#endif
135
136static void ths8200_print_timings(struct v4l2_subdev *sd,
137 struct v4l2_dv_timings *timings,
138 const char *txt, bool detailed)
139{
140 struct v4l2_bt_timings *bt = &timings->bt;
141 u32 htot, vtot;
142
143 if (timings->type != V4L2_DV_BT_656_1120)
144 return;
145
146 htot = htotal(bt);
147 vtot = vtotal(bt);
148
149 v4l2_info(sd, "%s %dx%d%s%d (%dx%d)",
150 txt, bt->width, bt->height, bt->interlaced ? "i" : "p",
151 (htot * vtot) > 0 ? ((u32)bt->pixelclock / (htot * vtot)) : 0,
152 htot, vtot);
153
154 if (detailed) {
155 v4l2_info(sd, " horizontal: fp = %d, %ssync = %d, bp = %d\n",
156 bt->hfrontporch,
157 (bt->polarities & V4L2_DV_HSYNC_POS_POL) ? "+" : "-",
158 bt->hsync, bt->hbackporch);
159 v4l2_info(sd, " vertical: fp = %d, %ssync = %d, bp = %d\n",
160 bt->vfrontporch,
161 (bt->polarities & V4L2_DV_VSYNC_POS_POL) ? "+" : "-",
162 bt->vsync, bt->vbackporch);
163 v4l2_info(sd,
164 " pixelclock: %lld, flags: 0x%x, standards: 0x%x\n",
165 bt->pixelclock, bt->flags, bt->standards);
166 }
167}
168
169static int ths8200_log_status(struct v4l2_subdev *sd)
170{
171 struct ths8200_state *state = to_state(sd);
172 uint8_t reg_03 = ths8200_read(sd, THS8200_CHIP_CTL);
173
174 v4l2_info(sd, "----- Chip status -----\n");
175 v4l2_info(sd, "version: %u\n", state->chip_version);
176 v4l2_info(sd, "power: %s\n", (reg_03 & 0x0c) ? "off" : "on");
177 v4l2_info(sd, "reset: %s\n", (reg_03 & 0x01) ? "off" : "on");
178 v4l2_info(sd, "test pattern: %s\n",
179 (reg_03 & 0x20) ? "enabled" : "disabled");
180 v4l2_info(sd, "format: %ux%u\n",
181 ths8200_read(sd, THS8200_DTG2_PIXEL_CNT_MSB) * 256 +
182 ths8200_read(sd, THS8200_DTG2_PIXEL_CNT_LSB),
183 (ths8200_read(sd, THS8200_DTG2_LINE_CNT_MSB) & 0x07) * 256 +
184 ths8200_read(sd, THS8200_DTG2_LINE_CNT_LSB));
185 ths8200_print_timings(sd, &state->dv_timings,
186 "Configured format:", true);
187
188 return 0;
189}
190
191/* Power up/down ths8200 */
192static int ths8200_s_power(struct v4l2_subdev *sd, int on)
193{
194 struct ths8200_state *state = to_state(sd);
195
196 v4l2_dbg(1, debug, sd, "%s: power %s\n", __func__, on ? "on" : "off");
197
198 state->power_on = on;
199
200 /* Power up/down - leave in reset state until input video is present */
201 ths8200_write_and_or(sd, THS8200_CHIP_CTL, 0xf2, (on ? 0x00 : 0x0c));
202
203 return 0;
204}
205
206static const struct v4l2_subdev_core_ops ths8200_core_ops = {
207 .log_status = ths8200_log_status,
208 .s_power = ths8200_s_power,
209#ifdef CONFIG_VIDEO_ADV_DEBUG
210 .g_register = ths8200_g_register,
211 .s_register = ths8200_s_register,
212#endif
213};
214
215/* -----------------------------------------------------------------------------
216 * V4L2 subdev video operations
217 */
218
219static int ths8200_s_stream(struct v4l2_subdev *sd, int enable)
220{
221 struct ths8200_state *state = to_state(sd);
222
223 if (enable && !state->power_on)
224 ths8200_s_power(sd, true);
225
226 ths8200_write_and_or(sd, THS8200_CHIP_CTL, 0xfe,
227 (enable ? 0x01 : 0x00));
228
229 v4l2_dbg(1, debug, sd, "%s: %sable\n",
230 __func__, (enable ? "en" : "dis"));
231
232 return 0;
233}
234
235static void ths8200_core_init(struct v4l2_subdev *sd)
236{
237 /* setup clocks */
238 ths8200_write_and_or(sd, THS8200_CHIP_CTL, 0x3f, 0xc0);
239
240 /**** Data path control (DATA) ****/
241 /* Set FSADJ 700 mV,
242 * bypass 422-444 interpolation,
243 * input format 30 bit RGB444
244 */
245 ths8200_write(sd, THS8200_DATA_CNTL, 0x70);
246
247 /* DTG Mode (Video blocked during blanking
248 * VESA slave
249 */
250 ths8200_write(sd, THS8200_DTG1_MODE, 0x87);
251
252 /**** Display Timing Generator Control, Part 1 (DTG1). ****/
253
254 /* Disable embedded syncs on the output by setting
255 * the amplitude to zero for all channels.
256 */
257 ths8200_write(sd, THS8200_DTG1_Y_SYNC_MSB, 0x2a);
258 ths8200_write(sd, THS8200_DTG1_CBCR_SYNC_MSB, 0x2a);
259}
260
261static void ths8200_setup(struct v4l2_subdev *sd, struct v4l2_bt_timings *bt)
262{
263 uint8_t polarity = 0;
264 uint16_t line_start_active_video = (bt->vsync + bt->vbackporch);
265 uint16_t line_start_front_porch = (vtotal(bt) - bt->vfrontporch);
266
267 /*** System ****/
268 /* Set chip in reset while it is configured */
269 ths8200_s_stream(sd, false);
270
271 /* configure video output timings */
272 ths8200_write(sd, THS8200_DTG1_SPEC_A, bt->hsync);
273 ths8200_write(sd, THS8200_DTG1_SPEC_B, bt->hfrontporch);
274
275 /* Zero for progressive scan formats.*/
276 if (!bt->interlaced)
277 ths8200_write(sd, THS8200_DTG1_SPEC_C, 0x00);
278
279 /* Distance from leading edge of h sync to start of active video.
280 * MSB in 0x2b
281 */
282 ths8200_write(sd, THS8200_DTG1_SPEC_D_LSB,
283 (bt->hbackporch + bt->hsync) & 0xff);
284 /* Zero for SDTV-mode. MSB in 0x2b */
285 ths8200_write(sd, THS8200_DTG1_SPEC_E_LSB, 0x00);
286 /*
287 * MSB for dtg1_spec(d/e/h). See comment for
288 * corresponding LSB registers.
289 */
290 ths8200_write(sd, THS8200_DTG1_SPEC_DEH_MSB,
291 ((bt->hbackporch + bt->hsync) & 0x100) >> 1);
292
293 /* h front porch */
294 ths8200_write(sd, THS8200_DTG1_SPEC_K_LSB, (bt->hfrontporch) & 0xff);
295 ths8200_write(sd, THS8200_DTG1_SPEC_K_MSB,
296 ((bt->hfrontporch) & 0x700) >> 8);
297
298 /* Half the line length. Used to calculate SDTV line types. */
299 ths8200_write(sd, THS8200_DTG1_SPEC_G_LSB, (htotal(bt)/2) & 0xff);
300 ths8200_write(sd, THS8200_DTG1_SPEC_G_MSB,
301 ((htotal(bt)/2) >> 8) & 0x0f);
302
303 /* Total pixels per line (ex. 720p: 1650) */
304 ths8200_write(sd, THS8200_DTG1_TOT_PIXELS_MSB, htotal(bt) >> 8);
305 ths8200_write(sd, THS8200_DTG1_TOT_PIXELS_LSB, htotal(bt) & 0xff);
306
307 /* Frame height and field height */
308 /* Field height should be programmed higher than frame_size for
309 * progressive scan formats
310 */
311 ths8200_write(sd, THS8200_DTG1_FRAME_FIELD_SZ_MSB,
312 ((vtotal(bt) >> 4) & 0xf0) + 0x7);
313 ths8200_write(sd, THS8200_DTG1_FRAME_SZ_LSB, vtotal(bt) & 0xff);
314
315 /* Should be programmed higher than frame_size
316 * for progressive formats
317 */
318 if (!bt->interlaced)
319 ths8200_write(sd, THS8200_DTG1_FIELD_SZ_LSB, 0xff);
320
321 /**** Display Timing Generator Control, Part 2 (DTG2). ****/
322 /* Set breakpoint line numbers and types
323 * THS8200 generates line types with different properties. A line type
324 * that sets all the RGB-outputs to zero is used in the blanking areas,
325 * while a line type that enable the RGB-outputs is used in active video
326 * area. The line numbers for start of active video, start of front
327 * porch and after the last line in the frame must be set with the
328 * corresponding line types.
329 *
330 * Line types:
331 * 0x9 - Full normal sync pulse: Blocks data when dtg1_pass is off.
332 * Used in blanking area.
333 * 0x0 - Active video: Video data is always passed. Used in active
334 * video area.
335 */
336 ths8200_write_and_or(sd, THS8200_DTG2_BP1_2_MSB, 0x88,
337 ((line_start_active_video >> 4) & 0x70) +
338 ((line_start_front_porch >> 8) & 0x07));
339 ths8200_write(sd, THS8200_DTG2_BP3_4_MSB, ((vtotal(bt)) >> 4) & 0x70);
340 ths8200_write(sd, THS8200_DTG2_BP1_LSB, line_start_active_video & 0xff);
341 ths8200_write(sd, THS8200_DTG2_BP2_LSB, line_start_front_porch & 0xff);
342 ths8200_write(sd, THS8200_DTG2_BP3_LSB, (vtotal(bt)) & 0xff);
343
344 /* line types */
345 ths8200_write(sd, THS8200_DTG2_LINETYPE1, 0x90);
346 ths8200_write(sd, THS8200_DTG2_LINETYPE2, 0x90);
347
348 /* h sync width transmitted */
349 ths8200_write(sd, THS8200_DTG2_HLENGTH_LSB, bt->hsync & 0xff);
350 ths8200_write_and_or(sd, THS8200_DTG2_HLENGTH_LSB_HDLY_MSB, 0x3f,
351 (bt->hsync >> 2) & 0xc0);
352
353 /* The pixel value h sync is asserted on */
354 ths8200_write_and_or(sd, THS8200_DTG2_HLENGTH_LSB_HDLY_MSB, 0xe0,
355 (htotal(bt) >> 8) & 0x1f);
356 ths8200_write(sd, THS8200_DTG2_HLENGTH_HDLY_LSB, htotal(bt));
357
358 /* v sync width transmitted */
359 ths8200_write(sd, THS8200_DTG2_VLENGTH1_LSB, (bt->vsync) & 0xff);
360 ths8200_write_and_or(sd, THS8200_DTG2_VLENGTH1_MSB_VDLY1_MSB, 0x3f,
361 ((bt->vsync) >> 2) & 0xc0);
362
363 /* The pixel value v sync is asserted on */
364 ths8200_write_and_or(sd, THS8200_DTG2_VLENGTH1_MSB_VDLY1_MSB, 0xf8,
365 (vtotal(bt)>>8) & 0x7);
366 ths8200_write(sd, THS8200_DTG2_VDLY1_LSB, vtotal(bt));
367
368 /* For progressive video vlength2 must be set to all 0 and vdly2 must
369 * be set to all 1.
370 */
371 ths8200_write(sd, THS8200_DTG2_VLENGTH2_LSB, 0x00);
372 ths8200_write(sd, THS8200_DTG2_VLENGTH2_MSB_VDLY2_MSB, 0x07);
373 ths8200_write(sd, THS8200_DTG2_VDLY2_LSB, 0xff);
374
375 /* Internal delay factors to synchronize the sync pulses and the data */
376 /* Experimental values delays (hor 4, ver 1) */
377 ths8200_write(sd, THS8200_DTG2_HS_IN_DLY_MSB, (htotal(bt)>>8) & 0x1f);
378 ths8200_write(sd, THS8200_DTG2_HS_IN_DLY_LSB, (htotal(bt) - 4) & 0xff);
379 ths8200_write(sd, THS8200_DTG2_VS_IN_DLY_MSB, 0);
380 ths8200_write(sd, THS8200_DTG2_VS_IN_DLY_LSB, 1);
381
382 /* Polarity of received and transmitted sync signals */
383 if (bt->polarities & V4L2_DV_HSYNC_POS_POL) {
384 polarity |= 0x01; /* HS_IN */
385 polarity |= 0x08; /* HS_OUT */
386 }
387 if (bt->polarities & V4L2_DV_VSYNC_POS_POL) {
388 polarity |= 0x02; /* VS_IN */
389 polarity |= 0x10; /* VS_OUT */
390 }
391
392 /* RGB mode, no embedded timings */
393 /* Timing of video input bus is derived from HS, VS, and FID dedicated
394 * inputs
395 */
396 ths8200_write(sd, THS8200_DTG2_CNTL, 0x47 | polarity);
397
398 /* leave reset */
399 ths8200_s_stream(sd, true);
400
401 v4l2_dbg(1, debug, sd, "%s: frame %dx%d, polarity %d\n"
402 "horizontal: front porch %d, back porch %d, sync %d\n"
403 "vertical: sync %d\n", __func__, htotal(bt), vtotal(bt),
404 polarity, bt->hfrontporch, bt->hbackporch,
405 bt->hsync, bt->vsync);
406}
407
408static int ths8200_s_dv_timings(struct v4l2_subdev *sd,
409 struct v4l2_dv_timings *timings)
410{
411 struct ths8200_state *state = to_state(sd);
412 int i;
413
414 v4l2_dbg(1, debug, sd, "%s:\n", __func__);
415
416 if (timings->type != V4L2_DV_BT_656_1120)
417 return -EINVAL;
418
419 /* TODO Support interlaced formats */
420 if (timings->bt.interlaced) {
421 v4l2_dbg(1, debug, sd, "TODO Support interlaced formats\n");
422 return -EINVAL;
423 }
424
425 for (i = 0; i < ARRAY_SIZE(ths8200_timings); i++) {
426 if (v4l_match_dv_timings(&ths8200_timings[i], timings, 10))
427 break;
428 }
429
430 if (i == ARRAY_SIZE(ths8200_timings)) {
431 v4l2_dbg(1, debug, sd, "Unsupported format\n");
432 return -EINVAL;
433 }
434
435 timings->bt.flags &= ~V4L2_DV_FL_REDUCED_FPS;
436
437 /* save timings */
438 state->dv_timings = *timings;
439
440 ths8200_setup(sd, &timings->bt);
441
442 return 0;
443}
444
445static int ths8200_g_dv_timings(struct v4l2_subdev *sd,
446 struct v4l2_dv_timings *timings)
447{
448 struct ths8200_state *state = to_state(sd);
449
450 v4l2_dbg(1, debug, sd, "%s:\n", __func__);
451
452 *timings = state->dv_timings;
453
454 return 0;
455}
456
457static int ths8200_enum_dv_timings(struct v4l2_subdev *sd,
458 struct v4l2_enum_dv_timings *timings)
459{
460 /* Check requested format index is within range */
461 if (timings->index >= ARRAY_SIZE(ths8200_timings))
462 return -EINVAL;
463
464 timings->timings = ths8200_timings[timings->index];
465
466 return 0;
467}
468
469static int ths8200_dv_timings_cap(struct v4l2_subdev *sd,
470 struct v4l2_dv_timings_cap *cap)
471{
472 cap->type = V4L2_DV_BT_656_1120;
473 cap->bt.max_width = 1920;
474 cap->bt.max_height = 1080;
475 cap->bt.min_pixelclock = 27000000;
476 cap->bt.max_pixelclock = 148500000;
477 cap->bt.standards = V4L2_DV_BT_STD_CEA861;
478 cap->bt.capabilities = V4L2_DV_BT_CAP_PROGRESSIVE;
479
480 return 0;
481}
482
483/* Specific video subsystem operation handlers */
484static const struct v4l2_subdev_video_ops ths8200_video_ops = {
485 .s_stream = ths8200_s_stream,
486 .s_dv_timings = ths8200_s_dv_timings,
487 .g_dv_timings = ths8200_g_dv_timings,
488 .enum_dv_timings = ths8200_enum_dv_timings,
489 .dv_timings_cap = ths8200_dv_timings_cap,
490};
491
492/* V4L2 top level operation handlers */
493static const struct v4l2_subdev_ops ths8200_ops = {
494 .core = &ths8200_core_ops,
495 .video = &ths8200_video_ops,
496};
497
498static int ths8200_probe(struct i2c_client *client,
499 const struct i2c_device_id *id)
500{
501 struct ths8200_state *state;
502 struct v4l2_subdev *sd;
503
504 /* Check if the adapter supports the needed features */
505 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
506 return -EIO;
507
508 state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL);
509 if (!state)
510 return -ENOMEM;
511
512 sd = &state->sd;
513 v4l2_i2c_subdev_init(sd, client, &ths8200_ops);
514
515 state->chip_version = ths8200_read(sd, THS8200_VERSION);
516 v4l2_dbg(1, debug, sd, "chip version 0x%x\n", state->chip_version);
517
518 ths8200_core_init(sd);
519
520 v4l2_info(sd, "%s found @ 0x%x (%s)\n", client->name,
521 client->addr << 1, client->adapter->name);
522
523 return 0;
524}
525
526static int ths8200_remove(struct i2c_client *client)
527{
528 struct v4l2_subdev *sd = i2c_get_clientdata(client);
529
530 v4l2_dbg(1, debug, sd, "%s removed @ 0x%x (%s)\n", client->name,
531 client->addr << 1, client->adapter->name);
532
533 ths8200_s_power(sd, false);
534
535 v4l2_device_unregister_subdev(sd);
536
537 return 0;
538}
539
540static struct i2c_device_id ths8200_id[] = {
541 { "ths8200", 0 },
542 {},
543};
544MODULE_DEVICE_TABLE(i2c, ths8200_id);
545
546static struct i2c_driver ths8200_driver = {
547 .driver = {
548 .owner = THIS_MODULE,
549 .name = "ths8200",
550 },
551 .probe = ths8200_probe,
552 .remove = ths8200_remove,
553 .id_table = ths8200_id,
554};
555
556module_i2c_driver(ths8200_driver);
diff --git a/drivers/media/i2c/ths8200_regs.h b/drivers/media/i2c/ths8200_regs.h
new file mode 100644
index 000000000000..6bc9fd1111db
--- /dev/null
+++ b/drivers/media/i2c/ths8200_regs.h
@@ -0,0 +1,161 @@
1/*
2 * ths8200 - Texas Instruments THS8200 video encoder driver
3 *
4 * Copyright 2013 Cisco Systems, Inc. and/or its affiliates.
5 *
6 * This program is free software; you may redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation version 2.
13 *
14 * This program is distributed .as is. WITHOUT ANY WARRANTY of any
15 * kind, whether express or implied; without even the implied warranty
16 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */
19
20#ifndef THS8200_REGS_H
21#define THS8200_REGS_H
22
23/* Register offset macros */
24#define THS8200_VERSION 0x02
25#define THS8200_CHIP_CTL 0x03
26#define THS8200_CSC_R11 0x04
27#define THS8200_CSC_R12 0x05
28#define THS8200_CSC_R21 0x06
29#define THS8200_CSC_R22 0x07
30#define THS8200_CSC_R31 0x08
31#define THS8200_CSC_R32 0x09
32#define THS8200_CSC_G11 0x0a
33#define THS8200_CSC_G12 0x0b
34#define THS8200_CSC_G21 0x0c
35#define THS8200_CSC_G22 0x0d
36#define THS8200_CSC_G31 0x0e
37#define THS8200_CSC_G32 0x0f
38#define THS8200_CSC_B11 0x10
39#define THS8200_CSC_B12 0x11
40#define THS8200_CSC_B21 0x12
41#define THS8200_CSC_B22 0x13
42#define THS8200_CSC_B31 0x14
43#define THS8200_CSC_B32 0x15
44#define THS8200_CSC_OFFS1 0x16
45#define THS8200_CSC_OFFS12 0x17
46#define THS8200_CSC_OFFS23 0x18
47#define THS8200_CSC_OFFS3 0x19
48#define THS8200_TST_CNTL1 0x1a
49#define THS8200_TST_CNTL2 0x1b
50#define THS8200_DATA_CNTL 0x1c
51#define THS8200_DTG1_Y_SYNC1_LSB 0x1d
52#define THS8200_DTG1_Y_SYNC2_LSB 0x1e
53#define THS8200_DTG1_Y_SYNC3_LSB 0x1f
54#define THS8200_DTG1_CBCR_SYNC1_LSB 0x20
55#define THS8200_DTG1_CBCR_SYNC2_LSB 0x21
56#define THS8200_DTG1_CBCR_SYNC3_LSB 0x22
57#define THS8200_DTG1_Y_SYNC_MSB 0x23
58#define THS8200_DTG1_CBCR_SYNC_MSB 0x24
59#define THS8200_DTG1_SPEC_A 0x25
60#define THS8200_DTG1_SPEC_B 0x26
61#define THS8200_DTG1_SPEC_C 0x27
62#define THS8200_DTG1_SPEC_D_LSB 0x28
63#define THS8200_DTG1_SPEC_D1 0x29
64#define THS8200_DTG1_SPEC_E_LSB 0x2a
65#define THS8200_DTG1_SPEC_DEH_MSB 0x2b
66#define THS8200_DTG1_SPEC_H_LSB 0x2c
67#define THS8200_DTG1_SPEC_I_MSB 0x2d
68#define THS8200_DTG1_SPEC_I_LSB 0x2e
69#define THS8200_DTG1_SPEC_K_LSB 0x2f
70#define THS8200_DTG1_SPEC_K_MSB 0x30
71#define THS8200_DTG1_SPEC_K1 0x31
72#define THS8200_DTG1_SPEC_G_LSB 0x32
73#define THS8200_DTG1_SPEC_G_MSB 0x33
74#define THS8200_DTG1_TOT_PIXELS_MSB 0x34
75#define THS8200_DTG1_TOT_PIXELS_LSB 0x35
76#define THS8200_DTG1_FLD_FLIP_LINECNT_MSB 0x36
77#define THS8200_DTG1_LINECNT_LSB 0x37
78#define THS8200_DTG1_MODE 0x38
79#define THS8200_DTG1_FRAME_FIELD_SZ_MSB 0x39
80#define THS8200_DTG1_FRAME_SZ_LSB 0x3a
81#define THS8200_DTG1_FIELD_SZ_LSB 0x3b
82#define THS8200_DTG1_VESA_CBAR_SIZE 0x3c
83#define THS8200_DAC_CNTL_MSB 0x3d
84#define THS8200_DAC1_CNTL_LSB 0x3e
85#define THS8200_DAC2_CNTL_LSB 0x3f
86#define THS8200_DAC3_CNTL_LSB 0x40
87#define THS8200_CSM_CLIP_GY_LOW 0x41
88#define THS8200_CSM_CLIP_BCB_LOW 0x42
89#define THS8200_CSM_CLIP_RCR_LOW 0x43
90#define THS8200_CSM_CLIP_GY_HIGH 0x44
91#define THS8200_CSM_CLIP_BCB_HIGH 0x45
92#define THS8200_CSM_CLIP_RCR_HIGH 0x46
93#define THS8200_CSM_SHIFT_GY 0x47
94#define THS8200_CSM_SHIFT_BCB 0x48
95#define THS8200_CSM_SHIFT_RCR 0x49
96#define THS8200_CSM_GY_CNTL_MULT_MSB 0x4a
97#define THS8200_CSM_MULT_BCB_RCR_MSB 0x4b
98#define THS8200_CSM_MULT_GY_LSB 0x4c
99#define THS8200_CSM_MULT_BCB_LSB 0x4d
100#define THS8200_CSM_MULT_RCR_LSB 0x4e
101#define THS8200_CSM_MULT_RCR_BCB_CNTL 0x4f
102#define THS8200_CSM_MULT_RCR_LSB 0x4e
103#define THS8200_DTG2_BP1_2_MSB 0x50
104#define THS8200_DTG2_BP3_4_MSB 0x51
105#define THS8200_DTG2_BP5_6_MSB 0x52
106#define THS8200_DTG2_BP7_8_MSB 0x53
107#define THS8200_DTG2_BP9_10_MSB 0x54
108#define THS8200_DTG2_BP11_12_MSB 0x55
109#define THS8200_DTG2_BP13_14_MSB 0x56
110#define THS8200_DTG2_BP15_16_MSB 0x57
111#define THS8200_DTG2_BP1_LSB 0x58
112#define THS8200_DTG2_BP2_LSB 0x59
113#define THS8200_DTG2_BP3_LSB 0x5a
114#define THS8200_DTG2_BP4_LSB 0x5b
115#define THS8200_DTG2_BP5_LSB 0x5c
116#define THS8200_DTG2_BP6_LSB 0x5d
117#define THS8200_DTG2_BP7_LSB 0x5e
118#define THS8200_DTG2_BP8_LSB 0x5f
119#define THS8200_DTG2_BP9_LSB 0x60
120#define THS8200_DTG2_BP10_LSB 0x61
121#define THS8200_DTG2_BP11_LSB 0x62
122#define THS8200_DTG2_BP12_LSB 0x63
123#define THS8200_DTG2_BP13_LSB 0x64
124#define THS8200_DTG2_BP14_LSB 0x65
125#define THS8200_DTG2_BP15_LSB 0x66
126#define THS8200_DTG2_BP16_LSB 0x67
127#define THS8200_DTG2_LINETYPE1 0x68
128#define THS8200_DTG2_LINETYPE2 0x69
129#define THS8200_DTG2_LINETYPE3 0x6a
130#define THS8200_DTG2_LINETYPE4 0x6b
131#define THS8200_DTG2_LINETYPE5 0x6c
132#define THS8200_DTG2_LINETYPE6 0x6d
133#define THS8200_DTG2_LINETYPE7 0x6e
134#define THS8200_DTG2_LINETYPE8 0x6f
135#define THS8200_DTG2_HLENGTH_LSB 0x70
136#define THS8200_DTG2_HLENGTH_LSB_HDLY_MSB 0x71
137#define THS8200_DTG2_HLENGTH_HDLY_LSB 0x72
138#define THS8200_DTG2_VLENGTH1_LSB 0x73
139#define THS8200_DTG2_VLENGTH1_MSB_VDLY1_MSB 0x74
140#define THS8200_DTG2_VDLY1_LSB 0x75
141#define THS8200_DTG2_VLENGTH2_LSB 0x76
142#define THS8200_DTG2_VLENGTH2_MSB_VDLY2_MSB 0x77
143#define THS8200_DTG2_VDLY2_LSB 0x78
144#define THS8200_DTG2_HS_IN_DLY_MSB 0x79
145#define THS8200_DTG2_HS_IN_DLY_LSB 0x7a
146#define THS8200_DTG2_VS_IN_DLY_MSB 0x7b
147#define THS8200_DTG2_VS_IN_DLY_LSB 0x7c
148#define THS8200_DTG2_PIXEL_CNT_MSB 0x7d
149#define THS8200_DTG2_PIXEL_CNT_LSB 0x7e
150#define THS8200_DTG2_LINE_CNT_MSB 0x7f
151#define THS8200_DTG2_LINE_CNT_LSB 0x80
152#define THS8200_DTG2_CNTL 0x82
153#define THS8200_CGMS_CNTL_HEADER 0x83
154#define THS8200_CGMS_PAYLOAD_MSB 0x84
155#define THS8200_CGMS_PAYLOAD_LSB 0x85
156#define THS8200_MISC_PPL_LSB 0x86
157#define THS8200_MISC_PPL_MSB 0x87
158#define THS8200_MISC_LPF_MSB 0x88
159#define THS8200_MISC_LPF_LSB 0x89
160
161#endif /* THS8200_REGS_H */
diff --git a/drivers/media/i2c/tlv320aic23b.c b/drivers/media/i2c/tlv320aic23b.c
index 809a75a558ee..ef87f7b09ea2 100644
--- a/drivers/media/i2c/tlv320aic23b.c
+++ b/drivers/media/i2c/tlv320aic23b.c
@@ -162,7 +162,7 @@ static int tlv320aic23b_probe(struct i2c_client *client,
162 v4l_info(client, "chip found @ 0x%x (%s)\n", 162 v4l_info(client, "chip found @ 0x%x (%s)\n",
163 client->addr << 1, client->adapter->name); 163 client->addr << 1, client->adapter->name);
164 164
165 state = kzalloc(sizeof(struct tlv320aic23b_state), GFP_KERNEL); 165 state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL);
166 if (state == NULL) 166 if (state == NULL)
167 return -ENOMEM; 167 return -ENOMEM;
168 sd = &state->sd; 168 sd = &state->sd;
@@ -191,7 +191,6 @@ static int tlv320aic23b_probe(struct i2c_client *client,
191 int err = state->hdl.error; 191 int err = state->hdl.error;
192 192
193 v4l2_ctrl_handler_free(&state->hdl); 193 v4l2_ctrl_handler_free(&state->hdl);
194 kfree(state);
195 return err; 194 return err;
196 } 195 }
197 v4l2_ctrl_handler_setup(&state->hdl); 196 v4l2_ctrl_handler_setup(&state->hdl);
@@ -205,7 +204,6 @@ static int tlv320aic23b_remove(struct i2c_client *client)
205 204
206 v4l2_device_unregister_subdev(sd); 205 v4l2_device_unregister_subdev(sd);
207 v4l2_ctrl_handler_free(&state->hdl); 206 v4l2_ctrl_handler_free(&state->hdl);
208 kfree(state);
209 return 0; 207 return 0;
210} 208}
211 209
diff --git a/drivers/media/i2c/tvaudio.c b/drivers/media/i2c/tvaudio.c
index e0634c8b7e0b..d76c53a8f027 100644
--- a/drivers/media/i2c/tvaudio.c
+++ b/drivers/media/i2c/tvaudio.c
@@ -38,7 +38,6 @@
38 38
39#include <media/tvaudio.h> 39#include <media/tvaudio.h>
40#include <media/v4l2-device.h> 40#include <media/v4l2-device.h>
41#include <media/v4l2-chip-ident.h>
42#include <media/v4l2-ctrls.h> 41#include <media/v4l2-ctrls.h>
43 42
44#include <media/i2c-addr.h> 43#include <media/i2c-addr.h>
@@ -1838,13 +1837,6 @@ static int tvaudio_s_frequency(struct v4l2_subdev *sd, const struct v4l2_frequen
1838 return 0; 1837 return 0;
1839} 1838}
1840 1839
1841static int tvaudio_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
1842{
1843 struct i2c_client *client = v4l2_get_subdevdata(sd);
1844
1845 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_TVAUDIO, 0);
1846}
1847
1848static int tvaudio_log_status(struct v4l2_subdev *sd) 1840static int tvaudio_log_status(struct v4l2_subdev *sd)
1849{ 1841{
1850 struct CHIPSTATE *chip = to_state(sd); 1842 struct CHIPSTATE *chip = to_state(sd);
@@ -1863,7 +1855,6 @@ static const struct v4l2_ctrl_ops tvaudio_ctrl_ops = {
1863 1855
1864static const struct v4l2_subdev_core_ops tvaudio_core_ops = { 1856static const struct v4l2_subdev_core_ops tvaudio_core_ops = {
1865 .log_status = tvaudio_log_status, 1857 .log_status = tvaudio_log_status,
1866 .g_chip_ident = tvaudio_g_chip_ident,
1867 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls, 1858 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls,
1868 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, 1859 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls,
1869 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls, 1860 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls,
@@ -1910,7 +1901,7 @@ static int tvaudio_probe(struct i2c_client *client, const struct i2c_device_id *
1910 printk("\n"); 1901 printk("\n");
1911 } 1902 }
1912 1903
1913 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 1904 chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
1914 if (!chip) 1905 if (!chip)
1915 return -ENOMEM; 1906 return -ENOMEM;
1916 sd = &chip->sd; 1907 sd = &chip->sd;
@@ -1930,7 +1921,6 @@ static int tvaudio_probe(struct i2c_client *client, const struct i2c_device_id *
1930 } 1921 }
1931 if (desc->name == NULL) { 1922 if (desc->name == NULL) {
1932 v4l2_dbg(1, debug, sd, "no matching chip description found\n"); 1923 v4l2_dbg(1, debug, sd, "no matching chip description found\n");
1933 kfree(chip);
1934 return -EIO; 1924 return -EIO;
1935 } 1925 }
1936 v4l2_info(sd, "%s found @ 0x%x (%s)\n", desc->name, client->addr<<1, client->adapter->name); 1926 v4l2_info(sd, "%s found @ 0x%x (%s)\n", desc->name, client->addr<<1, client->adapter->name);
@@ -2001,7 +1991,6 @@ static int tvaudio_probe(struct i2c_client *client, const struct i2c_device_id *
2001 int err = chip->hdl.error; 1991 int err = chip->hdl.error;
2002 1992
2003 v4l2_ctrl_handler_free(&chip->hdl); 1993 v4l2_ctrl_handler_free(&chip->hdl);
2004 kfree(chip);
2005 return err; 1994 return err;
2006 } 1995 }
2007 /* set controls to the default values */ 1996 /* set controls to the default values */
@@ -2044,7 +2033,6 @@ static int tvaudio_remove(struct i2c_client *client)
2044 2033
2045 v4l2_device_unregister_subdev(sd); 2034 v4l2_device_unregister_subdev(sd);
2046 v4l2_ctrl_handler_free(&chip->hdl); 2035 v4l2_ctrl_handler_free(&chip->hdl);
2047 kfree(chip);
2048 return 0; 2036 return 0;
2049} 2037}
2050 2038
diff --git a/drivers/media/i2c/tvp514x.c b/drivers/media/i2c/tvp514x.c
index ab8f3fee7e94..9c6d66a9868f 100644
--- a/drivers/media/i2c/tvp514x.c
+++ b/drivers/media/i2c/tvp514x.c
@@ -39,7 +39,7 @@
39#include <media/v4l2-device.h> 39#include <media/v4l2-device.h>
40#include <media/v4l2-common.h> 40#include <media/v4l2-common.h>
41#include <media/v4l2-mediabus.h> 41#include <media/v4l2-mediabus.h>
42#include <media/v4l2-chip-ident.h> 42#include <media/v4l2-of.h>
43#include <media/v4l2-ctrls.h> 43#include <media/v4l2-ctrls.h>
44#include <media/tvp514x.h> 44#include <media/tvp514x.h>
45#include <media/media-entity.h> 45#include <media/media-entity.h>
@@ -123,6 +123,8 @@ struct tvp514x_decoder {
123 /* mc related members */ 123 /* mc related members */
124 struct media_pad pad; 124 struct media_pad pad;
125 struct v4l2_mbus_framefmt format; 125 struct v4l2_mbus_framefmt format;
126
127 struct tvp514x_reg *int_seq;
126}; 128};
127 129
128/* TVP514x default register values */ 130/* TVP514x default register values */
@@ -543,8 +545,6 @@ static int tvp514x_querystd(struct v4l2_subdev *sd, v4l2_std_id *std_id)
543 if (std_id == NULL) 545 if (std_id == NULL)
544 return -EINVAL; 546 return -EINVAL;
545 547
546 *std_id = V4L2_STD_UNKNOWN;
547
548 /* To query the standard the TVP514x must power on the ADCs. */ 548 /* To query the standard the TVP514x must power on the ADCs. */
549 if (!decoder->streaming) { 549 if (!decoder->streaming) {
550 tvp514x_s_stream(sd, 1); 550 tvp514x_s_stream(sd, 1);
@@ -553,8 +553,10 @@ static int tvp514x_querystd(struct v4l2_subdev *sd, v4l2_std_id *std_id)
553 553
554 /* query the current standard */ 554 /* query the current standard */
555 current_std = tvp514x_query_current_std(sd); 555 current_std = tvp514x_query_current_std(sd);
556 if (current_std == STD_INVALID) 556 if (current_std == STD_INVALID) {
557 *std_id = V4L2_STD_UNKNOWN;
557 return 0; 558 return 0;
559 }
558 560
559 input_sel = decoder->input; 561 input_sel = decoder->input;
560 562
@@ -595,10 +597,12 @@ static int tvp514x_querystd(struct v4l2_subdev *sd, v4l2_std_id *std_id)
595 } 597 }
596 /* check whether signal is locked */ 598 /* check whether signal is locked */
597 sync_lock_status = tvp514x_read_reg(sd, REG_STATUS1); 599 sync_lock_status = tvp514x_read_reg(sd, REG_STATUS1);
598 if (lock_mask != (sync_lock_status & lock_mask)) 600 if (lock_mask != (sync_lock_status & lock_mask)) {
601 *std_id = V4L2_STD_UNKNOWN;
599 return 0; /* No input detected */ 602 return 0; /* No input detected */
603 }
600 604
601 *std_id = decoder->std_list[current_std].standard.id; 605 *std_id &= decoder->std_list[current_std].standard.id;
602 606
603 v4l2_dbg(1, debug, sd, "Current STD: %s\n", 607 v4l2_dbg(1, debug, sd, "Current STD: %s\n",
604 decoder->std_list[current_std].standard.name); 608 decoder->std_list[current_std].standard.name);
@@ -862,7 +866,6 @@ tvp514x_s_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *a)
862static int tvp514x_s_stream(struct v4l2_subdev *sd, int enable) 866static int tvp514x_s_stream(struct v4l2_subdev *sd, int enable)
863{ 867{
864 int err = 0; 868 int err = 0;
865 struct i2c_client *client = v4l2_get_subdevdata(sd);
866 struct tvp514x_decoder *decoder = to_decoder(sd); 869 struct tvp514x_decoder *decoder = to_decoder(sd);
867 870
868 if (decoder->streaming == enable) 871 if (decoder->streaming == enable)
@@ -882,11 +885,8 @@ static int tvp514x_s_stream(struct v4l2_subdev *sd, int enable)
882 } 885 }
883 case 1: 886 case 1:
884 { 887 {
885 struct tvp514x_reg *int_seq = (struct tvp514x_reg *)
886 client->driver->id_table->driver_data;
887
888 /* Power Up Sequence */ 888 /* Power Up Sequence */
889 err = tvp514x_write_regs(sd, int_seq); 889 err = tvp514x_write_regs(sd, decoder->int_seq);
890 if (err) { 890 if (err) {
891 v4l2_err(sd, "Unable to turn on decoder\n"); 891 v4l2_err(sd, "Unable to turn on decoder\n");
892 return err; 892 return err;
@@ -1055,6 +1055,42 @@ static struct tvp514x_decoder tvp514x_dev = {
1055 1055
1056}; 1056};
1057 1057
1058static struct tvp514x_platform_data *
1059tvp514x_get_pdata(struct i2c_client *client)
1060{
1061 struct tvp514x_platform_data *pdata;
1062 struct v4l2_of_endpoint bus_cfg;
1063 struct device_node *endpoint;
1064 unsigned int flags;
1065
1066 if (!IS_ENABLED(CONFIG_OF) || !client->dev.of_node)
1067 return client->dev.platform_data;
1068
1069 endpoint = v4l2_of_get_next_endpoint(client->dev.of_node, NULL);
1070 if (!endpoint)
1071 return NULL;
1072
1073 pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL);
1074 if (!pdata)
1075 goto done;
1076
1077 v4l2_of_parse_endpoint(endpoint, &bus_cfg);
1078 flags = bus_cfg.bus.parallel.flags;
1079
1080 if (flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH)
1081 pdata->hs_polarity = 1;
1082
1083 if (flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH)
1084 pdata->vs_polarity = 1;
1085
1086 if (flags & V4L2_MBUS_PCLK_SAMPLE_RISING)
1087 pdata->clk_polarity = 1;
1088
1089done:
1090 of_node_put(endpoint);
1091 return pdata;
1092}
1093
1058/** 1094/**
1059 * tvp514x_probe() - decoder driver i2c probe handler 1095 * tvp514x_probe() - decoder driver i2c probe handler
1060 * @client: i2c driver client device structure 1096 * @client: i2c driver client device structure
@@ -1066,19 +1102,20 @@ static struct tvp514x_decoder tvp514x_dev = {
1066static int 1102static int
1067tvp514x_probe(struct i2c_client *client, const struct i2c_device_id *id) 1103tvp514x_probe(struct i2c_client *client, const struct i2c_device_id *id)
1068{ 1104{
1105 struct tvp514x_platform_data *pdata = tvp514x_get_pdata(client);
1069 struct tvp514x_decoder *decoder; 1106 struct tvp514x_decoder *decoder;
1070 struct v4l2_subdev *sd; 1107 struct v4l2_subdev *sd;
1071 int ret; 1108 int ret;
1072 1109
1110 if (pdata == NULL) {
1111 dev_err(&client->dev, "No platform data\n");
1112 return -EINVAL;
1113 }
1114
1073 /* Check if the adapter supports the needed features */ 1115 /* Check if the adapter supports the needed features */
1074 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 1116 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
1075 return -EIO; 1117 return -EIO;
1076 1118
1077 if (!client->dev.platform_data) {
1078 v4l2_err(client, "No platform data!!\n");
1079 return -ENODEV;
1080 }
1081
1082 decoder = devm_kzalloc(&client->dev, sizeof(*decoder), GFP_KERNEL); 1119 decoder = devm_kzalloc(&client->dev, sizeof(*decoder), GFP_KERNEL);
1083 if (!decoder) 1120 if (!decoder)
1084 return -ENOMEM; 1121 return -ENOMEM;
@@ -1089,8 +1126,10 @@ tvp514x_probe(struct i2c_client *client, const struct i2c_device_id *id)
1089 memcpy(decoder->tvp514x_regs, tvp514x_reg_list_default, 1126 memcpy(decoder->tvp514x_regs, tvp514x_reg_list_default,
1090 sizeof(tvp514x_reg_list_default)); 1127 sizeof(tvp514x_reg_list_default));
1091 1128
1129 decoder->int_seq = (struct tvp514x_reg *)id->driver_data;
1130
1092 /* Copy board specific information here */ 1131 /* Copy board specific information here */
1093 decoder->pdata = client->dev.platform_data; 1132 decoder->pdata = pdata;
1094 1133
1095 /** 1134 /**
1096 * Fetch platform specific data, and configure the 1135 * Fetch platform specific data, and configure the
@@ -1109,7 +1148,6 @@ tvp514x_probe(struct i2c_client *client, const struct i2c_device_id *id)
1109 /* Register with V4L2 layer as slave device */ 1148 /* Register with V4L2 layer as slave device */
1110 sd = &decoder->sd; 1149 sd = &decoder->sd;
1111 v4l2_i2c_subdev_init(sd, client, &tvp514x_ops); 1150 v4l2_i2c_subdev_init(sd, client, &tvp514x_ops);
1112 strlcpy(sd->name, TVP514X_MODULE_NAME, sizeof(sd->name));
1113 1151
1114#if defined(CONFIG_MEDIA_CONTROLLER) 1152#if defined(CONFIG_MEDIA_CONTROLLER)
1115 decoder->pad.flags = MEDIA_PAD_FL_SOURCE; 1153 decoder->pad.flags = MEDIA_PAD_FL_SOURCE;
@@ -1120,7 +1158,6 @@ tvp514x_probe(struct i2c_client *client, const struct i2c_device_id *id)
1120 if (ret < 0) { 1158 if (ret < 0) {
1121 v4l2_err(sd, "%s decoder driver failed to register !!\n", 1159 v4l2_err(sd, "%s decoder driver failed to register !!\n",
1122 sd->name); 1160 sd->name);
1123 kfree(decoder);
1124 return ret; 1161 return ret;
1125 } 1162 }
1126#endif 1163#endif
@@ -1231,8 +1268,20 @@ static const struct i2c_device_id tvp514x_id[] = {
1231 1268
1232MODULE_DEVICE_TABLE(i2c, tvp514x_id); 1269MODULE_DEVICE_TABLE(i2c, tvp514x_id);
1233 1270
1271#if IS_ENABLED(CONFIG_OF)
1272static const struct of_device_id tvp514x_of_match[] = {
1273 { .compatible = "ti,tvp5146", },
1274 { .compatible = "ti,tvp5146m2", },
1275 { .compatible = "ti,tvp5147", },
1276 { .compatible = "ti,tvp5147m1", },
1277 { /* sentinel */ },
1278};
1279MODULE_DEVICE_TABLE(of, tvp514x_of_match);
1280#endif
1281
1234static struct i2c_driver tvp514x_driver = { 1282static struct i2c_driver tvp514x_driver = {
1235 .driver = { 1283 .driver = {
1284 .of_match_table = of_match_ptr(tvp514x_of_match),
1236 .owner = THIS_MODULE, 1285 .owner = THIS_MODULE,
1237 .name = TVP514X_MODULE_NAME, 1286 .name = TVP514X_MODULE_NAME,
1238 }, 1287 },
diff --git a/drivers/media/i2c/tvp5150.c b/drivers/media/i2c/tvp5150.c
index 485159a3c0b7..89c0b13463b7 100644
--- a/drivers/media/i2c/tvp5150.c
+++ b/drivers/media/i2c/tvp5150.c
@@ -12,7 +12,6 @@
12#include <linux/module.h> 12#include <linux/module.h>
13#include <media/v4l2-device.h> 13#include <media/v4l2-device.h>
14#include <media/tvp5150.h> 14#include <media/tvp5150.h>
15#include <media/v4l2-chip-ident.h>
16#include <media/v4l2-ctrls.h> 15#include <media/v4l2-ctrls.h>
17 16
18#include "tvp5150_reg.h" 17#include "tvp5150_reg.h"
@@ -727,13 +726,11 @@ static int tvp5150_set_std(struct v4l2_subdev *sd, v4l2_std_id std)
727 726
728 /* First tests should be against specific std */ 727 /* First tests should be against specific std */
729 728
730 if (std == V4L2_STD_ALL) { 729 if (std == V4L2_STD_NTSC_443) {
731 fmt = VIDEO_STD_AUTO_SWITCH_BIT; /* Autodetect mode */
732 } else if (std & V4L2_STD_NTSC_443) {
733 fmt = VIDEO_STD_NTSC_4_43_BIT; 730 fmt = VIDEO_STD_NTSC_4_43_BIT;
734 } else if (std & V4L2_STD_PAL_M) { 731 } else if (std == V4L2_STD_PAL_M) {
735 fmt = VIDEO_STD_PAL_M_BIT; 732 fmt = VIDEO_STD_PAL_M_BIT;
736 } else if (std & (V4L2_STD_PAL_N | V4L2_STD_PAL_Nc)) { 733 } else if (std == V4L2_STD_PAL_N || std == V4L2_STD_PAL_Nc) {
737 fmt = VIDEO_STD_PAL_COMBINATION_N_BIT; 734 fmt = VIDEO_STD_PAL_COMBINATION_N_BIT;
738 } else { 735 } else {
739 /* Then, test against generic ones */ 736 /* Then, test against generic ones */
@@ -1031,31 +1028,11 @@ static int tvp5150_g_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_f
1031 return 0; 1028 return 0;
1032} 1029}
1033 1030
1034static int tvp5150_g_chip_ident(struct v4l2_subdev *sd,
1035 struct v4l2_dbg_chip_ident *chip)
1036{
1037 int rev;
1038 struct i2c_client *client = v4l2_get_subdevdata(sd);
1039
1040 rev = tvp5150_read(sd, TVP5150_ROM_MAJOR_VER) << 8 |
1041 tvp5150_read(sd, TVP5150_ROM_MINOR_VER);
1042
1043 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_TVP5150,
1044 rev);
1045}
1046
1047
1048#ifdef CONFIG_VIDEO_ADV_DEBUG 1031#ifdef CONFIG_VIDEO_ADV_DEBUG
1049static int tvp5150_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 1032static int tvp5150_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
1050{ 1033{
1051 int res; 1034 int res;
1052 1035
1053 struct i2c_client *client = v4l2_get_subdevdata(sd);
1054
1055 if (!v4l2_chip_match_i2c_client(client, &reg->match))
1056 return -EINVAL;
1057 if (!capable(CAP_SYS_ADMIN))
1058 return -EPERM;
1059 res = tvp5150_read(sd, reg->reg & 0xff); 1036 res = tvp5150_read(sd, reg->reg & 0xff);
1060 if (res < 0) { 1037 if (res < 0) {
1061 v4l2_err(sd, "%s: failed with error = %d\n", __func__, res); 1038 v4l2_err(sd, "%s: failed with error = %d\n", __func__, res);
@@ -1069,12 +1046,6 @@ static int tvp5150_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *
1069 1046
1070static int tvp5150_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg) 1047static int tvp5150_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
1071{ 1048{
1072 struct i2c_client *client = v4l2_get_subdevdata(sd);
1073
1074 if (!v4l2_chip_match_i2c_client(client, &reg->match))
1075 return -EINVAL;
1076 if (!capable(CAP_SYS_ADMIN))
1077 return -EPERM;
1078 tvp5150_write(sd, reg->reg & 0xff, reg->val & 0xff); 1049 tvp5150_write(sd, reg->reg & 0xff, reg->val & 0xff);
1079 return 0; 1050 return 0;
1080} 1051}
@@ -1098,7 +1069,6 @@ static const struct v4l2_subdev_core_ops tvp5150_core_ops = {
1098 .log_status = tvp5150_log_status, 1069 .log_status = tvp5150_log_status,
1099 .s_std = tvp5150_s_std, 1070 .s_std = tvp5150_s_std,
1100 .reset = tvp5150_reset, 1071 .reset = tvp5150_reset,
1101 .g_chip_ident = tvp5150_g_chip_ident,
1102#ifdef CONFIG_VIDEO_ADV_DEBUG 1072#ifdef CONFIG_VIDEO_ADV_DEBUG
1103 .g_register = tvp5150_g_register, 1073 .g_register = tvp5150_g_register,
1104 .s_register = tvp5150_s_register, 1074 .s_register = tvp5150_s_register,
@@ -1152,10 +1122,9 @@ static int tvp5150_probe(struct i2c_client *c,
1152 I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) 1122 I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
1153 return -EIO; 1123 return -EIO;
1154 1124
1155 core = kzalloc(sizeof(struct tvp5150), GFP_KERNEL); 1125 core = devm_kzalloc(&c->dev, sizeof(*core), GFP_KERNEL);
1156 if (!core) { 1126 if (!core)
1157 return -ENOMEM; 1127 return -ENOMEM;
1158 }
1159 sd = &core->sd; 1128 sd = &core->sd;
1160 v4l2_i2c_subdev_init(sd, c, &tvp5150_ops); 1129 v4l2_i2c_subdev_init(sd, c, &tvp5150_ops);
1161 1130
@@ -1166,7 +1135,7 @@ static int tvp5150_probe(struct i2c_client *c,
1166 for (i = 0; i < 4; i++) { 1135 for (i = 0; i < 4; i++) {
1167 res = tvp5150_read(sd, TVP5150_MSB_DEV_ID + i); 1136 res = tvp5150_read(sd, TVP5150_MSB_DEV_ID + i);
1168 if (res < 0) 1137 if (res < 0)
1169 goto free_core; 1138 return res;
1170 tvp5150_id[i] = res; 1139 tvp5150_id[i] = res;
1171 } 1140 }
1172 1141
@@ -1209,7 +1178,7 @@ static int tvp5150_probe(struct i2c_client *c,
1209 if (core->hdl.error) { 1178 if (core->hdl.error) {
1210 res = core->hdl.error; 1179 res = core->hdl.error;
1211 v4l2_ctrl_handler_free(&core->hdl); 1180 v4l2_ctrl_handler_free(&core->hdl);
1212 goto free_core; 1181 return res;
1213 } 1182 }
1214 v4l2_ctrl_handler_setup(&core->hdl); 1183 v4l2_ctrl_handler_setup(&core->hdl);
1215 1184
@@ -1225,10 +1194,6 @@ static int tvp5150_probe(struct i2c_client *c,
1225 if (debug > 1) 1194 if (debug > 1)
1226 tvp5150_log_status(sd); 1195 tvp5150_log_status(sd);
1227 return 0; 1196 return 0;
1228
1229free_core:
1230 kfree(core);
1231 return res;
1232} 1197}
1233 1198
1234static int tvp5150_remove(struct i2c_client *c) 1199static int tvp5150_remove(struct i2c_client *c)
@@ -1242,7 +1207,6 @@ static int tvp5150_remove(struct i2c_client *c)
1242 1207
1243 v4l2_device_unregister_subdev(sd); 1208 v4l2_device_unregister_subdev(sd);
1244 v4l2_ctrl_handler_free(&decoder->hdl); 1209 v4l2_ctrl_handler_free(&decoder->hdl);
1245 kfree(to_tvp5150(sd));
1246 return 0; 1210 return 0;
1247} 1211}
1248 1212
diff --git a/drivers/media/i2c/tvp7002.c b/drivers/media/i2c/tvp7002.c
index 027809cca5f5..a4e49483de6a 100644
--- a/drivers/media/i2c/tvp7002.c
+++ b/drivers/media/i2c/tvp7002.c
@@ -32,7 +32,6 @@
32#include <linux/v4l2-dv-timings.h> 32#include <linux/v4l2-dv-timings.h>
33#include <media/tvp7002.h> 33#include <media/tvp7002.h>
34#include <media/v4l2-device.h> 34#include <media/v4l2-device.h>
35#include <media/v4l2-chip-ident.h>
36#include <media/v4l2-common.h> 35#include <media/v4l2-common.h>
37#include <media/v4l2-ctrls.h> 36#include <media/v4l2-ctrls.h>
38#include "tvp7002_reg.h" 37#include "tvp7002_reg.h"
@@ -41,9 +40,6 @@ MODULE_DESCRIPTION("TI TVP7002 Video and Graphics Digitizer driver");
41MODULE_AUTHOR("Santiago Nunez-Corrales <santiago.nunez@ridgerun.com>"); 40MODULE_AUTHOR("Santiago Nunez-Corrales <santiago.nunez@ridgerun.com>");
42MODULE_LICENSE("GPL"); 41MODULE_LICENSE("GPL");
43 42
44/* Module Name */
45#define TVP7002_MODULE_NAME "tvp7002"
46
47/* I2C retry attempts */ 43/* I2C retry attempts */
48#define I2C_RETRY_COUNT (5) 44#define I2C_RETRY_COUNT (5)
49 45
@@ -424,6 +420,7 @@ struct tvp7002 {
424 int streaming; 420 int streaming;
425 421
426 const struct tvp7002_timings_definition *current_timings; 422 const struct tvp7002_timings_definition *current_timings;
423 struct media_pad pad;
427}; 424};
428 425
429/* 426/*
@@ -535,29 +532,6 @@ static inline void tvp7002_write_err(struct v4l2_subdev *sd, u8 reg,
535} 532}
536 533
537/* 534/*
538 * tvp7002_g_chip_ident() - Get chip identification number
539 * @sd: ptr to v4l2_subdev struct
540 * @chip: ptr to v4l2_dbg_chip_ident struct
541 *
542 * Obtains the chip's identification number.
543 * Returns zero or -EINVAL if read operation fails.
544 */
545static int tvp7002_g_chip_ident(struct v4l2_subdev *sd,
546 struct v4l2_dbg_chip_ident *chip)
547{
548 u8 rev;
549 int error;
550 struct i2c_client *client = v4l2_get_subdevdata(sd);
551
552 error = tvp7002_read(sd, TVP7002_CHIP_REV, &rev);
553
554 if (error < 0)
555 return error;
556
557 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_TVP7002, rev);
558}
559
560/*
561 * tvp7002_write_inittab() - Write initialization values 535 * tvp7002_write_inittab() - Write initialization values
562 * @sd: ptr to v4l2_subdev struct 536 * @sd: ptr to v4l2_subdev struct
563 * @regs: ptr to i2c_reg_value struct 537 * @regs: ptr to i2c_reg_value struct
@@ -738,23 +712,17 @@ static int tvp7002_query_dv_timings(struct v4l2_subdev *sd,
738 * 712 *
739 * Get the value of a TVP7002 decoder device register. 713 * Get the value of a TVP7002 decoder device register.
740 * Returns zero when successful, -EINVAL if register read fails or 714 * Returns zero when successful, -EINVAL if register read fails or
741 * access to I2C client fails, -EPERM if the call is not allowed 715 * access to I2C client fails.
742 * by disabled CAP_SYS_ADMIN.
743 */ 716 */
744static int tvp7002_g_register(struct v4l2_subdev *sd, 717static int tvp7002_g_register(struct v4l2_subdev *sd,
745 struct v4l2_dbg_register *reg) 718 struct v4l2_dbg_register *reg)
746{ 719{
747 struct i2c_client *client = v4l2_get_subdevdata(sd);
748 u8 val; 720 u8 val;
749 int ret; 721 int ret;
750 722
751 if (!v4l2_chip_match_i2c_client(client, &reg->match))
752 return -EINVAL;
753 if (!capable(CAP_SYS_ADMIN))
754 return -EPERM;
755
756 ret = tvp7002_read(sd, reg->reg & 0xff, &val); 723 ret = tvp7002_read(sd, reg->reg & 0xff, &val);
757 reg->val = val; 724 reg->val = val;
725 reg->size = 1;
758 return ret; 726 return ret;
759} 727}
760 728
@@ -764,19 +732,11 @@ static int tvp7002_g_register(struct v4l2_subdev *sd,
764 * @reg: ptr to v4l2_dbg_register struct 732 * @reg: ptr to v4l2_dbg_register struct
765 * 733 *
766 * Get the value of a TVP7002 decoder device register. 734 * Get the value of a TVP7002 decoder device register.
767 * Returns zero when successful, -EINVAL if register read fails or 735 * Returns zero when successful, -EINVAL if register read fails.
768 * -EPERM if call not allowed.
769 */ 736 */
770static int tvp7002_s_register(struct v4l2_subdev *sd, 737static int tvp7002_s_register(struct v4l2_subdev *sd,
771 const struct v4l2_dbg_register *reg) 738 const struct v4l2_dbg_register *reg)
772{ 739{
773 struct i2c_client *client = v4l2_get_subdevdata(sd);
774
775 if (!v4l2_chip_match_i2c_client(client, &reg->match))
776 return -EINVAL;
777 if (!capable(CAP_SYS_ADMIN))
778 return -EPERM;
779
780 return tvp7002_write(sd, reg->reg & 0xff, reg->val & 0xff); 740 return tvp7002_write(sd, reg->reg & 0xff, reg->val & 0xff);
781} 741}
782#endif 742#endif
@@ -880,9 +840,67 @@ static const struct v4l2_ctrl_ops tvp7002_ctrl_ops = {
880 .s_ctrl = tvp7002_s_ctrl, 840 .s_ctrl = tvp7002_s_ctrl,
881}; 841};
882 842
843/*
844 * tvp7002_enum_mbus_code() - Enum supported digital video format on pad
845 * @sd: pointer to standard V4L2 sub-device structure
846 * @fh: file handle for the subdev
847 * @code: pointer to subdev enum mbus code struct
848 *
849 * Enumerate supported digital video formats for pad.
850 */
851static int
852tvp7002_enum_mbus_code(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
853 struct v4l2_subdev_mbus_code_enum *code)
854{
855 /* Check requested format index is within range */
856 if (code->index != 0)
857 return -EINVAL;
858
859 code->code = V4L2_MBUS_FMT_YUYV10_1X20;
860
861 return 0;
862}
863
864/*
865 * tvp7002_get_pad_format() - get video format on pad
866 * @sd: pointer to standard V4L2 sub-device structure
867 * @fh: file handle for the subdev
868 * @fmt: pointer to subdev format struct
869 *
870 * get video format for pad.
871 */
872static int
873tvp7002_get_pad_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
874 struct v4l2_subdev_format *fmt)
875{
876 struct tvp7002 *tvp7002 = to_tvp7002(sd);
877
878 fmt->format.code = V4L2_MBUS_FMT_YUYV10_1X20;
879 fmt->format.width = tvp7002->current_timings->timings.bt.width;
880 fmt->format.height = tvp7002->current_timings->timings.bt.height;
881 fmt->format.field = tvp7002->current_timings->scanmode;
882 fmt->format.colorspace = tvp7002->current_timings->color_space;
883
884 return 0;
885}
886
887/*
888 * tvp7002_set_pad_format() - set video format on pad
889 * @sd: pointer to standard V4L2 sub-device structure
890 * @fh: file handle for the subdev
891 * @fmt: pointer to subdev format struct
892 *
893 * set video format for pad.
894 */
895static int
896tvp7002_set_pad_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
897 struct v4l2_subdev_format *fmt)
898{
899 return tvp7002_get_pad_format(sd, fh, fmt);
900}
901
883/* V4L2 core operation handlers */ 902/* V4L2 core operation handlers */
884static const struct v4l2_subdev_core_ops tvp7002_core_ops = { 903static const struct v4l2_subdev_core_ops tvp7002_core_ops = {
885 .g_chip_ident = tvp7002_g_chip_ident,
886 .log_status = tvp7002_log_status, 904 .log_status = tvp7002_log_status,
887 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls, 905 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls,
888 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, 906 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls,
@@ -910,10 +928,18 @@ static const struct v4l2_subdev_video_ops tvp7002_video_ops = {
910 .enum_mbus_fmt = tvp7002_enum_mbus_fmt, 928 .enum_mbus_fmt = tvp7002_enum_mbus_fmt,
911}; 929};
912 930
931/* media pad related operation handlers */
932static const struct v4l2_subdev_pad_ops tvp7002_pad_ops = {
933 .enum_mbus_code = tvp7002_enum_mbus_code,
934 .get_fmt = tvp7002_get_pad_format,
935 .set_fmt = tvp7002_set_pad_format,
936};
937
913/* V4L2 top level operation handlers */ 938/* V4L2 top level operation handlers */
914static const struct v4l2_subdev_ops tvp7002_ops = { 939static const struct v4l2_subdev_ops tvp7002_ops = {
915 .core = &tvp7002_core_ops, 940 .core = &tvp7002_core_ops,
916 .video = &tvp7002_video_ops, 941 .video = &tvp7002_video_ops,
942 .pad = &tvp7002_pad_ops,
917}; 943};
918 944
919/* 945/*
@@ -993,19 +1019,34 @@ static int tvp7002_probe(struct i2c_client *c, const struct i2c_device_id *id)
993 timings = device->current_timings->timings; 1019 timings = device->current_timings->timings;
994 error = tvp7002_s_dv_timings(sd, &timings); 1020 error = tvp7002_s_dv_timings(sd, &timings);
995 1021
1022#if defined(CONFIG_MEDIA_CONTROLLER)
1023 device->pad.flags = MEDIA_PAD_FL_SOURCE;
1024 device->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
1025 device->sd.entity.flags |= MEDIA_ENT_T_V4L2_SUBDEV_DECODER;
1026
1027 error = media_entity_init(&device->sd.entity, 1, &device->pad, 0);
1028 if (error < 0)
1029 return error;
1030#endif
1031
996 v4l2_ctrl_handler_init(&device->hdl, 1); 1032 v4l2_ctrl_handler_init(&device->hdl, 1);
997 v4l2_ctrl_new_std(&device->hdl, &tvp7002_ctrl_ops, 1033 v4l2_ctrl_new_std(&device->hdl, &tvp7002_ctrl_ops,
998 V4L2_CID_GAIN, 0, 255, 1, 0); 1034 V4L2_CID_GAIN, 0, 255, 1, 0);
999 sd->ctrl_handler = &device->hdl; 1035 sd->ctrl_handler = &device->hdl;
1000 if (device->hdl.error) { 1036 if (device->hdl.error) {
1001 int err = device->hdl.error; 1037 error = device->hdl.error;
1002 1038 goto error;
1003 v4l2_ctrl_handler_free(&device->hdl);
1004 return err;
1005 } 1039 }
1006 v4l2_ctrl_handler_setup(&device->hdl); 1040 v4l2_ctrl_handler_setup(&device->hdl);
1007 1041
1008 return 0; 1042 return 0;
1043
1044error:
1045 v4l2_ctrl_handler_free(&device->hdl);
1046#if defined(CONFIG_MEDIA_CONTROLLER)
1047 media_entity_cleanup(&device->sd.entity);
1048#endif
1049 return error;
1009} 1050}
1010 1051
1011/* 1052/*
@@ -1022,7 +1063,9 @@ static int tvp7002_remove(struct i2c_client *c)
1022 1063
1023 v4l2_dbg(1, debug, sd, "Removing tvp7002 adapter" 1064 v4l2_dbg(1, debug, sd, "Removing tvp7002 adapter"
1024 "on address 0x%x\n", c->addr); 1065 "on address 0x%x\n", c->addr);
1025 1066#if defined(CONFIG_MEDIA_CONTROLLER)
1067 media_entity_cleanup(&device->sd.entity);
1068#endif
1026 v4l2_device_unregister_subdev(sd); 1069 v4l2_device_unregister_subdev(sd);
1027 v4l2_ctrl_handler_free(&device->hdl); 1070 v4l2_ctrl_handler_free(&device->hdl);
1028 return 0; 1071 return 0;
diff --git a/drivers/media/i2c/tw2804.c b/drivers/media/i2c/tw2804.c
index c5dc2c3bf2d7..f58607df6193 100644
--- a/drivers/media/i2c/tw2804.c
+++ b/drivers/media/i2c/tw2804.c
@@ -23,7 +23,6 @@
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <media/v4l2-subdev.h> 24#include <media/v4l2-subdev.h>
25#include <media/v4l2-device.h> 25#include <media/v4l2-device.h>
26#include <media/v4l2-chip-ident.h>
27#include <media/v4l2-ctrls.h> 26#include <media/v4l2-ctrls.h>
28 27
29#define TW2804_REG_AUTOGAIN 0x02 28#define TW2804_REG_AUTOGAIN 0x02
@@ -368,8 +367,7 @@ static int tw2804_probe(struct i2c_client *client,
368 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 367 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
369 return -ENODEV; 368 return -ENODEV;
370 369
371 state = kzalloc(sizeof(struct tw2804), GFP_KERNEL); 370 state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL);
372
373 if (state == NULL) 371 if (state == NULL)
374 return -ENOMEM; 372 return -ENOMEM;
375 sd = &state->sd; 373 sd = &state->sd;
@@ -410,7 +408,6 @@ static int tw2804_probe(struct i2c_client *client,
410 err = state->hdl.error; 408 err = state->hdl.error;
411 if (err) { 409 if (err) {
412 v4l2_ctrl_handler_free(&state->hdl); 410 v4l2_ctrl_handler_free(&state->hdl);
413 kfree(state);
414 return err; 411 return err;
415 } 412 }
416 413
@@ -427,7 +424,6 @@ static int tw2804_remove(struct i2c_client *client)
427 424
428 v4l2_device_unregister_subdev(sd); 425 v4l2_device_unregister_subdev(sd);
429 v4l2_ctrl_handler_free(&state->hdl); 426 v4l2_ctrl_handler_free(&state->hdl);
430 kfree(state);
431 return 0; 427 return 0;
432} 428}
433 429
diff --git a/drivers/media/i2c/tw9903.c b/drivers/media/i2c/tw9903.c
index 87880b19d8c3..285b759a5f7f 100644
--- a/drivers/media/i2c/tw9903.c
+++ b/drivers/media/i2c/tw9903.c
@@ -215,7 +215,7 @@ static int tw9903_probe(struct i2c_client *client,
215 v4l_info(client, "chip found @ 0x%02x (%s)\n", 215 v4l_info(client, "chip found @ 0x%02x (%s)\n",
216 client->addr << 1, client->adapter->name); 216 client->addr << 1, client->adapter->name);
217 217
218 dec = kzalloc(sizeof(struct tw9903), GFP_KERNEL); 218 dec = devm_kzalloc(&client->dev, sizeof(*dec), GFP_KERNEL);
219 if (dec == NULL) 219 if (dec == NULL)
220 return -ENOMEM; 220 return -ENOMEM;
221 sd = &dec->sd; 221 sd = &dec->sd;
@@ -233,7 +233,6 @@ static int tw9903_probe(struct i2c_client *client,
233 int err = hdl->error; 233 int err = hdl->error;
234 234
235 v4l2_ctrl_handler_free(hdl); 235 v4l2_ctrl_handler_free(hdl);
236 kfree(dec);
237 return err; 236 return err;
238 } 237 }
239 238
@@ -242,7 +241,6 @@ static int tw9903_probe(struct i2c_client *client,
242 241
243 if (write_regs(sd, initial_registers) < 0) { 242 if (write_regs(sd, initial_registers) < 0) {
244 v4l2_err(client, "error initializing TW9903\n"); 243 v4l2_err(client, "error initializing TW9903\n");
245 kfree(dec);
246 return -EINVAL; 244 return -EINVAL;
247 } 245 }
248 246
@@ -255,7 +253,6 @@ static int tw9903_remove(struct i2c_client *client)
255 253
256 v4l2_device_unregister_subdev(sd); 254 v4l2_device_unregister_subdev(sd);
257 v4l2_ctrl_handler_free(&to_state(sd)->hdl); 255 v4l2_ctrl_handler_free(&to_state(sd)->hdl);
258 kfree(to_state(sd));
259 return 0; 256 return 0;
260} 257}
261 258
diff --git a/drivers/media/i2c/tw9906.c b/drivers/media/i2c/tw9906.c
index accd79e5a7fd..f6bef25bd9ce 100644
--- a/drivers/media/i2c/tw9906.c
+++ b/drivers/media/i2c/tw9906.c
@@ -183,7 +183,7 @@ static int tw9906_probe(struct i2c_client *client,
183 v4l_info(client, "chip found @ 0x%02x (%s)\n", 183 v4l_info(client, "chip found @ 0x%02x (%s)\n",
184 client->addr << 1, client->adapter->name); 184 client->addr << 1, client->adapter->name);
185 185
186 dec = kzalloc(sizeof(struct tw9906), GFP_KERNEL); 186 dec = devm_kzalloc(&client->dev, sizeof(*dec), GFP_KERNEL);
187 if (dec == NULL) 187 if (dec == NULL)
188 return -ENOMEM; 188 return -ENOMEM;
189 sd = &dec->sd; 189 sd = &dec->sd;
@@ -201,7 +201,6 @@ static int tw9906_probe(struct i2c_client *client,
201 int err = hdl->error; 201 int err = hdl->error;
202 202
203 v4l2_ctrl_handler_free(hdl); 203 v4l2_ctrl_handler_free(hdl);
204 kfree(dec);
205 return err; 204 return err;
206 } 205 }
207 206
@@ -210,7 +209,6 @@ static int tw9906_probe(struct i2c_client *client,
210 209
211 if (write_regs(sd, initial_registers) < 0) { 210 if (write_regs(sd, initial_registers) < 0) {
212 v4l2_err(client, "error initializing TW9906\n"); 211 v4l2_err(client, "error initializing TW9906\n");
213 kfree(dec);
214 return -EINVAL; 212 return -EINVAL;
215 } 213 }
216 214
@@ -223,7 +221,6 @@ static int tw9906_remove(struct i2c_client *client)
223 221
224 v4l2_device_unregister_subdev(sd); 222 v4l2_device_unregister_subdev(sd);
225 v4l2_ctrl_handler_free(&to_state(sd)->hdl); 223 v4l2_ctrl_handler_free(&to_state(sd)->hdl);
226 kfree(to_state(sd));
227 return 0; 224 return 0;
228} 225}
229 226
diff --git a/drivers/media/i2c/uda1342.c b/drivers/media/i2c/uda1342.c
index 3af408556d27..081786d176d0 100644
--- a/drivers/media/i2c/uda1342.c
+++ b/drivers/media/i2c/uda1342.c
@@ -69,7 +69,7 @@ static int uda1342_probe(struct i2c_client *client,
69 dev_dbg(&client->dev, "initializing UDA1342 at address %d on %s\n", 69 dev_dbg(&client->dev, "initializing UDA1342 at address %d on %s\n",
70 client->addr, adapter->name); 70 client->addr, adapter->name);
71 71
72 sd = kzalloc(sizeof(struct v4l2_subdev), GFP_KERNEL); 72 sd = devm_kzalloc(&client->dev, sizeof(*sd), GFP_KERNEL);
73 if (sd == NULL) 73 if (sd == NULL)
74 return -ENOMEM; 74 return -ENOMEM;
75 75
@@ -89,7 +89,6 @@ static int uda1342_remove(struct i2c_client *client)
89 struct v4l2_subdev *sd = i2c_get_clientdata(client); 89 struct v4l2_subdev *sd = i2c_get_clientdata(client);
90 90
91 v4l2_device_unregister_subdev(sd); 91 v4l2_device_unregister_subdev(sd);
92 kfree(sd);
93 return 0; 92 return 0;
94} 93}
95 94
diff --git a/drivers/media/i2c/upd64031a.c b/drivers/media/i2c/upd64031a.c
index f0a09214c519..d248e6a12b8e 100644
--- a/drivers/media/i2c/upd64031a.c
+++ b/drivers/media/i2c/upd64031a.c
@@ -27,7 +27,6 @@
27#include <linux/videodev2.h> 27#include <linux/videodev2.h>
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <media/v4l2-device.h> 29#include <media/v4l2-device.h>
30#include <media/v4l2-chip-ident.h>
31#include <media/upd64031a.h> 30#include <media/upd64031a.h>
32 31
33/* --------------------- read registers functions define -------------------- */ 32/* --------------------- read registers functions define -------------------- */
@@ -147,13 +146,6 @@ static int upd64031a_s_routing(struct v4l2_subdev *sd,
147 return upd64031a_s_frequency(sd, NULL); 146 return upd64031a_s_frequency(sd, NULL);
148} 147}
149 148
150static int upd64031a_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
151{
152 struct i2c_client *client = v4l2_get_subdevdata(sd);
153
154 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_UPD64031A, 0);
155}
156
157static int upd64031a_log_status(struct v4l2_subdev *sd) 149static int upd64031a_log_status(struct v4l2_subdev *sd)
158{ 150{
159 v4l2_info(sd, "Status: SA00=0x%02x SA01=0x%02x\n", 151 v4l2_info(sd, "Status: SA00=0x%02x SA01=0x%02x\n",
@@ -164,12 +156,6 @@ static int upd64031a_log_status(struct v4l2_subdev *sd)
164#ifdef CONFIG_VIDEO_ADV_DEBUG 156#ifdef CONFIG_VIDEO_ADV_DEBUG
165static int upd64031a_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 157static int upd64031a_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
166{ 158{
167 struct i2c_client *client = v4l2_get_subdevdata(sd);
168
169 if (!v4l2_chip_match_i2c_client(client, &reg->match))
170 return -EINVAL;
171 if (!capable(CAP_SYS_ADMIN))
172 return -EPERM;
173 reg->val = upd64031a_read(sd, reg->reg & 0xff); 159 reg->val = upd64031a_read(sd, reg->reg & 0xff);
174 reg->size = 1; 160 reg->size = 1;
175 return 0; 161 return 0;
@@ -177,12 +163,6 @@ static int upd64031a_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register
177 163
178static int upd64031a_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg) 164static int upd64031a_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
179{ 165{
180 struct i2c_client *client = v4l2_get_subdevdata(sd);
181
182 if (!v4l2_chip_match_i2c_client(client, &reg->match))
183 return -EINVAL;
184 if (!capable(CAP_SYS_ADMIN))
185 return -EPERM;
186 upd64031a_write(sd, reg->reg & 0xff, reg->val & 0xff); 166 upd64031a_write(sd, reg->reg & 0xff, reg->val & 0xff);
187 return 0; 167 return 0;
188} 168}
@@ -192,7 +172,6 @@ static int upd64031a_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_re
192 172
193static const struct v4l2_subdev_core_ops upd64031a_core_ops = { 173static const struct v4l2_subdev_core_ops upd64031a_core_ops = {
194 .log_status = upd64031a_log_status, 174 .log_status = upd64031a_log_status,
195 .g_chip_ident = upd64031a_g_chip_ident,
196#ifdef CONFIG_VIDEO_ADV_DEBUG 175#ifdef CONFIG_VIDEO_ADV_DEBUG
197 .g_register = upd64031a_g_register, 176 .g_register = upd64031a_g_register,
198 .s_register = upd64031a_s_register, 177 .s_register = upd64031a_s_register,
@@ -230,7 +209,7 @@ static int upd64031a_probe(struct i2c_client *client,
230 v4l_info(client, "chip found @ 0x%x (%s)\n", 209 v4l_info(client, "chip found @ 0x%x (%s)\n",
231 client->addr << 1, client->adapter->name); 210 client->addr << 1, client->adapter->name);
232 211
233 state = kzalloc(sizeof(struct upd64031a_state), GFP_KERNEL); 212 state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL);
234 if (state == NULL) 213 if (state == NULL)
235 return -ENOMEM; 214 return -ENOMEM;
236 sd = &state->sd; 215 sd = &state->sd;
@@ -249,7 +228,6 @@ static int upd64031a_remove(struct i2c_client *client)
249 struct v4l2_subdev *sd = i2c_get_clientdata(client); 228 struct v4l2_subdev *sd = i2c_get_clientdata(client);
250 229
251 v4l2_device_unregister_subdev(sd); 230 v4l2_device_unregister_subdev(sd);
252 kfree(to_state(sd));
253 return 0; 231 return 0;
254} 232}
255 233
diff --git a/drivers/media/i2c/upd64083.c b/drivers/media/i2c/upd64083.c
index 343e0215f74c..3a152ce7258a 100644
--- a/drivers/media/i2c/upd64083.c
+++ b/drivers/media/i2c/upd64083.c
@@ -27,7 +27,6 @@
27#include <linux/videodev2.h> 27#include <linux/videodev2.h>
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <media/v4l2-device.h> 29#include <media/v4l2-device.h>
30#include <media/v4l2-chip-ident.h>
31#include <media/upd64083.h> 30#include <media/upd64083.h>
32 31
33MODULE_DESCRIPTION("uPD64083 driver"); 32MODULE_DESCRIPTION("uPD64083 driver");
@@ -122,12 +121,6 @@ static int upd64083_s_routing(struct v4l2_subdev *sd,
122#ifdef CONFIG_VIDEO_ADV_DEBUG 121#ifdef CONFIG_VIDEO_ADV_DEBUG
123static int upd64083_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 122static int upd64083_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
124{ 123{
125 struct i2c_client *client = v4l2_get_subdevdata(sd);
126
127 if (!v4l2_chip_match_i2c_client(client, &reg->match))
128 return -EINVAL;
129 if (!capable(CAP_SYS_ADMIN))
130 return -EPERM;
131 reg->val = upd64083_read(sd, reg->reg & 0xff); 124 reg->val = upd64083_read(sd, reg->reg & 0xff);
132 reg->size = 1; 125 reg->size = 1;
133 return 0; 126 return 0;
@@ -135,24 +128,11 @@ static int upd64083_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register
135 128
136static int upd64083_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg) 129static int upd64083_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
137{ 130{
138 struct i2c_client *client = v4l2_get_subdevdata(sd);
139
140 if (!v4l2_chip_match_i2c_client(client, &reg->match))
141 return -EINVAL;
142 if (!capable(CAP_SYS_ADMIN))
143 return -EPERM;
144 upd64083_write(sd, reg->reg & 0xff, reg->val & 0xff); 131 upd64083_write(sd, reg->reg & 0xff, reg->val & 0xff);
145 return 0; 132 return 0;
146} 133}
147#endif 134#endif
148 135
149static int upd64083_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
150{
151 struct i2c_client *client = v4l2_get_subdevdata(sd);
152
153 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_UPD64083, 0);
154}
155
156static int upd64083_log_status(struct v4l2_subdev *sd) 136static int upd64083_log_status(struct v4l2_subdev *sd)
157{ 137{
158 struct i2c_client *client = v4l2_get_subdevdata(sd); 138 struct i2c_client *client = v4l2_get_subdevdata(sd);
@@ -169,7 +149,6 @@ static int upd64083_log_status(struct v4l2_subdev *sd)
169 149
170static const struct v4l2_subdev_core_ops upd64083_core_ops = { 150static const struct v4l2_subdev_core_ops upd64083_core_ops = {
171 .log_status = upd64083_log_status, 151 .log_status = upd64083_log_status,
172 .g_chip_ident = upd64083_g_chip_ident,
173#ifdef CONFIG_VIDEO_ADV_DEBUG 152#ifdef CONFIG_VIDEO_ADV_DEBUG
174 .g_register = upd64083_g_register, 153 .g_register = upd64083_g_register,
175 .s_register = upd64083_s_register, 154 .s_register = upd64083_s_register,
@@ -202,7 +181,7 @@ static int upd64083_probe(struct i2c_client *client,
202 v4l_info(client, "chip found @ 0x%x (%s)\n", 181 v4l_info(client, "chip found @ 0x%x (%s)\n",
203 client->addr << 1, client->adapter->name); 182 client->addr << 1, client->adapter->name);
204 183
205 state = kzalloc(sizeof(struct upd64083_state), GFP_KERNEL); 184 state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL);
206 if (state == NULL) 185 if (state == NULL)
207 return -ENOMEM; 186 return -ENOMEM;
208 sd = &state->sd; 187 sd = &state->sd;
@@ -221,7 +200,6 @@ static int upd64083_remove(struct i2c_client *client)
221 struct v4l2_subdev *sd = i2c_get_clientdata(client); 200 struct v4l2_subdev *sd = i2c_get_clientdata(client);
222 201
223 v4l2_device_unregister_subdev(sd); 202 v4l2_device_unregister_subdev(sd);
224 kfree(to_state(sd));
225 return 0; 203 return 0;
226} 204}
227 205
diff --git a/drivers/media/i2c/vp27smpx.c b/drivers/media/i2c/vp27smpx.c
index e71f139695af..6a3a3ff7ee6a 100644
--- a/drivers/media/i2c/vp27smpx.c
+++ b/drivers/media/i2c/vp27smpx.c
@@ -29,7 +29,6 @@
29#include <linux/i2c.h> 29#include <linux/i2c.h>
30#include <linux/videodev2.h> 30#include <linux/videodev2.h>
31#include <media/v4l2-device.h> 31#include <media/v4l2-device.h>
32#include <media/v4l2-chip-ident.h>
33 32
34MODULE_DESCRIPTION("vp27smpx driver"); 33MODULE_DESCRIPTION("vp27smpx driver");
35MODULE_AUTHOR("Hans Verkuil"); 34MODULE_AUTHOR("Hans Verkuil");
@@ -112,13 +111,6 @@ static int vp27smpx_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
112 return 0; 111 return 0;
113} 112}
114 113
115static int vp27smpx_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
116{
117 struct i2c_client *client = v4l2_get_subdevdata(sd);
118
119 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_VP27SMPX, 0);
120}
121
122static int vp27smpx_log_status(struct v4l2_subdev *sd) 114static int vp27smpx_log_status(struct v4l2_subdev *sd)
123{ 115{
124 struct vp27smpx_state *state = to_state(sd); 116 struct vp27smpx_state *state = to_state(sd);
@@ -132,7 +124,6 @@ static int vp27smpx_log_status(struct v4l2_subdev *sd)
132 124
133static const struct v4l2_subdev_core_ops vp27smpx_core_ops = { 125static const struct v4l2_subdev_core_ops vp27smpx_core_ops = {
134 .log_status = vp27smpx_log_status, 126 .log_status = vp27smpx_log_status,
135 .g_chip_ident = vp27smpx_g_chip_ident,
136 .s_std = vp27smpx_s_std, 127 .s_std = vp27smpx_s_std,
137}; 128};
138 129
@@ -169,7 +160,7 @@ static int vp27smpx_probe(struct i2c_client *client,
169 v4l_info(client, "chip found @ 0x%x (%s)\n", 160 v4l_info(client, "chip found @ 0x%x (%s)\n",
170 client->addr << 1, client->adapter->name); 161 client->addr << 1, client->adapter->name);
171 162
172 state = kzalloc(sizeof(struct vp27smpx_state), GFP_KERNEL); 163 state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL);
173 if (state == NULL) 164 if (state == NULL)
174 return -ENOMEM; 165 return -ENOMEM;
175 sd = &state->sd; 166 sd = &state->sd;
@@ -186,7 +177,6 @@ static int vp27smpx_remove(struct i2c_client *client)
186 struct v4l2_subdev *sd = i2c_get_clientdata(client); 177 struct v4l2_subdev *sd = i2c_get_clientdata(client);
187 178
188 v4l2_device_unregister_subdev(sd); 179 v4l2_device_unregister_subdev(sd);
189 kfree(to_state(sd));
190 return 0; 180 return 0;
191} 181}
192 182
diff --git a/drivers/media/i2c/vpx3220.c b/drivers/media/i2c/vpx3220.c
index 2f67b4c5c823..ece90df6a043 100644
--- a/drivers/media/i2c/vpx3220.c
+++ b/drivers/media/i2c/vpx3220.c
@@ -27,7 +27,6 @@
27#include <linux/i2c.h> 27#include <linux/i2c.h>
28#include <linux/videodev2.h> 28#include <linux/videodev2.h>
29#include <media/v4l2-device.h> 29#include <media/v4l2-device.h>
30#include <media/v4l2-chip-ident.h>
31#include <media/v4l2-ctrls.h> 30#include <media/v4l2-ctrls.h>
32 31
33MODULE_DESCRIPTION("vpx3220a/vpx3216b/vpx3214c video decoder driver"); 32MODULE_DESCRIPTION("vpx3220a/vpx3216b/vpx3214c video decoder driver");
@@ -49,7 +48,6 @@ struct vpx3220 {
49 unsigned char reg[255]; 48 unsigned char reg[255];
50 49
51 v4l2_std_id norm; 50 v4l2_std_id norm;
52 int ident;
53 int input; 51 int input;
54 int enable; 52 int enable;
55}; 53};
@@ -297,7 +295,7 @@ static int vpx3220_init(struct v4l2_subdev *sd, u32 val)
297static int vpx3220_status(struct v4l2_subdev *sd, u32 *pstatus, v4l2_std_id *pstd) 295static int vpx3220_status(struct v4l2_subdev *sd, u32 *pstatus, v4l2_std_id *pstd)
298{ 296{
299 int res = V4L2_IN_ST_NO_SIGNAL, status; 297 int res = V4L2_IN_ST_NO_SIGNAL, status;
300 v4l2_std_id std = 0; 298 v4l2_std_id std = pstd ? *pstd : V4L2_STD_ALL;
301 299
302 status = vpx3220_fp_read(sd, 0x0f3); 300 status = vpx3220_fp_read(sd, 0x0f3);
303 301
@@ -314,19 +312,21 @@ static int vpx3220_status(struct v4l2_subdev *sd, u32 *pstatus, v4l2_std_id *pst
314 case 0x10: 312 case 0x10:
315 case 0x14: 313 case 0x14:
316 case 0x18: 314 case 0x18:
317 std = V4L2_STD_PAL; 315 std &= V4L2_STD_PAL;
318 break; 316 break;
319 317
320 case 0x08: 318 case 0x08:
321 std = V4L2_STD_SECAM; 319 std &= V4L2_STD_SECAM;
322 break; 320 break;
323 321
324 case 0x04: 322 case 0x04:
325 case 0x0c: 323 case 0x0c:
326 case 0x1c: 324 case 0x1c:
327 std = V4L2_STD_NTSC; 325 std &= V4L2_STD_NTSC;
328 break; 326 break;
329 } 327 }
328 } else {
329 std = V4L2_STD_UNKNOWN;
330 } 330 }
331 if (pstd) 331 if (pstd)
332 *pstd = std; 332 *pstd = std;
@@ -442,14 +442,6 @@ static int vpx3220_s_ctrl(struct v4l2_ctrl *ctrl)
442 return -EINVAL; 442 return -EINVAL;
443} 443}
444 444
445static int vpx3220_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
446{
447 struct vpx3220 *decoder = to_vpx3220(sd);
448 struct i2c_client *client = v4l2_get_subdevdata(sd);
449
450 return v4l2_chip_ident_i2c_client(client, chip, decoder->ident, 0);
451}
452
453/* ----------------------------------------------------------------------- */ 445/* ----------------------------------------------------------------------- */
454 446
455static const struct v4l2_ctrl_ops vpx3220_ctrl_ops = { 447static const struct v4l2_ctrl_ops vpx3220_ctrl_ops = {
@@ -457,7 +449,6 @@ static const struct v4l2_ctrl_ops vpx3220_ctrl_ops = {
457}; 449};
458 450
459static const struct v4l2_subdev_core_ops vpx3220_core_ops = { 451static const struct v4l2_subdev_core_ops vpx3220_core_ops = {
460 .g_chip_ident = vpx3220_g_chip_ident,
461 .init = vpx3220_init, 452 .init = vpx3220_init,
462 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls, 453 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls,
463 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, 454 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls,
@@ -499,7 +490,7 @@ static int vpx3220_probe(struct i2c_client *client,
499 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA)) 490 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA))
500 return -ENODEV; 491 return -ENODEV;
501 492
502 decoder = kzalloc(sizeof(struct vpx3220), GFP_KERNEL); 493 decoder = devm_kzalloc(&client->dev, sizeof(*decoder), GFP_KERNEL);
503 if (decoder == NULL) 494 if (decoder == NULL)
504 return -ENOMEM; 495 return -ENOMEM;
505 sd = &decoder->sd; 496 sd = &decoder->sd;
@@ -521,7 +512,6 @@ static int vpx3220_probe(struct i2c_client *client,
521 int err = decoder->hdl.error; 512 int err = decoder->hdl.error;
522 513
523 v4l2_ctrl_handler_free(&decoder->hdl); 514 v4l2_ctrl_handler_free(&decoder->hdl);
524 kfree(decoder);
525 return err; 515 return err;
526 } 516 }
527 v4l2_ctrl_handler_setup(&decoder->hdl); 517 v4l2_ctrl_handler_setup(&decoder->hdl);
@@ -529,7 +519,6 @@ static int vpx3220_probe(struct i2c_client *client,
529 ver = i2c_smbus_read_byte_data(client, 0x00); 519 ver = i2c_smbus_read_byte_data(client, 0x00);
530 pn = (i2c_smbus_read_byte_data(client, 0x02) << 8) + 520 pn = (i2c_smbus_read_byte_data(client, 0x02) << 8) +
531 i2c_smbus_read_byte_data(client, 0x01); 521 i2c_smbus_read_byte_data(client, 0x01);
532 decoder->ident = V4L2_IDENT_VPX3220A;
533 if (ver == 0xec) { 522 if (ver == 0xec) {
534 switch (pn) { 523 switch (pn) {
535 case 0x4680: 524 case 0x4680:
@@ -537,11 +526,9 @@ static int vpx3220_probe(struct i2c_client *client,
537 break; 526 break;
538 case 0x4260: 527 case 0x4260:
539 name = "vpx3216b"; 528 name = "vpx3216b";
540 decoder->ident = V4L2_IDENT_VPX3216B;
541 break; 529 break;
542 case 0x4280: 530 case 0x4280:
543 name = "vpx3214c"; 531 name = "vpx3214c";
544 decoder->ident = V4L2_IDENT_VPX3214C;
545 break; 532 break;
546 } 533 }
547 } 534 }
@@ -566,7 +553,7 @@ static int vpx3220_remove(struct i2c_client *client)
566 553
567 v4l2_device_unregister_subdev(sd); 554 v4l2_device_unregister_subdev(sd);
568 v4l2_ctrl_handler_free(&decoder->hdl); 555 v4l2_ctrl_handler_free(&decoder->hdl);
569 kfree(decoder); 556
570 return 0; 557 return 0;
571} 558}
572 559
diff --git a/drivers/media/i2c/vs6624.c b/drivers/media/i2c/vs6624.c
index f366fad6269e..25bdd9312fea 100644
--- a/drivers/media/i2c/vs6624.c
+++ b/drivers/media/i2c/vs6624.c
@@ -27,7 +27,6 @@
27#include <linux/types.h> 27#include <linux/types.h>
28#include <linux/videodev2.h> 28#include <linux/videodev2.h>
29 29
30#include <media/v4l2-chip-ident.h>
31#include <media/v4l2-ctrls.h> 30#include <media/v4l2-ctrls.h>
32#include <media/v4l2-device.h> 31#include <media/v4l2-device.h>
33#include <media/v4l2-mediabus.h> 32#include <media/v4l2-mediabus.h>
@@ -722,27 +721,9 @@ static int vs6624_s_stream(struct v4l2_subdev *sd, int enable)
722 return 0; 721 return 0;
723} 722}
724 723
725static int vs6624_g_chip_ident(struct v4l2_subdev *sd,
726 struct v4l2_dbg_chip_ident *chip)
727{
728 int rev;
729 struct i2c_client *client = v4l2_get_subdevdata(sd);
730
731 rev = (vs6624_read(sd, VS6624_FW_VSN_MAJOR) << 8)
732 | vs6624_read(sd, VS6624_FW_VSN_MINOR);
733
734 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_VS6624, rev);
735}
736
737#ifdef CONFIG_VIDEO_ADV_DEBUG 724#ifdef CONFIG_VIDEO_ADV_DEBUG
738static int vs6624_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 725static int vs6624_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
739{ 726{
740 struct i2c_client *client = v4l2_get_subdevdata(sd);
741
742 if (!v4l2_chip_match_i2c_client(client, &reg->match))
743 return -EINVAL;
744 if (!capable(CAP_SYS_ADMIN))
745 return -EPERM;
746 reg->val = vs6624_read(sd, reg->reg & 0xffff); 727 reg->val = vs6624_read(sd, reg->reg & 0xffff);
747 reg->size = 1; 728 reg->size = 1;
748 return 0; 729 return 0;
@@ -750,12 +731,6 @@ static int vs6624_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *r
750 731
751static int vs6624_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg) 732static int vs6624_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
752{ 733{
753 struct i2c_client *client = v4l2_get_subdevdata(sd);
754
755 if (!v4l2_chip_match_i2c_client(client, &reg->match))
756 return -EINVAL;
757 if (!capable(CAP_SYS_ADMIN))
758 return -EPERM;
759 vs6624_write(sd, reg->reg & 0xffff, reg->val & 0xff); 734 vs6624_write(sd, reg->reg & 0xffff, reg->val & 0xff);
760 return 0; 735 return 0;
761} 736}
@@ -766,7 +741,6 @@ static const struct v4l2_ctrl_ops vs6624_ctrl_ops = {
766}; 741};
767 742
768static const struct v4l2_subdev_core_ops vs6624_core_ops = { 743static const struct v4l2_subdev_core_ops vs6624_core_ops = {
769 .g_chip_ident = vs6624_g_chip_ident,
770#ifdef CONFIG_VIDEO_ADV_DEBUG 744#ifdef CONFIG_VIDEO_ADV_DEBUG
771 .g_register = vs6624_g_register, 745 .g_register = vs6624_g_register,
772 .s_register = vs6624_s_register, 746 .s_register = vs6624_s_register,
@@ -805,20 +779,18 @@ static int vs6624_probe(struct i2c_client *client,
805 if (ce == NULL) 779 if (ce == NULL)
806 return -EINVAL; 780 return -EINVAL;
807 781
808 ret = gpio_request(*ce, "VS6624 Chip Enable"); 782 ret = devm_gpio_request_one(&client->dev, *ce, GPIOF_OUT_INIT_HIGH,
783 "VS6624 Chip Enable");
809 if (ret) { 784 if (ret) {
810 v4l_err(client, "failed to request GPIO %d\n", *ce); 785 v4l_err(client, "failed to request GPIO %d\n", *ce);
811 return ret; 786 return ret;
812 } 787 }
813 gpio_direction_output(*ce, 1);
814 /* wait 100ms before any further i2c writes are performed */ 788 /* wait 100ms before any further i2c writes are performed */
815 mdelay(100); 789 mdelay(100);
816 790
817 sensor = kzalloc(sizeof(*sensor), GFP_KERNEL); 791 sensor = devm_kzalloc(&client->dev, sizeof(*sensor), GFP_KERNEL);
818 if (sensor == NULL) { 792 if (sensor == NULL)
819 gpio_free(*ce);
820 return -ENOMEM; 793 return -ENOMEM;
821 }
822 794
823 sd = &sensor->sd; 795 sd = &sensor->sd;
824 v4l2_i2c_subdev_init(sd, client, &vs6624_ops); 796 v4l2_i2c_subdev_init(sd, client, &vs6624_ops);
@@ -866,30 +838,22 @@ static int vs6624_probe(struct i2c_client *client,
866 int err = hdl->error; 838 int err = hdl->error;
867 839
868 v4l2_ctrl_handler_free(hdl); 840 v4l2_ctrl_handler_free(hdl);
869 kfree(sensor);
870 gpio_free(*ce);
871 return err; 841 return err;
872 } 842 }
873 843
874 /* initialize the hardware to the default control values */ 844 /* initialize the hardware to the default control values */
875 ret = v4l2_ctrl_handler_setup(hdl); 845 ret = v4l2_ctrl_handler_setup(hdl);
876 if (ret) { 846 if (ret)
877 v4l2_ctrl_handler_free(hdl); 847 v4l2_ctrl_handler_free(hdl);
878 kfree(sensor);
879 gpio_free(*ce);
880 }
881 return ret; 848 return ret;
882} 849}
883 850
884static int vs6624_remove(struct i2c_client *client) 851static int vs6624_remove(struct i2c_client *client)
885{ 852{
886 struct v4l2_subdev *sd = i2c_get_clientdata(client); 853 struct v4l2_subdev *sd = i2c_get_clientdata(client);
887 struct vs6624 *sensor = to_vs6624(sd);
888 854
889 v4l2_device_unregister_subdev(sd); 855 v4l2_device_unregister_subdev(sd);
890 v4l2_ctrl_handler_free(sd->ctrl_handler); 856 v4l2_ctrl_handler_free(sd->ctrl_handler);
891 gpio_free(sensor->ce_pin);
892 kfree(sensor);
893 return 0; 857 return 0;
894} 858}
895 859
diff --git a/drivers/media/i2c/wm8739.c b/drivers/media/i2c/wm8739.c
index 3bb99e93febe..3be73f6a40e9 100644
--- a/drivers/media/i2c/wm8739.c
+++ b/drivers/media/i2c/wm8739.c
@@ -29,7 +29,6 @@
29#include <linux/i2c.h> 29#include <linux/i2c.h>
30#include <linux/videodev2.h> 30#include <linux/videodev2.h>
31#include <media/v4l2-device.h> 31#include <media/v4l2-device.h>
32#include <media/v4l2-chip-ident.h>
33#include <media/v4l2-ctrls.h> 32#include <media/v4l2-ctrls.h>
34 33
35MODULE_DESCRIPTION("wm8739 driver"); 34MODULE_DESCRIPTION("wm8739 driver");
@@ -160,13 +159,6 @@ static int wm8739_s_clock_freq(struct v4l2_subdev *sd, u32 audiofreq)
160 return 0; 159 return 0;
161} 160}
162 161
163static int wm8739_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
164{
165 struct i2c_client *client = v4l2_get_subdevdata(sd);
166
167 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_WM8739, 0);
168}
169
170static int wm8739_log_status(struct v4l2_subdev *sd) 162static int wm8739_log_status(struct v4l2_subdev *sd)
171{ 163{
172 struct wm8739_state *state = to_state(sd); 164 struct wm8739_state *state = to_state(sd);
@@ -184,7 +176,6 @@ static const struct v4l2_ctrl_ops wm8739_ctrl_ops = {
184 176
185static const struct v4l2_subdev_core_ops wm8739_core_ops = { 177static const struct v4l2_subdev_core_ops wm8739_core_ops = {
186 .log_status = wm8739_log_status, 178 .log_status = wm8739_log_status,
187 .g_chip_ident = wm8739_g_chip_ident,
188 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls, 179 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls,
189 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, 180 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls,
190 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls, 181 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls,
@@ -220,7 +211,7 @@ static int wm8739_probe(struct i2c_client *client,
220 v4l_info(client, "chip found @ 0x%x (%s)\n", 211 v4l_info(client, "chip found @ 0x%x (%s)\n",
221 client->addr << 1, client->adapter->name); 212 client->addr << 1, client->adapter->name);
222 213
223 state = kzalloc(sizeof(struct wm8739_state), GFP_KERNEL); 214 state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL);
224 if (state == NULL) 215 if (state == NULL)
225 return -ENOMEM; 216 return -ENOMEM;
226 sd = &state->sd; 217 sd = &state->sd;
@@ -237,7 +228,6 @@ static int wm8739_probe(struct i2c_client *client,
237 int err = state->hdl.error; 228 int err = state->hdl.error;
238 229
239 v4l2_ctrl_handler_free(&state->hdl); 230 v4l2_ctrl_handler_free(&state->hdl);
240 kfree(state);
241 return err; 231 return err;
242 } 232 }
243 v4l2_ctrl_cluster(3, &state->volume); 233 v4l2_ctrl_cluster(3, &state->volume);
@@ -271,7 +261,6 @@ static int wm8739_remove(struct i2c_client *client)
271 261
272 v4l2_device_unregister_subdev(sd); 262 v4l2_device_unregister_subdev(sd);
273 v4l2_ctrl_handler_free(&state->hdl); 263 v4l2_ctrl_handler_free(&state->hdl);
274 kfree(to_state(sd));
275 return 0; 264 return 0;
276} 265}
277 266
diff --git a/drivers/media/i2c/wm8775.c b/drivers/media/i2c/wm8775.c
index 27c27b4ae238..3f584a7d0781 100644
--- a/drivers/media/i2c/wm8775.c
+++ b/drivers/media/i2c/wm8775.c
@@ -33,7 +33,6 @@
33#include <linux/i2c.h> 33#include <linux/i2c.h>
34#include <linux/videodev2.h> 34#include <linux/videodev2.h>
35#include <media/v4l2-device.h> 35#include <media/v4l2-device.h>
36#include <media/v4l2-chip-ident.h>
37#include <media/v4l2-ctrls.h> 36#include <media/v4l2-ctrls.h>
38#include <media/wm8775.h> 37#include <media/wm8775.h>
39 38
@@ -158,13 +157,6 @@ static int wm8775_s_ctrl(struct v4l2_ctrl *ctrl)
158 return -EINVAL; 157 return -EINVAL;
159} 158}
160 159
161static int wm8775_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
162{
163 struct i2c_client *client = v4l2_get_subdevdata(sd);
164
165 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_WM8775, 0);
166}
167
168static int wm8775_log_status(struct v4l2_subdev *sd) 160static int wm8775_log_status(struct v4l2_subdev *sd)
169{ 161{
170 struct wm8775_state *state = to_state(sd); 162 struct wm8775_state *state = to_state(sd);
@@ -188,7 +180,6 @@ static const struct v4l2_ctrl_ops wm8775_ctrl_ops = {
188 180
189static const struct v4l2_subdev_core_ops wm8775_core_ops = { 181static const struct v4l2_subdev_core_ops wm8775_core_ops = {
190 .log_status = wm8775_log_status, 182 .log_status = wm8775_log_status,
191 .g_chip_ident = wm8775_g_chip_ident,
192 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls, 183 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls,
193 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, 184 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls,
194 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls, 185 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls,
@@ -241,7 +232,7 @@ static int wm8775_probe(struct i2c_client *client,
241 v4l_info(client, "chip found @ 0x%02x (%s)\n", 232 v4l_info(client, "chip found @ 0x%02x (%s)\n",
242 client->addr << 1, client->adapter->name); 233 client->addr << 1, client->adapter->name);
243 234
244 state = kzalloc(sizeof(struct wm8775_state), GFP_KERNEL); 235 state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL);
245 if (state == NULL) 236 if (state == NULL)
246 return -ENOMEM; 237 return -ENOMEM;
247 sd = &state->sd; 238 sd = &state->sd;
@@ -261,7 +252,6 @@ static int wm8775_probe(struct i2c_client *client,
261 err = state->hdl.error; 252 err = state->hdl.error;
262 if (err) { 253 if (err) {
263 v4l2_ctrl_handler_free(&state->hdl); 254 v4l2_ctrl_handler_free(&state->hdl);
264 kfree(state);
265 return err; 255 return err;
266 } 256 }
267 257
@@ -319,7 +309,6 @@ static int wm8775_remove(struct i2c_client *client)
319 309
320 v4l2_device_unregister_subdev(sd); 310 v4l2_device_unregister_subdev(sd);
321 v4l2_ctrl_handler_free(&state->hdl); 311 v4l2_ctrl_handler_free(&state->hdl);
322 kfree(state);
323 return 0; 312 return 0;
324} 313}
325 314
diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 1957c0df08fd..d5a7a135f75d 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -142,6 +142,8 @@ static long __media_device_enum_links(struct media_device *mdev,
142 142
143 for (p = 0; p < entity->num_pads; p++) { 143 for (p = 0; p < entity->num_pads; p++) {
144 struct media_pad_desc pad; 144 struct media_pad_desc pad;
145
146 memset(&pad, 0, sizeof(pad));
145 media_device_kpad_to_upad(&entity->pads[p], &pad); 147 media_device_kpad_to_upad(&entity->pads[p], &pad);
146 if (copy_to_user(&links->pads[p], &pad, sizeof(pad))) 148 if (copy_to_user(&links->pads[p], &pad, sizeof(pad)))
147 return -EFAULT; 149 return -EFAULT;
@@ -159,6 +161,7 @@ static long __media_device_enum_links(struct media_device *mdev,
159 if (entity->links[l].source->entity != entity) 161 if (entity->links[l].source->entity != entity)
160 continue; 162 continue;
161 163
164 memset(&link, 0, sizeof(link));
162 media_device_kpad_to_upad(entity->links[l].source, 165 media_device_kpad_to_upad(entity->links[l].source,
163 &link.source); 166 &link.source);
164 media_device_kpad_to_upad(entity->links[l].sink, 167 media_device_kpad_to_upad(entity->links[l].sink,
diff --git a/drivers/media/media-entity.c b/drivers/media/media-entity.c
index e1cd13283407..cb30ffbd5ba8 100644
--- a/drivers/media/media-entity.c
+++ b/drivers/media/media-entity.c
@@ -429,6 +429,56 @@ media_entity_create_link(struct media_entity *source, u16 source_pad,
429} 429}
430EXPORT_SYMBOL_GPL(media_entity_create_link); 430EXPORT_SYMBOL_GPL(media_entity_create_link);
431 431
432void __media_entity_remove_links(struct media_entity *entity)
433{
434 unsigned int i;
435
436 for (i = 0; i < entity->num_links; i++) {
437 struct media_link *link = &entity->links[i];
438 struct media_entity *remote;
439 unsigned int r = 0;
440
441 if (link->source->entity == entity)
442 remote = link->sink->entity;
443 else
444 remote = link->source->entity;
445
446 while (r < remote->num_links) {
447 struct media_link *rlink = &remote->links[r];
448
449 if (rlink != link->reverse) {
450 r++;
451 continue;
452 }
453
454 if (link->source->entity == entity)
455 remote->num_backlinks--;
456
457 if (--remote->num_links == 0)
458 break;
459
460 /* Insert last entry in place of the dropped link. */
461 *rlink = remote->links[remote->num_links];
462 }
463 }
464
465 entity->num_links = 0;
466 entity->num_backlinks = 0;
467}
468EXPORT_SYMBOL_GPL(__media_entity_remove_links);
469
470void media_entity_remove_links(struct media_entity *entity)
471{
472 /* Do nothing if the entity is not registered. */
473 if (entity->parent == NULL)
474 return;
475
476 mutex_lock(&entity->parent->graph_mutex);
477 __media_entity_remove_links(entity);
478 mutex_unlock(&entity->parent->graph_mutex);
479}
480EXPORT_SYMBOL_GPL(media_entity_remove_links);
481
432static int __media_entity_setup_link_notify(struct media_link *link, u32 flags) 482static int __media_entity_setup_link_notify(struct media_link *link, u32 flags)
433{ 483{
434 int ret; 484 int ret;
@@ -496,25 +546,17 @@ int __media_entity_setup_link(struct media_link *link, u32 flags)
496 546
497 mdev = source->parent; 547 mdev = source->parent;
498 548
499 if ((flags & MEDIA_LNK_FL_ENABLED) && mdev->link_notify) { 549 if (mdev->link_notify) {
500 ret = mdev->link_notify(link->source, link->sink, 550 ret = mdev->link_notify(link, flags,
501 MEDIA_LNK_FL_ENABLED); 551 MEDIA_DEV_NOTIFY_PRE_LINK_CH);
502 if (ret < 0) 552 if (ret < 0)
503 return ret; 553 return ret;
504 } 554 }
505 555
506 ret = __media_entity_setup_link_notify(link, flags); 556 ret = __media_entity_setup_link_notify(link, flags);
507 if (ret < 0)
508 goto err;
509
510 if (!(flags & MEDIA_LNK_FL_ENABLED) && mdev->link_notify)
511 mdev->link_notify(link->source, link->sink, 0);
512
513 return 0;
514 557
515err: 558 if (mdev->link_notify)
516 if ((flags & MEDIA_LNK_FL_ENABLED) && mdev->link_notify) 559 mdev->link_notify(link, flags, MEDIA_DEV_NOTIFY_POST_LINK_CH);
517 mdev->link_notify(link->source, link->sink, 0);
518 560
519 return ret; 561 return ret;
520} 562}
@@ -560,17 +602,16 @@ media_entity_find_link(struct media_pad *source, struct media_pad *sink)
560EXPORT_SYMBOL_GPL(media_entity_find_link); 602EXPORT_SYMBOL_GPL(media_entity_find_link);
561 603
562/** 604/**
563 * media_entity_remote_source - Find the source pad at the remote end of a link 605 * media_entity_remote_pad - Find the pad at the remote end of a link
564 * @pad: Sink pad at the local end of the link 606 * @pad: Pad at the local end of the link
565 * 607 *
566 * Search for a remote source pad connected to the given sink pad by iterating 608 * Search for a remote pad connected to the given pad by iterating over all
567 * over all links originating or terminating at that pad until an enabled link 609 * links originating or terminating at that pad until an enabled link is found.
568 * is found.
569 * 610 *
570 * Return a pointer to the pad at the remote end of the first found enabled 611 * Return a pointer to the pad at the remote end of the first found enabled
571 * link, or NULL if no enabled link has been found. 612 * link, or NULL if no enabled link has been found.
572 */ 613 */
573struct media_pad *media_entity_remote_source(struct media_pad *pad) 614struct media_pad *media_entity_remote_pad(struct media_pad *pad)
574{ 615{
575 unsigned int i; 616 unsigned int i;
576 617
@@ -590,4 +631,4 @@ struct media_pad *media_entity_remote_source(struct media_pad *pad)
590 return NULL; 631 return NULL;
591 632
592} 633}
593EXPORT_SYMBOL_GPL(media_entity_remote_source); 634EXPORT_SYMBOL_GPL(media_entity_remote_pad);
diff --git a/drivers/media/parport/bw-qcam.c b/drivers/media/parport/bw-qcam.c
index 06231b85e1a9..d12bd33f39cb 100644
--- a/drivers/media/parport/bw-qcam.c
+++ b/drivers/media/parport/bw-qcam.c
@@ -687,6 +687,7 @@ static int buffer_finish(struct vb2_buffer *vb)
687 687
688 parport_release(qcam->pdev); 688 parport_release(qcam->pdev);
689 mutex_unlock(&qcam->lock); 689 mutex_unlock(&qcam->lock);
690 v4l2_get_timestamp(&vb->v4l2_buf.timestamp);
690 if (len != size) 691 if (len != size)
691 vb->state = VB2_BUF_STATE_ERROR; 692 vb->state = VB2_BUF_STATE_ERROR;
692 vb2_set_plane_payload(vb, 0, len); 693 vb2_set_plane_payload(vb, 0, len);
@@ -964,6 +965,7 @@ static struct qcam *qcam_init(struct parport *port)
964 q->drv_priv = qcam; 965 q->drv_priv = qcam;
965 q->ops = &qcam_video_qops; 966 q->ops = &qcam_video_qops;
966 q->mem_ops = &vb2_vmalloc_memops; 967 q->mem_ops = &vb2_vmalloc_memops;
968 q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
967 err = vb2_queue_init(q); 969 err = vb2_queue_init(q);
968 if (err < 0) { 970 if (err < 0) {
969 v4l2_err(v4l2_dev, "couldn't init vb2_queue for %s.\n", port->name); 971 v4l2_err(v4l2_dev, "couldn't init vb2_queue for %s.\n", port->name);
diff --git a/drivers/media/pci/Kconfig b/drivers/media/pci/Kconfig
index d4e2ed3f27e5..53196f1366f3 100644
--- a/drivers/media/pci/Kconfig
+++ b/drivers/media/pci/Kconfig
@@ -1,6 +1,7 @@
1if PCI && MEDIA_SUPPORT
2
1menuconfig MEDIA_PCI_SUPPORT 3menuconfig MEDIA_PCI_SUPPORT
2 bool "Media PCI Adapters" 4 bool "Media PCI Adapters"
3 depends on PCI && MEDIA_SUPPORT
4 help 5 help
5 Enable media drivers for PCI/PCIe bus. 6 Enable media drivers for PCI/PCIe bus.
6 If you have such devices, say Y. 7 If you have such devices, say Y.
@@ -45,3 +46,4 @@ source "drivers/media/pci/ddbridge/Kconfig"
45endif 46endif
46 47
47endif #MEDIA_PCI_SUPPORT 48endif #MEDIA_PCI_SUPPORT
49endif #PCI
diff --git a/drivers/media/pci/b2c2/flexcop-pci.c b/drivers/media/pci/b2c2/flexcop-pci.c
index 44f8fb5f17ff..447afbd904a4 100644
--- a/drivers/media/pci/b2c2/flexcop-pci.c
+++ b/drivers/media/pci/b2c2/flexcop-pci.c
@@ -432,18 +432,7 @@ static struct pci_driver flexcop_pci_driver = {
432 .remove = flexcop_pci_remove, 432 .remove = flexcop_pci_remove,
433}; 433};
434 434
435static int __init flexcop_pci_module_init(void) 435module_pci_driver(flexcop_pci_driver);
436{
437 return pci_register_driver(&flexcop_pci_driver);
438}
439
440static void __exit flexcop_pci_module_exit(void)
441{
442 pci_unregister_driver(&flexcop_pci_driver);
443}
444
445module_init(flexcop_pci_module_init);
446module_exit(flexcop_pci_module_exit);
447 436
448MODULE_AUTHOR(DRIVER_AUTHOR); 437MODULE_AUTHOR(DRIVER_AUTHOR);
449MODULE_DESCRIPTION(DRIVER_NAME); 438MODULE_DESCRIPTION(DRIVER_NAME);
diff --git a/drivers/media/pci/bt8xx/bttv-cards.c b/drivers/media/pci/bt8xx/bttv-cards.c
index b7dc921e1b91..e564aac0aa30 100644
--- a/drivers/media/pci/bt8xx/bttv-cards.c
+++ b/drivers/media/pci/bt8xx/bttv-cards.c
@@ -131,7 +131,7 @@ MODULE_PARM_DESC(vsfx,"set VSFX pci config bit "
131 "[yet another chipset flaw workaround]"); 131 "[yet another chipset flaw workaround]");
132MODULE_PARM_DESC(latency,"pci latency timer"); 132MODULE_PARM_DESC(latency,"pci latency timer");
133MODULE_PARM_DESC(card,"specify TV/grabber card model, see CARDLIST file for a list"); 133MODULE_PARM_DESC(card,"specify TV/grabber card model, see CARDLIST file for a list");
134MODULE_PARM_DESC(pll,"specify installed crystal (0=none, 28=28 MHz, 35=35 MHz)"); 134MODULE_PARM_DESC(pll, "specify installed crystal (0=none, 28=28 MHz, 35=35 MHz, 14=14 MHz)");
135MODULE_PARM_DESC(tuner,"specify installed tuner type"); 135MODULE_PARM_DESC(tuner,"specify installed tuner type");
136MODULE_PARM_DESC(autoload, "obsolete option, please do not use anymore"); 136MODULE_PARM_DESC(autoload, "obsolete option, please do not use anymore");
137MODULE_PARM_DESC(audiodev, "specify audio device:\n" 137MODULE_PARM_DESC(audiodev, "specify audio device:\n"
@@ -2705,7 +2705,7 @@ struct tvcard bttv_tvcards[] = {
2705 .has_radio = 1, 2705 .has_radio = 1,
2706 .has_remote = 1, 2706 .has_remote = 1,
2707 }, 2707 },
2708 [BTTV_BOARD_VD012] = { 2708 [BTTV_BOARD_VD012] = {
2709 /* D.Heer@Phytec.de */ 2709 /* D.Heer@Phytec.de */
2710 .name = "PHYTEC VD-012 (bt878)", 2710 .name = "PHYTEC VD-012 (bt878)",
2711 .video_inputs = 4, 2711 .video_inputs = 4,
@@ -2718,7 +2718,7 @@ struct tvcard bttv_tvcards[] = {
2718 .tuner_type = TUNER_ABSENT, 2718 .tuner_type = TUNER_ABSENT,
2719 .tuner_addr = ADDR_UNSET, 2719 .tuner_addr = ADDR_UNSET,
2720 }, 2720 },
2721 [BTTV_BOARD_VD012_X1] = { 2721 [BTTV_BOARD_VD012_X1] = {
2722 /* D.Heer@Phytec.de */ 2722 /* D.Heer@Phytec.de */
2723 .name = "PHYTEC VD-012-X1 (bt878)", 2723 .name = "PHYTEC VD-012-X1 (bt878)",
2724 .video_inputs = 4, 2724 .video_inputs = 4,
@@ -2731,7 +2731,7 @@ struct tvcard bttv_tvcards[] = {
2731 .tuner_type = TUNER_ABSENT, 2731 .tuner_type = TUNER_ABSENT,
2732 .tuner_addr = ADDR_UNSET, 2732 .tuner_addr = ADDR_UNSET,
2733 }, 2733 },
2734 [BTTV_BOARD_VD012_X2] = { 2734 [BTTV_BOARD_VD012_X2] = {
2735 /* D.Heer@Phytec.de */ 2735 /* D.Heer@Phytec.de */
2736 .name = "PHYTEC VD-012-X2 (bt878)", 2736 .name = "PHYTEC VD-012-X2 (bt878)",
2737 .video_inputs = 4, 2737 .video_inputs = 4,
@@ -2744,7 +2744,7 @@ struct tvcard bttv_tvcards[] = {
2744 .tuner_type = TUNER_ABSENT, 2744 .tuner_type = TUNER_ABSENT,
2745 .tuner_addr = ADDR_UNSET, 2745 .tuner_addr = ADDR_UNSET,
2746 }, 2746 },
2747 [BTTV_BOARD_GEOVISION_GV800S] = { 2747 [BTTV_BOARD_GEOVISION_GV800S] = {
2748 /* Bruno Christo <bchristo@inf.ufsm.br> 2748 /* Bruno Christo <bchristo@inf.ufsm.br>
2749 * 2749 *
2750 * GeoVision GV-800(S) has 4 Conexant Fusion 878A: 2750 * GeoVision GV-800(S) has 4 Conexant Fusion 878A:
@@ -2771,7 +2771,7 @@ struct tvcard bttv_tvcards[] = {
2771 .no_tda7432 = 1, 2771 .no_tda7432 = 1,
2772 .muxsel_hook = gv800s_muxsel, 2772 .muxsel_hook = gv800s_muxsel,
2773 }, 2773 },
2774 [BTTV_BOARD_GEOVISION_GV800S_SL] = { 2774 [BTTV_BOARD_GEOVISION_GV800S_SL] = {
2775 /* Bruno Christo <bchristo@inf.ufsm.br> 2775 /* Bruno Christo <bchristo@inf.ufsm.br>
2776 * 2776 *
2777 * GeoVision GV-800(S) has 4 Conexant Fusion 878A: 2777 * GeoVision GV-800(S) has 4 Conexant Fusion 878A:
@@ -2808,6 +2808,7 @@ struct tvcard bttv_tvcards[] = {
2808 .tuner_type = TUNER_ABSENT, 2808 .tuner_type = TUNER_ABSENT,
2809 .tuner_addr = ADDR_UNSET, 2809 .tuner_addr = ADDR_UNSET,
2810 }, 2810 },
2811 /* ---- card 0xa0---------------------------------- */
2811 [BTTV_BOARD_TVT_TD3116] = { 2812 [BTTV_BOARD_TVT_TD3116] = {
2812 .name = "Tongwei Video Technology TD-3116", 2813 .name = "Tongwei Video Technology TD-3116",
2813 .video_inputs = 16, 2814 .video_inputs = 16,
@@ -2825,6 +2826,35 @@ struct tvcard bttv_tvcards[] = {
2825 .muxsel = MUXSEL(2, 3, 1, 0), 2826 .muxsel = MUXSEL(2, 3, 1, 0),
2826 .tuner_type = TUNER_ABSENT, 2827 .tuner_type = TUNER_ABSENT,
2827 }, 2828 },
2829 [BTTV_BOARD_ADLINK_MPG24] = {
2830 /* Adlink MPG24 */
2831 .name = "Adlink MPG24",
2832 .video_inputs = 1,
2833 /* .audio_inputs= 1, */
2834 .svhs = NO_SVHS,
2835 .muxsel = MUXSEL(2, 2, 2, 2),
2836 .tuner_type = UNSET,
2837 .tuner_addr = ADDR_UNSET,
2838 .pll = PLL_28,
2839 },
2840 [BTTV_BOARD_BT848_CAP_14] = {
2841 .name = "Bt848 Capture 14MHz",
2842 .video_inputs = 4,
2843 .svhs = 2,
2844 .muxsel = MUXSEL(2, 3, 1, 0),
2845 .pll = PLL_14,
2846 .tuner_type = TUNER_ABSENT,
2847 },
2848 [BTTV_BOARD_CYBERVISION_CV06] = {
2849 .name = "CyberVision CV06 (SV)",
2850 .video_inputs = 4,
2851 /* .audio_inputs= 0, */
2852 .svhs = NO_SVHS,
2853 .muxsel = MUXSEL(2, 3, 1, 0),
2854 .pll = PLL_28,
2855 .tuner_type = TUNER_ABSENT,
2856 .tuner_addr = ADDR_UNSET,
2857 },
2828 2858
2829}; 2859};
2830 2860
@@ -3390,6 +3420,10 @@ void bttv_init_card2(struct bttv *btv)
3390 btv->pll.pll_ifreq=35468950; 3420 btv->pll.pll_ifreq=35468950;
3391 btv->pll.pll_crystal=BT848_IFORM_XT1; 3421 btv->pll.pll_crystal=BT848_IFORM_XT1;
3392 } 3422 }
3423 if (PLL_14 == bttv_tvcards[btv->c.type].pll) {
3424 btv->pll.pll_ifreq = 14318181;
3425 btv->pll.pll_crystal = BT848_IFORM_XT0;
3426 }
3393 /* insmod options can override */ 3427 /* insmod options can override */
3394 switch (pll[btv->c.nr]) { 3428 switch (pll[btv->c.nr]) {
3395 case 0: /* none */ 3429 case 0: /* none */
@@ -3409,6 +3443,12 @@ void bttv_init_card2(struct bttv *btv)
3409 btv->pll.pll_ofreq = 0; 3443 btv->pll.pll_ofreq = 0;
3410 btv->pll.pll_crystal = BT848_IFORM_XT1; 3444 btv->pll.pll_crystal = BT848_IFORM_XT1;
3411 break; 3445 break;
3446 case 3: /* 14 MHz */
3447 case 14:
3448 btv->pll.pll_ifreq = 14318181;
3449 btv->pll.pll_ofreq = 0;
3450 btv->pll.pll_crystal = BT848_IFORM_XT0;
3451 break;
3412 } 3452 }
3413 } 3453 }
3414 btv->pll.pll_current = -1; 3454 btv->pll.pll_current = -1;
diff --git a/drivers/media/pci/bt8xx/bttv-driver.c b/drivers/media/pci/bt8xx/bttv-driver.c
index e7d088413411..c6532de0eac7 100644
--- a/drivers/media/pci/bt8xx/bttv-driver.c
+++ b/drivers/media/pci/bt8xx/bttv-driver.c
@@ -50,7 +50,6 @@
50#include <media/v4l2-common.h> 50#include <media/v4l2-common.h>
51#include <media/v4l2-ioctl.h> 51#include <media/v4l2-ioctl.h>
52#include <media/v4l2-event.h> 52#include <media/v4l2-event.h>
53#include <media/v4l2-chip-ident.h>
54#include <media/tvaudio.h> 53#include <media/tvaudio.h>
55#include <media/msp3400.h> 54#include <media/msp3400.h>
56 55
@@ -1761,9 +1760,9 @@ static int bttv_querystd(struct file *file, void *f, v4l2_std_id *id)
1761 struct bttv *btv = fh->btv; 1760 struct bttv *btv = fh->btv;
1762 1761
1763 if (btread(BT848_DSTATUS) & BT848_DSTATUS_NUML) 1762 if (btread(BT848_DSTATUS) & BT848_DSTATUS_NUML)
1764 *id = V4L2_STD_625_50; 1763 *id &= V4L2_STD_625_50;
1765 else 1764 else
1766 *id = V4L2_STD_525_60; 1765 *id &= V4L2_STD_525_60;
1767 return 0; 1766 return 0;
1768} 1767}
1769 1768
@@ -1907,28 +1906,6 @@ static int bttv_log_status(struct file *file, void *f)
1907 return 0; 1906 return 0;
1908} 1907}
1909 1908
1910static int bttv_g_chip_ident(struct file *file, void *f, struct v4l2_dbg_chip_ident *chip)
1911{
1912 struct bttv_fh *fh = f;
1913 struct bttv *btv = fh->btv;
1914
1915 chip->ident = V4L2_IDENT_NONE;
1916 chip->revision = 0;
1917 if (chip->match.type == V4L2_CHIP_MATCH_HOST) {
1918 if (v4l2_chip_match_host(&chip->match)) {
1919 chip->ident = btv->id;
1920 if (chip->ident == PCI_DEVICE_ID_FUSION879)
1921 chip->ident = V4L2_IDENT_BT879;
1922 }
1923 return 0;
1924 }
1925 if (chip->match.type != V4L2_CHIP_MATCH_I2C_DRIVER &&
1926 chip->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
1927 return -EINVAL;
1928 /* TODO: is this correct? */
1929 return bttv_call_all_err(btv, core, g_chip_ident, chip);
1930}
1931
1932#ifdef CONFIG_VIDEO_ADV_DEBUG 1909#ifdef CONFIG_VIDEO_ADV_DEBUG
1933static int bttv_g_register(struct file *file, void *f, 1910static int bttv_g_register(struct file *file, void *f,
1934 struct v4l2_dbg_register *reg) 1911 struct v4l2_dbg_register *reg)
@@ -1936,16 +1913,6 @@ static int bttv_g_register(struct file *file, void *f,
1936 struct bttv_fh *fh = f; 1913 struct bttv_fh *fh = f;
1937 struct bttv *btv = fh->btv; 1914 struct bttv *btv = fh->btv;
1938 1915
1939 if (!capable(CAP_SYS_ADMIN))
1940 return -EPERM;
1941
1942 if (!v4l2_chip_match_host(&reg->match)) {
1943 /* TODO: subdev errors should not be ignored, this should become a
1944 subdev helper function. */
1945 bttv_call_all(btv, core, g_register, reg);
1946 return 0;
1947 }
1948
1949 /* bt848 has a 12-bit register space */ 1916 /* bt848 has a 12-bit register space */
1950 reg->reg &= 0xfff; 1917 reg->reg &= 0xfff;
1951 reg->val = btread(reg->reg); 1918 reg->val = btread(reg->reg);
@@ -1960,16 +1927,6 @@ static int bttv_s_register(struct file *file, void *f,
1960 struct bttv_fh *fh = f; 1927 struct bttv_fh *fh = f;
1961 struct bttv *btv = fh->btv; 1928 struct bttv *btv = fh->btv;
1962 1929
1963 if (!capable(CAP_SYS_ADMIN))
1964 return -EPERM;
1965
1966 if (!v4l2_chip_match_host(&reg->match)) {
1967 /* TODO: subdev errors should not be ignored, this should become a
1968 subdev helper function. */
1969 bttv_call_all(btv, core, s_register, reg);
1970 return 0;
1971 }
1972
1973 /* bt848 has a 12-bit register space */ 1930 /* bt848 has a 12-bit register space */
1974 btwrite(reg->val, reg->reg & 0xfff); 1931 btwrite(reg->val, reg->reg & 0xfff);
1975 1932
@@ -3209,7 +3166,6 @@ static const struct v4l2_ioctl_ops bttv_ioctl_ops = {
3209 .vidioc_querystd = bttv_querystd, 3166 .vidioc_querystd = bttv_querystd,
3210 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, 3167 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
3211 .vidioc_unsubscribe_event = v4l2_event_unsubscribe, 3168 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
3212 .vidioc_g_chip_ident = bttv_g_chip_ident,
3213#ifdef CONFIG_VIDEO_ADV_DEBUG 3169#ifdef CONFIG_VIDEO_ADV_DEBUG
3214 .vidioc_g_register = bttv_g_register, 3170 .vidioc_g_register = bttv_g_register,
3215 .vidioc_s_register = bttv_s_register, 3171 .vidioc_s_register = bttv_s_register,
diff --git a/drivers/media/pci/bt8xx/bttv.h b/drivers/media/pci/bt8xx/bttv.h
index 6139ce26dc2c..df578efe03c9 100644
--- a/drivers/media/pci/bt8xx/bttv.h
+++ b/drivers/media/pci/bt8xx/bttv.h
@@ -185,6 +185,9 @@
185#define BTTV_BOARD_PV183 0x9f 185#define BTTV_BOARD_PV183 0x9f
186#define BTTV_BOARD_TVT_TD3116 0xa0 186#define BTTV_BOARD_TVT_TD3116 0xa0
187#define BTTV_BOARD_APOSONIC_WDVR 0xa1 187#define BTTV_BOARD_APOSONIC_WDVR 0xa1
188#define BTTV_BOARD_ADLINK_MPG24 0xa2
189#define BTTV_BOARD_BT848_CAP_14 0xa3
190#define BTTV_BOARD_CYBERVISION_CV06 0xa4
188 191
189/* more card-specific defines */ 192/* more card-specific defines */
190#define PT2254_L_CHANNEL 0x10 193#define PT2254_L_CHANNEL 0x10
@@ -232,6 +235,7 @@ struct tvcard {
232#define PLL_NONE 0 235#define PLL_NONE 0
233#define PLL_28 1 236#define PLL_28 1
234#define PLL_35 2 237#define PLL_35 2
238#define PLL_14 3
235 239
236 /* i2c audio flags */ 240 /* i2c audio flags */
237 unsigned int no_msp34xx:1; 241 unsigned int no_msp34xx:1;
diff --git a/drivers/media/pci/cx18/cx18-av-core.c b/drivers/media/pci/cx18/cx18-av-core.c
index 38b1d64ffc27..c4890a430dc6 100644
--- a/drivers/media/pci/cx18/cx18-av-core.c
+++ b/drivers/media/pci/cx18/cx18-av-core.c
@@ -22,7 +22,6 @@
22 * 02110-1301, USA. 22 * 02110-1301, USA.
23 */ 23 */
24 24
25#include <media/v4l2-chip-ident.h>
26#include "cx18-driver.h" 25#include "cx18-driver.h"
27#include "cx18-io.h" 26#include "cx18-io.h"
28#include "cx18-cards.h" 27#include "cx18-cards.h"
@@ -1231,35 +1230,14 @@ static int cx18_av_log_status(struct v4l2_subdev *sd)
1231 return 0; 1230 return 0;
1232} 1231}
1233 1232
1234static inline int cx18_av_dbg_match(const struct v4l2_dbg_match *match)
1235{
1236 return match->type == V4L2_CHIP_MATCH_HOST && match->addr == 1;
1237}
1238
1239static int cx18_av_g_chip_ident(struct v4l2_subdev *sd,
1240 struct v4l2_dbg_chip_ident *chip)
1241{
1242 struct cx18_av_state *state = to_cx18_av_state(sd);
1243
1244 if (cx18_av_dbg_match(&chip->match)) {
1245 chip->ident = state->id;
1246 chip->revision = state->rev;
1247 }
1248 return 0;
1249}
1250
1251#ifdef CONFIG_VIDEO_ADV_DEBUG 1233#ifdef CONFIG_VIDEO_ADV_DEBUG
1252static int cx18_av_g_register(struct v4l2_subdev *sd, 1234static int cx18_av_g_register(struct v4l2_subdev *sd,
1253 struct v4l2_dbg_register *reg) 1235 struct v4l2_dbg_register *reg)
1254{ 1236{
1255 struct cx18 *cx = v4l2_get_subdevdata(sd); 1237 struct cx18 *cx = v4l2_get_subdevdata(sd);
1256 1238
1257 if (!cx18_av_dbg_match(&reg->match))
1258 return -EINVAL;
1259 if ((reg->reg & 0x3) != 0) 1239 if ((reg->reg & 0x3) != 0)
1260 return -EINVAL; 1240 return -EINVAL;
1261 if (!capable(CAP_SYS_ADMIN))
1262 return -EPERM;
1263 reg->size = 4; 1241 reg->size = 4;
1264 reg->val = cx18_av_read4(cx, reg->reg & 0x00000ffc); 1242 reg->val = cx18_av_read4(cx, reg->reg & 0x00000ffc);
1265 return 0; 1243 return 0;
@@ -1270,12 +1248,8 @@ static int cx18_av_s_register(struct v4l2_subdev *sd,
1270{ 1248{
1271 struct cx18 *cx = v4l2_get_subdevdata(sd); 1249 struct cx18 *cx = v4l2_get_subdevdata(sd);
1272 1250
1273 if (!cx18_av_dbg_match(&reg->match))
1274 return -EINVAL;
1275 if ((reg->reg & 0x3) != 0) 1251 if ((reg->reg & 0x3) != 0)
1276 return -EINVAL; 1252 return -EINVAL;
1277 if (!capable(CAP_SYS_ADMIN))
1278 return -EPERM;
1279 cx18_av_write4(cx, reg->reg & 0x00000ffc, reg->val); 1253 cx18_av_write4(cx, reg->reg & 0x00000ffc, reg->val);
1280 return 0; 1254 return 0;
1281} 1255}
@@ -1286,17 +1260,9 @@ static const struct v4l2_ctrl_ops cx18_av_ctrl_ops = {
1286}; 1260};
1287 1261
1288static const struct v4l2_subdev_core_ops cx18_av_general_ops = { 1262static const struct v4l2_subdev_core_ops cx18_av_general_ops = {
1289 .g_chip_ident = cx18_av_g_chip_ident,
1290 .log_status = cx18_av_log_status, 1263 .log_status = cx18_av_log_status,
1291 .load_fw = cx18_av_load_fw, 1264 .load_fw = cx18_av_load_fw,
1292 .reset = cx18_av_reset, 1265 .reset = cx18_av_reset,
1293 .g_ctrl = v4l2_subdev_g_ctrl,
1294 .s_ctrl = v4l2_subdev_s_ctrl,
1295 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls,
1296 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls,
1297 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls,
1298 .queryctrl = v4l2_subdev_queryctrl,
1299 .querymenu = v4l2_subdev_querymenu,
1300 .s_std = cx18_av_s_std, 1266 .s_std = cx18_av_s_std,
1301#ifdef CONFIG_VIDEO_ADV_DEBUG 1267#ifdef CONFIG_VIDEO_ADV_DEBUG
1302 .g_register = cx18_av_g_register, 1268 .g_register = cx18_av_g_register,
@@ -1344,8 +1310,6 @@ int cx18_av_probe(struct cx18 *cx)
1344 int err; 1310 int err;
1345 1311
1346 state->rev = cx18_av_read4(cx, CXADEC_CHIP_CTRL) & 0xffff; 1312 state->rev = cx18_av_read4(cx, CXADEC_CHIP_CTRL) & 0xffff;
1347 state->id = ((state->rev >> 4) == CXADEC_CHIP_TYPE_MAKO)
1348 ? V4L2_IDENT_CX23418_843 : V4L2_IDENT_UNKNOWN;
1349 1313
1350 state->vid_input = CX18_AV_COMPOSITE7; 1314 state->vid_input = CX18_AV_COMPOSITE7;
1351 state->aud_input = CX18_AV_AUDIO8; 1315 state->aud_input = CX18_AV_AUDIO8;
diff --git a/drivers/media/pci/cx18/cx18-av-core.h b/drivers/media/pci/cx18/cx18-av-core.h
index e9c69d9c9e4a..4c559e86e340 100644
--- a/drivers/media/pci/cx18/cx18-av-core.h
+++ b/drivers/media/pci/cx18/cx18-av-core.h
@@ -104,7 +104,6 @@ struct cx18_av_state {
104 enum cx18_av_audio_input aud_input; 104 enum cx18_av_audio_input aud_input;
105 u32 audclk_freq; 105 u32 audclk_freq;
106 int audmode; 106 int audmode;
107 u32 id;
108 u32 rev; 107 u32 rev;
109 int is_initialized; 108 int is_initialized;
110 109
diff --git a/drivers/media/pci/cx18/cx18-ioctl.c b/drivers/media/pci/cx18/cx18-ioctl.c
index aee7b6dacbfe..1110bcb14e2f 100644
--- a/drivers/media/pci/cx18/cx18-ioctl.c
+++ b/drivers/media/pci/cx18/cx18-ioctl.c
@@ -39,7 +39,6 @@
39#include "cx18-cards.h" 39#include "cx18-cards.h"
40#include "cx18-av-core.h" 40#include "cx18-av-core.h"
41#include <media/tveeprom.h> 41#include <media/tveeprom.h>
42#include <media/v4l2-chip-ident.h>
43 42
44u16 cx18_service2vbi(int type) 43u16 cx18_service2vbi(int type)
45{ 44{
@@ -362,73 +361,18 @@ static int cx18_s_fmt_sliced_vbi_cap(struct file *file, void *fh,
362 return 0; 361 return 0;
363} 362}
364 363
365static int cx18_g_chip_ident(struct file *file, void *fh,
366 struct v4l2_dbg_chip_ident *chip)
367{
368 struct cx18 *cx = fh2id(fh)->cx;
369 int err = 0;
370
371 chip->ident = V4L2_IDENT_NONE;
372 chip->revision = 0;
373 switch (chip->match.type) {
374 case V4L2_CHIP_MATCH_HOST:
375 switch (chip->match.addr) {
376 case 0:
377 chip->ident = V4L2_IDENT_CX23418;
378 chip->revision = cx18_read_reg(cx, 0xC72028);
379 break;
380 case 1:
381 /*
382 * The A/V decoder is always present, but in the rare
383 * case that the card doesn't have analog, we don't
384 * use it. We find it w/o using the cx->sd_av pointer
385 */
386 cx18_call_hw(cx, CX18_HW_418_AV,
387 core, g_chip_ident, chip);
388 break;
389 default:
390 /*
391 * Could return ident = V4L2_IDENT_UNKNOWN if we had
392 * other host chips at higher addresses, but we don't
393 */
394 err = -EINVAL; /* per V4L2 spec */
395 break;
396 }
397 break;
398 case V4L2_CHIP_MATCH_I2C_DRIVER:
399 /* If needed, returns V4L2_IDENT_AMBIGUOUS without extra work */
400 cx18_call_all(cx, core, g_chip_ident, chip);
401 break;
402 case V4L2_CHIP_MATCH_I2C_ADDR:
403 /*
404 * We could return V4L2_IDENT_UNKNOWN, but we don't do the work
405 * to look if a chip is at the address with no driver. That's a
406 * dangerous thing to do with EEPROMs anyway.
407 */
408 cx18_call_all(cx, core, g_chip_ident, chip);
409 break;
410 default:
411 err = -EINVAL;
412 break;
413 }
414 return err;
415}
416
417#ifdef CONFIG_VIDEO_ADV_DEBUG 364#ifdef CONFIG_VIDEO_ADV_DEBUG
418static int cx18_g_register(struct file *file, void *fh, 365static int cx18_g_register(struct file *file, void *fh,
419 struct v4l2_dbg_register *reg) 366 struct v4l2_dbg_register *reg)
420{ 367{
421 struct cx18 *cx = fh2id(fh)->cx; 368 struct cx18 *cx = fh2id(fh)->cx;
422 369
423 if (v4l2_chip_match_host(&reg->match)) { 370 if (reg->reg & 0x3)
424 if (reg->reg >= CX18_MEM_OFFSET + CX18_MEM_SIZE) 371 return -EINVAL;
425 return -EINVAL; 372 if (reg->reg >= CX18_MEM_OFFSET + CX18_MEM_SIZE)
426 reg->size = 4; 373 return -EINVAL;
427 reg->val = cx18_read_enc(cx, reg->reg); 374 reg->size = 4;
428 return 0; 375 reg->val = cx18_read_enc(cx, reg->reg);
429 }
430 /* FIXME - errors shouldn't be ignored */
431 cx18_call_all(cx, core, g_register, reg);
432 return 0; 376 return 0;
433} 377}
434 378
@@ -437,14 +381,11 @@ static int cx18_s_register(struct file *file, void *fh,
437{ 381{
438 struct cx18 *cx = fh2id(fh)->cx; 382 struct cx18 *cx = fh2id(fh)->cx;
439 383
440 if (v4l2_chip_match_host(&reg->match)) { 384 if (reg->reg & 0x3)
441 if (reg->reg >= CX18_MEM_OFFSET + CX18_MEM_SIZE) 385 return -EINVAL;
442 return -EINVAL; 386 if (reg->reg >= CX18_MEM_OFFSET + CX18_MEM_SIZE)
443 cx18_write_enc(cx, reg->val, reg->reg); 387 return -EINVAL;
444 return 0; 388 cx18_write_enc(cx, reg->val, reg->reg);
445 }
446 /* FIXME - errors shouldn't be ignored */
447 cx18_call_all(cx, core, s_register, reg);
448 return 0; 389 return 0;
449} 390}
450#endif 391#endif
@@ -1162,7 +1103,6 @@ static const struct v4l2_ioctl_ops cx18_ioctl_ops = {
1162 .vidioc_try_fmt_vbi_cap = cx18_try_fmt_vbi_cap, 1103 .vidioc_try_fmt_vbi_cap = cx18_try_fmt_vbi_cap,
1163 .vidioc_try_fmt_sliced_vbi_cap = cx18_try_fmt_sliced_vbi_cap, 1104 .vidioc_try_fmt_sliced_vbi_cap = cx18_try_fmt_sliced_vbi_cap,
1164 .vidioc_g_sliced_vbi_cap = cx18_g_sliced_vbi_cap, 1105 .vidioc_g_sliced_vbi_cap = cx18_g_sliced_vbi_cap,
1165 .vidioc_g_chip_ident = cx18_g_chip_ident,
1166#ifdef CONFIG_VIDEO_ADV_DEBUG 1106#ifdef CONFIG_VIDEO_ADV_DEBUG
1167 .vidioc_g_register = cx18_g_register, 1107 .vidioc_g_register = cx18_g_register,
1168 .vidioc_s_register = cx18_s_register, 1108 .vidioc_s_register = cx18_s_register,
diff --git a/drivers/media/pci/cx23885/cx23885-417.c b/drivers/media/pci/cx23885/cx23885-417.c
index 6dea11a7a858..e3fc2c71808a 100644
--- a/drivers/media/pci/cx23885/cx23885-417.c
+++ b/drivers/media/pci/cx23885/cx23885-417.c
@@ -1217,8 +1217,7 @@ static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *id)
1217 struct cx23885_fh *fh = file->private_data; 1217 struct cx23885_fh *fh = file->private_data;
1218 struct cx23885_dev *dev = fh->dev; 1218 struct cx23885_dev *dev = fh->dev;
1219 1219
1220 call_all(dev, core, g_std, id); 1220 *id = dev->tvnorm;
1221
1222 return 0; 1221 return 0;
1223} 1222}
1224 1223
@@ -1661,7 +1660,6 @@ static struct v4l2_file_operations mpeg_fops = {
1661}; 1660};
1662 1661
1663static const struct v4l2_ioctl_ops mpeg_ioctl_ops = { 1662static const struct v4l2_ioctl_ops mpeg_ioctl_ops = {
1664 .vidioc_querystd = vidioc_g_std,
1665 .vidioc_g_std = vidioc_g_std, 1663 .vidioc_g_std = vidioc_g_std,
1666 .vidioc_s_std = vidioc_s_std, 1664 .vidioc_s_std = vidioc_s_std,
1667 .vidioc_enum_input = vidioc_enum_input, 1665 .vidioc_enum_input = vidioc_enum_input,
@@ -1690,8 +1688,8 @@ static const struct v4l2_ioctl_ops mpeg_ioctl_ops = {
1690 .vidioc_log_status = vidioc_log_status, 1688 .vidioc_log_status = vidioc_log_status,
1691 .vidioc_querymenu = vidioc_querymenu, 1689 .vidioc_querymenu = vidioc_querymenu,
1692 .vidioc_queryctrl = vidioc_queryctrl, 1690 .vidioc_queryctrl = vidioc_queryctrl,
1693 .vidioc_g_chip_ident = cx23885_g_chip_ident,
1694#ifdef CONFIG_VIDEO_ADV_DEBUG 1691#ifdef CONFIG_VIDEO_ADV_DEBUG
1692 .vidioc_g_chip_info = cx23885_g_chip_info,
1695 .vidioc_g_register = cx23885_g_register, 1693 .vidioc_g_register = cx23885_g_register,
1696 .vidioc_s_register = cx23885_s_register, 1694 .vidioc_s_register = cx23885_s_register,
1697#endif 1695#endif
@@ -1702,7 +1700,6 @@ static struct video_device cx23885_mpeg_template = {
1702 .fops = &mpeg_fops, 1700 .fops = &mpeg_fops,
1703 .ioctl_ops = &mpeg_ioctl_ops, 1701 .ioctl_ops = &mpeg_ioctl_ops,
1704 .tvnorms = CX23885_NORMS, 1702 .tvnorms = CX23885_NORMS,
1705 .current_norm = V4L2_STD_NTSC_M,
1706}; 1703};
1707 1704
1708void cx23885_417_unregister(struct cx23885_dev *dev) 1705void cx23885_417_unregister(struct cx23885_dev *dev)
@@ -1735,7 +1732,7 @@ static struct video_device *cx23885_video_dev_alloc(
1735 *vfd = *template; 1732 *vfd = *template;
1736 snprintf(vfd->name, sizeof(vfd->name), "%s (%s)", 1733 snprintf(vfd->name, sizeof(vfd->name), "%s (%s)",
1737 cx23885_boards[tsport->dev->board].name, type); 1734 cx23885_boards[tsport->dev->board].name, type);
1738 vfd->parent = &pci->dev; 1735 vfd->v4l2_dev = &dev->v4l2_dev;
1739 vfd->release = video_device_release; 1736 vfd->release = video_device_release;
1740 return vfd; 1737 return vfd;
1741} 1738}
diff --git a/drivers/media/pci/cx23885/cx23885-ioctl.c b/drivers/media/pci/cx23885/cx23885-ioctl.c
index acdb6d58db58..271d69d1ca8c 100644
--- a/drivers/media/pci/cx23885/cx23885-ioctl.c
+++ b/drivers/media/pci/cx23885/cx23885-ioctl.c
@@ -24,93 +24,21 @@
24#include "cx23885.h" 24#include "cx23885.h"
25#include "cx23885-ioctl.h" 25#include "cx23885-ioctl.h"
26 26
27#include <media/v4l2-chip-ident.h> 27#ifdef CONFIG_VIDEO_ADV_DEBUG
28 28int cx23885_g_chip_info(struct file *file, void *fh,
29int cx23885_g_chip_ident(struct file *file, void *fh, 29 struct v4l2_dbg_chip_info *chip)
30 struct v4l2_dbg_chip_ident *chip)
31{ 30{
32 struct cx23885_dev *dev = ((struct cx23885_fh *)fh)->dev; 31 struct cx23885_dev *dev = ((struct cx23885_fh *)fh)->dev;
33 int err = 0;
34 u8 rev;
35
36 chip->ident = V4L2_IDENT_NONE;
37 chip->revision = 0;
38 switch (chip->match.type) {
39 case V4L2_CHIP_MATCH_HOST:
40 switch (chip->match.addr) {
41 case 0:
42 rev = cx_read(RDR_CFG2) & 0xff;
43 switch (dev->pci->device) {
44 case 0x8852:
45 /* rev 0x04 could be '885 or '888. Pick '888. */
46 if (rev == 0x04)
47 chip->ident = V4L2_IDENT_CX23888;
48 else
49 chip->ident = V4L2_IDENT_CX23885;
50 break;
51 case 0x8880:
52 if (rev == 0x0e || rev == 0x0f)
53 chip->ident = V4L2_IDENT_CX23887;
54 else
55 chip->ident = V4L2_IDENT_CX23888;
56 break;
57 default:
58 chip->ident = V4L2_IDENT_UNKNOWN;
59 break;
60 }
61 chip->revision = (dev->pci->device << 16) | (rev << 8) |
62 (dev->hwrevision & 0xff);
63 break;
64 case 1:
65 if (dev->v4l_device != NULL) {
66 chip->ident = V4L2_IDENT_CX23417;
67 chip->revision = 0;
68 }
69 break;
70 case 2:
71 /*
72 * The integrated IR controller on the CX23888 is
73 * host chip 2. It may not be used/initialized or sd_ir
74 * may be pointing at the cx25840 subdevice for the
75 * IR controller on the CX23885. Thus we find it
76 * without using the dev->sd_ir pointer.
77 */
78 call_hw(dev, CX23885_HW_888_IR, core, g_chip_ident,
79 chip);
80 break;
81 default:
82 err = -EINVAL; /* per V4L2 spec */
83 break;
84 }
85 break;
86 case V4L2_CHIP_MATCH_I2C_DRIVER:
87 /* If needed, returns V4L2_IDENT_AMBIGUOUS without extra work */
88 call_all(dev, core, g_chip_ident, chip);
89 break;
90 case V4L2_CHIP_MATCH_I2C_ADDR:
91 /*
92 * We could return V4L2_IDENT_UNKNOWN, but we don't do the work
93 * to look if a chip is at the address with no driver. That's a
94 * dangerous thing to do with EEPROMs anyway.
95 */
96 call_all(dev, core, g_chip_ident, chip);
97 break;
98 default:
99 err = -EINVAL;
100 break;
101 }
102 return err;
103}
104 32
105#ifdef CONFIG_VIDEO_ADV_DEBUG 33 if (chip->match.addr > 1)
106static int cx23885_g_host_register(struct cx23885_dev *dev,
107 struct v4l2_dbg_register *reg)
108{
109 if ((reg->reg & 0x3) != 0 || reg->reg >= pci_resource_len(dev->pci, 0))
110 return -EINVAL; 34 return -EINVAL;
111 35 if (chip->match.addr == 1) {
112 reg->size = 4; 36 if (dev->v4l_device == NULL)
113 reg->val = cx_read(reg->reg); 37 return -EINVAL;
38 strlcpy(chip->name, "cx23417", sizeof(chip->name));
39 } else {
40 strlcpy(chip->name, dev->v4l2_dev.name, sizeof(chip->name));
41 }
114 return 0; 42 return 0;
115} 43}
116 44
@@ -138,32 +66,16 @@ int cx23885_g_register(struct file *file, void *fh,
138{ 66{
139 struct cx23885_dev *dev = ((struct cx23885_fh *)fh)->dev; 67 struct cx23885_dev *dev = ((struct cx23885_fh *)fh)->dev;
140 68
141 if (!capable(CAP_SYS_ADMIN)) 69 if (reg->match.addr > 1)
142 return -EPERM; 70 return -EINVAL;
143 71 if (reg->match.addr)
144 if (reg->match.type == V4L2_CHIP_MATCH_HOST) { 72 return cx23417_g_register(dev, reg);
145 switch (reg->match.addr) {
146 case 0:
147 return cx23885_g_host_register(dev, reg);
148 case 1:
149 return cx23417_g_register(dev, reg);
150 default:
151 break;
152 }
153 }
154
155 /* FIXME - any error returns should not be ignored */
156 call_all(dev, core, g_register, reg);
157 return 0;
158}
159 73
160static int cx23885_s_host_register(struct cx23885_dev *dev,
161 const struct v4l2_dbg_register *reg)
162{
163 if ((reg->reg & 0x3) != 0 || reg->reg >= pci_resource_len(dev->pci, 0)) 74 if ((reg->reg & 0x3) != 0 || reg->reg >= pci_resource_len(dev->pci, 0))
164 return -EINVAL; 75 return -EINVAL;
165 76
166 cx_write(reg->reg, reg->val); 77 reg->size = 4;
78 reg->val = cx_read(reg->reg);
167 return 0; 79 return 0;
168} 80}
169 81
@@ -186,22 +98,15 @@ int cx23885_s_register(struct file *file, void *fh,
186{ 98{
187 struct cx23885_dev *dev = ((struct cx23885_fh *)fh)->dev; 99 struct cx23885_dev *dev = ((struct cx23885_fh *)fh)->dev;
188 100
189 if (!capable(CAP_SYS_ADMIN)) 101 if (reg->match.addr > 1)
190 return -EPERM; 102 return -EINVAL;
191 103 if (reg->match.addr)
192 if (reg->match.type == V4L2_CHIP_MATCH_HOST) { 104 return cx23417_s_register(dev, reg);
193 switch (reg->match.addr) { 105
194 case 0: 106 if ((reg->reg & 0x3) != 0 || reg->reg >= pci_resource_len(dev->pci, 0))
195 return cx23885_s_host_register(dev, reg); 107 return -EINVAL;
196 case 1:
197 return cx23417_s_register(dev, reg);
198 default:
199 break;
200 }
201 }
202 108
203 /* FIXME - any error returns should not be ignored */ 109 cx_write(reg->reg, reg->val);
204 call_all(dev, core, s_register, reg);
205 return 0; 110 return 0;
206} 111}
207#endif 112#endif
diff --git a/drivers/media/pci/cx23885/cx23885-ioctl.h b/drivers/media/pci/cx23885/cx23885-ioctl.h
index a6080964a9ee..92d9f0774366 100644
--- a/drivers/media/pci/cx23885/cx23885-ioctl.h
+++ b/drivers/media/pci/cx23885/cx23885-ioctl.h
@@ -24,8 +24,8 @@
24#ifndef _CX23885_IOCTL_H_ 24#ifndef _CX23885_IOCTL_H_
25#define _CX23885_IOCTL_H_ 25#define _CX23885_IOCTL_H_
26 26
27int cx23885_g_chip_ident(struct file *file, void *fh, 27int cx23885_g_chip_info(struct file *file, void *fh,
28 struct v4l2_dbg_chip_ident *chip); 28 struct v4l2_dbg_chip_info *chip);
29 29
30#ifdef CONFIG_VIDEO_ADV_DEBUG 30#ifdef CONFIG_VIDEO_ADV_DEBUG
31int cx23885_g_register(struct file *file, void *fh, 31int cx23885_g_register(struct file *file, void *fh,
diff --git a/drivers/media/pci/cx23885/cx23885-video.c b/drivers/media/pci/cx23885/cx23885-video.c
index ed08c89adde0..e33d1a7dfdd0 100644
--- a/drivers/media/pci/cx23885/cx23885-video.c
+++ b/drivers/media/pci/cx23885/cx23885-video.c
@@ -1254,8 +1254,7 @@ static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *id)
1254 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev; 1254 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1255 dprintk(1, "%s()\n", __func__); 1255 dprintk(1, "%s()\n", __func__);
1256 1256
1257 call_all(dev, core, g_std, id); 1257 *id = dev->tvnorm;
1258
1259 return 0; 1258 return 0;
1260} 1259}
1261 1260
@@ -1743,7 +1742,6 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
1743 .vidioc_dqbuf = vidioc_dqbuf, 1742 .vidioc_dqbuf = vidioc_dqbuf,
1744 .vidioc_s_std = vidioc_s_std, 1743 .vidioc_s_std = vidioc_s_std,
1745 .vidioc_g_std = vidioc_g_std, 1744 .vidioc_g_std = vidioc_g_std,
1746 .vidioc_querystd = vidioc_g_std,
1747 .vidioc_enum_input = vidioc_enum_input, 1745 .vidioc_enum_input = vidioc_enum_input,
1748 .vidioc_g_input = vidioc_g_input, 1746 .vidioc_g_input = vidioc_g_input,
1749 .vidioc_s_input = vidioc_s_input, 1747 .vidioc_s_input = vidioc_s_input,
@@ -1757,8 +1755,8 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
1757 .vidioc_s_tuner = vidioc_s_tuner, 1755 .vidioc_s_tuner = vidioc_s_tuner,
1758 .vidioc_g_frequency = vidioc_g_frequency, 1756 .vidioc_g_frequency = vidioc_g_frequency,
1759 .vidioc_s_frequency = vidioc_s_frequency, 1757 .vidioc_s_frequency = vidioc_s_frequency,
1760 .vidioc_g_chip_ident = cx23885_g_chip_ident,
1761#ifdef CONFIG_VIDEO_ADV_DEBUG 1758#ifdef CONFIG_VIDEO_ADV_DEBUG
1759 .vidioc_g_chip_info = cx23885_g_chip_info,
1762 .vidioc_g_register = cx23885_g_register, 1760 .vidioc_g_register = cx23885_g_register,
1763 .vidioc_s_register = cx23885_s_register, 1761 .vidioc_s_register = cx23885_s_register,
1764#endif 1762#endif
@@ -1773,7 +1771,6 @@ static struct video_device cx23885_video_template = {
1773 .fops = &video_fops, 1771 .fops = &video_fops,
1774 .ioctl_ops = &video_ioctl_ops, 1772 .ioctl_ops = &video_ioctl_ops,
1775 .tvnorms = CX23885_NORMS, 1773 .tvnorms = CX23885_NORMS,
1776 .current_norm = V4L2_STD_NTSC_M,
1777}; 1774};
1778 1775
1779static const struct v4l2_file_operations radio_fops = { 1776static const struct v4l2_file_operations radio_fops = {
@@ -1822,7 +1819,7 @@ int cx23885_video_register(struct cx23885_dev *dev)
1822 cx23885_vbi_template = cx23885_video_template; 1819 cx23885_vbi_template = cx23885_video_template;
1823 strcpy(cx23885_vbi_template.name, "cx23885-vbi"); 1820 strcpy(cx23885_vbi_template.name, "cx23885-vbi");
1824 1821
1825 dev->tvnorm = cx23885_video_template.current_norm; 1822 dev->tvnorm = V4L2_STD_NTSC_M;
1826 1823
1827 /* init video dma queues */ 1824 /* init video dma queues */
1828 INIT_LIST_HEAD(&dev->vidq.active); 1825 INIT_LIST_HEAD(&dev->vidq.active);
diff --git a/drivers/media/pci/cx23885/cx23888-ir.c b/drivers/media/pci/cx23885/cx23888-ir.c
index fa672fe41079..2c951dec2d33 100644
--- a/drivers/media/pci/cx23885/cx23888-ir.c
+++ b/drivers/media/pci/cx23885/cx23888-ir.c
@@ -25,7 +25,6 @@
25#include <linux/slab.h> 25#include <linux/slab.h>
26 26
27#include <media/v4l2-device.h> 27#include <media/v4l2-device.h>
28#include <media/v4l2-chip-ident.h>
29#include <media/rc-core.h> 28#include <media/rc-core.h>
30 29
31#include "cx23885.h" 30#include "cx23885.h"
@@ -131,8 +130,6 @@ union cx23888_ir_fifo_rec {
131struct cx23888_ir_state { 130struct cx23888_ir_state {
132 struct v4l2_subdev sd; 131 struct v4l2_subdev sd;
133 struct cx23885_dev *dev; 132 struct cx23885_dev *dev;
134 u32 id;
135 u32 rev;
136 133
137 struct v4l2_subdev_ir_parameters rx_params; 134 struct v4l2_subdev_ir_parameters rx_params;
138 struct mutex rx_params_lock; 135 struct mutex rx_params_lock;
@@ -1086,23 +1083,6 @@ static int cx23888_ir_log_status(struct v4l2_subdev *sd)
1086 return 0; 1083 return 0;
1087} 1084}
1088 1085
1089static inline int cx23888_ir_dbg_match(const struct v4l2_dbg_match *match)
1090{
1091 return match->type == V4L2_CHIP_MATCH_HOST && match->addr == 2;
1092}
1093
1094static int cx23888_ir_g_chip_ident(struct v4l2_subdev *sd,
1095 struct v4l2_dbg_chip_ident *chip)
1096{
1097 struct cx23888_ir_state *state = to_state(sd);
1098
1099 if (cx23888_ir_dbg_match(&chip->match)) {
1100 chip->ident = state->id;
1101 chip->revision = state->rev;
1102 }
1103 return 0;
1104}
1105
1106#ifdef CONFIG_VIDEO_ADV_DEBUG 1086#ifdef CONFIG_VIDEO_ADV_DEBUG
1107static int cx23888_ir_g_register(struct v4l2_subdev *sd, 1087static int cx23888_ir_g_register(struct v4l2_subdev *sd,
1108 struct v4l2_dbg_register *reg) 1088 struct v4l2_dbg_register *reg)
@@ -1110,14 +1090,10 @@ static int cx23888_ir_g_register(struct v4l2_subdev *sd,
1110 struct cx23888_ir_state *state = to_state(sd); 1090 struct cx23888_ir_state *state = to_state(sd);
1111 u32 addr = CX23888_IR_REG_BASE + (u32) reg->reg; 1091 u32 addr = CX23888_IR_REG_BASE + (u32) reg->reg;
1112 1092
1113 if (!cx23888_ir_dbg_match(&reg->match))
1114 return -EINVAL;
1115 if ((addr & 0x3) != 0) 1093 if ((addr & 0x3) != 0)
1116 return -EINVAL; 1094 return -EINVAL;
1117 if (addr < CX23888_IR_CNTRL_REG || addr > CX23888_IR_LEARN_REG) 1095 if (addr < CX23888_IR_CNTRL_REG || addr > CX23888_IR_LEARN_REG)
1118 return -EINVAL; 1096 return -EINVAL;
1119 if (!capable(CAP_SYS_ADMIN))
1120 return -EPERM;
1121 reg->size = 4; 1097 reg->size = 4;
1122 reg->val = cx23888_ir_read4(state->dev, addr); 1098 reg->val = cx23888_ir_read4(state->dev, addr);
1123 return 0; 1099 return 0;
@@ -1129,21 +1105,16 @@ static int cx23888_ir_s_register(struct v4l2_subdev *sd,
1129 struct cx23888_ir_state *state = to_state(sd); 1105 struct cx23888_ir_state *state = to_state(sd);
1130 u32 addr = CX23888_IR_REG_BASE + (u32) reg->reg; 1106 u32 addr = CX23888_IR_REG_BASE + (u32) reg->reg;
1131 1107
1132 if (!cx23888_ir_dbg_match(&reg->match))
1133 return -EINVAL;
1134 if ((addr & 0x3) != 0) 1108 if ((addr & 0x3) != 0)
1135 return -EINVAL; 1109 return -EINVAL;
1136 if (addr < CX23888_IR_CNTRL_REG || addr > CX23888_IR_LEARN_REG) 1110 if (addr < CX23888_IR_CNTRL_REG || addr > CX23888_IR_LEARN_REG)
1137 return -EINVAL; 1111 return -EINVAL;
1138 if (!capable(CAP_SYS_ADMIN))
1139 return -EPERM;
1140 cx23888_ir_write4(state->dev, addr, reg->val); 1112 cx23888_ir_write4(state->dev, addr, reg->val);
1141 return 0; 1113 return 0;
1142} 1114}
1143#endif 1115#endif
1144 1116
1145static const struct v4l2_subdev_core_ops cx23888_ir_core_ops = { 1117static const struct v4l2_subdev_core_ops cx23888_ir_core_ops = {
1146 .g_chip_ident = cx23888_ir_g_chip_ident,
1147 .log_status = cx23888_ir_log_status, 1118 .log_status = cx23888_ir_log_status,
1148#ifdef CONFIG_VIDEO_ADV_DEBUG 1119#ifdef CONFIG_VIDEO_ADV_DEBUG
1149 .g_register = cx23888_ir_g_register, 1120 .g_register = cx23888_ir_g_register,
@@ -1217,8 +1188,6 @@ int cx23888_ir_probe(struct cx23885_dev *dev)
1217 return -ENOMEM; 1188 return -ENOMEM;
1218 1189
1219 state->dev = dev; 1190 state->dev = dev;
1220 state->id = V4L2_IDENT_CX23888_IR;
1221 state->rev = 0;
1222 sd = &state->sd; 1191 sd = &state->sd;
1223 1192
1224 v4l2_subdev_init(sd, &cx23888_ir_controller_ops); 1193 v4l2_subdev_init(sd, &cx23888_ir_controller_ops);
diff --git a/drivers/media/pci/cx88/cx88-cards.c b/drivers/media/pci/cx88/cx88-cards.c
index a87a0e19593e..e18a7ace08b1 100644
--- a/drivers/media/pci/cx88/cx88-cards.c
+++ b/drivers/media/pci/cx88/cx88-cards.c
@@ -744,7 +744,7 @@ static const struct cx88_board cx88_boards[] = {
744 .tuner_addr = ADDR_UNSET, 744 .tuner_addr = ADDR_UNSET,
745 .radio_addr = ADDR_UNSET, 745 .radio_addr = ADDR_UNSET,
746 /* Some variants use a tda9874 and so need the tvaudio module. */ 746 /* Some variants use a tda9874 and so need the tvaudio module. */
747 .audio_chip = V4L2_IDENT_TVAUDIO, 747 .audio_chip = CX88_AUDIO_TVAUDIO,
748 .input = {{ 748 .input = {{
749 .type = CX88_VMUX_TELEVISION, 749 .type = CX88_VMUX_TELEVISION,
750 .vmux = 0, 750 .vmux = 0,
@@ -976,7 +976,7 @@ static const struct cx88_board cx88_boards[] = {
976 .radio_type = UNSET, 976 .radio_type = UNSET,
977 .tuner_addr = ADDR_UNSET, 977 .tuner_addr = ADDR_UNSET,
978 .radio_addr = ADDR_UNSET, 978 .radio_addr = ADDR_UNSET,
979 .audio_chip = V4L2_IDENT_WM8775, 979 .audio_chip = CX88_AUDIO_WM8775,
980 .i2sinputcntl = 2, 980 .i2sinputcntl = 2,
981 .input = {{ 981 .input = {{
982 .type = CX88_VMUX_DVB, 982 .type = CX88_VMUX_DVB,
@@ -1014,7 +1014,7 @@ static const struct cx88_board cx88_boards[] = {
1014 .radio_type = UNSET, 1014 .radio_type = UNSET,
1015 .tuner_addr = ADDR_UNSET, 1015 .tuner_addr = ADDR_UNSET,
1016 .radio_addr = ADDR_UNSET, 1016 .radio_addr = ADDR_UNSET,
1017 .audio_chip = V4L2_IDENT_WM8775, 1017 .audio_chip = CX88_AUDIO_WM8775,
1018 .input = {{ 1018 .input = {{
1019 .type = CX88_VMUX_DVB, 1019 .type = CX88_VMUX_DVB,
1020 .vmux = 0, 1020 .vmux = 0,
@@ -1376,7 +1376,7 @@ static const struct cx88_board cx88_boards[] = {
1376 .tuner_addr = ADDR_UNSET, 1376 .tuner_addr = ADDR_UNSET,
1377 .radio_addr = ADDR_UNSET, 1377 .radio_addr = ADDR_UNSET,
1378 .tda9887_conf = TDA9887_PRESENT, 1378 .tda9887_conf = TDA9887_PRESENT,
1379 .audio_chip = V4L2_IDENT_WM8775, 1379 .audio_chip = CX88_AUDIO_WM8775,
1380 .input = {{ 1380 .input = {{
1381 .type = CX88_VMUX_TELEVISION, 1381 .type = CX88_VMUX_TELEVISION,
1382 .vmux = 0, 1382 .vmux = 0,
@@ -1461,7 +1461,7 @@ static const struct cx88_board cx88_boards[] = {
1461 .tuner_addr = ADDR_UNSET, 1461 .tuner_addr = ADDR_UNSET,
1462 .radio_addr = ADDR_UNSET, 1462 .radio_addr = ADDR_UNSET,
1463 .tda9887_conf = TDA9887_PRESENT, 1463 .tda9887_conf = TDA9887_PRESENT,
1464 .audio_chip = V4L2_IDENT_WM8775, 1464 .audio_chip = CX88_AUDIO_WM8775,
1465 /* 1465 /*
1466 * gpio0 as reported by Mike Crash <mike AT mikecrash.com> 1466 * gpio0 as reported by Mike Crash <mike AT mikecrash.com>
1467 */ 1467 */
@@ -1929,7 +1929,7 @@ static const struct cx88_board cx88_boards[] = {
1929 .tuner_addr = ADDR_UNSET, 1929 .tuner_addr = ADDR_UNSET,
1930 .radio_addr = ADDR_UNSET, 1930 .radio_addr = ADDR_UNSET,
1931 .tda9887_conf = TDA9887_PRESENT, 1931 .tda9887_conf = TDA9887_PRESENT,
1932 .audio_chip = V4L2_IDENT_WM8775, 1932 .audio_chip = CX88_AUDIO_WM8775,
1933 /* 1933 /*
1934 * GPIO0 (WINTV2000) 1934 * GPIO0 (WINTV2000)
1935 * 1935 *
diff --git a/drivers/media/pci/cx88/cx88-core.c b/drivers/media/pci/cx88/cx88-core.c
index c8f3dcc579d4..ad59dc9235ae 100644
--- a/drivers/media/pci/cx88/cx88-core.c
+++ b/drivers/media/pci/cx88/cx88-core.c
@@ -1034,7 +1034,14 @@ struct video_device *cx88_vdev_init(struct cx88_core *core,
1034 if (NULL == vfd) 1034 if (NULL == vfd)
1035 return NULL; 1035 return NULL;
1036 *vfd = *template_; 1036 *vfd = *template_;
1037 /*
1038 * The dev pointer of v4l2_device is NULL, instead we set the
1039 * video_device dev_parent pointer to the correct PCI bus device.
1040 * This driver is a rare example where there is one v4l2_device,
1041 * but the video nodes have different parent (PCI) devices.
1042 */
1037 vfd->v4l2_dev = &core->v4l2_dev; 1043 vfd->v4l2_dev = &core->v4l2_dev;
1044 vfd->dev_parent = &pci->dev;
1038 vfd->release = video_device_release; 1045 vfd->release = video_device_release;
1039 snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)", 1046 snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)",
1040 core->name, type, core->board.name); 1047 core->name, type, core->board.name);
diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
index c7a9be1065c0..ecf21d9f1f34 100644
--- a/drivers/media/pci/cx88/cx88-video.c
+++ b/drivers/media/pci/cx88/cx88-video.c
@@ -1353,26 +1353,14 @@ static int vidioc_s_frequency (struct file *file, void *priv,
1353 return cx88_set_freq(core, f); 1353 return cx88_set_freq(core, f);
1354} 1354}
1355 1355
1356static int vidioc_g_chip_ident(struct file *file, void *priv,
1357 struct v4l2_dbg_chip_ident *chip)
1358{
1359 if (!v4l2_chip_match_host(&chip->match))
1360 return -EINVAL;
1361 chip->revision = 0;
1362 chip->ident = V4L2_IDENT_UNKNOWN;
1363 return 0;
1364}
1365
1366#ifdef CONFIG_VIDEO_ADV_DEBUG 1356#ifdef CONFIG_VIDEO_ADV_DEBUG
1367static int vidioc_g_register (struct file *file, void *fh, 1357static int vidioc_g_register (struct file *file, void *fh,
1368 struct v4l2_dbg_register *reg) 1358 struct v4l2_dbg_register *reg)
1369{ 1359{
1370 struct cx88_core *core = ((struct cx8800_fh*)fh)->dev->core; 1360 struct cx88_core *core = ((struct cx8800_fh*)fh)->dev->core;
1371 1361
1372 if (!v4l2_chip_match_host(&reg->match))
1373 return -EINVAL;
1374 /* cx2388x has a 24-bit register space */ 1362 /* cx2388x has a 24-bit register space */
1375 reg->val = cx_read(reg->reg & 0xffffff); 1363 reg->val = cx_read(reg->reg & 0xfffffc);
1376 reg->size = 4; 1364 reg->size = 4;
1377 return 0; 1365 return 0;
1378} 1366}
@@ -1382,9 +1370,7 @@ static int vidioc_s_register (struct file *file, void *fh,
1382{ 1370{
1383 struct cx88_core *core = ((struct cx8800_fh*)fh)->dev->core; 1371 struct cx88_core *core = ((struct cx8800_fh*)fh)->dev->core;
1384 1372
1385 if (!v4l2_chip_match_host(&reg->match)) 1373 cx_write(reg->reg & 0xfffffc, reg->val);
1386 return -EINVAL;
1387 cx_write(reg->reg & 0xffffff, reg->val);
1388 return 0; 1374 return 0;
1389} 1375}
1390#endif 1376#endif
@@ -1578,7 +1564,6 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
1578 .vidioc_s_frequency = vidioc_s_frequency, 1564 .vidioc_s_frequency = vidioc_s_frequency,
1579 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, 1565 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1580 .vidioc_unsubscribe_event = v4l2_event_unsubscribe, 1566 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1581 .vidioc_g_chip_ident = vidioc_g_chip_ident,
1582#ifdef CONFIG_VIDEO_ADV_DEBUG 1567#ifdef CONFIG_VIDEO_ADV_DEBUG
1583 .vidioc_g_register = vidioc_g_register, 1568 .vidioc_g_register = vidioc_g_register,
1584 .vidioc_s_register = vidioc_s_register, 1569 .vidioc_s_register = vidioc_s_register,
@@ -1612,7 +1597,6 @@ static const struct v4l2_ioctl_ops vbi_ioctl_ops = {
1612 .vidioc_s_tuner = vidioc_s_tuner, 1597 .vidioc_s_tuner = vidioc_s_tuner,
1613 .vidioc_g_frequency = vidioc_g_frequency, 1598 .vidioc_g_frequency = vidioc_g_frequency,
1614 .vidioc_s_frequency = vidioc_s_frequency, 1599 .vidioc_s_frequency = vidioc_s_frequency,
1615 .vidioc_g_chip_ident = vidioc_g_chip_ident,
1616#ifdef CONFIG_VIDEO_ADV_DEBUG 1600#ifdef CONFIG_VIDEO_ADV_DEBUG
1617 .vidioc_g_register = vidioc_g_register, 1601 .vidioc_g_register = vidioc_g_register,
1618 .vidioc_s_register = vidioc_s_register, 1602 .vidioc_s_register = vidioc_s_register,
@@ -1643,7 +1627,6 @@ static const struct v4l2_ioctl_ops radio_ioctl_ops = {
1643 .vidioc_s_frequency = vidioc_s_frequency, 1627 .vidioc_s_frequency = vidioc_s_frequency,
1644 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, 1628 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1645 .vidioc_unsubscribe_event = v4l2_event_unsubscribe, 1629 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1646 .vidioc_g_chip_ident = vidioc_g_chip_ident,
1647#ifdef CONFIG_VIDEO_ADV_DEBUG 1630#ifdef CONFIG_VIDEO_ADV_DEBUG
1648 .vidioc_g_register = vidioc_g_register, 1631 .vidioc_g_register = vidioc_g_register,
1649 .vidioc_s_register = vidioc_s_register, 1632 .vidioc_s_register = vidioc_s_register,
@@ -1794,7 +1777,7 @@ static int cx8800_initdev(struct pci_dev *pci_dev,
1794 1777
1795 /* load and configure helper modules */ 1778 /* load and configure helper modules */
1796 1779
1797 if (core->board.audio_chip == V4L2_IDENT_WM8775) { 1780 if (core->board.audio_chip == CX88_AUDIO_WM8775) {
1798 struct i2c_board_info wm8775_info = { 1781 struct i2c_board_info wm8775_info = {
1799 .type = "wm8775", 1782 .type = "wm8775",
1800 .addr = 0x36 >> 1, 1783 .addr = 0x36 >> 1,
@@ -1815,7 +1798,7 @@ static int cx8800_initdev(struct pci_dev *pci_dev,
1815 } 1798 }
1816 } 1799 }
1817 1800
1818 if (core->board.audio_chip == V4L2_IDENT_TVAUDIO) { 1801 if (core->board.audio_chip == CX88_AUDIO_TVAUDIO) {
1819 /* This probes for a tda9874 as is used on some 1802 /* This probes for a tda9874 as is used on some
1820 Pixelview Ultra boards. */ 1803 Pixelview Ultra boards. */
1821 v4l2_i2c_new_subdev(&core->v4l2_dev, &core->i2c_adap, 1804 v4l2_i2c_new_subdev(&core->v4l2_dev, &core->i2c_adap,
diff --git a/drivers/media/pci/cx88/cx88.h b/drivers/media/pci/cx88/cx88.h
index 51ce2c0e8bc1..afe0eaea81b4 100644
--- a/drivers/media/pci/cx88/cx88.h
+++ b/drivers/media/pci/cx88/cx88.h
@@ -30,7 +30,6 @@
30#include <media/tuner.h> 30#include <media/tuner.h>
31#include <media/tveeprom.h> 31#include <media/tveeprom.h>
32#include <media/videobuf-dma-sg.h> 32#include <media/videobuf-dma-sg.h>
33#include <media/v4l2-chip-ident.h>
34#include <media/cx2341x.h> 33#include <media/cx2341x.h>
35#include <media/videobuf-dvb.h> 34#include <media/videobuf-dvb.h>
36#include <media/ir-kbd-i2c.h> 35#include <media/ir-kbd-i2c.h>
@@ -259,6 +258,11 @@ struct cx88_input {
259 unsigned int audioroute:4; 258 unsigned int audioroute:4;
260}; 259};
261 260
261enum cx88_audio_chip {
262 CX88_AUDIO_WM8775,
263 CX88_AUDIO_TVAUDIO,
264};
265
262struct cx88_board { 266struct cx88_board {
263 const char *name; 267 const char *name;
264 unsigned int tuner_type; 268 unsigned int tuner_type;
@@ -269,7 +273,7 @@ struct cx88_board {
269 struct cx88_input input[MAX_CX88_INPUT]; 273 struct cx88_input input[MAX_CX88_INPUT];
270 struct cx88_input radio; 274 struct cx88_input radio;
271 enum cx88_board_type mpeg; 275 enum cx88_board_type mpeg;
272 unsigned int audio_chip; 276 enum cx88_audio_chip audio_chip;
273 int num_frontends; 277 int num_frontends;
274 278
275 /* Used for I2S devices */ 279 /* Used for I2S devices */
diff --git a/drivers/media/pci/dm1105/dm1105.c b/drivers/media/pci/dm1105/dm1105.c
index 026767bed5cd..ab797fe466d2 100644
--- a/drivers/media/pci/dm1105/dm1105.c
+++ b/drivers/media/pci/dm1105/dm1105.c
@@ -1241,18 +1241,7 @@ static struct pci_driver dm1105_driver = {
1241 .remove = dm1105_remove, 1241 .remove = dm1105_remove,
1242}; 1242};
1243 1243
1244static int __init dm1105_init(void) 1244module_pci_driver(dm1105_driver);
1245{
1246 return pci_register_driver(&dm1105_driver);
1247}
1248
1249static void __exit dm1105_exit(void)
1250{
1251 pci_unregister_driver(&dm1105_driver);
1252}
1253
1254module_init(dm1105_init);
1255module_exit(dm1105_exit);
1256 1245
1257MODULE_AUTHOR("Igor M. Liplianin <liplianin@me.by>"); 1246MODULE_AUTHOR("Igor M. Liplianin <liplianin@me.by>");
1258MODULE_DESCRIPTION("SDMC DM1105 DVB driver"); 1247MODULE_DESCRIPTION("SDMC DM1105 DVB driver");
diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
index b809bc868a9f..c08ae3eb9554 100644
--- a/drivers/media/pci/ivtv/ivtv-driver.c
+++ b/drivers/media/pci/ivtv/ivtv-driver.c
@@ -58,7 +58,6 @@
58#include <linux/dma-mapping.h> 58#include <linux/dma-mapping.h>
59#include <media/tveeprom.h> 59#include <media/tveeprom.h>
60#include <media/saa7115.h> 60#include <media/saa7115.h>
61#include <media/v4l2-chip-ident.h>
62#include "tuner-xc2028.h" 61#include "tuner-xc2028.h"
63 62
64/* If you have already X v4l cards, then set this to X. This way 63/* If you have already X v4l cards, then set this to X. This way
@@ -968,15 +967,10 @@ static void ivtv_load_and_init_modules(struct ivtv *itv)
968 } 967 }
969 968
970 if (hw & IVTV_HW_SAA711X) { 969 if (hw & IVTV_HW_SAA711X) {
971 struct v4l2_dbg_chip_ident v;
972
973 /* determine the exact saa711x model */ 970 /* determine the exact saa711x model */
974 itv->hw_flags &= ~IVTV_HW_SAA711X; 971 itv->hw_flags &= ~IVTV_HW_SAA711X;
975 972
976 v.match.type = V4L2_CHIP_MATCH_I2C_DRIVER; 973 if (strstr(itv->sd_video->name, "saa7114")) {
977 strlcpy(v.match.name, "saa7115", sizeof(v.match.name));
978 ivtv_call_hw(itv, IVTV_HW_SAA711X, core, g_chip_ident, &v);
979 if (v.ident == V4L2_IDENT_SAA7114) {
980 itv->hw_flags |= IVTV_HW_SAA7114; 974 itv->hw_flags |= IVTV_HW_SAA7114;
981 /* VBI is not yet supported by the saa7114 driver. */ 975 /* VBI is not yet supported by the saa7114 driver. */
982 itv->v4l2_cap &= ~(V4L2_CAP_SLICED_VBI_CAPTURE|V4L2_CAP_VBI_CAPTURE); 976 itv->v4l2_cap &= ~(V4L2_CAP_SLICED_VBI_CAPTURE|V4L2_CAP_VBI_CAPTURE);
diff --git a/drivers/media/pci/ivtv/ivtv-ioctl.c b/drivers/media/pci/ivtv/ivtv-ioctl.c
index 9cbbce0eaedc..807b275a847e 100644
--- a/drivers/media/pci/ivtv/ivtv-ioctl.c
+++ b/drivers/media/pci/ivtv/ivtv-ioctl.c
@@ -34,7 +34,6 @@
34#include "ivtv-cards.h" 34#include "ivtv-cards.h"
35#include <media/saa7127.h> 35#include <media/saa7127.h>
36#include <media/tveeprom.h> 36#include <media/tveeprom.h>
37#include <media/v4l2-chip-ident.h>
38#include <media/v4l2-event.h> 37#include <media/v4l2-event.h>
39#include <linux/dvb/audio.h> 38#include <linux/dvb/audio.h>
40 39
@@ -692,31 +691,13 @@ static int ivtv_s_fmt_vid_out_overlay(struct file *file, void *fh, struct v4l2_f
692 return ret; 691 return ret;
693} 692}
694 693
695static int ivtv_g_chip_ident(struct file *file, void *fh, struct v4l2_dbg_chip_ident *chip)
696{
697 struct ivtv *itv = fh2id(fh)->itv;
698
699 chip->ident = V4L2_IDENT_NONE;
700 chip->revision = 0;
701 if (chip->match.type == V4L2_CHIP_MATCH_HOST) {
702 if (v4l2_chip_match_host(&chip->match))
703 chip->ident = itv->has_cx23415 ? V4L2_IDENT_CX23415 : V4L2_IDENT_CX23416;
704 return 0;
705 }
706 if (chip->match.type != V4L2_CHIP_MATCH_I2C_DRIVER &&
707 chip->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
708 return -EINVAL;
709 /* TODO: is this correct? */
710 return ivtv_call_all_err(itv, core, g_chip_ident, chip);
711}
712
713#ifdef CONFIG_VIDEO_ADV_DEBUG 694#ifdef CONFIG_VIDEO_ADV_DEBUG
714static int ivtv_itvc(struct ivtv *itv, bool get, u64 reg, u64 *val) 695static int ivtv_itvc(struct ivtv *itv, bool get, u64 reg, u64 *val)
715{ 696{
716 volatile u8 __iomem *reg_start; 697 volatile u8 __iomem *reg_start;
717 698
718 if (!capable(CAP_SYS_ADMIN)) 699 if (reg & 0x3)
719 return -EPERM; 700 return -EINVAL;
720 if (reg >= IVTV_REG_OFFSET && reg < IVTV_REG_OFFSET + IVTV_REG_SIZE) 701 if (reg >= IVTV_REG_OFFSET && reg < IVTV_REG_OFFSET + IVTV_REG_SIZE)
721 reg_start = itv->reg_mem - IVTV_REG_OFFSET; 702 reg_start = itv->reg_mem - IVTV_REG_OFFSET;
722 else if (itv->has_cx23415 && reg >= IVTV_DECODER_OFFSET && 703 else if (itv->has_cx23415 && reg >= IVTV_DECODER_OFFSET &&
@@ -738,29 +719,16 @@ static int ivtv_g_register(struct file *file, void *fh, struct v4l2_dbg_register
738{ 719{
739 struct ivtv *itv = fh2id(fh)->itv; 720 struct ivtv *itv = fh2id(fh)->itv;
740 721
741 if (v4l2_chip_match_host(&reg->match)) { 722 reg->size = 4;
742 reg->size = 4; 723 return ivtv_itvc(itv, true, reg->reg, &reg->val);
743 return ivtv_itvc(itv, true, reg->reg, &reg->val);
744 }
745 /* TODO: subdev errors should not be ignored, this should become a
746 subdev helper function. */
747 ivtv_call_all(itv, core, g_register, reg);
748 return 0;
749} 724}
750 725
751static int ivtv_s_register(struct file *file, void *fh, const struct v4l2_dbg_register *reg) 726static int ivtv_s_register(struct file *file, void *fh, const struct v4l2_dbg_register *reg)
752{ 727{
753 struct ivtv *itv = fh2id(fh)->itv; 728 struct ivtv *itv = fh2id(fh)->itv;
729 u64 val = reg->val;
754 730
755 if (v4l2_chip_match_host(&reg->match)) { 731 return ivtv_itvc(itv, false, reg->reg, &val);
756 u64 val = reg->val;
757
758 return ivtv_itvc(itv, false, reg->reg, &val);
759 }
760 /* TODO: subdev errors should not be ignored, this should become a
761 subdev helper function. */
762 ivtv_call_all(itv, core, s_register, reg);
763 return 0;
764} 732}
765#endif 733#endif
766 734
@@ -1914,7 +1882,6 @@ static const struct v4l2_ioctl_ops ivtv_ioctl_ops = {
1914 .vidioc_try_fmt_vid_out_overlay = ivtv_try_fmt_vid_out_overlay, 1882 .vidioc_try_fmt_vid_out_overlay = ivtv_try_fmt_vid_out_overlay,
1915 .vidioc_try_fmt_sliced_vbi_out = ivtv_try_fmt_sliced_vbi_out, 1883 .vidioc_try_fmt_sliced_vbi_out = ivtv_try_fmt_sliced_vbi_out,
1916 .vidioc_g_sliced_vbi_cap = ivtv_g_sliced_vbi_cap, 1884 .vidioc_g_sliced_vbi_cap = ivtv_g_sliced_vbi_cap,
1917 .vidioc_g_chip_ident = ivtv_g_chip_ident,
1918#ifdef CONFIG_VIDEO_ADV_DEBUG 1885#ifdef CONFIG_VIDEO_ADV_DEBUG
1919 .vidioc_g_register = ivtv_g_register, 1886 .vidioc_g_register = ivtv_g_register,
1920 .vidioc_s_register = ivtv_s_register, 1887 .vidioc_s_register = ivtv_s_register,
diff --git a/drivers/media/pci/mantis/hopper_cards.c b/drivers/media/pci/mantis/hopper_cards.c
index 6fe9fe5293dc..104914a5bf06 100644
--- a/drivers/media/pci/mantis/hopper_cards.c
+++ b/drivers/media/pci/mantis/hopper_cards.c
@@ -260,18 +260,7 @@ static struct pci_driver hopper_pci_driver = {
260 .remove = hopper_pci_remove, 260 .remove = hopper_pci_remove,
261}; 261};
262 262
263static int hopper_init(void) 263module_pci_driver(hopper_pci_driver);
264{
265 return pci_register_driver(&hopper_pci_driver);
266}
267
268static void hopper_exit(void)
269{
270 return pci_unregister_driver(&hopper_pci_driver);
271}
272
273module_init(hopper_init);
274module_exit(hopper_exit);
275 264
276MODULE_DESCRIPTION("HOPPER driver"); 265MODULE_DESCRIPTION("HOPPER driver");
277MODULE_AUTHOR("Manu Abraham"); 266MODULE_AUTHOR("Manu Abraham");
diff --git a/drivers/media/pci/mantis/mantis_cards.c b/drivers/media/pci/mantis/mantis_cards.c
index 932a0d73a7f8..801fc55b6167 100644
--- a/drivers/media/pci/mantis/mantis_cards.c
+++ b/drivers/media/pci/mantis/mantis_cards.c
@@ -290,18 +290,7 @@ static struct pci_driver mantis_pci_driver = {
290 .remove = mantis_pci_remove, 290 .remove = mantis_pci_remove,
291}; 291};
292 292
293static int mantis_init(void) 293module_pci_driver(mantis_pci_driver);
294{
295 return pci_register_driver(&mantis_pci_driver);
296}
297
298static void mantis_exit(void)
299{
300 return pci_unregister_driver(&mantis_pci_driver);
301}
302
303module_init(mantis_init);
304module_exit(mantis_exit);
305 294
306MODULE_DESCRIPTION("MANTIS driver"); 295MODULE_DESCRIPTION("MANTIS driver");
307MODULE_AUTHOR("Manu Abraham"); 296MODULE_AUTHOR("Manu Abraham");
diff --git a/drivers/media/pci/mantis/mantis_vp1041.c b/drivers/media/pci/mantis/mantis_vp1041.c
index 07aa887a4b4a..07a20748b707 100644
--- a/drivers/media/pci/mantis/mantis_vp1041.c
+++ b/drivers/media/pci/mantis/mantis_vp1041.c
@@ -273,7 +273,7 @@ struct stb0899_config vp1041_stb0899_config = {
273 .demod_address = 0x68, /* 0xd0 >> 1 */ 273 .demod_address = 0x68, /* 0xd0 >> 1 */
274 274
275 .xtal_freq = 27000000, 275 .xtal_freq = 27000000,
276 .inversion = IQ_SWAP_ON, /* 1 */ 276 .inversion = IQ_SWAP_ON,
277 277
278 .lo_clk = 76500000, 278 .lo_clk = 76500000,
279 .hi_clk = 99000000, 279 .hi_clk = 99000000,
diff --git a/drivers/media/pci/pluto2/pluto2.c b/drivers/media/pci/pluto2/pluto2.c
index 2290faee5852..493828500055 100644
--- a/drivers/media/pci/pluto2/pluto2.c
+++ b/drivers/media/pci/pluto2/pluto2.c
@@ -796,18 +796,7 @@ static struct pci_driver pluto2_driver = {
796 .remove = pluto2_remove, 796 .remove = pluto2_remove,
797}; 797};
798 798
799static int __init pluto2_init(void) 799module_pci_driver(pluto2_driver);
800{
801 return pci_register_driver(&pluto2_driver);
802}
803
804static void __exit pluto2_exit(void)
805{
806 pci_unregister_driver(&pluto2_driver);
807}
808
809module_init(pluto2_init);
810module_exit(pluto2_exit);
811 800
812MODULE_AUTHOR("Andreas Oberritter <obi@linuxtv.org>"); 801MODULE_AUTHOR("Andreas Oberritter <obi@linuxtv.org>");
813MODULE_DESCRIPTION("Pluto2 driver"); 802MODULE_DESCRIPTION("Pluto2 driver");
diff --git a/drivers/media/pci/pt1/pt1.c b/drivers/media/pci/pt1/pt1.c
index e9211086df49..75ce14229e03 100644
--- a/drivers/media/pci/pt1/pt1.c
+++ b/drivers/media/pci/pt1/pt1.c
@@ -1225,20 +1225,7 @@ static struct pci_driver pt1_driver = {
1225 .id_table = pt1_id_table, 1225 .id_table = pt1_id_table,
1226}; 1226};
1227 1227
1228 1228module_pci_driver(pt1_driver);
1229static int __init pt1_init(void)
1230{
1231 return pci_register_driver(&pt1_driver);
1232}
1233
1234
1235static void __exit pt1_cleanup(void)
1236{
1237 pci_unregister_driver(&pt1_driver);
1238}
1239
1240module_init(pt1_init);
1241module_exit(pt1_cleanup);
1242 1229
1243MODULE_AUTHOR("Takahito HIRANO <hiranotaka@zng.info>"); 1230MODULE_AUTHOR("Takahito HIRANO <hiranotaka@zng.info>");
1244MODULE_DESCRIPTION("Earthsoft PT1/PT2 Driver"); 1231MODULE_DESCRIPTION("Earthsoft PT1/PT2 Driver");
diff --git a/drivers/media/pci/saa7134/saa6752hs.c b/drivers/media/pci/saa7134/saa6752hs.c
index f147b05bd860..8ac4b1f2322d 100644
--- a/drivers/media/pci/saa7134/saa6752hs.c
+++ b/drivers/media/pci/saa7134/saa6752hs.c
@@ -34,8 +34,8 @@
34#include <linux/types.h> 34#include <linux/types.h>
35#include <linux/videodev2.h> 35#include <linux/videodev2.h>
36#include <media/v4l2-device.h> 36#include <media/v4l2-device.h>
37#include <media/v4l2-ctrls.h>
37#include <media/v4l2-common.h> 38#include <media/v4l2-common.h>
38#include <media/v4l2-chip-ident.h>
39#include <linux/init.h> 39#include <linux/init.h>
40#include <linux/crc32.h> 40#include <linux/crc32.h>
41 41
@@ -92,7 +92,12 @@ static const struct v4l2_format v4l2_format_table[] =
92 92
93struct saa6752hs_state { 93struct saa6752hs_state {
94 struct v4l2_subdev sd; 94 struct v4l2_subdev sd;
95 int chip; 95 struct v4l2_ctrl_handler hdl;
96 struct { /* video bitrate mode control cluster */
97 struct v4l2_ctrl *video_bitrate_mode;
98 struct v4l2_ctrl *video_bitrate;
99 struct v4l2_ctrl *video_bitrate_peak;
100 };
96 u32 revision; 101 u32 revision;
97 int has_ac3; 102 int has_ac3;
98 struct saa6752hs_mpeg_params params; 103 struct saa6752hs_mpeg_params params;
@@ -362,316 +367,72 @@ static int saa6752hs_set_bitrate(struct i2c_client *client,
362 return 0; 367 return 0;
363} 368}
364 369
365 370static int saa6752hs_try_ctrl(struct v4l2_ctrl *ctrl)
366static int get_ctrl(int has_ac3, struct saa6752hs_mpeg_params *params,
367 struct v4l2_ext_control *ctrl)
368{ 371{
372 struct saa6752hs_state *h =
373 container_of(ctrl->handler, struct saa6752hs_state, hdl);
374
369 switch (ctrl->id) { 375 switch (ctrl->id) {
370 case V4L2_CID_MPEG_STREAM_TYPE:
371 ctrl->value = V4L2_MPEG_STREAM_TYPE_MPEG2_TS;
372 break;
373 case V4L2_CID_MPEG_STREAM_PID_PMT:
374 ctrl->value = params->ts_pid_pmt;
375 break;
376 case V4L2_CID_MPEG_STREAM_PID_AUDIO:
377 ctrl->value = params->ts_pid_audio;
378 break;
379 case V4L2_CID_MPEG_STREAM_PID_VIDEO:
380 ctrl->value = params->ts_pid_video;
381 break;
382 case V4L2_CID_MPEG_STREAM_PID_PCR:
383 ctrl->value = params->ts_pid_pcr;
384 break;
385 case V4L2_CID_MPEG_AUDIO_ENCODING:
386 ctrl->value = params->au_encoding;
387 break;
388 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
389 ctrl->value = params->au_l2_bitrate;
390 break;
391 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
392 if (!has_ac3)
393 return -EINVAL;
394 ctrl->value = params->au_ac3_bitrate;
395 break;
396 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
397 ctrl->value = V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000;
398 break;
399 case V4L2_CID_MPEG_VIDEO_ENCODING:
400 ctrl->value = V4L2_MPEG_VIDEO_ENCODING_MPEG_2;
401 break;
402 case V4L2_CID_MPEG_VIDEO_ASPECT:
403 ctrl->value = params->vi_aspect;
404 break;
405 case V4L2_CID_MPEG_VIDEO_BITRATE:
406 ctrl->value = params->vi_bitrate * 1000;
407 break;
408 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:
409 ctrl->value = params->vi_bitrate_peak * 1000;
410 break;
411 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: 376 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
412 ctrl->value = params->vi_bitrate_mode; 377 /* peak bitrate shall be >= normal bitrate */
378 if (ctrl->val == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR &&
379 h->video_bitrate_peak->val < h->video_bitrate->val)
380 h->video_bitrate_peak->val = h->video_bitrate->val;
413 break; 381 break;
414 default:
415 return -EINVAL;
416 } 382 }
417 return 0; 383 return 0;
418} 384}
419 385
420static int handle_ctrl(int has_ac3, struct saa6752hs_mpeg_params *params, 386static int saa6752hs_s_ctrl(struct v4l2_ctrl *ctrl)
421 struct v4l2_ext_control *ctrl, int set)
422{ 387{
423 int old = 0, new; 388 struct saa6752hs_state *h =
389 container_of(ctrl->handler, struct saa6752hs_state, hdl);
390 struct saa6752hs_mpeg_params *params = &h->params;
424 391
425 new = ctrl->value;
426 switch (ctrl->id) { 392 switch (ctrl->id) {
427 case V4L2_CID_MPEG_STREAM_TYPE: 393 case V4L2_CID_MPEG_STREAM_TYPE:
428 old = V4L2_MPEG_STREAM_TYPE_MPEG2_TS;
429 if (set && new != old)
430 return -ERANGE;
431 new = old;
432 break; 394 break;
433 case V4L2_CID_MPEG_STREAM_PID_PMT: 395 case V4L2_CID_MPEG_STREAM_PID_PMT:
434 old = params->ts_pid_pmt; 396 params->ts_pid_pmt = ctrl->val;
435 if (set && new > MPEG_PID_MAX)
436 return -ERANGE;
437 if (new > MPEG_PID_MAX)
438 new = MPEG_PID_MAX;
439 params->ts_pid_pmt = new;
440 break; 397 break;
441 case V4L2_CID_MPEG_STREAM_PID_AUDIO: 398 case V4L2_CID_MPEG_STREAM_PID_AUDIO:
442 old = params->ts_pid_audio; 399 params->ts_pid_audio = ctrl->val;
443 if (set && new > MPEG_PID_MAX)
444 return -ERANGE;
445 if (new > MPEG_PID_MAX)
446 new = MPEG_PID_MAX;
447 params->ts_pid_audio = new;
448 break; 400 break;
449 case V4L2_CID_MPEG_STREAM_PID_VIDEO: 401 case V4L2_CID_MPEG_STREAM_PID_VIDEO:
450 old = params->ts_pid_video; 402 params->ts_pid_video = ctrl->val;
451 if (set && new > MPEG_PID_MAX)
452 return -ERANGE;
453 if (new > MPEG_PID_MAX)
454 new = MPEG_PID_MAX;
455 params->ts_pid_video = new;
456 break; 403 break;
457 case V4L2_CID_MPEG_STREAM_PID_PCR: 404 case V4L2_CID_MPEG_STREAM_PID_PCR:
458 old = params->ts_pid_pcr; 405 params->ts_pid_pcr = ctrl->val;
459 if (set && new > MPEG_PID_MAX)
460 return -ERANGE;
461 if (new > MPEG_PID_MAX)
462 new = MPEG_PID_MAX;
463 params->ts_pid_pcr = new;
464 break; 406 break;
465 case V4L2_CID_MPEG_AUDIO_ENCODING: 407 case V4L2_CID_MPEG_AUDIO_ENCODING:
466 old = params->au_encoding; 408 params->au_encoding = ctrl->val;
467 if (set && new != V4L2_MPEG_AUDIO_ENCODING_LAYER_2 &&
468 (!has_ac3 || new != V4L2_MPEG_AUDIO_ENCODING_AC3))
469 return -ERANGE;
470 params->au_encoding = new;
471 break; 409 break;
472 case V4L2_CID_MPEG_AUDIO_L2_BITRATE: 410 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
473 old = params->au_l2_bitrate; 411 params->au_l2_bitrate = ctrl->val;
474 if (set && new != V4L2_MPEG_AUDIO_L2_BITRATE_256K &&
475 new != V4L2_MPEG_AUDIO_L2_BITRATE_384K)
476 return -ERANGE;
477 if (new <= V4L2_MPEG_AUDIO_L2_BITRATE_256K)
478 new = V4L2_MPEG_AUDIO_L2_BITRATE_256K;
479 else
480 new = V4L2_MPEG_AUDIO_L2_BITRATE_384K;
481 params->au_l2_bitrate = new;
482 break; 412 break;
483 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE: 413 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
484 if (!has_ac3) 414 params->au_ac3_bitrate = ctrl->val;
485 return -EINVAL;
486 old = params->au_ac3_bitrate;
487 if (set && new != V4L2_MPEG_AUDIO_AC3_BITRATE_256K &&
488 new != V4L2_MPEG_AUDIO_AC3_BITRATE_384K)
489 return -ERANGE;
490 if (new <= V4L2_MPEG_AUDIO_AC3_BITRATE_256K)
491 new = V4L2_MPEG_AUDIO_AC3_BITRATE_256K;
492 else
493 new = V4L2_MPEG_AUDIO_AC3_BITRATE_384K;
494 params->au_ac3_bitrate = new;
495 break; 415 break;
496 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: 416 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
497 old = V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000;
498 if (set && new != old)
499 return -ERANGE;
500 new = old;
501 break; 417 break;
502 case V4L2_CID_MPEG_VIDEO_ENCODING: 418 case V4L2_CID_MPEG_VIDEO_ENCODING:
503 old = V4L2_MPEG_VIDEO_ENCODING_MPEG_2;
504 if (set && new != old)
505 return -ERANGE;
506 new = old;
507 break; 419 break;
508 case V4L2_CID_MPEG_VIDEO_ASPECT: 420 case V4L2_CID_MPEG_VIDEO_ASPECT:
509 old = params->vi_aspect; 421 params->vi_aspect = ctrl->val;
510 if (set && new != V4L2_MPEG_VIDEO_ASPECT_16x9 &&
511 new != V4L2_MPEG_VIDEO_ASPECT_4x3)
512 return -ERANGE;
513 if (new != V4L2_MPEG_VIDEO_ASPECT_16x9)
514 new = V4L2_MPEG_VIDEO_ASPECT_4x3;
515 params->vi_aspect = new;
516 break;
517 case V4L2_CID_MPEG_VIDEO_BITRATE:
518 old = params->vi_bitrate * 1000;
519 new = 1000 * (new / 1000);
520 if (set && new > MPEG_VIDEO_TARGET_BITRATE_MAX * 1000)
521 return -ERANGE;
522 if (new > MPEG_VIDEO_TARGET_BITRATE_MAX * 1000)
523 new = MPEG_VIDEO_TARGET_BITRATE_MAX * 1000;
524 params->vi_bitrate = new / 1000;
525 break;
526 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:
527 old = params->vi_bitrate_peak * 1000;
528 new = 1000 * (new / 1000);
529 if (set && new > MPEG_VIDEO_TARGET_BITRATE_MAX * 1000)
530 return -ERANGE;
531 if (new > MPEG_VIDEO_TARGET_BITRATE_MAX * 1000)
532 new = MPEG_VIDEO_TARGET_BITRATE_MAX * 1000;
533 params->vi_bitrate_peak = new / 1000;
534 break; 422 break;
535 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: 423 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
536 old = params->vi_bitrate_mode; 424 params->vi_bitrate_mode = ctrl->val;
537 params->vi_bitrate_mode = new; 425 params->vi_bitrate = h->video_bitrate->val / 1000;
426 params->vi_bitrate_peak = h->video_bitrate_peak->val / 1000;
427 v4l2_ctrl_activate(h->video_bitrate_peak,
428 ctrl->val == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR);
538 break; 429 break;
539 default: 430 default:
540 return -EINVAL; 431 return -EINVAL;
541 } 432 }
542 ctrl->value = new;
543 return 0; 433 return 0;
544} 434}
545 435
546
547static int saa6752hs_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qctrl)
548{
549 struct saa6752hs_state *h = to_state(sd);
550 struct saa6752hs_mpeg_params *params = &h->params;
551 int err;
552
553 switch (qctrl->id) {
554 case V4L2_CID_MPEG_AUDIO_ENCODING:
555 return v4l2_ctrl_query_fill(qctrl,
556 V4L2_MPEG_AUDIO_ENCODING_LAYER_2,
557 h->has_ac3 ? V4L2_MPEG_AUDIO_ENCODING_AC3 :
558 V4L2_MPEG_AUDIO_ENCODING_LAYER_2,
559 1, V4L2_MPEG_AUDIO_ENCODING_LAYER_2);
560
561 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
562 return v4l2_ctrl_query_fill(qctrl,
563 V4L2_MPEG_AUDIO_L2_BITRATE_256K,
564 V4L2_MPEG_AUDIO_L2_BITRATE_384K, 1,
565 V4L2_MPEG_AUDIO_L2_BITRATE_256K);
566
567 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
568 if (!h->has_ac3)
569 return -EINVAL;
570 return v4l2_ctrl_query_fill(qctrl,
571 V4L2_MPEG_AUDIO_AC3_BITRATE_256K,
572 V4L2_MPEG_AUDIO_AC3_BITRATE_384K, 1,
573 V4L2_MPEG_AUDIO_AC3_BITRATE_256K);
574
575 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
576 return v4l2_ctrl_query_fill(qctrl,
577 V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000,
578 V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000, 1,
579 V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000);
580
581 case V4L2_CID_MPEG_VIDEO_ENCODING:
582 return v4l2_ctrl_query_fill(qctrl,
583 V4L2_MPEG_VIDEO_ENCODING_MPEG_2,
584 V4L2_MPEG_VIDEO_ENCODING_MPEG_2, 1,
585 V4L2_MPEG_VIDEO_ENCODING_MPEG_2);
586
587 case V4L2_CID_MPEG_VIDEO_ASPECT:
588 return v4l2_ctrl_query_fill(qctrl,
589 V4L2_MPEG_VIDEO_ASPECT_4x3,
590 V4L2_MPEG_VIDEO_ASPECT_16x9, 1,
591 V4L2_MPEG_VIDEO_ASPECT_4x3);
592
593 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:
594 err = v4l2_ctrl_query_fill(qctrl, 0, 27000000, 1, 8000000);
595 if (err == 0 &&
596 params->vi_bitrate_mode ==
597 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR)
598 qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE;
599 return err;
600
601 case V4L2_CID_MPEG_STREAM_TYPE:
602 return v4l2_ctrl_query_fill(qctrl,
603 V4L2_MPEG_STREAM_TYPE_MPEG2_TS,
604 V4L2_MPEG_STREAM_TYPE_MPEG2_TS, 1,
605 V4L2_MPEG_STREAM_TYPE_MPEG2_TS);
606
607 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
608 return v4l2_ctrl_query_fill(qctrl,
609 V4L2_MPEG_VIDEO_BITRATE_MODE_VBR,
610 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR, 1,
611 V4L2_MPEG_VIDEO_BITRATE_MODE_VBR);
612 case V4L2_CID_MPEG_VIDEO_BITRATE:
613 return v4l2_ctrl_query_fill(qctrl, 0, 27000000, 1, 6000000);
614 case V4L2_CID_MPEG_STREAM_PID_PMT:
615 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 16);
616 case V4L2_CID_MPEG_STREAM_PID_AUDIO:
617 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 260);
618 case V4L2_CID_MPEG_STREAM_PID_VIDEO:
619 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 256);
620 case V4L2_CID_MPEG_STREAM_PID_PCR:
621 return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 259);
622
623 default:
624 break;
625 }
626 return -EINVAL;
627}
628
629static int saa6752hs_querymenu(struct v4l2_subdev *sd, struct v4l2_querymenu *qmenu)
630{
631 static const u32 mpeg_audio_encoding[] = {
632 V4L2_MPEG_AUDIO_ENCODING_LAYER_2,
633 V4L2_CTRL_MENU_IDS_END
634 };
635 static const u32 mpeg_audio_ac3_encoding[] = {
636 V4L2_MPEG_AUDIO_ENCODING_LAYER_2,
637 V4L2_MPEG_AUDIO_ENCODING_AC3,
638 V4L2_CTRL_MENU_IDS_END
639 };
640 static u32 mpeg_audio_l2_bitrate[] = {
641 V4L2_MPEG_AUDIO_L2_BITRATE_256K,
642 V4L2_MPEG_AUDIO_L2_BITRATE_384K,
643 V4L2_CTRL_MENU_IDS_END
644 };
645 static u32 mpeg_audio_ac3_bitrate[] = {
646 V4L2_MPEG_AUDIO_AC3_BITRATE_256K,
647 V4L2_MPEG_AUDIO_AC3_BITRATE_384K,
648 V4L2_CTRL_MENU_IDS_END
649 };
650 struct saa6752hs_state *h = to_state(sd);
651 struct v4l2_queryctrl qctrl;
652 int err;
653
654 qctrl.id = qmenu->id;
655 err = saa6752hs_queryctrl(sd, &qctrl);
656 if (err)
657 return err;
658 switch (qmenu->id) {
659 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
660 return v4l2_ctrl_query_menu_valid_items(qmenu,
661 mpeg_audio_l2_bitrate);
662 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
663 if (!h->has_ac3)
664 return -EINVAL;
665 return v4l2_ctrl_query_menu_valid_items(qmenu,
666 mpeg_audio_ac3_bitrate);
667 case V4L2_CID_MPEG_AUDIO_ENCODING:
668 return v4l2_ctrl_query_menu_valid_items(qmenu,
669 h->has_ac3 ? mpeg_audio_ac3_encoding :
670 mpeg_audio_encoding);
671 }
672 return v4l2_ctrl_query_menu(qmenu, &qctrl, NULL);
673}
674
675static int saa6752hs_init(struct v4l2_subdev *sd, u32 leading_null_bytes) 436static int saa6752hs_init(struct v4l2_subdev *sd, u32 leading_null_bytes)
676{ 437{
677 unsigned char buf[9], buf2[4]; 438 unsigned char buf[9], buf2[4];
@@ -793,58 +554,6 @@ static int saa6752hs_init(struct v4l2_subdev *sd, u32 leading_null_bytes)
793 return 0; 554 return 0;
794} 555}
795 556
796static int saa6752hs_do_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ctrls, int set)
797{
798 struct saa6752hs_state *h = to_state(sd);
799 struct saa6752hs_mpeg_params params;
800 int i;
801
802 if (ctrls->ctrl_class != V4L2_CTRL_CLASS_MPEG)
803 return -EINVAL;
804
805 params = h->params;
806 for (i = 0; i < ctrls->count; i++) {
807 int err = handle_ctrl(h->has_ac3, &params, ctrls->controls + i, set);
808
809 if (err) {
810 ctrls->error_idx = i;
811 return err;
812 }
813 }
814 if (set)
815 h->params = params;
816 return 0;
817}
818
819static int saa6752hs_s_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ctrls)
820{
821 return saa6752hs_do_ext_ctrls(sd, ctrls, 1);
822}
823
824static int saa6752hs_try_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ctrls)
825{
826 return saa6752hs_do_ext_ctrls(sd, ctrls, 0);
827}
828
829static int saa6752hs_g_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ctrls)
830{
831 struct saa6752hs_state *h = to_state(sd);
832 int i;
833
834 if (ctrls->ctrl_class != V4L2_CTRL_CLASS_MPEG)
835 return -EINVAL;
836
837 for (i = 0; i < ctrls->count; i++) {
838 int err = get_ctrl(h->has_ac3, &h->params, ctrls->controls + i);
839
840 if (err) {
841 ctrls->error_idx = i;
842 return err;
843 }
844 }
845 return 0;
846}
847
848static int saa6752hs_g_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *f) 557static int saa6752hs_g_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *f)
849{ 558{
850 struct saa6752hs_state *h = to_state(sd); 559 struct saa6752hs_state *h = to_state(sd);
@@ -859,25 +568,11 @@ static int saa6752hs_g_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefm
859 return 0; 568 return 0;
860} 569}
861 570
862static int saa6752hs_s_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *f) 571static int saa6752hs_try_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *f)
863{ 572{
864 struct saa6752hs_state *h = to_state(sd);
865 int dist_352, dist_480, dist_720; 573 int dist_352, dist_480, dist_720;
866 574
867 if (f->code != V4L2_MBUS_FMT_FIXED) 575 f->code = V4L2_MBUS_FMT_FIXED;
868 return -EINVAL;
869
870 /*
871 FIXME: translate and round width/height into EMPRESS
872 subsample type:
873
874 type | PAL | NTSC
875 ---------------------------
876 SIF | 352x288 | 352x240
877 1/2 D1 | 352x576 | 352x480
878 2/3 D1 | 480x576 | 480x480
879 D1 | 720x576 | 720x480
880 */
881 576
882 dist_352 = abs(f->width - 352); 577 dist_352 = abs(f->width - 352);
883 dist_480 = abs(f->width - 480); 578 dist_480 = abs(f->width - 480);
@@ -885,59 +580,82 @@ static int saa6752hs_s_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefm
885 if (dist_720 < dist_480) { 580 if (dist_720 < dist_480) {
886 f->width = 720; 581 f->width = 720;
887 f->height = 576; 582 f->height = 576;
888 h->video_format = SAA6752HS_VF_D1;
889 } else if (dist_480 < dist_352) { 583 } else if (dist_480 < dist_352) {
890 f->width = 480; 584 f->width = 480;
891 f->height = 576; 585 f->height = 576;
892 h->video_format = SAA6752HS_VF_2_3_D1;
893 } else { 586 } else {
894 f->width = 352; 587 f->width = 352;
895 if (abs(f->height - 576) < 588 if (abs(f->height - 576) < abs(f->height - 288))
896 abs(f->height - 288)) {
897 f->height = 576; 589 f->height = 576;
898 h->video_format = SAA6752HS_VF_1_2_D1; 590 else
899 } else {
900 f->height = 288; 591 f->height = 288;
901 h->video_format = SAA6752HS_VF_SIF;
902 }
903 } 592 }
904 f->field = V4L2_FIELD_INTERLACED; 593 f->field = V4L2_FIELD_INTERLACED;
905 f->colorspace = V4L2_COLORSPACE_SMPTE170M; 594 f->colorspace = V4L2_COLORSPACE_SMPTE170M;
906 return 0; 595 return 0;
907} 596}
908 597
909static int saa6752hs_s_std(struct v4l2_subdev *sd, v4l2_std_id std) 598static int saa6752hs_s_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *f)
910{ 599{
911 struct saa6752hs_state *h = to_state(sd); 600 struct saa6752hs_state *h = to_state(sd);
912 601
913 h->standard = std; 602 if (f->code != V4L2_MBUS_FMT_FIXED)
603 return -EINVAL;
604
605 /*
606 FIXME: translate and round width/height into EMPRESS
607 subsample type:
608
609 type | PAL | NTSC
610 ---------------------------
611 SIF | 352x288 | 352x240
612 1/2 D1 | 352x576 | 352x480
613 2/3 D1 | 480x576 | 480x480
614 D1 | 720x576 | 720x480
615 */
616
617 saa6752hs_try_mbus_fmt(sd, f);
618 if (f->width == 720)
619 h->video_format = SAA6752HS_VF_D1;
620 else if (f->width == 480)
621 h->video_format = SAA6752HS_VF_2_3_D1;
622 else if (f->height == 576)
623 h->video_format = SAA6752HS_VF_1_2_D1;
624 else
625 h->video_format = SAA6752HS_VF_SIF;
914 return 0; 626 return 0;
915} 627}
916 628
917static int saa6752hs_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip) 629static int saa6752hs_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
918{ 630{
919 struct i2c_client *client = v4l2_get_subdevdata(sd);
920 struct saa6752hs_state *h = to_state(sd); 631 struct saa6752hs_state *h = to_state(sd);
921 632
922 return v4l2_chip_ident_i2c_client(client, 633 h->standard = std;
923 chip, h->chip, h->revision); 634 return 0;
924} 635}
925 636
926/* ----------------------------------------------------------------------- */ 637/* ----------------------------------------------------------------------- */
927 638
639static const struct v4l2_ctrl_ops saa6752hs_ctrl_ops = {
640 .try_ctrl = saa6752hs_try_ctrl,
641 .s_ctrl = saa6752hs_s_ctrl,
642};
643
928static const struct v4l2_subdev_core_ops saa6752hs_core_ops = { 644static const struct v4l2_subdev_core_ops saa6752hs_core_ops = {
929 .g_chip_ident = saa6752hs_g_chip_ident,
930 .init = saa6752hs_init, 645 .init = saa6752hs_init,
931 .queryctrl = saa6752hs_queryctrl, 646 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls,
932 .querymenu = saa6752hs_querymenu, 647 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls,
933 .g_ext_ctrls = saa6752hs_g_ext_ctrls, 648 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls,
934 .s_ext_ctrls = saa6752hs_s_ext_ctrls, 649 .g_ctrl = v4l2_subdev_g_ctrl,
935 .try_ext_ctrls = saa6752hs_try_ext_ctrls, 650 .s_ctrl = v4l2_subdev_s_ctrl,
651 .queryctrl = v4l2_subdev_queryctrl,
652 .querymenu = v4l2_subdev_querymenu,
936 .s_std = saa6752hs_s_std, 653 .s_std = saa6752hs_s_std,
937}; 654};
938 655
939static const struct v4l2_subdev_video_ops saa6752hs_video_ops = { 656static const struct v4l2_subdev_video_ops saa6752hs_video_ops = {
940 .s_mbus_fmt = saa6752hs_s_mbus_fmt, 657 .s_mbus_fmt = saa6752hs_s_mbus_fmt,
658 .try_mbus_fmt = saa6752hs_try_mbus_fmt,
941 .g_mbus_fmt = saa6752hs_g_mbus_fmt, 659 .g_mbus_fmt = saa6752hs_g_mbus_fmt,
942}; 660};
943 661
@@ -951,6 +669,7 @@ static int saa6752hs_probe(struct i2c_client *client,
951{ 669{
952 struct saa6752hs_state *h = kzalloc(sizeof(*h), GFP_KERNEL); 670 struct saa6752hs_state *h = kzalloc(sizeof(*h), GFP_KERNEL);
953 struct v4l2_subdev *sd; 671 struct v4l2_subdev *sd;
672 struct v4l2_ctrl_handler *hdl;
954 u8 addr = 0x13; 673 u8 addr = 0x13;
955 u8 data[12]; 674 u8 data[12];
956 675
@@ -963,15 +682,88 @@ static int saa6752hs_probe(struct i2c_client *client,
963 682
964 i2c_master_send(client, &addr, 1); 683 i2c_master_send(client, &addr, 1);
965 i2c_master_recv(client, data, sizeof(data)); 684 i2c_master_recv(client, data, sizeof(data));
966 h->chip = V4L2_IDENT_SAA6752HS;
967 h->revision = (data[8] << 8) | data[9]; 685 h->revision = (data[8] << 8) | data[9];
968 h->has_ac3 = 0; 686 h->has_ac3 = 0;
969 if (h->revision == 0x0206) { 687 if (h->revision == 0x0206) {
970 h->chip = V4L2_IDENT_SAA6752HS_AC3;
971 h->has_ac3 = 1; 688 h->has_ac3 = 1;
972 v4l_info(client, "support AC-3\n"); 689 v4l_info(client, "supports AC-3\n");
973 } 690 }
974 h->params = param_defaults; 691 h->params = param_defaults;
692
693 hdl = &h->hdl;
694 v4l2_ctrl_handler_init(hdl, 14);
695 v4l2_ctrl_new_std_menu(hdl, &saa6752hs_ctrl_ops,
696 V4L2_CID_MPEG_AUDIO_ENCODING,
697 h->has_ac3 ? V4L2_MPEG_AUDIO_ENCODING_AC3 :
698 V4L2_MPEG_AUDIO_ENCODING_LAYER_2,
699 0x0d, V4L2_MPEG_AUDIO_ENCODING_LAYER_2);
700
701 v4l2_ctrl_new_std_menu(hdl, &saa6752hs_ctrl_ops,
702 V4L2_CID_MPEG_AUDIO_L2_BITRATE,
703 V4L2_MPEG_AUDIO_L2_BITRATE_384K,
704 ~((1 << V4L2_MPEG_AUDIO_L2_BITRATE_256K) |
705 (1 << V4L2_MPEG_AUDIO_L2_BITRATE_384K)),
706 V4L2_MPEG_AUDIO_L2_BITRATE_256K);
707
708 if (h->has_ac3)
709 v4l2_ctrl_new_std_menu(hdl, &saa6752hs_ctrl_ops,
710 V4L2_CID_MPEG_AUDIO_AC3_BITRATE,
711 V4L2_MPEG_AUDIO_AC3_BITRATE_384K,
712 ~((1 << V4L2_MPEG_AUDIO_AC3_BITRATE_256K) |
713 (1 << V4L2_MPEG_AUDIO_AC3_BITRATE_384K)),
714 V4L2_MPEG_AUDIO_AC3_BITRATE_256K);
715
716 v4l2_ctrl_new_std_menu(hdl, &saa6752hs_ctrl_ops,
717 V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ,
718 V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000,
719 ~(1 << V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000),
720 V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000);
721
722 v4l2_ctrl_new_std_menu(hdl, &saa6752hs_ctrl_ops,
723 V4L2_CID_MPEG_VIDEO_ENCODING,
724 V4L2_MPEG_VIDEO_ENCODING_MPEG_2,
725 ~(1 << V4L2_MPEG_VIDEO_ENCODING_MPEG_2),
726 V4L2_MPEG_VIDEO_ENCODING_MPEG_2);
727
728 v4l2_ctrl_new_std_menu(hdl, &saa6752hs_ctrl_ops,
729 V4L2_CID_MPEG_VIDEO_ASPECT,
730 V4L2_MPEG_VIDEO_ASPECT_16x9, 0x01,
731 V4L2_MPEG_VIDEO_ASPECT_4x3);
732
733 h->video_bitrate_peak = v4l2_ctrl_new_std(hdl, &saa6752hs_ctrl_ops,
734 V4L2_CID_MPEG_VIDEO_BITRATE_PEAK,
735 1000000, 27000000, 1000, 8000000);
736
737 v4l2_ctrl_new_std_menu(hdl, &saa6752hs_ctrl_ops,
738 V4L2_CID_MPEG_STREAM_TYPE,
739 V4L2_MPEG_STREAM_TYPE_MPEG2_TS,
740 ~(1 << V4L2_MPEG_STREAM_TYPE_MPEG2_TS),
741 V4L2_MPEG_STREAM_TYPE_MPEG2_TS);
742
743 h->video_bitrate_mode = v4l2_ctrl_new_std_menu(hdl, &saa6752hs_ctrl_ops,
744 V4L2_CID_MPEG_VIDEO_BITRATE_MODE,
745 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR, 0,
746 V4L2_MPEG_VIDEO_BITRATE_MODE_VBR);
747 h->video_bitrate = v4l2_ctrl_new_std(hdl, &saa6752hs_ctrl_ops,
748 V4L2_CID_MPEG_VIDEO_BITRATE, 1000000, 27000000, 1000, 6000000);
749 v4l2_ctrl_new_std(hdl, &saa6752hs_ctrl_ops,
750 V4L2_CID_MPEG_STREAM_PID_PMT, 0, (1 << 14) - 1, 1, 16);
751 v4l2_ctrl_new_std(hdl, &saa6752hs_ctrl_ops,
752 V4L2_CID_MPEG_STREAM_PID_AUDIO, 0, (1 << 14) - 1, 1, 260);
753 v4l2_ctrl_new_std(hdl, &saa6752hs_ctrl_ops,
754 V4L2_CID_MPEG_STREAM_PID_VIDEO, 0, (1 << 14) - 1, 1, 256);
755 v4l2_ctrl_new_std(hdl, &saa6752hs_ctrl_ops,
756 V4L2_CID_MPEG_STREAM_PID_PCR, 0, (1 << 14) - 1, 1, 259);
757 sd->ctrl_handler = hdl;
758 if (hdl->error) {
759 int err = hdl->error;
760
761 v4l2_ctrl_handler_free(hdl);
762 kfree(h);
763 return err;
764 }
765 v4l2_ctrl_cluster(3, &h->video_bitrate_mode);
766 v4l2_ctrl_handler_setup(hdl);
975 h->standard = 0; /* Assume 625 input lines */ 767 h->standard = 0; /* Assume 625 input lines */
976 return 0; 768 return 0;
977} 769}
@@ -981,6 +773,7 @@ static int saa6752hs_remove(struct i2c_client *client)
981 struct v4l2_subdev *sd = i2c_get_clientdata(client); 773 struct v4l2_subdev *sd = i2c_get_clientdata(client);
982 774
983 v4l2_device_unregister_subdev(sd); 775 v4l2_device_unregister_subdev(sd);
776 v4l2_ctrl_handler_free(&to_state(sd)->hdl);
984 kfree(to_state(sd)); 777 kfree(to_state(sd));
985 return 0; 778 return 0;
986} 779}
@@ -1002,11 +795,3 @@ static struct i2c_driver saa6752hs_driver = {
1002}; 795};
1003 796
1004module_i2c_driver(saa6752hs_driver); 797module_i2c_driver(saa6752hs_driver);
1005
1006/*
1007 * Overrides for Emacs so that we follow Linus's tabbing style.
1008 * ---------------------------------------------------------------------------
1009 * Local variables:
1010 * c-basic-offset: 8
1011 * End:
1012 */
diff --git a/drivers/media/pci/saa7134/saa7134-empress.c b/drivers/media/pci/saa7134/saa7134-empress.c
index 66a70814004c..3022eb2a7925 100644
--- a/drivers/media/pci/saa7134/saa7134-empress.c
+++ b/drivers/media/pci/saa7134/saa7134-empress.c
@@ -28,7 +28,6 @@
28 28
29#include <media/saa6752hs.h> 29#include <media/saa6752hs.h>
30#include <media/v4l2-common.h> 30#include <media/v4l2-common.h>
31#include <media/v4l2-chip-ident.h>
32 31
33/* ------------------------------------------------------------------ */ 32/* ------------------------------------------------------------------ */
34 33
@@ -213,7 +212,7 @@ static int empress_enum_fmt_vid_cap(struct file *file, void *priv,
213 212
214 strlcpy(f->description, "MPEG TS", sizeof(f->description)); 213 strlcpy(f->description, "MPEG TS", sizeof(f->description));
215 f->pixelformat = V4L2_PIX_FMT_MPEG; 214 f->pixelformat = V4L2_PIX_FMT_MPEG;
216 215 f->flags = V4L2_FMT_FLAG_COMPRESSED;
217 return 0; 216 return 0;
218} 217}
219 218
@@ -228,6 +227,8 @@ static int empress_g_fmt_vid_cap(struct file *file, void *priv,
228 v4l2_fill_pix_format(&f->fmt.pix, &mbus_fmt); 227 v4l2_fill_pix_format(&f->fmt.pix, &mbus_fmt);
229 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; 228 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
230 f->fmt.pix.sizeimage = TS_PACKET_SIZE * dev->ts.nr_packets; 229 f->fmt.pix.sizeimage = TS_PACKET_SIZE * dev->ts.nr_packets;
230 f->fmt.pix.bytesperline = 0;
231 f->fmt.pix.priv = 0;
231 232
232 return 0; 233 return 0;
233} 234}
@@ -244,6 +245,8 @@ static int empress_s_fmt_vid_cap(struct file *file, void *priv,
244 245
245 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; 246 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
246 f->fmt.pix.sizeimage = TS_PACKET_SIZE * dev->ts.nr_packets; 247 f->fmt.pix.sizeimage = TS_PACKET_SIZE * dev->ts.nr_packets;
248 f->fmt.pix.bytesperline = 0;
249 f->fmt.pix.priv = 0;
247 250
248 return 0; 251 return 0;
249} 252}
@@ -252,9 +255,16 @@ static int empress_try_fmt_vid_cap(struct file *file, void *priv,
252 struct v4l2_format *f) 255 struct v4l2_format *f)
253{ 256{
254 struct saa7134_dev *dev = file->private_data; 257 struct saa7134_dev *dev = file->private_data;
258 struct v4l2_mbus_framefmt mbus_fmt;
259
260 v4l2_fill_mbus_format(&mbus_fmt, &f->fmt.pix, V4L2_MBUS_FMT_FIXED);
261 saa_call_all(dev, video, try_mbus_fmt, &mbus_fmt);
262 v4l2_fill_pix_format(&f->fmt.pix, &mbus_fmt);
255 263
256 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; 264 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
257 f->fmt.pix.sizeimage = TS_PACKET_SIZE * dev->ts.nr_packets; 265 f->fmt.pix.sizeimage = TS_PACKET_SIZE * dev->ts.nr_packets;
266 f->fmt.pix.bytesperline = 0;
267 f->fmt.pix.priv = 0;
258 268
259 return 0; 269 return 0;
260} 270}
@@ -413,21 +423,6 @@ static int empress_querymenu(struct file *file, void *priv,
413 return saa_call_empress(dev, core, querymenu, c); 423 return saa_call_empress(dev, core, querymenu, c);
414} 424}
415 425
416static int empress_g_chip_ident(struct file *file, void *fh,
417 struct v4l2_dbg_chip_ident *chip)
418{
419 struct saa7134_dev *dev = file->private_data;
420
421 chip->ident = V4L2_IDENT_NONE;
422 chip->revision = 0;
423 if (chip->match.type == V4L2_CHIP_MATCH_I2C_DRIVER &&
424 !strcmp(chip->match.name, "saa6752hs"))
425 return saa_call_empress(dev, core, g_chip_ident, chip);
426 if (chip->match.type == V4L2_CHIP_MATCH_I2C_ADDR)
427 return saa_call_empress(dev, core, g_chip_ident, chip);
428 return -EINVAL;
429}
430
431static int empress_s_std(struct file *file, void *priv, v4l2_std_id id) 426static int empress_s_std(struct file *file, void *priv, v4l2_std_id id)
432{ 427{
433 struct saa7134_dev *dev = file->private_data; 428 struct saa7134_dev *dev = file->private_data;
@@ -475,7 +470,6 @@ static const struct v4l2_ioctl_ops ts_ioctl_ops = {
475 .vidioc_querymenu = empress_querymenu, 470 .vidioc_querymenu = empress_querymenu,
476 .vidioc_g_ctrl = empress_g_ctrl, 471 .vidioc_g_ctrl = empress_g_ctrl,
477 .vidioc_s_ctrl = empress_s_ctrl, 472 .vidioc_s_ctrl = empress_s_ctrl,
478 .vidioc_g_chip_ident = empress_g_chip_ident,
479 .vidioc_s_std = empress_s_std, 473 .vidioc_s_std = empress_s_std,
480 .vidioc_g_std = empress_g_std, 474 .vidioc_g_std = empress_g_std,
481}; 475};
@@ -488,7 +482,6 @@ static struct video_device saa7134_empress_template = {
488 .ioctl_ops = &ts_ioctl_ops, 482 .ioctl_ops = &ts_ioctl_ops,
489 483
490 .tvnorms = SAA7134_NORMS, 484 .tvnorms = SAA7134_NORMS,
491 .current_norm = V4L2_STD_PAL,
492}; 485};
493 486
494static void empress_signal_update(struct work_struct *work) 487static void empress_signal_update(struct work_struct *work)
@@ -518,7 +511,7 @@ static int empress_init(struct saa7134_dev *dev)
518 if (NULL == dev->empress_dev) 511 if (NULL == dev->empress_dev)
519 return -ENOMEM; 512 return -ENOMEM;
520 *(dev->empress_dev) = saa7134_empress_template; 513 *(dev->empress_dev) = saa7134_empress_template;
521 dev->empress_dev->parent = &dev->pci->dev; 514 dev->empress_dev->v4l2_dev = &dev->v4l2_dev;
522 dev->empress_dev->release = video_device_release; 515 dev->empress_dev->release = video_device_release;
523 snprintf(dev->empress_dev->name, sizeof(dev->empress_dev->name), 516 snprintf(dev->empress_dev->name, sizeof(dev->empress_dev->name),
524 "%s empress (%s)", dev->name, 517 "%s empress (%s)", dev->name,
diff --git a/drivers/media/pci/saa7134/saa7134-video.c b/drivers/media/pci/saa7134/saa7134-video.c
index cc409380ee16..e12bbd8c3f0b 100644
--- a/drivers/media/pci/saa7134/saa7134-video.c
+++ b/drivers/media/pci/saa7134/saa7134-video.c
@@ -825,20 +825,22 @@ static int setup_clipping(struct saa7134_dev *dev, struct v4l2_clip *clips,
825 return 0; 825 return 0;
826} 826}
827 827
828static int verify_preview(struct saa7134_dev *dev, struct v4l2_window *win) 828static int verify_preview(struct saa7134_dev *dev, struct v4l2_window *win, bool try)
829{ 829{
830 enum v4l2_field field; 830 enum v4l2_field field;
831 int maxw, maxh; 831 int maxw, maxh;
832 832
833 if (NULL == dev->ovbuf.base) 833 if (!try && (dev->ovbuf.base == NULL || dev->ovfmt == NULL))
834 return -EINVAL; 834 return -EINVAL;
835 if (NULL == dev->ovfmt) 835 if (win->w.width < 48)
836 return -EINVAL; 836 win->w.width = 48;
837 if (win->w.width < 48 || win->w.height < 32) 837 if (win->w.height < 32)
838 return -EINVAL; 838 win->w.height = 32;
839 if (win->clipcount > 2048) 839 if (win->clipcount > 8)
840 return -EINVAL; 840 win->clipcount = 8;
841 841
842 win->chromakey = 0;
843 win->global_alpha = 0;
842 field = win->field; 844 field = win->field;
843 maxw = dev->crop_current.width; 845 maxw = dev->crop_current.width;
844 maxh = dev->crop_current.height; 846 maxh = dev->crop_current.height;
@@ -853,10 +855,9 @@ static int verify_preview(struct saa7134_dev *dev, struct v4l2_window *win)
853 case V4L2_FIELD_BOTTOM: 855 case V4L2_FIELD_BOTTOM:
854 maxh = maxh / 2; 856 maxh = maxh / 2;
855 break; 857 break;
856 case V4L2_FIELD_INTERLACED:
857 break;
858 default: 858 default:
859 return -EINVAL; 859 field = V4L2_FIELD_INTERLACED;
860 break;
860 } 861 }
861 862
862 win->field = field; 863 win->field = field;
@@ -872,20 +873,20 @@ static int start_preview(struct saa7134_dev *dev, struct saa7134_fh *fh)
872 unsigned long base,control,bpl; 873 unsigned long base,control,bpl;
873 int err; 874 int err;
874 875
875 err = verify_preview(dev,&fh->win); 876 err = verify_preview(dev, &dev->win, false);
876 if (0 != err) 877 if (0 != err)
877 return err; 878 return err;
878 879
879 dev->ovfield = fh->win.field; 880 dev->ovfield = dev->win.field;
880 dprintk("start_preview %dx%d+%d+%d %s field=%s\n", 881 dprintk("start_preview %dx%d+%d+%d %s field=%s\n",
881 fh->win.w.width,fh->win.w.height, 882 dev->win.w.width, dev->win.w.height,
882 fh->win.w.left,fh->win.w.top, 883 dev->win.w.left, dev->win.w.top,
883 dev->ovfmt->name,v4l2_field_names[dev->ovfield]); 884 dev->ovfmt->name, v4l2_field_names[dev->ovfield]);
884 885
885 /* setup window + clipping */ 886 /* setup window + clipping */
886 set_size(dev,TASK_B,fh->win.w.width,fh->win.w.height, 887 set_size(dev, TASK_B, dev->win.w.width, dev->win.w.height,
887 V4L2_FIELD_HAS_BOTH(dev->ovfield)); 888 V4L2_FIELD_HAS_BOTH(dev->ovfield));
888 setup_clipping(dev,fh->clips,fh->nclips, 889 setup_clipping(dev, dev->clips, dev->nclips,
889 V4L2_FIELD_HAS_BOTH(dev->ovfield)); 890 V4L2_FIELD_HAS_BOTH(dev->ovfield));
890 if (dev->ovfmt->yuv) 891 if (dev->ovfmt->yuv)
891 saa_andorb(SAA7134_DATA_PATH(TASK_B), 0x3f, 0x03); 892 saa_andorb(SAA7134_DATA_PATH(TASK_B), 0x3f, 0x03);
@@ -895,8 +896,8 @@ static int start_preview(struct saa7134_dev *dev, struct saa7134_fh *fh)
895 896
896 /* dma: setup channel 1 (= Video Task B) */ 897 /* dma: setup channel 1 (= Video Task B) */
897 base = (unsigned long)dev->ovbuf.base; 898 base = (unsigned long)dev->ovbuf.base;
898 base += dev->ovbuf.fmt.bytesperline * fh->win.w.top; 899 base += dev->ovbuf.fmt.bytesperline * dev->win.w.top;
899 base += dev->ovfmt->depth/8 * fh->win.w.left; 900 base += dev->ovfmt->depth/8 * dev->win.w.left;
900 bpl = dev->ovbuf.fmt.bytesperline; 901 bpl = dev->ovbuf.fmt.bytesperline;
901 control = SAA7134_RS_CONTROL_BURST_16; 902 control = SAA7134_RS_CONTROL_BURST_16;
902 if (dev->ovfmt->bswap) 903 if (dev->ovfmt->bswap)
@@ -1024,38 +1025,38 @@ static int buffer_prepare(struct videobuf_queue *q,
1024 int err; 1025 int err;
1025 1026
1026 /* sanity checks */ 1027 /* sanity checks */
1027 if (NULL == fh->fmt) 1028 if (NULL == dev->fmt)
1028 return -EINVAL; 1029 return -EINVAL;
1029 if (fh->width < 48 || 1030 if (dev->width < 48 ||
1030 fh->height < 32 || 1031 dev->height < 32 ||
1031 fh->width/4 > dev->crop_current.width || 1032 dev->width/4 > dev->crop_current.width ||
1032 fh->height/4 > dev->crop_current.height || 1033 dev->height/4 > dev->crop_current.height ||
1033 fh->width > dev->crop_bounds.width || 1034 dev->width > dev->crop_bounds.width ||
1034 fh->height > dev->crop_bounds.height) 1035 dev->height > dev->crop_bounds.height)
1035 return -EINVAL; 1036 return -EINVAL;
1036 size = (fh->width * fh->height * fh->fmt->depth) >> 3; 1037 size = (dev->width * dev->height * dev->fmt->depth) >> 3;
1037 if (0 != buf->vb.baddr && buf->vb.bsize < size) 1038 if (0 != buf->vb.baddr && buf->vb.bsize < size)
1038 return -EINVAL; 1039 return -EINVAL;
1039 1040
1040 dprintk("buffer_prepare [%d,size=%dx%d,bytes=%d,fields=%s,%s]\n", 1041 dprintk("buffer_prepare [%d,size=%dx%d,bytes=%d,fields=%s,%s]\n",
1041 vb->i,fh->width,fh->height,size,v4l2_field_names[field], 1042 vb->i, dev->width, dev->height, size, v4l2_field_names[field],
1042 fh->fmt->name); 1043 dev->fmt->name);
1043 if (buf->vb.width != fh->width || 1044 if (buf->vb.width != dev->width ||
1044 buf->vb.height != fh->height || 1045 buf->vb.height != dev->height ||
1045 buf->vb.size != size || 1046 buf->vb.size != size ||
1046 buf->vb.field != field || 1047 buf->vb.field != field ||
1047 buf->fmt != fh->fmt) { 1048 buf->fmt != dev->fmt) {
1048 saa7134_dma_free(q,buf); 1049 saa7134_dma_free(q,buf);
1049 } 1050 }
1050 1051
1051 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { 1052 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
1052 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb); 1053 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
1053 1054
1054 buf->vb.width = fh->width; 1055 buf->vb.width = dev->width;
1055 buf->vb.height = fh->height; 1056 buf->vb.height = dev->height;
1056 buf->vb.size = size; 1057 buf->vb.size = size;
1057 buf->vb.field = field; 1058 buf->vb.field = field;
1058 buf->fmt = fh->fmt; 1059 buf->fmt = dev->fmt;
1059 buf->pt = &fh->pt_cap; 1060 buf->pt = &fh->pt_cap;
1060 dev->video_q.curr = NULL; 1061 dev->video_q.curr = NULL;
1061 1062
@@ -1082,8 +1083,9 @@ static int
1082buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size) 1083buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size)
1083{ 1084{
1084 struct saa7134_fh *fh = q->priv_data; 1085 struct saa7134_fh *fh = q->priv_data;
1086 struct saa7134_dev *dev = fh->dev;
1085 1087
1086 *size = fh->fmt->depth * fh->width * fh->height >> 3; 1088 *size = dev->fmt->depth * dev->width * dev->height >> 3;
1087 if (0 == *count) 1089 if (0 == *count)
1088 *count = gbuffers; 1090 *count = gbuffers;
1089 *count = saa7134_buffer_count(*size,*count); 1091 *count = saa7134_buffer_count(*size,*count);
@@ -1287,15 +1289,17 @@ static int saa7134_s_ctrl(struct file *file, void *f, struct v4l2_control *c)
1287 1289
1288/* ------------------------------------------------------------------ */ 1290/* ------------------------------------------------------------------ */
1289 1291
1290static struct videobuf_queue* saa7134_queue(struct saa7134_fh *fh) 1292static struct videobuf_queue *saa7134_queue(struct file *file)
1291{ 1293{
1292 struct videobuf_queue* q = NULL; 1294 struct video_device *vdev = video_devdata(file);
1295 struct saa7134_fh *fh = file->private_data;
1296 struct videobuf_queue *q = NULL;
1293 1297
1294 switch (fh->type) { 1298 switch (vdev->vfl_type) {
1295 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 1299 case VFL_TYPE_GRABBER:
1296 q = &fh->cap; 1300 q = &fh->cap;
1297 break; 1301 break;
1298 case V4L2_BUF_TYPE_VBI_CAPTURE: 1302 case VFL_TYPE_VBI:
1299 q = &fh->vbi; 1303 q = &fh->vbi;
1300 break; 1304 break;
1301 default: 1305 default:
@@ -1304,12 +1308,14 @@ static struct videobuf_queue* saa7134_queue(struct saa7134_fh *fh)
1304 return q; 1308 return q;
1305} 1309}
1306 1310
1307static int saa7134_resource(struct saa7134_fh *fh) 1311static int saa7134_resource(struct file *file)
1308{ 1312{
1309 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) 1313 struct video_device *vdev = video_devdata(file);
1314
1315 if (vdev->vfl_type == VFL_TYPE_GRABBER)
1310 return RESOURCE_VIDEO; 1316 return RESOURCE_VIDEO;
1311 1317
1312 if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) 1318 if (vdev->vfl_type == VFL_TYPE_VBI)
1313 return RESOURCE_VBI; 1319 return RESOURCE_VBI;
1314 1320
1315 BUG(); 1321 BUG();
@@ -1321,23 +1327,6 @@ static int video_open(struct file *file)
1321 struct video_device *vdev = video_devdata(file); 1327 struct video_device *vdev = video_devdata(file);
1322 struct saa7134_dev *dev = video_drvdata(file); 1328 struct saa7134_dev *dev = video_drvdata(file);
1323 struct saa7134_fh *fh; 1329 struct saa7134_fh *fh;
1324 enum v4l2_buf_type type = 0;
1325 int radio = 0;
1326
1327 switch (vdev->vfl_type) {
1328 case VFL_TYPE_GRABBER:
1329 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1330 break;
1331 case VFL_TYPE_VBI:
1332 type = V4L2_BUF_TYPE_VBI_CAPTURE;
1333 break;
1334 case VFL_TYPE_RADIO:
1335 radio = 1;
1336 break;
1337 }
1338
1339 dprintk("open dev=%s radio=%d type=%s\n", video_device_node_name(vdev),
1340 radio, v4l2_type_names[type]);
1341 1330
1342 /* allocate + initialize per filehandle data */ 1331 /* allocate + initialize per filehandle data */
1343 fh = kzalloc(sizeof(*fh),GFP_KERNEL); 1332 fh = kzalloc(sizeof(*fh),GFP_KERNEL);
@@ -1347,11 +1336,6 @@ static int video_open(struct file *file)
1347 v4l2_fh_init(&fh->fh, vdev); 1336 v4l2_fh_init(&fh->fh, vdev);
1348 file->private_data = fh; 1337 file->private_data = fh;
1349 fh->dev = dev; 1338 fh->dev = dev;
1350 fh->radio = radio;
1351 fh->type = type;
1352 fh->fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24);
1353 fh->width = 720;
1354 fh->height = 576;
1355 1339
1356 videobuf_queue_sg_init(&fh->cap, &video_qops, 1340 videobuf_queue_sg_init(&fh->cap, &video_qops,
1357 &dev->pci->dev, &dev->slock, 1341 &dev->pci->dev, &dev->slock,
@@ -1368,7 +1352,7 @@ static int video_open(struct file *file)
1368 saa7134_pgtable_alloc(dev->pci,&fh->pt_cap); 1352 saa7134_pgtable_alloc(dev->pci,&fh->pt_cap);
1369 saa7134_pgtable_alloc(dev->pci,&fh->pt_vbi); 1353 saa7134_pgtable_alloc(dev->pci,&fh->pt_vbi);
1370 1354
1371 if (fh->radio) { 1355 if (vdev->vfl_type == VFL_TYPE_RADIO) {
1372 /* switch to radio mode */ 1356 /* switch to radio mode */
1373 saa7134_tvaudio_setinput(dev,&card(dev).radio); 1357 saa7134_tvaudio_setinput(dev,&card(dev).radio);
1374 saa_call_all(dev, tuner, s_radio); 1358 saa_call_all(dev, tuner, s_radio);
@@ -1384,19 +1368,20 @@ static int video_open(struct file *file)
1384static ssize_t 1368static ssize_t
1385video_read(struct file *file, char __user *data, size_t count, loff_t *ppos) 1369video_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
1386{ 1370{
1371 struct video_device *vdev = video_devdata(file);
1387 struct saa7134_fh *fh = file->private_data; 1372 struct saa7134_fh *fh = file->private_data;
1388 1373
1389 switch (fh->type) { 1374 switch (vdev->vfl_type) {
1390 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 1375 case VFL_TYPE_GRABBER:
1391 if (res_locked(fh->dev,RESOURCE_VIDEO)) 1376 if (res_locked(fh->dev,RESOURCE_VIDEO))
1392 return -EBUSY; 1377 return -EBUSY;
1393 return videobuf_read_one(saa7134_queue(fh), 1378 return videobuf_read_one(saa7134_queue(file),
1394 data, count, ppos, 1379 data, count, ppos,
1395 file->f_flags & O_NONBLOCK); 1380 file->f_flags & O_NONBLOCK);
1396 case V4L2_BUF_TYPE_VBI_CAPTURE: 1381 case VFL_TYPE_VBI:
1397 if (!res_get(fh->dev,fh,RESOURCE_VBI)) 1382 if (!res_get(fh->dev,fh,RESOURCE_VBI))
1398 return -EBUSY; 1383 return -EBUSY;
1399 return videobuf_read_stream(saa7134_queue(fh), 1384 return videobuf_read_stream(saa7134_queue(file),
1400 data, count, ppos, 1, 1385 data, count, ppos, 1,
1401 file->f_flags & O_NONBLOCK); 1386 file->f_flags & O_NONBLOCK);
1402 break; 1387 break;
@@ -1409,11 +1394,12 @@ video_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
1409static unsigned int 1394static unsigned int
1410video_poll(struct file *file, struct poll_table_struct *wait) 1395video_poll(struct file *file, struct poll_table_struct *wait)
1411{ 1396{
1397 struct video_device *vdev = video_devdata(file);
1412 struct saa7134_fh *fh = file->private_data; 1398 struct saa7134_fh *fh = file->private_data;
1413 struct videobuf_buffer *buf = NULL; 1399 struct videobuf_buffer *buf = NULL;
1414 unsigned int rc = 0; 1400 unsigned int rc = 0;
1415 1401
1416 if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type) 1402 if (vdev->vfl_type == VFL_TYPE_VBI)
1417 return videobuf_poll_stream(file, &fh->vbi, wait); 1403 return videobuf_poll_stream(file, &fh->vbi, wait);
1418 1404
1419 if (res_check(fh,RESOURCE_VIDEO)) { 1405 if (res_check(fh,RESOURCE_VIDEO)) {
@@ -1451,6 +1437,7 @@ err:
1451 1437
1452static int video_release(struct file *file) 1438static int video_release(struct file *file)
1453{ 1439{
1440 struct video_device *vdev = video_devdata(file);
1454 struct saa7134_fh *fh = file->private_data; 1441 struct saa7134_fh *fh = file->private_data;
1455 struct saa7134_dev *dev = fh->dev; 1442 struct saa7134_dev *dev = fh->dev;
1456 struct saa6588_command cmd; 1443 struct saa6588_command cmd;
@@ -1489,7 +1476,7 @@ static int video_release(struct file *file)
1489 saa_andorb(SAA7134_OFMT_DATA_B, 0x1f, 0); 1476 saa_andorb(SAA7134_OFMT_DATA_B, 0x1f, 0);
1490 1477
1491 saa_call_all(dev, core, s_power, 0); 1478 saa_call_all(dev, core, s_power, 0);
1492 if (fh->radio) 1479 if (vdev->vfl_type == VFL_TYPE_RADIO)
1493 saa_call_all(dev, core, ioctl, SAA6588_CMD_CLOSE, &cmd); 1480 saa_call_all(dev, core, ioctl, SAA6588_CMD_CLOSE, &cmd);
1494 1481
1495 /* free stuff */ 1482 /* free stuff */
@@ -1507,9 +1494,7 @@ static int video_release(struct file *file)
1507 1494
1508static int video_mmap(struct file *file, struct vm_area_struct * vma) 1495static int video_mmap(struct file *file, struct vm_area_struct * vma)
1509{ 1496{
1510 struct saa7134_fh *fh = file->private_data; 1497 return videobuf_mmap_mapper(saa7134_queue(file), vma);
1511
1512 return videobuf_mmap_mapper(saa7134_queue(fh), vma);
1513} 1498}
1514 1499
1515static ssize_t radio_read(struct file *file, char __user *data, 1500static ssize_t radio_read(struct file *file, char __user *data,
@@ -1570,15 +1555,18 @@ static int saa7134_g_fmt_vid_cap(struct file *file, void *priv,
1570 struct v4l2_format *f) 1555 struct v4l2_format *f)
1571{ 1556{
1572 struct saa7134_fh *fh = priv; 1557 struct saa7134_fh *fh = priv;
1558 struct saa7134_dev *dev = fh->dev;
1573 1559
1574 f->fmt.pix.width = fh->width; 1560 f->fmt.pix.width = dev->width;
1575 f->fmt.pix.height = fh->height; 1561 f->fmt.pix.height = dev->height;
1576 f->fmt.pix.field = fh->cap.field; 1562 f->fmt.pix.field = fh->cap.field;
1577 f->fmt.pix.pixelformat = fh->fmt->fourcc; 1563 f->fmt.pix.pixelformat = dev->fmt->fourcc;
1578 f->fmt.pix.bytesperline = 1564 f->fmt.pix.bytesperline =
1579 (f->fmt.pix.width * fh->fmt->depth) >> 3; 1565 (f->fmt.pix.width * dev->fmt->depth) >> 3;
1580 f->fmt.pix.sizeimage = 1566 f->fmt.pix.sizeimage =
1581 f->fmt.pix.height * f->fmt.pix.bytesperline; 1567 f->fmt.pix.height * f->fmt.pix.bytesperline;
1568 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
1569 f->fmt.pix.priv = 0;
1582 return 0; 1570 return 0;
1583} 1571}
1584 1572
@@ -1586,14 +1574,33 @@ static int saa7134_g_fmt_vid_overlay(struct file *file, void *priv,
1586 struct v4l2_format *f) 1574 struct v4l2_format *f)
1587{ 1575{
1588 struct saa7134_fh *fh = priv; 1576 struct saa7134_fh *fh = priv;
1577 struct saa7134_dev *dev = fh->dev;
1578 struct v4l2_clip __user *clips = f->fmt.win.clips;
1579 u32 clipcount = f->fmt.win.clipcount;
1580 int err = 0;
1581 int i;
1589 1582
1590 if (saa7134_no_overlay > 0) { 1583 if (saa7134_no_overlay > 0) {
1591 printk(KERN_ERR "V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n"); 1584 printk(KERN_ERR "V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n");
1592 return -EINVAL; 1585 return -EINVAL;
1593 } 1586 }
1594 f->fmt.win = fh->win; 1587 mutex_lock(&dev->lock);
1588 f->fmt.win = dev->win;
1589 f->fmt.win.clips = clips;
1590 if (clips == NULL)
1591 clipcount = 0;
1592 if (dev->nclips < clipcount)
1593 clipcount = dev->nclips;
1594 f->fmt.win.clipcount = clipcount;
1595
1596 for (i = 0; !err && i < clipcount; i++) {
1597 if (copy_to_user(&f->fmt.win.clips[i].c, &dev->clips[i].c,
1598 sizeof(struct v4l2_rect)))
1599 err = -EFAULT;
1600 }
1601 mutex_unlock(&dev->lock);
1595 1602
1596 return 0; 1603 return err;
1597} 1604}
1598 1605
1599static int saa7134_try_fmt_vid_cap(struct file *file, void *priv, 1606static int saa7134_try_fmt_vid_cap(struct file *file, void *priv,
@@ -1623,10 +1630,9 @@ static int saa7134_try_fmt_vid_cap(struct file *file, void *priv,
1623 case V4L2_FIELD_BOTTOM: 1630 case V4L2_FIELD_BOTTOM:
1624 maxh = maxh / 2; 1631 maxh = maxh / 2;
1625 break; 1632 break;
1626 case V4L2_FIELD_INTERLACED:
1627 break;
1628 default: 1633 default:
1629 return -EINVAL; 1634 field = V4L2_FIELD_INTERLACED;
1635 break;
1630 } 1636 }
1631 1637
1632 f->fmt.pix.field = field; 1638 f->fmt.pix.field = field;
@@ -1643,6 +1649,8 @@ static int saa7134_try_fmt_vid_cap(struct file *file, void *priv,
1643 (f->fmt.pix.width * fmt->depth) >> 3; 1649 (f->fmt.pix.width * fmt->depth) >> 3;
1644 f->fmt.pix.sizeimage = 1650 f->fmt.pix.sizeimage =
1645 f->fmt.pix.height * f->fmt.pix.bytesperline; 1651 f->fmt.pix.height * f->fmt.pix.bytesperline;
1652 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
1653 f->fmt.pix.priv = 0;
1646 1654
1647 return 0; 1655 return 0;
1648} 1656}
@@ -1658,22 +1666,25 @@ static int saa7134_try_fmt_vid_overlay(struct file *file, void *priv,
1658 return -EINVAL; 1666 return -EINVAL;
1659 } 1667 }
1660 1668
1661 return verify_preview(dev, &f->fmt.win); 1669 if (f->fmt.win.clips == NULL)
1670 f->fmt.win.clipcount = 0;
1671 return verify_preview(dev, &f->fmt.win, true);
1662} 1672}
1663 1673
1664static int saa7134_s_fmt_vid_cap(struct file *file, void *priv, 1674static int saa7134_s_fmt_vid_cap(struct file *file, void *priv,
1665 struct v4l2_format *f) 1675 struct v4l2_format *f)
1666{ 1676{
1667 struct saa7134_fh *fh = priv; 1677 struct saa7134_fh *fh = priv;
1678 struct saa7134_dev *dev = fh->dev;
1668 int err; 1679 int err;
1669 1680
1670 err = saa7134_try_fmt_vid_cap(file, priv, f); 1681 err = saa7134_try_fmt_vid_cap(file, priv, f);
1671 if (0 != err) 1682 if (0 != err)
1672 return err; 1683 return err;
1673 1684
1674 fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat); 1685 dev->fmt = format_by_fourcc(f->fmt.pix.pixelformat);
1675 fh->width = f->fmt.pix.width; 1686 dev->width = f->fmt.pix.width;
1676 fh->height = f->fmt.pix.height; 1687 dev->height = f->fmt.pix.height;
1677 fh->cap.field = f->fmt.pix.field; 1688 fh->cap.field = f->fmt.pix.field;
1678 return 0; 1689 return 0;
1679} 1690}
@@ -1690,20 +1701,19 @@ static int saa7134_s_fmt_vid_overlay(struct file *file, void *priv,
1690 printk(KERN_ERR "V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n"); 1701 printk(KERN_ERR "V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n");
1691 return -EINVAL; 1702 return -EINVAL;
1692 } 1703 }
1693 err = verify_preview(dev, &f->fmt.win); 1704 if (f->fmt.win.clips == NULL)
1705 f->fmt.win.clipcount = 0;
1706 err = verify_preview(dev, &f->fmt.win, true);
1694 if (0 != err) 1707 if (0 != err)
1695 return err; 1708 return err;
1696 1709
1697 mutex_lock(&dev->lock); 1710 mutex_lock(&dev->lock);
1698 1711
1699 fh->win = f->fmt.win; 1712 dev->win = f->fmt.win;
1700 fh->nclips = f->fmt.win.clipcount; 1713 dev->nclips = f->fmt.win.clipcount;
1701 1714
1702 if (fh->nclips > 8) 1715 if (copy_from_user(dev->clips, f->fmt.win.clips,
1703 fh->nclips = 8; 1716 sizeof(struct v4l2_clip) * dev->nclips)) {
1704
1705 if (copy_from_user(fh->clips, f->fmt.win.clips,
1706 sizeof(struct v4l2_clip)*fh->nclips)) {
1707 mutex_unlock(&dev->lock); 1717 mutex_unlock(&dev->lock);
1708 return -EFAULT; 1718 return -EFAULT;
1709 } 1719 }
@@ -2057,7 +2067,6 @@ static int saa7134_g_frequency(struct file *file, void *priv,
2057 if (0 != f->tuner) 2067 if (0 != f->tuner)
2058 return -EINVAL; 2068 return -EINVAL;
2059 2069
2060 f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
2061 saa_call_all(dev, tuner, g_frequency, f); 2070 saa_call_all(dev, tuner, g_frequency, f);
2062 2071
2063 return 0; 2072 return 0;
@@ -2071,10 +2080,6 @@ static int saa7134_s_frequency(struct file *file, void *priv,
2071 2080
2072 if (0 != f->tuner) 2081 if (0 != f->tuner)
2073 return -EINVAL; 2082 return -EINVAL;
2074 if (0 == fh->radio && V4L2_TUNER_ANALOG_TV != f->type)
2075 return -EINVAL;
2076 if (1 == fh->radio && V4L2_TUNER_RADIO != f->type)
2077 return -EINVAL;
2078 mutex_lock(&dev->lock); 2083 mutex_lock(&dev->lock);
2079 2084
2080 saa_call_all(dev, tuner, s_frequency, f); 2085 saa_call_all(dev, tuner, s_frequency, f);
@@ -2186,27 +2191,23 @@ static int saa7134_overlay(struct file *file, void *f, unsigned int on)
2186static int saa7134_reqbufs(struct file *file, void *priv, 2191static int saa7134_reqbufs(struct file *file, void *priv,
2187 struct v4l2_requestbuffers *p) 2192 struct v4l2_requestbuffers *p)
2188{ 2193{
2189 struct saa7134_fh *fh = priv; 2194 return videobuf_reqbufs(saa7134_queue(file), p);
2190 return videobuf_reqbufs(saa7134_queue(fh), p);
2191} 2195}
2192 2196
2193static int saa7134_querybuf(struct file *file, void *priv, 2197static int saa7134_querybuf(struct file *file, void *priv,
2194 struct v4l2_buffer *b) 2198 struct v4l2_buffer *b)
2195{ 2199{
2196 struct saa7134_fh *fh = priv; 2200 return videobuf_querybuf(saa7134_queue(file), b);
2197 return videobuf_querybuf(saa7134_queue(fh), b);
2198} 2201}
2199 2202
2200static int saa7134_qbuf(struct file *file, void *priv, struct v4l2_buffer *b) 2203static int saa7134_qbuf(struct file *file, void *priv, struct v4l2_buffer *b)
2201{ 2204{
2202 struct saa7134_fh *fh = priv; 2205 return videobuf_qbuf(saa7134_queue(file), b);
2203 return videobuf_qbuf(saa7134_queue(fh), b);
2204} 2206}
2205 2207
2206static int saa7134_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b) 2208static int saa7134_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b)
2207{ 2209{
2208 struct saa7134_fh *fh = priv; 2210 return videobuf_dqbuf(saa7134_queue(file), b,
2209 return videobuf_dqbuf(saa7134_queue(fh), b,
2210 file->f_flags & O_NONBLOCK); 2211 file->f_flags & O_NONBLOCK);
2211} 2212}
2212 2213
@@ -2215,7 +2216,7 @@ static int saa7134_streamon(struct file *file, void *priv,
2215{ 2216{
2216 struct saa7134_fh *fh = priv; 2217 struct saa7134_fh *fh = priv;
2217 struct saa7134_dev *dev = fh->dev; 2218 struct saa7134_dev *dev = fh->dev;
2218 int res = saa7134_resource(fh); 2219 int res = saa7134_resource(file);
2219 2220
2220 if (!res_get(dev, fh, res)) 2221 if (!res_get(dev, fh, res))
2221 return -EBUSY; 2222 return -EBUSY;
@@ -2227,11 +2228,11 @@ static int saa7134_streamon(struct file *file, void *priv,
2227 * Unfortunately, I lack register-level documentation to check the 2228 * Unfortunately, I lack register-level documentation to check the
2228 * Linux FIFO setup and confirm the perfect value. 2229 * Linux FIFO setup and confirm the perfect value.
2229 */ 2230 */
2230 pm_qos_add_request(&fh->qos_request, 2231 pm_qos_add_request(&dev->qos_request,
2231 PM_QOS_CPU_DMA_LATENCY, 2232 PM_QOS_CPU_DMA_LATENCY,
2232 20); 2233 20);
2233 2234
2234 return videobuf_streamon(saa7134_queue(fh)); 2235 return videobuf_streamon(saa7134_queue(file));
2235} 2236}
2236 2237
2237static int saa7134_streamoff(struct file *file, void *priv, 2238static int saa7134_streamoff(struct file *file, void *priv,
@@ -2240,11 +2241,11 @@ static int saa7134_streamoff(struct file *file, void *priv,
2240 int err; 2241 int err;
2241 struct saa7134_fh *fh = priv; 2242 struct saa7134_fh *fh = priv;
2242 struct saa7134_dev *dev = fh->dev; 2243 struct saa7134_dev *dev = fh->dev;
2243 int res = saa7134_resource(fh); 2244 int res = saa7134_resource(file);
2244 2245
2245 pm_qos_remove_request(&fh->qos_request); 2246 pm_qos_remove_request(&dev->qos_request);
2246 2247
2247 err = videobuf_streamoff(saa7134_queue(fh)); 2248 err = videobuf_streamoff(saa7134_queue(file));
2248 if (err < 0) 2249 if (err < 0)
2249 return err; 2250 return err;
2250 res_free(dev, fh, res); 2251 res_free(dev, fh, res);
@@ -2258,9 +2259,7 @@ static int vidioc_g_register (struct file *file, void *priv,
2258 struct saa7134_fh *fh = priv; 2259 struct saa7134_fh *fh = priv;
2259 struct saa7134_dev *dev = fh->dev; 2260 struct saa7134_dev *dev = fh->dev;
2260 2261
2261 if (!v4l2_chip_match_host(&reg->match)) 2262 reg->val = saa_readb(reg->reg & 0xffffff);
2262 return -EINVAL;
2263 reg->val = saa_readb(reg->reg);
2264 reg->size = 1; 2263 reg->size = 1;
2265 return 0; 2264 return 0;
2266} 2265}
@@ -2271,9 +2270,7 @@ static int vidioc_s_register (struct file *file, void *priv,
2271 struct saa7134_fh *fh = priv; 2270 struct saa7134_fh *fh = priv;
2272 struct saa7134_dev *dev = fh->dev; 2271 struct saa7134_dev *dev = fh->dev;
2273 2272
2274 if (!v4l2_chip_match_host(&reg->match)) 2273 saa_writeb(reg->reg & 0xffffff, reg->val);
2275 return -EINVAL;
2276 saa_writeb(reg->reg&0xffffff, reg->val);
2277 return 0; 2274 return 0;
2278} 2275}
2279#endif 2276#endif
@@ -2287,9 +2284,7 @@ static int radio_g_tuner(struct file *file, void *priv,
2287 if (0 != t->index) 2284 if (0 != t->index)
2288 return -EINVAL; 2285 return -EINVAL;
2289 2286
2290 memset(t, 0, sizeof(*t));
2291 strcpy(t->name, "Radio"); 2287 strcpy(t->name, "Radio");
2292 t->type = V4L2_TUNER_RADIO;
2293 2288
2294 saa_call_all(dev, tuner, g_tuner, t); 2289 saa_call_all(dev, tuner, g_tuner, t);
2295 t->audmode &= V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO; 2290 t->audmode &= V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO;
@@ -2443,7 +2438,6 @@ struct video_device saa7134_video_template = {
2443 .fops = &video_fops, 2438 .fops = &video_fops,
2444 .ioctl_ops = &video_ioctl_ops, 2439 .ioctl_ops = &video_ioctl_ops,
2445 .tvnorms = SAA7134_NORMS, 2440 .tvnorms = SAA7134_NORMS,
2446 .current_norm = V4L2_STD_PAL,
2447}; 2441};
2448 2442
2449struct video_device saa7134_radio_template = { 2443struct video_device saa7134_radio_template = {
@@ -2480,6 +2474,16 @@ int saa7134_video_init1(struct saa7134_dev *dev)
2480 dev->video_q.timeout.function = saa7134_buffer_timeout; 2474 dev->video_q.timeout.function = saa7134_buffer_timeout;
2481 dev->video_q.timeout.data = (unsigned long)(&dev->video_q); 2475 dev->video_q.timeout.data = (unsigned long)(&dev->video_q);
2482 dev->video_q.dev = dev; 2476 dev->video_q.dev = dev;
2477 dev->fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24);
2478 dev->width = 720;
2479 dev->height = 576;
2480 dev->win.w.width = dev->width;
2481 dev->win.w.height = dev->height;
2482 dev->win.field = V4L2_FIELD_INTERLACED;
2483 dev->ovbuf.fmt.width = dev->width;
2484 dev->ovbuf.fmt.height = dev->height;
2485 dev->ovbuf.fmt.pixelformat = dev->fmt->fourcc;
2486 dev->ovbuf.fmt.colorspace = V4L2_COLORSPACE_SMPTE170M;
2483 2487
2484 if (saa7134_boards[dev->board].video_out) 2488 if (saa7134_boards[dev->board].video_out)
2485 saa7134_videoport_init(dev); 2489 saa7134_videoport_init(dev);
diff --git a/drivers/media/pci/saa7134/saa7134.h b/drivers/media/pci/saa7134/saa7134.h
index d2ad16c1569a..8d1453a48014 100644
--- a/drivers/media/pci/saa7134/saa7134.h
+++ b/drivers/media/pci/saa7134/saa7134.h
@@ -471,19 +471,9 @@ struct saa7134_dmaqueue {
471struct saa7134_fh { 471struct saa7134_fh {
472 struct v4l2_fh fh; 472 struct v4l2_fh fh;
473 struct saa7134_dev *dev; 473 struct saa7134_dev *dev;
474 unsigned int radio;
475 enum v4l2_buf_type type;
476 unsigned int resources; 474 unsigned int resources;
477 struct pm_qos_request qos_request;
478
479 /* video overlay */
480 struct v4l2_window win;
481 struct v4l2_clip clips[8];
482 unsigned int nclips;
483 475
484 /* video capture */ 476 /* video capture */
485 struct saa7134_format *fmt;
486 unsigned int width,height;
487 struct videobuf_queue cap; 477 struct videobuf_queue cap;
488 struct saa7134_pgtable pt_cap; 478 struct saa7134_pgtable pt_cap;
489 479
@@ -592,12 +582,19 @@ struct saa7134_dev {
592 struct saa7134_format *ovfmt; 582 struct saa7134_format *ovfmt;
593 unsigned int ovenable; 583 unsigned int ovenable;
594 enum v4l2_field ovfield; 584 enum v4l2_field ovfield;
585 struct v4l2_window win;
586 struct v4l2_clip clips[8];
587 unsigned int nclips;
588
595 589
596 /* video+ts+vbi capture */ 590 /* video+ts+vbi capture */
597 struct saa7134_dmaqueue video_q; 591 struct saa7134_dmaqueue video_q;
598 struct saa7134_dmaqueue vbi_q; 592 struct saa7134_dmaqueue vbi_q;
599 unsigned int video_fieldcount; 593 unsigned int video_fieldcount;
600 unsigned int vbi_fieldcount; 594 unsigned int vbi_fieldcount;
595 struct saa7134_format *fmt;
596 unsigned int width, height;
597 struct pm_qos_request qos_request;
601 598
602 /* various v4l controls */ 599 /* various v4l controls */
603 struct saa7134_tvnorm *tvnorm; /* video */ 600 struct saa7134_tvnorm *tvnorm; /* video */
diff --git a/drivers/media/pci/saa7146/mxb.c b/drivers/media/pci/saa7146/mxb.c
index 71e8bead321b..33abe332d175 100644
--- a/drivers/media/pci/saa7146/mxb.c
+++ b/drivers/media/pci/saa7146/mxb.c
@@ -669,14 +669,10 @@ static int vidioc_g_register(struct file *file, void *fh, struct v4l2_dbg_regist
669{ 669{
670 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev; 670 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
671 671
672 if (!capable(CAP_SYS_ADMIN)) 672 if (reg->reg > pci_resource_len(dev->pci, 0) - 4)
673 return -EPERM; 673 return -EINVAL;
674 if (v4l2_chip_match_host(&reg->match)) { 674 reg->val = saa7146_read(dev, reg->reg);
675 reg->val = saa7146_read(dev, reg->reg); 675 reg->size = 4;
676 reg->size = 4;
677 return 0;
678 }
679 call_all(dev, core, g_register, reg);
680 return 0; 676 return 0;
681} 677}
682 678
@@ -684,13 +680,10 @@ static int vidioc_s_register(struct file *file, void *fh, const struct v4l2_dbg_
684{ 680{
685 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev; 681 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
686 682
687 if (!capable(CAP_SYS_ADMIN)) 683 if (reg->reg > pci_resource_len(dev->pci, 0) - 4)
688 return -EPERM; 684 return -EINVAL;
689 if (v4l2_chip_match_host(&reg->match)) { 685 saa7146_write(dev, reg->reg, reg->val);
690 saa7146_write(dev, reg->reg, reg->val); 686 return 0;
691 return 0;
692 }
693 return call_all(dev, core, s_register, reg);
694} 687}
695#endif 688#endif
696 689
diff --git a/drivers/media/pci/saa7164/saa7164-core.c b/drivers/media/pci/saa7164/saa7164-core.c
index 7618fdae811e..d37ee37aaefe 100644
--- a/drivers/media/pci/saa7164/saa7164-core.c
+++ b/drivers/media/pci/saa7164/saa7164-core.c
@@ -1196,6 +1196,12 @@ static int saa7164_initdev(struct pci_dev *pci_dev,
1196 if (NULL == dev) 1196 if (NULL == dev)
1197 return -ENOMEM; 1197 return -ENOMEM;
1198 1198
1199 err = v4l2_device_register(&pci_dev->dev, &dev->v4l2_dev);
1200 if (err < 0) {
1201 dev_err(&pci_dev->dev, "v4l2_device_register failed\n");
1202 goto fail_free;
1203 }
1204
1199 /* pci init */ 1205 /* pci init */
1200 dev->pci = pci_dev; 1206 dev->pci = pci_dev;
1201 if (pci_enable_device(pci_dev)) { 1207 if (pci_enable_device(pci_dev)) {
@@ -1367,6 +1373,7 @@ fail_fw:
1367fail_irq: 1373fail_irq:
1368 saa7164_dev_unregister(dev); 1374 saa7164_dev_unregister(dev);
1369fail_free: 1375fail_free:
1376 v4l2_device_unregister(&dev->v4l2_dev);
1370 kfree(dev); 1377 kfree(dev);
1371 return err; 1378 return err;
1372} 1379}
@@ -1439,6 +1446,7 @@ static void saa7164_finidev(struct pci_dev *pci_dev)
1439 mutex_unlock(&devlist); 1446 mutex_unlock(&devlist);
1440 1447
1441 saa7164_dev_unregister(dev); 1448 saa7164_dev_unregister(dev);
1449 v4l2_device_unregister(&dev->v4l2_dev);
1442 kfree(dev); 1450 kfree(dev);
1443} 1451}
1444 1452
diff --git a/drivers/media/pci/saa7164/saa7164-encoder.c b/drivers/media/pci/saa7164/saa7164-encoder.c
index 0b74fb2300dd..9266965412c3 100644
--- a/drivers/media/pci/saa7164/saa7164-encoder.c
+++ b/drivers/media/pci/saa7164/saa7164-encoder.c
@@ -228,6 +228,7 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id id)
228 return -EINVAL; 228 return -EINVAL;
229 229
230 port->encodernorm = saa7164_tvnorms[i]; 230 port->encodernorm = saa7164_tvnorms[i];
231 port->std = id;
231 232
232 /* Update the audio decoder while is not running in 233 /* Update the audio decoder while is not running in
233 * auto detect mode. 234 * auto detect mode.
@@ -239,6 +240,15 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id id)
239 return 0; 240 return 0;
240} 241}
241 242
243static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *id)
244{
245 struct saa7164_encoder_fh *fh = file->private_data;
246 struct saa7164_port *port = fh->port;
247
248 *id = port->std;
249 return 0;
250}
251
242static int vidioc_enum_input(struct file *file, void *priv, 252static int vidioc_enum_input(struct file *file, void *priv,
243 struct v4l2_input *i) 253 struct v4l2_input *i)
244{ 254{
@@ -1288,46 +1298,9 @@ static const struct v4l2_file_operations mpeg_fops = {
1288 .unlocked_ioctl = video_ioctl2, 1298 .unlocked_ioctl = video_ioctl2,
1289}; 1299};
1290 1300
1291static int saa7164_g_chip_ident(struct file *file, void *fh,
1292 struct v4l2_dbg_chip_ident *chip)
1293{
1294 struct saa7164_port *port = ((struct saa7164_encoder_fh *)fh)->port;
1295 struct saa7164_dev *dev = port->dev;
1296 dprintk(DBGLVL_ENC, "%s()\n", __func__);
1297
1298 return 0;
1299}
1300
1301#ifdef CONFIG_VIDEO_ADV_DEBUG
1302static int saa7164_g_register(struct file *file, void *fh,
1303 struct v4l2_dbg_register *reg)
1304{
1305 struct saa7164_port *port = ((struct saa7164_encoder_fh *)fh)->port;
1306 struct saa7164_dev *dev = port->dev;
1307 dprintk(DBGLVL_ENC, "%s()\n", __func__);
1308
1309 if (!capable(CAP_SYS_ADMIN))
1310 return -EPERM;
1311
1312 return 0;
1313}
1314
1315static int saa7164_s_register(struct file *file, void *fh,
1316 const struct v4l2_dbg_register *reg)
1317{
1318 struct saa7164_port *port = ((struct saa7164_encoder_fh *)fh)->port;
1319 struct saa7164_dev *dev = port->dev;
1320 dprintk(DBGLVL_ENC, "%s()\n", __func__);
1321
1322 if (!capable(CAP_SYS_ADMIN))
1323 return -EPERM;
1324
1325 return 0;
1326}
1327#endif
1328
1329static const struct v4l2_ioctl_ops mpeg_ioctl_ops = { 1301static const struct v4l2_ioctl_ops mpeg_ioctl_ops = {
1330 .vidioc_s_std = vidioc_s_std, 1302 .vidioc_s_std = vidioc_s_std,
1303 .vidioc_g_std = vidioc_g_std,
1331 .vidioc_enum_input = vidioc_enum_input, 1304 .vidioc_enum_input = vidioc_enum_input,
1332 .vidioc_g_input = vidioc_g_input, 1305 .vidioc_g_input = vidioc_g_input,
1333 .vidioc_s_input = vidioc_s_input, 1306 .vidioc_s_input = vidioc_s_input,
@@ -1346,11 +1319,6 @@ static const struct v4l2_ioctl_ops mpeg_ioctl_ops = {
1346 .vidioc_s_ext_ctrls = vidioc_s_ext_ctrls, 1319 .vidioc_s_ext_ctrls = vidioc_s_ext_ctrls,
1347 .vidioc_try_ext_ctrls = vidioc_try_ext_ctrls, 1320 .vidioc_try_ext_ctrls = vidioc_try_ext_ctrls,
1348 .vidioc_queryctrl = vidioc_queryctrl, 1321 .vidioc_queryctrl = vidioc_queryctrl,
1349 .vidioc_g_chip_ident = saa7164_g_chip_ident,
1350#ifdef CONFIG_VIDEO_ADV_DEBUG
1351 .vidioc_g_register = saa7164_g_register,
1352 .vidioc_s_register = saa7164_s_register,
1353#endif
1354}; 1322};
1355 1323
1356static struct video_device saa7164_mpeg_template = { 1324static struct video_device saa7164_mpeg_template = {
@@ -1359,7 +1327,6 @@ static struct video_device saa7164_mpeg_template = {
1359 .ioctl_ops = &mpeg_ioctl_ops, 1327 .ioctl_ops = &mpeg_ioctl_ops,
1360 .minor = -1, 1328 .minor = -1,
1361 .tvnorms = SAA7164_NORMS, 1329 .tvnorms = SAA7164_NORMS,
1362 .current_norm = V4L2_STD_NTSC_M,
1363}; 1330};
1364 1331
1365static struct video_device *saa7164_encoder_alloc( 1332static struct video_device *saa7164_encoder_alloc(
@@ -1381,7 +1348,7 @@ static struct video_device *saa7164_encoder_alloc(
1381 snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)", dev->name, 1348 snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)", dev->name,
1382 type, saa7164_boards[dev->board].name); 1349 type, saa7164_boards[dev->board].name);
1383 1350
1384 vfd->parent = &pci->dev; 1351 vfd->v4l2_dev = &dev->v4l2_dev;
1385 vfd->release = video_device_release; 1352 vfd->release = video_device_release;
1386 return vfd; 1353 return vfd;
1387} 1354}
@@ -1426,6 +1393,7 @@ int saa7164_encoder_register(struct saa7164_port *port)
1426 port->encoder_params.ctl_aspect = V4L2_MPEG_VIDEO_ASPECT_4x3; 1393 port->encoder_params.ctl_aspect = V4L2_MPEG_VIDEO_ASPECT_4x3;
1427 port->encoder_params.refdist = 1; 1394 port->encoder_params.refdist = 1;
1428 port->encoder_params.gop_size = SAA7164_ENCODER_DEFAULT_GOP_SIZE; 1395 port->encoder_params.gop_size = SAA7164_ENCODER_DEFAULT_GOP_SIZE;
1396 port->std = V4L2_STD_NTSC_M;
1429 1397
1430 if (port->encodernorm.id & V4L2_STD_525_60) 1398 if (port->encodernorm.id & V4L2_STD_525_60)
1431 port->height = 480; 1399 port->height = 480;
diff --git a/drivers/media/pci/saa7164/saa7164-vbi.c b/drivers/media/pci/saa7164/saa7164-vbi.c
index da224eb39b95..6e025fea2542 100644
--- a/drivers/media/pci/saa7164/saa7164-vbi.c
+++ b/drivers/media/pci/saa7164/saa7164-vbi.c
@@ -200,6 +200,7 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id id)
200 return -EINVAL; 200 return -EINVAL;
201 201
202 port->encodernorm = saa7164_tvnorms[i]; 202 port->encodernorm = saa7164_tvnorms[i];
203 port->std = id;
203 204
204 /* Update the audio decoder while is not running in 205 /* Update the audio decoder while is not running in
205 * auto detect mode. 206 * auto detect mode.
@@ -211,6 +212,15 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id id)
211 return 0; 212 return 0;
212} 213}
213 214
215static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *id)
216{
217 struct saa7164_encoder_fh *fh = file->private_data;
218 struct saa7164_port *port = fh->port;
219
220 *id = port->std;
221 return 0;
222}
223
214static int vidioc_enum_input(struct file *file, void *priv, 224static int vidioc_enum_input(struct file *file, void *priv,
215 struct v4l2_input *i) 225 struct v4l2_input *i)
216{ 226{
@@ -1236,6 +1246,7 @@ static const struct v4l2_file_operations vbi_fops = {
1236 1246
1237static const struct v4l2_ioctl_ops vbi_ioctl_ops = { 1247static const struct v4l2_ioctl_ops vbi_ioctl_ops = {
1238 .vidioc_s_std = vidioc_s_std, 1248 .vidioc_s_std = vidioc_s_std,
1249 .vidioc_g_std = vidioc_g_std,
1239 .vidioc_enum_input = vidioc_enum_input, 1250 .vidioc_enum_input = vidioc_enum_input,
1240 .vidioc_g_input = vidioc_g_input, 1251 .vidioc_g_input = vidioc_g_input,
1241 .vidioc_s_input = vidioc_s_input, 1252 .vidioc_s_input = vidioc_s_input,
@@ -1254,15 +1265,6 @@ static const struct v4l2_ioctl_ops vbi_ioctl_ops = {
1254 .vidioc_s_ext_ctrls = vidioc_s_ext_ctrls, 1265 .vidioc_s_ext_ctrls = vidioc_s_ext_ctrls,
1255 .vidioc_try_ext_ctrls = vidioc_try_ext_ctrls, 1266 .vidioc_try_ext_ctrls = vidioc_try_ext_ctrls,
1256 .vidioc_queryctrl = vidioc_queryctrl, 1267 .vidioc_queryctrl = vidioc_queryctrl,
1257#if 0
1258 .vidioc_g_chip_ident = saa7164_g_chip_ident,
1259#endif
1260#ifdef CONFIG_VIDEO_ADV_DEBUG
1261#if 0
1262 .vidioc_g_register = saa7164_g_register,
1263 .vidioc_s_register = saa7164_s_register,
1264#endif
1265#endif
1266 .vidioc_g_fmt_vbi_cap = saa7164_vbi_fmt, 1268 .vidioc_g_fmt_vbi_cap = saa7164_vbi_fmt,
1267 .vidioc_try_fmt_vbi_cap = saa7164_vbi_fmt, 1269 .vidioc_try_fmt_vbi_cap = saa7164_vbi_fmt,
1268 .vidioc_s_fmt_vbi_cap = saa7164_vbi_fmt, 1270 .vidioc_s_fmt_vbi_cap = saa7164_vbi_fmt,
@@ -1274,7 +1276,6 @@ static struct video_device saa7164_vbi_template = {
1274 .ioctl_ops = &vbi_ioctl_ops, 1276 .ioctl_ops = &vbi_ioctl_ops,
1275 .minor = -1, 1277 .minor = -1,
1276 .tvnorms = SAA7164_NORMS, 1278 .tvnorms = SAA7164_NORMS,
1277 .current_norm = V4L2_STD_NTSC_M,
1278}; 1279};
1279 1280
1280static struct video_device *saa7164_vbi_alloc( 1281static struct video_device *saa7164_vbi_alloc(
@@ -1296,7 +1297,7 @@ static struct video_device *saa7164_vbi_alloc(
1296 snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)", dev->name, 1297 snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)", dev->name,
1297 type, saa7164_boards[dev->board].name); 1298 type, saa7164_boards[dev->board].name);
1298 1299
1299 vfd->parent = &pci->dev; 1300 vfd->v4l2_dev = &dev->v4l2_dev;
1300 vfd->release = video_device_release; 1301 vfd->release = video_device_release;
1301 return vfd; 1302 return vfd;
1302} 1303}
@@ -1333,6 +1334,7 @@ int saa7164_vbi_register(struct saa7164_port *port)
1333 goto failed; 1334 goto failed;
1334 } 1335 }
1335 1336
1337 port->std = V4L2_STD_NTSC_M;
1336 video_set_drvdata(port->v4l_device, port); 1338 video_set_drvdata(port->v4l_device, port);
1337 result = video_register_device(port->v4l_device, 1339 result = video_register_device(port->v4l_device,
1338 VFL_TYPE_VBI, -1); 1340 VFL_TYPE_VBI, -1);
diff --git a/drivers/media/pci/saa7164/saa7164.h b/drivers/media/pci/saa7164/saa7164.h
index 437284e747c9..8b29e8990301 100644
--- a/drivers/media/pci/saa7164/saa7164.h
+++ b/drivers/media/pci/saa7164/saa7164.h
@@ -63,7 +63,7 @@
63#include <dmxdev.h> 63#include <dmxdev.h>
64#include <media/v4l2-common.h> 64#include <media/v4l2-common.h>
65#include <media/v4l2-ioctl.h> 65#include <media/v4l2-ioctl.h>
66#include <media/v4l2-chip-ident.h> 66#include <media/v4l2-device.h>
67 67
68#include "saa7164-reg.h" 68#include "saa7164-reg.h"
69#include "saa7164-types.h" 69#include "saa7164-types.h"
@@ -376,6 +376,7 @@ struct saa7164_port {
376 /* Encoder */ 376 /* Encoder */
377 /* Defaults established in saa7164-encoder.c */ 377 /* Defaults established in saa7164-encoder.c */
378 struct saa7164_tvnorm encodernorm; 378 struct saa7164_tvnorm encodernorm;
379 v4l2_std_id std;
379 u32 height; 380 u32 height;
380 u32 width; 381 u32 width;
381 u32 freq; 382 u32 freq;
@@ -427,6 +428,8 @@ struct saa7164_dev {
427 struct list_head devlist; 428 struct list_head devlist;
428 atomic_t refcount; 429 atomic_t refcount;
429 430
431 struct v4l2_device v4l2_dev;
432
430 /* pci stuff */ 433 /* pci stuff */
431 struct pci_dev *pci; 434 struct pci_dev *pci;
432 unsigned char pci_rev, pci_lat; 435 unsigned char pci_rev, pci_lat;
diff --git a/drivers/media/pci/sta2x11/sta2x11_vip.c b/drivers/media/pci/sta2x11/sta2x11_vip.c
index 7005695aa4bd..77edc113e485 100644
--- a/drivers/media/pci/sta2x11/sta2x11_vip.c
+++ b/drivers/media/pci/sta2x11/sta2x11_vip.c
@@ -1047,7 +1047,8 @@ static int sta2x11_vip_init_one(struct pci_dev *pdev,
1047 ret = sta2x11_vip_init_controls(vip); 1047 ret = sta2x11_vip_init_controls(vip);
1048 if (ret) 1048 if (ret)
1049 goto free_mem; 1049 goto free_mem;
1050 if (v4l2_device_register(&pdev->dev, &vip->v4l2_dev)) 1050 ret = v4l2_device_register(&pdev->dev, &vip->v4l2_dev);
1051 if (ret)
1051 goto free_mem; 1052 goto free_mem;
1052 1053
1053 dev_dbg(&pdev->dev, "BAR #0 at 0x%lx 0x%lx irq %d\n", 1054 dev_dbg(&pdev->dev, "BAR #0 at 0x%lx 0x%lx irq %d\n",
diff --git a/drivers/media/pci/ttpci/budget-av.c b/drivers/media/pci/ttpci/budget-av.c
index 1f8b1bb0bf9f..0ba3875af22e 100644
--- a/drivers/media/pci/ttpci/budget-av.c
+++ b/drivers/media/pci/ttpci/budget-av.c
@@ -1128,7 +1128,7 @@ static struct stb0899_config knc1_dvbs2_config = {
1128// .ts_pfbit_toggle = STB0899_MPEG_NORMAL, /* DirecTV, MPEG toggling seq */ 1128// .ts_pfbit_toggle = STB0899_MPEG_NORMAL, /* DirecTV, MPEG toggling seq */
1129 1129
1130 .xtal_freq = 27000000, 1130 .xtal_freq = 27000000,
1131 .inversion = IQ_SWAP_OFF, /* 1 */ 1131 .inversion = IQ_SWAP_OFF,
1132 1132
1133 .lo_clk = 76500000, 1133 .lo_clk = 76500000,
1134 .hi_clk = 90000000, 1134 .hi_clk = 90000000,
diff --git a/drivers/media/pci/ttpci/budget-ci.c b/drivers/media/pci/ttpci/budget-ci.c
index 98e524178765..0acf9202103d 100644
--- a/drivers/media/pci/ttpci/budget-ci.c
+++ b/drivers/media/pci/ttpci/budget-ci.c
@@ -1280,7 +1280,7 @@ static struct stb0899_config tt3200_config = {
1280 .demod_address = 0x68, 1280 .demod_address = 0x68,
1281 1281
1282 .xtal_freq = 27000000, 1282 .xtal_freq = 27000000,
1283 .inversion = IQ_SWAP_ON, /* 1 */ 1283 .inversion = IQ_SWAP_ON,
1284 1284
1285 .lo_clk = 76500000, 1285 .lo_clk = 76500000,
1286 .hi_clk = 99000000, 1286 .hi_clk = 99000000,
diff --git a/drivers/media/pci/zoran/zoran_card.c b/drivers/media/pci/zoran/zoran_card.c
index bb53d2488ad0..923d59a321f8 100644
--- a/drivers/media/pci/zoran/zoran_card.c
+++ b/drivers/media/pci/zoran/zoran_card.c
@@ -1050,7 +1050,7 @@ static int zr36057_init (struct zoran *zr)
1050 * Now add the template and register the device unit. 1050 * Now add the template and register the device unit.
1051 */ 1051 */
1052 memcpy(zr->video_dev, &zoran_template, sizeof(zoran_template)); 1052 memcpy(zr->video_dev, &zoran_template, sizeof(zoran_template));
1053 zr->video_dev->parent = &zr->pci_dev->dev; 1053 zr->video_dev->v4l2_dev = &zr->v4l2_dev;
1054 strcpy(zr->video_dev->name, ZR_DEVNAME(zr)); 1054 strcpy(zr->video_dev->name, ZR_DEVNAME(zr));
1055 /* It's not a mem2mem device, but you can both capture and output from 1055 /* It's not a mem2mem device, but you can both capture and output from
1056 one and the same device. This should really be split up into two 1056 one and the same device. This should really be split up into two
diff --git a/drivers/media/pci/zoran/zoran_driver.c b/drivers/media/pci/zoran/zoran_driver.c
index d133c30c3fdc..e7e9840c6c35 100644
--- a/drivers/media/pci/zoran/zoran_driver.c
+++ b/drivers/media/pci/zoran/zoran_driver.c
@@ -1456,29 +1456,6 @@ zoran_set_norm (struct zoran *zr,
1456 return -EINVAL; 1456 return -EINVAL;
1457 } 1457 }
1458 1458
1459 if (norm == V4L2_STD_ALL) {
1460 unsigned int status = 0;
1461 v4l2_std_id std = 0;
1462
1463 decoder_call(zr, video, querystd, &std);
1464 decoder_call(zr, core, s_std, std);
1465
1466 /* let changes come into effect */
1467 ssleep(2);
1468
1469 decoder_call(zr, video, g_input_status, &status);
1470 if (status & V4L2_IN_ST_NO_SIGNAL) {
1471 dprintk(1,
1472 KERN_ERR
1473 "%s: %s - no norm detected\n",
1474 ZR_DEVNAME(zr), __func__);
1475 /* reset norm */
1476 decoder_call(zr, core, s_std, zr->norm);
1477 return -EIO;
1478 }
1479
1480 norm = std;
1481 }
1482 if (norm & V4L2_STD_SECAM) 1459 if (norm & V4L2_STD_SECAM)
1483 zr->timing = zr->card.tvn[2]; 1460 zr->timing = zr->card.tvn[2];
1484 else if (norm & V4L2_STD_NTSC) 1461 else if (norm & V4L2_STD_NTSC)
diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index 25eaf61b98b4..08de865cc399 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -36,7 +36,7 @@ source "drivers/media/platform/blackfin/Kconfig"
36config VIDEO_SH_VOU 36config VIDEO_SH_VOU
37 tristate "SuperH VOU video output driver" 37 tristate "SuperH VOU video output driver"
38 depends on MEDIA_CAMERA_SUPPORT 38 depends on MEDIA_CAMERA_SUPPORT
39 depends on VIDEO_DEV && ARCH_SHMOBILE 39 depends on VIDEO_DEV && ARCH_SHMOBILE && I2C
40 select VIDEOBUF_DMA_CONTIG 40 select VIDEOBUF_DMA_CONTIG
41 help 41 help
42 Support for the Video Output Unit (VOU) on SuperH SoCs. 42 Support for the Video Output Unit (VOU) on SuperH SoCs.
diff --git a/drivers/media/platform/blackfin/bfin_capture.c b/drivers/media/platform/blackfin/bfin_capture.c
index 0e55b087076f..7f838c681cea 100644
--- a/drivers/media/platform/blackfin/bfin_capture.c
+++ b/drivers/media/platform/blackfin/bfin_capture.c
@@ -32,7 +32,6 @@
32#include <linux/time.h> 32#include <linux/time.h>
33#include <linux/types.h> 33#include <linux/types.h>
34 34
35#include <media/v4l2-chip-ident.h>
36#include <media/v4l2-common.h> 35#include <media/v4l2-common.h>
37#include <media/v4l2-ctrls.h> 36#include <media/v4l2-ctrls.h>
38#include <media/v4l2-device.h> 37#include <media/v4l2-device.h>
@@ -649,18 +648,30 @@ static int bcap_s_std(struct file *file, void *priv, v4l2_std_id std)
649 return 0; 648 return 0;
650} 649}
651 650
652static int bcap_g_dv_timings(struct file *file, void *priv, 651static int bcap_enum_dv_timings(struct file *file, void *priv,
652 struct v4l2_enum_dv_timings *timings)
653{
654 struct bcap_device *bcap_dev = video_drvdata(file);
655
656 return v4l2_subdev_call(bcap_dev->sd, video,
657 enum_dv_timings, timings);
658}
659
660static int bcap_query_dv_timings(struct file *file, void *priv,
653 struct v4l2_dv_timings *timings) 661 struct v4l2_dv_timings *timings)
654{ 662{
655 struct bcap_device *bcap_dev = video_drvdata(file); 663 struct bcap_device *bcap_dev = video_drvdata(file);
656 int ret;
657 664
658 ret = v4l2_subdev_call(bcap_dev->sd, video, 665 return v4l2_subdev_call(bcap_dev->sd, video,
659 g_dv_timings, timings); 666 query_dv_timings, timings);
660 if (ret < 0) 667}
661 return ret;
662 668
663 bcap_dev->dv_timings = *timings; 669static int bcap_g_dv_timings(struct file *file, void *priv,
670 struct v4l2_dv_timings *timings)
671{
672 struct bcap_device *bcap_dev = video_drvdata(file);
673
674 *timings = bcap_dev->dv_timings;
664 return 0; 675 return 0;
665} 676}
666 677
@@ -864,41 +875,6 @@ static int bcap_s_parm(struct file *file, void *fh,
864 return v4l2_subdev_call(bcap_dev->sd, video, s_parm, a); 875 return v4l2_subdev_call(bcap_dev->sd, video, s_parm, a);
865} 876}
866 877
867static int bcap_g_chip_ident(struct file *file, void *priv,
868 struct v4l2_dbg_chip_ident *chip)
869{
870 struct bcap_device *bcap_dev = video_drvdata(file);
871
872 chip->ident = V4L2_IDENT_NONE;
873 chip->revision = 0;
874 if (chip->match.type != V4L2_CHIP_MATCH_I2C_DRIVER &&
875 chip->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
876 return -EINVAL;
877
878 return v4l2_subdev_call(bcap_dev->sd, core,
879 g_chip_ident, chip);
880}
881
882#ifdef CONFIG_VIDEO_ADV_DEBUG
883static int bcap_dbg_g_register(struct file *file, void *priv,
884 struct v4l2_dbg_register *reg)
885{
886 struct bcap_device *bcap_dev = video_drvdata(file);
887
888 return v4l2_subdev_call(bcap_dev->sd, core,
889 g_register, reg);
890}
891
892static int bcap_dbg_s_register(struct file *file, void *priv,
893 const struct v4l2_dbg_register *reg)
894{
895 struct bcap_device *bcap_dev = video_drvdata(file);
896
897 return v4l2_subdev_call(bcap_dev->sd, core,
898 s_register, reg);
899}
900#endif
901
902static int bcap_log_status(struct file *file, void *priv) 878static int bcap_log_status(struct file *file, void *priv)
903{ 879{
904 struct bcap_device *bcap_dev = video_drvdata(file); 880 struct bcap_device *bcap_dev = video_drvdata(file);
@@ -921,6 +897,8 @@ static const struct v4l2_ioctl_ops bcap_ioctl_ops = {
921 .vidioc_g_std = bcap_g_std, 897 .vidioc_g_std = bcap_g_std,
922 .vidioc_s_dv_timings = bcap_s_dv_timings, 898 .vidioc_s_dv_timings = bcap_s_dv_timings,
923 .vidioc_g_dv_timings = bcap_g_dv_timings, 899 .vidioc_g_dv_timings = bcap_g_dv_timings,
900 .vidioc_query_dv_timings = bcap_query_dv_timings,
901 .vidioc_enum_dv_timings = bcap_enum_dv_timings,
924 .vidioc_reqbufs = bcap_reqbufs, 902 .vidioc_reqbufs = bcap_reqbufs,
925 .vidioc_querybuf = bcap_querybuf, 903 .vidioc_querybuf = bcap_querybuf,
926 .vidioc_qbuf = bcap_qbuf, 904 .vidioc_qbuf = bcap_qbuf,
@@ -929,11 +907,6 @@ static const struct v4l2_ioctl_ops bcap_ioctl_ops = {
929 .vidioc_streamoff = bcap_streamoff, 907 .vidioc_streamoff = bcap_streamoff,
930 .vidioc_g_parm = bcap_g_parm, 908 .vidioc_g_parm = bcap_g_parm,
931 .vidioc_s_parm = bcap_s_parm, 909 .vidioc_s_parm = bcap_s_parm,
932 .vidioc_g_chip_ident = bcap_g_chip_ident,
933#ifdef CONFIG_VIDEO_ADV_DEBUG
934 .vidioc_g_register = bcap_dbg_g_register,
935 .vidioc_s_register = bcap_dbg_s_register,
936#endif
937 .vidioc_log_status = bcap_log_status, 910 .vidioc_log_status = bcap_log_status,
938}; 911};
939 912
@@ -960,7 +933,7 @@ static int bcap_probe(struct platform_device *pdev)
960 int ret; 933 int ret;
961 934
962 config = pdev->dev.platform_data; 935 config = pdev->dev.platform_data;
963 if (!config) { 936 if (!config || !config->num_inputs) {
964 v4l2_err(pdev->dev.driver, "Unable to get board config\n"); 937 v4l2_err(pdev->dev.driver, "Unable to get board config\n");
965 return -ENODEV; 938 return -ENODEV;
966 } 939 }
@@ -1031,7 +1004,9 @@ static int bcap_probe(struct platform_device *pdev)
1031 q->mem_ops = &vb2_dma_contig_memops; 1004 q->mem_ops = &vb2_dma_contig_memops;
1032 q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; 1005 q->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1033 1006
1034 vb2_queue_init(q); 1007 ret = vb2_queue_init(q);
1008 if (ret)
1009 goto err_free_handler;
1035 1010
1036 mutex_init(&bcap_dev->mutex); 1011 mutex_init(&bcap_dev->mutex);
1037 init_completion(&bcap_dev->comp); 1012 init_completion(&bcap_dev->comp);
@@ -1067,11 +1042,6 @@ static int bcap_probe(struct platform_device *pdev)
1067 NULL); 1042 NULL);
1068 if (bcap_dev->sd) { 1043 if (bcap_dev->sd) {
1069 int i; 1044 int i;
1070 if (!config->num_inputs) {
1071 v4l2_err(&bcap_dev->v4l2_dev,
1072 "Unable to work without input\n");
1073 goto err_unreg_vdev;
1074 }
1075 1045
1076 /* update tvnorms from the sub devices */ 1046 /* update tvnorms from the sub devices */
1077 for (i = 0; i < config->num_inputs; i++) 1047 for (i = 0; i < config->num_inputs; i++)
@@ -1079,6 +1049,7 @@ static int bcap_probe(struct platform_device *pdev)
1079 } else { 1049 } else {
1080 v4l2_err(&bcap_dev->v4l2_dev, 1050 v4l2_err(&bcap_dev->v4l2_dev,
1081 "Unable to register sub device\n"); 1051 "Unable to register sub device\n");
1052 ret = -ENODEV;
1082 goto err_unreg_vdev; 1053 goto err_unreg_vdev;
1083 } 1054 }
1084 1055
diff --git a/drivers/media/platform/blackfin/ppi.c b/drivers/media/platform/blackfin/ppi.c
index 01b5b501347e..15e9c2bac2b1 100644
--- a/drivers/media/platform/blackfin/ppi.c
+++ b/drivers/media/platform/blackfin/ppi.c
@@ -266,6 +266,18 @@ static int ppi_set_params(struct ppi_if *ppi, struct ppi_params *params)
266 bfin_write32(&reg->vcnt, params->height); 266 bfin_write32(&reg->vcnt, params->height);
267 if (params->int_mask) 267 if (params->int_mask)
268 bfin_write32(&reg->imsk, params->int_mask & 0xFF); 268 bfin_write32(&reg->imsk, params->int_mask & 0xFF);
269 if (ppi->ppi_control & PORT_DIR) {
270 u32 hsync_width, vsync_width, vsync_period;
271
272 hsync_width = params->hsync
273 * params->bpp / params->dlen;
274 vsync_width = params->vsync * samples_per_line;
275 vsync_period = samples_per_line * params->frame;
276 bfin_write32(&reg->fs1_wlhb, hsync_width);
277 bfin_write32(&reg->fs1_paspl, samples_per_line);
278 bfin_write32(&reg->fs2_wlvb, vsync_width);
279 bfin_write32(&reg->fs2_palpf, vsync_period);
280 }
269 break; 281 break;
270 } 282 }
271 default: 283 default:
diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index 9d1481a60bd9..df4ada880e42 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -49,16 +49,14 @@
49 49
50#define CODA_MAX_FRAMEBUFFERS 2 50#define CODA_MAX_FRAMEBUFFERS 2
51 51
52#define MAX_W 720 52#define MAX_W 8192
53#define MAX_H 576 53#define MAX_H 8192
54#define CODA_MAX_FRAME_SIZE 0x90000 54#define CODA_MAX_FRAME_SIZE 0x100000
55#define FMO_SLICE_SAVE_BUF_SIZE (32) 55#define FMO_SLICE_SAVE_BUF_SIZE (32)
56#define CODA_DEFAULT_GAMMA 4096 56#define CODA_DEFAULT_GAMMA 4096
57 57
58#define MIN_W 176 58#define MIN_W 176
59#define MIN_H 144 59#define MIN_H 144
60#define MAX_W 720
61#define MAX_H 576
62 60
63#define S_ALIGN 1 /* multiple of 2 */ 61#define S_ALIGN 1 /* multiple of 2 */
64#define W_ALIGN 1 /* multiple of 2 */ 62#define W_ALIGN 1 /* multiple of 2 */
@@ -67,7 +65,7 @@
67#define fh_to_ctx(__fh) container_of(__fh, struct coda_ctx, fh) 65#define fh_to_ctx(__fh) container_of(__fh, struct coda_ctx, fh)
68 66
69static int coda_debug; 67static int coda_debug;
70module_param(coda_debug, int, 0); 68module_param(coda_debug, int, 0644);
71MODULE_PARM_DESC(coda_debug, "Debug level (0-1)"); 69MODULE_PARM_DESC(coda_debug, "Debug level (0-1)");
72 70
73enum { 71enum {
@@ -75,11 +73,6 @@ enum {
75 V4L2_M2M_DST = 1, 73 V4L2_M2M_DST = 1,
76}; 74};
77 75
78enum coda_fmt_type {
79 CODA_FMT_ENC,
80 CODA_FMT_RAW,
81};
82
83enum coda_inst_type { 76enum coda_inst_type {
84 CODA_INST_ENCODER, 77 CODA_INST_ENCODER,
85 CODA_INST_DECODER, 78 CODA_INST_DECODER,
@@ -93,14 +86,21 @@ enum coda_product {
93struct coda_fmt { 86struct coda_fmt {
94 char *name; 87 char *name;
95 u32 fourcc; 88 u32 fourcc;
96 enum coda_fmt_type type; 89};
90
91struct coda_codec {
92 u32 mode;
93 u32 src_fourcc;
94 u32 dst_fourcc;
95 u32 max_w;
96 u32 max_h;
97}; 97};
98 98
99struct coda_devtype { 99struct coda_devtype {
100 char *firmware; 100 char *firmware;
101 enum coda_product product; 101 enum coda_product product;
102 struct coda_fmt *formats; 102 struct coda_codec *codecs;
103 unsigned int num_formats; 103 unsigned int num_codecs;
104 size_t workbuf_size; 104 size_t workbuf_size;
105}; 105};
106 106
@@ -109,7 +109,7 @@ struct coda_q_data {
109 unsigned int width; 109 unsigned int width;
110 unsigned int height; 110 unsigned int height;
111 unsigned int sizeimage; 111 unsigned int sizeimage;
112 struct coda_fmt *fmt; 112 unsigned int fourcc;
113}; 113};
114 114
115struct coda_aux_buf { 115struct coda_aux_buf {
@@ -137,12 +137,12 @@ struct coda_dev {
137 137
138 spinlock_t irqlock; 138 spinlock_t irqlock;
139 struct mutex dev_mutex; 139 struct mutex dev_mutex;
140 struct mutex coda_mutex;
140 struct v4l2_m2m_dev *m2m_dev; 141 struct v4l2_m2m_dev *m2m_dev;
141 struct vb2_alloc_ctx *alloc_ctx; 142 struct vb2_alloc_ctx *alloc_ctx;
142 struct list_head instances; 143 struct list_head instances;
143 unsigned long instance_mask; 144 unsigned long instance_mask;
144 struct delayed_work timeout; 145 struct delayed_work timeout;
145 struct completion done;
146}; 146};
147 147
148struct coda_params { 148struct coda_params {
@@ -164,11 +164,12 @@ struct coda_ctx {
164 struct coda_dev *dev; 164 struct coda_dev *dev;
165 struct list_head list; 165 struct list_head list;
166 int aborting; 166 int aborting;
167 int rawstreamon; 167 int streamon_out;
168 int compstreamon; 168 int streamon_cap;
169 u32 isequence; 169 u32 isequence;
170 struct coda_q_data q_data[2]; 170 struct coda_q_data q_data[2];
171 enum coda_inst_type inst_type; 171 enum coda_inst_type inst_type;
172 struct coda_codec *codec;
172 enum v4l2_colorspace colorspace; 173 enum v4l2_colorspace colorspace;
173 struct coda_params params; 174 struct coda_params params;
174 struct v4l2_m2m_ctx *m2m_ctx; 175 struct v4l2_m2m_ctx *m2m_ctx;
@@ -257,62 +258,89 @@ static struct coda_q_data *get_q_data(struct coda_ctx *ctx,
257} 258}
258 259
259/* 260/*
260 * Add one array of supported formats for each version of Coda: 261 * Array of all formats supported by any version of Coda:
261 * i.MX27 -> codadx6
262 * i.MX51 -> coda7
263 * i.MX6 -> coda960
264 */ 262 */
265static struct coda_fmt codadx6_formats[] = { 263static struct coda_fmt coda_formats[] = {
266 { 264 {
267 .name = "YUV 4:2:0 Planar", 265 .name = "YUV 4:2:0 Planar, YCbCr",
268 .fourcc = V4L2_PIX_FMT_YUV420, 266 .fourcc = V4L2_PIX_FMT_YUV420,
269 .type = CODA_FMT_RAW,
270 },
271 {
272 .name = "H264 Encoded Stream",
273 .fourcc = V4L2_PIX_FMT_H264,
274 .type = CODA_FMT_ENC,
275 }, 267 },
276 { 268 {
277 .name = "MPEG4 Encoded Stream", 269 .name = "YUV 4:2:0 Planar, YCrCb",
278 .fourcc = V4L2_PIX_FMT_MPEG4, 270 .fourcc = V4L2_PIX_FMT_YVU420,
279 .type = CODA_FMT_ENC,
280 },
281};
282
283static struct coda_fmt coda7_formats[] = {
284 {
285 .name = "YUV 4:2:0 Planar",
286 .fourcc = V4L2_PIX_FMT_YUV420,
287 .type = CODA_FMT_RAW,
288 }, 271 },
289 { 272 {
290 .name = "H264 Encoded Stream", 273 .name = "H264 Encoded Stream",
291 .fourcc = V4L2_PIX_FMT_H264, 274 .fourcc = V4L2_PIX_FMT_H264,
292 .type = CODA_FMT_ENC,
293 }, 275 },
294 { 276 {
295 .name = "MPEG4 Encoded Stream", 277 .name = "MPEG4 Encoded Stream",
296 .fourcc = V4L2_PIX_FMT_MPEG4, 278 .fourcc = V4L2_PIX_FMT_MPEG4,
297 .type = CODA_FMT_ENC,
298 }, 279 },
299}; 280};
300 281
301static struct coda_fmt *find_format(struct coda_dev *dev, struct v4l2_format *f) 282#define CODA_CODEC(mode, src_fourcc, dst_fourcc, max_w, max_h) \
283 { mode, src_fourcc, dst_fourcc, max_w, max_h }
284
285/*
286 * Arrays of codecs supported by each given version of Coda:
287 * i.MX27 -> codadx6
288 * i.MX5x -> coda7
289 * i.MX6 -> coda960
290 * Use V4L2_PIX_FMT_YUV420 as placeholder for all supported YUV 4:2:0 variants
291 */
292static struct coda_codec codadx6_codecs[] = {
293 CODA_CODEC(CODADX6_MODE_ENCODE_H264, V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_H264, 720, 576),
294 CODA_CODEC(CODADX6_MODE_ENCODE_MP4, V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_MPEG4, 720, 576),
295};
296
297static struct coda_codec coda7_codecs[] = {
298 CODA_CODEC(CODA7_MODE_ENCODE_H264, V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_H264, 1280, 720),
299 CODA_CODEC(CODA7_MODE_ENCODE_MP4, V4L2_PIX_FMT_YUV420, V4L2_PIX_FMT_MPEG4, 1280, 720),
300};
301
302static bool coda_format_is_yuv(u32 fourcc)
303{
304 switch (fourcc) {
305 case V4L2_PIX_FMT_YUV420:
306 case V4L2_PIX_FMT_YVU420:
307 return true;
308 default:
309 return false;
310 }
311}
312
313/*
314 * Normalize all supported YUV 4:2:0 formats to the value used in the codec
315 * tables.
316 */
317static u32 coda_format_normalize_yuv(u32 fourcc)
318{
319 return coda_format_is_yuv(fourcc) ? V4L2_PIX_FMT_YUV420 : fourcc;
320}
321
322static struct coda_codec *coda_find_codec(struct coda_dev *dev, int src_fourcc,
323 int dst_fourcc)
302{ 324{
303 struct coda_fmt *formats = dev->devtype->formats; 325 struct coda_codec *codecs = dev->devtype->codecs;
304 int num_formats = dev->devtype->num_formats; 326 int num_codecs = dev->devtype->num_codecs;
305 unsigned int k; 327 int k;
328
329 src_fourcc = coda_format_normalize_yuv(src_fourcc);
330 dst_fourcc = coda_format_normalize_yuv(dst_fourcc);
331 if (src_fourcc == dst_fourcc)
332 return NULL;
306 333
307 for (k = 0; k < num_formats; k++) { 334 for (k = 0; k < num_codecs; k++) {
308 if (formats[k].fourcc == f->fmt.pix.pixelformat) 335 if (codecs[k].src_fourcc == src_fourcc &&
336 codecs[k].dst_fourcc == dst_fourcc)
309 break; 337 break;
310 } 338 }
311 339
312 if (k == num_formats) 340 if (k == num_codecs)
313 return NULL; 341 return NULL;
314 342
315 return &formats[k]; 343 return &codecs[k];
316} 344}
317 345
318/* 346/*
@@ -323,7 +351,7 @@ static int vidioc_querycap(struct file *file, void *priv,
323{ 351{
324 strlcpy(cap->driver, CODA_NAME, sizeof(cap->driver)); 352 strlcpy(cap->driver, CODA_NAME, sizeof(cap->driver));
325 strlcpy(cap->card, CODA_NAME, sizeof(cap->card)); 353 strlcpy(cap->card, CODA_NAME, sizeof(cap->card));
326 strlcpy(cap->bus_info, CODA_NAME, sizeof(cap->bus_info)); 354 strlcpy(cap->bus_info, "platform:" CODA_NAME, sizeof(cap->bus_info));
327 /* 355 /*
328 * This is only a mem-to-mem video device. The capture and output 356 * This is only a mem-to-mem video device. The capture and output
329 * device capability flags are left only for backward compatibility 357 * device capability flags are left only for backward compatibility
@@ -337,17 +365,34 @@ static int vidioc_querycap(struct file *file, void *priv,
337} 365}
338 366
339static int enum_fmt(void *priv, struct v4l2_fmtdesc *f, 367static int enum_fmt(void *priv, struct v4l2_fmtdesc *f,
340 enum coda_fmt_type type) 368 enum v4l2_buf_type type)
341{ 369{
342 struct coda_ctx *ctx = fh_to_ctx(priv); 370 struct coda_ctx *ctx = fh_to_ctx(priv);
343 struct coda_dev *dev = ctx->dev; 371 struct coda_codec *codecs = ctx->dev->devtype->codecs;
344 struct coda_fmt *formats = dev->devtype->formats; 372 struct coda_fmt *formats = coda_formats;
345 struct coda_fmt *fmt; 373 struct coda_fmt *fmt;
346 int num_formats = dev->devtype->num_formats; 374 int num_codecs = ctx->dev->devtype->num_codecs;
347 int i, num = 0; 375 int num_formats = ARRAY_SIZE(coda_formats);
376 int i, k, num = 0;
348 377
349 for (i = 0; i < num_formats; i++) { 378 for (i = 0; i < num_formats; i++) {
350 if (formats[i].type == type) { 379 /* Both uncompressed formats are always supported */
380 if (coda_format_is_yuv(formats[i].fourcc)) {
381 if (num == f->index)
382 break;
383 ++num;
384 continue;
385 }
386 /* Compressed formats may be supported, check the codec list */
387 for (k = 0; k < num_codecs; k++) {
388 if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE &&
389 formats[i].fourcc == codecs[k].dst_fourcc)
390 break;
391 if (type == V4L2_BUF_TYPE_VIDEO_OUTPUT &&
392 formats[i].fourcc == codecs[k].src_fourcc)
393 break;
394 }
395 if (k < num_codecs) {
351 if (num == f->index) 396 if (num == f->index)
352 break; 397 break;
353 ++num; 398 ++num;
@@ -368,13 +413,13 @@ static int enum_fmt(void *priv, struct v4l2_fmtdesc *f,
368static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv, 413static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
369 struct v4l2_fmtdesc *f) 414 struct v4l2_fmtdesc *f)
370{ 415{
371 return enum_fmt(priv, f, CODA_FMT_ENC); 416 return enum_fmt(priv, f, V4L2_BUF_TYPE_VIDEO_CAPTURE);
372} 417}
373 418
374static int vidioc_enum_fmt_vid_out(struct file *file, void *priv, 419static int vidioc_enum_fmt_vid_out(struct file *file, void *priv,
375 struct v4l2_fmtdesc *f) 420 struct v4l2_fmtdesc *f)
376{ 421{
377 return enum_fmt(priv, f, CODA_FMT_RAW); 422 return enum_fmt(priv, f, V4L2_BUF_TYPE_VIDEO_OUTPUT);
378} 423}
379 424
380static int vidioc_g_fmt(struct file *file, void *priv, struct v4l2_format *f) 425static int vidioc_g_fmt(struct file *file, void *priv, struct v4l2_format *f)
@@ -390,10 +435,10 @@ static int vidioc_g_fmt(struct file *file, void *priv, struct v4l2_format *f)
390 q_data = get_q_data(ctx, f->type); 435 q_data = get_q_data(ctx, f->type);
391 436
392 f->fmt.pix.field = V4L2_FIELD_NONE; 437 f->fmt.pix.field = V4L2_FIELD_NONE;
393 f->fmt.pix.pixelformat = q_data->fmt->fourcc; 438 f->fmt.pix.pixelformat = q_data->fourcc;
394 f->fmt.pix.width = q_data->width; 439 f->fmt.pix.width = q_data->width;
395 f->fmt.pix.height = q_data->height; 440 f->fmt.pix.height = q_data->height;
396 if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_YUV420) 441 if (coda_format_is_yuv(f->fmt.pix.pixelformat))
397 f->fmt.pix.bytesperline = round_up(f->fmt.pix.width, 2); 442 f->fmt.pix.bytesperline = round_up(f->fmt.pix.width, 2);
398 else /* encoded formats h.264/mpeg4 */ 443 else /* encoded formats h.264/mpeg4 */
399 f->fmt.pix.bytesperline = 0; 444 f->fmt.pix.bytesperline = 0;
@@ -404,8 +449,9 @@ static int vidioc_g_fmt(struct file *file, void *priv, struct v4l2_format *f)
404 return 0; 449 return 0;
405} 450}
406 451
407static int vidioc_try_fmt(struct coda_dev *dev, struct v4l2_format *f) 452static int vidioc_try_fmt(struct coda_codec *codec, struct v4l2_format *f)
408{ 453{
454 unsigned int max_w, max_h;
409 enum v4l2_field field; 455 enum v4l2_field field;
410 456
411 field = f->fmt.pix.field; 457 field = f->fmt.pix.field;
@@ -418,12 +464,21 @@ static int vidioc_try_fmt(struct coda_dev *dev, struct v4l2_format *f)
418 * if any of the dimensions is unsupported */ 464 * if any of the dimensions is unsupported */
419 f->fmt.pix.field = field; 465 f->fmt.pix.field = field;
420 466
421 if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_YUV420) { 467 if (codec) {
422 v4l_bound_align_image(&f->fmt.pix.width, MIN_W, MAX_W, 468 max_w = codec->max_w;
423 W_ALIGN, &f->fmt.pix.height, 469 max_h = codec->max_h;
424 MIN_H, MAX_H, H_ALIGN, S_ALIGN); 470 } else {
425 f->fmt.pix.bytesperline = round_up(f->fmt.pix.width, 2); 471 max_w = MAX_W;
426 f->fmt.pix.sizeimage = f->fmt.pix.width * 472 max_h = MAX_H;
473 }
474 v4l_bound_align_image(&f->fmt.pix.width, MIN_W, max_w,
475 W_ALIGN, &f->fmt.pix.height,
476 MIN_H, max_h, H_ALIGN, S_ALIGN);
477
478 if (coda_format_is_yuv(f->fmt.pix.pixelformat)) {
479 /* Frame stride must be multiple of 8 */
480 f->fmt.pix.bytesperline = round_up(f->fmt.pix.width, 8);
481 f->fmt.pix.sizeimage = f->fmt.pix.bytesperline *
427 f->fmt.pix.height * 3 / 2; 482 f->fmt.pix.height * 3 / 2;
428 } else { /*encoded formats h.264/mpeg4 */ 483 } else { /*encoded formats h.264/mpeg4 */
429 f->fmt.pix.bytesperline = 0; 484 f->fmt.pix.bytesperline = 0;
@@ -436,57 +491,38 @@ static int vidioc_try_fmt(struct coda_dev *dev, struct v4l2_format *f)
436static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, 491static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
437 struct v4l2_format *f) 492 struct v4l2_format *f)
438{ 493{
439 int ret;
440 struct coda_fmt *fmt;
441 struct coda_ctx *ctx = fh_to_ctx(priv); 494 struct coda_ctx *ctx = fh_to_ctx(priv);
495 struct coda_codec *codec = NULL;
442 496
443 fmt = find_format(ctx->dev, f); 497 /* Determine codec by the encoded format */
444 /* 498 codec = coda_find_codec(ctx->dev, V4L2_PIX_FMT_YUV420,
445 * Since decoding support is not implemented yet do not allow 499 f->fmt.pix.pixelformat);
446 * CODA_FMT_RAW formats in the capture interface.
447 */
448 if (!fmt || !(fmt->type == CODA_FMT_ENC))
449 f->fmt.pix.pixelformat = V4L2_PIX_FMT_H264;
450 500
451 f->fmt.pix.colorspace = ctx->colorspace; 501 f->fmt.pix.colorspace = ctx->colorspace;
452 502
453 ret = vidioc_try_fmt(ctx->dev, f); 503 return vidioc_try_fmt(codec, f);
454 if (ret < 0)
455 return ret;
456
457 return 0;
458} 504}
459 505
460static int vidioc_try_fmt_vid_out(struct file *file, void *priv, 506static int vidioc_try_fmt_vid_out(struct file *file, void *priv,
461 struct v4l2_format *f) 507 struct v4l2_format *f)
462{ 508{
463 struct coda_ctx *ctx = fh_to_ctx(priv); 509 struct coda_ctx *ctx = fh_to_ctx(priv);
464 struct coda_fmt *fmt; 510 struct coda_codec *codec;
465 int ret;
466 511
467 fmt = find_format(ctx->dev, f); 512 /* Determine codec by encoded format, returns NULL if raw or invalid */
468 /* 513 codec = coda_find_codec(ctx->dev, f->fmt.pix.pixelformat,
469 * Since decoding support is not implemented yet do not allow 514 V4L2_PIX_FMT_YUV420);
470 * CODA_FMT formats in the capture interface.
471 */
472 if (!fmt || !(fmt->type == CODA_FMT_RAW))
473 f->fmt.pix.pixelformat = V4L2_PIX_FMT_YUV420;
474 515
475 if (!f->fmt.pix.colorspace) 516 if (!f->fmt.pix.colorspace)
476 f->fmt.pix.colorspace = V4L2_COLORSPACE_REC709; 517 f->fmt.pix.colorspace = V4L2_COLORSPACE_REC709;
477 518
478 ret = vidioc_try_fmt(ctx->dev, f); 519 return vidioc_try_fmt(codec, f);
479 if (ret < 0)
480 return ret;
481
482 return 0;
483} 520}
484 521
485static int vidioc_s_fmt(struct coda_ctx *ctx, struct v4l2_format *f) 522static int vidioc_s_fmt(struct coda_ctx *ctx, struct v4l2_format *f)
486{ 523{
487 struct coda_q_data *q_data; 524 struct coda_q_data *q_data;
488 struct vb2_queue *vq; 525 struct vb2_queue *vq;
489 int ret;
490 526
491 vq = v4l2_m2m_get_vq(ctx->m2m_ctx, f->type); 527 vq = v4l2_m2m_get_vq(ctx->m2m_ctx, f->type);
492 if (!vq) 528 if (!vq)
@@ -501,18 +537,14 @@ static int vidioc_s_fmt(struct coda_ctx *ctx, struct v4l2_format *f)
501 return -EBUSY; 537 return -EBUSY;
502 } 538 }
503 539
504 ret = vidioc_try_fmt(ctx->dev, f); 540 q_data->fourcc = f->fmt.pix.pixelformat;
505 if (ret)
506 return ret;
507
508 q_data->fmt = find_format(ctx->dev, f);
509 q_data->width = f->fmt.pix.width; 541 q_data->width = f->fmt.pix.width;
510 q_data->height = f->fmt.pix.height; 542 q_data->height = f->fmt.pix.height;
511 q_data->sizeimage = f->fmt.pix.sizeimage; 543 q_data->sizeimage = f->fmt.pix.sizeimage;
512 544
513 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, 545 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
514 "Setting format for type %d, wxh: %dx%d, fmt: %d\n", 546 "Setting format for type %d, wxh: %dx%d, fmt: %d\n",
515 f->type, q_data->width, q_data->height, q_data->fmt->fourcc); 547 f->type, q_data->width, q_data->height, q_data->fourcc);
516 548
517 return 0; 549 return 0;
518} 550}
@@ -520,13 +552,14 @@ static int vidioc_s_fmt(struct coda_ctx *ctx, struct v4l2_format *f)
520static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, 552static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
521 struct v4l2_format *f) 553 struct v4l2_format *f)
522{ 554{
555 struct coda_ctx *ctx = fh_to_ctx(priv);
523 int ret; 556 int ret;
524 557
525 ret = vidioc_try_fmt_vid_cap(file, priv, f); 558 ret = vidioc_try_fmt_vid_cap(file, priv, f);
526 if (ret) 559 if (ret)
527 return ret; 560 return ret;
528 561
529 return vidioc_s_fmt(fh_to_ctx(priv), f); 562 return vidioc_s_fmt(ctx, f);
530} 563}
531 564
532static int vidioc_s_fmt_vid_out(struct file *file, void *priv, 565static int vidioc_s_fmt_vid_out(struct file *file, void *priv,
@@ -569,6 +602,14 @@ static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
569 return v4l2_m2m_qbuf(file, ctx->m2m_ctx, buf); 602 return v4l2_m2m_qbuf(file, ctx->m2m_ctx, buf);
570} 603}
571 604
605static int vidioc_expbuf(struct file *file, void *priv,
606 struct v4l2_exportbuffer *eb)
607{
608 struct coda_ctx *ctx = fh_to_ctx(priv);
609
610 return v4l2_m2m_expbuf(file, ctx->m2m_ctx, eb);
611}
612
572static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf) 613static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
573{ 614{
574 struct coda_ctx *ctx = fh_to_ctx(priv); 615 struct coda_ctx *ctx = fh_to_ctx(priv);
@@ -617,6 +658,7 @@ static const struct v4l2_ioctl_ops coda_ioctl_ops = {
617 .vidioc_querybuf = vidioc_querybuf, 658 .vidioc_querybuf = vidioc_querybuf,
618 659
619 .vidioc_qbuf = vidioc_qbuf, 660 .vidioc_qbuf = vidioc_qbuf,
661 .vidioc_expbuf = vidioc_expbuf,
620 .vidioc_dqbuf = vidioc_dqbuf, 662 .vidioc_dqbuf = vidioc_dqbuf,
621 .vidioc_create_bufs = vidioc_create_bufs, 663 .vidioc_create_bufs = vidioc_create_bufs,
622 664
@@ -639,11 +681,13 @@ static void coda_device_run(void *m2m_priv)
639 u32 pic_stream_buffer_addr, pic_stream_buffer_size; 681 u32 pic_stream_buffer_addr, pic_stream_buffer_size;
640 u32 dst_fourcc; 682 u32 dst_fourcc;
641 683
684 mutex_lock(&dev->coda_mutex);
685
642 src_buf = v4l2_m2m_next_src_buf(ctx->m2m_ctx); 686 src_buf = v4l2_m2m_next_src_buf(ctx->m2m_ctx);
643 dst_buf = v4l2_m2m_next_dst_buf(ctx->m2m_ctx); 687 dst_buf = v4l2_m2m_next_dst_buf(ctx->m2m_ctx);
644 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); 688 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
645 q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); 689 q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
646 dst_fourcc = q_data_dst->fmt->fourcc; 690 dst_fourcc = q_data_dst->fourcc;
647 691
648 src_buf->v4l2_buf.sequence = ctx->isequence; 692 src_buf->v4l2_buf.sequence = ctx->isequence;
649 dst_buf->v4l2_buf.sequence = ctx->isequence; 693 dst_buf->v4l2_buf.sequence = ctx->isequence;
@@ -725,9 +769,20 @@ static void coda_device_run(void *m2m_priv)
725 769
726 770
727 picture_y = vb2_dma_contig_plane_dma_addr(src_buf, 0); 771 picture_y = vb2_dma_contig_plane_dma_addr(src_buf, 0);
728 picture_cb = picture_y + q_data_src->width * q_data_src->height; 772 switch (q_data_src->fourcc) {
729 picture_cr = picture_cb + q_data_src->width / 2 * 773 case V4L2_PIX_FMT_YVU420:
730 q_data_src->height / 2; 774 /* Switch Cb and Cr for YVU420 format */
775 picture_cr = picture_y + q_data_src->width * q_data_src->height;
776 picture_cb = picture_cr + q_data_src->width / 2 *
777 q_data_src->height / 2;
778 break;
779 case V4L2_PIX_FMT_YUV420:
780 default:
781 picture_cb = picture_y + q_data_src->width * q_data_src->height;
782 picture_cr = picture_cb + q_data_src->width / 2 *
783 q_data_src->height / 2;
784 break;
785 }
731 786
732 coda_write(dev, picture_y, CODA_CMD_ENC_PIC_SRC_ADDR_Y); 787 coda_write(dev, picture_y, CODA_CMD_ENC_PIC_SRC_ADDR_Y);
733 coda_write(dev, picture_cb, CODA_CMD_ENC_PIC_SRC_ADDR_CB); 788 coda_write(dev, picture_cb, CODA_CMD_ENC_PIC_SRC_ADDR_CB);
@@ -748,7 +803,6 @@ static void coda_device_run(void *m2m_priv)
748 /* 1 second timeout in case CODA locks up */ 803 /* 1 second timeout in case CODA locks up */
749 schedule_delayed_work(&dev->timeout, HZ); 804 schedule_delayed_work(&dev->timeout, HZ);
750 805
751 INIT_COMPLETION(dev->done);
752 coda_command_async(ctx, CODA_COMMAND_PIC_RUN); 806 coda_command_async(ctx, CODA_COMMAND_PIC_RUN);
753} 807}
754 808
@@ -767,6 +821,12 @@ static int coda_job_ready(void *m2m_priv)
767 return 0; 821 return 0;
768 } 822 }
769 823
824 if (ctx->aborting) {
825 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
826 "not ready: aborting\n");
827 return 0;
828 }
829
770 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, 830 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
771 "job ready\n"); 831 "job ready\n");
772 return 1; 832 return 1;
@@ -775,14 +835,11 @@ static int coda_job_ready(void *m2m_priv)
775static void coda_job_abort(void *priv) 835static void coda_job_abort(void *priv)
776{ 836{
777 struct coda_ctx *ctx = priv; 837 struct coda_ctx *ctx = priv;
778 struct coda_dev *dev = ctx->dev;
779 838
780 ctx->aborting = 1; 839 ctx->aborting = 1;
781 840
782 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, 841 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
783 "Aborting task\n"); 842 "Aborting task\n");
784
785 v4l2_m2m_job_finish(dev->m2m_dev, ctx->m2m_ctx);
786} 843}
787 844
788static void coda_lock(void *m2m_priv) 845static void coda_lock(void *m2m_priv)
@@ -809,7 +866,12 @@ static struct v4l2_m2m_ops coda_m2m_ops = {
809 866
810static void set_default_params(struct coda_ctx *ctx) 867static void set_default_params(struct coda_ctx *ctx)
811{ 868{
812 struct coda_dev *dev = ctx->dev; 869 int max_w;
870 int max_h;
871
872 ctx->codec = &ctx->dev->devtype->codecs[0];
873 max_w = ctx->codec->max_w;
874 max_h = ctx->codec->max_h;
813 875
814 ctx->params.codec_mode = CODA_MODE_INVALID; 876 ctx->params.codec_mode = CODA_MODE_INVALID;
815 ctx->colorspace = V4L2_COLORSPACE_REC709; 877 ctx->colorspace = V4L2_COLORSPACE_REC709;
@@ -817,13 +879,13 @@ static void set_default_params(struct coda_ctx *ctx)
817 ctx->aborting = 0; 879 ctx->aborting = 0;
818 880
819 /* Default formats for output and input queues */ 881 /* Default formats for output and input queues */
820 ctx->q_data[V4L2_M2M_SRC].fmt = &dev->devtype->formats[0]; 882 ctx->q_data[V4L2_M2M_SRC].fourcc = ctx->codec->src_fourcc;
821 ctx->q_data[V4L2_M2M_DST].fmt = &dev->devtype->formats[1]; 883 ctx->q_data[V4L2_M2M_DST].fourcc = ctx->codec->dst_fourcc;
822 ctx->q_data[V4L2_M2M_SRC].width = MAX_W; 884 ctx->q_data[V4L2_M2M_SRC].width = max_w;
823 ctx->q_data[V4L2_M2M_SRC].height = MAX_H; 885 ctx->q_data[V4L2_M2M_SRC].height = max_h;
824 ctx->q_data[V4L2_M2M_SRC].sizeimage = (MAX_W * MAX_H * 3) / 2; 886 ctx->q_data[V4L2_M2M_SRC].sizeimage = (max_w * max_h * 3) / 2;
825 ctx->q_data[V4L2_M2M_DST].width = MAX_W; 887 ctx->q_data[V4L2_M2M_DST].width = max_w;
826 ctx->q_data[V4L2_M2M_DST].height = MAX_H; 888 ctx->q_data[V4L2_M2M_DST].height = max_h;
827 ctx->q_data[V4L2_M2M_DST].sizeimage = CODA_MAX_FRAME_SIZE; 889 ctx->q_data[V4L2_M2M_DST].sizeimage = CODA_MAX_FRAME_SIZE;
828} 890}
829 891
@@ -868,8 +930,6 @@ static int coda_buf_prepare(struct vb2_buffer *vb)
868 return -EINVAL; 930 return -EINVAL;
869 } 931 }
870 932
871 vb2_set_plane_payload(vb, 0, q_data->sizeimage);
872
873 return 0; 933 return 0;
874} 934}
875 935
@@ -906,21 +966,34 @@ static void coda_free_framebuffers(struct coda_ctx *ctx)
906 } 966 }
907} 967}
908 968
969static void coda_parabuf_write(struct coda_ctx *ctx, int index, u32 value)
970{
971 struct coda_dev *dev = ctx->dev;
972 u32 *p = ctx->parabuf.vaddr;
973
974 if (dev->devtype->product == CODA_DX6)
975 p[index] = value;
976 else
977 p[index ^ 1] = value;
978}
979
909static int coda_alloc_framebuffers(struct coda_ctx *ctx, struct coda_q_data *q_data, u32 fourcc) 980static int coda_alloc_framebuffers(struct coda_ctx *ctx, struct coda_q_data *q_data, u32 fourcc)
910{ 981{
911 struct coda_dev *dev = ctx->dev; 982 struct coda_dev *dev = ctx->dev;
912 983
913 int height = q_data->height; 984 int height = q_data->height;
914 int width = q_data->width; 985 dma_addr_t paddr;
915 u32 *p; 986 int ysize;
916 int i; 987 int i;
917 988
989 ysize = round_up(q_data->width, 8) * height;
990
918 /* Allocate frame buffers */ 991 /* Allocate frame buffers */
919 ctx->num_internal_frames = CODA_MAX_FRAMEBUFFERS; 992 ctx->num_internal_frames = CODA_MAX_FRAMEBUFFERS;
920 for (i = 0; i < ctx->num_internal_frames; i++) { 993 for (i = 0; i < ctx->num_internal_frames; i++) {
921 ctx->internal_frames[i].size = q_data->sizeimage; 994 ctx->internal_frames[i].size = q_data->sizeimage;
922 if (fourcc == V4L2_PIX_FMT_H264 && dev->devtype->product != CODA_DX6) 995 if (fourcc == V4L2_PIX_FMT_H264 && dev->devtype->product != CODA_DX6)
923 ctx->internal_frames[i].size += width / 2 * height / 2; 996 ctx->internal_frames[i].size += ysize/4;
924 ctx->internal_frames[i].vaddr = dma_alloc_coherent( 997 ctx->internal_frames[i].vaddr = dma_alloc_coherent(
925 &dev->plat_dev->dev, ctx->internal_frames[i].size, 998 &dev->plat_dev->dev, ctx->internal_frames[i].size,
926 &ctx->internal_frames[i].paddr, GFP_KERNEL); 999 &ctx->internal_frames[i].paddr, GFP_KERNEL);
@@ -931,32 +1004,14 @@ static int coda_alloc_framebuffers(struct coda_ctx *ctx, struct coda_q_data *q_d
931 } 1004 }
932 1005
933 /* Register frame buffers in the parameter buffer */ 1006 /* Register frame buffers in the parameter buffer */
934 p = ctx->parabuf.vaddr; 1007 for (i = 0; i < ctx->num_internal_frames; i++) {
1008 paddr = ctx->internal_frames[i].paddr;
1009 coda_parabuf_write(ctx, i * 3 + 0, paddr); /* Y */
1010 coda_parabuf_write(ctx, i * 3 + 1, paddr + ysize); /* Cb */
1011 coda_parabuf_write(ctx, i * 3 + 2, paddr + ysize + ysize/4); /* Cr */
935 1012
936 if (dev->devtype->product == CODA_DX6) { 1013 if (dev->devtype->product != CODA_DX6 && fourcc == V4L2_PIX_FMT_H264)
937 for (i = 0; i < ctx->num_internal_frames; i++) { 1014 coda_parabuf_write(ctx, 96 + i, ctx->internal_frames[i].paddr + ysize + ysize/4 + ysize/4);
938 p[i * 3] = ctx->internal_frames[i].paddr; /* Y */
939 p[i * 3 + 1] = p[i * 3] + width * height; /* Cb */
940 p[i * 3 + 2] = p[i * 3 + 1] + width / 2 * height / 2; /* Cr */
941 }
942 } else {
943 for (i = 0; i < ctx->num_internal_frames; i += 2) {
944 p[i * 3 + 1] = ctx->internal_frames[i].paddr; /* Y */
945 p[i * 3] = p[i * 3 + 1] + width * height; /* Cb */
946 p[i * 3 + 3] = p[i * 3] + (width / 2) * (height / 2); /* Cr */
947
948 if (fourcc == V4L2_PIX_FMT_H264)
949 p[96 + i + 1] = p[i * 3 + 3] + (width / 2) * (height / 2);
950
951 if (i + 1 < ctx->num_internal_frames) {
952 p[i * 3 + 2] = ctx->internal_frames[i+1].paddr; /* Y */
953 p[i * 3 + 5] = p[i * 3 + 2] + width * height ; /* Cb */
954 p[i * 3 + 4] = p[i * 3 + 5] + (width / 2) * (height / 2); /* Cr */
955
956 if (fourcc == V4L2_PIX_FMT_H264)
957 p[96 + i] = p[i * 3 + 4] + (width / 2) * (height / 2);
958 }
959 }
960 } 1015 }
961 1016
962 return 0; 1017 return 0;
@@ -980,6 +1035,28 @@ static int coda_h264_padding(int size, char *p)
980 return nal_size; 1035 return nal_size;
981} 1036}
982 1037
1038static int coda_encode_header(struct coda_ctx *ctx, struct vb2_buffer *buf,
1039 int header_code, u8 *header, int *size)
1040{
1041 struct coda_dev *dev = ctx->dev;
1042 int ret;
1043
1044 coda_write(dev, vb2_dma_contig_plane_dma_addr(buf, 0),
1045 CODA_CMD_ENC_HEADER_BB_START);
1046 coda_write(dev, vb2_plane_size(buf, 0), CODA_CMD_ENC_HEADER_BB_SIZE);
1047 coda_write(dev, header_code, CODA_CMD_ENC_HEADER_CODE);
1048 ret = coda_command_sync(ctx, CODA_COMMAND_ENCODE_HEADER);
1049 if (ret < 0) {
1050 v4l2_err(&dev->v4l2_dev, "CODA_COMMAND_ENCODE_HEADER timeout\n");
1051 return ret;
1052 }
1053 *size = coda_read(dev, CODA_REG_BIT_WR_PTR(ctx->idx)) -
1054 coda_read(dev, CODA_CMD_ENC_HEADER_BB_START);
1055 memcpy(header, vb2_plane_vaddr(buf, 0), *size);
1056
1057 return 0;
1058}
1059
983static int coda_start_streaming(struct vb2_queue *q, unsigned int count) 1060static int coda_start_streaming(struct vb2_queue *q, unsigned int count)
984{ 1061{
985 struct coda_ctx *ctx = vb2_get_drv_priv(q); 1062 struct coda_ctx *ctx = vb2_get_drv_priv(q);
@@ -990,43 +1067,38 @@ static int coda_start_streaming(struct vb2_queue *q, unsigned int count)
990 struct vb2_buffer *buf; 1067 struct vb2_buffer *buf;
991 u32 dst_fourcc; 1068 u32 dst_fourcc;
992 u32 value; 1069 u32 value;
993 int ret; 1070 int ret = 0;
994 1071
995 if (count < 1) 1072 if (count < 1)
996 return -EINVAL; 1073 return -EINVAL;
997 1074
998 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) 1075 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
999 ctx->rawstreamon = 1; 1076 ctx->streamon_out = 1;
1000 else 1077 else
1001 ctx->compstreamon = 1; 1078 ctx->streamon_cap = 1;
1079
1080 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
1081 if (ctx->streamon_out) {
1082 if (coda_format_is_yuv(q_data_src->fourcc))
1083 ctx->inst_type = CODA_INST_ENCODER;
1084 else
1085 ctx->inst_type = CODA_INST_DECODER;
1086 }
1002 1087
1003 /* Don't start the coda unless both queues are on */ 1088 /* Don't start the coda unless both queues are on */
1004 if (!(ctx->rawstreamon & ctx->compstreamon)) 1089 if (!(ctx->streamon_out & ctx->streamon_cap))
1005 return 0; 1090 return 0;
1006 1091
1007 if (coda_isbusy(dev))
1008 if (wait_for_completion_interruptible_timeout(&dev->done, HZ) <= 0)
1009 return -EBUSY;
1010
1011 ctx->gopcounter = ctx->params.gop_size - 1; 1092 ctx->gopcounter = ctx->params.gop_size - 1;
1012
1013 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
1014 buf = v4l2_m2m_next_dst_buf(ctx->m2m_ctx); 1093 buf = v4l2_m2m_next_dst_buf(ctx->m2m_ctx);
1015 bitstream_buf = vb2_dma_contig_plane_dma_addr(buf, 0); 1094 bitstream_buf = vb2_dma_contig_plane_dma_addr(buf, 0);
1016 q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); 1095 q_data_dst = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
1017 bitstream_size = q_data_dst->sizeimage; 1096 bitstream_size = q_data_dst->sizeimage;
1018 dst_fourcc = q_data_dst->fmt->fourcc; 1097 dst_fourcc = q_data_dst->fourcc;
1019 1098
1020 /* Find out whether coda must encode or decode */ 1099 ctx->codec = coda_find_codec(ctx->dev, q_data_src->fourcc,
1021 if (q_data_src->fmt->type == CODA_FMT_RAW && 1100 q_data_dst->fourcc);
1022 q_data_dst->fmt->type == CODA_FMT_ENC) { 1101 if (!ctx->codec) {
1023 ctx->inst_type = CODA_INST_ENCODER;
1024 } else if (q_data_src->fmt->type == CODA_FMT_ENC &&
1025 q_data_dst->fmt->type == CODA_FMT_RAW) {
1026 ctx->inst_type = CODA_INST_DECODER;
1027 v4l2_err(v4l2_dev, "decoding not supported.\n");
1028 return -EINVAL;
1029 } else {
1030 v4l2_err(v4l2_dev, "couldn't tell instance type.\n"); 1102 v4l2_err(v4l2_dev, "couldn't tell instance type.\n");
1031 return -EINVAL; 1103 return -EINVAL;
1032 } 1104 }
@@ -1035,6 +1107,9 @@ static int coda_start_streaming(struct vb2_queue *q, unsigned int count)
1035 v4l2_err(v4l2_dev, "coda is not initialized.\n"); 1107 v4l2_err(v4l2_dev, "coda is not initialized.\n");
1036 return -EFAULT; 1108 return -EFAULT;
1037 } 1109 }
1110
1111 mutex_lock(&dev->coda_mutex);
1112
1038 coda_write(dev, ctx->parabuf.paddr, CODA_REG_BIT_PARA_BUF_ADDR); 1113 coda_write(dev, ctx->parabuf.paddr, CODA_REG_BIT_PARA_BUF_ADDR);
1039 coda_write(dev, bitstream_buf, CODA_REG_BIT_RD_PTR(ctx->idx)); 1114 coda_write(dev, bitstream_buf, CODA_REG_BIT_RD_PTR(ctx->idx));
1040 coda_write(dev, bitstream_buf, CODA_REG_BIT_WR_PTR(ctx->idx)); 1115 coda_write(dev, bitstream_buf, CODA_REG_BIT_WR_PTR(ctx->idx));
@@ -1057,38 +1132,31 @@ static int coda_start_streaming(struct vb2_queue *q, unsigned int count)
1057 switch (dev->devtype->product) { 1132 switch (dev->devtype->product) {
1058 case CODA_DX6: 1133 case CODA_DX6:
1059 value = (q_data_src->width & CODADX6_PICWIDTH_MASK) << CODADX6_PICWIDTH_OFFSET; 1134 value = (q_data_src->width & CODADX6_PICWIDTH_MASK) << CODADX6_PICWIDTH_OFFSET;
1135 value |= (q_data_src->height & CODADX6_PICHEIGHT_MASK) << CODA_PICHEIGHT_OFFSET;
1060 break; 1136 break;
1061 default: 1137 default:
1062 value = (q_data_src->width & CODA7_PICWIDTH_MASK) << CODA7_PICWIDTH_OFFSET; 1138 value = (q_data_src->width & CODA7_PICWIDTH_MASK) << CODA7_PICWIDTH_OFFSET;
1139 value |= (q_data_src->height & CODA7_PICHEIGHT_MASK) << CODA_PICHEIGHT_OFFSET;
1063 } 1140 }
1064 value |= (q_data_src->height & CODA_PICHEIGHT_MASK) << CODA_PICHEIGHT_OFFSET;
1065 coda_write(dev, value, CODA_CMD_ENC_SEQ_SRC_SIZE); 1141 coda_write(dev, value, CODA_CMD_ENC_SEQ_SRC_SIZE);
1066 coda_write(dev, ctx->params.framerate, 1142 coda_write(dev, ctx->params.framerate,
1067 CODA_CMD_ENC_SEQ_SRC_F_RATE); 1143 CODA_CMD_ENC_SEQ_SRC_F_RATE);
1068 1144
1145 ctx->params.codec_mode = ctx->codec->mode;
1069 switch (dst_fourcc) { 1146 switch (dst_fourcc) {
1070 case V4L2_PIX_FMT_MPEG4: 1147 case V4L2_PIX_FMT_MPEG4:
1071 if (dev->devtype->product == CODA_DX6)
1072 ctx->params.codec_mode = CODADX6_MODE_ENCODE_MP4;
1073 else
1074 ctx->params.codec_mode = CODA7_MODE_ENCODE_MP4;
1075
1076 coda_write(dev, CODA_STD_MPEG4, CODA_CMD_ENC_SEQ_COD_STD); 1148 coda_write(dev, CODA_STD_MPEG4, CODA_CMD_ENC_SEQ_COD_STD);
1077 coda_write(dev, 0, CODA_CMD_ENC_SEQ_MP4_PARA); 1149 coda_write(dev, 0, CODA_CMD_ENC_SEQ_MP4_PARA);
1078 break; 1150 break;
1079 case V4L2_PIX_FMT_H264: 1151 case V4L2_PIX_FMT_H264:
1080 if (dev->devtype->product == CODA_DX6)
1081 ctx->params.codec_mode = CODADX6_MODE_ENCODE_H264;
1082 else
1083 ctx->params.codec_mode = CODA7_MODE_ENCODE_H264;
1084
1085 coda_write(dev, CODA_STD_H264, CODA_CMD_ENC_SEQ_COD_STD); 1152 coda_write(dev, CODA_STD_H264, CODA_CMD_ENC_SEQ_COD_STD);
1086 coda_write(dev, 0, CODA_CMD_ENC_SEQ_264_PARA); 1153 coda_write(dev, 0, CODA_CMD_ENC_SEQ_264_PARA);
1087 break; 1154 break;
1088 default: 1155 default:
1089 v4l2_err(v4l2_dev, 1156 v4l2_err(v4l2_dev,
1090 "dst format (0x%08x) invalid.\n", dst_fourcc); 1157 "dst format (0x%08x) invalid.\n", dst_fourcc);
1091 return -EINVAL; 1158 ret = -EINVAL;
1159 goto out;
1092 } 1160 }
1093 1161
1094 switch (ctx->params.slice_mode) { 1162 switch (ctx->params.slice_mode) {
@@ -1129,8 +1197,14 @@ static int coda_start_streaming(struct vb2_queue *q, unsigned int count)
1129 value = (CODA_DEFAULT_GAMMA & CODA_GAMMA_MASK) << CODA_GAMMA_OFFSET; 1197 value = (CODA_DEFAULT_GAMMA & CODA_GAMMA_MASK) << CODA_GAMMA_OFFSET;
1130 coda_write(dev, value, CODA_CMD_ENC_SEQ_RC_GAMMA); 1198 coda_write(dev, value, CODA_CMD_ENC_SEQ_RC_GAMMA);
1131 1199
1132 value = (CODA_DEFAULT_GAMMA > 0) << CODA_OPTION_GAMMA_OFFSET; 1200 if (CODA_DEFAULT_GAMMA > 0) {
1133 value |= (0 & CODA_OPTION_SLICEREPORT_MASK) << CODA_OPTION_SLICEREPORT_OFFSET; 1201 if (dev->devtype->product == CODA_DX6)
1202 value = 1 << CODADX6_OPTION_GAMMA_OFFSET;
1203 else
1204 value = 1 << CODA7_OPTION_GAMMA_OFFSET;
1205 } else {
1206 value = 0;
1207 }
1134 coda_write(dev, value, CODA_CMD_ENC_SEQ_OPTION); 1208 coda_write(dev, value, CODA_CMD_ENC_SEQ_OPTION);
1135 1209
1136 if (dst_fourcc == V4L2_PIX_FMT_H264) { 1210 if (dst_fourcc == V4L2_PIX_FMT_H264) {
@@ -1145,17 +1219,23 @@ static int coda_start_streaming(struct vb2_queue *q, unsigned int count)
1145 } 1219 }
1146 } 1220 }
1147 1221
1148 if (coda_command_sync(ctx, CODA_COMMAND_SEQ_INIT)) { 1222 ret = coda_command_sync(ctx, CODA_COMMAND_SEQ_INIT);
1223 if (ret < 0) {
1149 v4l2_err(v4l2_dev, "CODA_COMMAND_SEQ_INIT timeout\n"); 1224 v4l2_err(v4l2_dev, "CODA_COMMAND_SEQ_INIT timeout\n");
1150 return -ETIMEDOUT; 1225 goto out;
1151 } 1226 }
1152 1227
1153 if (coda_read(dev, CODA_RET_ENC_SEQ_SUCCESS) == 0) 1228 if (coda_read(dev, CODA_RET_ENC_SEQ_SUCCESS) == 0) {
1154 return -EFAULT; 1229 v4l2_err(v4l2_dev, "CODA_COMMAND_SEQ_INIT failed\n");
1230 ret = -EFAULT;
1231 goto out;
1232 }
1155 1233
1156 ret = coda_alloc_framebuffers(ctx, q_data_src, dst_fourcc); 1234 ret = coda_alloc_framebuffers(ctx, q_data_src, dst_fourcc);
1157 if (ret < 0) 1235 if (ret < 0) {
1158 return ret; 1236 v4l2_err(v4l2_dev, "failed to allocate framebuffers\n");
1237 goto out;
1238 }
1159 1239
1160 coda_write(dev, ctx->num_internal_frames, CODA_CMD_SET_FRAME_BUF_NUM); 1240 coda_write(dev, ctx->num_internal_frames, CODA_CMD_SET_FRAME_BUF_NUM);
1161 coda_write(dev, round_up(q_data_src->width, 8), CODA_CMD_SET_FRAME_BUF_STRIDE); 1241 coda_write(dev, round_up(q_data_src->width, 8), CODA_CMD_SET_FRAME_BUF_STRIDE);
@@ -1167,9 +1247,10 @@ static int coda_start_streaming(struct vb2_queue *q, unsigned int count)
1167 coda_write(dev, dev->iram_paddr + 68 * 1024, CODA7_CMD_SET_FRAME_AXI_IPACDC_ADDR); 1247 coda_write(dev, dev->iram_paddr + 68 * 1024, CODA7_CMD_SET_FRAME_AXI_IPACDC_ADDR);
1168 coda_write(dev, 0x0, CODA7_CMD_SET_FRAME_AXI_OVL_ADDR); 1248 coda_write(dev, 0x0, CODA7_CMD_SET_FRAME_AXI_OVL_ADDR);
1169 } 1249 }
1170 if (coda_command_sync(ctx, CODA_COMMAND_SET_FRAME_BUF)) { 1250 ret = coda_command_sync(ctx, CODA_COMMAND_SET_FRAME_BUF);
1251 if (ret < 0) {
1171 v4l2_err(v4l2_dev, "CODA_COMMAND_SET_FRAME_BUF timeout\n"); 1252 v4l2_err(v4l2_dev, "CODA_COMMAND_SET_FRAME_BUF timeout\n");
1172 return -ETIMEDOUT; 1253 goto out;
1173 } 1254 }
1174 1255
1175 /* Save stream headers */ 1256 /* Save stream headers */
@@ -1180,33 +1261,22 @@ static int coda_start_streaming(struct vb2_queue *q, unsigned int count)
1180 * Get SPS in the first frame and copy it to an 1261 * Get SPS in the first frame and copy it to an
1181 * intermediate buffer. 1262 * intermediate buffer.
1182 */ 1263 */
1183 coda_write(dev, vb2_dma_contig_plane_dma_addr(buf, 0), CODA_CMD_ENC_HEADER_BB_START); 1264 ret = coda_encode_header(ctx, buf, CODA_HEADER_H264_SPS,
1184 coda_write(dev, bitstream_size, CODA_CMD_ENC_HEADER_BB_SIZE); 1265 &ctx->vpu_header[0][0],
1185 coda_write(dev, CODA_HEADER_H264_SPS, CODA_CMD_ENC_HEADER_CODE); 1266 &ctx->vpu_header_size[0]);
1186 if (coda_command_sync(ctx, CODA_COMMAND_ENCODE_HEADER)) { 1267 if (ret < 0)
1187 v4l2_err(v4l2_dev, "CODA_COMMAND_ENCODE_HEADER timeout\n"); 1268 goto out;
1188 return -ETIMEDOUT;
1189 }
1190 ctx->vpu_header_size[0] = coda_read(dev, CODA_REG_BIT_WR_PTR(ctx->idx)) -
1191 coda_read(dev, CODA_CMD_ENC_HEADER_BB_START);
1192 memcpy(&ctx->vpu_header[0][0], vb2_plane_vaddr(buf, 0),
1193 ctx->vpu_header_size[0]);
1194 1269
1195 /* 1270 /*
1196 * Get PPS in the first frame and copy it to an 1271 * Get PPS in the first frame and copy it to an
1197 * intermediate buffer. 1272 * intermediate buffer.
1198 */ 1273 */
1199 coda_write(dev, vb2_dma_contig_plane_dma_addr(buf, 0), CODA_CMD_ENC_HEADER_BB_START); 1274 ret = coda_encode_header(ctx, buf, CODA_HEADER_H264_PPS,
1200 coda_write(dev, bitstream_size, CODA_CMD_ENC_HEADER_BB_SIZE); 1275 &ctx->vpu_header[1][0],
1201 coda_write(dev, CODA_HEADER_H264_PPS, CODA_CMD_ENC_HEADER_CODE); 1276 &ctx->vpu_header_size[1]);
1202 if (coda_command_sync(ctx, CODA_COMMAND_ENCODE_HEADER)) { 1277 if (ret < 0)
1203 v4l2_err(v4l2_dev, "CODA_COMMAND_ENCODE_HEADER timeout\n"); 1278 goto out;
1204 return -ETIMEDOUT; 1279
1205 }
1206 ctx->vpu_header_size[1] = coda_read(dev, CODA_REG_BIT_WR_PTR(ctx->idx)) -
1207 coda_read(dev, CODA_CMD_ENC_HEADER_BB_START);
1208 memcpy(&ctx->vpu_header[1][0], vb2_plane_vaddr(buf, 0),
1209 ctx->vpu_header_size[1]);
1210 /* 1280 /*
1211 * Length of H.264 headers is variable and thus it might not be 1281 * Length of H.264 headers is variable and thus it might not be
1212 * aligned for the coda to append the encoded frame. In that is 1282 * aligned for the coda to append the encoded frame. In that is
@@ -1222,48 +1292,32 @@ static int coda_start_streaming(struct vb2_queue *q, unsigned int count)
1222 * Get VOS in the first frame and copy it to an 1292 * Get VOS in the first frame and copy it to an
1223 * intermediate buffer 1293 * intermediate buffer
1224 */ 1294 */
1225 coda_write(dev, vb2_dma_contig_plane_dma_addr(buf, 0), CODA_CMD_ENC_HEADER_BB_START); 1295 ret = coda_encode_header(ctx, buf, CODA_HEADER_MP4V_VOS,
1226 coda_write(dev, bitstream_size, CODA_CMD_ENC_HEADER_BB_SIZE); 1296 &ctx->vpu_header[0][0],
1227 coda_write(dev, CODA_HEADER_MP4V_VOS, CODA_CMD_ENC_HEADER_CODE); 1297 &ctx->vpu_header_size[0]);
1228 if (coda_command_sync(ctx, CODA_COMMAND_ENCODE_HEADER)) { 1298 if (ret < 0)
1229 v4l2_err(v4l2_dev, "CODA_COMMAND_ENCODE_HEADER timeout\n"); 1299 goto out;
1230 return -ETIMEDOUT; 1300
1231 } 1301 ret = coda_encode_header(ctx, buf, CODA_HEADER_MP4V_VIS,
1232 ctx->vpu_header_size[0] = coda_read(dev, CODA_REG_BIT_WR_PTR(ctx->idx)) - 1302 &ctx->vpu_header[1][0],
1233 coda_read(dev, CODA_CMD_ENC_HEADER_BB_START); 1303 &ctx->vpu_header_size[1]);
1234 memcpy(&ctx->vpu_header[0][0], vb2_plane_vaddr(buf, 0), 1304 if (ret < 0)
1235 ctx->vpu_header_size[0]); 1305 goto out;
1236 1306
1237 coda_write(dev, vb2_dma_contig_plane_dma_addr(buf, 0), CODA_CMD_ENC_HEADER_BB_START); 1307 ret = coda_encode_header(ctx, buf, CODA_HEADER_MP4V_VOL,
1238 coda_write(dev, bitstream_size, CODA_CMD_ENC_HEADER_BB_SIZE); 1308 &ctx->vpu_header[2][0],
1239 coda_write(dev, CODA_HEADER_MP4V_VIS, CODA_CMD_ENC_HEADER_CODE); 1309 &ctx->vpu_header_size[2]);
1240 if (coda_command_sync(ctx, CODA_COMMAND_ENCODE_HEADER)) { 1310 if (ret < 0)
1241 v4l2_err(v4l2_dev, "CODA_COMMAND_ENCODE_HEADER failed\n"); 1311 goto out;
1242 return -ETIMEDOUT;
1243 }
1244 ctx->vpu_header_size[1] = coda_read(dev, CODA_REG_BIT_WR_PTR(ctx->idx)) -
1245 coda_read(dev, CODA_CMD_ENC_HEADER_BB_START);
1246 memcpy(&ctx->vpu_header[1][0], vb2_plane_vaddr(buf, 0),
1247 ctx->vpu_header_size[1]);
1248
1249 coda_write(dev, vb2_dma_contig_plane_dma_addr(buf, 0), CODA_CMD_ENC_HEADER_BB_START);
1250 coda_write(dev, bitstream_size, CODA_CMD_ENC_HEADER_BB_SIZE);
1251 coda_write(dev, CODA_HEADER_MP4V_VOL, CODA_CMD_ENC_HEADER_CODE);
1252 if (coda_command_sync(ctx, CODA_COMMAND_ENCODE_HEADER)) {
1253 v4l2_err(v4l2_dev, "CODA_COMMAND_ENCODE_HEADER failed\n");
1254 return -ETIMEDOUT;
1255 }
1256 ctx->vpu_header_size[2] = coda_read(dev, CODA_REG_BIT_WR_PTR(ctx->idx)) -
1257 coda_read(dev, CODA_CMD_ENC_HEADER_BB_START);
1258 memcpy(&ctx->vpu_header[2][0], vb2_plane_vaddr(buf, 0),
1259 ctx->vpu_header_size[2]);
1260 break; 1312 break;
1261 default: 1313 default:
1262 /* No more formats need to save headers at the moment */ 1314 /* No more formats need to save headers at the moment */
1263 break; 1315 break;
1264 } 1316 }
1265 1317
1266 return 0; 1318out:
1319 mutex_unlock(&dev->coda_mutex);
1320 return ret;
1267} 1321}
1268 1322
1269static int coda_stop_streaming(struct vb2_queue *q) 1323static int coda_stop_streaming(struct vb2_queue *q)
@@ -1274,26 +1328,20 @@ static int coda_stop_streaming(struct vb2_queue *q)
1274 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) { 1328 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
1275 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, 1329 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
1276 "%s: output\n", __func__); 1330 "%s: output\n", __func__);
1277 ctx->rawstreamon = 0; 1331 ctx->streamon_out = 0;
1278 } else { 1332 } else {
1279 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, 1333 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
1280 "%s: capture\n", __func__); 1334 "%s: capture\n", __func__);
1281 ctx->compstreamon = 0; 1335 ctx->streamon_cap = 0;
1282 } 1336 }
1283 1337
1284 /* Don't stop the coda unless both queues are off */ 1338 /* Don't stop the coda unless both queues are off */
1285 if (ctx->rawstreamon || ctx->compstreamon) 1339 if (ctx->streamon_out || ctx->streamon_cap)
1286 return 0; 1340 return 0;
1287 1341
1288 if (coda_isbusy(dev)) {
1289 if (wait_for_completion_interruptible_timeout(&dev->done, HZ) <= 0) {
1290 v4l2_warn(&dev->v4l2_dev,
1291 "%s: timeout, sending SEQ_END anyway\n", __func__);
1292 }
1293 }
1294
1295 cancel_delayed_work(&dev->timeout); 1342 cancel_delayed_work(&dev->timeout);
1296 1343
1344 mutex_lock(&dev->coda_mutex);
1297 v4l2_dbg(1, coda_debug, &dev->v4l2_dev, 1345 v4l2_dbg(1, coda_debug, &dev->v4l2_dev,
1298 "%s: sent command 'SEQ_END' to coda\n", __func__); 1346 "%s: sent command 'SEQ_END' to coda\n", __func__);
1299 if (coda_command_sync(ctx, CODA_COMMAND_SEQ_END)) { 1347 if (coda_command_sync(ctx, CODA_COMMAND_SEQ_END)) {
@@ -1301,6 +1349,7 @@ static int coda_stop_streaming(struct vb2_queue *q)
1301 "CODA_COMMAND_SEQ_END failed\n"); 1349 "CODA_COMMAND_SEQ_END failed\n");
1302 return -ETIMEDOUT; 1350 return -ETIMEDOUT;
1303 } 1351 }
1352 mutex_unlock(&dev->coda_mutex);
1304 1353
1305 coda_free_framebuffers(ctx); 1354 coda_free_framebuffers(ctx);
1306 1355
@@ -1431,7 +1480,7 @@ static int coda_queue_init(void *priv, struct vb2_queue *src_vq,
1431 int ret; 1480 int ret;
1432 1481
1433 src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT; 1482 src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
1434 src_vq->io_modes = VB2_MMAP | VB2_USERPTR; 1483 src_vq->io_modes = VB2_DMABUF | VB2_MMAP | VB2_USERPTR;
1435 src_vq->drv_priv = ctx; 1484 src_vq->drv_priv = ctx;
1436 src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer); 1485 src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
1437 src_vq->ops = &coda_qops; 1486 src_vq->ops = &coda_qops;
@@ -1443,7 +1492,7 @@ static int coda_queue_init(void *priv, struct vb2_queue *src_vq,
1443 return ret; 1492 return ret;
1444 1493
1445 dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 1494 dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1446 dst_vq->io_modes = VB2_MMAP | VB2_USERPTR; 1495 dst_vq->io_modes = VB2_DMABUF | VB2_MMAP | VB2_USERPTR;
1447 dst_vq->drv_priv = ctx; 1496 dst_vq->drv_priv = ctx;
1448 dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer); 1497 dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
1449 dst_vq->ops = &coda_qops; 1498 dst_vq->ops = &coda_qops;
@@ -1484,7 +1533,7 @@ static int coda_open(struct file *file)
1484 ctx->m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, ctx, 1533 ctx->m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, ctx,
1485 &coda_queue_init); 1534 &coda_queue_init);
1486 if (IS_ERR(ctx->m2m_ctx)) { 1535 if (IS_ERR(ctx->m2m_ctx)) {
1487 int ret = PTR_ERR(ctx->m2m_ctx); 1536 ret = PTR_ERR(ctx->m2m_ctx);
1488 1537
1489 v4l2_err(&dev->v4l2_dev, "%s return error (%d)\n", 1538 v4l2_err(&dev->v4l2_dev, "%s return error (%d)\n",
1490 __func__, ret); 1539 __func__, ret);
@@ -1596,12 +1645,14 @@ static irqreturn_t coda_irq_handler(int irq, void *data)
1596 ctx = v4l2_m2m_get_curr_priv(dev->m2m_dev); 1645 ctx = v4l2_m2m_get_curr_priv(dev->m2m_dev);
1597 if (ctx == NULL) { 1646 if (ctx == NULL) {
1598 v4l2_err(&dev->v4l2_dev, "Instance released before the end of transaction\n"); 1647 v4l2_err(&dev->v4l2_dev, "Instance released before the end of transaction\n");
1648 mutex_unlock(&dev->coda_mutex);
1599 return IRQ_HANDLED; 1649 return IRQ_HANDLED;
1600 } 1650 }
1601 1651
1602 if (ctx->aborting) { 1652 if (ctx->aborting) {
1603 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, 1653 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
1604 "task has been aborted\n"); 1654 "task has been aborted\n");
1655 mutex_unlock(&dev->coda_mutex);
1605 return IRQ_HANDLED; 1656 return IRQ_HANDLED;
1606 } 1657 }
1607 1658
@@ -1611,8 +1662,6 @@ static irqreturn_t coda_irq_handler(int irq, void *data)
1611 return IRQ_NONE; 1662 return IRQ_NONE;
1612 } 1663 }
1613 1664
1614 complete(&dev->done);
1615
1616 src_buf = v4l2_m2m_src_buf_remove(ctx->m2m_ctx); 1665 src_buf = v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
1617 dst_buf = v4l2_m2m_dst_buf_remove(ctx->m2m_ctx); 1666 dst_buf = v4l2_m2m_dst_buf_remove(ctx->m2m_ctx);
1618 1667
@@ -1660,6 +1709,8 @@ static irqreturn_t coda_irq_handler(int irq, void *data)
1660 (dst_buf->v4l2_buf.flags & V4L2_BUF_FLAG_KEYFRAME) ? 1709 (dst_buf->v4l2_buf.flags & V4L2_BUF_FLAG_KEYFRAME) ?
1661 "KEYFRAME" : "PFRAME"); 1710 "KEYFRAME" : "PFRAME");
1662 1711
1712 mutex_unlock(&dev->coda_mutex);
1713
1663 v4l2_m2m_job_finish(ctx->dev->m2m_dev, ctx->m2m_ctx); 1714 v4l2_m2m_job_finish(ctx->dev->m2m_dev, ctx->m2m_ctx);
1664 1715
1665 return IRQ_HANDLED; 1716 return IRQ_HANDLED;
@@ -1671,12 +1722,7 @@ static void coda_timeout(struct work_struct *work)
1671 struct coda_dev *dev = container_of(to_delayed_work(work), 1722 struct coda_dev *dev = container_of(to_delayed_work(work),
1672 struct coda_dev, timeout); 1723 struct coda_dev, timeout);
1673 1724
1674 if (completion_done(&dev->done)) 1725 dev_err(&dev->plat_dev->dev, "CODA PIC_RUN timeout, stopping all streams\n");
1675 return;
1676
1677 complete(&dev->done);
1678
1679 v4l2_err(&dev->v4l2_dev, "CODA PIC_RUN timeout, stopping all streams\n");
1680 1726
1681 mutex_lock(&dev->dev_mutex); 1727 mutex_lock(&dev->dev_mutex);
1682 list_for_each_entry(ctx, &dev->instances, list) { 1728 list_for_each_entry(ctx, &dev->instances, list) {
@@ -1684,6 +1730,10 @@ static void coda_timeout(struct work_struct *work)
1684 v4l2_m2m_streamoff(NULL, ctx->m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); 1730 v4l2_m2m_streamoff(NULL, ctx->m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
1685 } 1731 }
1686 mutex_unlock(&dev->dev_mutex); 1732 mutex_unlock(&dev->dev_mutex);
1733
1734 mutex_unlock(&dev->coda_mutex);
1735 ctx = v4l2_m2m_get_curr_priv(dev->m2m_dev);
1736 v4l2_m2m_job_finish(ctx->dev->m2m_dev, ctx->m2m_ctx);
1687} 1737}
1688 1738
1689static u32 coda_supported_firmwares[] = { 1739static u32 coda_supported_firmwares[] = {
@@ -1748,6 +1798,10 @@ static int coda_hw_init(struct coda_dev *dev)
1748 } 1798 }
1749 } 1799 }
1750 1800
1801 /* Clear registers */
1802 for (i = 0; i < 64; i++)
1803 coda_write(dev, 0, CODA_REG_BIT_CODE_BUF_ADDR + i * 4);
1804
1751 /* Tell the BIT where to find everything it needs */ 1805 /* Tell the BIT where to find everything it needs */
1752 coda_write(dev, dev->workbuf.paddr, 1806 coda_write(dev, dev->workbuf.paddr,
1753 CODA_REG_BIT_WORK_BUF_ADDR); 1807 CODA_REG_BIT_WORK_BUF_ADDR);
@@ -1911,16 +1965,16 @@ enum coda_platform {
1911 1965
1912static const struct coda_devtype coda_devdata[] = { 1966static const struct coda_devtype coda_devdata[] = {
1913 [CODA_IMX27] = { 1967 [CODA_IMX27] = {
1914 .firmware = "v4l-codadx6-imx27.bin", 1968 .firmware = "v4l-codadx6-imx27.bin",
1915 .product = CODA_DX6, 1969 .product = CODA_DX6,
1916 .formats = codadx6_formats, 1970 .codecs = codadx6_codecs,
1917 .num_formats = ARRAY_SIZE(codadx6_formats), 1971 .num_codecs = ARRAY_SIZE(codadx6_codecs),
1918 }, 1972 },
1919 [CODA_IMX53] = { 1973 [CODA_IMX53] = {
1920 .firmware = "v4l-coda7541-imx53.bin", 1974 .firmware = "v4l-coda7541-imx53.bin",
1921 .product = CODA_7541, 1975 .product = CODA_7541,
1922 .formats = coda7_formats, 1976 .codecs = coda7_codecs,
1923 .num_formats = ARRAY_SIZE(coda7_formats), 1977 .num_codecs = ARRAY_SIZE(coda7_codecs),
1924 }, 1978 },
1925}; 1979};
1926 1980
@@ -1962,8 +2016,6 @@ static int coda_probe(struct platform_device *pdev)
1962 spin_lock_init(&dev->irqlock); 2016 spin_lock_init(&dev->irqlock);
1963 INIT_LIST_HEAD(&dev->instances); 2017 INIT_LIST_HEAD(&dev->instances);
1964 INIT_DELAYED_WORK(&dev->timeout, coda_timeout); 2018 INIT_DELAYED_WORK(&dev->timeout, coda_timeout);
1965 init_completion(&dev->done);
1966 complete(&dev->done);
1967 2019
1968 dev->plat_dev = pdev; 2020 dev->plat_dev = pdev;
1969 dev->clk_per = devm_clk_get(&pdev->dev, "per"); 2021 dev->clk_per = devm_clk_get(&pdev->dev, "per");
@@ -1985,17 +2037,9 @@ static int coda_probe(struct platform_device *pdev)
1985 return -ENOENT; 2037 return -ENOENT;
1986 } 2038 }
1987 2039
1988 if (devm_request_mem_region(&pdev->dev, res->start, 2040 dev->regs_base = devm_ioremap_resource(&pdev->dev, res);
1989 resource_size(res), CODA_NAME) == NULL) { 2041 if (IS_ERR(dev->regs_base))
1990 dev_err(&pdev->dev, "failed to request memory region\n"); 2042 return PTR_ERR(dev->regs_base);
1991 return -ENOENT;
1992 }
1993 dev->regs_base = devm_ioremap(&pdev->dev, res->start,
1994 resource_size(res));
1995 if (!dev->regs_base) {
1996 dev_err(&pdev->dev, "failed to ioremap address region\n");
1997 return -ENOENT;
1998 }
1999 2043
2000 /* IRQ */ 2044 /* IRQ */
2001 irq = platform_get_irq(pdev, 0); 2045 irq = platform_get_irq(pdev, 0);
@@ -2025,6 +2069,7 @@ static int coda_probe(struct platform_device *pdev)
2025 return ret; 2069 return ret;
2026 2070
2027 mutex_init(&dev->dev_mutex); 2071 mutex_init(&dev->dev_mutex);
2072 mutex_init(&dev->coda_mutex);
2028 2073
2029 pdev_id = of_id ? of_id->data : platform_get_device_id(pdev); 2074 pdev_id = of_id ? of_id->data : platform_get_device_id(pdev);
2030 2075
diff --git a/drivers/media/platform/coda.h b/drivers/media/platform/coda.h
index f3f5e43c1ac2..ace0bf0a3b9c 100644
--- a/drivers/media/platform/coda.h
+++ b/drivers/media/platform/coda.h
@@ -96,16 +96,12 @@
96#define CODA_CMD_ENC_SEQ_BB_START 0x180 96#define CODA_CMD_ENC_SEQ_BB_START 0x180
97#define CODA_CMD_ENC_SEQ_BB_SIZE 0x184 97#define CODA_CMD_ENC_SEQ_BB_SIZE 0x184
98#define CODA_CMD_ENC_SEQ_OPTION 0x188 98#define CODA_CMD_ENC_SEQ_OPTION 0x188
99#define CODA_OPTION_GAMMA_OFFSET 7 99#define CODA7_OPTION_GAMMA_OFFSET 8
100#define CODA_OPTION_GAMMA_MASK 0x01 100#define CODADX6_OPTION_GAMMA_OFFSET 7
101#define CODA_OPTION_LIMITQP_OFFSET 6 101#define CODA_OPTION_LIMITQP_OFFSET 6
102#define CODA_OPTION_LIMITQP_MASK 0x01
103#define CODA_OPTION_RCINTRAQP_OFFSET 5 102#define CODA_OPTION_RCINTRAQP_OFFSET 5
104#define CODA_OPTION_RCINTRAQP_MASK 0x01
105#define CODA_OPTION_FMO_OFFSET 4 103#define CODA_OPTION_FMO_OFFSET 4
106#define CODA_OPTION_FMO_MASK 0x01
107#define CODA_OPTION_SLICEREPORT_OFFSET 1 104#define CODA_OPTION_SLICEREPORT_OFFSET 1
108#define CODA_OPTION_SLICEREPORT_MASK 0x01
109#define CODA_CMD_ENC_SEQ_COD_STD 0x18c 105#define CODA_CMD_ENC_SEQ_COD_STD 0x18c
110#define CODA_STD_MPEG4 0 106#define CODA_STD_MPEG4 0
111#define CODA_STD_H263 1 107#define CODA_STD_H263 1
@@ -117,7 +113,8 @@
117#define CODADX6_PICWIDTH_OFFSET 10 113#define CODADX6_PICWIDTH_OFFSET 10
118#define CODADX6_PICWIDTH_MASK 0x3ff 114#define CODADX6_PICWIDTH_MASK 0x3ff
119#define CODA_PICHEIGHT_OFFSET 0 115#define CODA_PICHEIGHT_OFFSET 0
120#define CODA_PICHEIGHT_MASK 0x3ff 116#define CODADX6_PICHEIGHT_MASK 0x3ff
117#define CODA7_PICHEIGHT_MASK 0xffff
121#define CODA_CMD_ENC_SEQ_SRC_F_RATE 0x194 118#define CODA_CMD_ENC_SEQ_SRC_F_RATE 0x194
122#define CODA_CMD_ENC_SEQ_MP4_PARA 0x198 119#define CODA_CMD_ENC_SEQ_MP4_PARA 0x198
123#define CODA_MP4PARAM_VERID_OFFSET 6 120#define CODA_MP4PARAM_VERID_OFFSET 6
diff --git a/drivers/media/platform/davinci/vpbe_display.c b/drivers/media/platform/davinci/vpbe_display.c
index d0b375cf565f..e180ff7282d9 100644
--- a/drivers/media/platform/davinci/vpbe_display.c
+++ b/drivers/media/platform/davinci/vpbe_display.c
@@ -944,7 +944,7 @@ static int vpbe_display_s_fmt(struct file *file, void *priv,
944 cfg->interlaced = vpbe_dev->current_timings.interlaced; 944 cfg->interlaced = vpbe_dev->current_timings.interlaced;
945 945
946 if (V4L2_PIX_FMT_UYVY == pixfmt->pixelformat) 946 if (V4L2_PIX_FMT_UYVY == pixfmt->pixelformat)
947 cfg->pixfmt = PIXFMT_YCbCrI; 947 cfg->pixfmt = PIXFMT_YCBCRI;
948 948
949 /* Change of the default pixel format for both video windows */ 949 /* Change of the default pixel format for both video windows */
950 if (V4L2_PIX_FMT_NV12 == pixfmt->pixelformat) { 950 if (V4L2_PIX_FMT_NV12 == pixfmt->pixelformat) {
@@ -1593,31 +1593,6 @@ static int vpbe_display_release(struct file *file)
1593 return 0; 1593 return 0;
1594} 1594}
1595 1595
1596#ifdef CONFIG_VIDEO_ADV_DEBUG
1597static int vpbe_display_g_register(struct file *file, void *priv,
1598 struct v4l2_dbg_register *reg)
1599{
1600 struct v4l2_dbg_match *match = &reg->match;
1601 struct vpbe_fh *fh = file->private_data;
1602 struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
1603
1604 if (match->type >= 2) {
1605 v4l2_subdev_call(vpbe_dev->venc,
1606 core,
1607 g_register,
1608 reg);
1609 }
1610
1611 return 0;
1612}
1613
1614static int vpbe_display_s_register(struct file *file, void *priv,
1615 const struct v4l2_dbg_register *reg)
1616{
1617 return 0;
1618}
1619#endif
1620
1621/* vpbe capture ioctl operations */ 1596/* vpbe capture ioctl operations */
1622static const struct v4l2_ioctl_ops vpbe_ioctl_ops = { 1597static const struct v4l2_ioctl_ops vpbe_ioctl_ops = {
1623 .vidioc_querycap = vpbe_display_querycap, 1598 .vidioc_querycap = vpbe_display_querycap,
@@ -1644,10 +1619,6 @@ static const struct v4l2_ioctl_ops vpbe_ioctl_ops = {
1644 .vidioc_s_dv_timings = vpbe_display_s_dv_timings, 1619 .vidioc_s_dv_timings = vpbe_display_s_dv_timings,
1645 .vidioc_g_dv_timings = vpbe_display_g_dv_timings, 1620 .vidioc_g_dv_timings = vpbe_display_g_dv_timings,
1646 .vidioc_enum_dv_timings = vpbe_display_enum_dv_timings, 1621 .vidioc_enum_dv_timings = vpbe_display_enum_dv_timings,
1647#ifdef CONFIG_VIDEO_ADV_DEBUG
1648 .vidioc_g_register = vpbe_display_g_register,
1649 .vidioc_s_register = vpbe_display_s_register,
1650#endif
1651}; 1622};
1652 1623
1653static struct v4l2_file_operations vpbe_fops = { 1624static struct v4l2_file_operations vpbe_fops = {
diff --git a/drivers/media/platform/davinci/vpbe_osd.c b/drivers/media/platform/davinci/vpbe_osd.c
index 396a51cbede7..6ed82e8b297b 100644
--- a/drivers/media/platform/davinci/vpbe_osd.c
+++ b/drivers/media/platform/davinci/vpbe_osd.c
@@ -119,7 +119,7 @@ static inline u32 osd_modify(struct osd_state *sd, u32 mask, u32 val,
119#define is_rgb_pixfmt(pixfmt) \ 119#define is_rgb_pixfmt(pixfmt) \
120 (((pixfmt) == PIXFMT_RGB565) || ((pixfmt) == PIXFMT_RGB888)) 120 (((pixfmt) == PIXFMT_RGB565) || ((pixfmt) == PIXFMT_RGB888))
121#define is_yc_pixfmt(pixfmt) \ 121#define is_yc_pixfmt(pixfmt) \
122 (((pixfmt) == PIXFMT_YCbCrI) || ((pixfmt) == PIXFMT_YCrCbI) || \ 122 (((pixfmt) == PIXFMT_YCBCRI) || ((pixfmt) == PIXFMT_YCRCBI) || \
123 ((pixfmt) == PIXFMT_NV12)) 123 ((pixfmt) == PIXFMT_NV12))
124#define MAX_WIN_SIZE OSD_VIDWIN0XP_V0X 124#define MAX_WIN_SIZE OSD_VIDWIN0XP_V0X
125#define MAX_LINE_LENGTH (OSD_VIDWIN0OFST_V0LO << 5) 125#define MAX_LINE_LENGTH (OSD_VIDWIN0OFST_V0LO << 5)
@@ -360,8 +360,8 @@ static void _osd_enable_color_key(struct osd_state *sd,
360 osd_write(sd, colorkey & OSD_TRANSPVALL_RGBL, 360 osd_write(sd, colorkey & OSD_TRANSPVALL_RGBL,
361 OSD_TRANSPVALL); 361 OSD_TRANSPVALL);
362 break; 362 break;
363 case PIXFMT_YCbCrI: 363 case PIXFMT_YCBCRI:
364 case PIXFMT_YCrCbI: 364 case PIXFMT_YCRCBI:
365 if (sd->vpbe_type == VPBE_VERSION_3) 365 if (sd->vpbe_type == VPBE_VERSION_3)
366 osd_modify(sd, OSD_TRANSPVALU_Y, colorkey, 366 osd_modify(sd, OSD_TRANSPVALU_Y, colorkey,
367 OSD_TRANSPVALU); 367 OSD_TRANSPVALU);
@@ -813,8 +813,8 @@ static int try_layer_config(struct osd_state *sd, enum osd_layer layer,
813 if (osd->vpbe_type == VPBE_VERSION_1) 813 if (osd->vpbe_type == VPBE_VERSION_1)
814 bad_config = !is_vid_win(layer); 814 bad_config = !is_vid_win(layer);
815 break; 815 break;
816 case PIXFMT_YCbCrI: 816 case PIXFMT_YCBCRI:
817 case PIXFMT_YCrCbI: 817 case PIXFMT_YCRCBI:
818 bad_config = !is_vid_win(layer); 818 bad_config = !is_vid_win(layer);
819 break; 819 break;
820 case PIXFMT_RGB888: 820 case PIXFMT_RGB888:
@@ -950,9 +950,9 @@ static void _osd_set_cbcr_order(struct osd_state *sd,
950 * The caller must ensure that all windows using YC pixfmt use the same 950 * The caller must ensure that all windows using YC pixfmt use the same
951 * Cb/Cr order. 951 * Cb/Cr order.
952 */ 952 */
953 if (pixfmt == PIXFMT_YCbCrI) 953 if (pixfmt == PIXFMT_YCBCRI)
954 osd_clear(sd, OSD_MODE_CS, OSD_MODE); 954 osd_clear(sd, OSD_MODE_CS, OSD_MODE);
955 else if (pixfmt == PIXFMT_YCrCbI) 955 else if (pixfmt == PIXFMT_YCRCBI)
956 osd_set(sd, OSD_MODE_CS, OSD_MODE); 956 osd_set(sd, OSD_MODE_CS, OSD_MODE);
957} 957}
958 958
@@ -981,8 +981,8 @@ static void _osd_set_layer_config(struct osd_state *sd, enum osd_layer layer,
981 winmd |= (2 << OSD_OSDWIN0MD_BMP0MD_SHIFT); 981 winmd |= (2 << OSD_OSDWIN0MD_BMP0MD_SHIFT);
982 _osd_enable_rgb888_pixblend(sd, OSDWIN_OSD0); 982 _osd_enable_rgb888_pixblend(sd, OSDWIN_OSD0);
983 break; 983 break;
984 case PIXFMT_YCbCrI: 984 case PIXFMT_YCBCRI:
985 case PIXFMT_YCrCbI: 985 case PIXFMT_YCRCBI:
986 winmd |= (3 << OSD_OSDWIN0MD_BMP0MD_SHIFT); 986 winmd |= (3 << OSD_OSDWIN0MD_BMP0MD_SHIFT);
987 break; 987 break;
988 default: 988 default:
@@ -1128,8 +1128,8 @@ static void _osd_set_layer_config(struct osd_state *sd, enum osd_layer layer,
1128 _osd_enable_rgb888_pixblend(sd, 1128 _osd_enable_rgb888_pixblend(sd,
1129 OSDWIN_OSD1); 1129 OSDWIN_OSD1);
1130 break; 1130 break;
1131 case PIXFMT_YCbCrI: 1131 case PIXFMT_YCBCRI:
1132 case PIXFMT_YCrCbI: 1132 case PIXFMT_YCRCBI:
1133 winmd |= 1133 winmd |=
1134 (3 << OSD_OSDWIN1MD_BMP1MD_SHIFT); 1134 (3 << OSD_OSDWIN1MD_BMP1MD_SHIFT);
1135 break; 1135 break;
@@ -1508,7 +1508,7 @@ static int osd_initialize(struct osd_state *osd)
1508 _osd_init(osd); 1508 _osd_init(osd);
1509 1509
1510 /* set default Cb/Cr order */ 1510 /* set default Cb/Cr order */
1511 osd->yc_pixfmt = PIXFMT_YCbCrI; 1511 osd->yc_pixfmt = PIXFMT_YCBCRI;
1512 1512
1513 if (osd->vpbe_type == VPBE_VERSION_3) { 1513 if (osd->vpbe_type == VPBE_VERSION_3) {
1514 /* 1514 /*
diff --git a/drivers/media/platform/davinci/vpif.c b/drivers/media/platform/davinci/vpif.c
index ea82a8bd2803..cd08e5248387 100644
--- a/drivers/media/platform/davinci/vpif.c
+++ b/drivers/media/platform/davinci/vpif.c
@@ -17,30 +17,26 @@
17 * GNU General Public License for more details. 17 * GNU General Public License for more details.
18 */ 18 */
19 19
20#include <linux/err.h>
20#include <linux/init.h> 21#include <linux/init.h>
22#include <linux/io.h>
23#include <linux/kernel.h>
21#include <linux/module.h> 24#include <linux/module.h>
22#include <linux/platform_device.h> 25#include <linux/platform_device.h>
23#include <linux/spinlock.h>
24#include <linux/kernel.h>
25#include <linux/io.h>
26#include <linux/err.h>
27#include <linux/pm_runtime.h> 26#include <linux/pm_runtime.h>
27#include <linux/spinlock.h>
28#include <linux/v4l2-dv-timings.h> 28#include <linux/v4l2-dv-timings.h>
29 29
30#include <mach/hardware.h>
31
32#include "vpif.h" 30#include "vpif.h"
33 31
34MODULE_DESCRIPTION("TI DaVinci Video Port Interface driver"); 32MODULE_DESCRIPTION("TI DaVinci Video Port Interface driver");
35MODULE_LICENSE("GPL"); 33MODULE_LICENSE("GPL");
36 34
37#define VPIF_CH0_MAX_MODES (22) 35#define VPIF_CH0_MAX_MODES 22
38#define VPIF_CH1_MAX_MODES (02) 36#define VPIF_CH1_MAX_MODES 2
39#define VPIF_CH2_MAX_MODES (15) 37#define VPIF_CH2_MAX_MODES 15
40#define VPIF_CH3_MAX_MODES (02) 38#define VPIF_CH3_MAX_MODES 2
41 39
42static resource_size_t res_len;
43static struct resource *res;
44spinlock_t vpif_lock; 40spinlock_t vpif_lock;
45 41
46void __iomem *vpif_base; 42void __iomem *vpif_base;
@@ -423,23 +419,12 @@ EXPORT_SYMBOL(vpif_channel_getfid);
423 419
424static int vpif_probe(struct platform_device *pdev) 420static int vpif_probe(struct platform_device *pdev)
425{ 421{
426 int status = 0; 422 static struct resource *res;
427 423
428 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 424 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
429 if (!res) 425 vpif_base = devm_ioremap_resource(&pdev->dev, res);
430 return -ENOENT; 426 if (IS_ERR(vpif_base))
431 427 return PTR_ERR(vpif_base);
432 res_len = resource_size(res);
433
434 res = request_mem_region(res->start, res_len, res->name);
435 if (!res)
436 return -EBUSY;
437
438 vpif_base = ioremap(res->start, res_len);
439 if (!vpif_base) {
440 status = -EBUSY;
441 goto fail;
442 }
443 428
444 pm_runtime_enable(&pdev->dev); 429 pm_runtime_enable(&pdev->dev);
445 pm_runtime_get(&pdev->dev); 430 pm_runtime_get(&pdev->dev);
@@ -447,17 +432,11 @@ static int vpif_probe(struct platform_device *pdev)
447 spin_lock_init(&vpif_lock); 432 spin_lock_init(&vpif_lock);
448 dev_info(&pdev->dev, "vpif probe success\n"); 433 dev_info(&pdev->dev, "vpif probe success\n");
449 return 0; 434 return 0;
450
451fail:
452 release_mem_region(res->start, res_len);
453 return status;
454} 435}
455 436
456static int vpif_remove(struct platform_device *pdev) 437static int vpif_remove(struct platform_device *pdev)
457{ 438{
458 pm_runtime_disable(&pdev->dev); 439 pm_runtime_disable(&pdev->dev);
459 iounmap(vpif_base);
460 release_mem_region(res->start, res_len);
461 return 0; 440 return 0;
462} 441}
463 442
diff --git a/drivers/media/platform/davinci/vpif_capture.c b/drivers/media/platform/davinci/vpif_capture.c
index 5f98df1fc8a0..5514175bbd07 100644
--- a/drivers/media/platform/davinci/vpif_capture.c
+++ b/drivers/media/platform/davinci/vpif_capture.c
@@ -18,28 +18,16 @@
18 * TODO : add support for VBI & HBI data service 18 * TODO : add support for VBI & HBI data service
19 * add static buffer allocation 19 * add static buffer allocation
20 */ 20 */
21#include <linux/kernel.h> 21
22#include <linux/init.h>
23#include <linux/module.h> 22#include <linux/module.h>
24#include <linux/errno.h>
25#include <linux/fs.h>
26#include <linux/mm.h>
27#include <linux/interrupt.h> 23#include <linux/interrupt.h>
28#include <linux/workqueue.h>
29#include <linux/string.h>
30#include <linux/videodev2.h>
31#include <linux/wait.h>
32#include <linux/time.h>
33#include <linux/i2c.h>
34#include <linux/platform_device.h> 24#include <linux/platform_device.h>
35#include <linux/io.h>
36#include <linux/slab.h> 25#include <linux/slab.h>
37#include <media/v4l2-device.h> 26
38#include <media/v4l2-ioctl.h> 27#include <media/v4l2-ioctl.h>
39#include <media/v4l2-chip-ident.h>
40 28
41#include "vpif_capture.h"
42#include "vpif.h" 29#include "vpif.h"
30#include "vpif_capture.h"
43 31
44MODULE_DESCRIPTION("TI DaVinci VPIF Capture driver"); 32MODULE_DESCRIPTION("TI DaVinci VPIF Capture driver");
45MODULE_LICENSE("GPL"); 33MODULE_LICENSE("GPL");
@@ -1874,66 +1862,6 @@ static int vpif_g_dv_timings(struct file *file, void *priv,
1874} 1862}
1875 1863
1876/* 1864/*
1877 * vpif_g_chip_ident() - Identify the chip
1878 * @file: file ptr
1879 * @priv: file handle
1880 * @chip: chip identity
1881 *
1882 * Returns zero or -EINVAL if read operations fails.
1883 */
1884static int vpif_g_chip_ident(struct file *file, void *priv,
1885 struct v4l2_dbg_chip_ident *chip)
1886{
1887 chip->ident = V4L2_IDENT_NONE;
1888 chip->revision = 0;
1889 if (chip->match.type != V4L2_CHIP_MATCH_I2C_DRIVER &&
1890 chip->match.type != V4L2_CHIP_MATCH_I2C_ADDR) {
1891 vpif_dbg(2, debug, "match_type is invalid.\n");
1892 return -EINVAL;
1893 }
1894
1895 return v4l2_device_call_until_err(&vpif_obj.v4l2_dev, 0, core,
1896 g_chip_ident, chip);
1897}
1898
1899#ifdef CONFIG_VIDEO_ADV_DEBUG
1900/*
1901 * vpif_dbg_g_register() - Read register
1902 * @file: file ptr
1903 * @priv: file handle
1904 * @reg: register to be read
1905 *
1906 * Debugging only
1907 * Returns zero or -EINVAL if read operations fails.
1908 */
1909static int vpif_dbg_g_register(struct file *file, void *priv,
1910 struct v4l2_dbg_register *reg){
1911 struct vpif_fh *fh = priv;
1912 struct channel_obj *ch = fh->channel;
1913
1914 return v4l2_subdev_call(ch->sd, core, g_register, reg);
1915}
1916
1917/*
1918 * vpif_dbg_s_register() - Write to register
1919 * @file: file ptr
1920 * @priv: file handle
1921 * @reg: register to be modified
1922 *
1923 * Debugging only
1924 * Returns zero or -EINVAL if write operations fails.
1925 */
1926static int vpif_dbg_s_register(struct file *file, void *priv,
1927 const struct v4l2_dbg_register *reg)
1928{
1929 struct vpif_fh *fh = priv;
1930 struct channel_obj *ch = fh->channel;
1931
1932 return v4l2_subdev_call(ch->sd, core, s_register, reg);
1933}
1934#endif
1935
1936/*
1937 * vpif_log_status() - Status information 1865 * vpif_log_status() - Status information
1938 * @file: file ptr 1866 * @file: file ptr
1939 * @priv: file handle 1867 * @priv: file handle
@@ -1974,11 +1902,6 @@ static const struct v4l2_ioctl_ops vpif_ioctl_ops = {
1974 .vidioc_query_dv_timings = vpif_query_dv_timings, 1902 .vidioc_query_dv_timings = vpif_query_dv_timings,
1975 .vidioc_s_dv_timings = vpif_s_dv_timings, 1903 .vidioc_s_dv_timings = vpif_s_dv_timings,
1976 .vidioc_g_dv_timings = vpif_g_dv_timings, 1904 .vidioc_g_dv_timings = vpif_g_dv_timings,
1977 .vidioc_g_chip_ident = vpif_g_chip_ident,
1978#ifdef CONFIG_VIDEO_ADV_DEBUG
1979 .vidioc_g_register = vpif_dbg_g_register,
1980 .vidioc_s_register = vpif_dbg_s_register,
1981#endif
1982 .vidioc_log_status = vpif_log_status, 1905 .vidioc_log_status = vpif_log_status,
1983}; 1906};
1984 1907
@@ -2092,16 +2015,13 @@ static __init int vpif_probe(struct platform_device *pdev)
2092 } 2015 }
2093 2016
2094 while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, res_idx))) { 2017 while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, res_idx))) {
2095 for (i = res->start; i <= res->end; i++) { 2018 err = devm_request_irq(&pdev->dev, res->start, vpif_channel_isr,
2096 if (request_irq(i, vpif_channel_isr, IRQF_SHARED, 2019 IRQF_SHARED, "VPIF_Capture",
2097 "VPIF_Capture", (void *) 2020 (void *)(&vpif_obj.dev[res_idx]->
2098 (&vpif_obj.dev[res_idx]->channel_id))) { 2021 channel_id));
2099 err = -EBUSY; 2022 if (err) {
2100 for (j = 0; j < i; j++) 2023 err = -EINVAL;
2101 free_irq(j, (void *) 2024 goto vpif_unregister;
2102 (&vpif_obj.dev[res_idx]->channel_id));
2103 goto vpif_int_err;
2104 }
2105 } 2025 }
2106 res_idx++; 2026 res_idx++;
2107 } 2027 }
@@ -2117,7 +2037,7 @@ static __init int vpif_probe(struct platform_device *pdev)
2117 video_device_release(ch->video_dev); 2037 video_device_release(ch->video_dev);
2118 } 2038 }
2119 err = -ENOMEM; 2039 err = -ENOMEM;
2120 goto vpif_int_err; 2040 goto vpif_unregister;
2121 } 2041 }
2122 2042
2123 /* Initialize field of video device */ 2043 /* Initialize field of video device */
@@ -2170,6 +2090,7 @@ static __init int vpif_probe(struct platform_device *pdev)
2170 2090
2171 if (!vpif_obj.sd[i]) { 2091 if (!vpif_obj.sd[i]) {
2172 vpif_err("Error registering v4l2 subdevice\n"); 2092 vpif_err("Error registering v4l2 subdevice\n");
2093 err = -ENODEV;
2173 goto probe_subdev_out; 2094 goto probe_subdev_out;
2174 } 2095 }
2175 v4l2_info(&vpif_obj.v4l2_dev, "registered sub device %s\n", 2096 v4l2_info(&vpif_obj.v4l2_dev, "registered sub device %s\n",
@@ -2217,13 +2138,9 @@ vpif_sd_error:
2217 /* Note: does nothing if ch->video_dev == NULL */ 2138 /* Note: does nothing if ch->video_dev == NULL */
2218 video_device_release(ch->video_dev); 2139 video_device_release(ch->video_dev);
2219 } 2140 }
2220vpif_int_err: 2141vpif_unregister:
2221 v4l2_device_unregister(&vpif_obj.v4l2_dev); 2142 v4l2_device_unregister(&vpif_obj.v4l2_dev);
2222 for (i = 0; i < res_idx; i++) { 2143
2223 res = platform_get_resource(pdev, IORESOURCE_IRQ, i);
2224 for (j = res->start; j <= res->end; j++)
2225 free_irq(j, (void *)(&vpif_obj.dev[i]->channel_id));
2226 }
2227 return err; 2144 return err;
2228} 2145}
2229 2146
@@ -2235,17 +2152,19 @@ vpif_int_err:
2235 */ 2152 */
2236static int vpif_remove(struct platform_device *device) 2153static int vpif_remove(struct platform_device *device)
2237{ 2154{
2238 int i;
2239 struct channel_obj *ch; 2155 struct channel_obj *ch;
2156 int i;
2240 2157
2241 v4l2_device_unregister(&vpif_obj.v4l2_dev); 2158 v4l2_device_unregister(&vpif_obj.v4l2_dev);
2242 2159
2160 kfree(vpif_obj.sd);
2243 /* un-register device */ 2161 /* un-register device */
2244 for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) { 2162 for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
2245 /* Get the pointer to the channel object */ 2163 /* Get the pointer to the channel object */
2246 ch = vpif_obj.dev[i]; 2164 ch = vpif_obj.dev[i];
2247 /* Unregister video device */ 2165 /* Unregister video device */
2248 video_unregister_device(ch->video_dev); 2166 video_unregister_device(ch->video_dev);
2167 kfree(vpif_obj.dev[i]);
2249 } 2168 }
2250 return 0; 2169 return 0;
2251} 2170}
@@ -2336,47 +2255,4 @@ static __refdata struct platform_driver vpif_driver = {
2336 .remove = vpif_remove, 2255 .remove = vpif_remove,
2337}; 2256};
2338 2257
2339/** 2258module_platform_driver(vpif_driver);
2340 * vpif_init: initialize the vpif driver
2341 *
2342 * This function registers device and driver to the kernel, requests irq
2343 * handler and allocates memory
2344 * for channel objects
2345 */
2346static __init int vpif_init(void)
2347{
2348 return platform_driver_register(&vpif_driver);
2349}
2350
2351/**
2352 * vpif_cleanup : This function clean up the vpif capture resources
2353 *
2354 * This will un-registers device and driver to the kernel, frees
2355 * requested irq handler and de-allocates memory allocated for channel
2356 * objects.
2357 */
2358static void vpif_cleanup(void)
2359{
2360 struct platform_device *pdev;
2361 struct resource *res;
2362 int irq_num;
2363 int i = 0;
2364
2365 pdev = container_of(vpif_dev, struct platform_device, dev);
2366 while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, i))) {
2367 for (irq_num = res->start; irq_num <= res->end; irq_num++)
2368 free_irq(irq_num,
2369 (void *)(&vpif_obj.dev[i]->channel_id));
2370 i++;
2371 }
2372
2373 platform_driver_unregister(&vpif_driver);
2374
2375 kfree(vpif_obj.sd);
2376 for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++)
2377 kfree(vpif_obj.dev[i]);
2378}
2379
2380/* Function for module initialization and cleanup */
2381module_init(vpif_init);
2382module_exit(vpif_cleanup);
diff --git a/drivers/media/platform/davinci/vpif_capture.h b/drivers/media/platform/davinci/vpif_capture.h
index 3d3c1e5cd5d4..0ebb31260369 100644
--- a/drivers/media/platform/davinci/vpif_capture.h
+++ b/drivers/media/platform/davinci/vpif_capture.h
@@ -22,11 +22,8 @@
22#ifdef __KERNEL__ 22#ifdef __KERNEL__
23 23
24/* Header files */ 24/* Header files */
25#include <linux/videodev2.h>
26#include <media/v4l2-common.h>
27#include <media/v4l2-device.h>
28#include <media/videobuf2-dma-contig.h> 25#include <media/videobuf2-dma-contig.h>
29#include <media/davinci/vpif_types.h> 26#include <media/v4l2-device.h>
30 27
31#include "vpif.h" 28#include "vpif.h"
32 29
diff --git a/drivers/media/platform/davinci/vpif_display.c b/drivers/media/platform/davinci/vpif_display.c
index 1b3fb5ca2ad4..e6e573650250 100644
--- a/drivers/media/platform/davinci/vpif_display.c
+++ b/drivers/media/platform/davinci/vpif_display.c
@@ -14,33 +14,15 @@
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 */ 15 */
16 16
17#include <linux/kernel.h>
18#include <linux/init.h>
19#include <linux/module.h>
20#include <linux/errno.h>
21#include <linux/fs.h>
22#include <linux/mm.h>
23#include <linux/interrupt.h> 17#include <linux/interrupt.h>
24#include <linux/workqueue.h> 18#include <linux/module.h>
25#include <linux/string.h>
26#include <linux/videodev2.h>
27#include <linux/wait.h>
28#include <linux/time.h>
29#include <linux/i2c.h>
30#include <linux/platform_device.h> 19#include <linux/platform_device.h>
31#include <linux/io.h>
32#include <linux/slab.h> 20#include <linux/slab.h>
33 21
34#include <asm/irq.h>
35#include <asm/page.h>
36
37#include <media/adv7343.h>
38#include <media/v4l2-device.h>
39#include <media/v4l2-ioctl.h> 22#include <media/v4l2-ioctl.h>
40#include <media/v4l2-chip-ident.h>
41 23
42#include "vpif_display.h"
43#include "vpif.h" 24#include "vpif.h"
25#include "vpif_display.h"
44 26
45MODULE_DESCRIPTION("TI DaVinci VPIF Display driver"); 27MODULE_DESCRIPTION("TI DaVinci VPIF Display driver");
46MODULE_LICENSE("GPL"); 28MODULE_LICENSE("GPL");
@@ -1518,66 +1500,6 @@ static int vpif_g_dv_timings(struct file *file, void *priv,
1518} 1500}
1519 1501
1520/* 1502/*
1521 * vpif_g_chip_ident() - Identify the chip
1522 * @file: file ptr
1523 * @priv: file handle
1524 * @chip: chip identity
1525 *
1526 * Returns zero or -EINVAL if read operations fails.
1527 */
1528static int vpif_g_chip_ident(struct file *file, void *priv,
1529 struct v4l2_dbg_chip_ident *chip)
1530{
1531 chip->ident = V4L2_IDENT_NONE;
1532 chip->revision = 0;
1533 if (chip->match.type != V4L2_CHIP_MATCH_I2C_DRIVER &&
1534 chip->match.type != V4L2_CHIP_MATCH_I2C_ADDR) {
1535 vpif_dbg(2, debug, "match_type is invalid.\n");
1536 return -EINVAL;
1537 }
1538
1539 return v4l2_device_call_until_err(&vpif_obj.v4l2_dev, 0, core,
1540 g_chip_ident, chip);
1541}
1542
1543#ifdef CONFIG_VIDEO_ADV_DEBUG
1544/*
1545 * vpif_dbg_g_register() - Read register
1546 * @file: file ptr
1547 * @priv: file handle
1548 * @reg: register to be read
1549 *
1550 * Debugging only
1551 * Returns zero or -EINVAL if read operations fails.
1552 */
1553static int vpif_dbg_g_register(struct file *file, void *priv,
1554 struct v4l2_dbg_register *reg){
1555 struct vpif_fh *fh = priv;
1556 struct channel_obj *ch = fh->channel;
1557
1558 return v4l2_subdev_call(ch->sd, core, g_register, reg);
1559}
1560
1561/*
1562 * vpif_dbg_s_register() - Write to register
1563 * @file: file ptr
1564 * @priv: file handle
1565 * @reg: register to be modified
1566 *
1567 * Debugging only
1568 * Returns zero or -EINVAL if write operations fails.
1569 */
1570static int vpif_dbg_s_register(struct file *file, void *priv,
1571 const struct v4l2_dbg_register *reg)
1572{
1573 struct vpif_fh *fh = priv;
1574 struct channel_obj *ch = fh->channel;
1575
1576 return v4l2_subdev_call(ch->sd, core, s_register, reg);
1577}
1578#endif
1579
1580/*
1581 * vpif_log_status() - Status information 1503 * vpif_log_status() - Status information
1582 * @file: file ptr 1504 * @file: file ptr
1583 * @priv: file handle 1505 * @priv: file handle
@@ -1616,11 +1538,6 @@ static const struct v4l2_ioctl_ops vpif_ioctl_ops = {
1616 .vidioc_enum_dv_timings = vpif_enum_dv_timings, 1538 .vidioc_enum_dv_timings = vpif_enum_dv_timings,
1617 .vidioc_s_dv_timings = vpif_s_dv_timings, 1539 .vidioc_s_dv_timings = vpif_s_dv_timings,
1618 .vidioc_g_dv_timings = vpif_g_dv_timings, 1540 .vidioc_g_dv_timings = vpif_g_dv_timings,
1619 .vidioc_g_chip_ident = vpif_g_chip_ident,
1620#ifdef CONFIG_VIDEO_ADV_DEBUG
1621 .vidioc_g_register = vpif_dbg_g_register,
1622 .vidioc_s_register = vpif_dbg_s_register,
1623#endif
1624 .vidioc_log_status = vpif_log_status, 1541 .vidioc_log_status = vpif_log_status,
1625}; 1542};
1626 1543
@@ -1734,16 +1651,14 @@ static __init int vpif_probe(struct platform_device *pdev)
1734 } 1651 }
1735 1652
1736 while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, res_idx))) { 1653 while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, res_idx))) {
1737 for (i = res->start; i <= res->end; i++) { 1654 err = devm_request_irq(&pdev->dev, res->start, vpif_channel_isr,
1738 if (request_irq(i, vpif_channel_isr, IRQF_SHARED, 1655 IRQF_SHARED, "VPIF_Display",
1739 "VPIF_Display", (void *) 1656 (void *)(&vpif_obj.dev[res_idx]->
1740 (&vpif_obj.dev[res_idx]->channel_id))) { 1657 channel_id));
1741 err = -EBUSY; 1658 if (err) {
1742 for (j = 0; j < i; j++) 1659 err = -EINVAL;
1743 free_irq(j, (void *) 1660 vpif_err("VPIF IRQ request failed\n");
1744 (&vpif_obj.dev[res_idx]->channel_id)); 1661 goto vpif_unregister;
1745 goto vpif_int_err;
1746 }
1747 } 1662 }
1748 res_idx++; 1663 res_idx++;
1749 } 1664 }
@@ -1760,7 +1675,7 @@ static __init int vpif_probe(struct platform_device *pdev)
1760 video_device_release(ch->video_dev); 1675 video_device_release(ch->video_dev);
1761 } 1676 }
1762 err = -ENOMEM; 1677 err = -ENOMEM;
1763 goto vpif_int_err; 1678 goto vpif_unregister;
1764 } 1679 }
1765 1680
1766 /* Initialize field of video device */ 1681 /* Initialize field of video device */
@@ -1813,6 +1728,7 @@ static __init int vpif_probe(struct platform_device *pdev)
1813 NULL); 1728 NULL);
1814 if (!vpif_obj.sd[i]) { 1729 if (!vpif_obj.sd[i]) {
1815 vpif_err("Error registering v4l2 subdevice\n"); 1730 vpif_err("Error registering v4l2 subdevice\n");
1731 err = -ENODEV;
1816 goto probe_subdev_out; 1732 goto probe_subdev_out;
1817 } 1733 }
1818 1734
@@ -1893,14 +1809,8 @@ vpif_sd_error:
1893 /* Note: does nothing if ch->video_dev == NULL */ 1809 /* Note: does nothing if ch->video_dev == NULL */
1894 video_device_release(ch->video_dev); 1810 video_device_release(ch->video_dev);
1895 } 1811 }
1896vpif_int_err: 1812vpif_unregister:
1897 v4l2_device_unregister(&vpif_obj.v4l2_dev); 1813 v4l2_device_unregister(&vpif_obj.v4l2_dev);
1898 vpif_err("VPIF IRQ request failed\n");
1899 for (i = 0; i < res_idx; i++) {
1900 res = platform_get_resource(pdev, IORESOURCE_IRQ, i);
1901 for (j = res->start; j <= res->end; j++)
1902 free_irq(j, (void *)(&vpif_obj.dev[i]->channel_id));
1903 }
1904 1814
1905 return err; 1815 return err;
1906} 1816}
@@ -1915,6 +1825,7 @@ static int vpif_remove(struct platform_device *device)
1915 1825
1916 v4l2_device_unregister(&vpif_obj.v4l2_dev); 1826 v4l2_device_unregister(&vpif_obj.v4l2_dev);
1917 1827
1828 kfree(vpif_obj.sd);
1918 /* un-register device */ 1829 /* un-register device */
1919 for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) { 1830 for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) {
1920 /* Get the pointer to the channel object */ 1831 /* Get the pointer to the channel object */
@@ -1923,6 +1834,7 @@ static int vpif_remove(struct platform_device *device)
1923 video_unregister_device(ch->video_dev); 1834 video_unregister_device(ch->video_dev);
1924 1835
1925 ch->video_dev = NULL; 1836 ch->video_dev = NULL;
1837 kfree(vpif_obj.dev[i]);
1926 } 1838 }
1927 1839
1928 return 0; 1840 return 0;
@@ -2008,37 +1920,4 @@ static __refdata struct platform_driver vpif_driver = {
2008 .remove = vpif_remove, 1920 .remove = vpif_remove,
2009}; 1921};
2010 1922
2011static __init int vpif_init(void) 1923module_platform_driver(vpif_driver);
2012{
2013 return platform_driver_register(&vpif_driver);
2014}
2015
2016/*
2017 * vpif_cleanup: This function un-registers device and driver to the kernel,
2018 * frees requested irq handler and de-allocates memory allocated for channel
2019 * objects.
2020 */
2021static void vpif_cleanup(void)
2022{
2023 struct platform_device *pdev;
2024 struct resource *res;
2025 int irq_num;
2026 int i = 0;
2027
2028 pdev = container_of(vpif_dev, struct platform_device, dev);
2029
2030 while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, i))) {
2031 for (irq_num = res->start; irq_num <= res->end; irq_num++)
2032 free_irq(irq_num,
2033 (void *)(&vpif_obj.dev[i]->channel_id));
2034 i++;
2035 }
2036
2037 platform_driver_unregister(&vpif_driver);
2038 kfree(vpif_obj.sd);
2039 for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++)
2040 kfree(vpif_obj.dev[i]);
2041}
2042
2043module_init(vpif_init);
2044module_exit(vpif_cleanup);
diff --git a/drivers/media/platform/davinci/vpif_display.h b/drivers/media/platform/davinci/vpif_display.h
index a5a18f74395c..5d87fc86e580 100644
--- a/drivers/media/platform/davinci/vpif_display.h
+++ b/drivers/media/platform/davinci/vpif_display.h
@@ -17,11 +17,8 @@
17#define DAVINCIHD_DISPLAY_H 17#define DAVINCIHD_DISPLAY_H
18 18
19/* Header files */ 19/* Header files */
20#include <linux/videodev2.h>
21#include <media/v4l2-common.h>
22#include <media/v4l2-device.h>
23#include <media/videobuf2-dma-contig.h> 20#include <media/videobuf2-dma-contig.h>
24#include <media/davinci/vpif_types.h> 21#include <media/v4l2-device.h>
25 22
26#include "vpif.h" 23#include "vpif.h"
27 24
diff --git a/drivers/media/platform/exynos-gsc/gsc-core.c b/drivers/media/platform/exynos-gsc/gsc-core.c
index 33b5ffc8d66d..559fab2a2d67 100644
--- a/drivers/media/platform/exynos-gsc/gsc-core.c
+++ b/drivers/media/platform/exynos-gsc/gsc-core.c
@@ -988,7 +988,7 @@ static void *gsc_get_drv_data(struct platform_device *pdev)
988 988
989 if (pdev->dev.of_node) { 989 if (pdev->dev.of_node) {
990 const struct of_device_id *match; 990 const struct of_device_id *match;
991 match = of_match_node(of_match_ptr(exynos_gsc_match), 991 match = of_match_node(exynos_gsc_match,
992 pdev->dev.of_node); 992 pdev->dev.of_node);
993 if (match) 993 if (match)
994 driver_data = (struct gsc_driverdata *)match->data; 994 driver_data = (struct gsc_driverdata *)match->data;
diff --git a/drivers/media/platform/exynos4-is/Kconfig b/drivers/media/platform/exynos4-is/Kconfig
index 436a62a995ee..53ad0f080179 100644
--- a/drivers/media/platform/exynos4-is/Kconfig
+++ b/drivers/media/platform/exynos4-is/Kconfig
@@ -9,12 +9,16 @@ config VIDEO_SAMSUNG_EXYNOS4_IS
9 9
10if VIDEO_SAMSUNG_EXYNOS4_IS 10if VIDEO_SAMSUNG_EXYNOS4_IS
11 11
12config VIDEO_EXYNOS4_IS_COMMON
13 tristate
14
12config VIDEO_S5P_FIMC 15config VIDEO_S5P_FIMC
13 tristate "S5P/EXYNOS4 FIMC/CAMIF camera interface driver" 16 tristate "S5P/EXYNOS4 FIMC/CAMIF camera interface driver"
14 depends on I2C 17 depends on I2C
15 select VIDEOBUF2_DMA_CONTIG 18 select VIDEOBUF2_DMA_CONTIG
16 select V4L2_MEM2MEM_DEV 19 select V4L2_MEM2MEM_DEV
17 select MFD_SYSCON if OF 20 select MFD_SYSCON if OF
21 select VIDEO_EXYNOS4_IS_COMMON
18 help 22 help
19 This is a V4L2 driver for Samsung S5P and EXYNOS4 SoC camera host 23 This is a V4L2 driver for Samsung S5P and EXYNOS4 SoC camera host
20 interface and video postprocessor (FIMC) devices. 24 interface and video postprocessor (FIMC) devices.
@@ -39,6 +43,7 @@ config VIDEO_EXYNOS_FIMC_LITE
39 tristate "EXYNOS FIMC-LITE camera interface driver" 43 tristate "EXYNOS FIMC-LITE camera interface driver"
40 depends on I2C 44 depends on I2C
41 select VIDEOBUF2_DMA_CONTIG 45 select VIDEOBUF2_DMA_CONTIG
46 select VIDEO_EXYNOS4_IS_COMMON
42 help 47 help
43 This is a V4L2 driver for Samsung EXYNOS4/5 SoC FIMC-LITE camera 48 This is a V4L2 driver for Samsung EXYNOS4/5 SoC FIMC-LITE camera
44 host interface. 49 host interface.
diff --git a/drivers/media/platform/exynos4-is/Makefile b/drivers/media/platform/exynos4-is/Makefile
index f25f46377399..c2ff29ba6856 100644
--- a/drivers/media/platform/exynos4-is/Makefile
+++ b/drivers/media/platform/exynos4-is/Makefile
@@ -1,10 +1,13 @@
1s5p-fimc-objs := fimc-core.o fimc-reg.o fimc-m2m.o fimc-capture.o media-dev.o 1s5p-fimc-objs := fimc-core.o fimc-reg.o fimc-m2m.o fimc-capture.o media-dev.o
2exynos-fimc-lite-objs += fimc-lite-reg.o fimc-lite.o 2exynos-fimc-lite-objs += fimc-lite-reg.o fimc-lite.o
3s5p-csis-objs := mipi-csis.o
4exynos4-is-common-objs := common.o
5
3exynos-fimc-is-objs := fimc-is.o fimc-isp.o fimc-is-sensor.o fimc-is-regs.o 6exynos-fimc-is-objs := fimc-is.o fimc-isp.o fimc-is-sensor.o fimc-is-regs.o
4exynos-fimc-is-objs += fimc-is-param.o fimc-is-errno.o fimc-is-i2c.o 7exynos-fimc-is-objs += fimc-is-param.o fimc-is-errno.o fimc-is-i2c.o
5s5p-csis-objs := mipi-csis.o
6 8
7obj-$(CONFIG_VIDEO_S5P_MIPI_CSIS) += s5p-csis.o 9obj-$(CONFIG_VIDEO_S5P_MIPI_CSIS) += s5p-csis.o
8obj-$(CONFIG_VIDEO_EXYNOS_FIMC_LITE) += exynos-fimc-lite.o 10obj-$(CONFIG_VIDEO_EXYNOS_FIMC_LITE) += exynos-fimc-lite.o
9obj-$(CONFIG_VIDEO_EXYNOS4_FIMC_IS) += exynos-fimc-is.o 11obj-$(CONFIG_VIDEO_EXYNOS4_FIMC_IS) += exynos-fimc-is.o
10obj-$(CONFIG_VIDEO_S5P_FIMC) += s5p-fimc.o 12obj-$(CONFIG_VIDEO_S5P_FIMC) += s5p-fimc.o
13obj-$(CONFIG_VIDEO_EXYNOS4_IS_COMMON) += exynos4-is-common.o
diff --git a/drivers/media/platform/exynos4-is/common.c b/drivers/media/platform/exynos4-is/common.c
new file mode 100644
index 000000000000..0ec210b4da1d
--- /dev/null
+++ b/drivers/media/platform/exynos4-is/common.c
@@ -0,0 +1,53 @@
1/*
2 * Samsung S5P/EXYNOS4 SoC Camera Subsystem driver
3 *
4 * Copyright (C) 2013 Samsung Electronics Co., Ltd.
5 * Author: Sylwester Nawrocki <s.nawrocki@samsung.com>
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/module.h>
13#include <media/s5p_fimc.h>
14#include "common.h"
15
16/* Called with the media graph mutex held or entity->stream_count > 0. */
17struct v4l2_subdev *fimc_find_remote_sensor(struct media_entity *entity)
18{
19 struct media_pad *pad = &entity->pads[0];
20 struct v4l2_subdev *sd;
21
22 while (pad->flags & MEDIA_PAD_FL_SINK) {
23 /* source pad */
24 pad = media_entity_remote_pad(pad);
25 if (pad == NULL ||
26 media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
27 break;
28
29 sd = media_entity_to_v4l2_subdev(pad->entity);
30
31 if (sd->grp_id == GRP_ID_FIMC_IS_SENSOR ||
32 sd->grp_id == GRP_ID_SENSOR)
33 return sd;
34 /* sink pad */
35 pad = &sd->entity.pads[0];
36 }
37 return NULL;
38}
39EXPORT_SYMBOL(fimc_find_remote_sensor);
40
41void __fimc_vidioc_querycap(struct device *dev, struct v4l2_capability *cap,
42 unsigned int caps)
43{
44 strlcpy(cap->driver, dev->driver->name, sizeof(cap->driver));
45 strlcpy(cap->card, dev->driver->name, sizeof(cap->card));
46 snprintf(cap->bus_info, sizeof(cap->bus_info),
47 "platform:%s", dev_name(dev));
48 cap->device_caps = caps;
49 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
50}
51EXPORT_SYMBOL(__fimc_vidioc_querycap);
52
53MODULE_LICENSE("GPL");
diff --git a/drivers/media/platform/exynos4-is/common.h b/drivers/media/platform/exynos4-is/common.h
new file mode 100644
index 000000000000..75b9c71d9419
--- /dev/null
+++ b/drivers/media/platform/exynos4-is/common.h
@@ -0,0 +1,16 @@
1/*
2 * Copyright (C) 2013 Samsung Electronics Co., Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8
9#include <linux/device.h>
10#include <linux/videodev2.h>
11#include <media/media-entity.h>
12#include <media/v4l2-subdev.h>
13
14struct v4l2_subdev *fimc_find_remote_sensor(struct media_entity *entity);
15void __fimc_vidioc_querycap(struct device *dev, struct v4l2_capability *cap,
16 unsigned int caps);
diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c b/drivers/media/platform/exynos4-is/fimc-capture.c
index 528f41369364..fb27ff7e1e07 100644
--- a/drivers/media/platform/exynos4-is/fimc-capture.c
+++ b/drivers/media/platform/exynos4-is/fimc-capture.c
@@ -27,9 +27,10 @@
27#include <media/videobuf2-core.h> 27#include <media/videobuf2-core.h>
28#include <media/videobuf2-dma-contig.h> 28#include <media/videobuf2-dma-contig.h>
29 29
30#include "media-dev.h" 30#include "common.h"
31#include "fimc-core.h" 31#include "fimc-core.h"
32#include "fimc-reg.h" 32#include "fimc-reg.h"
33#include "media-dev.h"
33 34
34static int fimc_capture_hw_init(struct fimc_dev *fimc) 35static int fimc_capture_hw_init(struct fimc_dev *fimc)
35{ 36{
@@ -119,8 +120,7 @@ static int fimc_capture_state_cleanup(struct fimc_dev *fimc, bool suspend)
119 spin_unlock_irqrestore(&fimc->slock, flags); 120 spin_unlock_irqrestore(&fimc->slock, flags);
120 121
121 if (streaming) 122 if (streaming)
122 return fimc_pipeline_call(fimc, set_stream, 123 return fimc_pipeline_call(&cap->ve, set_stream, 0);
123 &fimc->pipeline, 0);
124 else 124 else
125 return 0; 125 return 0;
126} 126}
@@ -178,8 +178,9 @@ static int fimc_capture_config_update(struct fimc_ctx *ctx)
178 178
179void fimc_capture_irq_handler(struct fimc_dev *fimc, int deq_buf) 179void fimc_capture_irq_handler(struct fimc_dev *fimc, int deq_buf)
180{ 180{
181 struct v4l2_subdev *csis = fimc->pipeline.subdevs[IDX_CSIS];
182 struct fimc_vid_cap *cap = &fimc->vid_cap; 181 struct fimc_vid_cap *cap = &fimc->vid_cap;
182 struct fimc_pipeline *p = to_fimc_pipeline(cap->ve.pipe);
183 struct v4l2_subdev *csis = p->subdevs[IDX_CSIS];
183 struct fimc_frame *f = &cap->ctx->d_frame; 184 struct fimc_frame *f = &cap->ctx->d_frame;
184 struct fimc_vid_buffer *v_buf; 185 struct fimc_vid_buffer *v_buf;
185 struct timeval *tv; 186 struct timeval *tv;
@@ -287,8 +288,7 @@ static int start_streaming(struct vb2_queue *q, unsigned int count)
287 fimc_activate_capture(ctx); 288 fimc_activate_capture(ctx);
288 289
289 if (!test_and_set_bit(ST_CAPT_ISP_STREAM, &fimc->state)) 290 if (!test_and_set_bit(ST_CAPT_ISP_STREAM, &fimc->state))
290 return fimc_pipeline_call(fimc, set_stream, 291 return fimc_pipeline_call(&vid_cap->ve, set_stream, 1);
291 &fimc->pipeline, 1);
292 } 292 }
293 293
294 return 0; 294 return 0;
@@ -312,7 +312,7 @@ int fimc_capture_suspend(struct fimc_dev *fimc)
312 int ret = fimc_stop_capture(fimc, suspend); 312 int ret = fimc_stop_capture(fimc, suspend);
313 if (ret) 313 if (ret)
314 return ret; 314 return ret;
315 return fimc_pipeline_call(fimc, close, &fimc->pipeline); 315 return fimc_pipeline_call(&fimc->vid_cap.ve, close);
316} 316}
317 317
318static void buffer_queue(struct vb2_buffer *vb); 318static void buffer_queue(struct vb2_buffer *vb);
@@ -320,6 +320,7 @@ static void buffer_queue(struct vb2_buffer *vb);
320int fimc_capture_resume(struct fimc_dev *fimc) 320int fimc_capture_resume(struct fimc_dev *fimc)
321{ 321{
322 struct fimc_vid_cap *vid_cap = &fimc->vid_cap; 322 struct fimc_vid_cap *vid_cap = &fimc->vid_cap;
323 struct exynos_video_entity *ve = &vid_cap->ve;
323 struct fimc_vid_buffer *buf; 324 struct fimc_vid_buffer *buf;
324 int i; 325 int i;
325 326
@@ -328,8 +329,7 @@ int fimc_capture_resume(struct fimc_dev *fimc)
328 329
329 INIT_LIST_HEAD(&fimc->vid_cap.active_buf_q); 330 INIT_LIST_HEAD(&fimc->vid_cap.active_buf_q);
330 vid_cap->buf_index = 0; 331 vid_cap->buf_index = 0;
331 fimc_pipeline_call(fimc, open, &fimc->pipeline, 332 fimc_pipeline_call(ve, open, &ve->vdev.entity, false);
332 &vid_cap->vfd.entity, false);
333 fimc_capture_hw_init(fimc); 333 fimc_capture_hw_init(fimc);
334 334
335 clear_bit(ST_CAPT_SUSPENDED, &fimc->state); 335 clear_bit(ST_CAPT_SUSPENDED, &fimc->state);
@@ -397,7 +397,7 @@ static int buffer_prepare(struct vb2_buffer *vb)
397 unsigned long size = ctx->d_frame.payload[i]; 397 unsigned long size = ctx->d_frame.payload[i];
398 398
399 if (vb2_plane_size(vb, i) < size) { 399 if (vb2_plane_size(vb, i) < size) {
400 v4l2_err(&ctx->fimc_dev->vid_cap.vfd, 400 v4l2_err(&ctx->fimc_dev->vid_cap.ve.vdev,
401 "User buffer too small (%ld < %ld)\n", 401 "User buffer too small (%ld < %ld)\n",
402 vb2_plane_size(vb, i), size); 402 vb2_plane_size(vb, i), size);
403 return -EINVAL; 403 return -EINVAL;
@@ -415,6 +415,7 @@ static void buffer_queue(struct vb2_buffer *vb)
415 struct fimc_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue); 415 struct fimc_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
416 struct fimc_dev *fimc = ctx->fimc_dev; 416 struct fimc_dev *fimc = ctx->fimc_dev;
417 struct fimc_vid_cap *vid_cap = &fimc->vid_cap; 417 struct fimc_vid_cap *vid_cap = &fimc->vid_cap;
418 struct exynos_video_entity *ve = &vid_cap->ve;
418 unsigned long flags; 419 unsigned long flags;
419 int min_bufs; 420 int min_bufs;
420 421
@@ -452,9 +453,9 @@ static void buffer_queue(struct vb2_buffer *vb)
452 if (test_and_set_bit(ST_CAPT_ISP_STREAM, &fimc->state)) 453 if (test_and_set_bit(ST_CAPT_ISP_STREAM, &fimc->state))
453 return; 454 return;
454 455
455 ret = fimc_pipeline_call(fimc, set_stream, &fimc->pipeline, 1); 456 ret = fimc_pipeline_call(ve, set_stream, 1);
456 if (ret < 0) 457 if (ret < 0)
457 v4l2_err(&vid_cap->vfd, "stream on failed: %d\n", ret); 458 v4l2_err(&ve->vdev, "stream on failed: %d\n", ret);
458 return; 459 return;
459 } 460 }
460 spin_unlock_irqrestore(&fimc->slock, flags); 461 spin_unlock_irqrestore(&fimc->slock, flags);
@@ -470,44 +471,17 @@ static struct vb2_ops fimc_capture_qops = {
470 .stop_streaming = stop_streaming, 471 .stop_streaming = stop_streaming,
471}; 472};
472 473
473/**
474 * fimc_capture_ctrls_create - initialize the control handler
475 * Initialize the capture video node control handler and fill it
476 * with the FIMC controls. Inherit any sensor's controls if the
477 * 'user_subdev_api' flag is false (default behaviour).
478 * This function need to be called with the graph mutex held.
479 */
480int fimc_capture_ctrls_create(struct fimc_dev *fimc)
481{
482 struct fimc_vid_cap *vid_cap = &fimc->vid_cap;
483 struct v4l2_subdev *sensor = fimc->pipeline.subdevs[IDX_SENSOR];
484 int ret;
485
486 if (WARN_ON(vid_cap->ctx == NULL))
487 return -ENXIO;
488 if (vid_cap->ctx->ctrls.ready)
489 return 0;
490
491 ret = fimc_ctrls_create(vid_cap->ctx);
492
493 if (ret || vid_cap->user_subdev_api || !sensor ||
494 !vid_cap->ctx->ctrls.ready)
495 return ret;
496
497 return v4l2_ctrl_add_handler(&vid_cap->ctx->ctrls.handler,
498 sensor->ctrl_handler, NULL);
499}
500
501static int fimc_capture_set_default_format(struct fimc_dev *fimc); 474static int fimc_capture_set_default_format(struct fimc_dev *fimc);
502 475
503static int fimc_capture_open(struct file *file) 476static int fimc_capture_open(struct file *file)
504{ 477{
505 struct fimc_dev *fimc = video_drvdata(file); 478 struct fimc_dev *fimc = video_drvdata(file);
479 struct fimc_vid_cap *vc = &fimc->vid_cap;
480 struct exynos_video_entity *ve = &vc->ve;
506 int ret = -EBUSY; 481 int ret = -EBUSY;
507 482
508 dbg("pid: %d, state: 0x%lx", task_pid_nr(current), fimc->state); 483 dbg("pid: %d, state: 0x%lx", task_pid_nr(current), fimc->state);
509 484
510 fimc_md_graph_lock(fimc);
511 mutex_lock(&fimc->lock); 485 mutex_lock(&fimc->lock);
512 486
513 if (fimc_m2m_active(fimc)) 487 if (fimc_m2m_active(fimc))
@@ -520,31 +494,42 @@ static int fimc_capture_open(struct file *file)
520 494
521 ret = v4l2_fh_open(file); 495 ret = v4l2_fh_open(file);
522 if (ret) { 496 if (ret) {
523 pm_runtime_put(&fimc->pdev->dev); 497 pm_runtime_put_sync(&fimc->pdev->dev);
524 goto unlock; 498 goto unlock;
525 } 499 }
526 500
527 if (v4l2_fh_is_singular_file(file)) { 501 if (v4l2_fh_is_singular_file(file)) {
528 ret = fimc_pipeline_call(fimc, open, &fimc->pipeline, 502 fimc_md_graph_lock(ve);
529 &fimc->vid_cap.vfd.entity, true);
530 503
531 if (!ret && !fimc->vid_cap.user_subdev_api) 504 ret = fimc_pipeline_call(ve, open, &ve->vdev.entity, true);
532 ret = fimc_capture_set_default_format(fimc);
533 505
534 if (!ret) 506 if (ret == 0 && vc->user_subdev_api && vc->inh_sensor_ctrls) {
535 ret = fimc_capture_ctrls_create(fimc); 507 /*
508 * Recreate controls of the the video node to drop
509 * any controls inherited from the sensor subdev.
510 */
511 fimc_ctrls_delete(vc->ctx);
512
513 ret = fimc_ctrls_create(vc->ctx);
514 if (ret == 0)
515 vc->inh_sensor_ctrls = false;
516 }
517 if (ret == 0)
518 ve->vdev.entity.use_count++;
519
520 fimc_md_graph_unlock(ve);
521
522 if (ret == 0)
523 ret = fimc_capture_set_default_format(fimc);
536 524
537 if (ret < 0) { 525 if (ret < 0) {
538 clear_bit(ST_CAPT_BUSY, &fimc->state); 526 clear_bit(ST_CAPT_BUSY, &fimc->state);
539 pm_runtime_put_sync(&fimc->pdev->dev); 527 pm_runtime_put_sync(&fimc->pdev->dev);
540 v4l2_fh_release(file); 528 v4l2_fh_release(file);
541 } else {
542 fimc->vid_cap.refcnt++;
543 } 529 }
544 } 530 }
545unlock: 531unlock:
546 mutex_unlock(&fimc->lock); 532 mutex_unlock(&fimc->lock);
547 fimc_md_graph_unlock(fimc);
548 return ret; 533 return ret;
549} 534}
550 535
@@ -552,30 +537,31 @@ static int fimc_capture_release(struct file *file)
552{ 537{
553 struct fimc_dev *fimc = video_drvdata(file); 538 struct fimc_dev *fimc = video_drvdata(file);
554 struct fimc_vid_cap *vc = &fimc->vid_cap; 539 struct fimc_vid_cap *vc = &fimc->vid_cap;
540 bool close = v4l2_fh_is_singular_file(file);
555 int ret; 541 int ret;
556 542
557 dbg("pid: %d, state: 0x%lx", task_pid_nr(current), fimc->state); 543 dbg("pid: %d, state: 0x%lx", task_pid_nr(current), fimc->state);
558 544
559 mutex_lock(&fimc->lock); 545 mutex_lock(&fimc->lock);
560 546
561 if (v4l2_fh_is_singular_file(file)) { 547 if (close && vc->streaming) {
562 if (vc->streaming) { 548 media_entity_pipeline_stop(&vc->ve.vdev.entity);
563 media_entity_pipeline_stop(&vc->vfd.entity); 549 vc->streaming = false;
564 vc->streaming = false;
565 }
566 clear_bit(ST_CAPT_BUSY, &fimc->state);
567 fimc_stop_capture(fimc, false);
568 fimc_pipeline_call(fimc, close, &fimc->pipeline);
569 clear_bit(ST_CAPT_SUSPENDED, &fimc->state);
570 fimc->vid_cap.refcnt--;
571 } 550 }
572 551
573 pm_runtime_put(&fimc->pdev->dev); 552 ret = vb2_fop_release(file);
574 553
575 if (v4l2_fh_is_singular_file(file)) 554 if (close) {
576 fimc_ctrls_delete(fimc->vid_cap.ctx); 555 clear_bit(ST_CAPT_BUSY, &fimc->state);
556 fimc_pipeline_call(&vc->ve, close);
557 clear_bit(ST_CAPT_SUSPENDED, &fimc->state);
577 558
578 ret = vb2_fop_release(file); 559 fimc_md_graph_lock(&vc->ve);
560 vc->ve.vdev.entity.use_count--;
561 fimc_md_graph_unlock(&vc->ve);
562 }
563
564 pm_runtime_put_sync(&fimc->pdev->dev);
579 mutex_unlock(&fimc->lock); 565 mutex_unlock(&fimc->lock);
580 566
581 return ret; 567 return ret;
@@ -773,7 +759,7 @@ static struct media_entity *fimc_pipeline_get_head(struct media_entity *me)
773 struct media_pad *pad = &me->pads[0]; 759 struct media_pad *pad = &me->pads[0];
774 760
775 while (!(pad->flags & MEDIA_PAD_FL_SOURCE)) { 761 while (!(pad->flags & MEDIA_PAD_FL_SOURCE)) {
776 pad = media_entity_remote_source(pad); 762 pad = media_entity_remote_pad(pad);
777 if (!pad) 763 if (!pad)
778 break; 764 break;
779 me = pad->entity; 765 me = pad->entity;
@@ -797,7 +783,8 @@ static int fimc_pipeline_try_format(struct fimc_ctx *ctx,
797 bool set) 783 bool set)
798{ 784{
799 struct fimc_dev *fimc = ctx->fimc_dev; 785 struct fimc_dev *fimc = ctx->fimc_dev;
800 struct v4l2_subdev *sd = fimc->pipeline.subdevs[IDX_SENSOR]; 786 struct fimc_pipeline *p = to_fimc_pipeline(fimc->vid_cap.ve.pipe);
787 struct v4l2_subdev *sd = p->subdevs[IDX_SENSOR];
801 struct v4l2_subdev_format sfmt; 788 struct v4l2_subdev_format sfmt;
802 struct v4l2_mbus_framefmt *mf = &sfmt.format; 789 struct v4l2_mbus_framefmt *mf = &sfmt.format;
803 struct media_entity *me; 790 struct media_entity *me;
@@ -845,7 +832,7 @@ static int fimc_pipeline_try_format(struct fimc_ctx *ctx,
845 return ret; 832 return ret;
846 } 833 }
847 834
848 pad = media_entity_remote_source(&me->pads[sfmt.pad]); 835 pad = media_entity_remote_pad(&me->pads[sfmt.pad]);
849 if (!pad) 836 if (!pad)
850 return -EINVAL; 837 return -EINVAL;
851 me = pad->entity; 838 me = pad->entity;
@@ -929,57 +916,101 @@ static int fimc_cap_g_fmt_mplane(struct file *file, void *fh,
929 return 0; 916 return 0;
930} 917}
931 918
932static int fimc_cap_try_fmt_mplane(struct file *file, void *fh, 919/*
933 struct v4l2_format *f) 920 * Try or set format on the fimc.X.capture video node and additionally
921 * on the whole pipeline if @try is false.
922 * Locking: the caller must _not_ hold the graph mutex.
923 */
924static int __video_try_or_set_format(struct fimc_dev *fimc,
925 struct v4l2_format *f, bool try,
926 struct fimc_fmt **inp_fmt,
927 struct fimc_fmt **out_fmt)
934{ 928{
935 struct v4l2_pix_format_mplane *pix = &f->fmt.pix_mp; 929 struct v4l2_pix_format_mplane *pix = &f->fmt.pix_mp;
936 struct fimc_dev *fimc = video_drvdata(file); 930 struct fimc_vid_cap *vc = &fimc->vid_cap;
937 struct fimc_ctx *ctx = fimc->vid_cap.ctx; 931 struct exynos_video_entity *ve = &vc->ve;
938 struct v4l2_mbus_framefmt mf; 932 struct fimc_ctx *ctx = vc->ctx;
939 struct fimc_fmt *ffmt = NULL; 933 unsigned int width = 0, height = 0;
940 int ret = 0; 934 int ret = 0;
941 935
942 fimc_md_graph_lock(fimc); 936 /* Pre-configure format at the camera input interface, for JPEG only */
943 mutex_lock(&fimc->lock);
944
945 if (fimc_jpeg_fourcc(pix->pixelformat)) { 937 if (fimc_jpeg_fourcc(pix->pixelformat)) {
946 fimc_capture_try_format(ctx, &pix->width, &pix->height, 938 fimc_capture_try_format(ctx, &pix->width, &pix->height,
947 NULL, &pix->pixelformat, 939 NULL, &pix->pixelformat,
948 FIMC_SD_PAD_SINK_CAM); 940 FIMC_SD_PAD_SINK_CAM);
949 ctx->s_frame.f_width = pix->width; 941 if (try) {
950 ctx->s_frame.f_height = pix->height; 942 width = pix->width;
943 height = pix->height;
944 } else {
945 ctx->s_frame.f_width = pix->width;
946 ctx->s_frame.f_height = pix->height;
947 }
951 } 948 }
952 ffmt = fimc_capture_try_format(ctx, &pix->width, &pix->height, 949
953 NULL, &pix->pixelformat, 950 /* Try the format at the scaler and the DMA output */
954 FIMC_SD_PAD_SOURCE); 951 *out_fmt = fimc_capture_try_format(ctx, &pix->width, &pix->height,
955 if (!ffmt) { 952 NULL, &pix->pixelformat,
956 ret = -EINVAL; 953 FIMC_SD_PAD_SOURCE);
957 goto unlock; 954 if (*out_fmt == NULL)
955 return -EINVAL;
956
957 /* Restore image width/height for JPEG (no resizing supported). */
958 if (try && fimc_jpeg_fourcc(pix->pixelformat)) {
959 pix->width = width;
960 pix->height = height;
958 } 961 }
959 962
960 if (!fimc->vid_cap.user_subdev_api) { 963 /* Try to match format at the host and the sensor */
961 mf.width = pix->width; 964 if (!vc->user_subdev_api) {
962 mf.height = pix->height; 965 struct v4l2_mbus_framefmt mbus_fmt;
963 mf.code = ffmt->mbus_code; 966 struct v4l2_mbus_framefmt *mf;
964 fimc_pipeline_try_format(ctx, &mf, &ffmt, false); 967
965 pix->width = mf.width; 968 mf = try ? &mbus_fmt : &fimc->vid_cap.ci_fmt;
966 pix->height = mf.height; 969
967 if (ffmt) 970 mf->code = (*out_fmt)->mbus_code;
968 pix->pixelformat = ffmt->fourcc; 971 mf->width = pix->width;
972 mf->height = pix->height;
973
974 fimc_md_graph_lock(ve);
975 ret = fimc_pipeline_try_format(ctx, mf, inp_fmt, try);
976 fimc_md_graph_unlock(ve);
977
978 if (ret < 0)
979 return ret;
980
981 pix->width = mf->width;
982 pix->height = mf->height;
969 } 983 }
970 984
971 fimc_adjust_mplane_format(ffmt, pix->width, pix->height, pix); 985 fimc_adjust_mplane_format(*out_fmt, pix->width, pix->height, pix);
972 986
973 if (ffmt->flags & FMT_FLAGS_COMPRESSED) 987 if ((*out_fmt)->flags & FMT_FLAGS_COMPRESSED) {
974 fimc_get_sensor_frame_desc(fimc->pipeline.subdevs[IDX_SENSOR], 988 struct v4l2_subdev *sensor;
975 pix->plane_fmt, ffmt->memplanes, true); 989
976unlock: 990 fimc_md_graph_lock(ve);
977 mutex_unlock(&fimc->lock); 991
978 fimc_md_graph_unlock(fimc); 992 sensor = __fimc_md_get_subdev(ve->pipe, IDX_SENSOR);
993 if (sensor)
994 fimc_get_sensor_frame_desc(sensor, pix->plane_fmt,
995 (*out_fmt)->memplanes, try);
996 else
997 ret = -EPIPE;
998
999 fimc_md_graph_unlock(ve);
1000 }
979 1001
980 return ret; 1002 return ret;
981} 1003}
982 1004
1005static int fimc_cap_try_fmt_mplane(struct file *file, void *fh,
1006 struct v4l2_format *f)
1007{
1008 struct fimc_dev *fimc = video_drvdata(file);
1009 struct fimc_fmt *out_fmt = NULL, *inp_fmt = NULL;
1010
1011 return __video_try_or_set_format(fimc, f, true, &inp_fmt, &out_fmt);
1012}
1013
983static void fimc_capture_mark_jpeg_xfer(struct fimc_ctx *ctx, 1014static void fimc_capture_mark_jpeg_xfer(struct fimc_ctx *ctx,
984 enum fimc_color_fmt color) 1015 enum fimc_color_fmt color)
985{ 1016{
@@ -997,57 +1028,23 @@ static void fimc_capture_mark_jpeg_xfer(struct fimc_ctx *ctx,
997static int __fimc_capture_set_format(struct fimc_dev *fimc, 1028static int __fimc_capture_set_format(struct fimc_dev *fimc,
998 struct v4l2_format *f) 1029 struct v4l2_format *f)
999{ 1030{
1000 struct fimc_ctx *ctx = fimc->vid_cap.ctx; 1031 struct fimc_vid_cap *vc = &fimc->vid_cap;
1032 struct fimc_ctx *ctx = vc->ctx;
1001 struct v4l2_pix_format_mplane *pix = &f->fmt.pix_mp; 1033 struct v4l2_pix_format_mplane *pix = &f->fmt.pix_mp;
1002 struct v4l2_mbus_framefmt *mf = &fimc->vid_cap.ci_fmt;
1003 struct fimc_frame *ff = &ctx->d_frame; 1034 struct fimc_frame *ff = &ctx->d_frame;
1004 struct fimc_fmt *s_fmt = NULL; 1035 struct fimc_fmt *inp_fmt = NULL;
1005 int ret, i; 1036 int ret, i;
1006 1037
1007 if (vb2_is_busy(&fimc->vid_cap.vbq)) 1038 if (vb2_is_busy(&fimc->vid_cap.vbq))
1008 return -EBUSY; 1039 return -EBUSY;
1009 1040
1010 /* Pre-configure format at camera interface input, for JPEG only */ 1041 ret = __video_try_or_set_format(fimc, f, false, &inp_fmt, &ff->fmt);
1011 if (fimc_jpeg_fourcc(pix->pixelformat)) { 1042 if (ret < 0)
1012 fimc_capture_try_format(ctx, &pix->width, &pix->height, 1043 return ret;
1013 NULL, &pix->pixelformat,
1014 FIMC_SD_PAD_SINK_CAM);
1015 ctx->s_frame.f_width = pix->width;
1016 ctx->s_frame.f_height = pix->height;
1017 }
1018 /* Try the format at the scaler and the DMA output */
1019 ff->fmt = fimc_capture_try_format(ctx, &pix->width, &pix->height,
1020 NULL, &pix->pixelformat,
1021 FIMC_SD_PAD_SOURCE);
1022 if (!ff->fmt)
1023 return -EINVAL;
1024 1044
1025 /* Update RGB Alpha control state and value range */ 1045 /* Update RGB Alpha control state and value range */
1026 fimc_alpha_ctrl_update(ctx); 1046 fimc_alpha_ctrl_update(ctx);
1027 1047
1028 /* Try to match format at the host and the sensor */
1029 if (!fimc->vid_cap.user_subdev_api) {
1030 mf->code = ff->fmt->mbus_code;
1031 mf->width = pix->width;
1032 mf->height = pix->height;
1033 ret = fimc_pipeline_try_format(ctx, mf, &s_fmt, true);
1034 if (ret)
1035 return ret;
1036
1037 pix->width = mf->width;
1038 pix->height = mf->height;
1039 }
1040
1041 fimc_adjust_mplane_format(ff->fmt, pix->width, pix->height, pix);
1042
1043 if (ff->fmt->flags & FMT_FLAGS_COMPRESSED) {
1044 ret = fimc_get_sensor_frame_desc(fimc->pipeline.subdevs[IDX_SENSOR],
1045 pix->plane_fmt, ff->fmt->memplanes,
1046 true);
1047 if (ret < 0)
1048 return ret;
1049 }
1050
1051 for (i = 0; i < ff->fmt->memplanes; i++) { 1048 for (i = 0; i < ff->fmt->memplanes; i++) {
1052 ff->bytesperline[i] = pix->plane_fmt[i].bytesperline; 1049 ff->bytesperline[i] = pix->plane_fmt[i].bytesperline;
1053 ff->payload[i] = pix->plane_fmt[i].sizeimage; 1050 ff->payload[i] = pix->plane_fmt[i].sizeimage;
@@ -1061,8 +1058,8 @@ static int __fimc_capture_set_format(struct fimc_dev *fimc,
1061 fimc_capture_mark_jpeg_xfer(ctx, ff->fmt->color); 1058 fimc_capture_mark_jpeg_xfer(ctx, ff->fmt->color);
1062 1059
1063 /* Reset cropping and set format at the camera interface input */ 1060 /* Reset cropping and set format at the camera interface input */
1064 if (!fimc->vid_cap.user_subdev_api) { 1061 if (!vc->user_subdev_api) {
1065 ctx->s_frame.fmt = s_fmt; 1062 ctx->s_frame.fmt = inp_fmt;
1066 set_frame_bounds(&ctx->s_frame, pix->width, pix->height); 1063 set_frame_bounds(&ctx->s_frame, pix->width, pix->height);
1067 set_frame_crop(&ctx->s_frame, 0, 0, pix->width, pix->height); 1064 set_frame_crop(&ctx->s_frame, 0, 0, pix->width, pix->height);
1068 } 1065 }
@@ -1074,37 +1071,28 @@ static int fimc_cap_s_fmt_mplane(struct file *file, void *priv,
1074 struct v4l2_format *f) 1071 struct v4l2_format *f)
1075{ 1072{
1076 struct fimc_dev *fimc = video_drvdata(file); 1073 struct fimc_dev *fimc = video_drvdata(file);
1077 int ret;
1078 1074
1079 fimc_md_graph_lock(fimc); 1075 return __fimc_capture_set_format(fimc, f);
1080 mutex_lock(&fimc->lock);
1081 /*
1082 * The graph is walked within __fimc_capture_set_format() to set
1083 * the format at subdevs thus the graph mutex needs to be held at
1084 * this point and acquired before the video mutex, to avoid AB-BA
1085 * deadlock when fimc_md_link_notify() is called by other thread.
1086 * Ideally the graph walking and setting format at the whole pipeline
1087 * should be removed from this driver and handled in userspace only.
1088 */
1089 ret = __fimc_capture_set_format(fimc, f);
1090
1091 mutex_unlock(&fimc->lock);
1092 fimc_md_graph_unlock(fimc);
1093 return ret;
1094} 1076}
1095 1077
1096static int fimc_cap_enum_input(struct file *file, void *priv, 1078static int fimc_cap_enum_input(struct file *file, void *priv,
1097 struct v4l2_input *i) 1079 struct v4l2_input *i)
1098{ 1080{
1099 struct fimc_dev *fimc = video_drvdata(file); 1081 struct fimc_dev *fimc = video_drvdata(file);
1100 struct v4l2_subdev *sd = fimc->pipeline.subdevs[IDX_SENSOR]; 1082 struct exynos_video_entity *ve = &fimc->vid_cap.ve;
1083 struct v4l2_subdev *sd;
1101 1084
1102 if (i->index != 0) 1085 if (i->index != 0)
1103 return -EINVAL; 1086 return -EINVAL;
1104 1087
1105 i->type = V4L2_INPUT_TYPE_CAMERA; 1088 i->type = V4L2_INPUT_TYPE_CAMERA;
1089 fimc_md_graph_lock(ve);
1090 sd = __fimc_md_get_subdev(ve->pipe, IDX_SENSOR);
1091 fimc_md_graph_unlock(ve);
1092
1106 if (sd) 1093 if (sd)
1107 strlcpy(i->name, sd->name, sizeof(i->name)); 1094 strlcpy(i->name, sd->name, sizeof(i->name));
1095
1108 return 0; 1096 return 0;
1109} 1097}
1110 1098
@@ -1130,6 +1118,7 @@ static int fimc_pipeline_validate(struct fimc_dev *fimc)
1130 struct v4l2_subdev_format sink_fmt, src_fmt; 1118 struct v4l2_subdev_format sink_fmt, src_fmt;
1131 struct fimc_vid_cap *vc = &fimc->vid_cap; 1119 struct fimc_vid_cap *vc = &fimc->vid_cap;
1132 struct v4l2_subdev *sd = &vc->subdev; 1120 struct v4l2_subdev *sd = &vc->subdev;
1121 struct fimc_pipeline *p = to_fimc_pipeline(vc->ve.pipe);
1133 struct media_pad *sink_pad, *src_pad; 1122 struct media_pad *sink_pad, *src_pad;
1134 int i, ret; 1123 int i, ret;
1135 1124
@@ -1146,7 +1135,7 @@ static int fimc_pipeline_validate(struct fimc_dev *fimc)
1146 1135
1147 if (p->flags & MEDIA_PAD_FL_SINK) { 1136 if (p->flags & MEDIA_PAD_FL_SINK) {
1148 sink_pad = p; 1137 sink_pad = p;
1149 src_pad = media_entity_remote_source(sink_pad); 1138 src_pad = media_entity_remote_pad(sink_pad);
1150 if (src_pad) 1139 if (src_pad)
1151 break; 1140 break;
1152 } 1141 }
@@ -1183,7 +1172,7 @@ static int fimc_pipeline_validate(struct fimc_dev *fimc)
1183 src_fmt.format.code != sink_fmt.format.code) 1172 src_fmt.format.code != sink_fmt.format.code)
1184 return -EPIPE; 1173 return -EPIPE;
1185 1174
1186 if (sd == fimc->pipeline.subdevs[IDX_SENSOR] && 1175 if (sd == p->subdevs[IDX_SENSOR] &&
1187 fimc_user_defined_mbus_fmt(src_fmt.format.code)) { 1176 fimc_user_defined_mbus_fmt(src_fmt.format.code)) {
1188 struct v4l2_plane_pix_format plane_fmt[FIMC_MAX_PLANES]; 1177 struct v4l2_plane_pix_format plane_fmt[FIMC_MAX_PLANES];
1189 struct fimc_frame *frame = &vc->ctx->d_frame; 1178 struct fimc_frame *frame = &vc->ctx->d_frame;
@@ -1207,9 +1196,8 @@ static int fimc_cap_streamon(struct file *file, void *priv,
1207 enum v4l2_buf_type type) 1196 enum v4l2_buf_type type)
1208{ 1197{
1209 struct fimc_dev *fimc = video_drvdata(file); 1198 struct fimc_dev *fimc = video_drvdata(file);
1210 struct fimc_pipeline *p = &fimc->pipeline;
1211 struct fimc_vid_cap *vc = &fimc->vid_cap; 1199 struct fimc_vid_cap *vc = &fimc->vid_cap;
1212 struct media_entity *entity = &vc->vfd.entity; 1200 struct media_entity *entity = &vc->ve.vdev.entity;
1213 struct fimc_source_info *si = NULL; 1201 struct fimc_source_info *si = NULL;
1214 struct v4l2_subdev *sd; 1202 struct v4l2_subdev *sd;
1215 int ret; 1203 int ret;
@@ -1217,11 +1205,11 @@ static int fimc_cap_streamon(struct file *file, void *priv,
1217 if (fimc_capture_active(fimc)) 1205 if (fimc_capture_active(fimc))
1218 return -EBUSY; 1206 return -EBUSY;
1219 1207
1220 ret = media_entity_pipeline_start(entity, p->m_pipeline); 1208 ret = media_entity_pipeline_start(entity, &vc->ve.pipe->mp);
1221 if (ret < 0) 1209 if (ret < 0)
1222 return ret; 1210 return ret;
1223 1211
1224 sd = p->subdevs[IDX_SENSOR]; 1212 sd = __fimc_md_get_subdev(vc->ve.pipe, IDX_SENSOR);
1225 if (sd) 1213 if (sd)
1226 si = v4l2_get_subdev_hostdata(sd); 1214 si = v4l2_get_subdev_hostdata(sd);
1227 1215
@@ -1259,14 +1247,15 @@ static int fimc_cap_streamoff(struct file *file, void *priv,
1259 enum v4l2_buf_type type) 1247 enum v4l2_buf_type type)
1260{ 1248{
1261 struct fimc_dev *fimc = video_drvdata(file); 1249 struct fimc_dev *fimc = video_drvdata(file);
1250 struct fimc_vid_cap *vc = &fimc->vid_cap;
1262 int ret; 1251 int ret;
1263 1252
1264 ret = vb2_ioctl_streamoff(file, priv, type); 1253 ret = vb2_ioctl_streamoff(file, priv, type);
1265 if (ret < 0) 1254 if (ret < 0)
1266 return ret; 1255 return ret;
1267 1256
1268 media_entity_pipeline_stop(&fimc->vid_cap.vfd.entity); 1257 media_entity_pipeline_stop(&vc->ve.vdev.entity);
1269 fimc->vid_cap.streaming = false; 1258 vc->streaming = false;
1270 return 0; 1259 return 0;
1271} 1260}
1272 1261
@@ -1405,6 +1394,8 @@ static int fimc_link_setup(struct media_entity *entity,
1405{ 1394{
1406 struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity); 1395 struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
1407 struct fimc_dev *fimc = v4l2_get_subdevdata(sd); 1396 struct fimc_dev *fimc = v4l2_get_subdevdata(sd);
1397 struct fimc_vid_cap *vc = &fimc->vid_cap;
1398 struct v4l2_subdev *sensor;
1408 1399
1409 if (media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV) 1400 if (media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
1410 return -EINVAL; 1401 return -EINVAL;
@@ -1416,15 +1407,26 @@ static int fimc_link_setup(struct media_entity *entity,
1416 local->entity->name, remote->entity->name, flags, 1407 local->entity->name, remote->entity->name, flags,
1417 fimc->vid_cap.input); 1408 fimc->vid_cap.input);
1418 1409
1419 if (flags & MEDIA_LNK_FL_ENABLED) { 1410 if (!(flags & MEDIA_LNK_FL_ENABLED)) {
1420 if (fimc->vid_cap.input != 0) 1411 fimc->vid_cap.input = 0;
1421 return -EBUSY;
1422 fimc->vid_cap.input = sd->grp_id;
1423 return 0; 1412 return 0;
1424 } 1413 }
1425 1414
1426 fimc->vid_cap.input = 0; 1415 if (vc->input != 0)
1427 return 0; 1416 return -EBUSY;
1417
1418 vc->input = sd->grp_id;
1419
1420 if (vc->user_subdev_api || vc->inh_sensor_ctrls)
1421 return 0;
1422
1423 /* Inherit V4L2 controls from the image sensor subdev. */
1424 sensor = fimc_find_remote_sensor(&vc->subdev.entity);
1425 if (sensor == NULL)
1426 return 0;
1427
1428 return v4l2_ctrl_add_handler(&vc->ctx->ctrls.handler,
1429 sensor->ctrl_handler, NULL);
1428} 1430}
1429 1431
1430static const struct media_entity_operations fimc_sd_media_ops = { 1432static const struct media_entity_operations fimc_sd_media_ops = {
@@ -1720,8 +1722,8 @@ static int fimc_capture_set_default_format(struct fimc_dev *fimc)
1720 struct v4l2_format fmt = { 1722 struct v4l2_format fmt = {
1721 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, 1723 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
1722 .fmt.pix_mp = { 1724 .fmt.pix_mp = {
1723 .width = 640, 1725 .width = FIMC_DEFAULT_WIDTH,
1724 .height = 480, 1726 .height = FIMC_DEFAULT_HEIGHT,
1725 .pixelformat = V4L2_PIX_FMT_YUYV, 1727 .pixelformat = V4L2_PIX_FMT_YUYV,
1726 .field = V4L2_FIELD_NONE, 1728 .field = V4L2_FIELD_NONE,
1727 .colorspace = V4L2_COLORSPACE_JPEG, 1729 .colorspace = V4L2_COLORSPACE_JPEG,
@@ -1735,10 +1737,11 @@ static int fimc_capture_set_default_format(struct fimc_dev *fimc)
1735static int fimc_register_capture_device(struct fimc_dev *fimc, 1737static int fimc_register_capture_device(struct fimc_dev *fimc,
1736 struct v4l2_device *v4l2_dev) 1738 struct v4l2_device *v4l2_dev)
1737{ 1739{
1738 struct video_device *vfd = &fimc->vid_cap.vfd; 1740 struct video_device *vfd = &fimc->vid_cap.ve.vdev;
1739 struct vb2_queue *q = &fimc->vid_cap.vbq; 1741 struct vb2_queue *q = &fimc->vid_cap.vbq;
1740 struct fimc_ctx *ctx; 1742 struct fimc_ctx *ctx;
1741 struct fimc_vid_cap *vid_cap; 1743 struct fimc_vid_cap *vid_cap;
1744 struct fimc_fmt *fmt;
1742 int ret = -ENOMEM; 1745 int ret = -ENOMEM;
1743 1746
1744 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); 1747 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
@@ -1784,22 +1787,34 @@ static int fimc_register_capture_device(struct fimc_dev *fimc,
1784 1787
1785 ret = vb2_queue_init(q); 1788 ret = vb2_queue_init(q);
1786 if (ret) 1789 if (ret)
1787 goto err_ent; 1790 goto err_free_ctx;
1791
1792 /* Default format configuration */
1793 fmt = fimc_find_format(NULL, NULL, FMT_FLAGS_CAM, 0);
1794 vid_cap->ci_fmt.width = FIMC_DEFAULT_WIDTH;
1795 vid_cap->ci_fmt.height = FIMC_DEFAULT_HEIGHT;
1796 vid_cap->ci_fmt.code = fmt->mbus_code;
1797
1798 ctx->s_frame.width = FIMC_DEFAULT_WIDTH;
1799 ctx->s_frame.height = FIMC_DEFAULT_HEIGHT;
1800 ctx->s_frame.fmt = fmt;
1801
1802 fmt = fimc_find_format(NULL, NULL, FMT_FLAGS_WRITEBACK, 0);
1803 vid_cap->wb_fmt = vid_cap->ci_fmt;
1804 vid_cap->wb_fmt.code = fmt->mbus_code;
1788 1805
1789 vid_cap->vd_pad.flags = MEDIA_PAD_FL_SINK; 1806 vid_cap->vd_pad.flags = MEDIA_PAD_FL_SINK;
1790 ret = media_entity_init(&vfd->entity, 1, &vid_cap->vd_pad, 0); 1807 ret = media_entity_init(&vfd->entity, 1, &vid_cap->vd_pad, 0);
1791 if (ret) 1808 if (ret)
1792 goto err_ent; 1809 goto err_free_ctx;
1793 /* 1810
1794 * For proper order of acquiring/releasing the video 1811 ret = fimc_ctrls_create(ctx);
1795 * and the graph mutex. 1812 if (ret)
1796 */ 1813 goto err_me_cleanup;
1797 v4l2_disable_ioctl_locking(vfd, VIDIOC_TRY_FMT);
1798 v4l2_disable_ioctl_locking(vfd, VIDIOC_S_FMT);
1799 1814
1800 ret = video_register_device(vfd, VFL_TYPE_GRABBER, -1); 1815 ret = video_register_device(vfd, VFL_TYPE_GRABBER, -1);
1801 if (ret) 1816 if (ret)
1802 goto err_vd; 1817 goto err_ctrl_free;
1803 1818
1804 v4l2_info(v4l2_dev, "Registered %s as /dev/%s\n", 1819 v4l2_info(v4l2_dev, "Registered %s as /dev/%s\n",
1805 vfd->name, video_device_node_name(vfd)); 1820 vfd->name, video_device_node_name(vfd));
@@ -1807,9 +1822,11 @@ static int fimc_register_capture_device(struct fimc_dev *fimc,
1807 vfd->ctrl_handler = &ctx->ctrls.handler; 1822 vfd->ctrl_handler = &ctx->ctrls.handler;
1808 return 0; 1823 return 0;
1809 1824
1810err_vd: 1825err_ctrl_free:
1826 fimc_ctrls_delete(ctx);
1827err_me_cleanup:
1811 media_entity_cleanup(&vfd->entity); 1828 media_entity_cleanup(&vfd->entity);
1812err_ent: 1829err_free_ctx:
1813 kfree(ctx); 1830 kfree(ctx);
1814 return ret; 1831 return ret;
1815} 1832}
@@ -1826,12 +1843,12 @@ static int fimc_capture_subdev_registered(struct v4l2_subdev *sd)
1826 if (ret) 1843 if (ret)
1827 return ret; 1844 return ret;
1828 1845
1829 fimc->pipeline_ops = v4l2_get_subdev_hostdata(sd); 1846 fimc->vid_cap.ve.pipe = v4l2_get_subdev_hostdata(sd);
1830 1847
1831 ret = fimc_register_capture_device(fimc, sd->v4l2_dev); 1848 ret = fimc_register_capture_device(fimc, sd->v4l2_dev);
1832 if (ret) { 1849 if (ret) {
1833 fimc_unregister_m2m_device(fimc); 1850 fimc_unregister_m2m_device(fimc);
1834 fimc->pipeline_ops = NULL; 1851 fimc->vid_cap.ve.pipe = NULL;
1835 } 1852 }
1836 1853
1837 return ret; 1854 return ret;
@@ -1840,19 +1857,26 @@ static int fimc_capture_subdev_registered(struct v4l2_subdev *sd)
1840static void fimc_capture_subdev_unregistered(struct v4l2_subdev *sd) 1857static void fimc_capture_subdev_unregistered(struct v4l2_subdev *sd)
1841{ 1858{
1842 struct fimc_dev *fimc = v4l2_get_subdevdata(sd); 1859 struct fimc_dev *fimc = v4l2_get_subdevdata(sd);
1860 struct video_device *vdev;
1843 1861
1844 if (fimc == NULL) 1862 if (fimc == NULL)
1845 return; 1863 return;
1846 1864
1865 mutex_lock(&fimc->lock);
1866
1847 fimc_unregister_m2m_device(fimc); 1867 fimc_unregister_m2m_device(fimc);
1868 vdev = &fimc->vid_cap.ve.vdev;
1848 1869
1849 if (video_is_registered(&fimc->vid_cap.vfd)) { 1870 if (video_is_registered(vdev)) {
1850 video_unregister_device(&fimc->vid_cap.vfd); 1871 video_unregister_device(vdev);
1851 media_entity_cleanup(&fimc->vid_cap.vfd.entity); 1872 media_entity_cleanup(&vdev->entity);
1852 fimc->pipeline_ops = NULL; 1873 fimc_ctrls_delete(fimc->vid_cap.ctx);
1874 fimc->vid_cap.ve.pipe = NULL;
1853 } 1875 }
1854 kfree(fimc->vid_cap.ctx); 1876 kfree(fimc->vid_cap.ctx);
1855 fimc->vid_cap.ctx = NULL; 1877 fimc->vid_cap.ctx = NULL;
1878
1879 mutex_unlock(&fimc->lock);
1856} 1880}
1857 1881
1858static const struct v4l2_subdev_internal_ops fimc_capture_sd_internal_ops = { 1882static const struct v4l2_subdev_internal_ops fimc_capture_sd_internal_ops = {
diff --git a/drivers/media/platform/exynos4-is/fimc-core.c b/drivers/media/platform/exynos4-is/fimc-core.c
index 379a5e9d52a7..6489c5160ee8 100644
--- a/drivers/media/platform/exynos4-is/fimc-core.c
+++ b/drivers/media/platform/exynos4-is/fimc-core.c
@@ -213,17 +213,6 @@ struct fimc_fmt *fimc_get_format(unsigned int index)
213 return &fimc_formats[index]; 213 return &fimc_formats[index];
214} 214}
215 215
216void __fimc_vidioc_querycap(struct device *dev, struct v4l2_capability *cap,
217 unsigned int caps)
218{
219 strlcpy(cap->driver, dev->driver->name, sizeof(cap->driver));
220 strlcpy(cap->card, dev->driver->name, sizeof(cap->card));
221 snprintf(cap->bus_info, sizeof(cap->bus_info),
222 "platform:%s", dev_name(dev));
223 cap->device_caps = caps;
224 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
225}
226
227int fimc_check_scaler_ratio(struct fimc_ctx *ctx, int sw, int sh, 216int fimc_check_scaler_ratio(struct fimc_ctx *ctx, int sw, int sh,
228 int dw, int dh, int rotation) 217 int dw, int dh, int rotation)
229{ 218{
diff --git a/drivers/media/platform/exynos4-is/fimc-core.h b/drivers/media/platform/exynos4-is/fimc-core.h
index 539a3f71c16a..3d376faec777 100644
--- a/drivers/media/platform/exynos4-is/fimc-core.h
+++ b/drivers/media/platform/exynos4-is/fimc-core.h
@@ -48,6 +48,8 @@
48#define FIMC_DEF_MIN_SIZE 16 48#define FIMC_DEF_MIN_SIZE 16
49#define FIMC_DEF_HEIGHT_ALIGN 2 49#define FIMC_DEF_HEIGHT_ALIGN 2
50#define FIMC_DEF_HOR_OFFS_ALIGN 1 50#define FIMC_DEF_HOR_OFFS_ALIGN 1
51#define FIMC_DEFAULT_WIDTH 640
52#define FIMC_DEFAULT_HEIGHT 480
51 53
52/* indices to the clocks array */ 54/* indices to the clocks array */
53enum { 55enum {
@@ -283,8 +285,8 @@ struct fimc_m2m_device {
283/** 285/**
284 * struct fimc_vid_cap - camera capture device information 286 * struct fimc_vid_cap - camera capture device information
285 * @ctx: hardware context data 287 * @ctx: hardware context data
286 * @vfd: video device node for camera capture mode
287 * @subdev: subdev exposing the FIMC processing block 288 * @subdev: subdev exposing the FIMC processing block
289 * @ve: exynos video device entity structure
288 * @vd_pad: fimc video capture node pad 290 * @vd_pad: fimc video capture node pad
289 * @sd_pads: fimc video processing block pads 291 * @sd_pads: fimc video processing block pads
290 * @ci_fmt: image format at the FIMC camera input (and the scaler output) 292 * @ci_fmt: image format at the FIMC camera input (and the scaler output)
@@ -298,15 +300,16 @@ struct fimc_m2m_device {
298 * @frame_count: the frame counter for statistics 300 * @frame_count: the frame counter for statistics
299 * @reqbufs_count: the number of buffers requested in REQBUFS ioctl 301 * @reqbufs_count: the number of buffers requested in REQBUFS ioctl
300 * @input_index: input (camera sensor) index 302 * @input_index: input (camera sensor) index
301 * @refcnt: driver's private reference counter
302 * @input: capture input type, grp_id of the attached subdev 303 * @input: capture input type, grp_id of the attached subdev
303 * @user_subdev_api: true if subdevs are not configured by the host driver 304 * @user_subdev_api: true if subdevs are not configured by the host driver
305 * @inh_sensor_ctrls: a flag indicating v4l2 controls are inherited from
306 * an image sensor subdev
304 */ 307 */
305struct fimc_vid_cap { 308struct fimc_vid_cap {
306 struct fimc_ctx *ctx; 309 struct fimc_ctx *ctx;
307 struct vb2_alloc_ctx *alloc_ctx; 310 struct vb2_alloc_ctx *alloc_ctx;
308 struct video_device vfd;
309 struct v4l2_subdev subdev; 311 struct v4l2_subdev subdev;
312 struct exynos_video_entity ve;
310 struct media_pad vd_pad; 313 struct media_pad vd_pad;
311 struct media_pad sd_pads[FIMC_SD_PADS_NUM]; 314 struct media_pad sd_pads[FIMC_SD_PADS_NUM];
312 struct v4l2_mbus_framefmt ci_fmt; 315 struct v4l2_mbus_framefmt ci_fmt;
@@ -321,9 +324,9 @@ struct fimc_vid_cap {
321 unsigned int reqbufs_count; 324 unsigned int reqbufs_count;
322 bool streaming; 325 bool streaming;
323 int input_index; 326 int input_index;
324 int refcnt;
325 u32 input; 327 u32 input;
326 bool user_subdev_api; 328 bool user_subdev_api;
329 bool inh_sensor_ctrls;
327}; 330};
328 331
329/** 332/**
@@ -434,8 +437,6 @@ struct fimc_dev {
434 struct fimc_vid_cap vid_cap; 437 struct fimc_vid_cap vid_cap;
435 unsigned long state; 438 unsigned long state;
436 struct vb2_alloc_ctx *alloc_ctx; 439 struct vb2_alloc_ctx *alloc_ctx;
437 struct fimc_pipeline pipeline;
438 const struct fimc_pipeline_ops *pipeline_ops;
439}; 440};
440 441
441/** 442/**
@@ -620,8 +621,6 @@ static inline struct fimc_frame *ctx_get_frame(struct fimc_ctx *ctx,
620/* fimc-core.c */ 621/* fimc-core.c */
621int fimc_vidioc_enum_fmt_mplane(struct file *file, void *priv, 622int fimc_vidioc_enum_fmt_mplane(struct file *file, void *priv,
622 struct v4l2_fmtdesc *f); 623 struct v4l2_fmtdesc *f);
623void __fimc_vidioc_querycap(struct device *dev, struct v4l2_capability *cap,
624 unsigned int caps);
625int fimc_ctrls_create(struct fimc_ctx *ctx); 624int fimc_ctrls_create(struct fimc_ctx *ctx);
626void fimc_ctrls_delete(struct fimc_ctx *ctx); 625void fimc_ctrls_delete(struct fimc_ctx *ctx);
627void fimc_ctrls_activate(struct fimc_ctx *ctx, bool active); 626void fimc_ctrls_activate(struct fimc_ctx *ctx, bool active);
diff --git a/drivers/media/platform/exynos4-is/fimc-is-i2c.c b/drivers/media/platform/exynos4-is/fimc-is-i2c.c
index c397777d7cbb..617a798d9235 100644
--- a/drivers/media/platform/exynos4-is/fimc-is-i2c.c
+++ b/drivers/media/platform/exynos4-is/fimc-is-i2c.c
@@ -96,7 +96,7 @@ static int fimc_is_i2c_resume(struct device *dev)
96 return clk_prepare_enable(isp_i2c->clock); 96 return clk_prepare_enable(isp_i2c->clock);
97} 97}
98 98
99UNIVERSAL_DEV_PM_OPS(fimc_is_i2c_pm_ops, fimc_is_i2c_suspend, 99static UNIVERSAL_DEV_PM_OPS(fimc_is_i2c_pm_ops, fimc_is_i2c_suspend,
100 fimc_is_i2c_resume, NULL); 100 fimc_is_i2c_resume, NULL);
101 101
102static const struct of_device_id fimc_is_i2c_of_match[] = { 102static const struct of_device_id fimc_is_i2c_of_match[] = {
diff --git a/drivers/media/platform/exynos4-is/fimc-is-param.c b/drivers/media/platform/exynos4-is/fimc-is-param.c
index 53fe2a2b4db3..c7e7f694c6ed 100644
--- a/drivers/media/platform/exynos4-is/fimc-is-param.c
+++ b/drivers/media/platform/exynos4-is/fimc-is-param.c
@@ -38,7 +38,7 @@ static void __hw_param_copy(void *dst, void *src)
38 memcpy(dst, src, FIMC_IS_PARAM_MAX_SIZE); 38 memcpy(dst, src, FIMC_IS_PARAM_MAX_SIZE);
39} 39}
40 40
41void __fimc_is_hw_update_param_global_shotmode(struct fimc_is *is) 41static void __fimc_is_hw_update_param_global_shotmode(struct fimc_is *is)
42{ 42{
43 struct param_global_shotmode *dst, *src; 43 struct param_global_shotmode *dst, *src;
44 44
@@ -47,7 +47,7 @@ void __fimc_is_hw_update_param_global_shotmode(struct fimc_is *is)
47 __hw_param_copy(dst, src); 47 __hw_param_copy(dst, src);
48} 48}
49 49
50void __fimc_is_hw_update_param_sensor_framerate(struct fimc_is *is) 50static void __fimc_is_hw_update_param_sensor_framerate(struct fimc_is *is)
51{ 51{
52 struct param_sensor_framerate *dst, *src; 52 struct param_sensor_framerate *dst, *src;
53 53
@@ -168,8 +168,8 @@ unsigned int __get_pending_param_count(struct fimc_is *is)
168 unsigned int count; 168 unsigned int count;
169 169
170 spin_lock_irqsave(&is->slock, flags); 170 spin_lock_irqsave(&is->slock, flags);
171 count = hweight32(config->p_region_index1); 171 count = hweight32(config->p_region_index[0]);
172 count += hweight32(config->p_region_index2); 172 count += hweight32(config->p_region_index[1]);
173 spin_unlock_irqrestore(&is->slock, flags); 173 spin_unlock_irqrestore(&is->slock, flags);
174 174
175 return count; 175 return count;
@@ -177,31 +177,30 @@ unsigned int __get_pending_param_count(struct fimc_is *is)
177 177
178int __is_hw_update_params(struct fimc_is *is) 178int __is_hw_update_params(struct fimc_is *is)
179{ 179{
180 unsigned long *p_index1, *p_index2; 180 unsigned long *p_index;
181 int i, id, ret = 0; 181 int i, id, ret = 0;
182 182
183 id = is->config_index; 183 id = is->config_index;
184 p_index1 = &is->config[id].p_region_index1; 184 p_index = &is->config[id].p_region_index[0];
185 p_index2 = &is->config[id].p_region_index2;
186 185
187 if (test_bit(PARAM_GLOBAL_SHOTMODE, p_index1)) 186 if (test_bit(PARAM_GLOBAL_SHOTMODE, p_index))
188 __fimc_is_hw_update_param_global_shotmode(is); 187 __fimc_is_hw_update_param_global_shotmode(is);
189 188
190 if (test_bit(PARAM_SENSOR_FRAME_RATE, p_index1)) 189 if (test_bit(PARAM_SENSOR_FRAME_RATE, p_index))
191 __fimc_is_hw_update_param_sensor_framerate(is); 190 __fimc_is_hw_update_param_sensor_framerate(is);
192 191
193 for (i = PARAM_ISP_CONTROL; i < PARAM_DRC_CONTROL; i++) { 192 for (i = PARAM_ISP_CONTROL; i < PARAM_DRC_CONTROL; i++) {
194 if (test_bit(i, p_index1)) 193 if (test_bit(i, p_index))
195 ret = __fimc_is_hw_update_param(is, i); 194 ret = __fimc_is_hw_update_param(is, i);
196 } 195 }
197 196
198 for (i = PARAM_DRC_CONTROL; i < PARAM_SCALERC_CONTROL; i++) { 197 for (i = PARAM_DRC_CONTROL; i < PARAM_SCALERC_CONTROL; i++) {
199 if (test_bit(i, p_index1)) 198 if (test_bit(i, p_index))
200 ret = __fimc_is_hw_update_param(is, i); 199 ret = __fimc_is_hw_update_param(is, i);
201 } 200 }
202 201
203 for (i = PARAM_FD_CONTROL; i <= PARAM_FD_CONFIG; i++) { 202 for (i = PARAM_FD_CONTROL; i <= PARAM_FD_CONFIG; i++) {
204 if (test_bit((i - 32), p_index2)) 203 if (test_bit(i, p_index))
205 ret = __fimc_is_hw_update_param(is, i); 204 ret = __fimc_is_hw_update_param(is, i);
206 } 205 }
207 206
@@ -243,7 +242,7 @@ void __is_set_frame_size(struct fimc_is *is, struct v4l2_mbus_framefmt *mf)
243 fd->otf_input.height = mf->height; 242 fd->otf_input.height = mf->height;
244 243
245 if (test_bit(PARAM_ISP_OTF_INPUT, 244 if (test_bit(PARAM_ISP_OTF_INPUT,
246 &is->config[index].p_region_index1)) 245 &is->config[index].p_region_index[0]))
247 return; 246 return;
248 247
249 /* Update field */ 248 /* Update field */
@@ -368,7 +367,7 @@ void __is_set_isp_adjust(struct fimc_is *is, u32 cmd, u32 val)
368 unsigned long *p_index; 367 unsigned long *p_index;
369 struct isp_param *isp; 368 struct isp_param *isp;
370 369
371 p_index = &is->config[index].p_region_index1; 370 p_index = &is->config[index].p_region_index[0];
372 isp = &is->config[index].isp; 371 isp = &is->config[index].isp;
373 372
374 switch (cmd) { 373 switch (cmd) {
@@ -415,7 +414,7 @@ void __is_set_isp_metering(struct fimc_is *is, u32 id, u32 val)
415 struct isp_param *isp; 414 struct isp_param *isp;
416 unsigned long *p_index; 415 unsigned long *p_index;
417 416
418 p_index = &is->config[index].p_region_index1; 417 p_index = &is->config[index].p_region_index[0];
419 isp = &is->config[index].isp; 418 isp = &is->config[index].isp;
420 419
421 switch (id) { 420 switch (id) {
@@ -476,7 +475,7 @@ void __is_set_fd_control(struct fimc_is *is, u32 val)
476 struct fd_param *fd; 475 struct fd_param *fd;
477 unsigned long *p_index; 476 unsigned long *p_index;
478 477
479 p_index = &is->config[index].p_region_index2; 478 p_index = &is->config[index].p_region_index[1];
480 fd = &is->config[index].fd; 479 fd = &is->config[index].fd;
481 480
482 fd->control.cmd = val; 481 fd->control.cmd = val;
@@ -491,7 +490,7 @@ void __is_set_fd_config_maxface(struct fimc_is *is, u32 val)
491 struct fd_param *fd; 490 struct fd_param *fd;
492 unsigned long *p_index; 491 unsigned long *p_index;
493 492
494 p_index = &is->config[index].p_region_index2; 493 p_index = &is->config[index].p_region_index[1];
495 fd = &is->config[index].fd; 494 fd = &is->config[index].fd;
496 495
497 fd->config.max_number = val; 496 fd->config.max_number = val;
@@ -511,7 +510,7 @@ void __is_set_fd_config_rollangle(struct fimc_is *is, u32 val)
511 struct fd_param *fd; 510 struct fd_param *fd;
512 unsigned long *p_index; 511 unsigned long *p_index;
513 512
514 p_index = &is->config[index].p_region_index2; 513 p_index = &is->config[index].p_region_index[1];
515 fd = &is->config[index].fd; 514 fd = &is->config[index].fd;
516 515
517 fd->config.roll_angle = val; 516 fd->config.roll_angle = val;
@@ -531,7 +530,7 @@ void __is_set_fd_config_yawangle(struct fimc_is *is, u32 val)
531 struct fd_param *fd; 530 struct fd_param *fd;
532 unsigned long *p_index; 531 unsigned long *p_index;
533 532
534 p_index = &is->config[index].p_region_index2; 533 p_index = &is->config[index].p_region_index[1];
535 fd = &is->config[index].fd; 534 fd = &is->config[index].fd;
536 535
537 fd->config.yaw_angle = val; 536 fd->config.yaw_angle = val;
@@ -551,7 +550,7 @@ void __is_set_fd_config_smilemode(struct fimc_is *is, u32 val)
551 struct fd_param *fd; 550 struct fd_param *fd;
552 unsigned long *p_index; 551 unsigned long *p_index;
553 552
554 p_index = &is->config[index].p_region_index2; 553 p_index = &is->config[index].p_region_index[1];
555 fd = &is->config[index].fd; 554 fd = &is->config[index].fd;
556 555
557 fd->config.smile_mode = val; 556 fd->config.smile_mode = val;
@@ -571,7 +570,7 @@ void __is_set_fd_config_blinkmode(struct fimc_is *is, u32 val)
571 struct fd_param *fd; 570 struct fd_param *fd;
572 unsigned long *p_index; 571 unsigned long *p_index;
573 572
574 p_index = &is->config[index].p_region_index2; 573 p_index = &is->config[index].p_region_index[1];
575 fd = &is->config[index].fd; 574 fd = &is->config[index].fd;
576 575
577 fd->config.blink_mode = val; 576 fd->config.blink_mode = val;
@@ -591,7 +590,7 @@ void __is_set_fd_config_eyedetect(struct fimc_is *is, u32 val)
591 struct fd_param *fd; 590 struct fd_param *fd;
592 unsigned long *p_index; 591 unsigned long *p_index;
593 592
594 p_index = &is->config[index].p_region_index2; 593 p_index = &is->config[index].p_region_index[1];
595 fd = &is->config[index].fd; 594 fd = &is->config[index].fd;
596 595
597 fd->config.eye_detect = val; 596 fd->config.eye_detect = val;
@@ -611,7 +610,7 @@ void __is_set_fd_config_mouthdetect(struct fimc_is *is, u32 val)
611 struct fd_param *fd; 610 struct fd_param *fd;
612 unsigned long *p_index; 611 unsigned long *p_index;
613 612
614 p_index = &is->config[index].p_region_index2; 613 p_index = &is->config[index].p_region_index[1];
615 fd = &is->config[index].fd; 614 fd = &is->config[index].fd;
616 615
617 fd->config.mouth_detect = val; 616 fd->config.mouth_detect = val;
@@ -631,7 +630,7 @@ void __is_set_fd_config_orientation(struct fimc_is *is, u32 val)
631 struct fd_param *fd; 630 struct fd_param *fd;
632 unsigned long *p_index; 631 unsigned long *p_index;
633 632
634 p_index = &is->config[index].p_region_index2; 633 p_index = &is->config[index].p_region_index[1];
635 fd = &is->config[index].fd; 634 fd = &is->config[index].fd;
636 635
637 fd->config.orientation = val; 636 fd->config.orientation = val;
@@ -651,7 +650,7 @@ void __is_set_fd_config_orientation_val(struct fimc_is *is, u32 val)
651 struct fd_param *fd; 650 struct fd_param *fd;
652 unsigned long *p_index; 651 unsigned long *p_index;
653 652
654 p_index = &is->config[index].p_region_index2; 653 p_index = &is->config[index].p_region_index[1];
655 fd = &is->config[index].fd; 654 fd = &is->config[index].fd;
656 655
657 fd->config.orientation_value = val; 656 fd->config.orientation_value = val;
@@ -672,7 +671,7 @@ void fimc_is_set_initial_params(struct fimc_is *is)
672 struct isp_param *isp; 671 struct isp_param *isp;
673 struct drc_param *drc; 672 struct drc_param *drc;
674 struct fd_param *fd; 673 struct fd_param *fd;
675 unsigned long *p_index1, *p_index2; 674 unsigned long *p_index;
676 unsigned int index; 675 unsigned int index;
677 676
678 index = is->config_index; 677 index = is->config_index;
@@ -681,8 +680,7 @@ void fimc_is_set_initial_params(struct fimc_is *is)
681 isp = &is->config[index].isp; 680 isp = &is->config[index].isp;
682 drc = &is->config[index].drc; 681 drc = &is->config[index].drc;
683 fd = &is->config[index].fd; 682 fd = &is->config[index].fd;
684 p_index1 = &is->config[index].p_region_index1; 683 p_index = &is->config[index].p_region_index[0];
685 p_index2 = &is->config[index].p_region_index2;
686 684
687 /* Global */ 685 /* Global */
688 global->shotmode.cmd = 1; 686 global->shotmode.cmd = 1;
@@ -695,7 +693,7 @@ void fimc_is_set_initial_params(struct fimc_is *is)
695 fimc_is_set_param_bit(is, PARAM_ISP_CONTROL); 693 fimc_is_set_param_bit(is, PARAM_ISP_CONTROL);
696 694
697 isp->otf_input.cmd = OTF_INPUT_COMMAND_ENABLE; 695 isp->otf_input.cmd = OTF_INPUT_COMMAND_ENABLE;
698 if (!test_bit(PARAM_ISP_OTF_INPUT, p_index1)) { 696 if (!test_bit(PARAM_ISP_OTF_INPUT, p_index)) {
699 isp->otf_input.width = DEFAULT_PREVIEW_STILL_WIDTH; 697 isp->otf_input.width = DEFAULT_PREVIEW_STILL_WIDTH;
700 isp->otf_input.height = DEFAULT_PREVIEW_STILL_HEIGHT; 698 isp->otf_input.height = DEFAULT_PREVIEW_STILL_HEIGHT;
701 fimc_is_set_param_bit(is, PARAM_ISP_OTF_INPUT); 699 fimc_is_set_param_bit(is, PARAM_ISP_OTF_INPUT);
@@ -738,20 +736,20 @@ void fimc_is_set_initial_params(struct fimc_is *is)
738 isp->aa.target = ISP_AA_TARGET_AE | ISP_AA_TARGET_AWB; 736 isp->aa.target = ISP_AA_TARGET_AE | ISP_AA_TARGET_AWB;
739 fimc_is_set_param_bit(is, PARAM_ISP_AA); 737 fimc_is_set_param_bit(is, PARAM_ISP_AA);
740 738
741 if (!test_bit(PARAM_ISP_FLASH, p_index1)) 739 if (!test_bit(PARAM_ISP_FLASH, p_index))
742 __is_set_isp_flash(is, ISP_FLASH_COMMAND_DISABLE, 740 __is_set_isp_flash(is, ISP_FLASH_COMMAND_DISABLE,
743 ISP_FLASH_REDEYE_DISABLE); 741 ISP_FLASH_REDEYE_DISABLE);
744 742
745 if (!test_bit(PARAM_ISP_AWB, p_index1)) 743 if (!test_bit(PARAM_ISP_AWB, p_index))
746 __is_set_isp_awb(is, ISP_AWB_COMMAND_AUTO, 0); 744 __is_set_isp_awb(is, ISP_AWB_COMMAND_AUTO, 0);
747 745
748 if (!test_bit(PARAM_ISP_IMAGE_EFFECT, p_index1)) 746 if (!test_bit(PARAM_ISP_IMAGE_EFFECT, p_index))
749 __is_set_isp_effect(is, ISP_IMAGE_EFFECT_DISABLE); 747 __is_set_isp_effect(is, ISP_IMAGE_EFFECT_DISABLE);
750 748
751 if (!test_bit(PARAM_ISP_ISO, p_index1)) 749 if (!test_bit(PARAM_ISP_ISO, p_index))
752 __is_set_isp_iso(is, ISP_ISO_COMMAND_AUTO, 0); 750 __is_set_isp_iso(is, ISP_ISO_COMMAND_AUTO, 0);
753 751
754 if (!test_bit(PARAM_ISP_ADJUST, p_index1)) { 752 if (!test_bit(PARAM_ISP_ADJUST, p_index)) {
755 __is_set_isp_adjust(is, ISP_ADJUST_COMMAND_MANUAL_CONTRAST, 0); 753 __is_set_isp_adjust(is, ISP_ADJUST_COMMAND_MANUAL_CONTRAST, 0);
756 __is_set_isp_adjust(is, 754 __is_set_isp_adjust(is,
757 ISP_ADJUST_COMMAND_MANUAL_SATURATION, 0); 755 ISP_ADJUST_COMMAND_MANUAL_SATURATION, 0);
@@ -762,7 +760,7 @@ void fimc_is_set_initial_params(struct fimc_is *is)
762 __is_set_isp_adjust(is, ISP_ADJUST_COMMAND_MANUAL_HUE, 0); 760 __is_set_isp_adjust(is, ISP_ADJUST_COMMAND_MANUAL_HUE, 0);
763 } 761 }
764 762
765 if (!test_bit(PARAM_ISP_METERING, p_index1)) { 763 if (!test_bit(PARAM_ISP_METERING, p_index)) {
766 __is_set_isp_metering(is, 0, ISP_METERING_COMMAND_CENTER); 764 __is_set_isp_metering(is, 0, ISP_METERING_COMMAND_CENTER);
767 __is_set_isp_metering(is, 1, 0); 765 __is_set_isp_metering(is, 1, 0);
768 __is_set_isp_metering(is, 2, 0); 766 __is_set_isp_metering(is, 2, 0);
@@ -770,11 +768,11 @@ void fimc_is_set_initial_params(struct fimc_is *is)
770 __is_set_isp_metering(is, 4, 0); 768 __is_set_isp_metering(is, 4, 0);
771 } 769 }
772 770
773 if (!test_bit(PARAM_ISP_AFC, p_index1)) 771 if (!test_bit(PARAM_ISP_AFC, p_index))
774 __is_set_isp_afc(is, ISP_AFC_COMMAND_AUTO, 0); 772 __is_set_isp_afc(is, ISP_AFC_COMMAND_AUTO, 0);
775 773
776 isp->otf_output.cmd = OTF_OUTPUT_COMMAND_ENABLE; 774 isp->otf_output.cmd = OTF_OUTPUT_COMMAND_ENABLE;
777 if (!test_bit(PARAM_ISP_OTF_OUTPUT, p_index1)) { 775 if (!test_bit(PARAM_ISP_OTF_OUTPUT, p_index)) {
778 isp->otf_output.width = DEFAULT_PREVIEW_STILL_WIDTH; 776 isp->otf_output.width = DEFAULT_PREVIEW_STILL_WIDTH;
779 isp->otf_output.height = DEFAULT_PREVIEW_STILL_HEIGHT; 777 isp->otf_output.height = DEFAULT_PREVIEW_STILL_HEIGHT;
780 fimc_is_set_param_bit(is, PARAM_ISP_OTF_OUTPUT); 778 fimc_is_set_param_bit(is, PARAM_ISP_OTF_OUTPUT);
@@ -784,7 +782,7 @@ void fimc_is_set_initial_params(struct fimc_is *is)
784 isp->otf_output.order = 0; 782 isp->otf_output.order = 0;
785 isp->otf_output.err = OTF_OUTPUT_ERROR_NONE; 783 isp->otf_output.err = OTF_OUTPUT_ERROR_NONE;
786 784
787 if (!test_bit(PARAM_ISP_DMA1_OUTPUT, p_index1)) { 785 if (!test_bit(PARAM_ISP_DMA1_OUTPUT, p_index)) {
788 isp->dma1_output.cmd = DMA_OUTPUT_COMMAND_DISABLE; 786 isp->dma1_output.cmd = DMA_OUTPUT_COMMAND_DISABLE;
789 isp->dma1_output.width = 0; 787 isp->dma1_output.width = 0;
790 isp->dma1_output.height = 0; 788 isp->dma1_output.height = 0;
@@ -800,7 +798,7 @@ void fimc_is_set_initial_params(struct fimc_is *is)
800 fimc_is_set_param_bit(is, PARAM_ISP_DMA1_OUTPUT); 798 fimc_is_set_param_bit(is, PARAM_ISP_DMA1_OUTPUT);
801 } 799 }
802 800
803 if (!test_bit(PARAM_ISP_DMA2_OUTPUT, p_index1)) { 801 if (!test_bit(PARAM_ISP_DMA2_OUTPUT, p_index)) {
804 isp->dma2_output.cmd = DMA_OUTPUT_COMMAND_DISABLE; 802 isp->dma2_output.cmd = DMA_OUTPUT_COMMAND_DISABLE;
805 isp->dma2_output.width = 0; 803 isp->dma2_output.width = 0;
806 isp->dma2_output.height = 0; 804 isp->dma2_output.height = 0;
@@ -817,7 +815,7 @@ void fimc_is_set_initial_params(struct fimc_is *is)
817 } 815 }
818 816
819 /* Sensor */ 817 /* Sensor */
820 if (!test_bit(PARAM_SENSOR_FRAME_RATE, p_index1)) { 818 if (!test_bit(PARAM_SENSOR_FRAME_RATE, p_index)) {
821 if (is->config_index == 0) 819 if (is->config_index == 0)
822 __is_set_sensor(is, 0); 820 __is_set_sensor(is, 0);
823 } 821 }
@@ -827,7 +825,7 @@ void fimc_is_set_initial_params(struct fimc_is *is)
827 __is_set_drc_control(is, CONTROL_BYPASS_ENABLE); 825 __is_set_drc_control(is, CONTROL_BYPASS_ENABLE);
828 826
829 drc->otf_input.cmd = OTF_INPUT_COMMAND_ENABLE; 827 drc->otf_input.cmd = OTF_INPUT_COMMAND_ENABLE;
830 if (!test_bit(PARAM_DRC_OTF_INPUT, p_index1)) { 828 if (!test_bit(PARAM_DRC_OTF_INPUT, p_index)) {
831 drc->otf_input.width = DEFAULT_PREVIEW_STILL_WIDTH; 829 drc->otf_input.width = DEFAULT_PREVIEW_STILL_WIDTH;
832 drc->otf_input.height = DEFAULT_PREVIEW_STILL_HEIGHT; 830 drc->otf_input.height = DEFAULT_PREVIEW_STILL_HEIGHT;
833 fimc_is_set_param_bit(is, PARAM_DRC_OTF_INPUT); 831 fimc_is_set_param_bit(is, PARAM_DRC_OTF_INPUT);
@@ -850,7 +848,7 @@ void fimc_is_set_initial_params(struct fimc_is *is)
850 fimc_is_set_param_bit(is, PARAM_DRC_DMA_INPUT); 848 fimc_is_set_param_bit(is, PARAM_DRC_DMA_INPUT);
851 849
852 drc->otf_output.cmd = OTF_OUTPUT_COMMAND_ENABLE; 850 drc->otf_output.cmd = OTF_OUTPUT_COMMAND_ENABLE;
853 if (!test_bit(PARAM_DRC_OTF_OUTPUT, p_index1)) { 851 if (!test_bit(PARAM_DRC_OTF_OUTPUT, p_index)) {
854 drc->otf_output.width = DEFAULT_PREVIEW_STILL_WIDTH; 852 drc->otf_output.width = DEFAULT_PREVIEW_STILL_WIDTH;
855 drc->otf_output.height = DEFAULT_PREVIEW_STILL_HEIGHT; 853 drc->otf_output.height = DEFAULT_PREVIEW_STILL_HEIGHT;
856 fimc_is_set_param_bit(is, PARAM_DRC_OTF_OUTPUT); 854 fimc_is_set_param_bit(is, PARAM_DRC_OTF_OUTPUT);
@@ -865,7 +863,7 @@ void fimc_is_set_initial_params(struct fimc_is *is)
865 fd->control.bypass = CONTROL_BYPASS_DISABLE; 863 fd->control.bypass = CONTROL_BYPASS_DISABLE;
866 864
867 fd->otf_input.cmd = OTF_INPUT_COMMAND_ENABLE; 865 fd->otf_input.cmd = OTF_INPUT_COMMAND_ENABLE;
868 if (!test_bit((PARAM_FD_OTF_INPUT - 32), p_index2)) { 866 if (!test_bit(PARAM_FD_OTF_INPUT, p_index)) {
869 fd->otf_input.width = DEFAULT_PREVIEW_STILL_WIDTH; 867 fd->otf_input.width = DEFAULT_PREVIEW_STILL_WIDTH;
870 fd->otf_input.height = DEFAULT_PREVIEW_STILL_HEIGHT; 868 fd->otf_input.height = DEFAULT_PREVIEW_STILL_HEIGHT;
871 fimc_is_set_param_bit(is, PARAM_FD_OTF_INPUT); 869 fimc_is_set_param_bit(is, PARAM_FD_OTF_INPUT);
diff --git a/drivers/media/platform/exynos4-is/fimc-is-regs.c b/drivers/media/platform/exynos4-is/fimc-is-regs.c
index d05eaa2c8490..63c68ec7cfa4 100644
--- a/drivers/media/platform/exynos4-is/fimc-is-regs.c
+++ b/drivers/media/platform/exynos4-is/fimc-is-regs.c
@@ -89,8 +89,8 @@ int fimc_is_hw_set_param(struct fimc_is *is)
89 mcuctl_write(is->config_index, is, MCUCTL_REG_ISSR(2)); 89 mcuctl_write(is->config_index, is, MCUCTL_REG_ISSR(2));
90 90
91 mcuctl_write(param_count, is, MCUCTL_REG_ISSR(3)); 91 mcuctl_write(param_count, is, MCUCTL_REG_ISSR(3));
92 mcuctl_write(config->p_region_index1, is, MCUCTL_REG_ISSR(4)); 92 mcuctl_write(config->p_region_index[0], is, MCUCTL_REG_ISSR(4));
93 mcuctl_write(config->p_region_index2, is, MCUCTL_REG_ISSR(5)); 93 mcuctl_write(config->p_region_index[1], is, MCUCTL_REG_ISSR(5));
94 94
95 fimc_is_hw_set_intgr0_gd0(is); 95 fimc_is_hw_set_intgr0_gd0(is);
96 return 0; 96 return 0;
diff --git a/drivers/media/platform/exynos4-is/fimc-is.c b/drivers/media/platform/exynos4-is/fimc-is.c
index 0741945b79ed..967f6a939340 100644
--- a/drivers/media/platform/exynos4-is/fimc-is.c
+++ b/drivers/media/platform/exynos4-is/fimc-is.c
@@ -129,7 +129,7 @@ static int fimc_is_setup_clocks(struct fimc_is *is)
129 ATCLK_MCUISP_FREQUENCY); 129 ATCLK_MCUISP_FREQUENCY);
130} 130}
131 131
132int fimc_is_enable_clocks(struct fimc_is *is) 132static int fimc_is_enable_clocks(struct fimc_is *is)
133{ 133{
134 int i, ret; 134 int i, ret;
135 135
@@ -149,7 +149,7 @@ int fimc_is_enable_clocks(struct fimc_is *is)
149 return 0; 149 return 0;
150} 150}
151 151
152void fimc_is_disable_clocks(struct fimc_is *is) 152static void fimc_is_disable_clocks(struct fimc_is *is)
153{ 153{
154 int i; 154 int i;
155 155
@@ -527,8 +527,8 @@ static void fimc_is_general_irq_handler(struct fimc_is *is)
527 break; 527 break;
528 528
529 case HIC_SET_PARAMETER: 529 case HIC_SET_PARAMETER:
530 is->config[is->config_index].p_region_index1 = 0; 530 is->config[is->config_index].p_region_index[0] = 0;
531 is->config[is->config_index].p_region_index2 = 0; 531 is->config[is->config_index].p_region_index[1] = 0;
532 set_bit(IS_ST_BLOCK_CMD_CLEARED, &is->state); 532 set_bit(IS_ST_BLOCK_CMD_CLEARED, &is->state);
533 pr_debug("HIC_SET_PARAMETER\n"); 533 pr_debug("HIC_SET_PARAMETER\n");
534 break; 534 break;
@@ -587,8 +587,8 @@ static void fimc_is_general_irq_handler(struct fimc_is *is)
587 587
588 switch (is->i2h_cmd.args[0]) { 588 switch (is->i2h_cmd.args[0]) {
589 case HIC_SET_PARAMETER: 589 case HIC_SET_PARAMETER:
590 is->config[is->config_index].p_region_index1 = 0; 590 is->config[is->config_index].p_region_index[0] = 0;
591 is->config[is->config_index].p_region_index2 = 0; 591 is->config[is->config_index].p_region_index[1] = 0;
592 set_bit(IS_ST_BLOCK_CMD_CLEARED, &is->state); 592 set_bit(IS_ST_BLOCK_CMD_CLEARED, &is->state);
593 break; 593 break;
594 } 594 }
diff --git a/drivers/media/platform/exynos4-is/fimc-is.h b/drivers/media/platform/exynos4-is/fimc-is.h
index d7db133b493f..61bb0127e19d 100644
--- a/drivers/media/platform/exynos4-is/fimc-is.h
+++ b/drivers/media/platform/exynos4-is/fimc-is.h
@@ -33,8 +33,8 @@
33 33
34#define FIMC_IS_DRV_NAME "exynos4-fimc-is" 34#define FIMC_IS_DRV_NAME "exynos4-fimc-is"
35 35
36#define FIMC_IS_FW_FILENAME "fimc_is_fw.bin" 36#define FIMC_IS_FW_FILENAME "exynos4_fimc_is_fw.bin"
37#define FIMC_IS_SETFILE_6A3 "setfile.bin" 37#define FIMC_IS_SETFILE_6A3 "exynos4_s5k6a3_setfile.bin"
38 38
39#define FIMC_IS_FW_LOAD_TIMEOUT 1000 /* ms */ 39#define FIMC_IS_FW_LOAD_TIMEOUT 1000 /* ms */
40#define FIMC_IS_POWER_ON_TIMEOUT 1000 /* us */ 40#define FIMC_IS_POWER_ON_TIMEOUT 1000 /* us */
@@ -225,8 +225,7 @@ struct chain_config {
225 struct drc_param drc; 225 struct drc_param drc;
226 struct fd_param fd; 226 struct fd_param fd;
227 227
228 unsigned long p_region_index1; 228 unsigned long p_region_index[2];
229 unsigned long p_region_index2;
230}; 229};
231 230
232/** 231/**
@@ -302,10 +301,7 @@ static inline void fimc_is_set_param_bit(struct fimc_is *is, int num)
302{ 301{
303 struct chain_config *cfg = &is->config[is->config_index]; 302 struct chain_config *cfg = &is->config[is->config_index];
304 303
305 if (num >= 32) 304 set_bit(num, &cfg->p_region_index[0]);
306 set_bit(num - 32, &cfg->p_region_index2);
307 else
308 set_bit(num, &cfg->p_region_index1);
309} 305}
310 306
311static inline void fimc_is_set_param_ctrl_cmd(struct fimc_is *is, int cmd) 307static inline void fimc_is_set_param_ctrl_cmd(struct fimc_is *is, int cmd)
diff --git a/drivers/media/platform/exynos4-is/fimc-isp.c b/drivers/media/platform/exynos4-is/fimc-isp.c
index 7ede30b5910f..cf520a7d7f71 100644
--- a/drivers/media/platform/exynos4-is/fimc-isp.c
+++ b/drivers/media/platform/exynos4-is/fimc-isp.c
@@ -30,8 +30,8 @@
30#include "fimc-is-regs.h" 30#include "fimc-is-regs.h"
31#include "fimc-is.h" 31#include "fimc-is.h"
32 32
33static int debug; 33int fimc_isp_debug;
34module_param_named(debug_isp, debug, int, S_IRUGO | S_IWUSR); 34module_param_named(debug_isp, fimc_isp_debug, int, S_IRUGO | S_IWUSR);
35 35
36static const struct fimc_fmt fimc_isp_formats[FIMC_ISP_NUM_FORMATS] = { 36static const struct fimc_fmt fimc_isp_formats[FIMC_ISP_NUM_FORMATS] = {
37 { 37 {
@@ -128,57 +128,70 @@ static int fimc_isp_subdev_get_fmt(struct v4l2_subdev *sd,
128 struct v4l2_subdev_format *fmt) 128 struct v4l2_subdev_format *fmt)
129{ 129{
130 struct fimc_isp *isp = v4l2_get_subdevdata(sd); 130 struct fimc_isp *isp = v4l2_get_subdevdata(sd);
131 struct fimc_is *is = fimc_isp_to_is(isp);
132 struct v4l2_mbus_framefmt *mf = &fmt->format; 131 struct v4l2_mbus_framefmt *mf = &fmt->format;
133 struct v4l2_mbus_framefmt cur_fmt;
134 132
135 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { 133 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
136 mf = v4l2_subdev_get_try_format(fh, fmt->pad); 134 *mf = *v4l2_subdev_get_try_format(fh, fmt->pad);
137 fmt->format = *mf;
138 return 0; 135 return 0;
139 } 136 }
140 137
141 mf->colorspace = V4L2_COLORSPACE_SRGB; 138 mf->colorspace = V4L2_COLORSPACE_SRGB;
142 139
143 mutex_lock(&isp->subdev_lock); 140 mutex_lock(&isp->subdev_lock);
144 __is_get_frame_size(is, &cur_fmt);
145 141
146 if (fmt->pad == FIMC_ISP_SD_PAD_SINK) { 142 if (fmt->pad == FIMC_ISP_SD_PAD_SINK) {
147 /* full camera input frame size */ 143 /* ISP OTF input image format */
148 mf->width = cur_fmt.width + FIMC_ISP_CAC_MARGIN_WIDTH; 144 *mf = isp->sink_fmt;
149 mf->height = cur_fmt.height + FIMC_ISP_CAC_MARGIN_HEIGHT;
150 mf->code = V4L2_MBUS_FMT_SGRBG10_1X10;
151 } else { 145 } else {
152 /* crop size */ 146 /* ISP OTF output image format */
153 mf->width = cur_fmt.width; 147 *mf = isp->src_fmt;
154 mf->height = cur_fmt.height; 148
155 mf->code = V4L2_MBUS_FMT_YUV10_1X30; 149 if (fmt->pad == FIMC_ISP_SD_PAD_SRC_FIFO) {
150 mf->colorspace = V4L2_COLORSPACE_JPEG;
151 mf->code = V4L2_MBUS_FMT_YUV10_1X30;
152 }
156 } 153 }
157 154
158 mutex_unlock(&isp->subdev_lock); 155 mutex_unlock(&isp->subdev_lock);
159 156
160 v4l2_dbg(1, debug, sd, "%s: pad%d: fmt: 0x%x, %dx%d\n", 157 isp_dbg(1, sd, "%s: pad%d: fmt: 0x%x, %dx%d\n", __func__,
161 __func__, fmt->pad, mf->code, mf->width, mf->height); 158 fmt->pad, mf->code, mf->width, mf->height);
162 159
163 return 0; 160 return 0;
164} 161}
165 162
166static void __isp_subdev_try_format(struct fimc_isp *isp, 163static void __isp_subdev_try_format(struct fimc_isp *isp,
167 struct v4l2_subdev_format *fmt) 164 struct v4l2_subdev_fh *fh,
165 struct v4l2_subdev_format *fmt)
168{ 166{
169 struct v4l2_mbus_framefmt *mf = &fmt->format; 167 struct v4l2_mbus_framefmt *mf = &fmt->format;
168 struct v4l2_mbus_framefmt *format;
169
170 mf->colorspace = V4L2_COLORSPACE_SRGB;
170 171
171 if (fmt->pad == FIMC_ISP_SD_PAD_SINK) { 172 if (fmt->pad == FIMC_ISP_SD_PAD_SINK) {
172 v4l_bound_align_image(&mf->width, FIMC_ISP_SINK_WIDTH_MIN, 173 v4l_bound_align_image(&mf->width, FIMC_ISP_SINK_WIDTH_MIN,
173 FIMC_ISP_SINK_WIDTH_MAX, 0, 174 FIMC_ISP_SINK_WIDTH_MAX, 0,
174 &mf->height, FIMC_ISP_SINK_HEIGHT_MIN, 175 &mf->height, FIMC_ISP_SINK_HEIGHT_MIN,
175 FIMC_ISP_SINK_HEIGHT_MAX, 0, 0); 176 FIMC_ISP_SINK_HEIGHT_MAX, 0, 0);
176 isp->subdev_fmt = *mf; 177 mf->code = V4L2_MBUS_FMT_SGRBG10_1X10;
177 } else { 178 } else {
179 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY)
180 format = v4l2_subdev_get_try_format(fh,
181 FIMC_ISP_SD_PAD_SINK);
182 else
183 format = &isp->sink_fmt;
184
178 /* Allow changing format only on sink pad */ 185 /* Allow changing format only on sink pad */
179 mf->width = isp->subdev_fmt.width - FIMC_ISP_CAC_MARGIN_WIDTH; 186 mf->width = format->width - FIMC_ISP_CAC_MARGIN_WIDTH;
180 mf->height = isp->subdev_fmt.height - FIMC_ISP_CAC_MARGIN_HEIGHT; 187 mf->height = format->height - FIMC_ISP_CAC_MARGIN_HEIGHT;
181 mf->code = isp->subdev_fmt.code; 188
189 if (fmt->pad == FIMC_ISP_SD_PAD_SRC_FIFO) {
190 mf->code = V4L2_MBUS_FMT_YUV10_1X30;
191 mf->colorspace = V4L2_COLORSPACE_JPEG;
192 } else {
193 mf->code = format->code;
194 }
182 } 195 }
183} 196}
184 197
@@ -191,27 +204,50 @@ static int fimc_isp_subdev_set_fmt(struct v4l2_subdev *sd,
191 struct v4l2_mbus_framefmt *mf = &fmt->format; 204 struct v4l2_mbus_framefmt *mf = &fmt->format;
192 int ret = 0; 205 int ret = 0;
193 206
194 v4l2_dbg(1, debug, sd, "%s: pad%d: code: 0x%x, %dx%d\n", 207 isp_dbg(1, sd, "%s: pad%d: code: 0x%x, %dx%d\n",
195 __func__, fmt->pad, mf->code, mf->width, mf->height); 208 __func__, fmt->pad, mf->code, mf->width, mf->height);
196 209
197 mf->colorspace = V4L2_COLORSPACE_SRGB;
198
199 mutex_lock(&isp->subdev_lock); 210 mutex_lock(&isp->subdev_lock);
200 __isp_subdev_try_format(isp, fmt); 211 __isp_subdev_try_format(isp, fh, fmt);
201 212
202 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { 213 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
203 mf = v4l2_subdev_get_try_format(fh, fmt->pad); 214 mf = v4l2_subdev_get_try_format(fh, fmt->pad);
204 *mf = fmt->format; 215 *mf = fmt->format;
205 mutex_unlock(&isp->subdev_lock); 216
206 return 0; 217 /* Propagate format to the source pads */
218 if (fmt->pad == FIMC_ISP_SD_PAD_SINK) {
219 struct v4l2_subdev_format format = *fmt;
220 unsigned int pad;
221
222 for (pad = FIMC_ISP_SD_PAD_SRC_FIFO;
223 pad < FIMC_ISP_SD_PADS_NUM; pad++) {
224 format.pad = pad;
225 __isp_subdev_try_format(isp, fh, &format);
226 mf = v4l2_subdev_get_try_format(fh, pad);
227 *mf = format.format;
228 }
229 }
230 } else {
231 if (sd->entity.stream_count == 0) {
232 if (fmt->pad == FIMC_ISP_SD_PAD_SINK) {
233 struct v4l2_subdev_format format = *fmt;
234
235 isp->sink_fmt = *mf;
236
237 format.pad = FIMC_ISP_SD_PAD_SRC_DMA;
238 __isp_subdev_try_format(isp, fh, &format);
239
240 isp->src_fmt = format.format;
241 __is_set_frame_size(is, &isp->src_fmt);
242 } else {
243 isp->src_fmt = *mf;
244 }
245 } else {
246 ret = -EBUSY;
247 }
207 } 248 }
208 249
209 if (sd->entity.stream_count == 0)
210 __is_set_frame_size(is, mf);
211 else
212 ret = -EBUSY;
213 mutex_unlock(&isp->subdev_lock); 250 mutex_unlock(&isp->subdev_lock);
214
215 return ret; 251 return ret;
216} 252}
217 253
@@ -221,7 +257,7 @@ static int fimc_isp_subdev_s_stream(struct v4l2_subdev *sd, int on)
221 struct fimc_is *is = fimc_isp_to_is(isp); 257 struct fimc_is *is = fimc_isp_to_is(isp);
222 int ret; 258 int ret;
223 259
224 v4l2_dbg(1, debug, sd, "%s: on: %d\n", __func__, on); 260 isp_dbg(1, sd, "%s: on: %d\n", __func__, on);
225 261
226 if (!test_bit(IS_ST_INIT_DONE, &is->state)) 262 if (!test_bit(IS_ST_INIT_DONE, &is->state))
227 return -EBUSY; 263 return -EBUSY;
@@ -235,8 +271,8 @@ static int fimc_isp_subdev_s_stream(struct v4l2_subdev *sd, int on)
235 return ret; 271 return ret;
236 } 272 }
237 273
238 v4l2_dbg(1, debug, sd, "changing mode to %d\n", 274 isp_dbg(1, sd, "changing mode to %d\n", is->config_index);
239 is->config_index); 275
240 ret = fimc_is_itf_mode_change(is); 276 ret = fimc_is_itf_mode_change(is);
241 if (ret) 277 if (ret)
242 return -EINVAL; 278 return -EINVAL;
@@ -317,8 +353,8 @@ static int fimc_isp_subdev_s_power(struct v4l2_subdev *sd, int on)
317 clear_bit(IS_ST_PWR_ON, &is->state); 353 clear_bit(IS_ST_PWR_ON, &is->state);
318 clear_bit(IS_ST_INIT_DONE, &is->state); 354 clear_bit(IS_ST_INIT_DONE, &is->state);
319 is->state = 0; 355 is->state = 0;
320 is->config[is->config_index].p_region_index1 = 0; 356 is->config[is->config_index].p_region_index[0] = 0;
321 is->config[is->config_index].p_region_index2 = 0; 357 is->config[is->config_index].p_region_index[1] = 0;
322 set_bit(IS_ST_IDLE, &is->state); 358 set_bit(IS_ST_IDLE, &is->state);
323 wmb(); 359 wmb();
324 } 360 }
@@ -609,6 +645,22 @@ static const struct v4l2_ctrl_ops fimc_isp_ctrl_ops = {
609 .s_ctrl = fimc_is_s_ctrl, 645 .s_ctrl = fimc_is_s_ctrl,
610}; 646};
611 647
648static void __isp_subdev_set_default_format(struct fimc_isp *isp)
649{
650 struct fimc_is *is = fimc_isp_to_is(isp);
651
652 isp->sink_fmt.width = DEFAULT_PREVIEW_STILL_WIDTH +
653 FIMC_ISP_CAC_MARGIN_WIDTH;
654 isp->sink_fmt.height = DEFAULT_PREVIEW_STILL_HEIGHT +
655 FIMC_ISP_CAC_MARGIN_HEIGHT;
656 isp->sink_fmt.code = V4L2_MBUS_FMT_SGRBG10_1X10;
657
658 isp->src_fmt.width = DEFAULT_PREVIEW_STILL_WIDTH;
659 isp->src_fmt.height = DEFAULT_PREVIEW_STILL_HEIGHT;
660 isp->src_fmt.code = V4L2_MBUS_FMT_SGRBG10_1X10;
661 __is_set_frame_size(is, &isp->src_fmt);
662}
663
612int fimc_isp_subdev_create(struct fimc_isp *isp) 664int fimc_isp_subdev_create(struct fimc_isp *isp)
613{ 665{
614 const struct v4l2_ctrl_ops *ops = &fimc_isp_ctrl_ops; 666 const struct v4l2_ctrl_ops *ops = &fimc_isp_ctrl_ops;
@@ -689,6 +741,8 @@ int fimc_isp_subdev_create(struct fimc_isp *isp)
689 sd->entity.ops = &fimc_is_subdev_media_ops; 741 sd->entity.ops = &fimc_is_subdev_media_ops;
690 v4l2_set_subdevdata(sd, isp); 742 v4l2_set_subdevdata(sd, isp);
691 743
744 __isp_subdev_set_default_format(isp);
745
692 return 0; 746 return 0;
693} 747}
694 748
diff --git a/drivers/media/platform/exynos4-is/fimc-isp.h b/drivers/media/platform/exynos4-is/fimc-isp.h
index 800aba7ab4a7..03bf95ab017b 100644
--- a/drivers/media/platform/exynos4-is/fimc-isp.h
+++ b/drivers/media/platform/exynos4-is/fimc-isp.h
@@ -26,6 +26,11 @@
26#include <media/v4l2-mediabus.h> 26#include <media/v4l2-mediabus.h>
27#include <media/s5p_fimc.h> 27#include <media/s5p_fimc.h>
28 28
29extern int fimc_isp_debug;
30
31#define isp_dbg(level, dev, fmt, arg...) \
32 v4l2_dbg(level, fimc_isp_debug, dev, fmt, ## arg)
33
29/* FIXME: revisit these constraints */ 34/* FIXME: revisit these constraints */
30#define FIMC_ISP_SINK_WIDTH_MIN (16 + 8) 35#define FIMC_ISP_SINK_WIDTH_MIN (16 + 8)
31#define FIMC_ISP_SINK_HEIGHT_MIN (12 + 8) 36#define FIMC_ISP_SINK_HEIGHT_MIN (12 + 8)
@@ -118,7 +123,6 @@ struct fimc_is_video {
118 unsigned int frame_count; 123 unsigned int frame_count;
119 unsigned int reqbufs_count; 124 unsigned int reqbufs_count;
120 int streaming; 125 int streaming;
121 unsigned long payload[FIMC_ISP_MAX_PLANES];
122 const struct fimc_fmt *format; 126 const struct fimc_fmt *format;
123}; 127};
124 128
@@ -128,15 +132,9 @@ struct fimc_is_video {
128 * @alloc_ctx: videobuf2 memory allocator context 132 * @alloc_ctx: videobuf2 memory allocator context
129 * @subdev: ISP v4l2_subdev 133 * @subdev: ISP v4l2_subdev
130 * @subdev_pads: the ISP subdev media pads 134 * @subdev_pads: the ISP subdev media pads
131 * @ctrl_handler: v4l2 controls handler
132 * @test_pattern: test pattern controls 135 * @test_pattern: test pattern controls
133 * @pipeline: video capture pipeline data structure 136 * @ctrls: v4l2 controls structure
134 * @video_lock: mutex serializing video device and the subdev operations 137 * @video_lock: mutex serializing video device and the subdev operations
135 * @fmt: pointer to color format description structure
136 * @payload: image size in bytes (w x h x bpp)
137 * @inp_frame: camera input frame structure
138 * @out_frame: DMA output frame structure
139 * @source_subdev_grp_id: group id of remote source subdev
140 * @cac_margin_x: horizontal CAC margin in pixels 138 * @cac_margin_x: horizontal CAC margin in pixels
141 * @cac_margin_y: vertical CAC margin in pixels 139 * @cac_margin_y: vertical CAC margin in pixels
142 * @state: driver state flags 140 * @state: driver state flags
@@ -147,17 +145,14 @@ struct fimc_isp {
147 struct vb2_alloc_ctx *alloc_ctx; 145 struct vb2_alloc_ctx *alloc_ctx;
148 struct v4l2_subdev subdev; 146 struct v4l2_subdev subdev;
149 struct media_pad subdev_pads[FIMC_ISP_SD_PADS_NUM]; 147 struct media_pad subdev_pads[FIMC_ISP_SD_PADS_NUM];
150 struct v4l2_mbus_framefmt subdev_fmt; 148 struct v4l2_mbus_framefmt src_fmt;
149 struct v4l2_mbus_framefmt sink_fmt;
151 struct v4l2_ctrl *test_pattern; 150 struct v4l2_ctrl *test_pattern;
152 struct fimc_isp_ctrls ctrls; 151 struct fimc_isp_ctrls ctrls;
153 152
154 struct mutex video_lock; 153 struct mutex video_lock;
155 struct mutex subdev_lock; 154 struct mutex subdev_lock;
156 155
157 struct fimc_isp_frame inp_frame;
158 struct fimc_isp_frame out_frame;
159 unsigned int source_subdev_grp_id;
160
161 unsigned int cac_margin_x; 156 unsigned int cac_margin_x;
162 unsigned int cac_margin_y; 157 unsigned int cac_margin_y;
163 158
diff --git a/drivers/media/platform/exynos4-is/fimc-lite-reg.c b/drivers/media/platform/exynos4-is/fimc-lite-reg.c
index 8cc0d39a2fea..72a343e3b5e8 100644
--- a/drivers/media/platform/exynos4-is/fimc-lite-reg.c
+++ b/drivers/media/platform/exynos4-is/fimc-lite-reg.c
@@ -2,15 +2,16 @@
2 * Register interface file for EXYNOS FIMC-LITE (camera interface) driver 2 * Register interface file for EXYNOS FIMC-LITE (camera interface) driver
3 * 3 *
4 * Copyright (C) 2012 Samsung Electronics Co., Ltd. 4 * Copyright (C) 2012 Samsung Electronics Co., Ltd.
5 * Sylwester Nawrocki <s.nawrocki@samsung.com> 5 * Author: Sylwester Nawrocki <s.nawrocki@samsung.com>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as 8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation. 9 * published by the Free Software Foundation.
10*/ 10*/
11 11
12#include <linux/io.h> 12#include <linux/bitops.h>
13#include <linux/delay.h> 13#include <linux/delay.h>
14#include <linux/io.h>
14#include <media/s5p_fimc.h> 15#include <media/s5p_fimc.h>
15 16
16#include "fimc-lite-reg.h" 17#include "fimc-lite-reg.h"
@@ -68,7 +69,8 @@ void flite_hw_set_interrupt_mask(struct fimc_lite *dev)
68 if (atomic_read(&dev->out_path) == FIMC_IO_DMA) { 69 if (atomic_read(&dev->out_path) == FIMC_IO_DMA) {
69 intsrc = FLITE_REG_CIGCTRL_IRQ_OVFEN | 70 intsrc = FLITE_REG_CIGCTRL_IRQ_OVFEN |
70 FLITE_REG_CIGCTRL_IRQ_LASTEN | 71 FLITE_REG_CIGCTRL_IRQ_LASTEN |
71 FLITE_REG_CIGCTRL_IRQ_STARTEN; 72 FLITE_REG_CIGCTRL_IRQ_STARTEN |
73 FLITE_REG_CIGCTRL_IRQ_ENDEN;
72 } else { 74 } else {
73 /* An output to the FIMC-IS */ 75 /* An output to the FIMC-IS */
74 intsrc = FLITE_REG_CIGCTRL_IRQ_OVFEN | 76 intsrc = FLITE_REG_CIGCTRL_IRQ_OVFEN |
@@ -137,7 +139,7 @@ void flite_hw_set_source_format(struct fimc_lite *dev, struct flite_frame *f)
137 } 139 }
138 140
139 if (i == 0 && src_pixfmt_map[i][0] != pixelcode) { 141 if (i == 0 && src_pixfmt_map[i][0] != pixelcode) {
140 v4l2_err(&dev->vfd, 142 v4l2_err(&dev->ve.vdev,
141 "Unsupported pixel code, falling back to %#08x\n", 143 "Unsupported pixel code, falling back to %#08x\n",
142 src_pixfmt_map[i][0]); 144 src_pixfmt_map[i][0]);
143 } 145 }
@@ -215,6 +217,18 @@ void flite_hw_set_camera_bus(struct fimc_lite *dev,
215 flite_hw_set_camera_port(dev, si->mux_id); 217 flite_hw_set_camera_port(dev, si->mux_id);
216} 218}
217 219
220static void flite_hw_set_pack12(struct fimc_lite *dev, int on)
221{
222 u32 cfg = readl(dev->regs + FLITE_REG_CIODMAFMT);
223
224 cfg &= ~FLITE_REG_CIODMAFMT_PACK12;
225
226 if (on)
227 cfg |= FLITE_REG_CIODMAFMT_PACK12;
228
229 writel(cfg, dev->regs + FLITE_REG_CIODMAFMT);
230}
231
218static void flite_hw_set_out_order(struct fimc_lite *dev, struct flite_frame *f) 232static void flite_hw_set_out_order(struct fimc_lite *dev, struct flite_frame *f)
219{ 233{
220 static const u32 pixcode[4][2] = { 234 static const u32 pixcode[4][2] = {
@@ -250,6 +264,38 @@ void flite_hw_set_dma_window(struct fimc_lite *dev, struct flite_frame *f)
250 writel(cfg, dev->regs + FLITE_REG_CIOOFF); 264 writel(cfg, dev->regs + FLITE_REG_CIOOFF);
251} 265}
252 266
267void flite_hw_set_dma_buffer(struct fimc_lite *dev, struct flite_buffer *buf)
268{
269 unsigned int index;
270 u32 cfg;
271
272 if (dev->dd->max_dma_bufs == 1)
273 index = 0;
274 else
275 index = buf->index;
276
277 if (index == 0)
278 writel(buf->paddr, dev->regs + FLITE_REG_CIOSA);
279 else
280 writel(buf->paddr, dev->regs + FLITE_REG_CIOSAN(index - 1));
281
282 cfg = readl(dev->regs + FLITE_REG_CIFCNTSEQ);
283 cfg |= BIT(index);
284 writel(cfg, dev->regs + FLITE_REG_CIFCNTSEQ);
285}
286
287void flite_hw_mask_dma_buffer(struct fimc_lite *dev, u32 index)
288{
289 u32 cfg;
290
291 if (dev->dd->max_dma_bufs == 1)
292 index = 0;
293
294 cfg = readl(dev->regs + FLITE_REG_CIFCNTSEQ);
295 cfg &= ~BIT(index);
296 writel(cfg, dev->regs + FLITE_REG_CIFCNTSEQ);
297}
298
253/* Enable/disable output DMA, set output pixel size and offsets (composition) */ 299/* Enable/disable output DMA, set output pixel size and offsets (composition) */
254void flite_hw_set_output_dma(struct fimc_lite *dev, struct flite_frame *f, 300void flite_hw_set_output_dma(struct fimc_lite *dev, struct flite_frame *f,
255 bool enable) 301 bool enable)
@@ -267,6 +313,7 @@ void flite_hw_set_output_dma(struct fimc_lite *dev, struct flite_frame *f,
267 313
268 flite_hw_set_out_order(dev, f); 314 flite_hw_set_out_order(dev, f);
269 flite_hw_set_dma_window(dev, f); 315 flite_hw_set_dma_window(dev, f);
316 flite_hw_set_pack12(dev, 0);
270} 317}
271 318
272void flite_hw_dump_regs(struct fimc_lite *dev, const char *label) 319void flite_hw_dump_regs(struct fimc_lite *dev, const char *label)
diff --git a/drivers/media/platform/exynos4-is/fimc-lite-reg.h b/drivers/media/platform/exynos4-is/fimc-lite-reg.h
index 390383941c19..10a7d7bbcc27 100644
--- a/drivers/media/platform/exynos4-is/fimc-lite-reg.h
+++ b/drivers/media/platform/exynos4-is/fimc-lite-reg.h
@@ -120,6 +120,9 @@
120/* b0: 1 - camera B, 0 - camera A */ 120/* b0: 1 - camera B, 0 - camera A */
121#define FLITE_REG_CIGENERAL_CAM_B (1 << 0) 121#define FLITE_REG_CIGENERAL_CAM_B (1 << 0)
122 122
123#define FLITE_REG_CIFCNTSEQ 0x100
124#define FLITE_REG_CIOSAN(x) (0x200 + (4 * (x)))
125
123/* ---------------------------------------------------------------------------- 126/* ----------------------------------------------------------------------------
124 * Function declarations 127 * Function declarations
125 */ 128 */
@@ -142,9 +145,12 @@ void flite_hw_set_output_dma(struct fimc_lite *dev, struct flite_frame *f,
142void flite_hw_set_dma_window(struct fimc_lite *dev, struct flite_frame *f); 145void flite_hw_set_dma_window(struct fimc_lite *dev, struct flite_frame *f);
143void flite_hw_set_test_pattern(struct fimc_lite *dev, bool on); 146void flite_hw_set_test_pattern(struct fimc_lite *dev, bool on);
144void flite_hw_dump_regs(struct fimc_lite *dev, const char *label); 147void flite_hw_dump_regs(struct fimc_lite *dev, const char *label);
148void flite_hw_set_dma_buffer(struct fimc_lite *dev, struct flite_buffer *buf);
149void flite_hw_mask_dma_buffer(struct fimc_lite *dev, u32 index);
145 150
146static inline void flite_hw_set_output_addr(struct fimc_lite *dev, u32 paddr) 151static inline void flite_hw_set_dma_buf_mask(struct fimc_lite *dev, u32 mask)
147{ 152{
148 writel(paddr, dev->regs + FLITE_REG_CIOSA); 153 writel(mask, dev->regs + FLITE_REG_CIFCNTSEQ);
149} 154}
155
150#endif /* FIMC_LITE_REG_H */ 156#endif /* FIMC_LITE_REG_H */
diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
index 14bb7bc8adbe..08fbfedea90f 100644
--- a/drivers/media/platform/exynos4-is/fimc-lite.c
+++ b/drivers/media/platform/exynos4-is/fimc-lite.c
@@ -1,8 +1,8 @@
1/* 1/*
2 * Samsung EXYNOS FIMC-LITE (camera host interface) driver 2 * Samsung EXYNOS FIMC-LITE (camera host interface) driver
3* 3*
4 * Copyright (C) 2012 Samsung Electronics Co., Ltd. 4 * Copyright (C) 2012 - 2013 Samsung Electronics Co., Ltd.
5 * Sylwester Nawrocki <s.nawrocki@samsung.com> 5 * Author: Sylwester Nawrocki <s.nawrocki@samsung.com>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as 8 * it under the terms of the GNU General Public License version 2 as
@@ -32,6 +32,7 @@
32#include <media/videobuf2-dma-contig.h> 32#include <media/videobuf2-dma-contig.h>
33#include <media/s5p_fimc.h> 33#include <media/s5p_fimc.h>
34 34
35#include "common.h"
35#include "fimc-core.h" 36#include "fimc-core.h"
36#include "fimc-lite.h" 37#include "fimc-lite.h"
37#include "fimc-lite-reg.h" 38#include "fimc-lite-reg.h"
@@ -43,6 +44,7 @@ static const struct fimc_fmt fimc_lite_formats[] = {
43 { 44 {
44 .name = "YUV 4:2:2 packed, YCbYCr", 45 .name = "YUV 4:2:2 packed, YCbYCr",
45 .fourcc = V4L2_PIX_FMT_YUYV, 46 .fourcc = V4L2_PIX_FMT_YUYV,
47 .colorspace = V4L2_COLORSPACE_JPEG,
46 .depth = { 16 }, 48 .depth = { 16 },
47 .color = FIMC_FMT_YCBYCR422, 49 .color = FIMC_FMT_YCBYCR422,
48 .memplanes = 1, 50 .memplanes = 1,
@@ -51,6 +53,7 @@ static const struct fimc_fmt fimc_lite_formats[] = {
51 }, { 53 }, {
52 .name = "YUV 4:2:2 packed, CbYCrY", 54 .name = "YUV 4:2:2 packed, CbYCrY",
53 .fourcc = V4L2_PIX_FMT_UYVY, 55 .fourcc = V4L2_PIX_FMT_UYVY,
56 .colorspace = V4L2_COLORSPACE_JPEG,
54 .depth = { 16 }, 57 .depth = { 16 },
55 .color = FIMC_FMT_CBYCRY422, 58 .color = FIMC_FMT_CBYCRY422,
56 .memplanes = 1, 59 .memplanes = 1,
@@ -59,6 +62,7 @@ static const struct fimc_fmt fimc_lite_formats[] = {
59 }, { 62 }, {
60 .name = "YUV 4:2:2 packed, CrYCbY", 63 .name = "YUV 4:2:2 packed, CrYCbY",
61 .fourcc = V4L2_PIX_FMT_VYUY, 64 .fourcc = V4L2_PIX_FMT_VYUY,
65 .colorspace = V4L2_COLORSPACE_JPEG,
62 .depth = { 16 }, 66 .depth = { 16 },
63 .color = FIMC_FMT_CRYCBY422, 67 .color = FIMC_FMT_CRYCBY422,
64 .memplanes = 1, 68 .memplanes = 1,
@@ -67,6 +71,7 @@ static const struct fimc_fmt fimc_lite_formats[] = {
67 }, { 71 }, {
68 .name = "YUV 4:2:2 packed, YCrYCb", 72 .name = "YUV 4:2:2 packed, YCrYCb",
69 .fourcc = V4L2_PIX_FMT_YVYU, 73 .fourcc = V4L2_PIX_FMT_YVYU,
74 .colorspace = V4L2_COLORSPACE_JPEG,
70 .depth = { 16 }, 75 .depth = { 16 },
71 .color = FIMC_FMT_YCRYCB422, 76 .color = FIMC_FMT_YCRYCB422,
72 .memplanes = 1, 77 .memplanes = 1,
@@ -75,6 +80,7 @@ static const struct fimc_fmt fimc_lite_formats[] = {
75 }, { 80 }, {
76 .name = "RAW8 (GRBG)", 81 .name = "RAW8 (GRBG)",
77 .fourcc = V4L2_PIX_FMT_SGRBG8, 82 .fourcc = V4L2_PIX_FMT_SGRBG8,
83 .colorspace = V4L2_COLORSPACE_SRGB,
78 .depth = { 8 }, 84 .depth = { 8 },
79 .color = FIMC_FMT_RAW8, 85 .color = FIMC_FMT_RAW8,
80 .memplanes = 1, 86 .memplanes = 1,
@@ -83,6 +89,7 @@ static const struct fimc_fmt fimc_lite_formats[] = {
83 }, { 89 }, {
84 .name = "RAW10 (GRBG)", 90 .name = "RAW10 (GRBG)",
85 .fourcc = V4L2_PIX_FMT_SGRBG10, 91 .fourcc = V4L2_PIX_FMT_SGRBG10,
92 .colorspace = V4L2_COLORSPACE_SRGB,
86 .depth = { 10 }, 93 .depth = { 10 },
87 .color = FIMC_FMT_RAW10, 94 .color = FIMC_FMT_RAW10,
88 .memplanes = 1, 95 .memplanes = 1,
@@ -91,6 +98,7 @@ static const struct fimc_fmt fimc_lite_formats[] = {
91 }, { 98 }, {
92 .name = "RAW12 (GRBG)", 99 .name = "RAW12 (GRBG)",
93 .fourcc = V4L2_PIX_FMT_SGRBG12, 100 .fourcc = V4L2_PIX_FMT_SGRBG12,
101 .colorspace = V4L2_COLORSPACE_SRGB,
94 .depth = { 12 }, 102 .depth = { 12 },
95 .color = FIMC_FMT_RAW12, 103 .color = FIMC_FMT_RAW12,
96 .memplanes = 1, 104 .memplanes = 1,
@@ -131,30 +139,6 @@ static const struct fimc_fmt *fimc_lite_find_format(const u32 *pixelformat,
131 return def_fmt; 139 return def_fmt;
132} 140}
133 141
134/* Called with the media graph mutex held or @me stream_count > 0. */
135static struct v4l2_subdev *__find_remote_sensor(struct media_entity *me)
136{
137 struct media_pad *pad = &me->pads[0];
138 struct v4l2_subdev *sd;
139
140 while (pad->flags & MEDIA_PAD_FL_SINK) {
141 /* source pad */
142 pad = media_entity_remote_source(pad);
143 if (pad == NULL ||
144 media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
145 break;
146
147 sd = media_entity_to_v4l2_subdev(pad->entity);
148
149 if (sd->grp_id == GRP_ID_FIMC_IS_SENSOR ||
150 sd->grp_id == GRP_ID_SENSOR)
151 return sd;
152 /* sink pad */
153 pad = &sd->entity.pads[0];
154 }
155 return NULL;
156}
157
158static int fimc_lite_hw_init(struct fimc_lite *fimc, bool isp_output) 142static int fimc_lite_hw_init(struct fimc_lite *fimc, bool isp_output)
159{ 143{
160 struct fimc_source_info *si; 144 struct fimc_source_info *si;
@@ -176,6 +160,7 @@ static int fimc_lite_hw_init(struct fimc_lite *fimc, bool isp_output)
176 flite_hw_set_camera_bus(fimc, si); 160 flite_hw_set_camera_bus(fimc, si);
177 flite_hw_set_source_format(fimc, &fimc->inp_frame); 161 flite_hw_set_source_format(fimc, &fimc->inp_frame);
178 flite_hw_set_window_offset(fimc, &fimc->inp_frame); 162 flite_hw_set_window_offset(fimc, &fimc->inp_frame);
163 flite_hw_set_dma_buf_mask(fimc, 0);
179 flite_hw_set_output_dma(fimc, &fimc->out_frame, !isp_output); 164 flite_hw_set_output_dma(fimc, &fimc->out_frame, !isp_output);
180 flite_hw_set_interrupt_mask(fimc); 165 flite_hw_set_interrupt_mask(fimc);
181 flite_hw_set_test_pattern(fimc, fimc->test_pattern->val); 166 flite_hw_set_test_pattern(fimc, fimc->test_pattern->val);
@@ -233,7 +218,7 @@ static int fimc_lite_reinit(struct fimc_lite *fimc, bool suspend)
233 if (!streaming) 218 if (!streaming)
234 return 0; 219 return 0;
235 220
236 return fimc_pipeline_call(fimc, set_stream, &fimc->pipeline, 0); 221 return fimc_pipeline_call(&fimc->ve, set_stream, 0);
237} 222}
238 223
239static int fimc_lite_stop_capture(struct fimc_lite *fimc, bool suspend) 224static int fimc_lite_stop_capture(struct fimc_lite *fimc, bool suspend)
@@ -299,19 +284,23 @@ static irqreturn_t flite_irq_handler(int irq, void *priv)
299 284
300 if ((intsrc & FLITE_REG_CISTATUS_IRQ_SRC_FRMSTART) && 285 if ((intsrc & FLITE_REG_CISTATUS_IRQ_SRC_FRMSTART) &&
301 test_bit(ST_FLITE_RUN, &fimc->state) && 286 test_bit(ST_FLITE_RUN, &fimc->state) &&
302 !list_empty(&fimc->active_buf_q) &&
303 !list_empty(&fimc->pending_buf_q)) { 287 !list_empty(&fimc->pending_buf_q)) {
288 vbuf = fimc_lite_pending_queue_pop(fimc);
289 flite_hw_set_dma_buffer(fimc, vbuf);
290 fimc_lite_active_queue_add(fimc, vbuf);
291 }
292
293 if ((intsrc & FLITE_REG_CISTATUS_IRQ_SRC_FRMEND) &&
294 test_bit(ST_FLITE_RUN, &fimc->state) &&
295 !list_empty(&fimc->active_buf_q)) {
304 vbuf = fimc_lite_active_queue_pop(fimc); 296 vbuf = fimc_lite_active_queue_pop(fimc);
305 ktime_get_ts(&ts); 297 ktime_get_ts(&ts);
306 tv = &vbuf->vb.v4l2_buf.timestamp; 298 tv = &vbuf->vb.v4l2_buf.timestamp;
307 tv->tv_sec = ts.tv_sec; 299 tv->tv_sec = ts.tv_sec;
308 tv->tv_usec = ts.tv_nsec / NSEC_PER_USEC; 300 tv->tv_usec = ts.tv_nsec / NSEC_PER_USEC;
309 vbuf->vb.v4l2_buf.sequence = fimc->frame_count++; 301 vbuf->vb.v4l2_buf.sequence = fimc->frame_count++;
302 flite_hw_mask_dma_buffer(fimc, vbuf->index);
310 vb2_buffer_done(&vbuf->vb, VB2_BUF_STATE_DONE); 303 vb2_buffer_done(&vbuf->vb, VB2_BUF_STATE_DONE);
311
312 vbuf = fimc_lite_pending_queue_pop(fimc);
313 flite_hw_set_output_addr(fimc, vbuf->paddr);
314 fimc_lite_active_queue_add(fimc, vbuf);
315 } 304 }
316 305
317 if (test_bit(ST_FLITE_CONFIG, &fimc->state)) 306 if (test_bit(ST_FLITE_CONFIG, &fimc->state))
@@ -330,10 +319,16 @@ done:
330static int start_streaming(struct vb2_queue *q, unsigned int count) 319static int start_streaming(struct vb2_queue *q, unsigned int count)
331{ 320{
332 struct fimc_lite *fimc = q->drv_priv; 321 struct fimc_lite *fimc = q->drv_priv;
322 unsigned long flags;
333 int ret; 323 int ret;
334 324
325 spin_lock_irqsave(&fimc->slock, flags);
326
327 fimc->buf_index = 0;
335 fimc->frame_count = 0; 328 fimc->frame_count = 0;
336 329
330 spin_unlock_irqrestore(&fimc->slock, flags);
331
337 ret = fimc_lite_hw_init(fimc, false); 332 ret = fimc_lite_hw_init(fimc, false);
338 if (ret) { 333 if (ret) {
339 fimc_lite_reinit(fimc, false); 334 fimc_lite_reinit(fimc, false);
@@ -347,8 +342,7 @@ static int start_streaming(struct vb2_queue *q, unsigned int count)
347 flite_hw_capture_start(fimc); 342 flite_hw_capture_start(fimc);
348 343
349 if (!test_and_set_bit(ST_SENSOR_STREAM, &fimc->state)) 344 if (!test_and_set_bit(ST_SENSOR_STREAM, &fimc->state))
350 fimc_pipeline_call(fimc, set_stream, 345 fimc_pipeline_call(&fimc->ve, set_stream, 1);
351 &fimc->pipeline, 1);
352 } 346 }
353 if (debug > 0) 347 if (debug > 0)
354 flite_hw_dump_regs(fimc, __func__); 348 flite_hw_dump_regs(fimc, __func__);
@@ -415,7 +409,7 @@ static int buffer_prepare(struct vb2_buffer *vb)
415 unsigned long size = fimc->payload[i]; 409 unsigned long size = fimc->payload[i];
416 410
417 if (vb2_plane_size(vb, i) < size) { 411 if (vb2_plane_size(vb, i) < size) {
418 v4l2_err(&fimc->vfd, 412 v4l2_err(&fimc->ve.vdev,
419 "User buffer too small (%ld < %ld)\n", 413 "User buffer too small (%ld < %ld)\n",
420 vb2_plane_size(vb, i), size); 414 vb2_plane_size(vb, i), size);
421 return -EINVAL; 415 return -EINVAL;
@@ -436,10 +430,14 @@ static void buffer_queue(struct vb2_buffer *vb)
436 spin_lock_irqsave(&fimc->slock, flags); 430 spin_lock_irqsave(&fimc->slock, flags);
437 buf->paddr = vb2_dma_contig_plane_dma_addr(vb, 0); 431 buf->paddr = vb2_dma_contig_plane_dma_addr(vb, 0);
438 432
433 buf->index = fimc->buf_index++;
434 if (fimc->buf_index >= fimc->reqbufs_count)
435 fimc->buf_index = 0;
436
439 if (!test_bit(ST_FLITE_SUSPENDED, &fimc->state) && 437 if (!test_bit(ST_FLITE_SUSPENDED, &fimc->state) &&
440 !test_bit(ST_FLITE_STREAM, &fimc->state) && 438 !test_bit(ST_FLITE_STREAM, &fimc->state) &&
441 list_empty(&fimc->active_buf_q)) { 439 list_empty(&fimc->active_buf_q)) {
442 flite_hw_set_output_addr(fimc, buf->paddr); 440 flite_hw_set_dma_buffer(fimc, buf);
443 fimc_lite_active_queue_add(fimc, buf); 441 fimc_lite_active_queue_add(fimc, buf);
444 } else { 442 } else {
445 fimc_lite_pending_queue_add(fimc, buf); 443 fimc_lite_pending_queue_add(fimc, buf);
@@ -452,8 +450,7 @@ static void buffer_queue(struct vb2_buffer *vb)
452 spin_unlock_irqrestore(&fimc->slock, flags); 450 spin_unlock_irqrestore(&fimc->slock, flags);
453 451
454 if (!test_and_set_bit(ST_SENSOR_STREAM, &fimc->state)) 452 if (!test_and_set_bit(ST_SENSOR_STREAM, &fimc->state))
455 fimc_pipeline_call(fimc, set_stream, 453 fimc_pipeline_call(&fimc->ve, set_stream, 1);
456 &fimc->pipeline, 1);
457 return; 454 return;
458 } 455 }
459 spin_unlock_irqrestore(&fimc->slock, flags); 456 spin_unlock_irqrestore(&fimc->slock, flags);
@@ -481,11 +478,9 @@ static void fimc_lite_clear_event_counters(struct fimc_lite *fimc)
481static int fimc_lite_open(struct file *file) 478static int fimc_lite_open(struct file *file)
482{ 479{
483 struct fimc_lite *fimc = video_drvdata(file); 480 struct fimc_lite *fimc = video_drvdata(file);
484 struct media_entity *me = &fimc->vfd.entity; 481 struct media_entity *me = &fimc->ve.vdev.entity;
485 int ret; 482 int ret;
486 483
487 mutex_lock(&me->parent->graph_mutex);
488
489 mutex_lock(&fimc->lock); 484 mutex_lock(&fimc->lock);
490 if (atomic_read(&fimc->out_path) != FIMC_IO_DMA) { 485 if (atomic_read(&fimc->out_path) != FIMC_IO_DMA) {
491 ret = -EBUSY; 486 ret = -EBUSY;
@@ -505,11 +500,18 @@ static int fimc_lite_open(struct file *file)
505 atomic_read(&fimc->out_path) != FIMC_IO_DMA) 500 atomic_read(&fimc->out_path) != FIMC_IO_DMA)
506 goto unlock; 501 goto unlock;
507 502
508 ret = fimc_pipeline_call(fimc, open, &fimc->pipeline, 503 mutex_lock(&me->parent->graph_mutex);
509 me, true); 504
505 ret = fimc_pipeline_call(&fimc->ve, open, me, true);
506
507 /* Mark video pipeline ending at this video node as in use. */
508 if (ret == 0)
509 me->use_count++;
510
511 mutex_unlock(&me->parent->graph_mutex);
512
510 if (!ret) { 513 if (!ret) {
511 fimc_lite_clear_event_counters(fimc); 514 fimc_lite_clear_event_counters(fimc);
512 fimc->ref_count++;
513 goto unlock; 515 goto unlock;
514 } 516 }
515 517
@@ -519,26 +521,29 @@ err_pm:
519 clear_bit(ST_FLITE_IN_USE, &fimc->state); 521 clear_bit(ST_FLITE_IN_USE, &fimc->state);
520unlock: 522unlock:
521 mutex_unlock(&fimc->lock); 523 mutex_unlock(&fimc->lock);
522 mutex_unlock(&me->parent->graph_mutex);
523 return ret; 524 return ret;
524} 525}
525 526
526static int fimc_lite_release(struct file *file) 527static int fimc_lite_release(struct file *file)
527{ 528{
528 struct fimc_lite *fimc = video_drvdata(file); 529 struct fimc_lite *fimc = video_drvdata(file);
530 struct media_entity *entity = &fimc->ve.vdev.entity;
529 531
530 mutex_lock(&fimc->lock); 532 mutex_lock(&fimc->lock);
531 533
532 if (v4l2_fh_is_singular_file(file) && 534 if (v4l2_fh_is_singular_file(file) &&
533 atomic_read(&fimc->out_path) == FIMC_IO_DMA) { 535 atomic_read(&fimc->out_path) == FIMC_IO_DMA) {
534 if (fimc->streaming) { 536 if (fimc->streaming) {
535 media_entity_pipeline_stop(&fimc->vfd.entity); 537 media_entity_pipeline_stop(entity);
536 fimc->streaming = false; 538 fimc->streaming = false;
537 } 539 }
538 clear_bit(ST_FLITE_IN_USE, &fimc->state);
539 fimc_lite_stop_capture(fimc, false); 540 fimc_lite_stop_capture(fimc, false);
540 fimc_pipeline_call(fimc, close, &fimc->pipeline); 541 fimc_pipeline_call(&fimc->ve, close);
541 fimc->ref_count--; 542 clear_bit(ST_FLITE_IN_USE, &fimc->state);
543
544 mutex_lock(&entity->parent->graph_mutex);
545 entity->use_count--;
546 mutex_unlock(&entity->parent->graph_mutex);
542 } 547 }
543 548
544 vb2_fop_release(file); 549 vb2_fop_release(file);
@@ -562,37 +567,54 @@ static const struct v4l2_file_operations fimc_lite_fops = {
562 * Format and crop negotiation helpers 567 * Format and crop negotiation helpers
563 */ 568 */
564 569
565static const struct fimc_fmt *fimc_lite_try_format(struct fimc_lite *fimc, 570static const struct fimc_fmt *fimc_lite_subdev_try_fmt(struct fimc_lite *fimc,
566 u32 *width, u32 *height, 571 struct v4l2_subdev_fh *fh,
567 u32 *code, u32 *fourcc, int pad) 572 struct v4l2_subdev_format *format)
568{ 573{
569 struct flite_drvdata *dd = fimc->dd; 574 struct flite_drvdata *dd = fimc->dd;
570 const struct fimc_fmt *fmt; 575 struct v4l2_mbus_framefmt *mf = &format->format;
571 unsigned int flags = 0; 576 const struct fimc_fmt *fmt = NULL;
577
578 if (format->pad == FLITE_SD_PAD_SINK) {
579 v4l_bound_align_image(&mf->width, 8, dd->max_width,
580 ffs(dd->out_width_align) - 1,
581 &mf->height, 0, dd->max_height, 0, 0);
582
583 fmt = fimc_lite_find_format(NULL, &mf->code, 0, 0);
584 if (WARN_ON(!fmt))
585 return NULL;
572 586
573 if (pad == FLITE_SD_PAD_SINK) { 587 mf->colorspace = fmt->colorspace;
574 v4l_bound_align_image(width, 8, dd->max_width, 588 mf->code = fmt->mbus_code;
575 ffs(dd->out_width_align) - 1,
576 height, 0, dd->max_height, 0, 0);
577 } else { 589 } else {
578 v4l_bound_align_image(width, 8, fimc->inp_frame.rect.width, 590 struct flite_frame *sink = &fimc->inp_frame;
579 ffs(dd->out_width_align) - 1, 591 struct v4l2_mbus_framefmt *sink_fmt;
580 height, 0, fimc->inp_frame.rect.height, 592 struct v4l2_rect *rect;
581 0, 0);
582 flags = fimc->inp_frame.fmt->flags;
583 }
584 593
585 fmt = fimc_lite_find_format(fourcc, code, flags, 0); 594 if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
586 if (WARN_ON(!fmt)) 595 sink_fmt = v4l2_subdev_get_try_format(fh,
587 return NULL; 596 FLITE_SD_PAD_SINK);
588 597
589 if (code) 598 mf->code = sink_fmt->code;
590 *code = fmt->mbus_code; 599 mf->colorspace = sink_fmt->colorspace;
591 if (fourcc)
592 *fourcc = fmt->fourcc;
593 600
594 v4l2_dbg(1, debug, &fimc->subdev, "code: 0x%x, %dx%d\n", 601 rect = v4l2_subdev_get_try_crop(fh,
595 code ? *code : 0, *width, *height); 602 FLITE_SD_PAD_SINK);
603 } else {
604 mf->code = sink->fmt->mbus_code;
605 mf->colorspace = sink->fmt->colorspace;
606 rect = &sink->rect;
607 }
608
609 /* Allow changing format only on sink pad */
610 mf->width = rect->width;
611 mf->height = rect->height;
612 }
613
614 mf->field = V4L2_FIELD_NONE;
615
616 v4l2_dbg(1, debug, &fimc->subdev, "code: %#x (%d), %dx%d\n",
617 mf->code, mf->colorspace, mf->width, mf->height);
596 618
597 return fmt; 619 return fmt;
598} 620}
@@ -637,13 +659,18 @@ static void fimc_lite_try_compose(struct fimc_lite *fimc, struct v4l2_rect *r)
637/* 659/*
638 * Video node ioctl operations 660 * Video node ioctl operations
639 */ 661 */
640static int fimc_vidioc_querycap_capture(struct file *file, void *priv, 662static int fimc_lite_querycap(struct file *file, void *priv,
641 struct v4l2_capability *cap) 663 struct v4l2_capability *cap)
642{ 664{
665 struct fimc_lite *fimc = video_drvdata(file);
666
643 strlcpy(cap->driver, FIMC_LITE_DRV_NAME, sizeof(cap->driver)); 667 strlcpy(cap->driver, FIMC_LITE_DRV_NAME, sizeof(cap->driver));
644 cap->bus_info[0] = 0; 668 strlcpy(cap->card, FIMC_LITE_DRV_NAME, sizeof(cap->card));
645 cap->card[0] = 0; 669 snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
646 cap->capabilities = V4L2_CAP_STREAMING; 670 dev_name(&fimc->pdev->dev));
671
672 cap->device_caps = V4L2_CAP_STREAMING;
673 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
647 return 0; 674 return 0;
648} 675}
649 676
@@ -679,7 +706,7 @@ static int fimc_lite_g_fmt_mplane(struct file *file, void *fh,
679 pixm->width = frame->f_width; 706 pixm->width = frame->f_width;
680 pixm->height = frame->f_height; 707 pixm->height = frame->f_height;
681 pixm->field = V4L2_FIELD_NONE; 708 pixm->field = V4L2_FIELD_NONE;
682 pixm->colorspace = V4L2_COLORSPACE_JPEG; 709 pixm->colorspace = fmt->colorspace;
683 return 0; 710 return 0;
684} 711}
685 712
@@ -722,7 +749,7 @@ static int fimc_lite_try_fmt(struct fimc_lite *fimc,
722 fmt->depth[0]) / 8; 749 fmt->depth[0]) / 8;
723 pixm->num_planes = fmt->memplanes; 750 pixm->num_planes = fmt->memplanes;
724 pixm->pixelformat = fmt->fourcc; 751 pixm->pixelformat = fmt->fourcc;
725 pixm->colorspace = V4L2_COLORSPACE_JPEG; 752 pixm->colorspace = fmt->colorspace;
726 pixm->field = V4L2_FIELD_NONE; 753 pixm->field = V4L2_FIELD_NONE;
727 return 0; 754 return 0;
728} 755}
@@ -786,7 +813,7 @@ static int fimc_pipeline_validate(struct fimc_lite *fimc)
786 return -EPIPE; 813 return -EPIPE;
787 } 814 }
788 /* Retrieve format at the source pad */ 815 /* Retrieve format at the source pad */
789 pad = media_entity_remote_source(pad); 816 pad = media_entity_remote_pad(pad);
790 if (pad == NULL || 817 if (pad == NULL ||
791 media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV) 818 media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
792 break; 819 break;
@@ -810,14 +837,13 @@ static int fimc_lite_streamon(struct file *file, void *priv,
810 enum v4l2_buf_type type) 837 enum v4l2_buf_type type)
811{ 838{
812 struct fimc_lite *fimc = video_drvdata(file); 839 struct fimc_lite *fimc = video_drvdata(file);
813 struct media_entity *entity = &fimc->vfd.entity; 840 struct media_entity *entity = &fimc->ve.vdev.entity;
814 struct fimc_pipeline *p = &fimc->pipeline;
815 int ret; 841 int ret;
816 842
817 if (fimc_lite_active(fimc)) 843 if (fimc_lite_active(fimc))
818 return -EBUSY; 844 return -EBUSY;
819 845
820 ret = media_entity_pipeline_start(entity, p->m_pipeline); 846 ret = media_entity_pipeline_start(entity, &fimc->ve.pipe->mp);
821 if (ret < 0) 847 if (ret < 0)
822 return ret; 848 return ret;
823 849
@@ -825,7 +851,7 @@ static int fimc_lite_streamon(struct file *file, void *priv,
825 if (ret < 0) 851 if (ret < 0)
826 goto err_p_stop; 852 goto err_p_stop;
827 853
828 fimc->sensor = __find_remote_sensor(&fimc->subdev.entity); 854 fimc->sensor = fimc_find_remote_sensor(&fimc->subdev.entity);
829 855
830 ret = vb2_ioctl_streamon(file, priv, type); 856 ret = vb2_ioctl_streamon(file, priv, type);
831 if (!ret) { 857 if (!ret) {
@@ -848,7 +874,7 @@ static int fimc_lite_streamoff(struct file *file, void *priv,
848 if (ret < 0) 874 if (ret < 0)
849 return ret; 875 return ret;
850 876
851 media_entity_pipeline_stop(&fimc->vfd.entity); 877 media_entity_pipeline_stop(&fimc->ve.vdev.entity);
852 fimc->streaming = false; 878 fimc->streaming = false;
853 return 0; 879 return 0;
854} 880}
@@ -938,7 +964,7 @@ static int fimc_lite_s_selection(struct file *file, void *fh,
938} 964}
939 965
940static const struct v4l2_ioctl_ops fimc_lite_ioctl_ops = { 966static const struct v4l2_ioctl_ops fimc_lite_ioctl_ops = {
941 .vidioc_querycap = fimc_vidioc_querycap_capture, 967 .vidioc_querycap = fimc_lite_querycap,
942 .vidioc_enum_fmt_vid_cap_mplane = fimc_lite_enum_fmt_mplane, 968 .vidioc_enum_fmt_vid_cap_mplane = fimc_lite_enum_fmt_mplane,
943 .vidioc_try_fmt_vid_cap_mplane = fimc_lite_try_fmt_mplane, 969 .vidioc_try_fmt_vid_cap_mplane = fimc_lite_try_fmt_mplane,
944 .vidioc_s_fmt_vid_cap_mplane = fimc_lite_s_fmt_mplane, 970 .vidioc_s_fmt_vid_cap_mplane = fimc_lite_s_fmt_mplane,
@@ -972,8 +998,6 @@ static int fimc_lite_link_setup(struct media_entity *entity,
972 __func__, remote->entity->name, local->entity->name, 998 __func__, remote->entity->name, local->entity->name,
973 flags, fimc->source_subdev_grp_id); 999 flags, fimc->source_subdev_grp_id);
974 1000
975 mutex_lock(&fimc->lock);
976
977 switch (local->index) { 1001 switch (local->index) {
978 case FLITE_SD_PAD_SINK: 1002 case FLITE_SD_PAD_SINK:
979 if (remote_ent_type != MEDIA_ENT_T_V4L2_SUBDEV) { 1003 if (remote_ent_type != MEDIA_ENT_T_V4L2_SUBDEV) {
@@ -1015,7 +1039,6 @@ static int fimc_lite_link_setup(struct media_entity *entity,
1015 } 1039 }
1016 mb(); 1040 mb();
1017 1041
1018 mutex_unlock(&fimc->lock);
1019 return ret; 1042 return ret;
1020} 1043}
1021 1044
@@ -1036,6 +1059,15 @@ static int fimc_lite_subdev_enum_mbus_code(struct v4l2_subdev *sd,
1036 return 0; 1059 return 0;
1037} 1060}
1038 1061
1062static struct v4l2_mbus_framefmt *__fimc_lite_subdev_get_try_fmt(
1063 struct v4l2_subdev_fh *fh, unsigned int pad)
1064{
1065 if (pad != FLITE_SD_PAD_SINK)
1066 pad = FLITE_SD_PAD_SOURCE_DMA;
1067
1068 return v4l2_subdev_get_try_format(fh, pad);
1069}
1070
1039static int fimc_lite_subdev_get_fmt(struct v4l2_subdev *sd, 1071static int fimc_lite_subdev_get_fmt(struct v4l2_subdev *sd,
1040 struct v4l2_subdev_fh *fh, 1072 struct v4l2_subdev_fh *fh,
1041 struct v4l2_subdev_format *fmt) 1073 struct v4l2_subdev_format *fmt)
@@ -1045,13 +1077,13 @@ static int fimc_lite_subdev_get_fmt(struct v4l2_subdev *sd,
1045 struct flite_frame *f = &fimc->inp_frame; 1077 struct flite_frame *f = &fimc->inp_frame;
1046 1078
1047 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { 1079 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
1048 mf = v4l2_subdev_get_try_format(fh, fmt->pad); 1080 mf = __fimc_lite_subdev_get_try_fmt(fh, fmt->pad);
1049 fmt->format = *mf; 1081 fmt->format = *mf;
1050 return 0; 1082 return 0;
1051 } 1083 }
1052 mf->colorspace = V4L2_COLORSPACE_JPEG;
1053 1084
1054 mutex_lock(&fimc->lock); 1085 mutex_lock(&fimc->lock);
1086 mf->colorspace = f->fmt->colorspace;
1055 mf->code = f->fmt->mbus_code; 1087 mf->code = f->fmt->mbus_code;
1056 1088
1057 if (fmt->pad == FLITE_SD_PAD_SINK) { 1089 if (fmt->pad == FLITE_SD_PAD_SINK) {
@@ -1080,7 +1112,6 @@ static int fimc_lite_subdev_set_fmt(struct v4l2_subdev *sd,
1080 v4l2_dbg(1, debug, sd, "pad%d: code: 0x%x, %dx%d\n", 1112 v4l2_dbg(1, debug, sd, "pad%d: code: 0x%x, %dx%d\n",
1081 fmt->pad, mf->code, mf->width, mf->height); 1113 fmt->pad, mf->code, mf->width, mf->height);
1082 1114
1083 mf->colorspace = V4L2_COLORSPACE_JPEG;
1084 mutex_lock(&fimc->lock); 1115 mutex_lock(&fimc->lock);
1085 1116
1086 if ((atomic_read(&fimc->out_path) == FIMC_IO_ISP && 1117 if ((atomic_read(&fimc->out_path) == FIMC_IO_ISP &&
@@ -1091,12 +1122,20 @@ static int fimc_lite_subdev_set_fmt(struct v4l2_subdev *sd,
1091 return -EBUSY; 1122 return -EBUSY;
1092 } 1123 }
1093 1124
1094 ffmt = fimc_lite_try_format(fimc, &mf->width, &mf->height, 1125 ffmt = fimc_lite_subdev_try_fmt(fimc, fh, fmt);
1095 &mf->code, NULL, fmt->pad);
1096 1126
1097 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { 1127 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
1098 mf = v4l2_subdev_get_try_format(fh, fmt->pad); 1128 struct v4l2_mbus_framefmt *src_fmt;
1129
1130 mf = __fimc_lite_subdev_get_try_fmt(fh, fmt->pad);
1099 *mf = fmt->format; 1131 *mf = fmt->format;
1132
1133 if (fmt->pad == FLITE_SD_PAD_SINK) {
1134 unsigned int pad = FLITE_SD_PAD_SOURCE_DMA;
1135 src_fmt = __fimc_lite_subdev_get_try_fmt(fh, pad);
1136 *src_fmt = *mf;
1137 }
1138
1100 mutex_unlock(&fimc->lock); 1139 mutex_unlock(&fimc->lock);
1101 return 0; 1140 return 0;
1102 } 1141 }
@@ -1114,11 +1153,6 @@ static int fimc_lite_subdev_set_fmt(struct v4l2_subdev *sd,
1114 source->rect = sink->rect; 1153 source->rect = sink->rect;
1115 source->f_width = mf->width; 1154 source->f_width = mf->width;
1116 source->f_height = mf->height; 1155 source->f_height = mf->height;
1117 } else {
1118 /* Allow changing format only on sink pad */
1119 mf->code = sink->fmt->mbus_code;
1120 mf->width = sink->rect.width;
1121 mf->height = sink->rect.height;
1122 } 1156 }
1123 1157
1124 mutex_unlock(&fimc->lock); 1158 mutex_unlock(&fimc->lock);
@@ -1207,7 +1241,7 @@ static int fimc_lite_subdev_s_stream(struct v4l2_subdev *sd, int on)
1207 * The pipeline links are protected through entity.stream_count 1241 * The pipeline links are protected through entity.stream_count
1208 * so there is no need to take the media graph mutex here. 1242 * so there is no need to take the media graph mutex here.
1209 */ 1243 */
1210 fimc->sensor = __find_remote_sensor(&sd->entity); 1244 fimc->sensor = fimc_find_remote_sensor(&sd->entity);
1211 1245
1212 if (atomic_read(&fimc->out_path) != FIMC_IO_ISP) 1246 if (atomic_read(&fimc->out_path) != FIMC_IO_ISP)
1213 return -ENOIOCTLCMD; 1247 return -ENOIOCTLCMD;
@@ -1252,13 +1286,10 @@ static int fimc_lite_subdev_registered(struct v4l2_subdev *sd)
1252{ 1286{
1253 struct fimc_lite *fimc = v4l2_get_subdevdata(sd); 1287 struct fimc_lite *fimc = v4l2_get_subdevdata(sd);
1254 struct vb2_queue *q = &fimc->vb_queue; 1288 struct vb2_queue *q = &fimc->vb_queue;
1255 struct video_device *vfd = &fimc->vfd; 1289 struct video_device *vfd = &fimc->ve.vdev;
1256 int ret; 1290 int ret;
1257 1291
1258 memset(vfd, 0, sizeof(*vfd)); 1292 memset(vfd, 0, sizeof(*vfd));
1259
1260 fimc->inp_frame.fmt = &fimc_lite_formats[0];
1261 fimc->out_frame.fmt = &fimc_lite_formats[0];
1262 atomic_set(&fimc->out_path, FIMC_IO_DMA); 1293 atomic_set(&fimc->out_path, FIMC_IO_DMA);
1263 1294
1264 snprintf(vfd->name, sizeof(vfd->name), "fimc-lite.%d.capture", 1295 snprintf(vfd->name, sizeof(vfd->name), "fimc-lite.%d.capture",
@@ -1295,12 +1326,12 @@ static int fimc_lite_subdev_registered(struct v4l2_subdev *sd)
1295 return ret; 1326 return ret;
1296 1327
1297 video_set_drvdata(vfd, fimc); 1328 video_set_drvdata(vfd, fimc);
1298 fimc->pipeline_ops = v4l2_get_subdev_hostdata(sd); 1329 fimc->ve.pipe = v4l2_get_subdev_hostdata(sd);
1299 1330
1300 ret = video_register_device(vfd, VFL_TYPE_GRABBER, -1); 1331 ret = video_register_device(vfd, VFL_TYPE_GRABBER, -1);
1301 if (ret < 0) { 1332 if (ret < 0) {
1302 media_entity_cleanup(&vfd->entity); 1333 media_entity_cleanup(&vfd->entity);
1303 fimc->pipeline_ops = NULL; 1334 fimc->ve.pipe = NULL;
1304 return ret; 1335 return ret;
1305 } 1336 }
1306 1337
@@ -1316,11 +1347,15 @@ static void fimc_lite_subdev_unregistered(struct v4l2_subdev *sd)
1316 if (fimc == NULL) 1347 if (fimc == NULL)
1317 return; 1348 return;
1318 1349
1319 if (video_is_registered(&fimc->vfd)) { 1350 mutex_lock(&fimc->lock);
1320 video_unregister_device(&fimc->vfd); 1351
1321 media_entity_cleanup(&fimc->vfd.entity); 1352 if (video_is_registered(&fimc->ve.vdev)) {
1322 fimc->pipeline_ops = NULL; 1353 video_unregister_device(&fimc->ve.vdev);
1354 media_entity_cleanup(&fimc->ve.vdev.entity);
1355 fimc->ve.pipe = NULL;
1323 } 1356 }
1357
1358 mutex_unlock(&fimc->lock);
1324} 1359}
1325 1360
1326static const struct v4l2_subdev_internal_ops fimc_lite_subdev_internal_ops = { 1361static const struct v4l2_subdev_internal_ops fimc_lite_subdev_internal_ops = {
@@ -1370,6 +1405,23 @@ static const struct v4l2_ctrl_config fimc_lite_ctrl = {
1370 .step = 1, 1405 .step = 1,
1371}; 1406};
1372 1407
1408static void fimc_lite_set_default_config(struct fimc_lite *fimc)
1409{
1410 struct flite_frame *sink = &fimc->inp_frame;
1411 struct flite_frame *source = &fimc->out_frame;
1412
1413 sink->fmt = &fimc_lite_formats[0];
1414 sink->f_width = FLITE_DEFAULT_WIDTH;
1415 sink->f_height = FLITE_DEFAULT_HEIGHT;
1416
1417 sink->rect.width = FLITE_DEFAULT_WIDTH;
1418 sink->rect.height = FLITE_DEFAULT_HEIGHT;
1419 sink->rect.left = 0;
1420 sink->rect.top = 0;
1421
1422 *source = *sink;
1423}
1424
1373static int fimc_lite_create_capture_subdev(struct fimc_lite *fimc) 1425static int fimc_lite_create_capture_subdev(struct fimc_lite *fimc)
1374{ 1426{
1375 struct v4l2_ctrl_handler *handler = &fimc->ctrl_handler; 1427 struct v4l2_ctrl_handler *handler = &fimc->ctrl_handler;
@@ -1417,12 +1469,12 @@ static void fimc_lite_unregister_capture_subdev(struct fimc_lite *fimc)
1417 1469
1418static void fimc_lite_clk_put(struct fimc_lite *fimc) 1470static void fimc_lite_clk_put(struct fimc_lite *fimc)
1419{ 1471{
1420 if (IS_ERR_OR_NULL(fimc->clock)) 1472 if (IS_ERR(fimc->clock))
1421 return; 1473 return;
1422 1474
1423 clk_unprepare(fimc->clock); 1475 clk_unprepare(fimc->clock);
1424 clk_put(fimc->clock); 1476 clk_put(fimc->clock);
1425 fimc->clock = NULL; 1477 fimc->clock = ERR_PTR(-EINVAL);
1426} 1478}
1427 1479
1428static int fimc_lite_clk_get(struct fimc_lite *fimc) 1480static int fimc_lite_clk_get(struct fimc_lite *fimc)
@@ -1436,7 +1488,7 @@ static int fimc_lite_clk_get(struct fimc_lite *fimc)
1436 ret = clk_prepare(fimc->clock); 1488 ret = clk_prepare(fimc->clock);
1437 if (ret < 0) { 1489 if (ret < 0) {
1438 clk_put(fimc->clock); 1490 clk_put(fimc->clock);
1439 fimc->clock = NULL; 1491 fimc->clock = ERR_PTR(-EINVAL);
1440 } 1492 }
1441 return ret; 1493 return ret;
1442} 1494}
@@ -1461,13 +1513,14 @@ static int fimc_lite_probe(struct platform_device *pdev)
1461 if (of_id) 1513 if (of_id)
1462 drv_data = (struct flite_drvdata *)of_id->data; 1514 drv_data = (struct flite_drvdata *)of_id->data;
1463 fimc->index = of_alias_get_id(dev->of_node, "fimc-lite"); 1515 fimc->index = of_alias_get_id(dev->of_node, "fimc-lite");
1464 } else {
1465 drv_data = fimc_lite_get_drvdata(pdev);
1466 fimc->index = pdev->id;
1467 } 1516 }
1468 1517
1469 if (!drv_data || fimc->index < 0 || fimc->index >= FIMC_LITE_MAX_DEVS) 1518 if (!drv_data || fimc->index >= drv_data->num_instances ||
1519 fimc->index < 0) {
1520 dev_err(dev, "Wrong %s node alias\n",
1521 dev->of_node->full_name);
1470 return -EINVAL; 1522 return -EINVAL;
1523 }
1471 1524
1472 fimc->dd = drv_data; 1525 fimc->dd = drv_data;
1473 fimc->pdev = pdev; 1526 fimc->pdev = pdev;
@@ -1514,8 +1567,11 @@ static int fimc_lite_probe(struct platform_device *pdev)
1514 ret = PTR_ERR(fimc->alloc_ctx); 1567 ret = PTR_ERR(fimc->alloc_ctx);
1515 goto err_pm; 1568 goto err_pm;
1516 } 1569 }
1570
1517 pm_runtime_put(dev); 1571 pm_runtime_put(dev);
1518 1572
1573 fimc_lite_set_default_config(fimc);
1574
1519 dev_dbg(dev, "FIMC-LITE.%d registered successfully\n", 1575 dev_dbg(dev, "FIMC-LITE.%d registered successfully\n",
1520 fimc->index); 1576 fimc->index);
1521 return 0; 1577 return 0;
@@ -1565,8 +1621,8 @@ static int fimc_lite_resume(struct device *dev)
1565 return 0; 1621 return 0;
1566 1622
1567 INIT_LIST_HEAD(&fimc->active_buf_q); 1623 INIT_LIST_HEAD(&fimc->active_buf_q);
1568 fimc_pipeline_call(fimc, open, &fimc->pipeline, 1624 fimc_pipeline_call(&fimc->ve, open,
1569 &fimc->vfd.entity, false); 1625 &fimc->ve.vdev.entity, false);
1570 fimc_lite_hw_init(fimc, atomic_read(&fimc->out_path) == FIMC_IO_ISP); 1626 fimc_lite_hw_init(fimc, atomic_read(&fimc->out_path) == FIMC_IO_ISP);
1571 clear_bit(ST_FLITE_SUSPENDED, &fimc->state); 1627 clear_bit(ST_FLITE_SUSPENDED, &fimc->state);
1572 1628
@@ -1592,7 +1648,7 @@ static int fimc_lite_suspend(struct device *dev)
1592 if (ret < 0 || !fimc_lite_active(fimc)) 1648 if (ret < 0 || !fimc_lite_active(fimc))
1593 return ret; 1649 return ret;
1594 1650
1595 return fimc_pipeline_call(fimc, close, &fimc->pipeline); 1651 return fimc_pipeline_call(&fimc->ve, close);
1596} 1652}
1597#endif /* CONFIG_PM_SLEEP */ 1653#endif /* CONFIG_PM_SLEEP */
1598 1654
@@ -1624,22 +1680,30 @@ static struct flite_drvdata fimc_lite_drvdata_exynos4 = {
1624 .out_width_align = 8, 1680 .out_width_align = 8,
1625 .win_hor_offs_align = 2, 1681 .win_hor_offs_align = 2,
1626 .out_hor_offs_align = 8, 1682 .out_hor_offs_align = 8,
1683 .max_dma_bufs = 1,
1684 .num_instances = 2,
1627}; 1685};
1628 1686
1629static struct platform_device_id fimc_lite_driver_ids[] = { 1687/* EXYNOS5250 */
1630 { 1688static struct flite_drvdata fimc_lite_drvdata_exynos5 = {
1631 .name = "exynos-fimc-lite", 1689 .max_width = 8192,
1632 .driver_data = (unsigned long)&fimc_lite_drvdata_exynos4, 1690 .max_height = 8192,
1633 }, 1691 .out_width_align = 8,
1634 { /* sentinel */ }, 1692 .win_hor_offs_align = 2,
1693 .out_hor_offs_align = 8,
1694 .max_dma_bufs = 32,
1695 .num_instances = 3,
1635}; 1696};
1636MODULE_DEVICE_TABLE(platform, fimc_lite_driver_ids);
1637 1697
1638static const struct of_device_id flite_of_match[] = { 1698static const struct of_device_id flite_of_match[] = {
1639 { 1699 {
1640 .compatible = "samsung,exynos4212-fimc-lite", 1700 .compatible = "samsung,exynos4212-fimc-lite",
1641 .data = &fimc_lite_drvdata_exynos4, 1701 .data = &fimc_lite_drvdata_exynos4,
1642 }, 1702 },
1703 {
1704 .compatible = "samsung,exynos5250-fimc-lite",
1705 .data = &fimc_lite_drvdata_exynos5,
1706 },
1643 { /* sentinel */ }, 1707 { /* sentinel */ },
1644}; 1708};
1645MODULE_DEVICE_TABLE(of, flite_of_match); 1709MODULE_DEVICE_TABLE(of, flite_of_match);
@@ -1647,7 +1711,6 @@ MODULE_DEVICE_TABLE(of, flite_of_match);
1647static struct platform_driver fimc_lite_driver = { 1711static struct platform_driver fimc_lite_driver = {
1648 .probe = fimc_lite_probe, 1712 .probe = fimc_lite_probe,
1649 .remove = fimc_lite_remove, 1713 .remove = fimc_lite_remove,
1650 .id_table = fimc_lite_driver_ids,
1651 .driver = { 1714 .driver = {
1652 .of_match_table = flite_of_match, 1715 .of_match_table = flite_of_match,
1653 .name = FIMC_LITE_DRV_NAME, 1716 .name = FIMC_LITE_DRV_NAME,
diff --git a/drivers/media/platform/exynos4-is/fimc-lite.h b/drivers/media/platform/exynos4-is/fimc-lite.h
index 47da5e049247..7428b2d22b52 100644
--- a/drivers/media/platform/exynos4-is/fimc-lite.h
+++ b/drivers/media/platform/exynos4-is/fimc-lite.h
@@ -27,8 +27,10 @@
27 27
28#define FIMC_LITE_DRV_NAME "exynos-fimc-lite" 28#define FIMC_LITE_DRV_NAME "exynos-fimc-lite"
29#define FLITE_CLK_NAME "flite" 29#define FLITE_CLK_NAME "flite"
30#define FIMC_LITE_MAX_DEVS 2 30#define FIMC_LITE_MAX_DEVS 3
31#define FLITE_REQ_BUFS_MIN 2 31#define FLITE_REQ_BUFS_MIN 2
32#define FLITE_DEFAULT_WIDTH 640
33#define FLITE_DEFAULT_HEIGHT 480
32 34
33/* Bit index definitions for struct fimc_lite::state */ 35/* Bit index definitions for struct fimc_lite::state */
34enum { 36enum {
@@ -48,17 +50,28 @@ enum {
48#define FLITE_SD_PAD_SOURCE_ISP 2 50#define FLITE_SD_PAD_SOURCE_ISP 2
49#define FLITE_SD_PADS_NUM 3 51#define FLITE_SD_PADS_NUM 3
50 52
53/**
54 * struct flite_drvdata - FIMC-LITE IP variant data structure
55 * @max_width: maximum camera interface input width in pixels
56 * @max_height: maximum camera interface input height in pixels
57 * @out_width_align: minimum output width alignment in pixels
58 * @win_hor_offs_align: minimum camera interface crop window horizontal
59 * offset alignment in pixels
60 * @out_hor_offs_align: minimum output DMA compose rectangle horizontal
61 * offset alignment in pixels
62 * @max_dma_bufs: number of output DMA buffer start address registers
63 * @num_instances: total number of FIMC-LITE IP instances available
64 */
51struct flite_drvdata { 65struct flite_drvdata {
52 unsigned short max_width; 66 unsigned short max_width;
53 unsigned short max_height; 67 unsigned short max_height;
54 unsigned short out_width_align; 68 unsigned short out_width_align;
55 unsigned short win_hor_offs_align; 69 unsigned short win_hor_offs_align;
56 unsigned short out_hor_offs_align; 70 unsigned short out_hor_offs_align;
71 unsigned short max_dma_bufs;
72 unsigned short num_instances;
57}; 73};
58 74
59#define fimc_lite_get_drvdata(_pdev) \
60 ((struct flite_drvdata *) platform_get_device_id(_pdev)->driver_data)
61
62struct fimc_lite_events { 75struct fimc_lite_events {
63 unsigned int data_overflow; 76 unsigned int data_overflow;
64}; 77};
@@ -83,20 +96,22 @@ struct flite_frame {
83 * struct flite_buffer - video buffer structure 96 * struct flite_buffer - video buffer structure
84 * @vb: vb2 buffer 97 * @vb: vb2 buffer
85 * @list: list head for the buffers queue 98 * @list: list head for the buffers queue
86 * @paddr: precalculated physical address 99 * @paddr: DMA buffer start address
100 * @index: DMA start address register's index
87 */ 101 */
88struct flite_buffer { 102struct flite_buffer {
89 struct vb2_buffer vb; 103 struct vb2_buffer vb;
90 struct list_head list; 104 struct list_head list;
91 dma_addr_t paddr; 105 dma_addr_t paddr;
106 unsigned short index;
92}; 107};
93 108
94/** 109/**
95 * struct fimc_lite - fimc lite structure 110 * struct fimc_lite - fimc lite structure
96 * @pdev: pointer to FIMC-LITE platform device 111 * @pdev: pointer to FIMC-LITE platform device
97 * @dd: SoC specific driver data structure 112 * @dd: SoC specific driver data structure
113 * @ve: exynos video device entity structure
98 * @v4l2_dev: pointer to top the level v4l2_device 114 * @v4l2_dev: pointer to top the level v4l2_device
99 * @vfd: video device node
100 * @fh: v4l2 file handle 115 * @fh: v4l2 file handle
101 * @alloc_ctx: videobuf2 memory allocator context 116 * @alloc_ctx: videobuf2 memory allocator context
102 * @subdev: FIMC-LITE subdev 117 * @subdev: FIMC-LITE subdev
@@ -122,16 +137,16 @@ struct flite_buffer {
122 * @pending_buf_q: pending buffers queue head 137 * @pending_buf_q: pending buffers queue head
123 * @active_buf_q: the queue head of buffers scheduled in hardware 138 * @active_buf_q: the queue head of buffers scheduled in hardware
124 * @vb_queue: vb2 buffers queue 139 * @vb_queue: vb2 buffers queue
140 * @buf_index: helps to keep track of the DMA start address register index
125 * @active_buf_count: number of video buffers scheduled in hardware 141 * @active_buf_count: number of video buffers scheduled in hardware
126 * @frame_count: the captured frames counter 142 * @frame_count: the captured frames counter
127 * @reqbufs_count: the number of buffers requested with REQBUFS ioctl 143 * @reqbufs_count: the number of buffers requested with REQBUFS ioctl
128 * @ref_count: driver's private reference counter
129 */ 144 */
130struct fimc_lite { 145struct fimc_lite {
131 struct platform_device *pdev; 146 struct platform_device *pdev;
132 struct flite_drvdata *dd; 147 struct flite_drvdata *dd;
148 struct exynos_video_entity ve;
133 struct v4l2_device *v4l2_dev; 149 struct v4l2_device *v4l2_dev;
134 struct video_device vfd;
135 struct v4l2_fh fh; 150 struct v4l2_fh fh;
136 struct vb2_alloc_ctx *alloc_ctx; 151 struct vb2_alloc_ctx *alloc_ctx;
137 struct v4l2_subdev subdev; 152 struct v4l2_subdev subdev;
@@ -141,8 +156,6 @@ struct fimc_lite {
141 struct v4l2_ctrl_handler ctrl_handler; 156 struct v4l2_ctrl_handler ctrl_handler;
142 struct v4l2_ctrl *test_pattern; 157 struct v4l2_ctrl *test_pattern;
143 int index; 158 int index;
144 struct fimc_pipeline pipeline;
145 const struct fimc_pipeline_ops *pipeline_ops;
146 159
147 struct mutex lock; 160 struct mutex lock;
148 spinlock_t slock; 161 spinlock_t slock;
@@ -161,9 +174,9 @@ struct fimc_lite {
161 struct list_head pending_buf_q; 174 struct list_head pending_buf_q;
162 struct list_head active_buf_q; 175 struct list_head active_buf_q;
163 struct vb2_queue vb_queue; 176 struct vb2_queue vb_queue;
177 unsigned short buf_index;
164 unsigned int frame_count; 178 unsigned int frame_count;
165 unsigned int reqbufs_count; 179 unsigned int reqbufs_count;
166 int ref_count;
167 180
168 struct fimc_lite_events events; 181 struct fimc_lite_events events;
169 bool streaming; 182 bool streaming;
diff --git a/drivers/media/platform/exynos4-is/fimc-m2m.c b/drivers/media/platform/exynos4-is/fimc-m2m.c
index bde1f47f7ed3..8d33b68c76ba 100644
--- a/drivers/media/platform/exynos4-is/fimc-m2m.c
+++ b/drivers/media/platform/exynos4-is/fimc-m2m.c
@@ -27,6 +27,7 @@
27#include <media/videobuf2-core.h> 27#include <media/videobuf2-core.h>
28#include <media/videobuf2-dma-contig.h> 28#include <media/videobuf2-dma-contig.h>
29 29
30#include "common.h"
30#include "fimc-core.h" 31#include "fimc-core.h"
31#include "fimc-reg.h" 32#include "fimc-reg.h"
32#include "media-dev.h" 33#include "media-dev.h"
diff --git a/drivers/media/platform/exynos4-is/fimc-reg.c b/drivers/media/platform/exynos4-is/fimc-reg.c
index f079f36099de..1db8cb4c46ef 100644
--- a/drivers/media/platform/exynos4-is/fimc-reg.c
+++ b/drivers/media/platform/exynos4-is/fimc-reg.c
@@ -618,7 +618,7 @@ int fimc_hw_set_camera_source(struct fimc_dev *fimc,
618 } 618 }
619 619
620 if (i == ARRAY_SIZE(pix_desc)) { 620 if (i == ARRAY_SIZE(pix_desc)) {
621 v4l2_err(&vc->vfd, 621 v4l2_err(&vc->ve.vdev,
622 "Camera color format not supported: %d\n", 622 "Camera color format not supported: %d\n",
623 vc->ci_fmt.code); 623 vc->ci_fmt.code);
624 return -EINVAL; 624 return -EINVAL;
@@ -698,7 +698,7 @@ int fimc_hw_set_camera_type(struct fimc_dev *fimc,
698 cfg |= FIMC_REG_CIGCTRL_CAM_JPEG; 698 cfg |= FIMC_REG_CIGCTRL_CAM_JPEG;
699 break; 699 break;
700 default: 700 default:
701 v4l2_err(&vid_cap->vfd, 701 v4l2_err(&vid_cap->ve.vdev,
702 "Not supported camera pixel format: %#x\n", 702 "Not supported camera pixel format: %#x\n",
703 vid_cap->ci_fmt.code); 703 vid_cap->ci_fmt.code);
704 return -EINVAL; 704 return -EINVAL;
@@ -721,7 +721,8 @@ int fimc_hw_set_camera_type(struct fimc_dev *fimc,
721 WARN_ONCE(1, "ISP Writeback input is not supported\n"); 721 WARN_ONCE(1, "ISP Writeback input is not supported\n");
722 break; 722 break;
723 default: 723 default:
724 v4l2_err(&vid_cap->vfd, "Invalid FIMC bus type selected: %d\n", 724 v4l2_err(&vid_cap->ve.vdev,
725 "Invalid FIMC bus type selected: %d\n",
725 source->fimc_bus_type); 726 source->fimc_bus_type);
726 return -EINVAL; 727 return -EINVAL;
727 } 728 }
diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
index 15ef8f28239b..19f556c5957f 100644
--- a/drivers/media/platform/exynos4-is/media-dev.c
+++ b/drivers/media/platform/exynos4-is/media-dev.c
@@ -1,8 +1,8 @@
1/* 1/*
2 * S5P/EXYNOS4 SoC series camera host interface media device driver 2 * S5P/EXYNOS4 SoC series camera host interface media device driver
3 * 3 *
4 * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. 4 * Copyright (C) 2011 - 2013 Samsung Electronics Co., Ltd.
5 * Sylwester Nawrocki <s.nawrocki@samsung.com> 5 * Author: Sylwester Nawrocki <s.nawrocki@samsung.com>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published 8 * it under the terms of the GNU General Public License as published
@@ -39,6 +39,26 @@
39static int __fimc_md_set_camclk(struct fimc_md *fmd, 39static int __fimc_md_set_camclk(struct fimc_md *fmd,
40 struct fimc_source_info *si, 40 struct fimc_source_info *si,
41 bool on); 41 bool on);
42
43/* Set up image sensor subdev -> FIMC capture node notifications. */
44static void __setup_sensor_notification(struct fimc_md *fmd,
45 struct v4l2_subdev *sensor,
46 struct v4l2_subdev *fimc_sd)
47{
48 struct fimc_source_info *src_inf;
49 struct fimc_sensor_info *md_si;
50 unsigned long flags;
51
52 src_inf = v4l2_get_subdev_hostdata(sensor);
53 if (!src_inf || WARN_ON(fmd == NULL))
54 return;
55
56 md_si = source_to_sensor_info(src_inf);
57 spin_lock_irqsave(&fmd->slock, flags);
58 md_si->host = v4l2_get_subdevdata(fimc_sd);
59 spin_unlock_irqrestore(&fmd->slock, flags);
60}
61
42/** 62/**
43 * fimc_pipeline_prepare - update pipeline information with subdevice pointers 63 * fimc_pipeline_prepare - update pipeline information with subdevice pointers
44 * @me: media entity terminating the pipeline 64 * @me: media entity terminating the pipeline
@@ -46,9 +66,11 @@ static int __fimc_md_set_camclk(struct fimc_md *fmd,
46 * Caller holds the graph mutex. 66 * Caller holds the graph mutex.
47 */ 67 */
48static void fimc_pipeline_prepare(struct fimc_pipeline *p, 68static void fimc_pipeline_prepare(struct fimc_pipeline *p,
49 struct media_entity *me) 69 struct media_entity *me)
50{ 70{
71 struct fimc_md *fmd = entity_to_fimc_mdev(me);
51 struct v4l2_subdev *sd; 72 struct v4l2_subdev *sd;
73 struct v4l2_subdev *sensor = NULL;
52 int i; 74 int i;
53 75
54 for (i = 0; i < IDX_MAX; i++) 76 for (i = 0; i < IDX_MAX; i++)
@@ -62,7 +84,7 @@ static void fimc_pipeline_prepare(struct fimc_pipeline *p,
62 struct media_pad *spad = &me->pads[i]; 84 struct media_pad *spad = &me->pads[i];
63 if (!(spad->flags & MEDIA_PAD_FL_SINK)) 85 if (!(spad->flags & MEDIA_PAD_FL_SINK))
64 continue; 86 continue;
65 pad = media_entity_remote_source(spad); 87 pad = media_entity_remote_pad(spad);
66 if (pad) 88 if (pad)
67 break; 89 break;
68 } 90 }
@@ -73,8 +95,10 @@ static void fimc_pipeline_prepare(struct fimc_pipeline *p,
73 sd = media_entity_to_v4l2_subdev(pad->entity); 95 sd = media_entity_to_v4l2_subdev(pad->entity);
74 96
75 switch (sd->grp_id) { 97 switch (sd->grp_id) {
76 case GRP_ID_FIMC_IS_SENSOR:
77 case GRP_ID_SENSOR: 98 case GRP_ID_SENSOR:
99 sensor = sd;
100 /* fall through */
101 case GRP_ID_FIMC_IS_SENSOR:
78 p->subdevs[IDX_SENSOR] = sd; 102 p->subdevs[IDX_SENSOR] = sd;
79 break; 103 break;
80 case GRP_ID_CSIS: 104 case GRP_ID_CSIS:
@@ -84,7 +108,7 @@ static void fimc_pipeline_prepare(struct fimc_pipeline *p,
84 p->subdevs[IDX_FLITE] = sd; 108 p->subdevs[IDX_FLITE] = sd;
85 break; 109 break;
86 case GRP_ID_FIMC: 110 case GRP_ID_FIMC:
87 /* No need to control FIMC subdev through subdev ops */ 111 p->subdevs[IDX_FIMC] = sd;
88 break; 112 break;
89 case GRP_ID_FIMC_IS: 113 case GRP_ID_FIMC_IS:
90 p->subdevs[IDX_IS_ISP] = sd; 114 p->subdevs[IDX_IS_ISP] = sd;
@@ -96,6 +120,9 @@ static void fimc_pipeline_prepare(struct fimc_pipeline *p,
96 if (me->num_pads == 1) 120 if (me->num_pads == 1)
97 break; 121 break;
98 } 122 }
123
124 if (sensor && p->subdevs[IDX_FIMC])
125 __setup_sensor_notification(fmd, sensor, p->subdevs[IDX_FIMC]);
99} 126}
100 127
101/** 128/**
@@ -168,10 +195,11 @@ error:
168 * 195 *
169 * Called with the graph mutex held. 196 * Called with the graph mutex held.
170 */ 197 */
171static int __fimc_pipeline_open(struct fimc_pipeline *p, 198static int __fimc_pipeline_open(struct exynos_media_pipeline *ep,
172 struct media_entity *me, bool prepare) 199 struct media_entity *me, bool prepare)
173{ 200{
174 struct fimc_md *fmd = entity_to_fimc_mdev(me); 201 struct fimc_md *fmd = entity_to_fimc_mdev(me);
202 struct fimc_pipeline *p = to_fimc_pipeline(ep);
175 struct v4l2_subdev *sd; 203 struct v4l2_subdev *sd;
176 int ret; 204 int ret;
177 205
@@ -214,20 +242,21 @@ err_wbclk:
214 * 242 *
215 * Disable power of all subdevs and turn the external sensor clock off. 243 * Disable power of all subdevs and turn the external sensor clock off.
216 */ 244 */
217static int __fimc_pipeline_close(struct fimc_pipeline *p) 245static int __fimc_pipeline_close(struct exynos_media_pipeline *ep)
218{ 246{
247 struct fimc_pipeline *p = to_fimc_pipeline(ep);
219 struct v4l2_subdev *sd = p ? p->subdevs[IDX_SENSOR] : NULL; 248 struct v4l2_subdev *sd = p ? p->subdevs[IDX_SENSOR] : NULL;
220 struct fimc_md *fmd; 249 struct fimc_md *fmd;
221 int ret = 0; 250 int ret;
222
223 if (WARN_ON(sd == NULL))
224 return -EINVAL;
225 251
226 if (p->subdevs[IDX_SENSOR]) { 252 if (sd == NULL) {
227 ret = fimc_pipeline_s_power(p, 0); 253 pr_warn("%s(): No sensor subdev\n", __func__);
228 fimc_md_set_camclk(sd, false); 254 return 0;
229 } 255 }
230 256
257 ret = fimc_pipeline_s_power(p, 0);
258 fimc_md_set_camclk(sd, false);
259
231 fmd = entity_to_fimc_mdev(&sd->entity); 260 fmd = entity_to_fimc_mdev(&sd->entity);
232 261
233 /* Disable PXLASYNC clock if this pipeline includes FIMC-IS */ 262 /* Disable PXLASYNC clock if this pipeline includes FIMC-IS */
@@ -242,12 +271,13 @@ static int __fimc_pipeline_close(struct fimc_pipeline *p)
242 * @pipeline: video pipeline structure 271 * @pipeline: video pipeline structure
243 * @on: passed as the s_stream() callback argument 272 * @on: passed as the s_stream() callback argument
244 */ 273 */
245static int __fimc_pipeline_s_stream(struct fimc_pipeline *p, bool on) 274static int __fimc_pipeline_s_stream(struct exynos_media_pipeline *ep, bool on)
246{ 275{
247 static const u8 seq[2][IDX_MAX] = { 276 static const u8 seq[2][IDX_MAX] = {
248 { IDX_FIMC, IDX_SENSOR, IDX_IS_ISP, IDX_CSIS, IDX_FLITE }, 277 { IDX_FIMC, IDX_SENSOR, IDX_IS_ISP, IDX_CSIS, IDX_FLITE },
249 { IDX_CSIS, IDX_FLITE, IDX_FIMC, IDX_SENSOR, IDX_IS_ISP }, 278 { IDX_CSIS, IDX_FLITE, IDX_FIMC, IDX_SENSOR, IDX_IS_ISP },
250 }; 279 };
280 struct fimc_pipeline *p = to_fimc_pipeline(ep);
251 int i, ret = 0; 281 int i, ret = 0;
252 282
253 if (p->subdevs[IDX_SENSOR] == NULL) 283 if (p->subdevs[IDX_SENSOR] == NULL)
@@ -271,12 +301,38 @@ error:
271} 301}
272 302
273/* Media pipeline operations for the FIMC/FIMC-LITE video device driver */ 303/* Media pipeline operations for the FIMC/FIMC-LITE video device driver */
274static const struct fimc_pipeline_ops fimc_pipeline_ops = { 304static const struct exynos_media_pipeline_ops fimc_pipeline_ops = {
275 .open = __fimc_pipeline_open, 305 .open = __fimc_pipeline_open,
276 .close = __fimc_pipeline_close, 306 .close = __fimc_pipeline_close,
277 .set_stream = __fimc_pipeline_s_stream, 307 .set_stream = __fimc_pipeline_s_stream,
278}; 308};
279 309
310static struct exynos_media_pipeline *fimc_md_pipeline_create(
311 struct fimc_md *fmd)
312{
313 struct fimc_pipeline *p;
314
315 p = kzalloc(sizeof(*p), GFP_KERNEL);
316 if (!p)
317 return NULL;
318
319 list_add_tail(&p->list, &fmd->pipelines);
320
321 p->ep.ops = &fimc_pipeline_ops;
322 return &p->ep;
323}
324
325static void fimc_md_pipelines_free(struct fimc_md *fmd)
326{
327 while (!list_empty(&fmd->pipelines)) {
328 struct fimc_pipeline *p;
329
330 p = list_entry(fmd->pipelines.next, typeof(*p), list);
331 list_del(&p->list);
332 kfree(p);
333 }
334}
335
280/* 336/*
281 * Sensor subdevice helper functions 337 * Sensor subdevice helper functions
282 */ 338 */
@@ -592,6 +648,7 @@ static int register_fimc_lite_entity(struct fimc_md *fmd,
592 struct fimc_lite *fimc_lite) 648 struct fimc_lite *fimc_lite)
593{ 649{
594 struct v4l2_subdev *sd; 650 struct v4l2_subdev *sd;
651 struct exynos_media_pipeline *ep;
595 int ret; 652 int ret;
596 653
597 if (WARN_ON(fimc_lite->index >= FIMC_LITE_MAX_DEVS || 654 if (WARN_ON(fimc_lite->index >= FIMC_LITE_MAX_DEVS ||
@@ -600,7 +657,12 @@ static int register_fimc_lite_entity(struct fimc_md *fmd,
600 657
601 sd = &fimc_lite->subdev; 658 sd = &fimc_lite->subdev;
602 sd->grp_id = GRP_ID_FLITE; 659 sd->grp_id = GRP_ID_FLITE;
603 v4l2_set_subdev_hostdata(sd, (void *)&fimc_pipeline_ops); 660
661 ep = fimc_md_pipeline_create(fmd);
662 if (!ep)
663 return -ENOMEM;
664
665 v4l2_set_subdev_hostdata(sd, ep);
604 666
605 ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd); 667 ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd);
606 if (!ret) 668 if (!ret)
@@ -614,6 +676,7 @@ static int register_fimc_lite_entity(struct fimc_md *fmd,
614static int register_fimc_entity(struct fimc_md *fmd, struct fimc_dev *fimc) 676static int register_fimc_entity(struct fimc_md *fmd, struct fimc_dev *fimc)
615{ 677{
616 struct v4l2_subdev *sd; 678 struct v4l2_subdev *sd;
679 struct exynos_media_pipeline *ep;
617 int ret; 680 int ret;
618 681
619 if (WARN_ON(fimc->id >= FIMC_MAX_DEVS || fmd->fimc[fimc->id])) 682 if (WARN_ON(fimc->id >= FIMC_MAX_DEVS || fmd->fimc[fimc->id]))
@@ -621,7 +684,12 @@ static int register_fimc_entity(struct fimc_md *fmd, struct fimc_dev *fimc)
621 684
622 sd = &fimc->vid_cap.subdev; 685 sd = &fimc->vid_cap.subdev;
623 sd->grp_id = GRP_ID_FIMC; 686 sd->grp_id = GRP_ID_FIMC;
624 v4l2_set_subdev_hostdata(sd, (void *)&fimc_pipeline_ops); 687
688 ep = fimc_md_pipeline_create(fmd);
689 if (!ep)
690 return -ENOMEM;
691
692 v4l2_set_subdev_hostdata(sd, ep);
625 693
626 ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd); 694 ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd);
627 if (!ret) { 695 if (!ret) {
@@ -736,8 +804,6 @@ static int fimc_md_pdev_match(struct device *dev, void *data)
736 804
737 if (!strcmp(pdev->name, CSIS_DRIVER_NAME)) { 805 if (!strcmp(pdev->name, CSIS_DRIVER_NAME)) {
738 plat_entity = IDX_CSIS; 806 plat_entity = IDX_CSIS;
739 } else if (!strcmp(pdev->name, FIMC_LITE_DRV_NAME)) {
740 plat_entity = IDX_FLITE;
741 } else { 807 } else {
742 p = strstr(pdev->name, "fimc"); 808 p = strstr(pdev->name, "fimc");
743 if (p && *(p + 4) == 0) 809 if (p && *(p + 4) == 0)
@@ -797,17 +863,19 @@ static void fimc_md_unregister_entities(struct fimc_md *fmd)
797 int i; 863 int i;
798 864
799 for (i = 0; i < FIMC_MAX_DEVS; i++) { 865 for (i = 0; i < FIMC_MAX_DEVS; i++) {
800 if (fmd->fimc[i] == NULL) 866 struct fimc_dev *dev = fmd->fimc[i];
867 if (dev == NULL)
801 continue; 868 continue;
802 v4l2_device_unregister_subdev(&fmd->fimc[i]->vid_cap.subdev); 869 v4l2_device_unregister_subdev(&dev->vid_cap.subdev);
803 fmd->fimc[i]->pipeline_ops = NULL; 870 dev->vid_cap.ve.pipe = NULL;
804 fmd->fimc[i] = NULL; 871 fmd->fimc[i] = NULL;
805 } 872 }
806 for (i = 0; i < FIMC_LITE_MAX_DEVS; i++) { 873 for (i = 0; i < FIMC_LITE_MAX_DEVS; i++) {
807 if (fmd->fimc_lite[i] == NULL) 874 struct fimc_lite *dev = fmd->fimc_lite[i];
875 if (dev == NULL)
808 continue; 876 continue;
809 v4l2_device_unregister_subdev(&fmd->fimc_lite[i]->subdev); 877 v4l2_device_unregister_subdev(&dev->subdev);
810 fmd->fimc_lite[i]->pipeline_ops = NULL; 878 dev->ve.pipe = NULL;
811 fmd->fimc_lite[i] = NULL; 879 fmd->fimc_lite[i] = NULL;
812 } 880 }
813 for (i = 0; i < CSIS_MAX_ENTITIES; i++) { 881 for (i = 0; i < CSIS_MAX_ENTITIES; i++) {
@@ -880,18 +948,6 @@ static int __fimc_md_create_fimc_sink_links(struct fimc_md *fmd,
880 948
881 v4l2_info(&fmd->v4l2_dev, "created link [%s] %c> [%s]\n", 949 v4l2_info(&fmd->v4l2_dev, "created link [%s] %c> [%s]\n",
882 source->name, flags ? '=' : '-', sink->name); 950 source->name, flags ? '=' : '-', sink->name);
883
884 if (flags == 0 || sensor == NULL)
885 continue;
886
887 if (!WARN_ON(si == NULL)) {
888 unsigned long irq_flags;
889 struct fimc_sensor_info *inf = source_to_sensor_info(si);
890
891 spin_lock_irqsave(&fmd->slock, irq_flags);
892 inf->host = fmd->fimc[i];
893 spin_unlock_irqrestore(&fmd->slock, irq_flags);
894 }
895 } 951 }
896 952
897 for (i = 0; i < FIMC_LITE_MAX_DEVS; i++) { 953 for (i = 0; i < FIMC_LITE_MAX_DEVS; i++) {
@@ -929,7 +985,7 @@ static int __fimc_md_create_flite_source_links(struct fimc_md *fmd)
929 continue; 985 continue;
930 986
931 source = &fimc->subdev.entity; 987 source = &fimc->subdev.entity;
932 sink = &fimc->vfd.entity; 988 sink = &fimc->ve.vdev.entity;
933 /* FIMC-LITE's subdev and video node */ 989 /* FIMC-LITE's subdev and video node */
934 ret = media_entity_create_link(source, FLITE_SD_PAD_SOURCE_DMA, 990 ret = media_entity_create_link(source, FLITE_SD_PAD_SOURCE_DMA,
935 sink, 0, 0); 991 sink, 0, 0);
@@ -1066,7 +1122,7 @@ static int fimc_md_create_links(struct fimc_md *fmd)
1066 continue; 1122 continue;
1067 1123
1068 source = &fmd->fimc[i]->vid_cap.subdev.entity; 1124 source = &fmd->fimc[i]->vid_cap.subdev.entity;
1069 sink = &fmd->fimc[i]->vid_cap.vfd.entity; 1125 sink = &fmd->fimc[i]->vid_cap.ve.vdev.entity;
1070 1126
1071 ret = media_entity_create_link(source, FIMC_SD_PAD_SOURCE, 1127 ret = media_entity_create_link(source, FIMC_SD_PAD_SOURCE,
1072 sink, 0, flags); 1128 sink, 0, flags);
@@ -1231,66 +1287,98 @@ int fimc_md_set_camclk(struct v4l2_subdev *sd, bool on)
1231 return __fimc_md_set_camclk(fmd, si, on); 1287 return __fimc_md_set_camclk(fmd, si, on);
1232} 1288}
1233 1289
1234static int fimc_md_link_notify(struct media_pad *source, 1290static int __fimc_md_modify_pipeline(struct media_entity *entity, bool enable)
1235 struct media_pad *sink, u32 flags)
1236{ 1291{
1237 struct fimc_lite *fimc_lite = NULL; 1292 struct exynos_video_entity *ve;
1238 struct fimc_dev *fimc = NULL; 1293 struct fimc_pipeline *p;
1239 struct fimc_pipeline *pipeline; 1294 struct video_device *vdev;
1240 struct v4l2_subdev *sd; 1295 int ret;
1241 struct mutex *lock;
1242 int i, ret = 0;
1243 int ref_count;
1244 1296
1245 if (media_entity_type(sink->entity) != MEDIA_ENT_T_V4L2_SUBDEV) 1297 vdev = media_entity_to_video_device(entity);
1298 if (vdev->entity.use_count == 0)
1246 return 0; 1299 return 0;
1247 1300
1248 sd = media_entity_to_v4l2_subdev(sink->entity); 1301 ve = vdev_to_exynos_video_entity(vdev);
1249 1302 p = to_fimc_pipeline(ve->pipe);
1250 switch (sd->grp_id) { 1303 /*
1251 case GRP_ID_FLITE: 1304 * Nothing to do if we are disabling the pipeline, some link
1252 fimc_lite = v4l2_get_subdevdata(sd); 1305 * has been disconnected and p->subdevs array is cleared now.
1253 if (WARN_ON(fimc_lite == NULL)) 1306 */
1254 return 0; 1307 if (!enable && p->subdevs[IDX_SENSOR] == NULL)
1255 pipeline = &fimc_lite->pipeline;
1256 lock = &fimc_lite->lock;
1257 break;
1258 case GRP_ID_FIMC:
1259 fimc = v4l2_get_subdevdata(sd);
1260 if (WARN_ON(fimc == NULL))
1261 return 0;
1262 pipeline = &fimc->pipeline;
1263 lock = &fimc->lock;
1264 break;
1265 default:
1266 return 0; 1308 return 0;
1309
1310 if (enable)
1311 ret = __fimc_pipeline_open(ve->pipe, entity, true);
1312 else
1313 ret = __fimc_pipeline_close(ve->pipe);
1314
1315 if (ret == 0 && !enable)
1316 memset(p->subdevs, 0, sizeof(p->subdevs));
1317
1318 return ret;
1319}
1320
1321/* Locking: called with entity->parent->graph_mutex mutex held. */
1322static int __fimc_md_modify_pipelines(struct media_entity *entity, bool enable)
1323{
1324 struct media_entity *entity_err = entity;
1325 struct media_entity_graph graph;
1326 int ret;
1327
1328 /*
1329 * Walk current graph and call the pipeline open/close routine for each
1330 * opened video node that belongs to the graph of entities connected
1331 * through active links. This is needed as we cannot power on/off the
1332 * subdevs in random order.
1333 */
1334 media_entity_graph_walk_start(&graph, entity);
1335
1336 while ((entity = media_entity_graph_walk_next(&graph))) {
1337 if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
1338 continue;
1339
1340 ret = __fimc_md_modify_pipeline(entity, enable);
1341
1342 if (ret < 0)
1343 goto err;
1267 } 1344 }
1268 1345
1269 mutex_lock(lock); 1346 return 0;
1270 ref_count = fimc ? fimc->vid_cap.refcnt : fimc_lite->ref_count; 1347 err:
1348 media_entity_graph_walk_start(&graph, entity_err);
1271 1349
1272 if (!(flags & MEDIA_LNK_FL_ENABLED)) { 1350 while ((entity_err = media_entity_graph_walk_next(&graph))) {
1273 if (ref_count > 0) { 1351 if (media_entity_type(entity_err) != MEDIA_ENT_T_DEVNODE)
1274 ret = __fimc_pipeline_close(pipeline); 1352 continue;
1275 if (!ret && fimc) 1353
1276 fimc_ctrls_delete(fimc->vid_cap.ctx); 1354 __fimc_md_modify_pipeline(entity_err, !enable);
1277 } 1355
1278 for (i = 0; i < IDX_MAX; i++) 1356 if (entity_err == entity)
1279 pipeline->subdevs[i] = NULL; 1357 break;
1280 } else if (ref_count > 0) { 1358 }
1281 /* 1359
1282 * Link activation. Enable power of pipeline elements only if 1360 return ret;
1283 * the pipeline is already in use, i.e. its video node is open. 1361}
1284 * Recreate the controls destroyed during the link deactivation. 1362
1285 */ 1363static int fimc_md_link_notify(struct media_link *link, unsigned int flags,
1286 ret = __fimc_pipeline_open(pipeline, 1364 unsigned int notification)
1287 source->entity, true); 1365{
1288 if (!ret && fimc) 1366 struct media_entity *sink = link->sink->entity;
1289 ret = fimc_capture_ctrls_create(fimc); 1367 int ret = 0;
1368
1369 /* Before link disconnection */
1370 if (notification == MEDIA_DEV_NOTIFY_PRE_LINK_CH) {
1371 if (!(flags & MEDIA_LNK_FL_ENABLED))
1372 ret = __fimc_md_modify_pipelines(sink, false);
1373 else
1374 ; /* TODO: Link state change validation */
1375 /* After link activation */
1376 } else if (notification == MEDIA_DEV_NOTIFY_POST_LINK_CH &&
1377 (link->flags & MEDIA_LNK_FL_ENABLED)) {
1378 ret = __fimc_md_modify_pipelines(sink, true);
1290 } 1379 }
1291 1380
1292 mutex_unlock(lock); 1381 return ret ? -EPIPE : 0;
1293 return ret ? -EPIPE : ret;
1294} 1382}
1295 1383
1296static ssize_t fimc_md_sysfs_show(struct device *dev, 1384static ssize_t fimc_md_sysfs_show(struct device *dev,
@@ -1370,6 +1458,7 @@ static int fimc_md_probe(struct platform_device *pdev)
1370 1458
1371 spin_lock_init(&fmd->slock); 1459 spin_lock_init(&fmd->slock);
1372 fmd->pdev = pdev; 1460 fmd->pdev = pdev;
1461 INIT_LIST_HEAD(&fmd->pipelines);
1373 1462
1374 strlcpy(fmd->media_dev.model, "SAMSUNG S5P FIMC", 1463 strlcpy(fmd->media_dev.model, "SAMSUNG S5P FIMC",
1375 sizeof(fmd->media_dev.model)); 1464 sizeof(fmd->media_dev.model));
@@ -1457,6 +1546,7 @@ static int fimc_md_remove(struct platform_device *pdev)
1457 return 0; 1546 return 0;
1458 device_remove_file(&pdev->dev, &dev_attr_subdev_conf_mode); 1547 device_remove_file(&pdev->dev, &dev_attr_subdev_conf_mode);
1459 fimc_md_unregister_entities(fmd); 1548 fimc_md_unregister_entities(fmd);
1549 fimc_md_pipelines_free(fmd);
1460 media_device_unregister(&fmd->media_dev); 1550 media_device_unregister(&fmd->media_dev);
1461 fimc_md_put_clocks(fmd); 1551 fimc_md_put_clocks(fmd);
1462 return 0; 1552 return 0;
diff --git a/drivers/media/platform/exynos4-is/media-dev.h b/drivers/media/platform/exynos4-is/media-dev.h
index 44d86b61d660..62599fd7756f 100644
--- a/drivers/media/platform/exynos4-is/media-dev.h
+++ b/drivers/media/platform/exynos4-is/media-dev.h
@@ -18,6 +18,7 @@
18#include <media/media-entity.h> 18#include <media/media-entity.h>
19#include <media/v4l2-device.h> 19#include <media/v4l2-device.h>
20#include <media/v4l2-subdev.h> 20#include <media/v4l2-subdev.h>
21#include <media/s5p_fimc.h>
21 22
22#include "fimc-core.h" 23#include "fimc-core.h"
23#include "fimc-lite.h" 24#include "fimc-lite.h"
@@ -40,6 +41,29 @@ enum {
40 FIMC_MAX_WBCLKS 41 FIMC_MAX_WBCLKS
41}; 42};
42 43
44enum fimc_subdev_index {
45 IDX_SENSOR,
46 IDX_CSIS,
47 IDX_FLITE,
48 IDX_IS_ISP,
49 IDX_FIMC,
50 IDX_MAX,
51};
52
53/*
54 * This structure represents a chain of media entities, including a data
55 * source entity (e.g. an image sensor subdevice), a data capture entity
56 * - a video capture device node and any remaining entities.
57 */
58struct fimc_pipeline {
59 struct exynos_media_pipeline ep;
60 struct list_head list;
61 struct media_entity *vdev_entity;
62 struct v4l2_subdev *subdevs[IDX_MAX];
63};
64
65#define to_fimc_pipeline(_ep) container_of(_ep, struct fimc_pipeline, ep)
66
43struct fimc_csis_info { 67struct fimc_csis_info {
44 struct v4l2_subdev *sd; 68 struct v4l2_subdev *sd;
45 int id; 69 int id;
@@ -104,17 +128,11 @@ struct fimc_md {
104 struct pinctrl_state *state_idle; 128 struct pinctrl_state *state_idle;
105 } pinctl; 129 } pinctl;
106 bool user_subdev_api; 130 bool user_subdev_api;
131
107 spinlock_t slock; 132 spinlock_t slock;
133 struct list_head pipelines;
108}; 134};
109 135
110#define is_subdev_pad(pad) (pad == NULL || \
111 media_entity_type(pad->entity) == MEDIA_ENT_T_V4L2_SUBDEV)
112
113#define me_subtype(me) \
114 ((me->type) & (MEDIA_ENT_TYPE_MASK | MEDIA_ENT_SUBTYPE_MASK))
115
116#define subdev_has_devnode(__sd) (__sd->flags & V4L2_SUBDEV_FL_HAS_DEVNODE)
117
118static inline 136static inline
119struct fimc_sensor_info *source_to_sensor_info(struct fimc_source_info *si) 137struct fimc_sensor_info *source_to_sensor_info(struct fimc_source_info *si)
120{ 138{
@@ -127,14 +145,14 @@ static inline struct fimc_md *entity_to_fimc_mdev(struct media_entity *me)
127 container_of(me->parent, struct fimc_md, media_dev); 145 container_of(me->parent, struct fimc_md, media_dev);
128} 146}
129 147
130static inline void fimc_md_graph_lock(struct fimc_dev *fimc) 148static inline void fimc_md_graph_lock(struct exynos_video_entity *ve)
131{ 149{
132 mutex_lock(&fimc->vid_cap.vfd.entity.parent->graph_mutex); 150 mutex_lock(&ve->vdev.entity.parent->graph_mutex);
133} 151}
134 152
135static inline void fimc_md_graph_unlock(struct fimc_dev *fimc) 153static inline void fimc_md_graph_unlock(struct exynos_video_entity *ve)
136{ 154{
137 mutex_unlock(&fimc->vid_cap.vfd.entity.parent->graph_mutex); 155 mutex_unlock(&ve->vdev.entity.parent->graph_mutex);
138} 156}
139 157
140int fimc_md_set_camclk(struct v4l2_subdev *sd, bool on); 158int fimc_md_set_camclk(struct v4l2_subdev *sd, bool on);
@@ -149,4 +167,16 @@ static inline bool fimc_md_is_isp_available(struct device_node *node)
149#define fimc_md_is_isp_available(node) (false) 167#define fimc_md_is_isp_available(node) (false)
150#endif /* CONFIG_OF */ 168#endif /* CONFIG_OF */
151 169
170static inline struct v4l2_subdev *__fimc_md_get_subdev(
171 struct exynos_media_pipeline *ep,
172 unsigned int index)
173{
174 struct fimc_pipeline *p = to_fimc_pipeline(ep);
175
176 if (!p || index >= IDX_MAX)
177 return NULL;
178 else
179 return p->subdevs[index];
180}
181
152#endif 182#endif
diff --git a/drivers/media/platform/exynos4-is/mipi-csis.c b/drivers/media/platform/exynos4-is/mipi-csis.c
index 254d70fe762a..0914230b42de 100644
--- a/drivers/media/platform/exynos4-is/mipi-csis.c
+++ b/drivers/media/platform/exynos4-is/mipi-csis.c
@@ -1,8 +1,8 @@
1/* 1/*
2 * Samsung S5P/EXYNOS4 SoC series MIPI-CSI receiver driver 2 * Samsung S5P/EXYNOS SoC series MIPI-CSI receiver driver
3 * 3 *
4 * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. 4 * Copyright (C) 2011 - 2013 Samsung Electronics Co., Ltd.
5 * Sylwester Nawrocki <s.nawrocki@samsung.com> 5 * Author: Sylwester Nawrocki <s.nawrocki@samsung.com>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as 8 * it under the terms of the GNU General Public License version 2 as
@@ -66,11 +66,12 @@ MODULE_PARM_DESC(debug, "Debug level (0-2)");
66 66
67/* Interrupt mask */ 67/* Interrupt mask */
68#define S5PCSIS_INTMSK 0x10 68#define S5PCSIS_INTMSK 0x10
69#define S5PCSIS_INTMSK_EN_ALL 0xf000103f
70#define S5PCSIS_INTMSK_EVEN_BEFORE (1 << 31) 69#define S5PCSIS_INTMSK_EVEN_BEFORE (1 << 31)
71#define S5PCSIS_INTMSK_EVEN_AFTER (1 << 30) 70#define S5PCSIS_INTMSK_EVEN_AFTER (1 << 30)
72#define S5PCSIS_INTMSK_ODD_BEFORE (1 << 29) 71#define S5PCSIS_INTMSK_ODD_BEFORE (1 << 29)
73#define S5PCSIS_INTMSK_ODD_AFTER (1 << 28) 72#define S5PCSIS_INTMSK_ODD_AFTER (1 << 28)
73#define S5PCSIS_INTMSK_FRAME_START (1 << 27)
74#define S5PCSIS_INTMSK_FRAME_END (1 << 26)
74#define S5PCSIS_INTMSK_ERR_SOT_HS (1 << 12) 75#define S5PCSIS_INTMSK_ERR_SOT_HS (1 << 12)
75#define S5PCSIS_INTMSK_ERR_LOST_FS (1 << 5) 76#define S5PCSIS_INTMSK_ERR_LOST_FS (1 << 5)
76#define S5PCSIS_INTMSK_ERR_LOST_FE (1 << 4) 77#define S5PCSIS_INTMSK_ERR_LOST_FE (1 << 4)
@@ -78,6 +79,8 @@ MODULE_PARM_DESC(debug, "Debug level (0-2)");
78#define S5PCSIS_INTMSK_ERR_ECC (1 << 2) 79#define S5PCSIS_INTMSK_ERR_ECC (1 << 2)
79#define S5PCSIS_INTMSK_ERR_CRC (1 << 1) 80#define S5PCSIS_INTMSK_ERR_CRC (1 << 1)
80#define S5PCSIS_INTMSK_ERR_UNKNOWN (1 << 0) 81#define S5PCSIS_INTMSK_ERR_UNKNOWN (1 << 0)
82#define S5PCSIS_INTMSK_EXYNOS4_EN_ALL 0xf000103f
83#define S5PCSIS_INTMSK_EXYNOS5_EN_ALL 0xfc00103f
81 84
82/* Interrupt source */ 85/* Interrupt source */
83#define S5PCSIS_INTSRC 0x14 86#define S5PCSIS_INTSRC 0x14
@@ -88,6 +91,8 @@ MODULE_PARM_DESC(debug, "Debug level (0-2)");
88#define S5PCSIS_INTSRC_ODD_AFTER (1 << 28) 91#define S5PCSIS_INTSRC_ODD_AFTER (1 << 28)
89#define S5PCSIS_INTSRC_ODD (0x3 << 28) 92#define S5PCSIS_INTSRC_ODD (0x3 << 28)
90#define S5PCSIS_INTSRC_NON_IMAGE_DATA (0xff << 28) 93#define S5PCSIS_INTSRC_NON_IMAGE_DATA (0xff << 28)
94#define S5PCSIS_INTSRC_FRAME_START (1 << 27)
95#define S5PCSIS_INTSRC_FRAME_END (1 << 26)
91#define S5PCSIS_INTSRC_ERR_SOT_HS (0xf << 12) 96#define S5PCSIS_INTSRC_ERR_SOT_HS (0xf << 12)
92#define S5PCSIS_INTSRC_ERR_LOST_FS (1 << 5) 97#define S5PCSIS_INTSRC_ERR_LOST_FS (1 << 5)
93#define S5PCSIS_INTSRC_ERR_LOST_FE (1 << 4) 98#define S5PCSIS_INTSRC_ERR_LOST_FE (1 << 4)
@@ -151,6 +156,9 @@ static const struct s5pcsis_event s5pcsis_events[] = {
151 { S5PCSIS_INTSRC_EVEN_AFTER, "Non-image data after even frame" }, 156 { S5PCSIS_INTSRC_EVEN_AFTER, "Non-image data after even frame" },
152 { S5PCSIS_INTSRC_ODD_BEFORE, "Non-image data before odd frame" }, 157 { S5PCSIS_INTSRC_ODD_BEFORE, "Non-image data before odd frame" },
153 { S5PCSIS_INTSRC_ODD_AFTER, "Non-image data after odd frame" }, 158 { S5PCSIS_INTSRC_ODD_AFTER, "Non-image data after odd frame" },
159 /* Frame start/end */
160 { S5PCSIS_INTSRC_FRAME_START, "Frame Start" },
161 { S5PCSIS_INTSRC_FRAME_END, "Frame End" },
154}; 162};
155#define S5PCSIS_NUM_EVENTS ARRAY_SIZE(s5pcsis_events) 163#define S5PCSIS_NUM_EVENTS ARRAY_SIZE(s5pcsis_events)
156 164
@@ -159,6 +167,11 @@ struct csis_pktbuf {
159 unsigned int len; 167 unsigned int len;
160}; 168};
161 169
170struct csis_drvdata {
171 /* Mask of all used interrupts in S5PCSIS_INTMSK register */
172 u32 interrupt_mask;
173};
174
162/** 175/**
163 * struct csis_state - the driver's internal state data structure 176 * struct csis_state - the driver's internal state data structure
164 * @lock: mutex serializing the subdev and power management operations, 177 * @lock: mutex serializing the subdev and power management operations,
@@ -171,6 +184,7 @@ struct csis_pktbuf {
171 * @supplies: CSIS regulator supplies 184 * @supplies: CSIS regulator supplies
172 * @clock: CSIS clocks 185 * @clock: CSIS clocks
173 * @irq: requested s5p-mipi-csis irq number 186 * @irq: requested s5p-mipi-csis irq number
187 * @interrupt_mask: interrupt mask of the all used interrupts
174 * @flags: the state variable for power and streaming control 188 * @flags: the state variable for power and streaming control
175 * @clock_frequency: device bus clock frequency 189 * @clock_frequency: device bus clock frequency
176 * @hs_settle: HS-RX settle time 190 * @hs_settle: HS-RX settle time
@@ -193,6 +207,7 @@ struct csis_state {
193 struct regulator_bulk_data supplies[CSIS_NUM_SUPPLIES]; 207 struct regulator_bulk_data supplies[CSIS_NUM_SUPPLIES];
194 struct clk *clock[NUM_CSIS_CLOCKS]; 208 struct clk *clock[NUM_CSIS_CLOCKS];
195 int irq; 209 int irq;
210 u32 interrupt_mask;
196 u32 flags; 211 u32 flags;
197 212
198 u32 clk_frequency; 213 u32 clk_frequency;
@@ -274,9 +289,10 @@ static const struct csis_pix_format *find_csis_format(
274static void s5pcsis_enable_interrupts(struct csis_state *state, bool on) 289static void s5pcsis_enable_interrupts(struct csis_state *state, bool on)
275{ 290{
276 u32 val = s5pcsis_read(state, S5PCSIS_INTMSK); 291 u32 val = s5pcsis_read(state, S5PCSIS_INTMSK);
277 292 if (on)
278 val = on ? val | S5PCSIS_INTMSK_EN_ALL : 293 val |= state->interrupt_mask;
279 val & ~S5PCSIS_INTMSK_EN_ALL; 294 else
295 val &= ~state->interrupt_mask;
280 s5pcsis_write(state, S5PCSIS_INTMSK, val); 296 s5pcsis_write(state, S5PCSIS_INTMSK, val);
281} 297}
282 298
@@ -771,8 +787,12 @@ static int s5pcsis_parse_dt(struct platform_device *pdev,
771#define s5pcsis_parse_dt(pdev, state) (-ENOSYS) 787#define s5pcsis_parse_dt(pdev, state) (-ENOSYS)
772#endif 788#endif
773 789
790static const struct of_device_id s5pcsis_of_match[];
791
774static int s5pcsis_probe(struct platform_device *pdev) 792static int s5pcsis_probe(struct platform_device *pdev)
775{ 793{
794 const struct of_device_id *of_id;
795 const struct csis_drvdata *drv_data;
776 struct device *dev = &pdev->dev; 796 struct device *dev = &pdev->dev;
777 struct resource *mem_res; 797 struct resource *mem_res;
778 struct csis_state *state; 798 struct csis_state *state;
@@ -787,10 +807,19 @@ static int s5pcsis_probe(struct platform_device *pdev)
787 spin_lock_init(&state->slock); 807 spin_lock_init(&state->slock);
788 state->pdev = pdev; 808 state->pdev = pdev;
789 809
790 if (dev->of_node) 810 if (dev->of_node) {
811 of_id = of_match_node(s5pcsis_of_match, dev->of_node);
812 if (WARN_ON(of_id == NULL))
813 return -EINVAL;
814
815 drv_data = of_id->data;
816 state->interrupt_mask = drv_data->interrupt_mask;
817
791 ret = s5pcsis_parse_dt(pdev, state); 818 ret = s5pcsis_parse_dt(pdev, state);
792 else 819 } else {
793 ret = s5pcsis_get_platform_data(pdev, state); 820 ret = s5pcsis_get_platform_data(pdev, state);
821 }
822
794 if (ret < 0) 823 if (ret < 0)
795 return ret; 824 return ret;
796 825
@@ -994,9 +1023,25 @@ static const struct dev_pm_ops s5pcsis_pm_ops = {
994 SET_SYSTEM_SLEEP_PM_OPS(s5pcsis_suspend, s5pcsis_resume) 1023 SET_SYSTEM_SLEEP_PM_OPS(s5pcsis_suspend, s5pcsis_resume)
995}; 1024};
996 1025
1026static const struct csis_drvdata exynos4_csis_drvdata = {
1027 .interrupt_mask = S5PCSIS_INTMSK_EXYNOS4_EN_ALL,
1028};
1029
1030static const struct csis_drvdata exynos5_csis_drvdata = {
1031 .interrupt_mask = S5PCSIS_INTMSK_EXYNOS5_EN_ALL,
1032};
1033
997static const struct of_device_id s5pcsis_of_match[] = { 1034static const struct of_device_id s5pcsis_of_match[] = {
998 { .compatible = "samsung,s5pv210-csis" }, 1035 {
999 { .compatible = "samsung,exynos4210-csis" }, 1036 .compatible = "samsung,s5pv210-csis",
1037 .data = &exynos4_csis_drvdata,
1038 }, {
1039 .compatible = "samsung,exynos4210-csis",
1040 .data = &exynos4_csis_drvdata,
1041 }, {
1042 .compatible = "samsung,exynos5250-csis",
1043 .data = &exynos5_csis_drvdata,
1044 },
1000 { /* sentinel */ }, 1045 { /* sentinel */ },
1001}; 1046};
1002MODULE_DEVICE_TABLE(of, s5pcsis_of_match); 1047MODULE_DEVICE_TABLE(of, s5pcsis_of_match);
diff --git a/drivers/media/platform/fsl-viu.c b/drivers/media/platform/fsl-viu.c
index 3a6a0dcdc3e4..221ec428a01e 100644
--- a/drivers/media/platform/fsl-viu.c
+++ b/drivers/media/platform/fsl-viu.c
@@ -1475,7 +1475,6 @@ static struct video_device viu_template = {
1475 .release = video_device_release, 1475 .release = video_device_release,
1476 1476
1477 .tvnorms = V4L2_STD_NTSC_M | V4L2_STD_PAL, 1477 .tvnorms = V4L2_STD_NTSC_M | V4L2_STD_PAL,
1478 .current_norm = V4L2_STD_NTSC_M,
1479}; 1478};
1480 1479
1481static int viu_of_probe(struct platform_device *op) 1480static int viu_of_probe(struct platform_device *op)
@@ -1546,6 +1545,7 @@ static int viu_of_probe(struct platform_device *op)
1546 viu_dev->vidq.timeout.function = viu_vid_timeout; 1545 viu_dev->vidq.timeout.function = viu_vid_timeout;
1547 viu_dev->vidq.timeout.data = (unsigned long)viu_dev; 1546 viu_dev->vidq.timeout.data = (unsigned long)viu_dev;
1548 init_timer(&viu_dev->vidq.timeout); 1547 init_timer(&viu_dev->vidq.timeout);
1548 viu_dev->std = V4L2_STD_NTSC_M;
1549 viu_dev->first = 1; 1549 viu_dev->first = 1;
1550 1550
1551 /* Allocate memory for video device */ 1551 /* Allocate memory for video device */
diff --git a/drivers/media/platform/indycam.c b/drivers/media/platform/indycam.c
index 548236333cce..f1d192bbcb4c 100644
--- a/drivers/media/platform/indycam.c
+++ b/drivers/media/platform/indycam.c
@@ -23,7 +23,6 @@
23#include <linux/videodev2.h> 23#include <linux/videodev2.h>
24#include <linux/i2c.h> 24#include <linux/i2c.h>
25#include <media/v4l2-device.h> 25#include <media/v4l2-device.h>
26#include <media/v4l2-chip-ident.h>
27 26
28#include "indycam.h" 27#include "indycam.h"
29 28
@@ -283,20 +282,9 @@ static int indycam_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
283 282
284/* I2C-interface */ 283/* I2C-interface */
285 284
286static int indycam_g_chip_ident(struct v4l2_subdev *sd,
287 struct v4l2_dbg_chip_ident *chip)
288{
289 struct i2c_client *client = v4l2_get_subdevdata(sd);
290 struct indycam *camera = to_indycam(sd);
291
292 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_INDYCAM,
293 camera->version);
294}
295
296/* ----------------------------------------------------------------------- */ 285/* ----------------------------------------------------------------------- */
297 286
298static const struct v4l2_subdev_core_ops indycam_core_ops = { 287static const struct v4l2_subdev_core_ops indycam_core_ops = {
299 .g_chip_ident = indycam_g_chip_ident,
300 .g_ctrl = indycam_g_ctrl, 288 .g_ctrl = indycam_g_ctrl,
301 .s_ctrl = indycam_s_ctrl, 289 .s_ctrl = indycam_s_ctrl,
302}; 290};
diff --git a/drivers/media/platform/m2m-deinterlace.c b/drivers/media/platform/m2m-deinterlace.c
index 758564649589..540516ca872c 100644
--- a/drivers/media/platform/m2m-deinterlace.c
+++ b/drivers/media/platform/m2m-deinterlace.c
@@ -1033,6 +1033,7 @@ static int deinterlace_probe(struct platform_device *pdev)
1033 1033
1034 *vfd = deinterlace_videodev; 1034 *vfd = deinterlace_videodev;
1035 vfd->lock = &pcdev->dev_mutex; 1035 vfd->lock = &pcdev->dev_mutex;
1036 vfd->v4l2_dev = &pcdev->v4l2_dev;
1036 1037
1037 ret = video_register_device(vfd, VFL_TYPE_GRABBER, 0); 1038 ret = video_register_device(vfd, VFL_TYPE_GRABBER, 0);
1038 if (ret) { 1039 if (ret) {
diff --git a/drivers/media/platform/marvell-ccic/cafe-driver.c b/drivers/media/platform/marvell-ccic/cafe-driver.c
index d030f9beae88..1f079ff33d4b 100644
--- a/drivers/media/platform/marvell-ccic/cafe-driver.c
+++ b/drivers/media/platform/marvell-ccic/cafe-driver.c
@@ -27,7 +27,6 @@
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/videodev2.h> 28#include <linux/videodev2.h>
29#include <media/v4l2-device.h> 29#include <media/v4l2-device.h>
30#include <media/v4l2-chip-ident.h>
31#include <linux/device.h> 30#include <linux/device.h>
32#include <linux/wait.h> 31#include <linux/wait.h>
33#include <linux/delay.h> 32#include <linux/delay.h>
@@ -469,7 +468,7 @@ static int cafe_pci_probe(struct pci_dev *pdev,
469 goto out; 468 goto out;
470 cam->pdev = pdev; 469 cam->pdev = pdev;
471 mcam = &cam->mcam; 470 mcam = &cam->mcam;
472 mcam->chip_id = V4L2_IDENT_CAFE; 471 mcam->chip_id = MCAM_CAFE;
473 spin_lock_init(&mcam->dev_lock); 472 spin_lock_init(&mcam->dev_lock);
474 init_waitqueue_head(&cam->smbus_wait); 473 init_waitqueue_head(&cam->smbus_wait);
475 mcam->plat_power_up = cafe_ctlr_power_up; 474 mcam->plat_power_up = cafe_ctlr_power_up;
@@ -501,6 +500,7 @@ static int cafe_pci_probe(struct pci_dev *pdev,
501 printk(KERN_ERR "Unable to ioremap cafe-ccic regs\n"); 500 printk(KERN_ERR "Unable to ioremap cafe-ccic regs\n");
502 goto out_disable; 501 goto out_disable;
503 } 502 }
503 mcam->regs_size = pci_resource_len(pdev, 0);
504 ret = request_irq(pdev->irq, cafe_irq, IRQF_SHARED, "cafe-ccic", cam); 504 ret = request_irq(pdev->irq, cafe_irq, IRQF_SHARED, "cafe-ccic", cam);
505 if (ret) 505 if (ret)
506 goto out_iounmap; 506 goto out_iounmap;
diff --git a/drivers/media/platform/marvell-ccic/mcam-core.c b/drivers/media/platform/marvell-ccic/mcam-core.c
index 64ab91edfb81..0821ed08c122 100644
--- a/drivers/media/platform/marvell-ccic/mcam-core.c
+++ b/drivers/media/platform/marvell-ccic/mcam-core.c
@@ -23,7 +23,6 @@
23#include <media/v4l2-device.h> 23#include <media/v4l2-device.h>
24#include <media/v4l2-ioctl.h> 24#include <media/v4l2-ioctl.h>
25#include <media/v4l2-ctrls.h> 25#include <media/v4l2-ctrls.h>
26#include <media/v4l2-chip-ident.h>
27#include <media/ov7670.h> 26#include <media/ov7670.h>
28#include <media/videobuf2-vmalloc.h> 27#include <media/videobuf2-vmalloc.h>
29#include <media/videobuf2-dma-contig.h> 28#include <media/videobuf2-dma-contig.h>
@@ -336,7 +335,7 @@ static void mcam_ctlr_dma_vmalloc(struct mcam_camera *cam)
336 mcam_reg_clear_bit(cam, REG_CTRL1, C1_TWOBUFS); 335 mcam_reg_clear_bit(cam, REG_CTRL1, C1_TWOBUFS);
337 } else 336 } else
338 mcam_reg_set_bit(cam, REG_CTRL1, C1_TWOBUFS); 337 mcam_reg_set_bit(cam, REG_CTRL1, C1_TWOBUFS);
339 if (cam->chip_id == V4L2_IDENT_CAFE) 338 if (cam->chip_id == MCAM_CAFE)
340 mcam_reg_write(cam, REG_UBAR, 0); /* 32 bits only */ 339 mcam_reg_write(cam, REG_UBAR, 0); /* 32 bits only */
341} 340}
342 341
@@ -796,7 +795,6 @@ static int __mcam_cam_reset(struct mcam_camera *cam)
796 */ 795 */
797static int mcam_cam_init(struct mcam_camera *cam) 796static int mcam_cam_init(struct mcam_camera *cam)
798{ 797{
799 struct v4l2_dbg_chip_ident chip;
800 int ret; 798 int ret;
801 799
802 mutex_lock(&cam->s_mutex); 800 mutex_lock(&cam->s_mutex);
@@ -804,24 +802,8 @@ static int mcam_cam_init(struct mcam_camera *cam)
804 cam_warn(cam, "Cam init with device in funky state %d", 802 cam_warn(cam, "Cam init with device in funky state %d",
805 cam->state); 803 cam->state);
806 ret = __mcam_cam_reset(cam); 804 ret = __mcam_cam_reset(cam);
807 if (ret) 805 /* Get/set parameters? */
808 goto out;
809 chip.ident = V4L2_IDENT_NONE;
810 chip.match.type = V4L2_CHIP_MATCH_I2C_ADDR;
811 chip.match.addr = cam->sensor_addr;
812 ret = sensor_call(cam, core, g_chip_ident, &chip);
813 if (ret)
814 goto out;
815 cam->sensor_type = chip.ident;
816 if (cam->sensor_type != V4L2_IDENT_OV7670) {
817 cam_err(cam, "Unsupported sensor type 0x%x", cam->sensor_type);
818 ret = -EINVAL;
819 goto out;
820 }
821/* Get/set parameters? */
822 ret = 0;
823 cam->state = S_IDLE; 806 cam->state = S_IDLE;
824out:
825 mcam_ctlr_power_down(cam); 807 mcam_ctlr_power_down(cam);
826 mutex_unlock(&cam->s_mutex); 808 mutex_unlock(&cam->s_mutex);
827 return ret; 809 return ret;
@@ -1362,6 +1344,12 @@ static int mcam_vidioc_s_std(struct file *filp, void *priv, v4l2_std_id a)
1362 return 0; 1344 return 0;
1363} 1345}
1364 1346
1347static int mcam_vidioc_g_std(struct file *filp, void *priv, v4l2_std_id *a)
1348{
1349 *a = V4L2_STD_NTSC_M;
1350 return 0;
1351}
1352
1365/* 1353/*
1366 * G/S_PARM. Most of this is done by the sensor, but we are 1354 * G/S_PARM. Most of this is done by the sensor, but we are
1367 * the level which controls the number of read buffers. 1355 * the level which controls the number of read buffers.
@@ -1392,20 +1380,6 @@ static int mcam_vidioc_s_parm(struct file *filp, void *priv,
1392 return ret; 1380 return ret;
1393} 1381}
1394 1382
1395static int mcam_vidioc_g_chip_ident(struct file *file, void *priv,
1396 struct v4l2_dbg_chip_ident *chip)
1397{
1398 struct mcam_camera *cam = priv;
1399
1400 chip->ident = V4L2_IDENT_NONE;
1401 chip->revision = 0;
1402 if (v4l2_chip_match_host(&chip->match)) {
1403 chip->ident = cam->chip_id;
1404 return 0;
1405 }
1406 return sensor_call(cam, core, g_chip_ident, chip);
1407}
1408
1409static int mcam_vidioc_enum_framesizes(struct file *filp, void *priv, 1383static int mcam_vidioc_enum_framesizes(struct file *filp, void *priv,
1410 struct v4l2_frmsizeenum *sizes) 1384 struct v4l2_frmsizeenum *sizes)
1411{ 1385{
@@ -1436,12 +1410,11 @@ static int mcam_vidioc_g_register(struct file *file, void *priv,
1436{ 1410{
1437 struct mcam_camera *cam = priv; 1411 struct mcam_camera *cam = priv;
1438 1412
1439 if (v4l2_chip_match_host(&reg->match)) { 1413 if (reg->reg > cam->regs_size - 4)
1440 reg->val = mcam_reg_read(cam, reg->reg); 1414 return -EINVAL;
1441 reg->size = 4; 1415 reg->val = mcam_reg_read(cam, reg->reg);
1442 return 0; 1416 reg->size = 4;
1443 } 1417 return 0;
1444 return sensor_call(cam, core, g_register, reg);
1445} 1418}
1446 1419
1447static int mcam_vidioc_s_register(struct file *file, void *priv, 1420static int mcam_vidioc_s_register(struct file *file, void *priv,
@@ -1449,11 +1422,10 @@ static int mcam_vidioc_s_register(struct file *file, void *priv,
1449{ 1422{
1450 struct mcam_camera *cam = priv; 1423 struct mcam_camera *cam = priv;
1451 1424
1452 if (v4l2_chip_match_host(&reg->match)) { 1425 if (reg->reg > cam->regs_size - 4)
1453 mcam_reg_write(cam, reg->reg, reg->val); 1426 return -EINVAL;
1454 return 0; 1427 mcam_reg_write(cam, reg->reg, reg->val);
1455 } 1428 return 0;
1456 return sensor_call(cam, core, s_register, reg);
1457} 1429}
1458#endif 1430#endif
1459 1431
@@ -1467,6 +1439,7 @@ static const struct v4l2_ioctl_ops mcam_v4l_ioctl_ops = {
1467 .vidioc_g_input = mcam_vidioc_g_input, 1439 .vidioc_g_input = mcam_vidioc_g_input,
1468 .vidioc_s_input = mcam_vidioc_s_input, 1440 .vidioc_s_input = mcam_vidioc_s_input,
1469 .vidioc_s_std = mcam_vidioc_s_std, 1441 .vidioc_s_std = mcam_vidioc_s_std,
1442 .vidioc_g_std = mcam_vidioc_g_std,
1470 .vidioc_reqbufs = mcam_vidioc_reqbufs, 1443 .vidioc_reqbufs = mcam_vidioc_reqbufs,
1471 .vidioc_querybuf = mcam_vidioc_querybuf, 1444 .vidioc_querybuf = mcam_vidioc_querybuf,
1472 .vidioc_qbuf = mcam_vidioc_qbuf, 1445 .vidioc_qbuf = mcam_vidioc_qbuf,
@@ -1477,7 +1450,6 @@ static const struct v4l2_ioctl_ops mcam_v4l_ioctl_ops = {
1477 .vidioc_s_parm = mcam_vidioc_s_parm, 1450 .vidioc_s_parm = mcam_vidioc_s_parm,
1478 .vidioc_enum_framesizes = mcam_vidioc_enum_framesizes, 1451 .vidioc_enum_framesizes = mcam_vidioc_enum_framesizes,
1479 .vidioc_enum_frameintervals = mcam_vidioc_enum_frameintervals, 1452 .vidioc_enum_frameintervals = mcam_vidioc_enum_frameintervals,
1480 .vidioc_g_chip_ident = mcam_vidioc_g_chip_ident,
1481#ifdef CONFIG_VIDEO_ADV_DEBUG 1453#ifdef CONFIG_VIDEO_ADV_DEBUG
1482 .vidioc_g_register = mcam_vidioc_g_register, 1454 .vidioc_g_register = mcam_vidioc_g_register,
1483 .vidioc_s_register = mcam_vidioc_s_register, 1455 .vidioc_s_register = mcam_vidioc_s_register,
@@ -1593,7 +1565,6 @@ static const struct v4l2_file_operations mcam_v4l_fops = {
1593static struct video_device mcam_v4l_template = { 1565static struct video_device mcam_v4l_template = {
1594 .name = "mcam", 1566 .name = "mcam",
1595 .tvnorms = V4L2_STD_NTSC_M, 1567 .tvnorms = V4L2_STD_NTSC_M,
1596 .current_norm = V4L2_STD_NTSC_M, /* make mplayer happy */
1597 1568
1598 .fops = &mcam_v4l_fops, 1569 .fops = &mcam_v4l_fops,
1599 .ioctl_ops = &mcam_v4l_ioctl_ops, 1570 .ioctl_ops = &mcam_v4l_ioctl_ops,
@@ -1695,7 +1666,7 @@ int mccic_register(struct mcam_camera *cam)
1695 if (buffer_mode >= 0) 1666 if (buffer_mode >= 0)
1696 cam->buffer_mode = buffer_mode; 1667 cam->buffer_mode = buffer_mode;
1697 if (cam->buffer_mode == B_DMA_sg && 1668 if (cam->buffer_mode == B_DMA_sg &&
1698 cam->chip_id == V4L2_IDENT_CAFE) { 1669 cam->chip_id == MCAM_CAFE) {
1699 printk(KERN_ERR "marvell-cam: Cafe can't do S/G I/O, " 1670 printk(KERN_ERR "marvell-cam: Cafe can't do S/G I/O, "
1700 "attempting vmalloc mode instead\n"); 1671 "attempting vmalloc mode instead\n");
1701 cam->buffer_mode = B_vmalloc; 1672 cam->buffer_mode = B_vmalloc;
diff --git a/drivers/media/platform/marvell-ccic/mcam-core.h b/drivers/media/platform/marvell-ccic/mcam-core.h
index 01dec9e5fc2b..520c8ded9443 100644
--- a/drivers/media/platform/marvell-ccic/mcam-core.h
+++ b/drivers/media/platform/marvell-ccic/mcam-core.h
@@ -53,6 +53,11 @@ enum mcam_buffer_mode {
53 B_DMA_sg = 2 53 B_DMA_sg = 2
54}; 54};
55 55
56enum mcam_chip_id {
57 MCAM_CAFE,
58 MCAM_ARMADA610,
59};
60
56/* 61/*
57 * Is a given buffer mode supported by the current kernel configuration? 62 * Is a given buffer mode supported by the current kernel configuration?
58 */ 63 */
@@ -96,9 +101,10 @@ struct mcam_camera {
96 */ 101 */
97 struct i2c_adapter *i2c_adapter; 102 struct i2c_adapter *i2c_adapter;
98 unsigned char __iomem *regs; 103 unsigned char __iomem *regs;
104 unsigned regs_size; /* size in bytes of the register space */
99 spinlock_t dev_lock; 105 spinlock_t dev_lock;
100 struct device *dev; /* For messages, dma alloc */ 106 struct device *dev; /* For messages, dma alloc */
101 unsigned int chip_id; 107 enum mcam_chip_id chip_id;
102 short int clock_speed; /* Sensor clock speed, default 30 */ 108 short int clock_speed; /* Sensor clock speed, default 30 */
103 short int use_smbus; /* SMBUS or straight I2c? */ 109 short int use_smbus; /* SMBUS or straight I2c? */
104 enum mcam_buffer_mode buffer_mode; 110 enum mcam_buffer_mode buffer_mode;
@@ -152,7 +158,6 @@ struct mcam_camera {
152 void (*frame_complete)(struct mcam_camera *cam, int frame); 158 void (*frame_complete)(struct mcam_camera *cam, int frame);
153 159
154 /* Current operating parameters */ 160 /* Current operating parameters */
155 u32 sensor_type; /* Currently ov7670 only */
156 struct v4l2_pix_format pix_format; 161 struct v4l2_pix_format pix_format;
157 enum v4l2_mbus_pixelcode mbus_code; 162 enum v4l2_mbus_pixelcode mbus_code;
158 163
diff --git a/drivers/media/platform/marvell-ccic/mmp-driver.c b/drivers/media/platform/marvell-ccic/mmp-driver.c
index c4c17fe76c0d..a634888271cd 100644
--- a/drivers/media/platform/marvell-ccic/mmp-driver.c
+++ b/drivers/media/platform/marvell-ccic/mmp-driver.c
@@ -18,7 +18,6 @@
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/videodev2.h> 19#include <linux/videodev2.h>
20#include <media/v4l2-device.h> 20#include <media/v4l2-device.h>
21#include <media/v4l2-chip-ident.h>
22#include <media/mmp-camera.h> 21#include <media/mmp-camera.h>
23#include <linux/device.h> 22#include <linux/device.h>
24#include <linux/platform_device.h> 23#include <linux/platform_device.h>
@@ -185,7 +184,7 @@ static int mmpcam_probe(struct platform_device *pdev)
185 mcam->plat_power_down = mmpcam_power_down; 184 mcam->plat_power_down = mmpcam_power_down;
186 mcam->dev = &pdev->dev; 185 mcam->dev = &pdev->dev;
187 mcam->use_smbus = 0; 186 mcam->use_smbus = 0;
188 mcam->chip_id = V4L2_IDENT_ARMADA610; 187 mcam->chip_id = MCAM_ARMADA610;
189 mcam->buffer_mode = B_DMA_sg; 188 mcam->buffer_mode = B_DMA_sg;
190 spin_lock_init(&mcam->dev_lock); 189 spin_lock_init(&mcam->dev_lock);
191 /* 190 /*
@@ -203,6 +202,7 @@ static int mmpcam_probe(struct platform_device *pdev)
203 ret = -ENODEV; 202 ret = -ENODEV;
204 goto out_free; 203 goto out_free;
205 } 204 }
205 mcam->regs_size = resource_size(res);
206 /* 206 /*
207 * Power/clock memory is elsewhere; get it too. Perhaps this 207 * Power/clock memory is elsewhere; get it too. Perhaps this
208 * should really be managed outside of this driver? 208 * should really be managed outside of this driver?
diff --git a/drivers/media/platform/mem2mem_testdev.c b/drivers/media/platform/mem2mem_testdev.c
index 4cc7f65d7d76..6a17676f9d72 100644
--- a/drivers/media/platform/mem2mem_testdev.c
+++ b/drivers/media/platform/mem2mem_testdev.c
@@ -1051,6 +1051,7 @@ static int m2mtest_probe(struct platform_device *pdev)
1051 1051
1052 *vfd = m2mtest_videodev; 1052 *vfd = m2mtest_videodev;
1053 vfd->lock = &dev->dev_mutex; 1053 vfd->lock = &dev->dev_mutex;
1054 vfd->v4l2_dev = &dev->v4l2_dev;
1054 1055
1055 ret = video_register_device(vfd, VFL_TYPE_GRABBER, 0); 1056 ret = video_register_device(vfd, VFL_TYPE_GRABBER, 0);
1056 if (ret) { 1057 if (ret) {
@@ -1061,7 +1062,7 @@ static int m2mtest_probe(struct platform_device *pdev)
1061 video_set_drvdata(vfd, dev); 1062 video_set_drvdata(vfd, dev);
1062 snprintf(vfd->name, sizeof(vfd->name), "%s", m2mtest_videodev.name); 1063 snprintf(vfd->name, sizeof(vfd->name), "%s", m2mtest_videodev.name);
1063 dev->vfd = vfd; 1064 dev->vfd = vfd;
1064 v4l2_info(&dev->v4l2_dev, MEM2MEM_TEST_MODULE_NAME 1065 v4l2_info(&dev->v4l2_dev,
1065 "Device registered as /dev/video%d\n", vfd->num); 1066 "Device registered as /dev/video%d\n", vfd->num);
1066 1067
1067 setup_timer(&dev->timer, device_isr, (long)dev); 1068 setup_timer(&dev->timer, device_isr, (long)dev);
diff --git a/drivers/media/platform/mx2_emmaprp.c b/drivers/media/platform/mx2_emmaprp.c
index f7440e585b6b..c690435853bd 100644
--- a/drivers/media/platform/mx2_emmaprp.c
+++ b/drivers/media/platform/mx2_emmaprp.c
@@ -937,6 +937,7 @@ static int emmaprp_probe(struct platform_device *pdev)
937 937
938 *vfd = emmaprp_videodev; 938 *vfd = emmaprp_videodev;
939 vfd->lock = &pcdev->dev_mutex; 939 vfd->lock = &pcdev->dev_mutex;
940 vfd->v4l2_dev = &pcdev->v4l2_dev;
940 941
941 video_set_drvdata(vfd, pcdev); 942 video_set_drvdata(vfd, pcdev);
942 snprintf(vfd->name, sizeof(vfd->name), "%s", emmaprp_videodev.name); 943 snprintf(vfd->name, sizeof(vfd->name), "%s", emmaprp_videodev.name);
diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
index d338b19da544..dfd0a21a0658 100644
--- a/drivers/media/platform/omap/omap_vout.c
+++ b/drivers/media/platform/omap/omap_vout.c
@@ -335,8 +335,6 @@ static int video_mode_to_dss_mode(struct omap_vout_device *vout)
335 ovl = ovid->overlays[0]; 335 ovl = ovid->overlays[0];
336 336
337 switch (pix->pixelformat) { 337 switch (pix->pixelformat) {
338 case 0:
339 break;
340 case V4L2_PIX_FMT_YUYV: 338 case V4L2_PIX_FMT_YUYV:
341 mode = OMAP_DSS_COLOR_YUV2; 339 mode = OMAP_DSS_COLOR_YUV2;
342 break; 340 break;
@@ -358,6 +356,7 @@ static int video_mode_to_dss_mode(struct omap_vout_device *vout)
358 break; 356 break;
359 default: 357 default:
360 mode = -EINVAL; 358 mode = -EINVAL;
359 break;
361 } 360 }
362 return mode; 361 return mode;
363} 362}
diff --git a/drivers/media/platform/omap24xxcam.c b/drivers/media/platform/omap24xxcam.c
index debb44ceb185..d2b440c842b3 100644
--- a/drivers/media/platform/omap24xxcam.c
+++ b/drivers/media/platform/omap24xxcam.c
@@ -1656,7 +1656,7 @@ static int omap24xxcam_device_register(struct v4l2_int_device *s)
1656 } 1656 }
1657 vfd->release = video_device_release; 1657 vfd->release = video_device_release;
1658 1658
1659 vfd->parent = cam->dev; 1659 vfd->v4l2_dev = &cam->v4l2_dev;
1660 1660
1661 strlcpy(vfd->name, CAM_NAME, sizeof(vfd->name)); 1661 strlcpy(vfd->name, CAM_NAME, sizeof(vfd->name));
1662 vfd->fops = &omap24xxcam_fops; 1662 vfd->fops = &omap24xxcam_fops;
@@ -1752,6 +1752,11 @@ static int omap24xxcam_probe(struct platform_device *pdev)
1752 1752
1753 cam->dev = &pdev->dev; 1753 cam->dev = &pdev->dev;
1754 1754
1755 if (v4l2_device_register(&pdev->dev, &cam->v4l2_dev)) {
1756 dev_err(&pdev->dev, "v4l2_device_register failed\n");
1757 goto err;
1758 }
1759
1755 /* 1760 /*
1756 * Impose a lower limit on the amount of memory allocated for 1761 * Impose a lower limit on the amount of memory allocated for
1757 * capture. We require at least enough memory to double-buffer 1762 * capture. We require at least enough memory to double-buffer
@@ -1849,6 +1854,8 @@ static int omap24xxcam_remove(struct platform_device *pdev)
1849 cam->mmio_base_phys = 0; 1854 cam->mmio_base_phys = 0;
1850 } 1855 }
1851 1856
1857 v4l2_device_unregister(&cam->v4l2_dev);
1858
1852 kfree(cam); 1859 kfree(cam);
1853 1860
1854 return 0; 1861 return 0;
diff --git a/drivers/media/platform/omap24xxcam.h b/drivers/media/platform/omap24xxcam.h
index c4395956a493..7f6f79155537 100644
--- a/drivers/media/platform/omap24xxcam.h
+++ b/drivers/media/platform/omap24xxcam.h
@@ -29,6 +29,7 @@
29 29
30#include <media/videobuf-dma-sg.h> 30#include <media/videobuf-dma-sg.h>
31#include <media/v4l2-int-device.h> 31#include <media/v4l2-int-device.h>
32#include <media/v4l2-device.h>
32 33
33/* 34/*
34 * 35 *
@@ -462,6 +463,8 @@ struct omap24xxcam_device {
462 */ 463 */
463 struct mutex mutex; 464 struct mutex mutex;
464 465
466 struct v4l2_device v4l2_dev;
467
465 /*** general driver state information ***/ 468 /*** general driver state information ***/
466 atomic_t users; 469 atomic_t users;
467 /* 470 /*
diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
index 1d7dbd5c0fba..df3a0ec7fd2c 100644
--- a/drivers/media/platform/omap3isp/isp.c
+++ b/drivers/media/platform/omap3isp/isp.c
@@ -792,9 +792,9 @@ int omap3isp_pipeline_pm_use(struct media_entity *entity, int use)
792 792
793/* 793/*
794 * isp_pipeline_link_notify - Link management notification callback 794 * isp_pipeline_link_notify - Link management notification callback
795 * @source: Pad at the start of the link 795 * @link: The link
796 * @sink: Pad at the end of the link
797 * @flags: New link flags that will be applied 796 * @flags: New link flags that will be applied
797 * @notification: The link's state change notification type (MEDIA_DEV_NOTIFY_*)
798 * 798 *
799 * React to link management on powered pipelines by updating the use count of 799 * React to link management on powered pipelines by updating the use count of
800 * all entities in the source and sink sides of the link. Entities are powered 800 * all entities in the source and sink sides of the link. Entities are powered
@@ -804,29 +804,38 @@ int omap3isp_pipeline_pm_use(struct media_entity *entity, int use)
804 * off is assumed to never fail. This function will not fail for disconnection 804 * off is assumed to never fail. This function will not fail for disconnection
805 * events. 805 * events.
806 */ 806 */
807static int isp_pipeline_link_notify(struct media_pad *source, 807static int isp_pipeline_link_notify(struct media_link *link, u32 flags,
808 struct media_pad *sink, u32 flags) 808 unsigned int notification)
809{ 809{
810 int source_use = isp_pipeline_pm_use_count(source->entity); 810 struct media_entity *source = link->source->entity;
811 int sink_use = isp_pipeline_pm_use_count(sink->entity); 811 struct media_entity *sink = link->sink->entity;
812 int source_use = isp_pipeline_pm_use_count(source);
813 int sink_use = isp_pipeline_pm_use_count(sink);
812 int ret; 814 int ret;
813 815
814 if (!(flags & MEDIA_LNK_FL_ENABLED)) { 816 if (notification == MEDIA_DEV_NOTIFY_POST_LINK_CH &&
817 !(link->flags & MEDIA_LNK_FL_ENABLED)) {
815 /* Powering off entities is assumed to never fail. */ 818 /* Powering off entities is assumed to never fail. */
816 isp_pipeline_pm_power(source->entity, -sink_use); 819 isp_pipeline_pm_power(source, -sink_use);
817 isp_pipeline_pm_power(sink->entity, -source_use); 820 isp_pipeline_pm_power(sink, -source_use);
818 return 0; 821 return 0;
819 } 822 }
820 823
821 ret = isp_pipeline_pm_power(source->entity, sink_use); 824 if (notification == MEDIA_DEV_NOTIFY_POST_LINK_CH &&
822 if (ret < 0) 825 (flags & MEDIA_LNK_FL_ENABLED)) {
823 return ret;
824 826
825 ret = isp_pipeline_pm_power(sink->entity, source_use); 827 ret = isp_pipeline_pm_power(source, sink_use);
826 if (ret < 0) 828 if (ret < 0)
827 isp_pipeline_pm_power(source->entity, -sink_use); 829 return ret;
828 830
829 return ret; 831 ret = isp_pipeline_pm_power(sink, source_use);
832 if (ret < 0)
833 isp_pipeline_pm_power(source, -sink_use);
834
835 return ret;
836 }
837
838 return 0;
830} 839}
831 840
832/* ----------------------------------------------------------------------------- 841/* -----------------------------------------------------------------------------
@@ -877,7 +886,7 @@ static int isp_pipeline_enable(struct isp_pipeline *pipe,
877 if (!(pad->flags & MEDIA_PAD_FL_SINK)) 886 if (!(pad->flags & MEDIA_PAD_FL_SINK))
878 break; 887 break;
879 888
880 pad = media_entity_remote_source(pad); 889 pad = media_entity_remote_pad(pad);
881 if (pad == NULL || 890 if (pad == NULL ||
882 media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV) 891 media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
883 break; 892 break;
@@ -967,7 +976,7 @@ static int isp_pipeline_disable(struct isp_pipeline *pipe)
967 if (!(pad->flags & MEDIA_PAD_FL_SINK)) 976 if (!(pad->flags & MEDIA_PAD_FL_SINK))
968 break; 977 break;
969 978
970 pad = media_entity_remote_source(pad); 979 pad = media_entity_remote_pad(pad);
971 if (pad == NULL || 980 if (pad == NULL ||
972 media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV) 981 media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
973 break; 982 break;
@@ -1083,7 +1092,7 @@ static int isp_pipeline_is_last(struct media_entity *me)
1083 pipe = to_isp_pipeline(me); 1092 pipe = to_isp_pipeline(me);
1084 if (pipe->stream_state == ISP_PIPELINE_STREAM_STOPPED) 1093 if (pipe->stream_state == ISP_PIPELINE_STREAM_STOPPED)
1085 return 0; 1094 return 0;
1086 pad = media_entity_remote_source(&pipe->output->pad); 1095 pad = media_entity_remote_pad(&pipe->output->pad);
1087 return pad->entity == me; 1096 return pad->entity == me;
1088} 1097}
1089 1098
@@ -2249,6 +2258,7 @@ static int isp_probe(struct platform_device *pdev)
2249 ret = iommu_attach_device(isp->domain, &pdev->dev); 2258 ret = iommu_attach_device(isp->domain, &pdev->dev);
2250 if (ret) { 2259 if (ret) {
2251 dev_err(&pdev->dev, "can't attach iommu device: %d\n", ret); 2260 dev_err(&pdev->dev, "can't attach iommu device: %d\n", ret);
2261 ret = -EPROBE_DEFER;
2252 goto free_domain; 2262 goto free_domain;
2253 } 2263 }
2254 2264
@@ -2287,12 +2297,11 @@ detach_dev:
2287 iommu_detach_device(isp->domain, &pdev->dev); 2297 iommu_detach_device(isp->domain, &pdev->dev);
2288free_domain: 2298free_domain:
2289 iommu_domain_free(isp->domain); 2299 iommu_domain_free(isp->domain);
2300 isp->domain = NULL;
2290error_isp: 2301error_isp:
2291 isp_xclk_cleanup(isp); 2302 isp_xclk_cleanup(isp);
2292 omap3isp_put(isp); 2303 omap3isp_put(isp);
2293error: 2304error:
2294 platform_set_drvdata(pdev, NULL);
2295
2296 mutex_destroy(&isp->isp_mutex); 2305 mutex_destroy(&isp->isp_mutex);
2297 2306
2298 return ret; 2307 return ret;
diff --git a/drivers/media/platform/omap3isp/ispccdc.c b/drivers/media/platform/omap3isp/ispccdc.c
index 60e60aa64fb4..907a205da5a5 100644
--- a/drivers/media/platform/omap3isp/ispccdc.c
+++ b/drivers/media/platform/omap3isp/ispccdc.c
@@ -1120,7 +1120,7 @@ static void ccdc_configure(struct isp_ccdc_device *ccdc)
1120 u32 syn_mode; 1120 u32 syn_mode;
1121 u32 ccdc_pattern; 1121 u32 ccdc_pattern;
1122 1122
1123 pad = media_entity_remote_source(&ccdc->pads[CCDC_PAD_SINK]); 1123 pad = media_entity_remote_pad(&ccdc->pads[CCDC_PAD_SINK]);
1124 sensor = media_entity_to_v4l2_subdev(pad->entity); 1124 sensor = media_entity_to_v4l2_subdev(pad->entity);
1125 if (ccdc->input == CCDC_INPUT_PARALLEL) 1125 if (ccdc->input == CCDC_INPUT_PARALLEL)
1126 pdata = &((struct isp_v4l2_subdevs_group *)sensor->host_priv) 1126 pdata = &((struct isp_v4l2_subdevs_group *)sensor->host_priv)
diff --git a/drivers/media/platform/omap3isp/ispccp2.c b/drivers/media/platform/omap3isp/ispccp2.c
index c5d84c977e29..e71651429dda 100644
--- a/drivers/media/platform/omap3isp/ispccp2.c
+++ b/drivers/media/platform/omap3isp/ispccp2.c
@@ -158,13 +158,17 @@ static void ccp2_pwr_cfg(struct isp_ccp2_device *ccp2)
158 * @ccp2: pointer to ISP CCP2 device 158 * @ccp2: pointer to ISP CCP2 device
159 * @enable: enable/disable flag 159 * @enable: enable/disable flag
160 */ 160 */
161static void ccp2_if_enable(struct isp_ccp2_device *ccp2, u8 enable) 161static int ccp2_if_enable(struct isp_ccp2_device *ccp2, u8 enable)
162{ 162{
163 struct isp_device *isp = to_isp_device(ccp2); 163 struct isp_device *isp = to_isp_device(ccp2);
164 int ret;
164 int i; 165 int i;
165 166
166 if (enable && ccp2->vdds_csib) 167 if (enable && ccp2->vdds_csib) {
167 regulator_enable(ccp2->vdds_csib); 168 ret = regulator_enable(ccp2->vdds_csib);
169 if (ret < 0)
170 return ret;
171 }
168 172
169 /* Enable/Disable all the LCx channels */ 173 /* Enable/Disable all the LCx channels */
170 for (i = 0; i < CCP2_LCx_CHANS_NUM; i++) 174 for (i = 0; i < CCP2_LCx_CHANS_NUM; i++)
@@ -179,6 +183,8 @@ static void ccp2_if_enable(struct isp_ccp2_device *ccp2, u8 enable)
179 183
180 if (!enable && ccp2->vdds_csib) 184 if (!enable && ccp2->vdds_csib)
181 regulator_disable(ccp2->vdds_csib); 185 regulator_disable(ccp2->vdds_csib);
186
187 return 0;
182} 188}
183 189
184/* 190/*
@@ -360,7 +366,7 @@ static int ccp2_if_configure(struct isp_ccp2_device *ccp2)
360 366
361 ccp2_pwr_cfg(ccp2); 367 ccp2_pwr_cfg(ccp2);
362 368
363 pad = media_entity_remote_source(&ccp2->pads[CCP2_PAD_SINK]); 369 pad = media_entity_remote_pad(&ccp2->pads[CCP2_PAD_SINK]);
364 sensor = media_entity_to_v4l2_subdev(pad->entity); 370 sensor = media_entity_to_v4l2_subdev(pad->entity);
365 pdata = sensor->host_priv; 371 pdata = sensor->host_priv;
366 372
@@ -851,7 +857,12 @@ static int ccp2_s_stream(struct v4l2_subdev *sd, int enable)
851 ccp2_print_status(ccp2); 857 ccp2_print_status(ccp2);
852 858
853 /* Enable CSI1/CCP2 interface */ 859 /* Enable CSI1/CCP2 interface */
854 ccp2_if_enable(ccp2, 1); 860 ret = ccp2_if_enable(ccp2, 1);
861 if (ret < 0) {
862 if (ccp2->phy)
863 omap3isp_csiphy_release(ccp2->phy);
864 return ret;
865 }
855 break; 866 break;
856 867
857 case ISP_PIPELINE_STREAM_SINGLESHOT: 868 case ISP_PIPELINE_STREAM_SINGLESHOT:
diff --git a/drivers/media/platform/omap3isp/ispcsi2.c b/drivers/media/platform/omap3isp/ispcsi2.c
index 783f4b05b153..6db245d84bbb 100644
--- a/drivers/media/platform/omap3isp/ispcsi2.c
+++ b/drivers/media/platform/omap3isp/ispcsi2.c
@@ -573,7 +573,7 @@ static int csi2_configure(struct isp_csi2_device *csi2)
573 if (csi2->contexts[0].enabled || csi2->ctrl.if_enable) 573 if (csi2->contexts[0].enabled || csi2->ctrl.if_enable)
574 return -EBUSY; 574 return -EBUSY;
575 575
576 pad = media_entity_remote_source(&csi2->pads[CSI2_PAD_SINK]); 576 pad = media_entity_remote_pad(&csi2->pads[CSI2_PAD_SINK]);
577 sensor = media_entity_to_v4l2_subdev(pad->entity); 577 sensor = media_entity_to_v4l2_subdev(pad->entity);
578 pdata = sensor->host_priv; 578 pdata = sensor->host_priv;
579 579
diff --git a/drivers/media/platform/omap3isp/ispqueue.h b/drivers/media/platform/omap3isp/ispqueue.h
index 908dfd712e8e..3e048ad65647 100644
--- a/drivers/media/platform/omap3isp/ispqueue.h
+++ b/drivers/media/platform/omap3isp/ispqueue.h
@@ -28,6 +28,7 @@
28 28
29#include <linux/kernel.h> 29#include <linux/kernel.h>
30#include <linux/list.h> 30#include <linux/list.h>
31#include <linux/mm_types.h>
31#include <linux/mutex.h> 32#include <linux/mutex.h>
32#include <linux/videodev2.h> 33#include <linux/videodev2.h>
33#include <linux/wait.h> 34#include <linux/wait.h>
diff --git a/drivers/media/platform/omap3isp/ispvideo.c b/drivers/media/platform/omap3isp/ispvideo.c
index 8dac17511e61..a908d006f527 100644
--- a/drivers/media/platform/omap3isp/ispvideo.c
+++ b/drivers/media/platform/omap3isp/ispvideo.c
@@ -219,7 +219,7 @@ isp_video_remote_subdev(struct isp_video *video, u32 *pad)
219{ 219{
220 struct media_pad *remote; 220 struct media_pad *remote;
221 221
222 remote = media_entity_remote_source(&video->pad); 222 remote = media_entity_remote_pad(&video->pad);
223 223
224 if (remote == NULL || 224 if (remote == NULL ||
225 media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV) 225 media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
@@ -314,7 +314,7 @@ static int isp_video_validate_pipeline(struct isp_pipeline *pipe)
314 * entity can be found, and stop checking the pipeline if the 314 * entity can be found, and stop checking the pipeline if the
315 * source entity isn't a subdev. 315 * source entity isn't a subdev.
316 */ 316 */
317 pad = media_entity_remote_source(pad); 317 pad = media_entity_remote_pad(pad);
318 if (pad == NULL) 318 if (pad == NULL)
319 return -EPIPE; 319 return -EPIPE;
320 320
@@ -901,7 +901,7 @@ static int isp_video_check_external_subdevs(struct isp_video *video,
901 continue; 901 continue;
902 902
903 /* ISP entities have always sink pad == 0. Find source. */ 903 /* ISP entities have always sink pad == 0. Find source. */
904 source_pad = media_entity_remote_source(&ents[i]->pads[0]); 904 source_pad = media_entity_remote_pad(&ents[i]->pads[0]);
905 if (source_pad == NULL) 905 if (source_pad == NULL)
906 continue; 906 continue;
907 907
diff --git a/drivers/media/platform/s3c-camif/camif-capture.c b/drivers/media/platform/s3c-camif/camif-capture.c
index 70438a0f62ae..40b298ab87f1 100644
--- a/drivers/media/platform/s3c-camif/camif-capture.c
+++ b/drivers/media/platform/s3c-camif/camif-capture.c
@@ -845,7 +845,7 @@ static int camif_pipeline_validate(struct camif_dev *camif)
845 int ret; 845 int ret;
846 846
847 /* Retrieve format at the sensor subdev source pad */ 847 /* Retrieve format at the sensor subdev source pad */
848 pad = media_entity_remote_source(&camif->pads[0]); 848 pad = media_entity_remote_pad(&camif->pads[0]);
849 if (!pad || media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV) 849 if (!pad || media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
850 return -EPIPE; 850 return -EPIPE;
851 851
diff --git a/drivers/media/platform/s3c-camif/camif-core.c b/drivers/media/platform/s3c-camif/camif-core.c
index 0d0fab1a7b5e..b38574702fe9 100644
--- a/drivers/media/platform/s3c-camif/camif-core.c
+++ b/drivers/media/platform/s3c-camif/camif-core.c
@@ -341,10 +341,11 @@ static void camif_clk_put(struct camif_dev *camif)
341 int i; 341 int i;
342 342
343 for (i = 0; i < CLK_MAX_NUM; i++) { 343 for (i = 0; i < CLK_MAX_NUM; i++) {
344 if (IS_ERR_OR_NULL(camif->clock[i])) 344 if (IS_ERR(camif->clock[i]))
345 continue; 345 continue;
346 clk_unprepare(camif->clock[i]); 346 clk_unprepare(camif->clock[i]);
347 clk_put(camif->clock[i]); 347 clk_put(camif->clock[i]);
348 camif->clock[i] = ERR_PTR(-EINVAL);
348 } 349 }
349} 350}
350 351
@@ -352,6 +353,9 @@ static int camif_clk_get(struct camif_dev *camif)
352{ 353{
353 int ret, i; 354 int ret, i;
354 355
356 for (i = 1; i < CLK_MAX_NUM; i++)
357 camif->clock[i] = ERR_PTR(-EINVAL);
358
355 for (i = 0; i < CLK_MAX_NUM; i++) { 359 for (i = 0; i < CLK_MAX_NUM; i++) {
356 camif->clock[i] = clk_get(camif->dev, camif_clocks[i]); 360 camif->clock[i] = clk_get(camif->dev, camif_clocks[i]);
357 if (IS_ERR(camif->clock[i])) { 361 if (IS_ERR(camif->clock[i])) {
diff --git a/drivers/media/platform/s3c-camif/camif-regs.c b/drivers/media/platform/s3c-camif/camif-regs.c
index 1a3b4fc05ec6..a9e3b16460b8 100644
--- a/drivers/media/platform/s3c-camif/camif-regs.c
+++ b/drivers/media/platform/s3c-camif/camif-regs.c
@@ -379,7 +379,7 @@ static void camif_hw_set_prescaler(struct camif_vp *vp)
379 camif_write(camif, S3C_CAMIF_REG_CISCPREDST(vp->id, vp->offset), cfg); 379 camif_write(camif, S3C_CAMIF_REG_CISCPREDST(vp->id, vp->offset), cfg);
380} 380}
381 381
382void camif_s3c244x_hw_set_scaler(struct camif_vp *vp) 382static void camif_s3c244x_hw_set_scaler(struct camif_vp *vp)
383{ 383{
384 struct camif_dev *camif = vp->camif; 384 struct camif_dev *camif = vp->camif;
385 struct camif_scaler *scaler = &vp->scaler; 385 struct camif_scaler *scaler = &vp->scaler;
@@ -426,7 +426,7 @@ void camif_s3c244x_hw_set_scaler(struct camif_vp *vp)
426 scaler->main_h_ratio, scaler->main_v_ratio); 426 scaler->main_h_ratio, scaler->main_v_ratio);
427} 427}
428 428
429void camif_s3c64xx_hw_set_scaler(struct camif_vp *vp) 429static void camif_s3c64xx_hw_set_scaler(struct camif_vp *vp)
430{ 430{
431 struct camif_dev *camif = vp->camif; 431 struct camif_dev *camif = vp->camif;
432 struct camif_scaler *scaler = &vp->scaler; 432 struct camif_scaler *scaler = &vp->scaler;
@@ -601,6 +601,6 @@ void camif_hw_dump_regs(struct camif_dev *camif, const char *label)
601 pr_info("--- %s ---\n", label); 601 pr_info("--- %s ---\n", label);
602 for (i = 0; i < ARRAY_SIZE(registers); i++) { 602 for (i = 0; i < ARRAY_SIZE(registers); i++) {
603 u32 cfg = readl(camif->io_base + registers[i].offset); 603 u32 cfg = readl(camif->io_base + registers[i].offset);
604 printk(KERN_INFO "%s:\t0x%08x\n", registers[i].name, cfg); 604 dev_info(camif->dev, "%s:\t0x%08x\n", registers[i].name, cfg);
605 } 605 }
606} 606}
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c b/drivers/media/platform/s5p-mfc/s5p_mfc.c
index d12faa691af8..a130dcdb7206 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
@@ -1424,7 +1424,7 @@ static void *mfc_get_drv_data(struct platform_device *pdev)
1424 1424
1425 if (pdev->dev.of_node) { 1425 if (pdev->dev.of_node) {
1426 const struct of_device_id *match; 1426 const struct of_device_id *match;
1427 match = of_match_node(of_match_ptr(exynos_mfc_match), 1427 match = of_match_node(exynos_mfc_match,
1428 pdev->dev.of_node); 1428 pdev->dev.of_node);
1429 if (match) 1429 if (match)
1430 driver_data = (struct s5p_mfc_variant *)match->data; 1430 driver_data = (struct s5p_mfc_variant *)match->data;
diff --git a/drivers/media/platform/s5p-tv/hdmi_drv.c b/drivers/media/platform/s5p-tv/hdmi_drv.c
index 4e86626dad4b..1b34c3629858 100644
--- a/drivers/media/platform/s5p-tv/hdmi_drv.c
+++ b/drivers/media/platform/s5p-tv/hdmi_drv.c
@@ -576,16 +576,22 @@ static int hdmi_s_stream(struct v4l2_subdev *sd, int enable)
576 return hdmi_streamoff(hdev); 576 return hdmi_streamoff(hdev);
577} 577}
578 578
579static void hdmi_resource_poweron(struct hdmi_resources *res) 579static int hdmi_resource_poweron(struct hdmi_resources *res)
580{ 580{
581 int ret;
582
581 /* turn HDMI power on */ 583 /* turn HDMI power on */
582 regulator_bulk_enable(res->regul_count, res->regul_bulk); 584 ret = regulator_bulk_enable(res->regul_count, res->regul_bulk);
585 if (ret < 0)
586 return ret;
583 /* power-on hdmi physical interface */ 587 /* power-on hdmi physical interface */
584 clk_enable(res->hdmiphy); 588 clk_enable(res->hdmiphy);
585 /* use VPP as parent clock; HDMIPHY is not working yet */ 589 /* use VPP as parent clock; HDMIPHY is not working yet */
586 clk_set_parent(res->sclk_hdmi, res->sclk_pixel); 590 clk_set_parent(res->sclk_hdmi, res->sclk_pixel);
587 /* turn clocks on */ 591 /* turn clocks on */
588 clk_enable(res->sclk_hdmi); 592 clk_enable(res->sclk_hdmi);
593
594 return 0;
589} 595}
590 596
591static void hdmi_resource_poweroff(struct hdmi_resources *res) 597static void hdmi_resource_poweroff(struct hdmi_resources *res)
@@ -728,11 +734,13 @@ static int hdmi_runtime_resume(struct device *dev)
728{ 734{
729 struct v4l2_subdev *sd = dev_get_drvdata(dev); 735 struct v4l2_subdev *sd = dev_get_drvdata(dev);
730 struct hdmi_device *hdev = sd_to_hdmi_dev(sd); 736 struct hdmi_device *hdev = sd_to_hdmi_dev(sd);
731 int ret = 0; 737 int ret;
732 738
733 dev_dbg(dev, "%s\n", __func__); 739 dev_dbg(dev, "%s\n", __func__);
734 740
735 hdmi_resource_poweron(&hdev->res); 741 ret = hdmi_resource_poweron(&hdev->res);
742 if (ret < 0)
743 return ret;
736 744
737 /* starting MHL */ 745 /* starting MHL */
738 ret = v4l2_subdev_call(hdev->mhl_sd, core, s_power, 1); 746 ret = v4l2_subdev_call(hdev->mhl_sd, core, s_power, 1);
@@ -755,6 +763,15 @@ static const struct dev_pm_ops hdmi_pm_ops = {
755 .runtime_resume = hdmi_runtime_resume, 763 .runtime_resume = hdmi_runtime_resume,
756}; 764};
757 765
766static void hdmi_resource_clear_clocks(struct hdmi_resources *res)
767{
768 res->hdmi = ERR_PTR(-EINVAL);
769 res->sclk_hdmi = ERR_PTR(-EINVAL);
770 res->sclk_pixel = ERR_PTR(-EINVAL);
771 res->sclk_hdmiphy = ERR_PTR(-EINVAL);
772 res->hdmiphy = ERR_PTR(-EINVAL);
773}
774
758static void hdmi_resources_cleanup(struct hdmi_device *hdev) 775static void hdmi_resources_cleanup(struct hdmi_device *hdev)
759{ 776{
760 struct hdmi_resources *res = &hdev->res; 777 struct hdmi_resources *res = &hdev->res;
@@ -765,17 +782,18 @@ static void hdmi_resources_cleanup(struct hdmi_device *hdev)
765 regulator_bulk_free(res->regul_count, res->regul_bulk); 782 regulator_bulk_free(res->regul_count, res->regul_bulk);
766 /* kfree is NULL-safe */ 783 /* kfree is NULL-safe */
767 kfree(res->regul_bulk); 784 kfree(res->regul_bulk);
768 if (!IS_ERR_OR_NULL(res->hdmiphy)) 785 if (!IS_ERR(res->hdmiphy))
769 clk_put(res->hdmiphy); 786 clk_put(res->hdmiphy);
770 if (!IS_ERR_OR_NULL(res->sclk_hdmiphy)) 787 if (!IS_ERR(res->sclk_hdmiphy))
771 clk_put(res->sclk_hdmiphy); 788 clk_put(res->sclk_hdmiphy);
772 if (!IS_ERR_OR_NULL(res->sclk_pixel)) 789 if (!IS_ERR(res->sclk_pixel))
773 clk_put(res->sclk_pixel); 790 clk_put(res->sclk_pixel);
774 if (!IS_ERR_OR_NULL(res->sclk_hdmi)) 791 if (!IS_ERR(res->sclk_hdmi))
775 clk_put(res->sclk_hdmi); 792 clk_put(res->sclk_hdmi);
776 if (!IS_ERR_OR_NULL(res->hdmi)) 793 if (!IS_ERR(res->hdmi))
777 clk_put(res->hdmi); 794 clk_put(res->hdmi);
778 memset(res, 0, sizeof(*res)); 795 memset(res, 0, sizeof(*res));
796 hdmi_resource_clear_clocks(res);
779} 797}
780 798
781static int hdmi_resources_init(struct hdmi_device *hdev) 799static int hdmi_resources_init(struct hdmi_device *hdev)
@@ -793,8 +811,9 @@ static int hdmi_resources_init(struct hdmi_device *hdev)
793 dev_dbg(dev, "HDMI resource init\n"); 811 dev_dbg(dev, "HDMI resource init\n");
794 812
795 memset(res, 0, sizeof(*res)); 813 memset(res, 0, sizeof(*res));
796 /* get clocks, power */ 814 hdmi_resource_clear_clocks(res);
797 815
816 /* get clocks, power */
798 res->hdmi = clk_get(dev, "hdmi"); 817 res->hdmi = clk_get(dev, "hdmi");
799 if (IS_ERR(res->hdmi)) { 818 if (IS_ERR(res->hdmi)) {
800 dev_err(dev, "failed to get clock 'hdmi'\n"); 819 dev_err(dev, "failed to get clock 'hdmi'\n");
diff --git a/drivers/media/platform/s5p-tv/mixer_drv.c b/drivers/media/platform/s5p-tv/mixer_drv.c
index 5733033a6ead..51805a5e2beb 100644
--- a/drivers/media/platform/s5p-tv/mixer_drv.c
+++ b/drivers/media/platform/s5p-tv/mixer_drv.c
@@ -211,6 +211,15 @@ fail:
211 return ret; 211 return ret;
212} 212}
213 213
214static void mxr_resource_clear_clocks(struct mxr_resources *res)
215{
216 res->mixer = ERR_PTR(-EINVAL);
217 res->vp = ERR_PTR(-EINVAL);
218 res->sclk_mixer = ERR_PTR(-EINVAL);
219 res->sclk_hdmi = ERR_PTR(-EINVAL);
220 res->sclk_dac = ERR_PTR(-EINVAL);
221}
222
214static void mxr_release_plat_resources(struct mxr_device *mdev) 223static void mxr_release_plat_resources(struct mxr_device *mdev)
215{ 224{
216 free_irq(mdev->res.irq, mdev); 225 free_irq(mdev->res.irq, mdev);
@@ -222,15 +231,15 @@ static void mxr_release_clocks(struct mxr_device *mdev)
222{ 231{
223 struct mxr_resources *res = &mdev->res; 232 struct mxr_resources *res = &mdev->res;
224 233
225 if (!IS_ERR_OR_NULL(res->sclk_dac)) 234 if (!IS_ERR(res->sclk_dac))
226 clk_put(res->sclk_dac); 235 clk_put(res->sclk_dac);
227 if (!IS_ERR_OR_NULL(res->sclk_hdmi)) 236 if (!IS_ERR(res->sclk_hdmi))
228 clk_put(res->sclk_hdmi); 237 clk_put(res->sclk_hdmi);
229 if (!IS_ERR_OR_NULL(res->sclk_mixer)) 238 if (!IS_ERR(res->sclk_mixer))
230 clk_put(res->sclk_mixer); 239 clk_put(res->sclk_mixer);
231 if (!IS_ERR_OR_NULL(res->vp)) 240 if (!IS_ERR(res->vp))
232 clk_put(res->vp); 241 clk_put(res->vp);
233 if (!IS_ERR_OR_NULL(res->mixer)) 242 if (!IS_ERR(res->mixer))
234 clk_put(res->mixer); 243 clk_put(res->mixer);
235} 244}
236 245
@@ -239,6 +248,8 @@ static int mxr_acquire_clocks(struct mxr_device *mdev)
239 struct mxr_resources *res = &mdev->res; 248 struct mxr_resources *res = &mdev->res;
240 struct device *dev = mdev->dev; 249 struct device *dev = mdev->dev;
241 250
251 mxr_resource_clear_clocks(res);
252
242 res->mixer = clk_get(dev, "mixer"); 253 res->mixer = clk_get(dev, "mixer");
243 if (IS_ERR(res->mixer)) { 254 if (IS_ERR(res->mixer)) {
244 mxr_err(mdev, "failed to get clock 'mixer'\n"); 255 mxr_err(mdev, "failed to get clock 'mixer'\n");
@@ -299,6 +310,7 @@ static void mxr_release_resources(struct mxr_device *mdev)
299 mxr_release_clocks(mdev); 310 mxr_release_clocks(mdev);
300 mxr_release_plat_resources(mdev); 311 mxr_release_plat_resources(mdev);
301 memset(&mdev->res, 0, sizeof(mdev->res)); 312 memset(&mdev->res, 0, sizeof(mdev->res));
313 mxr_resource_clear_clocks(&mdev->res);
302} 314}
303 315
304static void mxr_release_layers(struct mxr_device *mdev) 316static void mxr_release_layers(struct mxr_device *mdev)
diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
index ef0efdf422fe..641b1f071e06 100644
--- a/drivers/media/platform/s5p-tv/mixer_video.c
+++ b/drivers/media/platform/s5p-tv/mixer_video.c
@@ -81,8 +81,9 @@ int mxr_acquire_video(struct mxr_device *mdev,
81 } 81 }
82 82
83 mdev->alloc_ctx = vb2_dma_contig_init_ctx(mdev->dev); 83 mdev->alloc_ctx = vb2_dma_contig_init_ctx(mdev->dev);
84 if (IS_ERR_OR_NULL(mdev->alloc_ctx)) { 84 if (IS_ERR(mdev->alloc_ctx)) {
85 mxr_err(mdev, "could not acquire vb2 allocator\n"); 85 mxr_err(mdev, "could not acquire vb2 allocator\n");
86 ret = PTR_ERR(mdev->alloc_ctx);
86 goto fail_v4l2_dev; 87 goto fail_v4l2_dev;
87 } 88 }
88 89
diff --git a/drivers/media/platform/s5p-tv/sdo_drv.c b/drivers/media/platform/s5p-tv/sdo_drv.c
index ab6f9ef89423..0afa90f0f6ab 100644
--- a/drivers/media/platform/s5p-tv/sdo_drv.c
+++ b/drivers/media/platform/s5p-tv/sdo_drv.c
@@ -262,11 +262,21 @@ static int sdo_runtime_resume(struct device *dev)
262{ 262{
263 struct v4l2_subdev *sd = dev_get_drvdata(dev); 263 struct v4l2_subdev *sd = dev_get_drvdata(dev);
264 struct sdo_device *sdev = sd_to_sdev(sd); 264 struct sdo_device *sdev = sd_to_sdev(sd);
265 int ret;
265 266
266 dev_info(dev, "resume\n"); 267 dev_info(dev, "resume\n");
267 clk_enable(sdev->sclk_dac); 268
268 regulator_enable(sdev->vdac); 269 ret = clk_enable(sdev->sclk_dac);
269 regulator_enable(sdev->vdet); 270 if (ret < 0)
271 return ret;
272
273 ret = regulator_enable(sdev->vdac);
274 if (ret < 0)
275 goto dac_clk_dis;
276
277 ret = regulator_enable(sdev->vdet);
278 if (ret < 0)
279 goto vdac_r_dis;
270 280
271 /* software reset */ 281 /* software reset */
272 sdo_write_mask(sdev, SDO_CLKCON, ~0, SDO_TVOUT_SW_RESET); 282 sdo_write_mask(sdev, SDO_CLKCON, ~0, SDO_TVOUT_SW_RESET);
@@ -285,6 +295,12 @@ static int sdo_runtime_resume(struct device *dev)
285 SDO_COMPENSATION_CVBS_COMP_OFF); 295 SDO_COMPENSATION_CVBS_COMP_OFF);
286 sdo_reg_debug(sdev); 296 sdo_reg_debug(sdev);
287 return 0; 297 return 0;
298
299vdac_r_dis:
300 regulator_disable(sdev->vdac);
301dac_clk_dis:
302 clk_disable(sdev->sclk_dac);
303 return ret;
288} 304}
289 305
290static const struct dev_pm_ops sdo_pm_ops = { 306static const struct dev_pm_ops sdo_pm_ops = {
diff --git a/drivers/media/platform/s5p-tv/sii9234_drv.c b/drivers/media/platform/s5p-tv/sii9234_drv.c
index 39b77d24b9c2..3dd762e5b67e 100644
--- a/drivers/media/platform/s5p-tv/sii9234_drv.c
+++ b/drivers/media/platform/s5p-tv/sii9234_drv.c
@@ -249,7 +249,9 @@ static int sii9234_runtime_resume(struct device *dev)
249 int ret; 249 int ret;
250 250
251 dev_info(dev, "resume start\n"); 251 dev_info(dev, "resume start\n");
252 regulator_enable(ctx->power); 252 ret = regulator_enable(ctx->power);
253 if (ret < 0)
254 return ret;
253 255
254 ret = sii9234_reset(ctx); 256 ret = sii9234_reset(ctx);
255 if (ret) 257 if (ret)
diff --git a/drivers/media/platform/sh_veu.c b/drivers/media/platform/sh_veu.c
index 59a9deefb242..aa4cca371cbf 100644
--- a/drivers/media/platform/sh_veu.c
+++ b/drivers/media/platform/sh_veu.c
@@ -359,10 +359,7 @@ static int sh_veu_context_init(struct sh_veu_dev *veu)
359 veu->m2m_ctx = v4l2_m2m_ctx_init(veu->m2m_dev, veu, 359 veu->m2m_ctx = v4l2_m2m_ctx_init(veu->m2m_dev, veu,
360 sh_veu_queue_init); 360 sh_veu_queue_init);
361 361
362 if (IS_ERR(veu->m2m_ctx)) 362 return PTR_RET(veu->m2m_ctx);
363 return PTR_ERR(veu->m2m_ctx);
364
365 return 0;
366} 363}
367 364
368static int sh_veu_querycap(struct file *file, void *priv, 365static int sh_veu_querycap(struct file *file, void *priv,
diff --git a/drivers/media/platform/sh_vou.c b/drivers/media/platform/sh_vou.c
index 7d0235069c87..7a9c5e9329f2 100644
--- a/drivers/media/platform/sh_vou.c
+++ b/drivers/media/platform/sh_vou.c
@@ -1248,32 +1248,6 @@ static unsigned int sh_vou_poll(struct file *file, poll_table *wait)
1248 return res; 1248 return res;
1249} 1249}
1250 1250
1251static int sh_vou_g_chip_ident(struct file *file, void *fh,
1252 struct v4l2_dbg_chip_ident *id)
1253{
1254 struct sh_vou_device *vou_dev = video_drvdata(file);
1255
1256 return v4l2_device_call_until_err(&vou_dev->v4l2_dev, 0, core, g_chip_ident, id);
1257}
1258
1259#ifdef CONFIG_VIDEO_ADV_DEBUG
1260static int sh_vou_g_register(struct file *file, void *fh,
1261 struct v4l2_dbg_register *reg)
1262{
1263 struct sh_vou_device *vou_dev = video_drvdata(file);
1264
1265 return v4l2_device_call_until_err(&vou_dev->v4l2_dev, 0, core, g_register, reg);
1266}
1267
1268static int sh_vou_s_register(struct file *file, void *fh,
1269 const struct v4l2_dbg_register *reg)
1270{
1271 struct sh_vou_device *vou_dev = video_drvdata(file);
1272
1273 return v4l2_device_call_until_err(&vou_dev->v4l2_dev, 0, core, s_register, reg);
1274}
1275#endif
1276
1277/* sh_vou display ioctl operations */ 1251/* sh_vou display ioctl operations */
1278static const struct v4l2_ioctl_ops sh_vou_ioctl_ops = { 1252static const struct v4l2_ioctl_ops sh_vou_ioctl_ops = {
1279 .vidioc_querycap = sh_vou_querycap, 1253 .vidioc_querycap = sh_vou_querycap,
@@ -1292,11 +1266,6 @@ static const struct v4l2_ioctl_ops sh_vou_ioctl_ops = {
1292 .vidioc_cropcap = sh_vou_cropcap, 1266 .vidioc_cropcap = sh_vou_cropcap,
1293 .vidioc_g_crop = sh_vou_g_crop, 1267 .vidioc_g_crop = sh_vou_g_crop,
1294 .vidioc_s_crop = sh_vou_s_crop, 1268 .vidioc_s_crop = sh_vou_s_crop,
1295 .vidioc_g_chip_ident = sh_vou_g_chip_ident,
1296#ifdef CONFIG_VIDEO_ADV_DEBUG
1297 .vidioc_g_register = sh_vou_g_register,
1298 .vidioc_s_register = sh_vou_s_register,
1299#endif
1300}; 1269};
1301 1270
1302static const struct v4l2_file_operations sh_vou_fops = { 1271static const struct v4l2_file_operations sh_vou_fops = {
@@ -1313,7 +1282,6 @@ static const struct video_device sh_vou_video_template = {
1313 .fops = &sh_vou_fops, 1282 .fops = &sh_vou_fops,
1314 .ioctl_ops = &sh_vou_ioctl_ops, 1283 .ioctl_ops = &sh_vou_ioctl_ops,
1315 .tvnorms = V4L2_STD_525_60, /* PAL only supported in 8-bit non-bt656 mode */ 1284 .tvnorms = V4L2_STD_525_60, /* PAL only supported in 8-bit non-bt656 mode */
1316 .current_norm = V4L2_STD_NTSC_M,
1317 .vfl_dir = VFL_DIR_TX, 1285 .vfl_dir = VFL_DIR_TX,
1318}; 1286};
1319 1287
@@ -1352,7 +1320,7 @@ static int sh_vou_probe(struct platform_device *pdev)
1352 pix = &vou_dev->pix; 1320 pix = &vou_dev->pix;
1353 1321
1354 /* Fill in defaults */ 1322 /* Fill in defaults */
1355 vou_dev->std = sh_vou_video_template.current_norm; 1323 vou_dev->std = V4L2_STD_NTSC_M;
1356 rect->left = 0; 1324 rect->left = 0;
1357 rect->top = 0; 1325 rect->top = 0;
1358 rect->width = VOU_MAX_IMAGE_WIDTH; 1326 rect->width = VOU_MAX_IMAGE_WIDTH;
diff --git a/drivers/media/platform/soc_camera/Kconfig b/drivers/media/platform/soc_camera/Kconfig
index b139b525bb16..626dcccc37da 100644
--- a/drivers/media/platform/soc_camera/Kconfig
+++ b/drivers/media/platform/soc_camera/Kconfig
@@ -8,6 +8,9 @@ config SOC_CAMERA
8 over a bus like PCI or USB. For example some i2c camera connected 8 over a bus like PCI or USB. For example some i2c camera connected
9 directly to the data bus of an SoC. 9 directly to the data bus of an SoC.
10 10
11config SOC_CAMERA_SCALE_CROP
12 tristate
13
11config SOC_CAMERA_PLATFORM 14config SOC_CAMERA_PLATFORM
12 tristate "platform camera support" 15 tristate "platform camera support"
13 depends on SOC_CAMERA 16 depends on SOC_CAMERA
@@ -27,14 +30,10 @@ config VIDEO_MX1
27 ---help--- 30 ---help---
28 This is a v4l2 driver for the i.MX1/i.MXL CMOS Sensor Interface 31 This is a v4l2 driver for the i.MX1/i.MXL CMOS Sensor Interface
29 32
30config MX3_VIDEO
31 bool
32
33config VIDEO_MX3 33config VIDEO_MX3
34 tristate "i.MX3x Camera Sensor Interface driver" 34 tristate "i.MX3x Camera Sensor Interface driver"
35 depends on VIDEO_DEV && MX3_IPU && SOC_CAMERA 35 depends on VIDEO_DEV && MX3_IPU && SOC_CAMERA
36 select VIDEOBUF2_DMA_CONTIG 36 select VIDEOBUF2_DMA_CONTIG
37 select MX3_VIDEO
38 ---help--- 37 ---help---
39 This is a v4l2 driver for the i.MX3x Camera Sensor Interface 38 This is a v4l2 driver for the i.MX3x Camera Sensor Interface
40 39
@@ -55,6 +54,7 @@ config VIDEO_SH_MOBILE_CEU
55 tristate "SuperH Mobile CEU Interface driver" 54 tristate "SuperH Mobile CEU Interface driver"
56 depends on VIDEO_DEV && SOC_CAMERA && HAS_DMA && HAVE_CLK 55 depends on VIDEO_DEV && SOC_CAMERA && HAS_DMA && HAVE_CLK
57 select VIDEOBUF2_DMA_CONTIG 56 select VIDEOBUF2_DMA_CONTIG
57 select SOC_CAMERA_SCALE_CROP
58 ---help--- 58 ---help---
59 This is a v4l2 driver for the SuperH Mobile CEU Interface 59 This is a v4l2 driver for the SuperH Mobile CEU Interface
60 60
@@ -66,14 +66,10 @@ config VIDEO_OMAP1
66 ---help--- 66 ---help---
67 This is a v4l2 driver for the TI OMAP1 camera interface 67 This is a v4l2 driver for the TI OMAP1 camera interface
68 68
69config VIDEO_MX2_HOSTSUPPORT
70 bool
71
72config VIDEO_MX2 69config VIDEO_MX2
73 tristate "i.MX27 Camera Sensor Interface driver" 70 tristate "i.MX27 Camera Sensor Interface driver"
74 depends on VIDEO_DEV && SOC_CAMERA && MACH_MX27 71 depends on VIDEO_DEV && SOC_CAMERA && MACH_MX27
75 select VIDEOBUF2_DMA_CONTIG 72 select VIDEOBUF2_DMA_CONTIG
76 select VIDEO_MX2_HOSTSUPPORT
77 ---help--- 73 ---help---
78 This is a v4l2 driver for the i.MX27 Camera Sensor Interface 74 This is a v4l2 driver for the i.MX27 Camera Sensor Interface
79 75
diff --git a/drivers/media/platform/soc_camera/Makefile b/drivers/media/platform/soc_camera/Makefile
index 136b7f8ff10d..39186224c16a 100644
--- a/drivers/media/platform/soc_camera/Makefile
+++ b/drivers/media/platform/soc_camera/Makefile
@@ -1,4 +1,8 @@
1obj-$(CONFIG_SOC_CAMERA) += soc_camera.o soc_mediabus.o 1obj-$(CONFIG_SOC_CAMERA) += soc_camera.o soc_mediabus.o
2obj-$(CONFIG_SOC_CAMERA_SCALE_CROP) += soc_scale_crop.o
3
4# a platform subdevice driver stub, allowing to support cameras by adding a
5# couple of callback functions to the board code
2obj-$(CONFIG_SOC_CAMERA_PLATFORM) += soc_camera_platform.o 6obj-$(CONFIG_SOC_CAMERA_PLATFORM) += soc_camera_platform.o
3 7
4# soc-camera host drivers have to be linked after camera drivers 8# soc-camera host drivers have to be linked after camera drivers
@@ -10,5 +14,3 @@ obj-$(CONFIG_VIDEO_OMAP1) += omap1_camera.o
10obj-$(CONFIG_VIDEO_PXA27x) += pxa_camera.o 14obj-$(CONFIG_VIDEO_PXA27x) += pxa_camera.o
11obj-$(CONFIG_VIDEO_SH_MOBILE_CEU) += sh_mobile_ceu_camera.o 15obj-$(CONFIG_VIDEO_SH_MOBILE_CEU) += sh_mobile_ceu_camera.o
12obj-$(CONFIG_VIDEO_SH_MOBILE_CSI2) += sh_mobile_csi2.o 16obj-$(CONFIG_VIDEO_SH_MOBILE_CSI2) += sh_mobile_csi2.o
13
14ccflags-y += -I$(srctree)/drivers/media/i2c/soc_camera
diff --git a/drivers/media/platform/soc_camera/atmel-isi.c b/drivers/media/platform/soc_camera/atmel-isi.c
index 1abbb36d0755..104485632501 100644
--- a/drivers/media/platform/soc_camera/atmel-isi.c
+++ b/drivers/media/platform/soc_camera/atmel-isi.c
@@ -102,7 +102,6 @@ struct atmel_isi {
102 struct list_head video_buffer_list; 102 struct list_head video_buffer_list;
103 struct frame_buffer *active; 103 struct frame_buffer *active;
104 104
105 struct soc_camera_device *icd;
106 struct soc_camera_host soc_host; 105 struct soc_camera_host soc_host;
107}; 106};
108 107
@@ -367,7 +366,7 @@ static void start_dma(struct atmel_isi *isi, struct frame_buffer *buffer)
367 366
368 /* Check if already in a frame */ 367 /* Check if already in a frame */
369 if (isi_readl(isi, ISI_STATUS) & ISI_CTRL_CDC) { 368 if (isi_readl(isi, ISI_STATUS) & ISI_CTRL_CDC) {
370 dev_err(isi->icd->parent, "Already in frame handling.\n"); 369 dev_err(isi->soc_host.icd->parent, "Already in frame handling.\n");
371 return; 370 return;
372 } 371 }
373 372
@@ -746,16 +745,26 @@ static int isi_camera_get_formats(struct soc_camera_device *icd,
746 return formats; 745 return formats;
747} 746}
748 747
749/* Called with .host_lock held */
750static int isi_camera_add_device(struct soc_camera_device *icd) 748static int isi_camera_add_device(struct soc_camera_device *icd)
751{ 749{
752 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 750 dev_dbg(icd->parent, "Atmel ISI Camera driver attached to camera %d\n",
751 icd->devnum);
752
753 return 0;
754}
755
756static void isi_camera_remove_device(struct soc_camera_device *icd)
757{
758 dev_dbg(icd->parent, "Atmel ISI Camera driver detached from camera %d\n",
759 icd->devnum);
760}
761
762/* Called with .host_lock held */
763static int isi_camera_clock_start(struct soc_camera_host *ici)
764{
753 struct atmel_isi *isi = ici->priv; 765 struct atmel_isi *isi = ici->priv;
754 int ret; 766 int ret;
755 767
756 if (isi->icd)
757 return -EBUSY;
758
759 ret = clk_enable(isi->pclk); 768 ret = clk_enable(isi->pclk);
760 if (ret) 769 if (ret)
761 return ret; 770 return ret;
@@ -766,25 +775,16 @@ static int isi_camera_add_device(struct soc_camera_device *icd)
766 return ret; 775 return ret;
767 } 776 }
768 777
769 isi->icd = icd;
770 dev_dbg(icd->parent, "Atmel ISI Camera driver attached to camera %d\n",
771 icd->devnum);
772 return 0; 778 return 0;
773} 779}
780
774/* Called with .host_lock held */ 781/* Called with .host_lock held */
775static void isi_camera_remove_device(struct soc_camera_device *icd) 782static void isi_camera_clock_stop(struct soc_camera_host *ici)
776{ 783{
777 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
778 struct atmel_isi *isi = ici->priv; 784 struct atmel_isi *isi = ici->priv;
779 785
780 BUG_ON(icd != isi->icd);
781
782 clk_disable(isi->mck); 786 clk_disable(isi->mck);
783 clk_disable(isi->pclk); 787 clk_disable(isi->pclk);
784 isi->icd = NULL;
785
786 dev_dbg(icd->parent, "Atmel ISI Camera driver detached from camera %d\n",
787 icd->devnum);
788} 788}
789 789
790static unsigned int isi_camera_poll(struct file *file, poll_table *pt) 790static unsigned int isi_camera_poll(struct file *file, poll_table *pt)
@@ -888,6 +888,8 @@ static struct soc_camera_host_ops isi_soc_camera_host_ops = {
888 .owner = THIS_MODULE, 888 .owner = THIS_MODULE,
889 .add = isi_camera_add_device, 889 .add = isi_camera_add_device,
890 .remove = isi_camera_remove_device, 890 .remove = isi_camera_remove_device,
891 .clock_start = isi_camera_clock_start,
892 .clock_stop = isi_camera_clock_stop,
891 .set_fmt = isi_camera_set_fmt, 893 .set_fmt = isi_camera_set_fmt,
892 .try_fmt = isi_camera_try_fmt, 894 .try_fmt = isi_camera_try_fmt,
893 .get_formats = isi_camera_get_formats, 895 .get_formats = isi_camera_get_formats,
diff --git a/drivers/media/platform/soc_camera/mx1_camera.c b/drivers/media/platform/soc_camera/mx1_camera.c
index a3fd8d63546c..fea3e61476ae 100644
--- a/drivers/media/platform/soc_camera/mx1_camera.c
+++ b/drivers/media/platform/soc_camera/mx1_camera.c
@@ -104,7 +104,6 @@ struct mx1_buffer {
104 */ 104 */
105struct mx1_camera_dev { 105struct mx1_camera_dev {
106 struct soc_camera_host soc_host; 106 struct soc_camera_host soc_host;
107 struct soc_camera_device *icd;
108 struct mx1_camera_pdata *pdata; 107 struct mx1_camera_pdata *pdata;
109 struct mx1_buffer *active; 108 struct mx1_buffer *active;
110 struct resource *res; 109 struct resource *res;
@@ -220,7 +219,7 @@ out:
220static int mx1_camera_setup_dma(struct mx1_camera_dev *pcdev) 219static int mx1_camera_setup_dma(struct mx1_camera_dev *pcdev)
221{ 220{
222 struct videobuf_buffer *vbuf = &pcdev->active->vb; 221 struct videobuf_buffer *vbuf = &pcdev->active->vb;
223 struct device *dev = pcdev->icd->parent; 222 struct device *dev = pcdev->soc_host.icd->parent;
224 int ret; 223 int ret;
225 224
226 if (unlikely(!pcdev->active)) { 225 if (unlikely(!pcdev->active)) {
@@ -331,7 +330,7 @@ static void mx1_camera_wakeup(struct mx1_camera_dev *pcdev,
331static void mx1_camera_dma_irq(int channel, void *data) 330static void mx1_camera_dma_irq(int channel, void *data)
332{ 331{
333 struct mx1_camera_dev *pcdev = data; 332 struct mx1_camera_dev *pcdev = data;
334 struct device *dev = pcdev->icd->parent; 333 struct device *dev = pcdev->soc_host.icd->parent;
335 struct mx1_buffer *buf; 334 struct mx1_buffer *buf;
336 struct videobuf_buffer *vb; 335 struct videobuf_buffer *vb;
337 unsigned long flags; 336 unsigned long flags;
@@ -389,7 +388,7 @@ static int mclk_get_divisor(struct mx1_camera_dev *pcdev)
389 */ 388 */
390 div = (lcdclk + 2 * mclk - 1) / (2 * mclk) - 1; 389 div = (lcdclk + 2 * mclk - 1) / (2 * mclk) - 1;
391 390
392 dev_dbg(pcdev->icd->parent, 391 dev_dbg(pcdev->soc_host.icd->parent,
393 "System clock %lukHz, target freq %dkHz, divisor %lu\n", 392 "System clock %lukHz, target freq %dkHz, divisor %lu\n",
394 lcdclk / 1000, mclk / 1000, div); 393 lcdclk / 1000, mclk / 1000, div);
395 394
@@ -400,7 +399,7 @@ static void mx1_camera_activate(struct mx1_camera_dev *pcdev)
400{ 399{
401 unsigned int csicr1 = CSICR1_EN; 400 unsigned int csicr1 = CSICR1_EN;
402 401
403 dev_dbg(pcdev->icd->parent, "Activate device\n"); 402 dev_dbg(pcdev->soc_host.v4l2_dev.dev, "Activate device\n");
404 403
405 clk_prepare_enable(pcdev->clk); 404 clk_prepare_enable(pcdev->clk);
406 405
@@ -416,7 +415,7 @@ static void mx1_camera_activate(struct mx1_camera_dev *pcdev)
416 415
417static void mx1_camera_deactivate(struct mx1_camera_dev *pcdev) 416static void mx1_camera_deactivate(struct mx1_camera_dev *pcdev)
418{ 417{
419 dev_dbg(pcdev->icd->parent, "Deactivate device\n"); 418 dev_dbg(pcdev->soc_host.v4l2_dev.dev, "Deactivate device\n");
420 419
421 /* Disable all CSI interface */ 420 /* Disable all CSI interface */
422 __raw_writel(0x00, pcdev->base + CSICR1); 421 __raw_writel(0x00, pcdev->base + CSICR1);
@@ -424,36 +423,38 @@ static void mx1_camera_deactivate(struct mx1_camera_dev *pcdev)
424 clk_disable_unprepare(pcdev->clk); 423 clk_disable_unprepare(pcdev->clk);
425} 424}
426 425
426static int mx1_camera_add_device(struct soc_camera_device *icd)
427{
428 dev_info(icd->parent, "MX1 Camera driver attached to camera %d\n",
429 icd->devnum);
430
431 return 0;
432}
433
434static void mx1_camera_remove_device(struct soc_camera_device *icd)
435{
436 dev_info(icd->parent, "MX1 Camera driver detached from camera %d\n",
437 icd->devnum);
438}
439
427/* 440/*
428 * The following two functions absolutely depend on the fact, that 441 * The following two functions absolutely depend on the fact, that
429 * there can be only one camera on i.MX1/i.MXL camera sensor interface 442 * there can be only one camera on i.MX1/i.MXL camera sensor interface
430 */ 443 */
431static int mx1_camera_add_device(struct soc_camera_device *icd) 444static int mx1_camera_clock_start(struct soc_camera_host *ici)
432{ 445{
433 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
434 struct mx1_camera_dev *pcdev = ici->priv; 446 struct mx1_camera_dev *pcdev = ici->priv;
435 447
436 if (pcdev->icd)
437 return -EBUSY;
438
439 dev_info(icd->parent, "MX1 Camera driver attached to camera %d\n",
440 icd->devnum);
441
442 mx1_camera_activate(pcdev); 448 mx1_camera_activate(pcdev);
443 449
444 pcdev->icd = icd;
445
446 return 0; 450 return 0;
447} 451}
448 452
449static void mx1_camera_remove_device(struct soc_camera_device *icd) 453static void mx1_camera_clock_stop(struct soc_camera_host *ici)
450{ 454{
451 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
452 struct mx1_camera_dev *pcdev = ici->priv; 455 struct mx1_camera_dev *pcdev = ici->priv;
453 unsigned int csicr1; 456 unsigned int csicr1;
454 457
455 BUG_ON(icd != pcdev->icd);
456
457 /* disable interrupts */ 458 /* disable interrupts */
458 csicr1 = __raw_readl(pcdev->base + CSICR1) & ~CSI_IRQ_MASK; 459 csicr1 = __raw_readl(pcdev->base + CSICR1) & ~CSI_IRQ_MASK;
459 __raw_writel(csicr1, pcdev->base + CSICR1); 460 __raw_writel(csicr1, pcdev->base + CSICR1);
@@ -461,12 +462,7 @@ static void mx1_camera_remove_device(struct soc_camera_device *icd)
461 /* Stop DMA engine */ 462 /* Stop DMA engine */
462 imx_dma_disable(pcdev->dma_chan); 463 imx_dma_disable(pcdev->dma_chan);
463 464
464 dev_info(icd->parent, "MX1 Camera driver detached from camera %d\n",
465 icd->devnum);
466
467 mx1_camera_deactivate(pcdev); 465 mx1_camera_deactivate(pcdev);
468
469 pcdev->icd = NULL;
470} 466}
471 467
472static int mx1_camera_set_bus_param(struct soc_camera_device *icd) 468static int mx1_camera_set_bus_param(struct soc_camera_device *icd)
@@ -679,6 +675,8 @@ static struct soc_camera_host_ops mx1_soc_camera_host_ops = {
679 .owner = THIS_MODULE, 675 .owner = THIS_MODULE,
680 .add = mx1_camera_add_device, 676 .add = mx1_camera_add_device,
681 .remove = mx1_camera_remove_device, 677 .remove = mx1_camera_remove_device,
678 .clock_start = mx1_camera_clock_start,
679 .clock_stop = mx1_camera_clock_stop,
682 .set_bus_param = mx1_camera_set_bus_param, 680 .set_bus_param = mx1_camera_set_bus_param,
683 .set_fmt = mx1_camera_set_fmt, 681 .set_fmt = mx1_camera_set_fmt,
684 .try_fmt = mx1_camera_try_fmt, 682 .try_fmt = mx1_camera_try_fmt,
diff --git a/drivers/media/platform/soc_camera/mx2_camera.c b/drivers/media/platform/soc_camera/mx2_camera.c
index 5bbeb43e4531..45a0276be4e5 100644
--- a/drivers/media/platform/soc_camera/mx2_camera.c
+++ b/drivers/media/platform/soc_camera/mx2_camera.c
@@ -236,7 +236,6 @@ enum mx2_camera_type {
236struct mx2_camera_dev { 236struct mx2_camera_dev {
237 struct device *dev; 237 struct device *dev;
238 struct soc_camera_host soc_host; 238 struct soc_camera_host soc_host;
239 struct soc_camera_device *icd;
240 struct clk *clk_emma_ahb, *clk_emma_ipg; 239 struct clk *clk_emma_ahb, *clk_emma_ipg;
241 struct clk *clk_csi_ahb, *clk_csi_per; 240 struct clk *clk_csi_ahb, *clk_csi_per;
242 241
@@ -394,8 +393,8 @@ static void mx27_update_emma_buf(struct mx2_camera_dev *pcdev,
394 writel(phys, pcdev->base_emma + 393 writel(phys, pcdev->base_emma +
395 PRP_DEST_Y_PTR - 0x14 * bufnum); 394 PRP_DEST_Y_PTR - 0x14 * bufnum);
396 if (prp->out_fmt == V4L2_PIX_FMT_YUV420) { 395 if (prp->out_fmt == V4L2_PIX_FMT_YUV420) {
397 u32 imgsize = pcdev->icd->user_height * 396 u32 imgsize = pcdev->soc_host.icd->user_height *
398 pcdev->icd->user_width; 397 pcdev->soc_host.icd->user_width;
399 398
400 writel(phys + imgsize, pcdev->base_emma + 399 writel(phys + imgsize, pcdev->base_emma +
401 PRP_DEST_CB_PTR - 0x14 * bufnum); 400 PRP_DEST_CB_PTR - 0x14 * bufnum);
@@ -413,20 +412,30 @@ static void mx2_camera_deactivate(struct mx2_camera_dev *pcdev)
413 writel(0, pcdev->base_emma + PRP_CNTL); 412 writel(0, pcdev->base_emma + PRP_CNTL);
414} 413}
415 414
415static int mx2_camera_add_device(struct soc_camera_device *icd)
416{
417 dev_info(icd->parent, "Camera driver attached to camera %d\n",
418 icd->devnum);
419
420 return 0;
421}
422
423static void mx2_camera_remove_device(struct soc_camera_device *icd)
424{
425 dev_info(icd->parent, "Camera driver detached from camera %d\n",
426 icd->devnum);
427}
428
416/* 429/*
417 * The following two functions absolutely depend on the fact, that 430 * The following two functions absolutely depend on the fact, that
418 * there can be only one camera on mx2 camera sensor interface 431 * there can be only one camera on mx2 camera sensor interface
419 */ 432 */
420static int mx2_camera_add_device(struct soc_camera_device *icd) 433static int mx2_camera_clock_start(struct soc_camera_host *ici)
421{ 434{
422 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
423 struct mx2_camera_dev *pcdev = ici->priv; 435 struct mx2_camera_dev *pcdev = ici->priv;
424 int ret; 436 int ret;
425 u32 csicr1; 437 u32 csicr1;
426 438
427 if (pcdev->icd)
428 return -EBUSY;
429
430 ret = clk_prepare_enable(pcdev->clk_csi_ahb); 439 ret = clk_prepare_enable(pcdev->clk_csi_ahb);
431 if (ret < 0) 440 if (ret < 0)
432 return ret; 441 return ret;
@@ -441,12 +450,8 @@ static int mx2_camera_add_device(struct soc_camera_device *icd)
441 pcdev->csicr1 = csicr1; 450 pcdev->csicr1 = csicr1;
442 writel(pcdev->csicr1, pcdev->base_csi + CSICR1); 451 writel(pcdev->csicr1, pcdev->base_csi + CSICR1);
443 452
444 pcdev->icd = icd;
445 pcdev->frame_count = 0; 453 pcdev->frame_count = 0;
446 454
447 dev_info(icd->parent, "Camera driver attached to camera %d\n",
448 icd->devnum);
449
450 return 0; 455 return 0;
451 456
452exit_csi_ahb: 457exit_csi_ahb:
@@ -455,19 +460,11 @@ exit_csi_ahb:
455 return ret; 460 return ret;
456} 461}
457 462
458static void mx2_camera_remove_device(struct soc_camera_device *icd) 463static void mx2_camera_clock_stop(struct soc_camera_host *ici)
459{ 464{
460 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
461 struct mx2_camera_dev *pcdev = ici->priv; 465 struct mx2_camera_dev *pcdev = ici->priv;
462 466
463 BUG_ON(icd != pcdev->icd);
464
465 dev_info(icd->parent, "Camera driver detached from camera %d\n",
466 icd->devnum);
467
468 mx2_camera_deactivate(pcdev); 467 mx2_camera_deactivate(pcdev);
469
470 pcdev->icd = NULL;
471} 468}
472 469
473/* 470/*
@@ -1280,6 +1277,8 @@ static struct soc_camera_host_ops mx2_soc_camera_host_ops = {
1280 .owner = THIS_MODULE, 1277 .owner = THIS_MODULE,
1281 .add = mx2_camera_add_device, 1278 .add = mx2_camera_add_device,
1282 .remove = mx2_camera_remove_device, 1279 .remove = mx2_camera_remove_device,
1280 .clock_start = mx2_camera_clock_start,
1281 .clock_stop = mx2_camera_clock_stop,
1283 .set_fmt = mx2_camera_set_fmt, 1282 .set_fmt = mx2_camera_set_fmt,
1284 .set_crop = mx2_camera_set_crop, 1283 .set_crop = mx2_camera_set_crop,
1285 .get_formats = mx2_camera_get_formats, 1284 .get_formats = mx2_camera_get_formats,
diff --git a/drivers/media/platform/soc_camera/mx3_camera.c b/drivers/media/platform/soc_camera/mx3_camera.c
index 5da337736cd8..1047e3e8db77 100644
--- a/drivers/media/platform/soc_camera/mx3_camera.c
+++ b/drivers/media/platform/soc_camera/mx3_camera.c
@@ -94,7 +94,6 @@ struct mx3_camera_dev {
94 * Interface. If anyone ever builds hardware to enable more than one 94 * Interface. If anyone ever builds hardware to enable more than one
95 * camera _simultaneously_, they will have to modify this driver too 95 * camera _simultaneously_, they will have to modify this driver too
96 */ 96 */
97 struct soc_camera_device *icd;
98 struct clk *clk; 97 struct clk *clk;
99 98
100 void __iomem *base; 99 void __iomem *base;
@@ -461,8 +460,7 @@ static int mx3_camera_init_videobuf(struct vb2_queue *q,
461} 460}
462 461
463/* First part of ipu_csi_init_interface() */ 462/* First part of ipu_csi_init_interface() */
464static void mx3_camera_activate(struct mx3_camera_dev *mx3_cam, 463static void mx3_camera_activate(struct mx3_camera_dev *mx3_cam)
465 struct soc_camera_device *icd)
466{ 464{
467 u32 conf; 465 u32 conf;
468 long rate; 466 long rate;
@@ -506,51 +504,49 @@ static void mx3_camera_activate(struct mx3_camera_dev *mx3_cam,
506 504
507 clk_prepare_enable(mx3_cam->clk); 505 clk_prepare_enable(mx3_cam->clk);
508 rate = clk_round_rate(mx3_cam->clk, mx3_cam->mclk); 506 rate = clk_round_rate(mx3_cam->clk, mx3_cam->mclk);
509 dev_dbg(icd->parent, "Set SENS_CONF to %x, rate %ld\n", conf, rate); 507 dev_dbg(mx3_cam->soc_host.v4l2_dev.dev, "Set SENS_CONF to %x, rate %ld\n", conf, rate);
510 if (rate) 508 if (rate)
511 clk_set_rate(mx3_cam->clk, rate); 509 clk_set_rate(mx3_cam->clk, rate);
512} 510}
513 511
514/* Called with .host_lock held */
515static int mx3_camera_add_device(struct soc_camera_device *icd) 512static int mx3_camera_add_device(struct soc_camera_device *icd)
516{ 513{
517 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 514 dev_info(icd->parent, "MX3 Camera driver attached to camera %d\n",
518 struct mx3_camera_dev *mx3_cam = ici->priv; 515 icd->devnum);
519 516
520 if (mx3_cam->icd) 517 return 0;
521 return -EBUSY; 518}
522 519
523 mx3_camera_activate(mx3_cam, icd); 520static void mx3_camera_remove_device(struct soc_camera_device *icd)
521{
522 dev_info(icd->parent, "MX3 Camera driver detached from camera %d\n",
523 icd->devnum);
524}
524 525
525 mx3_cam->buf_total = 0; 526/* Called with .host_lock held */
526 mx3_cam->icd = icd; 527static int mx3_camera_clock_start(struct soc_camera_host *ici)
528{
529 struct mx3_camera_dev *mx3_cam = ici->priv;
527 530
528 dev_info(icd->parent, "MX3 Camera driver attached to camera %d\n", 531 mx3_camera_activate(mx3_cam);
529 icd->devnum); 532
533 mx3_cam->buf_total = 0;
530 534
531 return 0; 535 return 0;
532} 536}
533 537
534/* Called with .host_lock held */ 538/* Called with .host_lock held */
535static void mx3_camera_remove_device(struct soc_camera_device *icd) 539static void mx3_camera_clock_stop(struct soc_camera_host *ici)
536{ 540{
537 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
538 struct mx3_camera_dev *mx3_cam = ici->priv; 541 struct mx3_camera_dev *mx3_cam = ici->priv;
539 struct idmac_channel **ichan = &mx3_cam->idmac_channel[0]; 542 struct idmac_channel **ichan = &mx3_cam->idmac_channel[0];
540 543
541 BUG_ON(icd != mx3_cam->icd);
542
543 if (*ichan) { 544 if (*ichan) {
544 dma_release_channel(&(*ichan)->dma_chan); 545 dma_release_channel(&(*ichan)->dma_chan);
545 *ichan = NULL; 546 *ichan = NULL;
546 } 547 }
547 548
548 clk_disable_unprepare(mx3_cam->clk); 549 clk_disable_unprepare(mx3_cam->clk);
549
550 mx3_cam->icd = NULL;
551
552 dev_info(icd->parent, "MX3 Camera driver detached from camera %d\n",
553 icd->devnum);
554} 550}
555 551
556static int test_platform_param(struct mx3_camera_dev *mx3_cam, 552static int test_platform_param(struct mx3_camera_dev *mx3_cam,
@@ -1133,6 +1129,8 @@ static struct soc_camera_host_ops mx3_soc_camera_host_ops = {
1133 .owner = THIS_MODULE, 1129 .owner = THIS_MODULE,
1134 .add = mx3_camera_add_device, 1130 .add = mx3_camera_add_device,
1135 .remove = mx3_camera_remove_device, 1131 .remove = mx3_camera_remove_device,
1132 .clock_start = mx3_camera_clock_start,
1133 .clock_stop = mx3_camera_clock_stop,
1136 .set_crop = mx3_camera_set_crop, 1134 .set_crop = mx3_camera_set_crop,
1137 .set_fmt = mx3_camera_set_fmt, 1135 .set_fmt = mx3_camera_set_fmt,
1138 .try_fmt = mx3_camera_try_fmt, 1136 .try_fmt = mx3_camera_try_fmt,
diff --git a/drivers/media/platform/soc_camera/omap1_camera.c b/drivers/media/platform/soc_camera/omap1_camera.c
index 9689a6e89b7f..6769193c7c7b 100644
--- a/drivers/media/platform/soc_camera/omap1_camera.c
+++ b/drivers/media/platform/soc_camera/omap1_camera.c
@@ -150,7 +150,6 @@ struct omap1_cam_buf {
150 150
151struct omap1_cam_dev { 151struct omap1_cam_dev {
152 struct soc_camera_host soc_host; 152 struct soc_camera_host soc_host;
153 struct soc_camera_device *icd;
154 struct clk *clk; 153 struct clk *clk;
155 154
156 unsigned int irq; 155 unsigned int irq;
@@ -564,7 +563,7 @@ static void videobuf_done(struct omap1_cam_dev *pcdev,
564{ 563{
565 struct omap1_cam_buf *buf = pcdev->active; 564 struct omap1_cam_buf *buf = pcdev->active;
566 struct videobuf_buffer *vb; 565 struct videobuf_buffer *vb;
567 struct device *dev = pcdev->icd->parent; 566 struct device *dev = pcdev->soc_host.icd->parent;
568 567
569 if (WARN_ON(!buf)) { 568 if (WARN_ON(!buf)) {
570 suspend_capture(pcdev); 569 suspend_capture(pcdev);
@@ -790,7 +789,7 @@ out:
790static irqreturn_t cam_isr(int irq, void *data) 789static irqreturn_t cam_isr(int irq, void *data)
791{ 790{
792 struct omap1_cam_dev *pcdev = data; 791 struct omap1_cam_dev *pcdev = data;
793 struct device *dev = pcdev->icd->parent; 792 struct device *dev = pcdev->soc_host.icd->parent;
794 struct omap1_cam_buf *buf = pcdev->active; 793 struct omap1_cam_buf *buf = pcdev->active;
795 u32 it_status; 794 u32 it_status;
796 unsigned long flags; 795 unsigned long flags;
@@ -894,19 +893,29 @@ static void sensor_reset(struct omap1_cam_dev *pcdev, bool reset)
894 CAM_WRITE(pcdev, GPIO, !reset); 893 CAM_WRITE(pcdev, GPIO, !reset);
895} 894}
896 895
896static int omap1_cam_add_device(struct soc_camera_device *icd)
897{
898 dev_dbg(icd->parent, "OMAP1 Camera driver attached to camera %d\n",
899 icd->devnum);
900
901 return 0;
902}
903
904static void omap1_cam_remove_device(struct soc_camera_device *icd)
905{
906 dev_dbg(icd->parent,
907 "OMAP1 Camera driver detached from camera %d\n", icd->devnum);
908}
909
897/* 910/*
898 * The following two functions absolutely depend on the fact, that 911 * The following two functions absolutely depend on the fact, that
899 * there can be only one camera on OMAP1 camera sensor interface 912 * there can be only one camera on OMAP1 camera sensor interface
900 */ 913 */
901static int omap1_cam_add_device(struct soc_camera_device *icd) 914static int omap1_cam_clock_start(struct soc_camera_host *ici)
902{ 915{
903 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
904 struct omap1_cam_dev *pcdev = ici->priv; 916 struct omap1_cam_dev *pcdev = ici->priv;
905 u32 ctrlclock; 917 u32 ctrlclock;
906 918
907 if (pcdev->icd)
908 return -EBUSY;
909
910 clk_enable(pcdev->clk); 919 clk_enable(pcdev->clk);
911 920
912 /* setup sensor clock */ 921 /* setup sensor clock */
@@ -941,21 +950,14 @@ static int omap1_cam_add_device(struct soc_camera_device *icd)
941 950
942 sensor_reset(pcdev, false); 951 sensor_reset(pcdev, false);
943 952
944 pcdev->icd = icd;
945
946 dev_dbg(icd->parent, "OMAP1 Camera driver attached to camera %d\n",
947 icd->devnum);
948 return 0; 953 return 0;
949} 954}
950 955
951static void omap1_cam_remove_device(struct soc_camera_device *icd) 956static void omap1_cam_clock_stop(struct soc_camera_host *ici)
952{ 957{
953 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
954 struct omap1_cam_dev *pcdev = ici->priv; 958 struct omap1_cam_dev *pcdev = ici->priv;
955 u32 ctrlclock; 959 u32 ctrlclock;
956 960
957 BUG_ON(icd != pcdev->icd);
958
959 suspend_capture(pcdev); 961 suspend_capture(pcdev);
960 disable_capture(pcdev); 962 disable_capture(pcdev);
961 963
@@ -973,11 +975,6 @@ static void omap1_cam_remove_device(struct soc_camera_device *icd)
973 CAM_WRITE(pcdev, CTRLCLOCK, ctrlclock & ~MCLK_EN); 975 CAM_WRITE(pcdev, CTRLCLOCK, ctrlclock & ~MCLK_EN);
974 976
975 clk_disable(pcdev->clk); 977 clk_disable(pcdev->clk);
976
977 pcdev->icd = NULL;
978
979 dev_dbg(icd->parent,
980 "OMAP1 Camera driver detached from camera %d\n", icd->devnum);
981} 978}
982 979
983/* Duplicate standard formats based on host capability of byte swapping */ 980/* Duplicate standard formats based on host capability of byte swapping */
@@ -1535,6 +1532,8 @@ static struct soc_camera_host_ops omap1_host_ops = {
1535 .owner = THIS_MODULE, 1532 .owner = THIS_MODULE,
1536 .add = omap1_cam_add_device, 1533 .add = omap1_cam_add_device,
1537 .remove = omap1_cam_remove_device, 1534 .remove = omap1_cam_remove_device,
1535 .clock_start = omap1_cam_clock_start,
1536 .clock_stop = omap1_cam_clock_stop,
1538 .get_formats = omap1_cam_get_formats, 1537 .get_formats = omap1_cam_get_formats,
1539 .set_crop = omap1_cam_set_crop, 1538 .set_crop = omap1_cam_set_crop,
1540 .set_fmt = omap1_cam_set_fmt, 1539 .set_fmt = omap1_cam_set_fmt,
diff --git a/drivers/media/platform/soc_camera/pxa_camera.c b/drivers/media/platform/soc_camera/pxa_camera.c
index d665242e8207..d4df305fcc18 100644
--- a/drivers/media/platform/soc_camera/pxa_camera.c
+++ b/drivers/media/platform/soc_camera/pxa_camera.c
@@ -200,7 +200,6 @@ struct pxa_camera_dev {
200 * interface. If anyone ever builds hardware to enable more than 200 * interface. If anyone ever builds hardware to enable more than
201 * one camera, they will have to modify this driver too 201 * one camera, they will have to modify this driver too
202 */ 202 */
203 struct soc_camera_device *icd;
204 struct clk *clk; 203 struct clk *clk;
205 204
206 unsigned int irq; 205 unsigned int irq;
@@ -956,40 +955,39 @@ static irqreturn_t pxa_camera_irq(int irq, void *data)
956 return IRQ_HANDLED; 955 return IRQ_HANDLED;
957} 956}
958 957
958static int pxa_camera_add_device(struct soc_camera_device *icd)
959{
960 dev_info(icd->parent, "PXA Camera driver attached to camera %d\n",
961 icd->devnum);
962
963 return 0;
964}
965
966static void pxa_camera_remove_device(struct soc_camera_device *icd)
967{
968 dev_info(icd->parent, "PXA Camera driver detached from camera %d\n",
969 icd->devnum);
970}
971
959/* 972/*
960 * The following two functions absolutely depend on the fact, that 973 * The following two functions absolutely depend on the fact, that
961 * there can be only one camera on PXA quick capture interface 974 * there can be only one camera on PXA quick capture interface
962 * Called with .host_lock held 975 * Called with .host_lock held
963 */ 976 */
964static int pxa_camera_add_device(struct soc_camera_device *icd) 977static int pxa_camera_clock_start(struct soc_camera_host *ici)
965{ 978{
966 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
967 struct pxa_camera_dev *pcdev = ici->priv; 979 struct pxa_camera_dev *pcdev = ici->priv;
968 980
969 if (pcdev->icd)
970 return -EBUSY;
971
972 pxa_camera_activate(pcdev); 981 pxa_camera_activate(pcdev);
973 982
974 pcdev->icd = icd;
975
976 dev_info(icd->parent, "PXA Camera driver attached to camera %d\n",
977 icd->devnum);
978
979 return 0; 983 return 0;
980} 984}
981 985
982/* Called with .host_lock held */ 986/* Called with .host_lock held */
983static void pxa_camera_remove_device(struct soc_camera_device *icd) 987static void pxa_camera_clock_stop(struct soc_camera_host *ici)
984{ 988{
985 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
986 struct pxa_camera_dev *pcdev = ici->priv; 989 struct pxa_camera_dev *pcdev = ici->priv;
987 990
988 BUG_ON(icd != pcdev->icd);
989
990 dev_info(icd->parent, "PXA Camera driver detached from camera %d\n",
991 icd->devnum);
992
993 /* disable capture, disable interrupts */ 991 /* disable capture, disable interrupts */
994 __raw_writel(0x3ff, pcdev->base + CICR0); 992 __raw_writel(0x3ff, pcdev->base + CICR0);
995 993
@@ -999,8 +997,6 @@ static void pxa_camera_remove_device(struct soc_camera_device *icd)
999 DCSR(pcdev->dma_chans[2]) = 0; 997 DCSR(pcdev->dma_chans[2]) = 0;
1000 998
1001 pxa_camera_deactivate(pcdev); 999 pxa_camera_deactivate(pcdev);
1002
1003 pcdev->icd = NULL;
1004} 1000}
1005 1001
1006static int test_platform_param(struct pxa_camera_dev *pcdev, 1002static int test_platform_param(struct pxa_camera_dev *pcdev,
@@ -1596,8 +1592,8 @@ static int pxa_camera_suspend(struct device *dev)
1596 pcdev->save_cicr[i++] = __raw_readl(pcdev->base + CICR3); 1592 pcdev->save_cicr[i++] = __raw_readl(pcdev->base + CICR3);
1597 pcdev->save_cicr[i++] = __raw_readl(pcdev->base + CICR4); 1593 pcdev->save_cicr[i++] = __raw_readl(pcdev->base + CICR4);
1598 1594
1599 if (pcdev->icd) { 1595 if (pcdev->soc_host.icd) {
1600 struct v4l2_subdev *sd = soc_camera_to_subdev(pcdev->icd); 1596 struct v4l2_subdev *sd = soc_camera_to_subdev(pcdev->soc_host.icd);
1601 ret = v4l2_subdev_call(sd, core, s_power, 0); 1597 ret = v4l2_subdev_call(sd, core, s_power, 0);
1602 if (ret == -ENOIOCTLCMD) 1598 if (ret == -ENOIOCTLCMD)
1603 ret = 0; 1599 ret = 0;
@@ -1622,8 +1618,8 @@ static int pxa_camera_resume(struct device *dev)
1622 __raw_writel(pcdev->save_cicr[i++], pcdev->base + CICR3); 1618 __raw_writel(pcdev->save_cicr[i++], pcdev->base + CICR3);
1623 __raw_writel(pcdev->save_cicr[i++], pcdev->base + CICR4); 1619 __raw_writel(pcdev->save_cicr[i++], pcdev->base + CICR4);
1624 1620
1625 if (pcdev->icd) { 1621 if (pcdev->soc_host.icd) {
1626 struct v4l2_subdev *sd = soc_camera_to_subdev(pcdev->icd); 1622 struct v4l2_subdev *sd = soc_camera_to_subdev(pcdev->soc_host.icd);
1627 ret = v4l2_subdev_call(sd, core, s_power, 1); 1623 ret = v4l2_subdev_call(sd, core, s_power, 1);
1628 if (ret == -ENOIOCTLCMD) 1624 if (ret == -ENOIOCTLCMD)
1629 ret = 0; 1625 ret = 0;
@@ -1640,6 +1636,8 @@ static struct soc_camera_host_ops pxa_soc_camera_host_ops = {
1640 .owner = THIS_MODULE, 1636 .owner = THIS_MODULE,
1641 .add = pxa_camera_add_device, 1637 .add = pxa_camera_add_device,
1642 .remove = pxa_camera_remove_device, 1638 .remove = pxa_camera_remove_device,
1639 .clock_start = pxa_camera_clock_start,
1640 .clock_stop = pxa_camera_clock_stop,
1643 .set_crop = pxa_camera_set_crop, 1641 .set_crop = pxa_camera_set_crop,
1644 .get_formats = pxa_camera_get_formats, 1642 .get_formats = pxa_camera_get_formats,
1645 .put_formats = pxa_camera_put_formats, 1643 .put_formats = pxa_camera_put_formats,
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 143d29fe0137..f2de0066089a 100644
--- a/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c
+++ b/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c
@@ -27,6 +27,7 @@
27#include <linux/kernel.h> 27#include <linux/kernel.h>
28#include <linux/mm.h> 28#include <linux/mm.h>
29#include <linux/moduleparam.h> 29#include <linux/moduleparam.h>
30#include <linux/of.h>
30#include <linux/time.h> 31#include <linux/time.h>
31#include <linux/slab.h> 32#include <linux/slab.h>
32#include <linux/device.h> 33#include <linux/device.h>
@@ -35,6 +36,7 @@
35#include <linux/pm_runtime.h> 36#include <linux/pm_runtime.h>
36#include <linux/sched.h> 37#include <linux/sched.h>
37 38
39#include <media/v4l2-async.h>
38#include <media/v4l2-common.h> 40#include <media/v4l2-common.h>
39#include <media/v4l2-dev.h> 41#include <media/v4l2-dev.h>
40#include <media/soc_camera.h> 42#include <media/soc_camera.h>
@@ -44,6 +46,8 @@
44#include <media/v4l2-mediabus.h> 46#include <media/v4l2-mediabus.h>
45#include <media/soc_mediabus.h> 47#include <media/soc_mediabus.h>
46 48
49#include "soc_scale_crop.h"
50
47/* register offsets for sh7722 / sh7723 */ 51/* register offsets for sh7722 / sh7723 */
48 52
49#define CAPSR 0x00 /* Capture start register */ 53#define CAPSR 0x00 /* Capture start register */
@@ -95,7 +99,10 @@ struct sh_mobile_ceu_buffer {
95 99
96struct sh_mobile_ceu_dev { 100struct sh_mobile_ceu_dev {
97 struct soc_camera_host ici; 101 struct soc_camera_host ici;
98 struct soc_camera_device *icd; 102 /* Asynchronous CSI2 linking */
103 struct v4l2_async_subdev *csi2_asd;
104 struct v4l2_subdev *csi2_sd;
105 /* Synchronous probing compatibility */
99 struct platform_device *csi2_pdev; 106 struct platform_device *csi2_pdev;
100 107
101 unsigned int irq; 108 unsigned int irq;
@@ -119,6 +126,7 @@ struct sh_mobile_ceu_dev {
119 126
120 enum v4l2_field field; 127 enum v4l2_field field;
121 int sequence; 128 int sequence;
129 unsigned long flags;
122 130
123 unsigned int image_mode:1; 131 unsigned int image_mode:1;
124 unsigned int is_16bit:1; 132 unsigned int is_16bit:1;
@@ -163,7 +171,6 @@ static u32 ceu_read(struct sh_mobile_ceu_dev *priv, unsigned long reg_offs)
163static int sh_mobile_ceu_soft_reset(struct sh_mobile_ceu_dev *pcdev) 171static int sh_mobile_ceu_soft_reset(struct sh_mobile_ceu_dev *pcdev)
164{ 172{
165 int i, success = 0; 173 int i, success = 0;
166 struct soc_camera_device *icd = pcdev->icd;
167 174
168 ceu_write(pcdev, CAPSR, 1 << 16); /* reset */ 175 ceu_write(pcdev, CAPSR, 1 << 16); /* reset */
169 176
@@ -185,9 +192,8 @@ static int sh_mobile_ceu_soft_reset(struct sh_mobile_ceu_dev *pcdev)
185 udelay(1); 192 udelay(1);
186 } 193 }
187 194
188
189 if (2 != success) { 195 if (2 != success) {
190 dev_warn(icd->pdev, "soft reset time out\n"); 196 dev_warn(pcdev->ici.v4l2_dev.dev, "soft reset time out\n");
191 return -EIO; 197 return -EIO;
192 } 198 }
193 199
@@ -277,7 +283,7 @@ static int sh_mobile_ceu_videobuf_setup(struct vb2_queue *vq,
277 */ 283 */
278static int sh_mobile_ceu_capture(struct sh_mobile_ceu_dev *pcdev) 284static int sh_mobile_ceu_capture(struct sh_mobile_ceu_dev *pcdev)
279{ 285{
280 struct soc_camera_device *icd = pcdev->icd; 286 struct soc_camera_device *icd = pcdev->ici.icd;
281 dma_addr_t phys_addr_top, phys_addr_bottom; 287 dma_addr_t phys_addr_top, phys_addr_bottom;
282 unsigned long top1, top2; 288 unsigned long top1, top2;
283 unsigned long bottom1, bottom2; 289 unsigned long bottom1, bottom2;
@@ -534,72 +540,92 @@ static struct v4l2_subdev *find_csi2(struct sh_mobile_ceu_dev *pcdev)
534{ 540{
535 struct v4l2_subdev *sd; 541 struct v4l2_subdev *sd;
536 542
537 if (!pcdev->csi2_pdev) 543 if (pcdev->csi2_sd)
538 return NULL; 544 return pcdev->csi2_sd;
539 545
540 v4l2_device_for_each_subdev(sd, &pcdev->ici.v4l2_dev) 546 if (pcdev->csi2_asd) {
541 if (&pcdev->csi2_pdev->dev == v4l2_get_subdevdata(sd)) 547 char name[] = "sh-mobile-csi2";
542 return sd; 548 v4l2_device_for_each_subdev(sd, &pcdev->ici.v4l2_dev)
549 if (!strncmp(name, sd->name, sizeof(name) - 1)) {
550 pcdev->csi2_sd = sd;
551 return sd;
552 }
553 }
543 554
544 return NULL; 555 return NULL;
545} 556}
546 557
547/* Called with .host_lock held */ 558static struct v4l2_subdev *csi2_subdev(struct sh_mobile_ceu_dev *pcdev,
559 struct soc_camera_device *icd)
560{
561 struct v4l2_subdev *sd = pcdev->csi2_sd;
562
563 return sd && sd->grp_id == soc_camera_grp_id(icd) ? sd : NULL;
564}
565
548static int sh_mobile_ceu_add_device(struct soc_camera_device *icd) 566static int sh_mobile_ceu_add_device(struct soc_camera_device *icd)
549{ 567{
550 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 568 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
551 struct sh_mobile_ceu_dev *pcdev = ici->priv; 569 struct sh_mobile_ceu_dev *pcdev = ici->priv;
552 struct v4l2_subdev *csi2_sd; 570 struct v4l2_subdev *csi2_sd = find_csi2(pcdev);
553 int ret; 571 int ret;
554 572
555 if (pcdev->icd)
556 return -EBUSY;
557
558 dev_info(icd->parent,
559 "SuperH Mobile CEU driver attached to camera %d\n",
560 icd->devnum);
561
562 pm_runtime_get_sync(ici->v4l2_dev.dev);
563
564 pcdev->buf_total = 0;
565
566 ret = sh_mobile_ceu_soft_reset(pcdev);
567
568 csi2_sd = find_csi2(pcdev);
569 if (csi2_sd) { 573 if (csi2_sd) {
570 csi2_sd->grp_id = soc_camera_grp_id(icd); 574 csi2_sd->grp_id = soc_camera_grp_id(icd);
571 v4l2_set_subdev_hostdata(csi2_sd, icd); 575 v4l2_set_subdev_hostdata(csi2_sd, icd);
572 } 576 }
573 577
574 ret = v4l2_subdev_call(csi2_sd, core, s_power, 1); 578 ret = v4l2_subdev_call(csi2_sd, core, s_power, 1);
575 if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV) { 579 if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV)
576 pm_runtime_put(ici->v4l2_dev.dev);
577 return ret; 580 return ret;
578 }
579 581
580 /* 582 /*
581 * -ENODEV is special: either csi2_sd == NULL or the CSI-2 driver 583 * -ENODEV is special: either csi2_sd == NULL or the CSI-2 driver
582 * has not found this soc-camera device among its clients 584 * has not found this soc-camera device among its clients
583 */ 585 */
584 if (ret == -ENODEV && csi2_sd) 586 if (csi2_sd && ret == -ENODEV)
585 csi2_sd->grp_id = 0; 587 csi2_sd->grp_id = 0;
586 pcdev->icd = icd; 588
589 dev_info(icd->parent,
590 "SuperH Mobile CEU%s driver attached to camera %d\n",
591 csi2_sd && csi2_sd->grp_id ? "/CSI-2" : "", icd->devnum);
587 592
588 return 0; 593 return 0;
589} 594}
590 595
591/* Called with .host_lock held */
592static void sh_mobile_ceu_remove_device(struct soc_camera_device *icd) 596static void sh_mobile_ceu_remove_device(struct soc_camera_device *icd)
593{ 597{
594 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 598 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
595 struct sh_mobile_ceu_dev *pcdev = ici->priv; 599 struct sh_mobile_ceu_dev *pcdev = ici->priv;
596 struct v4l2_subdev *csi2_sd = find_csi2(pcdev); 600 struct v4l2_subdev *csi2_sd = find_csi2(pcdev);
597 601
598 BUG_ON(icd != pcdev->icd); 602 dev_info(icd->parent,
603 "SuperH Mobile CEU driver detached from camera %d\n",
604 icd->devnum);
599 605
600 v4l2_subdev_call(csi2_sd, core, s_power, 0); 606 v4l2_subdev_call(csi2_sd, core, s_power, 0);
601 if (csi2_sd) 607}
602 csi2_sd->grp_id = 0; 608
609/* Called with .host_lock held */
610static int sh_mobile_ceu_clock_start(struct soc_camera_host *ici)
611{
612 struct sh_mobile_ceu_dev *pcdev = ici->priv;
613 int ret;
614
615 pm_runtime_get_sync(ici->v4l2_dev.dev);
616
617 pcdev->buf_total = 0;
618
619 ret = sh_mobile_ceu_soft_reset(pcdev);
620
621 return 0;
622}
623
624/* Called with .host_lock held */
625static void sh_mobile_ceu_clock_stop(struct soc_camera_host *ici)
626{
627 struct sh_mobile_ceu_dev *pcdev = ici->priv;
628
603 /* disable capture, disable interrupts */ 629 /* disable capture, disable interrupts */
604 ceu_write(pcdev, CEIER, 0); 630 ceu_write(pcdev, CEIER, 0);
605 sh_mobile_ceu_soft_reset(pcdev); 631 sh_mobile_ceu_soft_reset(pcdev);
@@ -614,12 +640,6 @@ static void sh_mobile_ceu_remove_device(struct soc_camera_device *icd)
614 spin_unlock_irq(&pcdev->lock); 640 spin_unlock_irq(&pcdev->lock);
615 641
616 pm_runtime_put(ici->v4l2_dev.dev); 642 pm_runtime_put(ici->v4l2_dev.dev);
617
618 dev_info(icd->parent,
619 "SuperH Mobile CEU driver detached from camera %d\n",
620 icd->devnum);
621
622 pcdev->icd = NULL;
623} 643}
624 644
625/* 645/*
@@ -705,7 +725,7 @@ static void sh_mobile_ceu_set_rect(struct soc_camera_device *icd)
705 } 725 }
706 726
707 /* CSI2 special configuration */ 727 /* CSI2 special configuration */
708 if (pcdev->pdata->csi2) { 728 if (csi2_subdev(pcdev, icd)) {
709 in_width = ((in_width - 2) * 2); 729 in_width = ((in_width - 2) * 2);
710 left_offset *= 2; 730 left_offset *= 2;
711 } 731 }
@@ -762,13 +782,7 @@ static void capture_restore(struct sh_mobile_ceu_dev *pcdev, u32 capsr)
762static struct v4l2_subdev *find_bus_subdev(struct sh_mobile_ceu_dev *pcdev, 782static struct v4l2_subdev *find_bus_subdev(struct sh_mobile_ceu_dev *pcdev,
763 struct soc_camera_device *icd) 783 struct soc_camera_device *icd)
764{ 784{
765 if (pcdev->csi2_pdev) { 785 return csi2_subdev(pcdev, icd) ? : soc_camera_to_subdev(icd);
766 struct v4l2_subdev *csi2_sd = find_csi2(pcdev);
767 if (csi2_sd && csi2_sd->grp_id == soc_camera_grp_id(icd))
768 return csi2_sd;
769 }
770
771 return soc_camera_to_subdev(icd);
772} 786}
773 787
774#define CEU_BUS_FLAGS (V4L2_MBUS_MASTER | \ 788#define CEU_BUS_FLAGS (V4L2_MBUS_MASTER | \
@@ -809,7 +823,7 @@ static int sh_mobile_ceu_set_bus_param(struct soc_camera_device *icd)
809 /* Make choises, based on platform preferences */ 823 /* Make choises, based on platform preferences */
810 if ((common_flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH) && 824 if ((common_flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH) &&
811 (common_flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)) { 825 (common_flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)) {
812 if (pcdev->pdata->flags & SH_CEU_FLAG_HSYNC_LOW) 826 if (pcdev->flags & SH_CEU_FLAG_HSYNC_LOW)
813 common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_HIGH; 827 common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_HIGH;
814 else 828 else
815 common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_LOW; 829 common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_LOW;
@@ -817,7 +831,7 @@ static int sh_mobile_ceu_set_bus_param(struct soc_camera_device *icd)
817 831
818 if ((common_flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH) && 832 if ((common_flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH) &&
819 (common_flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)) { 833 (common_flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)) {
820 if (pcdev->pdata->flags & SH_CEU_FLAG_VSYNC_LOW) 834 if (pcdev->flags & SH_CEU_FLAG_VSYNC_LOW)
821 common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_HIGH; 835 common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_HIGH;
822 else 836 else
823 common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_LOW; 837 common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_LOW;
@@ -872,11 +886,11 @@ static int sh_mobile_ceu_set_bus_param(struct soc_camera_device *icd)
872 value |= common_flags & V4L2_MBUS_VSYNC_ACTIVE_LOW ? 1 << 1 : 0; 886 value |= common_flags & V4L2_MBUS_VSYNC_ACTIVE_LOW ? 1 << 1 : 0;
873 value |= common_flags & V4L2_MBUS_HSYNC_ACTIVE_LOW ? 1 << 0 : 0; 887 value |= common_flags & V4L2_MBUS_HSYNC_ACTIVE_LOW ? 1 << 0 : 0;
874 888
875 if (pcdev->pdata->csi2) /* CSI2 mode */ 889 if (csi2_subdev(pcdev, icd)) /* CSI2 mode */
876 value |= 3 << 12; 890 value |= 3 << 12;
877 else if (pcdev->is_16bit) 891 else if (pcdev->is_16bit)
878 value |= 1 << 12; 892 value |= 1 << 12;
879 else if (pcdev->pdata->flags & SH_CEU_FLAG_LOWER_8BIT) 893 else if (pcdev->flags & SH_CEU_FLAG_LOWER_8BIT)
880 value |= 2 << 12; 894 value |= 2 << 12;
881 895
882 ceu_write(pcdev, CAMCR, value); 896 ceu_write(pcdev, CAMCR, value);
@@ -993,8 +1007,6 @@ static bool sh_mobile_ceu_packing_supported(const struct soc_mbus_pixelfmt *fmt)
993 fmt->packing == SOC_MBUS_PACKING_EXTEND16); 1007 fmt->packing == SOC_MBUS_PACKING_EXTEND16);
994} 1008}
995 1009
996static int client_g_rect(struct v4l2_subdev *sd, struct v4l2_rect *rect);
997
998static struct soc_camera_device *ctrl_to_icd(struct v4l2_ctrl *ctrl) 1010static struct soc_camera_device *ctrl_to_icd(struct v4l2_ctrl *ctrl)
999{ 1011{
1000 return container_of(ctrl->handler, struct soc_camera_device, 1012 return container_of(ctrl->handler, struct soc_camera_device,
@@ -1051,7 +1063,7 @@ static int sh_mobile_ceu_get_formats(struct soc_camera_device *icd, unsigned int
1051 return 0; 1063 return 0;
1052 } 1064 }
1053 1065
1054 if (!pcdev->pdata->csi2) { 1066 if (!csi2_subdev(pcdev, icd)) {
1055 /* Are there any restrictions in the CSI-2 case? */ 1067 /* Are there any restrictions in the CSI-2 case? */
1056 ret = sh_mobile_ceu_try_bus_param(icd, fmt->bits_per_sample); 1068 ret = sh_mobile_ceu_try_bus_param(icd, fmt->bits_per_sample);
1057 if (ret < 0) 1069 if (ret < 0)
@@ -1072,7 +1084,7 @@ static int sh_mobile_ceu_get_formats(struct soc_camera_device *icd, unsigned int
1072 /* FIXME: subwindow is lost between close / open */ 1084 /* FIXME: subwindow is lost between close / open */
1073 1085
1074 /* Cache current client geometry */ 1086 /* Cache current client geometry */
1075 ret = client_g_rect(sd, &rect); 1087 ret = soc_camera_client_g_rect(sd, &rect);
1076 if (ret < 0) 1088 if (ret < 0)
1077 return ret; 1089 return ret;
1078 1090
@@ -1182,334 +1194,8 @@ static void sh_mobile_ceu_put_formats(struct soc_camera_device *icd)
1182 icd->host_priv = NULL; 1194 icd->host_priv = NULL;
1183} 1195}
1184 1196
1185/* Check if any dimension of r1 is smaller than respective one of r2 */ 1197#define scale_down(size, scale) soc_camera_shift_scale(size, 12, scale)
1186static bool is_smaller(const struct v4l2_rect *r1, const struct v4l2_rect *r2) 1198#define calc_generic_scale(in, out) soc_camera_calc_scale(in, 12, out)
1187{
1188 return r1->width < r2->width || r1->height < r2->height;
1189}
1190
1191/* Check if r1 fails to cover r2 */
1192static bool is_inside(const struct v4l2_rect *r1, const struct v4l2_rect *r2)
1193{
1194 return r1->left > r2->left || r1->top > r2->top ||
1195 r1->left + r1->width < r2->left + r2->width ||
1196 r1->top + r1->height < r2->top + r2->height;
1197}
1198
1199static unsigned int scale_down(unsigned int size, unsigned int scale)
1200{
1201 return (size * 4096 + scale / 2) / scale;
1202}
1203
1204static unsigned int calc_generic_scale(unsigned int input, unsigned int output)
1205{
1206 return (input * 4096 + output / 2) / output;
1207}
1208
1209/* Get and store current client crop */
1210static int client_g_rect(struct v4l2_subdev *sd, struct v4l2_rect *rect)
1211{
1212 struct v4l2_crop crop;
1213 struct v4l2_cropcap cap;
1214 int ret;
1215
1216 crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1217
1218 ret = v4l2_subdev_call(sd, video, g_crop, &crop);
1219 if (!ret) {
1220 *rect = crop.c;
1221 return ret;
1222 }
1223
1224 /* Camera driver doesn't support .g_crop(), assume default rectangle */
1225 cap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1226
1227 ret = v4l2_subdev_call(sd, video, cropcap, &cap);
1228 if (!ret)
1229 *rect = cap.defrect;
1230
1231 return ret;
1232}
1233
1234/* Client crop has changed, update our sub-rectangle to remain within the area */
1235static void update_subrect(struct sh_mobile_ceu_cam *cam)
1236{
1237 struct v4l2_rect *rect = &cam->rect, *subrect = &cam->subrect;
1238
1239 if (rect->width < subrect->width)
1240 subrect->width = rect->width;
1241
1242 if (rect->height < subrect->height)
1243 subrect->height = rect->height;
1244
1245 if (rect->left > subrect->left)
1246 subrect->left = rect->left;
1247 else if (rect->left + rect->width >
1248 subrect->left + subrect->width)
1249 subrect->left = rect->left + rect->width -
1250 subrect->width;
1251
1252 if (rect->top > subrect->top)
1253 subrect->top = rect->top;
1254 else if (rect->top + rect->height >
1255 subrect->top + subrect->height)
1256 subrect->top = rect->top + rect->height -
1257 subrect->height;
1258}
1259
1260/*
1261 * The common for both scaling and cropping iterative approach is:
1262 * 1. try if the client can produce exactly what requested by the user
1263 * 2. if (1) failed, try to double the client image until we get one big enough
1264 * 3. if (2) failed, try to request the maximum image
1265 */
1266static int client_s_crop(struct soc_camera_device *icd, struct v4l2_crop *crop,
1267 struct v4l2_crop *cam_crop)
1268{
1269 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
1270 struct v4l2_rect *rect = &crop->c, *cam_rect = &cam_crop->c;
1271 struct device *dev = sd->v4l2_dev->dev;
1272 struct sh_mobile_ceu_cam *cam = icd->host_priv;
1273 struct v4l2_cropcap cap;
1274 int ret;
1275 unsigned int width, height;
1276
1277 v4l2_subdev_call(sd, video, s_crop, crop);
1278 ret = client_g_rect(sd, cam_rect);
1279 if (ret < 0)
1280 return ret;
1281
1282 /*
1283 * Now cam_crop contains the current camera input rectangle, and it must
1284 * be within camera cropcap bounds
1285 */
1286 if (!memcmp(rect, cam_rect, sizeof(*rect))) {
1287 /* Even if camera S_CROP failed, but camera rectangle matches */
1288 dev_dbg(dev, "Camera S_CROP successful for %dx%d@%d:%d\n",
1289 rect->width, rect->height, rect->left, rect->top);
1290 cam->rect = *cam_rect;
1291 return 0;
1292 }
1293
1294 /* Try to fix cropping, that camera hasn't managed to set */
1295 dev_geo(dev, "Fix camera S_CROP for %dx%d@%d:%d to %dx%d@%d:%d\n",
1296 cam_rect->width, cam_rect->height,
1297 cam_rect->left, cam_rect->top,
1298 rect->width, rect->height, rect->left, rect->top);
1299
1300 /* We need sensor maximum rectangle */
1301 ret = v4l2_subdev_call(sd, video, cropcap, &cap);
1302 if (ret < 0)
1303 return ret;
1304
1305 /* Put user requested rectangle within sensor bounds */
1306 soc_camera_limit_side(&rect->left, &rect->width, cap.bounds.left, 2,
1307 cap.bounds.width);
1308 soc_camera_limit_side(&rect->top, &rect->height, cap.bounds.top, 4,
1309 cap.bounds.height);
1310
1311 /*
1312 * Popular special case - some cameras can only handle fixed sizes like
1313 * QVGA, VGA,... Take care to avoid infinite loop.
1314 */
1315 width = max(cam_rect->width, 2);
1316 height = max(cam_rect->height, 2);
1317
1318 /*
1319 * Loop as long as sensor is not covering the requested rectangle and
1320 * is still within its bounds
1321 */
1322 while (!ret && (is_smaller(cam_rect, rect) ||
1323 is_inside(cam_rect, rect)) &&
1324 (cap.bounds.width > width || cap.bounds.height > height)) {
1325
1326 width *= 2;
1327 height *= 2;
1328
1329 cam_rect->width = width;
1330 cam_rect->height = height;
1331
1332 /*
1333 * We do not know what capabilities the camera has to set up
1334 * left and top borders. We could try to be smarter in iterating
1335 * them, e.g., if camera current left is to the right of the
1336 * target left, set it to the middle point between the current
1337 * left and minimum left. But that would add too much
1338 * complexity: we would have to iterate each border separately.
1339 * Instead we just drop to the left and top bounds.
1340 */
1341 if (cam_rect->left > rect->left)
1342 cam_rect->left = cap.bounds.left;
1343
1344 if (cam_rect->left + cam_rect->width < rect->left + rect->width)
1345 cam_rect->width = rect->left + rect->width -
1346 cam_rect->left;
1347
1348 if (cam_rect->top > rect->top)
1349 cam_rect->top = cap.bounds.top;
1350
1351 if (cam_rect->top + cam_rect->height < rect->top + rect->height)
1352 cam_rect->height = rect->top + rect->height -
1353 cam_rect->top;
1354
1355 v4l2_subdev_call(sd, video, s_crop, cam_crop);
1356 ret = client_g_rect(sd, cam_rect);
1357 dev_geo(dev, "Camera S_CROP %d for %dx%d@%d:%d\n", ret,
1358 cam_rect->width, cam_rect->height,
1359 cam_rect->left, cam_rect->top);
1360 }
1361
1362 /* S_CROP must not modify the rectangle */
1363 if (is_smaller(cam_rect, rect) || is_inside(cam_rect, rect)) {
1364 /*
1365 * The camera failed to configure a suitable cropping,
1366 * we cannot use the current rectangle, set to max
1367 */
1368 *cam_rect = cap.bounds;
1369 v4l2_subdev_call(sd, video, s_crop, cam_crop);
1370 ret = client_g_rect(sd, cam_rect);
1371 dev_geo(dev, "Camera S_CROP %d for max %dx%d@%d:%d\n", ret,
1372 cam_rect->width, cam_rect->height,
1373 cam_rect->left, cam_rect->top);
1374 }
1375
1376 if (!ret) {
1377 cam->rect = *cam_rect;
1378 update_subrect(cam);
1379 }
1380
1381 return ret;
1382}
1383
1384/* Iterative s_mbus_fmt, also updates cached client crop on success */
1385static int client_s_fmt(struct soc_camera_device *icd,
1386 struct v4l2_mbus_framefmt *mf, bool ceu_can_scale)
1387{
1388 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
1389 struct sh_mobile_ceu_dev *pcdev = ici->priv;
1390 struct sh_mobile_ceu_cam *cam = icd->host_priv;
1391 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
1392 struct device *dev = icd->parent;
1393 unsigned int width = mf->width, height = mf->height, tmp_w, tmp_h;
1394 unsigned int max_width, max_height;
1395 struct v4l2_cropcap cap;
1396 bool ceu_1to1;
1397 int ret;
1398
1399 ret = v4l2_device_call_until_err(sd->v4l2_dev,
1400 soc_camera_grp_id(icd), video,
1401 s_mbus_fmt, mf);
1402 if (ret < 0)
1403 return ret;
1404
1405 dev_geo(dev, "camera scaled to %ux%u\n", mf->width, mf->height);
1406
1407 if (width == mf->width && height == mf->height) {
1408 /* Perfect! The client has done it all. */
1409 ceu_1to1 = true;
1410 goto update_cache;
1411 }
1412
1413 ceu_1to1 = false;
1414 if (!ceu_can_scale)
1415 goto update_cache;
1416
1417 cap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1418
1419 ret = v4l2_subdev_call(sd, video, cropcap, &cap);
1420 if (ret < 0)
1421 return ret;
1422
1423 max_width = min(cap.bounds.width, pcdev->max_width);
1424 max_height = min(cap.bounds.height, pcdev->max_height);
1425
1426 /* Camera set a format, but geometry is not precise, try to improve */
1427 tmp_w = mf->width;
1428 tmp_h = mf->height;
1429
1430 /* width <= max_width && height <= max_height - guaranteed by try_fmt */
1431 while ((width > tmp_w || height > tmp_h) &&
1432 tmp_w < max_width && tmp_h < max_height) {
1433 tmp_w = min(2 * tmp_w, max_width);
1434 tmp_h = min(2 * tmp_h, max_height);
1435 mf->width = tmp_w;
1436 mf->height = tmp_h;
1437 ret = v4l2_device_call_until_err(sd->v4l2_dev,
1438 soc_camera_grp_id(icd), video,
1439 s_mbus_fmt, mf);
1440 dev_geo(dev, "Camera scaled to %ux%u\n",
1441 mf->width, mf->height);
1442 if (ret < 0) {
1443 /* This shouldn't happen */
1444 dev_err(dev, "Client failed to set format: %d\n", ret);
1445 return ret;
1446 }
1447 }
1448
1449update_cache:
1450 /* Update cache */
1451 ret = client_g_rect(sd, &cam->rect);
1452 if (ret < 0)
1453 return ret;
1454
1455 if (ceu_1to1)
1456 cam->subrect = cam->rect;
1457 else
1458 update_subrect(cam);
1459
1460 return 0;
1461}
1462
1463/**
1464 * @width - on output: user width, mapped back to input
1465 * @height - on output: user height, mapped back to input
1466 * @mf - in- / output camera output window
1467 */
1468static int client_scale(struct soc_camera_device *icd,
1469 struct v4l2_mbus_framefmt *mf,
1470 unsigned int *width, unsigned int *height,
1471 bool ceu_can_scale)
1472{
1473 struct sh_mobile_ceu_cam *cam = icd->host_priv;
1474 struct device *dev = icd->parent;
1475 struct v4l2_mbus_framefmt mf_tmp = *mf;
1476 unsigned int scale_h, scale_v;
1477 int ret;
1478
1479 /*
1480 * 5. Apply iterative camera S_FMT for camera user window (also updates
1481 * client crop cache and the imaginary sub-rectangle).
1482 */
1483 ret = client_s_fmt(icd, &mf_tmp, ceu_can_scale);
1484 if (ret < 0)
1485 return ret;
1486
1487 dev_geo(dev, "5: camera scaled to %ux%u\n",
1488 mf_tmp.width, mf_tmp.height);
1489
1490 /* 6. Retrieve camera output window (g_fmt) */
1491
1492 /* unneeded - it is already in "mf_tmp" */
1493
1494 /* 7. Calculate new client scales. */
1495 scale_h = calc_generic_scale(cam->rect.width, mf_tmp.width);
1496 scale_v = calc_generic_scale(cam->rect.height, mf_tmp.height);
1497
1498 mf->width = mf_tmp.width;
1499 mf->height = mf_tmp.height;
1500 mf->colorspace = mf_tmp.colorspace;
1501
1502 /*
1503 * 8. Calculate new CEU crop - apply camera scales to previously
1504 * updated "effective" crop.
1505 */
1506 *width = scale_down(cam->subrect.width, scale_h);
1507 *height = scale_down(cam->subrect.height, scale_v);
1508
1509 dev_geo(dev, "8: new client sub-window %ux%u\n", *width, *height);
1510
1511 return 0;
1512}
1513 1199
1514/* 1200/*
1515 * CEU can scale and crop, but we don't want to waste bandwidth and kill the 1201 * CEU can scale and crop, but we don't want to waste bandwidth and kill the
@@ -1547,7 +1233,8 @@ static int sh_mobile_ceu_set_crop(struct soc_camera_device *icd,
1547 * 1. - 2. Apply iterative camera S_CROP for new input window, read back 1233 * 1. - 2. Apply iterative camera S_CROP for new input window, read back
1548 * actual camera rectangle. 1234 * actual camera rectangle.
1549 */ 1235 */
1550 ret = client_s_crop(icd, &a_writable, &cam_crop); 1236 ret = soc_camera_client_s_crop(sd, &a_writable, &cam_crop,
1237 &cam->rect, &cam->subrect);
1551 if (ret < 0) 1238 if (ret < 0)
1552 return ret; 1239 return ret;
1553 1240
@@ -1666,55 +1353,6 @@ static int sh_mobile_ceu_get_crop(struct soc_camera_device *icd,
1666 return 0; 1353 return 0;
1667} 1354}
1668 1355
1669/*
1670 * Calculate real client output window by applying new scales to the current
1671 * client crop. New scales are calculated from the requested output format and
1672 * CEU crop, mapped backed onto the client input (subrect).
1673 */
1674static void calculate_client_output(struct soc_camera_device *icd,
1675 const struct v4l2_pix_format *pix, struct v4l2_mbus_framefmt *mf)
1676{
1677 struct sh_mobile_ceu_cam *cam = icd->host_priv;
1678 struct device *dev = icd->parent;
1679 struct v4l2_rect *cam_subrect = &cam->subrect;
1680 unsigned int scale_v, scale_h;
1681
1682 if (cam_subrect->width == cam->rect.width &&
1683 cam_subrect->height == cam->rect.height) {
1684 /* No sub-cropping */
1685 mf->width = pix->width;
1686 mf->height = pix->height;
1687 return;
1688 }
1689
1690 /* 1.-2. Current camera scales and subwin - cached. */
1691
1692 dev_geo(dev, "2: subwin %ux%u@%u:%u\n",
1693 cam_subrect->width, cam_subrect->height,
1694 cam_subrect->left, cam_subrect->top);
1695
1696 /*
1697 * 3. Calculate new combined scales from input sub-window to requested
1698 * user window.
1699 */
1700
1701 /*
1702 * TODO: CEU cannot scale images larger than VGA to smaller than SubQCIF
1703 * (128x96) or larger than VGA
1704 */
1705 scale_h = calc_generic_scale(cam_subrect->width, pix->width);
1706 scale_v = calc_generic_scale(cam_subrect->height, pix->height);
1707
1708 dev_geo(dev, "3: scales %u:%u\n", scale_h, scale_v);
1709
1710 /*
1711 * 4. Calculate desired client output window by applying combined scales
1712 * to client (real) input window.
1713 */
1714 mf->width = scale_down(cam->rect.width, scale_h);
1715 mf->height = scale_down(cam->rect.height, scale_v);
1716}
1717
1718/* Similar to set_crop multistage iterative algorithm */ 1356/* Similar to set_crop multistage iterative algorithm */
1719static int sh_mobile_ceu_set_fmt(struct soc_camera_device *icd, 1357static int sh_mobile_ceu_set_fmt(struct soc_camera_device *icd,
1720 struct v4l2_format *f) 1358 struct v4l2_format *f)
@@ -1727,8 +1365,8 @@ static int sh_mobile_ceu_set_fmt(struct soc_camera_device *icd,
1727 struct v4l2_mbus_framefmt mf; 1365 struct v4l2_mbus_framefmt mf;
1728 __u32 pixfmt = pix->pixelformat; 1366 __u32 pixfmt = pix->pixelformat;
1729 const struct soc_camera_format_xlate *xlate; 1367 const struct soc_camera_format_xlate *xlate;
1730 /* Keep Compiler Happy */ 1368 unsigned int ceu_sub_width = pcdev->max_width,
1731 unsigned int ceu_sub_width = 0, ceu_sub_height = 0; 1369 ceu_sub_height = pcdev->max_height;
1732 u16 scale_v, scale_h; 1370 u16 scale_v, scale_h;
1733 int ret; 1371 int ret;
1734 bool image_mode; 1372 bool image_mode;
@@ -1755,7 +1393,7 @@ static int sh_mobile_ceu_set_fmt(struct soc_camera_device *icd,
1755 } 1393 }
1756 1394
1757 /* 1.-4. Calculate desired client output geometry */ 1395 /* 1.-4. Calculate desired client output geometry */
1758 calculate_client_output(icd, pix, &mf); 1396 soc_camera_calc_client_output(icd, &cam->rect, &cam->subrect, pix, &mf, 12);
1759 mf.field = pix->field; 1397 mf.field = pix->field;
1760 mf.colorspace = pix->colorspace; 1398 mf.colorspace = pix->colorspace;
1761 mf.code = xlate->code; 1399 mf.code = xlate->code;
@@ -1777,8 +1415,9 @@ static int sh_mobile_ceu_set_fmt(struct soc_camera_device *icd,
1777 dev_geo(dev, "4: request camera output %ux%u\n", mf.width, mf.height); 1415 dev_geo(dev, "4: request camera output %ux%u\n", mf.width, mf.height);
1778 1416
1779 /* 5. - 9. */ 1417 /* 5. - 9. */
1780 ret = client_scale(icd, &mf, &ceu_sub_width, &ceu_sub_height, 1418 ret = soc_camera_client_scale(icd, &cam->rect, &cam->subrect,
1781 image_mode && V4L2_FIELD_NONE == field); 1419 &mf, &ceu_sub_width, &ceu_sub_height,
1420 image_mode && V4L2_FIELD_NONE == field, 12);
1782 1421
1783 dev_geo(dev, "5-9: client scale return %d\n", ret); 1422 dev_geo(dev, "5-9: client scale return %d\n", ret);
1784 1423
@@ -2036,6 +1675,8 @@ static struct soc_camera_host_ops sh_mobile_ceu_host_ops = {
2036 .owner = THIS_MODULE, 1675 .owner = THIS_MODULE,
2037 .add = sh_mobile_ceu_add_device, 1676 .add = sh_mobile_ceu_add_device,
2038 .remove = sh_mobile_ceu_remove_device, 1677 .remove = sh_mobile_ceu_remove_device,
1678 .clock_start = sh_mobile_ceu_clock_start,
1679 .clock_stop = sh_mobile_ceu_clock_stop,
2039 .get_formats = sh_mobile_ceu_get_formats, 1680 .get_formats = sh_mobile_ceu_get_formats,
2040 .put_formats = sh_mobile_ceu_put_formats, 1681 .put_formats = sh_mobile_ceu_put_formats,
2041 .get_crop = sh_mobile_ceu_get_crop, 1682 .get_crop = sh_mobile_ceu_get_crop,
@@ -2079,7 +1720,7 @@ static int sh_mobile_ceu_probe(struct platform_device *pdev)
2079 struct resource *res; 1720 struct resource *res;
2080 void __iomem *base; 1721 void __iomem *base;
2081 unsigned int irq; 1722 unsigned int irq;
2082 int err = 0; 1723 int err, i;
2083 struct bus_wait wait = { 1724 struct bus_wait wait = {
2084 .completion = COMPLETION_INITIALIZER_ONSTACK(wait.completion), 1725 .completion = COMPLETION_INITIALIZER_ONSTACK(wait.completion),
2085 .notifier.notifier_call = bus_notify, 1726 .notifier.notifier_call = bus_notify,
@@ -2104,13 +1745,36 @@ static int sh_mobile_ceu_probe(struct platform_device *pdev)
2104 init_completion(&pcdev->complete); 1745 init_completion(&pcdev->complete);
2105 1746
2106 pcdev->pdata = pdev->dev.platform_data; 1747 pcdev->pdata = pdev->dev.platform_data;
2107 if (!pcdev->pdata) { 1748 if (!pcdev->pdata && !pdev->dev.of_node) {
2108 dev_err(&pdev->dev, "CEU platform data not set.\n"); 1749 dev_err(&pdev->dev, "CEU platform data not set.\n");
2109 return -EINVAL; 1750 return -EINVAL;
2110 } 1751 }
2111 1752
2112 pcdev->max_width = pcdev->pdata->max_width ? : 2560; 1753 /* TODO: implement per-device bus flags */
2113 pcdev->max_height = pcdev->pdata->max_height ? : 1920; 1754 if (pcdev->pdata) {
1755 pcdev->max_width = pcdev->pdata->max_width;
1756 pcdev->max_height = pcdev->pdata->max_height;
1757 pcdev->flags = pcdev->pdata->flags;
1758 }
1759
1760 if (!pcdev->max_width) {
1761 unsigned int v;
1762 err = of_property_read_u32(pdev->dev.of_node, "renesas,max-width", &v);
1763 if (!err)
1764 pcdev->max_width = v;
1765
1766 if (!pcdev->max_width)
1767 pcdev->max_width = 2560;
1768 }
1769 if (!pcdev->max_height) {
1770 unsigned int v;
1771 err = of_property_read_u32(pdev->dev.of_node, "renesas,max-height", &v);
1772 if (!err)
1773 pcdev->max_height = v;
1774
1775 if (!pcdev->max_height)
1776 pcdev->max_height = 1920;
1777 }
2114 1778
2115 base = devm_ioremap_resource(&pdev->dev, res); 1779 base = devm_ioremap_resource(&pdev->dev, res);
2116 if (IS_ERR(base)) 1780 if (IS_ERR(base))
@@ -2160,31 +1824,60 @@ static int sh_mobile_ceu_probe(struct platform_device *pdev)
2160 goto exit_free_clk; 1824 goto exit_free_clk;
2161 } 1825 }
2162 1826
2163 err = soc_camera_host_register(&pcdev->ici); 1827 if (pcdev->pdata && pcdev->pdata->asd_sizes) {
2164 if (err) 1828 struct v4l2_async_subdev **asd;
2165 goto exit_free_ctx; 1829 char name[] = "sh-mobile-csi2";
1830 int j;
1831
1832 /*
1833 * CSI2 interfacing: several groups can use CSI2, pick up the
1834 * first one
1835 */
1836 asd = pcdev->pdata->asd;
1837 for (j = 0; pcdev->pdata->asd_sizes[j]; j++) {
1838 for (i = 0; i < pcdev->pdata->asd_sizes[j]; i++, asd++) {
1839 dev_dbg(&pdev->dev, "%s(): subdev #%d, type %u\n",
1840 __func__, i, (*asd)->bus_type);
1841 if ((*asd)->bus_type == V4L2_ASYNC_BUS_PLATFORM &&
1842 !strncmp(name, (*asd)->match.platform.name,
1843 sizeof(name) - 1)) {
1844 pcdev->csi2_asd = *asd;
1845 break;
1846 }
1847 }
1848 if (pcdev->csi2_asd)
1849 break;
1850 }
2166 1851
2167 /* CSI2 interfacing */ 1852 pcdev->ici.asd = pcdev->pdata->asd;
2168 csi2 = pcdev->pdata->csi2; 1853 pcdev->ici.asd_sizes = pcdev->pdata->asd_sizes;
1854 }
1855
1856 /* Legacy CSI2 interfacing */
1857 csi2 = pcdev->pdata ? pcdev->pdata->csi2 : NULL;
2169 if (csi2) { 1858 if (csi2) {
1859 /*
1860 * TODO: remove this once all users are converted to
1861 * asynchronous CSI2 probing. If it has to be kept, csi2
1862 * platform device resources have to be added, using
1863 * platform_device_add_resources()
1864 */
2170 struct platform_device *csi2_pdev = 1865 struct platform_device *csi2_pdev =
2171 platform_device_alloc("sh-mobile-csi2", csi2->id); 1866 platform_device_alloc("sh-mobile-csi2", csi2->id);
2172 struct sh_csi2_pdata *csi2_pdata = csi2->platform_data; 1867 struct sh_csi2_pdata *csi2_pdata = csi2->platform_data;
2173 1868
2174 if (!csi2_pdev) { 1869 if (!csi2_pdev) {
2175 err = -ENOMEM; 1870 err = -ENOMEM;
2176 goto exit_host_unregister; 1871 goto exit_free_ctx;
2177 } 1872 }
2178 1873
2179 pcdev->csi2_pdev = csi2_pdev; 1874 pcdev->csi2_pdev = csi2_pdev;
2180 1875
2181 err = platform_device_add_data(csi2_pdev, csi2_pdata, sizeof(*csi2_pdata)); 1876 err = platform_device_add_data(csi2_pdev, csi2_pdata,
1877 sizeof(*csi2_pdata));
2182 if (err < 0) 1878 if (err < 0)
2183 goto exit_pdev_put; 1879 goto exit_pdev_put;
2184 1880
2185 csi2_pdata = csi2_pdev->dev.platform_data;
2186 csi2_pdata->v4l2_dev = &pcdev->ici.v4l2_dev;
2187
2188 csi2_pdev->resource = csi2->resource; 1881 csi2_pdev->resource = csi2->resource;
2189 csi2_pdev->num_resources = csi2->num_resources; 1882 csi2_pdev->num_resources = csi2->num_resources;
2190 1883
@@ -2226,17 +1919,38 @@ static int sh_mobile_ceu_probe(struct platform_device *pdev)
2226 err = -ENODEV; 1919 err = -ENODEV;
2227 goto exit_pdev_unregister; 1920 goto exit_pdev_unregister;
2228 } 1921 }
1922
1923 pcdev->csi2_sd = platform_get_drvdata(csi2_pdev);
1924 }
1925
1926 err = soc_camera_host_register(&pcdev->ici);
1927 if (err)
1928 goto exit_csi2_unregister;
1929
1930 if (csi2) {
1931 err = v4l2_device_register_subdev(&pcdev->ici.v4l2_dev,
1932 pcdev->csi2_sd);
1933 dev_dbg(&pdev->dev, "%s(): ret(register_subdev) = %d\n",
1934 __func__, err);
1935 if (err < 0)
1936 goto exit_host_unregister;
1937 /* v4l2_device_register_subdev() took a reference too */
1938 module_put(pcdev->csi2_sd->owner);
2229 } 1939 }
2230 1940
2231 return 0; 1941 return 0;
2232 1942
2233exit_pdev_unregister:
2234 platform_device_del(pcdev->csi2_pdev);
2235exit_pdev_put:
2236 pcdev->csi2_pdev->resource = NULL;
2237 platform_device_put(pcdev->csi2_pdev);
2238exit_host_unregister: 1943exit_host_unregister:
2239 soc_camera_host_unregister(&pcdev->ici); 1944 soc_camera_host_unregister(&pcdev->ici);
1945exit_csi2_unregister:
1946 if (csi2) {
1947 module_put(pcdev->csi2_pdev->dev.driver->owner);
1948exit_pdev_unregister:
1949 platform_device_del(pcdev->csi2_pdev);
1950exit_pdev_put:
1951 pcdev->csi2_pdev->resource = NULL;
1952 platform_device_put(pcdev->csi2_pdev);
1953 }
2240exit_free_ctx: 1954exit_free_ctx:
2241 vb2_dma_contig_cleanup_ctx(pcdev->alloc_ctx); 1955 vb2_dma_contig_cleanup_ctx(pcdev->alloc_ctx);
2242exit_free_clk: 1956exit_free_clk:
@@ -2287,10 +2001,18 @@ static const struct dev_pm_ops sh_mobile_ceu_dev_pm_ops = {
2287 .runtime_resume = sh_mobile_ceu_runtime_nop, 2001 .runtime_resume = sh_mobile_ceu_runtime_nop,
2288}; 2002};
2289 2003
2004static const struct of_device_id sh_mobile_ceu_of_match[] = {
2005 { .compatible = "renesas,sh-mobile-ceu" },
2006 { }
2007};
2008MODULE_DEVICE_TABLE(of, sh_mobile_ceu_of_match);
2009
2290static struct platform_driver sh_mobile_ceu_driver = { 2010static struct platform_driver sh_mobile_ceu_driver = {
2291 .driver = { 2011 .driver = {
2292 .name = "sh_mobile_ceu", 2012 .name = "sh_mobile_ceu",
2013 .owner = THIS_MODULE,
2293 .pm = &sh_mobile_ceu_dev_pm_ops, 2014 .pm = &sh_mobile_ceu_dev_pm_ops,
2015 .of_match_table = sh_mobile_ceu_of_match,
2294 }, 2016 },
2295 .probe = sh_mobile_ceu_probe, 2017 .probe = sh_mobile_ceu_probe,
2296 .remove = sh_mobile_ceu_remove, 2018 .remove = sh_mobile_ceu_remove,
@@ -2314,5 +2036,5 @@ module_exit(sh_mobile_ceu_exit);
2314MODULE_DESCRIPTION("SuperH Mobile CEU driver"); 2036MODULE_DESCRIPTION("SuperH Mobile CEU driver");
2315MODULE_AUTHOR("Magnus Damm"); 2037MODULE_AUTHOR("Magnus Damm");
2316MODULE_LICENSE("GPL"); 2038MODULE_LICENSE("GPL");
2317MODULE_VERSION("0.0.6"); 2039MODULE_VERSION("0.1.0");
2318MODULE_ALIAS("platform:sh_mobile_ceu"); 2040MODULE_ALIAS("platform:sh_mobile_ceu");
diff --git a/drivers/media/platform/soc_camera/sh_mobile_csi2.c b/drivers/media/platform/soc_camera/sh_mobile_csi2.c
index 09cb4fc88f34..05dd21a35d63 100644
--- a/drivers/media/platform/soc_camera/sh_mobile_csi2.c
+++ b/drivers/media/platform/soc_camera/sh_mobile_csi2.c
@@ -36,7 +36,6 @@
36 36
37struct sh_csi2 { 37struct sh_csi2 {
38 struct v4l2_subdev subdev; 38 struct v4l2_subdev subdev;
39 struct list_head list;
40 unsigned int irq; 39 unsigned int irq;
41 unsigned long mipi_flags; 40 unsigned long mipi_flags;
42 void __iomem *base; 41 void __iomem *base;
@@ -44,6 +43,8 @@ struct sh_csi2 {
44 struct sh_csi2_client_config *client; 43 struct sh_csi2_client_config *client;
45}; 44};
46 45
46static void sh_csi2_hwinit(struct sh_csi2 *priv);
47
47static int sh_csi2_try_fmt(struct v4l2_subdev *sd, 48static int sh_csi2_try_fmt(struct v4l2_subdev *sd,
48 struct v4l2_mbus_framefmt *mf) 49 struct v4l2_mbus_framefmt *mf)
49{ 50{
@@ -132,10 +133,58 @@ static int sh_csi2_s_fmt(struct v4l2_subdev *sd,
132static int sh_csi2_g_mbus_config(struct v4l2_subdev *sd, 133static int sh_csi2_g_mbus_config(struct v4l2_subdev *sd,
133 struct v4l2_mbus_config *cfg) 134 struct v4l2_mbus_config *cfg)
134{ 135{
135 cfg->flags = V4L2_MBUS_PCLK_SAMPLE_RISING | 136 struct sh_csi2 *priv = container_of(sd, struct sh_csi2, subdev);
136 V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_HIGH | 137
137 V4L2_MBUS_MASTER | V4L2_MBUS_DATA_ACTIVE_HIGH; 138 if (!priv->mipi_flags) {
138 cfg->type = V4L2_MBUS_PARALLEL; 139 struct soc_camera_device *icd = v4l2_get_subdev_hostdata(sd);
140 struct v4l2_subdev *client_sd = soc_camera_to_subdev(icd);
141 struct sh_csi2_pdata *pdata = priv->pdev->dev.platform_data;
142 unsigned long common_flags, csi2_flags;
143 struct v4l2_mbus_config client_cfg = {.type = V4L2_MBUS_CSI2,};
144 int ret;
145
146 /* Check if we can support this camera */
147 csi2_flags = V4L2_MBUS_CSI2_CONTINUOUS_CLOCK |
148 V4L2_MBUS_CSI2_1_LANE;
149
150 switch (pdata->type) {
151 case SH_CSI2C:
152 if (priv->client->lanes != 1)
153 csi2_flags |= V4L2_MBUS_CSI2_2_LANE;
154 break;
155 case SH_CSI2I:
156 switch (priv->client->lanes) {
157 default:
158 csi2_flags |= V4L2_MBUS_CSI2_4_LANE;
159 case 3:
160 csi2_flags |= V4L2_MBUS_CSI2_3_LANE;
161 case 2:
162 csi2_flags |= V4L2_MBUS_CSI2_2_LANE;
163 }
164 }
165
166 ret = v4l2_subdev_call(client_sd, video, g_mbus_config, &client_cfg);
167 if (ret == -ENOIOCTLCMD)
168 common_flags = csi2_flags;
169 else if (!ret)
170 common_flags = soc_mbus_config_compatible(&client_cfg,
171 csi2_flags);
172 else
173 common_flags = 0;
174
175 if (!common_flags)
176 return -EINVAL;
177
178 /* All good: camera MIPI configuration supported */
179 priv->mipi_flags = common_flags;
180 }
181
182 if (cfg) {
183 cfg->flags = V4L2_MBUS_PCLK_SAMPLE_RISING |
184 V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_HIGH |
185 V4L2_MBUS_MASTER | V4L2_MBUS_DATA_ACTIVE_HIGH;
186 cfg->type = V4L2_MBUS_PARALLEL;
187 }
139 188
140 return 0; 189 return 0;
141} 190}
@@ -146,8 +195,17 @@ static int sh_csi2_s_mbus_config(struct v4l2_subdev *sd,
146 struct sh_csi2 *priv = container_of(sd, struct sh_csi2, subdev); 195 struct sh_csi2 *priv = container_of(sd, struct sh_csi2, subdev);
147 struct soc_camera_device *icd = v4l2_get_subdev_hostdata(sd); 196 struct soc_camera_device *icd = v4l2_get_subdev_hostdata(sd);
148 struct v4l2_subdev *client_sd = soc_camera_to_subdev(icd); 197 struct v4l2_subdev *client_sd = soc_camera_to_subdev(icd);
149 struct v4l2_mbus_config client_cfg = {.type = V4L2_MBUS_CSI2, 198 struct v4l2_mbus_config client_cfg = {.type = V4L2_MBUS_CSI2,};
150 .flags = priv->mipi_flags}; 199 int ret = sh_csi2_g_mbus_config(sd, NULL);
200
201 if (ret < 0)
202 return ret;
203
204 pm_runtime_get_sync(&priv->pdev->dev);
205
206 sh_csi2_hwinit(priv);
207
208 client_cfg.flags = priv->mipi_flags;
151 209
152 return v4l2_subdev_call(client_sd, video, s_mbus_config, &client_cfg); 210 return v4l2_subdev_call(client_sd, video, s_mbus_config, &client_cfg);
153} 211}
@@ -202,19 +260,19 @@ static void sh_csi2_hwinit(struct sh_csi2 *priv)
202 260
203static int sh_csi2_client_connect(struct sh_csi2 *priv) 261static int sh_csi2_client_connect(struct sh_csi2 *priv)
204{ 262{
205 struct sh_csi2_pdata *pdata = priv->pdev->dev.platform_data;
206 struct soc_camera_device *icd = v4l2_get_subdev_hostdata(&priv->subdev);
207 struct v4l2_subdev *client_sd = soc_camera_to_subdev(icd);
208 struct device *dev = v4l2_get_subdevdata(&priv->subdev); 263 struct device *dev = v4l2_get_subdevdata(&priv->subdev);
209 struct v4l2_mbus_config cfg; 264 struct sh_csi2_pdata *pdata = dev->platform_data;
210 unsigned long common_flags, csi2_flags; 265 struct soc_camera_device *icd = v4l2_get_subdev_hostdata(&priv->subdev);
211 int i, ret; 266 int i;
212 267
213 if (priv->client) 268 if (priv->client)
214 return -EBUSY; 269 return -EBUSY;
215 270
216 for (i = 0; i < pdata->num_clients; i++) 271 for (i = 0; i < pdata->num_clients; i++)
217 if (&pdata->clients[i].pdev->dev == icd->pdev) 272 if ((pdata->clients[i].pdev &&
273 &pdata->clients[i].pdev->dev == icd->pdev) ||
274 (icd->control &&
275 strcmp(pdata->clients[i].name, dev_name(icd->control))))
218 break; 276 break;
219 277
220 dev_dbg(dev, "%s(%p): found #%d\n", __func__, dev, i); 278 dev_dbg(dev, "%s(%p): found #%d\n", __func__, dev, i);
@@ -222,46 +280,8 @@ static int sh_csi2_client_connect(struct sh_csi2 *priv)
222 if (i == pdata->num_clients) 280 if (i == pdata->num_clients)
223 return -ENODEV; 281 return -ENODEV;
224 282
225 /* Check if we can support this camera */
226 csi2_flags = V4L2_MBUS_CSI2_CONTINUOUS_CLOCK | V4L2_MBUS_CSI2_1_LANE;
227
228 switch (pdata->type) {
229 case SH_CSI2C:
230 if (pdata->clients[i].lanes != 1)
231 csi2_flags |= V4L2_MBUS_CSI2_2_LANE;
232 break;
233 case SH_CSI2I:
234 switch (pdata->clients[i].lanes) {
235 default:
236 csi2_flags |= V4L2_MBUS_CSI2_4_LANE;
237 case 3:
238 csi2_flags |= V4L2_MBUS_CSI2_3_LANE;
239 case 2:
240 csi2_flags |= V4L2_MBUS_CSI2_2_LANE;
241 }
242 }
243
244 cfg.type = V4L2_MBUS_CSI2;
245 ret = v4l2_subdev_call(client_sd, video, g_mbus_config, &cfg);
246 if (ret == -ENOIOCTLCMD)
247 common_flags = csi2_flags;
248 else if (!ret)
249 common_flags = soc_mbus_config_compatible(&cfg,
250 csi2_flags);
251 else
252 common_flags = 0;
253
254 if (!common_flags)
255 return -EINVAL;
256
257 /* All good: camera MIPI configuration supported */
258 priv->mipi_flags = common_flags;
259 priv->client = pdata->clients + i; 283 priv->client = pdata->clients + i;
260 284
261 pm_runtime_get_sync(dev);
262
263 sh_csi2_hwinit(priv);
264
265 return 0; 285 return 0;
266} 286}
267 287
@@ -304,11 +324,18 @@ static int sh_csi2_probe(struct platform_device *pdev)
304 /* Platform data specify the PHY, lanes, ECC, CRC */ 324 /* Platform data specify the PHY, lanes, ECC, CRC */
305 struct sh_csi2_pdata *pdata = pdev->dev.platform_data; 325 struct sh_csi2_pdata *pdata = pdev->dev.platform_data;
306 326
327 if (!pdata)
328 return -EINVAL;
329
330 priv = devm_kzalloc(&pdev->dev, sizeof(struct sh_csi2), GFP_KERNEL);
331 if (!priv)
332 return -ENOMEM;
333
307 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 334 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
308 /* Interrupt unused so far */ 335 /* Interrupt unused so far */
309 irq = platform_get_irq(pdev, 0); 336 irq = platform_get_irq(pdev, 0);
310 337
311 if (!res || (int)irq <= 0 || !pdata) { 338 if (!res || (int)irq <= 0) {
312 dev_err(&pdev->dev, "Not enough CSI2 platform resources.\n"); 339 dev_err(&pdev->dev, "Not enough CSI2 platform resources.\n");
313 return -ENODEV; 340 return -ENODEV;
314 } 341 }
@@ -319,10 +346,6 @@ static int sh_csi2_probe(struct platform_device *pdev)
319 return -EINVAL; 346 return -EINVAL;
320 } 347 }
321 348
322 priv = devm_kzalloc(&pdev->dev, sizeof(struct sh_csi2), GFP_KERNEL);
323 if (!priv)
324 return -ENOMEM;
325
326 priv->irq = irq; 349 priv->irq = irq;
327 350
328 priv->base = devm_ioremap_resource(&pdev->dev, res); 351 priv->base = devm_ioremap_resource(&pdev->dev, res);
@@ -330,37 +353,35 @@ static int sh_csi2_probe(struct platform_device *pdev)
330 return PTR_ERR(priv->base); 353 return PTR_ERR(priv->base);
331 354
332 priv->pdev = pdev; 355 priv->pdev = pdev;
333 platform_set_drvdata(pdev, priv); 356 priv->subdev.owner = THIS_MODULE;
357 priv->subdev.dev = &pdev->dev;
358 platform_set_drvdata(pdev, &priv->subdev);
334 359
335 v4l2_subdev_init(&priv->subdev, &sh_csi2_subdev_ops); 360 v4l2_subdev_init(&priv->subdev, &sh_csi2_subdev_ops);
336 v4l2_set_subdevdata(&priv->subdev, &pdev->dev); 361 v4l2_set_subdevdata(&priv->subdev, &pdev->dev);
337 362
338 snprintf(priv->subdev.name, V4L2_SUBDEV_NAME_SIZE, "%s.mipi-csi", 363 snprintf(priv->subdev.name, V4L2_SUBDEV_NAME_SIZE, "%s.mipi-csi",
339 dev_name(pdata->v4l2_dev->dev)); 364 dev_name(&pdev->dev));
340 ret = v4l2_device_register_subdev(pdata->v4l2_dev, &priv->subdev); 365
341 dev_dbg(&pdev->dev, "%s(%p): ret(register_subdev) = %d\n", __func__, priv, ret); 366 ret = v4l2_async_register_subdev(&priv->subdev);
342 if (ret < 0) 367 if (ret < 0)
343 goto esdreg; 368 return ret;
344 369
345 pm_runtime_enable(&pdev->dev); 370 pm_runtime_enable(&pdev->dev);
346 371
347 dev_dbg(&pdev->dev, "CSI2 probed.\n"); 372 dev_dbg(&pdev->dev, "CSI2 probed.\n");
348 373
349 return 0; 374 return 0;
350
351esdreg:
352 platform_set_drvdata(pdev, NULL);
353
354 return ret;
355} 375}
356 376
357static int sh_csi2_remove(struct platform_device *pdev) 377static int sh_csi2_remove(struct platform_device *pdev)
358{ 378{
359 struct sh_csi2 *priv = platform_get_drvdata(pdev); 379 struct v4l2_subdev *subdev = platform_get_drvdata(pdev);
380 struct sh_csi2 *priv = container_of(subdev, struct sh_csi2, subdev);
360 381
361 v4l2_device_unregister_subdev(&priv->subdev); 382 v4l2_async_unregister_subdev(&priv->subdev);
383 v4l2_device_unregister_subdev(subdev);
362 pm_runtime_disable(&pdev->dev); 384 pm_runtime_disable(&pdev->dev);
363 platform_set_drvdata(pdev, NULL);
364 385
365 return 0; 386 return 0;
366} 387}
diff --git a/drivers/media/platform/soc_camera/soc_camera.c b/drivers/media/platform/soc_camera/soc_camera.c
index 3a4efbdc7668..2dd0e5272941 100644
--- a/drivers/media/platform/soc_camera/soc_camera.c
+++ b/drivers/media/platform/soc_camera/soc_camera.c
@@ -21,21 +21,23 @@
21#include <linux/i2c.h> 21#include <linux/i2c.h>
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/list.h> 23#include <linux/list.h>
24#include <linux/mutex.h>
25#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/mutex.h>
26#include <linux/platform_device.h> 26#include <linux/platform_device.h>
27#include <linux/pm_runtime.h>
27#include <linux/regulator/consumer.h> 28#include <linux/regulator/consumer.h>
28#include <linux/slab.h> 29#include <linux/slab.h>
29#include <linux/pm_runtime.h>
30#include <linux/vmalloc.h> 30#include <linux/vmalloc.h>
31 31
32#include <media/soc_camera.h> 32#include <media/soc_camera.h>
33#include <media/soc_mediabus.h>
34#include <media/v4l2-async.h>
35#include <media/v4l2-clk.h>
33#include <media/v4l2-common.h> 36#include <media/v4l2-common.h>
34#include <media/v4l2-ioctl.h> 37#include <media/v4l2-ioctl.h>
35#include <media/v4l2-dev.h> 38#include <media/v4l2-dev.h>
36#include <media/videobuf-core.h> 39#include <media/videobuf-core.h>
37#include <media/videobuf2-core.h> 40#include <media/videobuf2-core.h>
38#include <media/soc_mediabus.h>
39 41
40/* Default to VGA resolution */ 42/* Default to VGA resolution */
41#define DEFAULT_WIDTH 640 43#define DEFAULT_WIDTH 640
@@ -46,17 +48,39 @@
46 (icd)->vb_vidq.streaming : \ 48 (icd)->vb_vidq.streaming : \
47 vb2_is_streaming(&(icd)->vb2_vidq)) 49 vb2_is_streaming(&(icd)->vb2_vidq))
48 50
51#define MAP_MAX_NUM 32
52static DECLARE_BITMAP(device_map, MAP_MAX_NUM);
49static LIST_HEAD(hosts); 53static LIST_HEAD(hosts);
50static LIST_HEAD(devices); 54static LIST_HEAD(devices);
51static DEFINE_MUTEX(list_lock); /* Protects the list of hosts */ 55/*
56 * Protects lists and bitmaps of hosts and devices.
57 * Lock nesting: Ok to take ->host_lock under list_lock.
58 */
59static DEFINE_MUTEX(list_lock);
60
61struct soc_camera_async_client {
62 struct v4l2_async_subdev *sensor;
63 struct v4l2_async_notifier notifier;
64 struct platform_device *pdev;
65 struct list_head list; /* needed for clean up */
66};
67
68static int soc_camera_video_start(struct soc_camera_device *icd);
69static int video_dev_create(struct soc_camera_device *icd);
52 70
53int soc_camera_power_on(struct device *dev, struct soc_camera_subdev_desc *ssdd) 71int soc_camera_power_on(struct device *dev, struct soc_camera_subdev_desc *ssdd,
72 struct v4l2_clk *clk)
54{ 73{
55 int ret = regulator_bulk_enable(ssdd->num_regulators, 74 int ret = clk ? v4l2_clk_enable(clk) : 0;
75 if (ret < 0) {
76 dev_err(dev, "Cannot enable clock: %d\n", ret);
77 return ret;
78 }
79 ret = regulator_bulk_enable(ssdd->num_regulators,
56 ssdd->regulators); 80 ssdd->regulators);
57 if (ret < 0) { 81 if (ret < 0) {
58 dev_err(dev, "Cannot enable regulators\n"); 82 dev_err(dev, "Cannot enable regulators\n");
59 return ret; 83 goto eregenable;
60 } 84 }
61 85
62 if (ssdd->power) { 86 if (ssdd->power) {
@@ -64,16 +88,25 @@ int soc_camera_power_on(struct device *dev, struct soc_camera_subdev_desc *ssdd)
64 if (ret < 0) { 88 if (ret < 0) {
65 dev_err(dev, 89 dev_err(dev,
66 "Platform failed to power-on the camera.\n"); 90 "Platform failed to power-on the camera.\n");
67 regulator_bulk_disable(ssdd->num_regulators, 91 goto epwron;
68 ssdd->regulators);
69 } 92 }
70 } 93 }
71 94
95 return 0;
96
97epwron:
98 regulator_bulk_disable(ssdd->num_regulators,
99 ssdd->regulators);
100eregenable:
101 if (clk)
102 v4l2_clk_disable(clk);
103
72 return ret; 104 return ret;
73} 105}
74EXPORT_SYMBOL(soc_camera_power_on); 106EXPORT_SYMBOL(soc_camera_power_on);
75 107
76int soc_camera_power_off(struct device *dev, struct soc_camera_subdev_desc *ssdd) 108int soc_camera_power_off(struct device *dev, struct soc_camera_subdev_desc *ssdd,
109 struct v4l2_clk *clk)
77{ 110{
78 int ret = 0; 111 int ret = 0;
79 int err; 112 int err;
@@ -94,10 +127,21 @@ int soc_camera_power_off(struct device *dev, struct soc_camera_subdev_desc *ssdd
94 ret = ret ? : err; 127 ret = ret ? : err;
95 } 128 }
96 129
130 if (clk)
131 v4l2_clk_disable(clk);
132
97 return ret; 133 return ret;
98} 134}
99EXPORT_SYMBOL(soc_camera_power_off); 135EXPORT_SYMBOL(soc_camera_power_off);
100 136
137int soc_camera_power_init(struct device *dev, struct soc_camera_subdev_desc *ssdd)
138{
139
140 return devm_regulator_bulk_get(dev, ssdd->num_regulators,
141 ssdd->regulators);
142}
143EXPORT_SYMBOL(soc_camera_power_init);
144
101static int __soc_camera_power_on(struct soc_camera_device *icd) 145static int __soc_camera_power_on(struct soc_camera_device *icd)
102{ 146{
103 struct v4l2_subdev *sd = soc_camera_to_subdev(icd); 147 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
@@ -235,7 +279,6 @@ static int soc_camera_enum_input(struct file *file, void *priv,
235 279
236 /* default is camera */ 280 /* default is camera */
237 inp->type = V4L2_INPUT_TYPE_CAMERA; 281 inp->type = V4L2_INPUT_TYPE_CAMERA;
238 inp->std = V4L2_STD_UNKNOWN;
239 strcpy(inp->name, "Camera"); 282 strcpy(inp->name, "Camera");
240 283
241 return 0; 284 return 0;
@@ -505,6 +548,58 @@ static int soc_camera_set_fmt(struct soc_camera_device *icd,
505 return ici->ops->set_bus_param(icd); 548 return ici->ops->set_bus_param(icd);
506} 549}
507 550
551static int soc_camera_add_device(struct soc_camera_device *icd)
552{
553 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
554 int ret;
555
556 if (ici->icd)
557 return -EBUSY;
558
559 if (!icd->clk) {
560 mutex_lock(&ici->clk_lock);
561 ret = ici->ops->clock_start(ici);
562 mutex_unlock(&ici->clk_lock);
563 if (ret < 0)
564 return ret;
565 }
566
567 if (ici->ops->add) {
568 ret = ici->ops->add(icd);
569 if (ret < 0)
570 goto eadd;
571 }
572
573 ici->icd = icd;
574
575 return 0;
576
577eadd:
578 if (!icd->clk) {
579 mutex_lock(&ici->clk_lock);
580 ici->ops->clock_stop(ici);
581 mutex_unlock(&ici->clk_lock);
582 }
583 return ret;
584}
585
586static void soc_camera_remove_device(struct soc_camera_device *icd)
587{
588 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
589
590 if (WARN_ON(icd != ici->icd))
591 return;
592
593 if (ici->ops->remove)
594 ici->ops->remove(icd);
595 if (!icd->clk) {
596 mutex_lock(&ici->clk_lock);
597 ici->ops->clock_stop(ici);
598 mutex_unlock(&ici->clk_lock);
599 }
600 ici->icd = NULL;
601}
602
508static int soc_camera_open(struct file *file) 603static int soc_camera_open(struct file *file)
509{ 604{
510 struct video_device *vdev = video_devdata(file); 605 struct video_device *vdev = video_devdata(file);
@@ -525,7 +620,7 @@ static int soc_camera_open(struct file *file)
525 return -ENODEV; 620 return -ENODEV;
526 } 621 }
527 622
528 icd = dev_get_drvdata(vdev->parent); 623 icd = video_get_drvdata(vdev);
529 ici = to_soc_camera_host(icd->parent); 624 ici = to_soc_camera_host(icd->parent);
530 625
531 ret = try_module_get(ici->ops->owner) ? 0 : -ENODEV; 626 ret = try_module_get(ici->ops->owner) ? 0 : -ENODEV;
@@ -568,7 +663,7 @@ static int soc_camera_open(struct file *file)
568 if (sdesc->subdev_desc.reset) 663 if (sdesc->subdev_desc.reset)
569 sdesc->subdev_desc.reset(icd->pdev); 664 sdesc->subdev_desc.reset(icd->pdev);
570 665
571 ret = ici->ops->add(icd); 666 ret = soc_camera_add_device(icd);
572 if (ret < 0) { 667 if (ret < 0) {
573 dev_err(icd->pdev, "Couldn't activate the camera: %d\n", ret); 668 dev_err(icd->pdev, "Couldn't activate the camera: %d\n", ret);
574 goto eiciadd; 669 goto eiciadd;
@@ -610,8 +705,8 @@ static int soc_camera_open(struct file *file)
610 return 0; 705 return 0;
611 706
612 /* 707 /*
613 * First four errors are entered with the .host_lock held 708 * All errors are entered with the .host_lock held, first four also
614 * and use_count == 1 709 * with use_count == 1
615 */ 710 */
616einitvb: 711einitvb:
617esfmt: 712esfmt:
@@ -619,7 +714,7 @@ esfmt:
619eresume: 714eresume:
620 __soc_camera_power_off(icd); 715 __soc_camera_power_off(icd);
621epower: 716epower:
622 ici->ops->remove(icd); 717 soc_camera_remove_device(icd);
623eiciadd: 718eiciadd:
624 icd->use_count--; 719 icd->use_count--;
625 mutex_unlock(&ici->host_lock); 720 mutex_unlock(&ici->host_lock);
@@ -645,7 +740,7 @@ static int soc_camera_close(struct file *file)
645 vb2_queue_release(&icd->vb2_vidq); 740 vb2_queue_release(&icd->vb2_vidq);
646 __soc_camera_power_off(icd); 741 __soc_camera_power_off(icd);
647 742
648 ici->ops->remove(icd); 743 soc_camera_remove_device(icd);
649 } 744 }
650 745
651 if (icd->streamer == file) 746 if (icd->streamer == file)
@@ -1036,76 +1131,225 @@ static int soc_camera_s_parm(struct file *file, void *fh,
1036 return -ENOIOCTLCMD; 1131 return -ENOIOCTLCMD;
1037} 1132}
1038 1133
1039static int soc_camera_g_chip_ident(struct file *file, void *fh, 1134static int soc_camera_probe(struct soc_camera_host *ici,
1040 struct v4l2_dbg_chip_ident *id) 1135 struct soc_camera_device *icd);
1136
1137/* So far this function cannot fail */
1138static void scan_add_host(struct soc_camera_host *ici)
1041{ 1139{
1042 struct soc_camera_device *icd = file->private_data; 1140 struct soc_camera_device *icd;
1043 struct v4l2_subdev *sd = soc_camera_to_subdev(icd); 1141
1142 mutex_lock(&list_lock);
1143
1144 list_for_each_entry(icd, &devices, list)
1145 if (icd->iface == ici->nr) {
1146 struct soc_camera_desc *sdesc = to_soc_camera_desc(icd);
1147 struct soc_camera_subdev_desc *ssdd = &sdesc->subdev_desc;
1148
1149 /* The camera could have been already on, try to reset */
1150 if (ssdd->reset)
1151 ssdd->reset(icd->pdev);
1044 1152
1045 return v4l2_subdev_call(sd, core, g_chip_ident, id); 1153 icd->parent = ici->v4l2_dev.dev;
1154
1155 /* Ignore errors */
1156 soc_camera_probe(ici, icd);
1157 }
1158
1159 mutex_unlock(&list_lock);
1046} 1160}
1047 1161
1048#ifdef CONFIG_VIDEO_ADV_DEBUG 1162/*
1049static int soc_camera_g_register(struct file *file, void *fh, 1163 * It is invalid to call v4l2_clk_enable() after a successful probing
1050 struct v4l2_dbg_register *reg) 1164 * asynchronously outside of V4L2 operations, i.e. with .host_lock not held.
1165 */
1166static int soc_camera_clk_enable(struct v4l2_clk *clk)
1051{ 1167{
1052 struct soc_camera_device *icd = file->private_data; 1168 struct soc_camera_device *icd = clk->priv;
1053 struct v4l2_subdev *sd = soc_camera_to_subdev(icd); 1169 struct soc_camera_host *ici;
1170 int ret;
1171
1172 if (!icd || !icd->parent)
1173 return -ENODEV;
1174
1175 ici = to_soc_camera_host(icd->parent);
1176
1177 if (!try_module_get(ici->ops->owner))
1178 return -ENODEV;
1054 1179
1055 return v4l2_subdev_call(sd, core, g_register, reg); 1180 /*
1181 * If a different client is currently being probed, the host will tell
1182 * you to go
1183 */
1184 mutex_lock(&ici->clk_lock);
1185 ret = ici->ops->clock_start(ici);
1186 mutex_unlock(&ici->clk_lock);
1187 return ret;
1056} 1188}
1057 1189
1058static int soc_camera_s_register(struct file *file, void *fh, 1190static void soc_camera_clk_disable(struct v4l2_clk *clk)
1059 const struct v4l2_dbg_register *reg)
1060{ 1191{
1061 struct soc_camera_device *icd = file->private_data; 1192 struct soc_camera_device *icd = clk->priv;
1062 struct v4l2_subdev *sd = soc_camera_to_subdev(icd); 1193 struct soc_camera_host *ici;
1194
1195 if (!icd || !icd->parent)
1196 return;
1197
1198 ici = to_soc_camera_host(icd->parent);
1199
1200 mutex_lock(&ici->clk_lock);
1201 ici->ops->clock_stop(ici);
1202 mutex_unlock(&ici->clk_lock);
1063 1203
1064 return v4l2_subdev_call(sd, core, s_register, reg); 1204 module_put(ici->ops->owner);
1065} 1205}
1066#endif
1067 1206
1068static int soc_camera_probe(struct soc_camera_device *icd); 1207/*
1208 * Eventually, it would be more logical to make the respective host the clock
1209 * owner, but then we would have to copy this struct for each ici. Besides, it
1210 * would introduce the circular dependency problem, unless we port all client
1211 * drivers to release the clock, when not in use.
1212 */
1213static const struct v4l2_clk_ops soc_camera_clk_ops = {
1214 .owner = THIS_MODULE,
1215 .enable = soc_camera_clk_enable,
1216 .disable = soc_camera_clk_disable,
1217};
1069 1218
1070/* So far this function cannot fail */ 1219static int soc_camera_dyn_pdev(struct soc_camera_desc *sdesc,
1071static void scan_add_host(struct soc_camera_host *ici) 1220 struct soc_camera_async_client *sasc)
1072{ 1221{
1073 struct soc_camera_device *icd; 1222 struct platform_device *pdev;
1223 int ret, i;
1074 1224
1075 mutex_lock(&list_lock); 1225 mutex_lock(&list_lock);
1226 i = find_first_zero_bit(device_map, MAP_MAX_NUM);
1227 if (i < MAP_MAX_NUM)
1228 set_bit(i, device_map);
1229 mutex_unlock(&list_lock);
1230 if (i >= MAP_MAX_NUM)
1231 return -ENOMEM;
1076 1232
1077 list_for_each_entry(icd, &devices, list) { 1233 pdev = platform_device_alloc("soc-camera-pdrv", i);
1078 if (icd->iface == ici->nr) { 1234 if (!pdev)
1079 icd->parent = ici->v4l2_dev.dev; 1235 return -ENOMEM;
1080 soc_camera_probe(icd); 1236
1081 } 1237 ret = platform_device_add_data(pdev, sdesc, sizeof(*sdesc));
1238 if (ret < 0) {
1239 platform_device_put(pdev);
1240 return ret;
1082 } 1241 }
1083 1242
1084 mutex_unlock(&list_lock); 1243 sasc->pdev = pdev;
1244
1245 return 0;
1246}
1247
1248static struct soc_camera_device *soc_camera_add_pdev(struct soc_camera_async_client *sasc)
1249{
1250 struct platform_device *pdev = sasc->pdev;
1251 int ret;
1252
1253 ret = platform_device_add(pdev);
1254 if (ret < 0 || !pdev->dev.driver)
1255 return NULL;
1256
1257 return platform_get_drvdata(pdev);
1258}
1259
1260/* Locking: called with .host_lock held */
1261static int soc_camera_probe_finish(struct soc_camera_device *icd)
1262{
1263 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
1264 struct v4l2_mbus_framefmt mf;
1265 int ret;
1266
1267 sd->grp_id = soc_camera_grp_id(icd);
1268 v4l2_set_subdev_hostdata(sd, icd);
1269
1270 ret = v4l2_ctrl_add_handler(&icd->ctrl_handler, sd->ctrl_handler, NULL);
1271 if (ret < 0)
1272 return ret;
1273
1274 ret = soc_camera_add_device(icd);
1275 if (ret < 0) {
1276 dev_err(icd->pdev, "Couldn't activate the camera: %d\n", ret);
1277 return ret;
1278 }
1279
1280 /* At this point client .probe() should have run already */
1281 ret = soc_camera_init_user_formats(icd);
1282 if (ret < 0)
1283 goto eusrfmt;
1284
1285 icd->field = V4L2_FIELD_ANY;
1286
1287 ret = soc_camera_video_start(icd);
1288 if (ret < 0)
1289 goto evidstart;
1290
1291 /* Try to improve our guess of a reasonable window format */
1292 if (!v4l2_subdev_call(sd, video, g_mbus_fmt, &mf)) {
1293 icd->user_width = mf.width;
1294 icd->user_height = mf.height;
1295 icd->colorspace = mf.colorspace;
1296 icd->field = mf.field;
1297 }
1298 soc_camera_remove_device(icd);
1299
1300 return 0;
1301
1302evidstart:
1303 soc_camera_free_user_formats(icd);
1304eusrfmt:
1305 soc_camera_remove_device(icd);
1306
1307 return ret;
1085} 1308}
1086 1309
1087#ifdef CONFIG_I2C_BOARDINFO 1310#ifdef CONFIG_I2C_BOARDINFO
1088static int soc_camera_init_i2c(struct soc_camera_device *icd, 1311static int soc_camera_i2c_init(struct soc_camera_device *icd,
1089 struct soc_camera_desc *sdesc) 1312 struct soc_camera_desc *sdesc)
1090{ 1313{
1091 struct i2c_client *client; 1314 struct i2c_client *client;
1092 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 1315 struct soc_camera_host *ici;
1093 struct soc_camera_host_desc *shd = &sdesc->host_desc; 1316 struct soc_camera_host_desc *shd = &sdesc->host_desc;
1094 struct i2c_adapter *adap = i2c_get_adapter(shd->i2c_adapter_id); 1317 struct i2c_adapter *adap;
1095 struct v4l2_subdev *subdev; 1318 struct v4l2_subdev *subdev;
1319 char clk_name[V4L2_SUBDEV_NAME_SIZE];
1320 int ret;
1096 1321
1322 /* First find out how we link the main client */
1323 if (icd->sasc) {
1324 /* Async non-OF probing handled by the subdevice list */
1325 return -EPROBE_DEFER;
1326 }
1327
1328 ici = to_soc_camera_host(icd->parent);
1329 adap = i2c_get_adapter(shd->i2c_adapter_id);
1097 if (!adap) { 1330 if (!adap) {
1098 dev_err(icd->pdev, "Cannot get I2C adapter #%d. No driver?\n", 1331 dev_err(icd->pdev, "Cannot get I2C adapter #%d. No driver?\n",
1099 shd->i2c_adapter_id); 1332 shd->i2c_adapter_id);
1100 goto ei2cga; 1333 return -ENODEV;
1101 } 1334 }
1102 1335
1103 shd->board_info->platform_data = &sdesc->subdev_desc; 1336 shd->board_info->platform_data = &sdesc->subdev_desc;
1104 1337
1338 snprintf(clk_name, sizeof(clk_name), "%d-%04x",
1339 shd->i2c_adapter_id, shd->board_info->addr);
1340
1341 icd->clk = v4l2_clk_register(&soc_camera_clk_ops, clk_name, "mclk", icd);
1342 if (IS_ERR(icd->clk)) {
1343 ret = PTR_ERR(icd->clk);
1344 goto eclkreg;
1345 }
1346
1105 subdev = v4l2_i2c_new_subdev_board(&ici->v4l2_dev, adap, 1347 subdev = v4l2_i2c_new_subdev_board(&ici->v4l2_dev, adap,
1106 shd->board_info, NULL); 1348 shd->board_info, NULL);
1107 if (!subdev) 1349 if (!subdev) {
1350 ret = -ENODEV;
1108 goto ei2cnd; 1351 goto ei2cnd;
1352 }
1109 1353
1110 client = v4l2_get_subdevdata(subdev); 1354 client = v4l2_get_subdevdata(subdev);
1111 1355
@@ -1114,39 +1358,203 @@ static int soc_camera_init_i2c(struct soc_camera_device *icd,
1114 1358
1115 return 0; 1359 return 0;
1116ei2cnd: 1360ei2cnd:
1361 v4l2_clk_unregister(icd->clk);
1362eclkreg:
1363 icd->clk = NULL;
1117 i2c_put_adapter(adap); 1364 i2c_put_adapter(adap);
1118ei2cga: 1365 return ret;
1119 return -ENODEV;
1120} 1366}
1121 1367
1122static void soc_camera_free_i2c(struct soc_camera_device *icd) 1368static void soc_camera_i2c_free(struct soc_camera_device *icd)
1123{ 1369{
1124 struct i2c_client *client = 1370 struct i2c_client *client =
1125 to_i2c_client(to_soc_camera_control(icd)); 1371 to_i2c_client(to_soc_camera_control(icd));
1126 struct i2c_adapter *adap = client->adapter; 1372 struct i2c_adapter *adap;
1127 1373
1128 icd->control = NULL; 1374 icd->control = NULL;
1375 if (icd->sasc)
1376 return;
1377
1378 adap = client->adapter;
1129 v4l2_device_unregister_subdev(i2c_get_clientdata(client)); 1379 v4l2_device_unregister_subdev(i2c_get_clientdata(client));
1130 i2c_unregister_device(client); 1380 i2c_unregister_device(client);
1131 i2c_put_adapter(adap); 1381 i2c_put_adapter(adap);
1382 v4l2_clk_unregister(icd->clk);
1383 icd->clk = NULL;
1384}
1385
1386/*
1387 * V4L2 asynchronous notifier callbacks. They are all called under a v4l2-async
1388 * internal global mutex, therefore cannot race against other asynchronous
1389 * events. Until notifier->complete() (soc_camera_async_complete()) is called,
1390 * the video device node is not registered and no V4L fops can occur. Unloading
1391 * of the host driver also calls a v4l2-async function, so also there we're
1392 * protected.
1393 */
1394static int soc_camera_async_bound(struct v4l2_async_notifier *notifier,
1395 struct v4l2_subdev *sd,
1396 struct v4l2_async_subdev *asd)
1397{
1398 struct soc_camera_async_client *sasc = container_of(notifier,
1399 struct soc_camera_async_client, notifier);
1400 struct soc_camera_device *icd = platform_get_drvdata(sasc->pdev);
1401
1402 if (asd == sasc->sensor && !WARN_ON(icd->control)) {
1403 struct i2c_client *client = v4l2_get_subdevdata(sd);
1404
1405 /*
1406 * Only now we get subdevice-specific information like
1407 * regulators, flags, callbacks, etc.
1408 */
1409 if (client) {
1410 struct soc_camera_desc *sdesc = to_soc_camera_desc(icd);
1411 struct soc_camera_subdev_desc *ssdd =
1412 soc_camera_i2c_to_desc(client);
1413 if (ssdd) {
1414 memcpy(&sdesc->subdev_desc, ssdd,
1415 sizeof(sdesc->subdev_desc));
1416 if (ssdd->reset)
1417 ssdd->reset(icd->pdev);
1418 }
1419
1420 icd->control = &client->dev;
1421 }
1422 }
1423
1424 return 0;
1425}
1426
1427static void soc_camera_async_unbind(struct v4l2_async_notifier *notifier,
1428 struct v4l2_subdev *sd,
1429 struct v4l2_async_subdev *asd)
1430{
1431 struct soc_camera_async_client *sasc = container_of(notifier,
1432 struct soc_camera_async_client, notifier);
1433 struct soc_camera_device *icd = platform_get_drvdata(sasc->pdev);
1434
1435 if (icd->clk) {
1436 v4l2_clk_unregister(icd->clk);
1437 icd->clk = NULL;
1438 }
1439}
1440
1441static int soc_camera_async_complete(struct v4l2_async_notifier *notifier)
1442{
1443 struct soc_camera_async_client *sasc = container_of(notifier,
1444 struct soc_camera_async_client, notifier);
1445 struct soc_camera_device *icd = platform_get_drvdata(sasc->pdev);
1446
1447 if (to_soc_camera_control(icd)) {
1448 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
1449 int ret;
1450
1451 mutex_lock(&list_lock);
1452 ret = soc_camera_probe(ici, icd);
1453 mutex_unlock(&list_lock);
1454 if (ret < 0)
1455 return ret;
1456 }
1457
1458 return 0;
1459}
1460
1461static int scan_async_group(struct soc_camera_host *ici,
1462 struct v4l2_async_subdev **asd, unsigned int size)
1463{
1464 struct soc_camera_async_subdev *sasd;
1465 struct soc_camera_async_client *sasc;
1466 struct soc_camera_device *icd;
1467 struct soc_camera_desc sdesc = {.host_desc.bus_id = ici->nr,};
1468 char clk_name[V4L2_SUBDEV_NAME_SIZE];
1469 int ret, i;
1470
1471 /* First look for a sensor */
1472 for (i = 0; i < size; i++) {
1473 sasd = container_of(asd[i], struct soc_camera_async_subdev, asd);
1474 if (sasd->role == SOCAM_SUBDEV_DATA_SOURCE)
1475 break;
1476 }
1477
1478 if (i == size || asd[i]->bus_type != V4L2_ASYNC_BUS_I2C) {
1479 /* All useless */
1480 dev_err(ici->v4l2_dev.dev, "No I2C data source found!\n");
1481 return -ENODEV;
1482 }
1483
1484 /* Or shall this be managed by the soc-camera device? */
1485 sasc = devm_kzalloc(ici->v4l2_dev.dev, sizeof(*sasc), GFP_KERNEL);
1486 if (!sasc)
1487 return -ENOMEM;
1488
1489 /* HACK: just need a != NULL */
1490 sdesc.host_desc.board_info = ERR_PTR(-ENODATA);
1491
1492 ret = soc_camera_dyn_pdev(&sdesc, sasc);
1493 if (ret < 0)
1494 return ret;
1495
1496 sasc->sensor = &sasd->asd;
1497
1498 icd = soc_camera_add_pdev(sasc);
1499 if (!icd) {
1500 platform_device_put(sasc->pdev);
1501 return -ENOMEM;
1502 }
1503
1504 sasc->notifier.subdev = asd;
1505 sasc->notifier.num_subdevs = size;
1506 sasc->notifier.bound = soc_camera_async_bound;
1507 sasc->notifier.unbind = soc_camera_async_unbind;
1508 sasc->notifier.complete = soc_camera_async_complete;
1509
1510 icd->sasc = sasc;
1511 icd->parent = ici->v4l2_dev.dev;
1512
1513 snprintf(clk_name, sizeof(clk_name), "%d-%04x",
1514 sasd->asd.match.i2c.adapter_id, sasd->asd.match.i2c.address);
1515
1516 icd->clk = v4l2_clk_register(&soc_camera_clk_ops, clk_name, "mclk", icd);
1517 if (IS_ERR(icd->clk)) {
1518 ret = PTR_ERR(icd->clk);
1519 goto eclkreg;
1520 }
1521
1522 ret = v4l2_async_notifier_register(&ici->v4l2_dev, &sasc->notifier);
1523 if (!ret)
1524 return 0;
1525
1526 v4l2_clk_unregister(icd->clk);
1527eclkreg:
1528 icd->clk = NULL;
1529 platform_device_unregister(sasc->pdev);
1530 dev_err(ici->v4l2_dev.dev, "group probe failed: %d\n", ret);
1531
1532 return ret;
1533}
1534
1535static void scan_async_host(struct soc_camera_host *ici)
1536{
1537 struct v4l2_async_subdev **asd;
1538 int j;
1539
1540 for (j = 0, asd = ici->asd; ici->asd_sizes[j]; j++) {
1541 scan_async_group(ici, asd, ici->asd_sizes[j]);
1542 asd += ici->asd_sizes[j];
1543 }
1132} 1544}
1133#else 1545#else
1134#define soc_camera_init_i2c(icd, sdesc) (-ENODEV) 1546#define soc_camera_i2c_init(icd, sdesc) (-ENODEV)
1135#define soc_camera_free_i2c(icd) do {} while (0) 1547#define soc_camera_i2c_free(icd) do {} while (0)
1548#define scan_async_host(ici) do {} while (0)
1136#endif 1549#endif
1137 1550
1138static int soc_camera_video_start(struct soc_camera_device *icd);
1139static int video_dev_create(struct soc_camera_device *icd);
1140/* Called during host-driver probe */ 1551/* Called during host-driver probe */
1141static int soc_camera_probe(struct soc_camera_device *icd) 1552static int soc_camera_probe(struct soc_camera_host *ici,
1553 struct soc_camera_device *icd)
1142{ 1554{
1143 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
1144 struct soc_camera_desc *sdesc = to_soc_camera_desc(icd); 1555 struct soc_camera_desc *sdesc = to_soc_camera_desc(icd);
1145 struct soc_camera_host_desc *shd = &sdesc->host_desc; 1556 struct soc_camera_host_desc *shd = &sdesc->host_desc;
1146 struct soc_camera_subdev_desc *ssdd = &sdesc->subdev_desc;
1147 struct device *control = NULL; 1557 struct device *control = NULL;
1148 struct v4l2_subdev *sd;
1149 struct v4l2_mbus_framefmt mf;
1150 int ret; 1558 int ret;
1151 1559
1152 dev_info(icd->pdev, "Probing %s\n", dev_name(icd->pdev)); 1560 dev_info(icd->pdev, "Probing %s\n", dev_name(icd->pdev));
@@ -1162,30 +1570,32 @@ static int soc_camera_probe(struct soc_camera_device *icd)
1162 if (ret < 0) 1570 if (ret < 0)
1163 return ret; 1571 return ret;
1164 1572
1165 /* The camera could have been already on, try to reset */
1166 if (ssdd->reset)
1167 ssdd->reset(icd->pdev);
1168
1169 mutex_lock(&ici->host_lock);
1170 ret = ici->ops->add(icd);
1171 mutex_unlock(&ici->host_lock);
1172 if (ret < 0)
1173 goto eadd;
1174
1175 /* Must have icd->vdev before registering the device */ 1573 /* Must have icd->vdev before registering the device */
1176 ret = video_dev_create(icd); 1574 ret = video_dev_create(icd);
1177 if (ret < 0) 1575 if (ret < 0)
1178 goto evdc; 1576 goto evdc;
1179 1577
1578 /*
1579 * ..._video_start() will create a device node, video_register_device()
1580 * itself is protected against concurrent open() calls, but we also have
1581 * to protect our data also during client probing.
1582 */
1583
1180 /* Non-i2c cameras, e.g., soc_camera_platform, have no board_info */ 1584 /* Non-i2c cameras, e.g., soc_camera_platform, have no board_info */
1181 if (shd->board_info) { 1585 if (shd->board_info) {
1182 ret = soc_camera_init_i2c(icd, sdesc); 1586 ret = soc_camera_i2c_init(icd, sdesc);
1183 if (ret < 0) 1587 if (ret < 0 && ret != -EPROBE_DEFER)
1184 goto eadddev; 1588 goto eadd;
1185 } else if (!shd->add_device || !shd->del_device) { 1589 } else if (!shd->add_device || !shd->del_device) {
1186 ret = -EINVAL; 1590 ret = -EINVAL;
1187 goto eadddev; 1591 goto eadd;
1188 } else { 1592 } else {
1593 mutex_lock(&ici->clk_lock);
1594 ret = ici->ops->clock_start(ici);
1595 mutex_unlock(&ici->clk_lock);
1596 if (ret < 0)
1597 goto eadd;
1598
1189 if (shd->module_name) 1599 if (shd->module_name)
1190 ret = request_module(shd->module_name); 1600 ret = request_module(shd->module_name);
1191 1601
@@ -1206,81 +1616,49 @@ static int soc_camera_probe(struct soc_camera_device *icd)
1206 } 1616 }
1207 } 1617 }
1208 1618
1209 sd = soc_camera_to_subdev(icd);
1210 sd->grp_id = soc_camera_grp_id(icd);
1211 v4l2_set_subdev_hostdata(sd, icd);
1212
1213 ret = v4l2_ctrl_add_handler(&icd->ctrl_handler, sd->ctrl_handler, NULL);
1214 if (ret < 0)
1215 goto ectrl;
1216
1217 /* At this point client .probe() should have run already */
1218 ret = soc_camera_init_user_formats(icd);
1219 if (ret < 0)
1220 goto eiufmt;
1221
1222 icd->field = V4L2_FIELD_ANY;
1223
1224 /*
1225 * ..._video_start() will create a device node, video_register_device()
1226 * itself is protected against concurrent open() calls, but we also have
1227 * to protect our data.
1228 */
1229 mutex_lock(&ici->host_lock); 1619 mutex_lock(&ici->host_lock);
1230 1620 ret = soc_camera_probe_finish(icd);
1231 ret = soc_camera_video_start(icd);
1232 if (ret < 0)
1233 goto evidstart;
1234
1235 /* Try to improve our guess of a reasonable window format */
1236 if (!v4l2_subdev_call(sd, video, g_mbus_fmt, &mf)) {
1237 icd->user_width = mf.width;
1238 icd->user_height = mf.height;
1239 icd->colorspace = mf.colorspace;
1240 icd->field = mf.field;
1241 }
1242
1243 ici->ops->remove(icd);
1244
1245 mutex_unlock(&ici->host_lock); 1621 mutex_unlock(&ici->host_lock);
1622 if (ret < 0)
1623 goto efinish;
1246 1624
1247 return 0; 1625 return 0;
1248 1626
1249evidstart: 1627efinish:
1250 mutex_unlock(&ici->host_lock);
1251 soc_camera_free_user_formats(icd);
1252eiufmt:
1253ectrl:
1254 if (shd->board_info) { 1628 if (shd->board_info) {
1255 soc_camera_free_i2c(icd); 1629 soc_camera_i2c_free(icd);
1256 } else { 1630 } else {
1257 shd->del_device(icd); 1631 shd->del_device(icd);
1258 module_put(control->driver->owner); 1632 module_put(control->driver->owner);
1259 }
1260enodrv: 1633enodrv:
1261eadddev: 1634eadddev:
1635 mutex_lock(&ici->clk_lock);
1636 ici->ops->clock_stop(ici);
1637 mutex_unlock(&ici->clk_lock);
1638 }
1639eadd:
1262 video_device_release(icd->vdev); 1640 video_device_release(icd->vdev);
1263 icd->vdev = NULL; 1641 icd->vdev = NULL;
1642 if (icd->vdev) {
1643 video_device_release(icd->vdev);
1644 icd->vdev = NULL;
1645 }
1264evdc: 1646evdc:
1265 mutex_lock(&ici->host_lock);
1266 ici->ops->remove(icd);
1267 mutex_unlock(&ici->host_lock);
1268eadd:
1269 v4l2_ctrl_handler_free(&icd->ctrl_handler); 1647 v4l2_ctrl_handler_free(&icd->ctrl_handler);
1270 return ret; 1648 return ret;
1271} 1649}
1272 1650
1273/* 1651/*
1274 * This is called on device_unregister, which only means we have to disconnect 1652 * This is called on device_unregister, which only means we have to disconnect
1275 * from the host, but not remove ourselves from the device list 1653 * from the host, but not remove ourselves from the device list. With
1654 * asynchronous client probing this can also be called without
1655 * soc_camera_probe_finish() having run. Careful with clean up.
1276 */ 1656 */
1277static int soc_camera_remove(struct soc_camera_device *icd) 1657static int soc_camera_remove(struct soc_camera_device *icd)
1278{ 1658{
1279 struct soc_camera_desc *sdesc = to_soc_camera_desc(icd); 1659 struct soc_camera_desc *sdesc = to_soc_camera_desc(icd);
1280 struct video_device *vdev = icd->vdev; 1660 struct video_device *vdev = icd->vdev;
1281 1661
1282 BUG_ON(!icd->parent);
1283
1284 v4l2_ctrl_handler_free(&icd->ctrl_handler); 1662 v4l2_ctrl_handler_free(&icd->ctrl_handler);
1285 if (vdev) { 1663 if (vdev) {
1286 video_unregister_device(vdev); 1664 video_unregister_device(vdev);
@@ -1288,15 +1666,27 @@ static int soc_camera_remove(struct soc_camera_device *icd)
1288 } 1666 }
1289 1667
1290 if (sdesc->host_desc.board_info) { 1668 if (sdesc->host_desc.board_info) {
1291 soc_camera_free_i2c(icd); 1669 soc_camera_i2c_free(icd);
1292 } else { 1670 } else {
1293 struct device_driver *drv = to_soc_camera_control(icd)->driver; 1671 struct device *dev = to_soc_camera_control(icd);
1672 struct device_driver *drv = dev ? dev->driver : NULL;
1294 if (drv) { 1673 if (drv) {
1295 sdesc->host_desc.del_device(icd); 1674 sdesc->host_desc.del_device(icd);
1296 module_put(drv->owner); 1675 module_put(drv->owner);
1297 } 1676 }
1298 } 1677 }
1299 soc_camera_free_user_formats(icd); 1678
1679 if (icd->num_user_formats)
1680 soc_camera_free_user_formats(icd);
1681
1682 if (icd->clk) {
1683 /* For the synchronous case */
1684 v4l2_clk_unregister(icd->clk);
1685 icd->clk = NULL;
1686 }
1687
1688 if (icd->sasc)
1689 platform_device_unregister(icd->sasc->pdev);
1300 1690
1301 return 0; 1691 return 0;
1302} 1692}
@@ -1372,8 +1762,8 @@ int soc_camera_host_register(struct soc_camera_host *ici)
1372 ((!ici->ops->init_videobuf || 1762 ((!ici->ops->init_videobuf ||
1373 !ici->ops->reqbufs) && 1763 !ici->ops->reqbufs) &&
1374 !ici->ops->init_videobuf2) || 1764 !ici->ops->init_videobuf2) ||
1375 !ici->ops->add || 1765 !ici->ops->clock_start ||
1376 !ici->ops->remove || 1766 !ici->ops->clock_stop ||
1377 !ici->ops->poll || 1767 !ici->ops->poll ||
1378 !ici->v4l2_dev.dev) 1768 !ici->v4l2_dev.dev)
1379 return -EINVAL; 1769 return -EINVAL;
@@ -1407,7 +1797,18 @@ int soc_camera_host_register(struct soc_camera_host *ici)
1407 mutex_unlock(&list_lock); 1797 mutex_unlock(&list_lock);
1408 1798
1409 mutex_init(&ici->host_lock); 1799 mutex_init(&ici->host_lock);
1410 scan_add_host(ici); 1800 mutex_init(&ici->clk_lock);
1801
1802 if (ici->asd_sizes)
1803 /*
1804 * No OF, host with a list of subdevices. Don't try to mix
1805 * modes by initialising some groups statically and some
1806 * dynamically!
1807 */
1808 scan_async_host(ici);
1809 else
1810 /* Legacy: static platform devices from board data */
1811 scan_add_host(ici);
1411 1812
1412 return 0; 1813 return 0;
1413 1814
@@ -1420,13 +1821,30 @@ EXPORT_SYMBOL(soc_camera_host_register);
1420/* Unregister all clients! */ 1821/* Unregister all clients! */
1421void soc_camera_host_unregister(struct soc_camera_host *ici) 1822void soc_camera_host_unregister(struct soc_camera_host *ici)
1422{ 1823{
1423 struct soc_camera_device *icd; 1824 struct soc_camera_device *icd, *tmp;
1825 struct soc_camera_async_client *sasc;
1826 LIST_HEAD(notifiers);
1424 1827
1425 mutex_lock(&list_lock); 1828 mutex_lock(&list_lock);
1426
1427 list_del(&ici->list); 1829 list_del(&ici->list);
1428 list_for_each_entry(icd, &devices, list) 1830 list_for_each_entry(icd, &devices, list)
1429 if (icd->iface == ici->nr && to_soc_camera_control(icd)) 1831 if (icd->iface == ici->nr && icd->sasc) {
1832 /* as long as we hold the device, sasc won't be freed */
1833 get_device(icd->pdev);
1834 list_add(&icd->sasc->list, &notifiers);
1835 }
1836 mutex_unlock(&list_lock);
1837
1838 list_for_each_entry(sasc, &notifiers, list) {
1839 /* Must call unlocked to avoid AB-BA dead-lock */
1840 v4l2_async_notifier_unregister(&sasc->notifier);
1841 put_device(&sasc->pdev->dev);
1842 }
1843
1844 mutex_lock(&list_lock);
1845
1846 list_for_each_entry_safe(icd, tmp, &devices, list)
1847 if (icd->iface == ici->nr)
1430 soc_camera_remove(icd); 1848 soc_camera_remove(icd);
1431 1849
1432 mutex_unlock(&list_lock); 1850 mutex_unlock(&list_lock);
@@ -1441,6 +1859,7 @@ static int soc_camera_device_register(struct soc_camera_device *icd)
1441 struct soc_camera_device *ix; 1859 struct soc_camera_device *ix;
1442 int num = -1, i; 1860 int num = -1, i;
1443 1861
1862 mutex_lock(&list_lock);
1444 for (i = 0; i < 256 && num < 0; i++) { 1863 for (i = 0; i < 256 && num < 0; i++) {
1445 num = i; 1864 num = i;
1446 /* Check if this index is available on this interface */ 1865 /* Check if this index is available on this interface */
@@ -1452,18 +1871,34 @@ static int soc_camera_device_register(struct soc_camera_device *icd)
1452 } 1871 }
1453 } 1872 }
1454 1873
1455 if (num < 0) 1874 if (num < 0) {
1456 /* 1875 /*
1457 * ok, we have 256 cameras on this host... 1876 * ok, we have 256 cameras on this host...
1458 * man, stay reasonable... 1877 * man, stay reasonable...
1459 */ 1878 */
1879 mutex_unlock(&list_lock);
1460 return -ENOMEM; 1880 return -ENOMEM;
1881 }
1461 1882
1462 icd->devnum = num; 1883 icd->devnum = num;
1463 icd->use_count = 0; 1884 icd->use_count = 0;
1464 icd->host_priv = NULL; 1885 icd->host_priv = NULL;
1465 1886
1887 /*
1888 * Dynamically allocated devices set the bit earlier, but it doesn't hurt setting
1889 * it again
1890 */
1891 i = to_platform_device(icd->pdev)->id;
1892 if (i < 0)
1893 /* One static (legacy) soc-camera platform device */
1894 i = 0;
1895 if (i >= MAP_MAX_NUM) {
1896 mutex_unlock(&list_lock);
1897 return -EBUSY;
1898 }
1899 set_bit(i, device_map);
1466 list_add_tail(&icd->list, &devices); 1900 list_add_tail(&icd->list, &devices);
1901 mutex_unlock(&list_lock);
1467 1902
1468 return 0; 1903 return 0;
1469} 1904}
@@ -1495,11 +1930,6 @@ static const struct v4l2_ioctl_ops soc_camera_ioctl_ops = {
1495 .vidioc_s_selection = soc_camera_s_selection, 1930 .vidioc_s_selection = soc_camera_s_selection,
1496 .vidioc_g_parm = soc_camera_g_parm, 1931 .vidioc_g_parm = soc_camera_g_parm,
1497 .vidioc_s_parm = soc_camera_s_parm, 1932 .vidioc_s_parm = soc_camera_s_parm,
1498 .vidioc_g_chip_ident = soc_camera_g_chip_ident,
1499#ifdef CONFIG_VIDEO_ADV_DEBUG
1500 .vidioc_g_register = soc_camera_g_register,
1501 .vidioc_s_register = soc_camera_s_register,
1502#endif
1503}; 1933};
1504 1934
1505static int video_dev_create(struct soc_camera_device *icd) 1935static int video_dev_create(struct soc_camera_device *icd)
@@ -1512,12 +1942,10 @@ static int video_dev_create(struct soc_camera_device *icd)
1512 1942
1513 strlcpy(vdev->name, ici->drv_name, sizeof(vdev->name)); 1943 strlcpy(vdev->name, ici->drv_name, sizeof(vdev->name));
1514 1944
1515 vdev->parent = icd->pdev; 1945 vdev->v4l2_dev = &ici->v4l2_dev;
1516 vdev->current_norm = V4L2_STD_UNKNOWN;
1517 vdev->fops = &soc_camera_fops; 1946 vdev->fops = &soc_camera_fops;
1518 vdev->ioctl_ops = &soc_camera_ioctl_ops; 1947 vdev->ioctl_ops = &soc_camera_ioctl_ops;
1519 vdev->release = video_device_release; 1948 vdev->release = video_device_release;
1520 vdev->tvnorms = V4L2_STD_UNKNOWN;
1521 vdev->ctrl_handler = &icd->ctrl_handler; 1949 vdev->ctrl_handler = &icd->ctrl_handler;
1522 vdev->lock = &ici->host_lock; 1950 vdev->lock = &ici->host_lock;
1523 1951
@@ -1537,6 +1965,7 @@ static int soc_camera_video_start(struct soc_camera_device *icd)
1537 if (!icd->parent) 1965 if (!icd->parent)
1538 return -ENODEV; 1966 return -ENODEV;
1539 1967
1968 video_set_drvdata(icd->vdev, icd);
1540 ret = video_register_device(icd->vdev, VFL_TYPE_GRABBER, -1); 1969 ret = video_register_device(icd->vdev, VFL_TYPE_GRABBER, -1);
1541 if (ret < 0) { 1970 if (ret < 0) {
1542 dev_err(icd->pdev, "video_register_device failed: %d\n", ret); 1971 dev_err(icd->pdev, "video_register_device failed: %d\n", ret);
@@ -1563,6 +1992,12 @@ static int soc_camera_pdrv_probe(struct platform_device *pdev)
1563 if (!icd) 1992 if (!icd)
1564 return -ENOMEM; 1993 return -ENOMEM;
1565 1994
1995 /*
1996 * In the asynchronous case ssdd->num_regulators == 0 yet, so, the below
1997 * regulator allocation is a dummy. They will be really requested later
1998 * in soc_camera_async_bind(). Also note, that in that case regulators
1999 * are attached to the I2C device and not to the camera platform device.
2000 */
1566 ret = devm_regulator_bulk_get(&pdev->dev, ssdd->num_regulators, 2001 ret = devm_regulator_bulk_get(&pdev->dev, ssdd->num_regulators,
1567 ssdd->regulators); 2002 ssdd->regulators);
1568 if (ret < 0) 2003 if (ret < 0)
@@ -1587,11 +2022,25 @@ static int soc_camera_pdrv_probe(struct platform_device *pdev)
1587static int soc_camera_pdrv_remove(struct platform_device *pdev) 2022static int soc_camera_pdrv_remove(struct platform_device *pdev)
1588{ 2023{
1589 struct soc_camera_device *icd = platform_get_drvdata(pdev); 2024 struct soc_camera_device *icd = platform_get_drvdata(pdev);
2025 int i;
1590 2026
1591 if (!icd) 2027 if (!icd)
1592 return -EINVAL; 2028 return -EINVAL;
1593 2029
1594 list_del(&icd->list); 2030 i = pdev->id;
2031 if (i < 0)
2032 i = 0;
2033
2034 /*
2035 * In synchronous mode with static platform devices this is called in a
2036 * loop from drivers/base/dd.c::driver_detach(), no parallel execution,
2037 * no need to lock. In asynchronous case the caller -
2038 * soc_camera_host_unregister() - already holds the lock
2039 */
2040 if (test_bit(i, device_map)) {
2041 clear_bit(i, device_map);
2042 list_del(&icd->list);
2043 }
1595 2044
1596 return 0; 2045 return 0;
1597} 2046}
diff --git a/drivers/media/platform/soc_camera/soc_camera_platform.c b/drivers/media/platform/soc_camera/soc_camera_platform.c
index 1b7a88ca195b..ceaddfb85e49 100644
--- a/drivers/media/platform/soc_camera/soc_camera_platform.c
+++ b/drivers/media/platform/soc_camera/soc_camera_platform.c
@@ -54,7 +54,7 @@ static int soc_camera_platform_s_power(struct v4l2_subdev *sd, int on)
54{ 54{
55 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd); 55 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd);
56 56
57 return soc_camera_set_power(p->icd->control, &p->icd->sdesc->subdev_desc, on); 57 return soc_camera_set_power(p->icd->control, &p->icd->sdesc->subdev_desc, NULL, on);
58} 58}
59 59
60static struct v4l2_subdev_core_ops platform_subdev_core_ops = { 60static struct v4l2_subdev_core_ops platform_subdev_core_ops = {
@@ -137,7 +137,6 @@ static int soc_camera_platform_probe(struct platform_device *pdev)
137 struct soc_camera_platform_priv *priv; 137 struct soc_camera_platform_priv *priv;
138 struct soc_camera_platform_info *p = pdev->dev.platform_data; 138 struct soc_camera_platform_info *p = pdev->dev.platform_data;
139 struct soc_camera_device *icd; 139 struct soc_camera_device *icd;
140 int ret;
141 140
142 if (!p) 141 if (!p)
143 return -EINVAL; 142 return -EINVAL;
@@ -165,15 +164,7 @@ static int soc_camera_platform_probe(struct platform_device *pdev)
165 v4l2_set_subdevdata(&priv->subdev, p); 164 v4l2_set_subdevdata(&priv->subdev, p);
166 strncpy(priv->subdev.name, dev_name(&pdev->dev), V4L2_SUBDEV_NAME_SIZE); 165 strncpy(priv->subdev.name, dev_name(&pdev->dev), V4L2_SUBDEV_NAME_SIZE);
167 166
168 ret = v4l2_device_register_subdev(&ici->v4l2_dev, &priv->subdev); 167 return v4l2_device_register_subdev(&ici->v4l2_dev, &priv->subdev);
169 if (ret)
170 goto evdrs;
171
172 return ret;
173
174evdrs:
175 platform_set_drvdata(pdev, NULL);
176 return ret;
177} 168}
178 169
179static int soc_camera_platform_remove(struct platform_device *pdev) 170static int soc_camera_platform_remove(struct platform_device *pdev)
@@ -183,7 +174,6 @@ static int soc_camera_platform_remove(struct platform_device *pdev)
183 174
184 p->icd->control = NULL; 175 p->icd->control = NULL;
185 v4l2_device_unregister_subdev(&priv->subdev); 176 v4l2_device_unregister_subdev(&priv->subdev);
186 platform_set_drvdata(pdev, NULL);
187 return 0; 177 return 0;
188} 178}
189 179
diff --git a/drivers/media/platform/soc_camera/soc_scale_crop.c b/drivers/media/platform/soc_camera/soc_scale_crop.c
new file mode 100644
index 000000000000..cbd3a34f4f3f
--- /dev/null
+++ b/drivers/media/platform/soc_camera/soc_scale_crop.c
@@ -0,0 +1,402 @@
1/*
2 * soc-camera generic scaling-cropping manipulation functions
3 *
4 * Copyright (C) 2013 Guennadi Liakhovetski <g.liakhovetski@gmx.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
12#include <linux/device.h>
13#include <linux/module.h>
14
15#include <media/soc_camera.h>
16#include <media/v4l2-common.h>
17
18#include "soc_scale_crop.h"
19
20#ifdef DEBUG_GEOMETRY
21#define dev_geo dev_info
22#else
23#define dev_geo dev_dbg
24#endif
25
26/* Check if any dimension of r1 is smaller than respective one of r2 */
27static bool is_smaller(const struct v4l2_rect *r1, const struct v4l2_rect *r2)
28{
29 return r1->width < r2->width || r1->height < r2->height;
30}
31
32/* Check if r1 fails to cover r2 */
33static bool is_inside(const struct v4l2_rect *r1, const struct v4l2_rect *r2)
34{
35 return r1->left > r2->left || r1->top > r2->top ||
36 r1->left + r1->width < r2->left + r2->width ||
37 r1->top + r1->height < r2->top + r2->height;
38}
39
40/* Get and store current client crop */
41int soc_camera_client_g_rect(struct v4l2_subdev *sd, struct v4l2_rect *rect)
42{
43 struct v4l2_crop crop;
44 struct v4l2_cropcap cap;
45 int ret;
46
47 crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
48
49 ret = v4l2_subdev_call(sd, video, g_crop, &crop);
50 if (!ret) {
51 *rect = crop.c;
52 return ret;
53 }
54
55 /* Camera driver doesn't support .g_crop(), assume default rectangle */
56 cap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
57
58 ret = v4l2_subdev_call(sd, video, cropcap, &cap);
59 if (!ret)
60 *rect = cap.defrect;
61
62 return ret;
63}
64EXPORT_SYMBOL(soc_camera_client_g_rect);
65
66/* Client crop has changed, update our sub-rectangle to remain within the area */
67static void update_subrect(struct v4l2_rect *rect, struct v4l2_rect *subrect)
68{
69 if (rect->width < subrect->width)
70 subrect->width = rect->width;
71
72 if (rect->height < subrect->height)
73 subrect->height = rect->height;
74
75 if (rect->left > subrect->left)
76 subrect->left = rect->left;
77 else if (rect->left + rect->width >
78 subrect->left + subrect->width)
79 subrect->left = rect->left + rect->width -
80 subrect->width;
81
82 if (rect->top > subrect->top)
83 subrect->top = rect->top;
84 else if (rect->top + rect->height >
85 subrect->top + subrect->height)
86 subrect->top = rect->top + rect->height -
87 subrect->height;
88}
89
90/*
91 * The common for both scaling and cropping iterative approach is:
92 * 1. try if the client can produce exactly what requested by the user
93 * 2. if (1) failed, try to double the client image until we get one big enough
94 * 3. if (2) failed, try to request the maximum image
95 */
96int soc_camera_client_s_crop(struct v4l2_subdev *sd,
97 struct v4l2_crop *crop, struct v4l2_crop *cam_crop,
98 struct v4l2_rect *target_rect, struct v4l2_rect *subrect)
99{
100 struct v4l2_rect *rect = &crop->c, *cam_rect = &cam_crop->c;
101 struct device *dev = sd->v4l2_dev->dev;
102 struct v4l2_cropcap cap;
103 int ret;
104 unsigned int width, height;
105
106 v4l2_subdev_call(sd, video, s_crop, crop);
107 ret = soc_camera_client_g_rect(sd, cam_rect);
108 if (ret < 0)
109 return ret;
110
111 /*
112 * Now cam_crop contains the current camera input rectangle, and it must
113 * be within camera cropcap bounds
114 */
115 if (!memcmp(rect, cam_rect, sizeof(*rect))) {
116 /* Even if camera S_CROP failed, but camera rectangle matches */
117 dev_dbg(dev, "Camera S_CROP successful for %dx%d@%d:%d\n",
118 rect->width, rect->height, rect->left, rect->top);
119 *target_rect = *cam_rect;
120 return 0;
121 }
122
123 /* Try to fix cropping, that camera hasn't managed to set */
124 dev_geo(dev, "Fix camera S_CROP for %dx%d@%d:%d to %dx%d@%d:%d\n",
125 cam_rect->width, cam_rect->height,
126 cam_rect->left, cam_rect->top,
127 rect->width, rect->height, rect->left, rect->top);
128
129 /* We need sensor maximum rectangle */
130 ret = v4l2_subdev_call(sd, video, cropcap, &cap);
131 if (ret < 0)
132 return ret;
133
134 /* Put user requested rectangle within sensor bounds */
135 soc_camera_limit_side(&rect->left, &rect->width, cap.bounds.left, 2,
136 cap.bounds.width);
137 soc_camera_limit_side(&rect->top, &rect->height, cap.bounds.top, 4,
138 cap.bounds.height);
139
140 /*
141 * Popular special case - some cameras can only handle fixed sizes like
142 * QVGA, VGA,... Take care to avoid infinite loop.
143 */
144 width = max(cam_rect->width, 2);
145 height = max(cam_rect->height, 2);
146
147 /*
148 * Loop as long as sensor is not covering the requested rectangle and
149 * is still within its bounds
150 */
151 while (!ret && (is_smaller(cam_rect, rect) ||
152 is_inside(cam_rect, rect)) &&
153 (cap.bounds.width > width || cap.bounds.height > height)) {
154
155 width *= 2;
156 height *= 2;
157
158 cam_rect->width = width;
159 cam_rect->height = height;
160
161 /*
162 * We do not know what capabilities the camera has to set up
163 * left and top borders. We could try to be smarter in iterating
164 * them, e.g., if camera current left is to the right of the
165 * target left, set it to the middle point between the current
166 * left and minimum left. But that would add too much
167 * complexity: we would have to iterate each border separately.
168 * Instead we just drop to the left and top bounds.
169 */
170 if (cam_rect->left > rect->left)
171 cam_rect->left = cap.bounds.left;
172
173 if (cam_rect->left + cam_rect->width < rect->left + rect->width)
174 cam_rect->width = rect->left + rect->width -
175 cam_rect->left;
176
177 if (cam_rect->top > rect->top)
178 cam_rect->top = cap.bounds.top;
179
180 if (cam_rect->top + cam_rect->height < rect->top + rect->height)
181 cam_rect->height = rect->top + rect->height -
182 cam_rect->top;
183
184 v4l2_subdev_call(sd, video, s_crop, cam_crop);
185 ret = soc_camera_client_g_rect(sd, cam_rect);
186 dev_geo(dev, "Camera S_CROP %d for %dx%d@%d:%d\n", ret,
187 cam_rect->width, cam_rect->height,
188 cam_rect->left, cam_rect->top);
189 }
190
191 /* S_CROP must not modify the rectangle */
192 if (is_smaller(cam_rect, rect) || is_inside(cam_rect, rect)) {
193 /*
194 * The camera failed to configure a suitable cropping,
195 * we cannot use the current rectangle, set to max
196 */
197 *cam_rect = cap.bounds;
198 v4l2_subdev_call(sd, video, s_crop, cam_crop);
199 ret = soc_camera_client_g_rect(sd, cam_rect);
200 dev_geo(dev, "Camera S_CROP %d for max %dx%d@%d:%d\n", ret,
201 cam_rect->width, cam_rect->height,
202 cam_rect->left, cam_rect->top);
203 }
204
205 if (!ret) {
206 *target_rect = *cam_rect;
207 update_subrect(target_rect, subrect);
208 }
209
210 return ret;
211}
212EXPORT_SYMBOL(soc_camera_client_s_crop);
213
214/* Iterative s_mbus_fmt, also updates cached client crop on success */
215static int client_s_fmt(struct soc_camera_device *icd,
216 struct v4l2_rect *rect, struct v4l2_rect *subrect,
217 unsigned int max_width, unsigned int max_height,
218 struct v4l2_mbus_framefmt *mf, bool host_can_scale)
219{
220 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
221 struct device *dev = icd->parent;
222 unsigned int width = mf->width, height = mf->height, tmp_w, tmp_h;
223 struct v4l2_cropcap cap;
224 bool host_1to1;
225 int ret;
226
227 ret = v4l2_device_call_until_err(sd->v4l2_dev,
228 soc_camera_grp_id(icd), video,
229 s_mbus_fmt, mf);
230 if (ret < 0)
231 return ret;
232
233 dev_geo(dev, "camera scaled to %ux%u\n", mf->width, mf->height);
234
235 if (width == mf->width && height == mf->height) {
236 /* Perfect! The client has done it all. */
237 host_1to1 = true;
238 goto update_cache;
239 }
240
241 host_1to1 = false;
242 if (!host_can_scale)
243 goto update_cache;
244
245 cap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
246
247 ret = v4l2_subdev_call(sd, video, cropcap, &cap);
248 if (ret < 0)
249 return ret;
250
251 if (max_width > cap.bounds.width)
252 max_width = cap.bounds.width;
253 if (max_height > cap.bounds.height)
254 max_height = cap.bounds.height;
255
256 /* Camera set a format, but geometry is not precise, try to improve */
257 tmp_w = mf->width;
258 tmp_h = mf->height;
259
260 /* width <= max_width && height <= max_height - guaranteed by try_fmt */
261 while ((width > tmp_w || height > tmp_h) &&
262 tmp_w < max_width && tmp_h < max_height) {
263 tmp_w = min(2 * tmp_w, max_width);
264 tmp_h = min(2 * tmp_h, max_height);
265 mf->width = tmp_w;
266 mf->height = tmp_h;
267 ret = v4l2_device_call_until_err(sd->v4l2_dev,
268 soc_camera_grp_id(icd), video,
269 s_mbus_fmt, mf);
270 dev_geo(dev, "Camera scaled to %ux%u\n",
271 mf->width, mf->height);
272 if (ret < 0) {
273 /* This shouldn't happen */
274 dev_err(dev, "Client failed to set format: %d\n", ret);
275 return ret;
276 }
277 }
278
279update_cache:
280 /* Update cache */
281 ret = soc_camera_client_g_rect(sd, rect);
282 if (ret < 0)
283 return ret;
284
285 if (host_1to1)
286 *subrect = *rect;
287 else
288 update_subrect(rect, subrect);
289
290 return 0;
291}
292
293/**
294 * @icd - soc-camera device
295 * @rect - camera cropping window
296 * @subrect - part of rect, sent to the user
297 * @mf - in- / output camera output window
298 * @width - on input: max host input width
299 * on output: user width, mapped back to input
300 * @height - on input: max host input height
301 * on output: user height, mapped back to input
302 * @host_can_scale - host can scale this pixel format
303 * @shift - shift, used for scaling
304 */
305int soc_camera_client_scale(struct soc_camera_device *icd,
306 struct v4l2_rect *rect, struct v4l2_rect *subrect,
307 struct v4l2_mbus_framefmt *mf,
308 unsigned int *width, unsigned int *height,
309 bool host_can_scale, unsigned int shift)
310{
311 struct device *dev = icd->parent;
312 struct v4l2_mbus_framefmt mf_tmp = *mf;
313 unsigned int scale_h, scale_v;
314 int ret;
315
316 /*
317 * 5. Apply iterative camera S_FMT for camera user window (also updates
318 * client crop cache and the imaginary sub-rectangle).
319 */
320 ret = client_s_fmt(icd, rect, subrect, *width, *height,
321 &mf_tmp, host_can_scale);
322 if (ret < 0)
323 return ret;
324
325 dev_geo(dev, "5: camera scaled to %ux%u\n",
326 mf_tmp.width, mf_tmp.height);
327
328 /* 6. Retrieve camera output window (g_fmt) */
329
330 /* unneeded - it is already in "mf_tmp" */
331
332 /* 7. Calculate new client scales. */
333 scale_h = soc_camera_calc_scale(rect->width, shift, mf_tmp.width);
334 scale_v = soc_camera_calc_scale(rect->height, shift, mf_tmp.height);
335
336 mf->width = mf_tmp.width;
337 mf->height = mf_tmp.height;
338 mf->colorspace = mf_tmp.colorspace;
339
340 /*
341 * 8. Calculate new host crop - apply camera scales to previously
342 * updated "effective" crop.
343 */
344 *width = soc_camera_shift_scale(subrect->width, shift, scale_h);
345 *height = soc_camera_shift_scale(subrect->height, shift, scale_v);
346
347 dev_geo(dev, "8: new client sub-window %ux%u\n", *width, *height);
348
349 return 0;
350}
351EXPORT_SYMBOL(soc_camera_client_scale);
352
353/*
354 * Calculate real client output window by applying new scales to the current
355 * client crop. New scales are calculated from the requested output format and
356 * host crop, mapped backed onto the client input (subrect).
357 */
358void soc_camera_calc_client_output(struct soc_camera_device *icd,
359 struct v4l2_rect *rect, struct v4l2_rect *subrect,
360 const struct v4l2_pix_format *pix, struct v4l2_mbus_framefmt *mf,
361 unsigned int shift)
362{
363 struct device *dev = icd->parent;
364 unsigned int scale_v, scale_h;
365
366 if (subrect->width == rect->width &&
367 subrect->height == rect->height) {
368 /* No sub-cropping */
369 mf->width = pix->width;
370 mf->height = pix->height;
371 return;
372 }
373
374 /* 1.-2. Current camera scales and subwin - cached. */
375
376 dev_geo(dev, "2: subwin %ux%u@%u:%u\n",
377 subrect->width, subrect->height,
378 subrect->left, subrect->top);
379
380 /*
381 * 3. Calculate new combined scales from input sub-window to requested
382 * user window.
383 */
384
385 /*
386 * TODO: CEU cannot scale images larger than VGA to smaller than SubQCIF
387 * (128x96) or larger than VGA. This and similar limitations have to be
388 * taken into account here.
389 */
390 scale_h = soc_camera_calc_scale(subrect->width, shift, pix->width);
391 scale_v = soc_camera_calc_scale(subrect->height, shift, pix->height);
392
393 dev_geo(dev, "3: scales %u:%u\n", scale_h, scale_v);
394
395 /*
396 * 4. Calculate desired client output window by applying combined scales
397 * to client (real) input window.
398 */
399 mf->width = soc_camera_shift_scale(rect->width, shift, scale_h);
400 mf->height = soc_camera_shift_scale(rect->height, shift, scale_v);
401}
402EXPORT_SYMBOL(soc_camera_calc_client_output);
diff --git a/drivers/media/platform/soc_camera/soc_scale_crop.h b/drivers/media/platform/soc_camera/soc_scale_crop.h
new file mode 100644
index 000000000000..184a30dff541
--- /dev/null
+++ b/drivers/media/platform/soc_camera/soc_scale_crop.h
@@ -0,0 +1,47 @@
1/*
2 * soc-camera generic scaling-cropping manipulation functions
3 *
4 * Copyright (C) 2013 Guennadi Liakhovetski <g.liakhovetski@gmx.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
12#ifndef SOC_SCALE_CROP_H
13#define SOC_SCALE_CROP_H
14
15#include <linux/kernel.h>
16
17struct soc_camera_device;
18
19struct v4l2_crop;
20struct v4l2_mbus_framefmt;
21struct v4l2_pix_format;
22struct v4l2_rect;
23struct v4l2_subdev;
24
25static inline unsigned int soc_camera_shift_scale(unsigned int size,
26 unsigned int shift, unsigned int scale)
27{
28 return DIV_ROUND_CLOSEST(size << shift, scale);
29}
30
31#define soc_camera_calc_scale(in, shift, out) soc_camera_shift_scale(in, shift, out)
32
33int soc_camera_client_g_rect(struct v4l2_subdev *sd, struct v4l2_rect *rect);
34int soc_camera_client_s_crop(struct v4l2_subdev *sd,
35 struct v4l2_crop *crop, struct v4l2_crop *cam_crop,
36 struct v4l2_rect *target_rect, struct v4l2_rect *subrect);
37int soc_camera_client_scale(struct soc_camera_device *icd,
38 struct v4l2_rect *rect, struct v4l2_rect *subrect,
39 struct v4l2_mbus_framefmt *mf,
40 unsigned int *width, unsigned int *height,
41 bool host_can_scale, unsigned int shift);
42void soc_camera_calc_client_output(struct soc_camera_device *icd,
43 struct v4l2_rect *rect, struct v4l2_rect *subrect,
44 const struct v4l2_pix_format *pix, struct v4l2_mbus_framefmt *mf,
45 unsigned int shift);
46
47#endif
diff --git a/drivers/media/platform/timblogiw.c b/drivers/media/platform/timblogiw.c
index a2f7bdd5104f..b557caf5b1a4 100644
--- a/drivers/media/platform/timblogiw.c
+++ b/drivers/media/platform/timblogiw.c
@@ -239,13 +239,12 @@ static int timblogiw_querycap(struct file *file, void *priv,
239 struct video_device *vdev = video_devdata(file); 239 struct video_device *vdev = video_devdata(file);
240 240
241 dev_dbg(&vdev->dev, "%s: Entry\n", __func__); 241 dev_dbg(&vdev->dev, "%s: Entry\n", __func__);
242 memset(cap, 0, sizeof(*cap));
243 strncpy(cap->card, TIMBLOGIWIN_NAME, sizeof(cap->card)-1); 242 strncpy(cap->card, TIMBLOGIWIN_NAME, sizeof(cap->card)-1);
244 strncpy(cap->driver, DRIVER_NAME, sizeof(cap->driver) - 1); 243 strncpy(cap->driver, DRIVER_NAME, sizeof(cap->driver) - 1);
245 strlcpy(cap->bus_info, vdev->name, sizeof(cap->bus_info)); 244 snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s", vdev->name);
246 cap->version = TIMBLOGIW_VERSION_CODE; 245 cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING |
247 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING |
248 V4L2_CAP_READWRITE; 246 V4L2_CAP_READWRITE;
247 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
249 248
250 return 0; 249 return 0;
251} 250}
@@ -834,11 +833,9 @@ static int timblogiw_probe(struct platform_device *pdev)
834 goto err_request; 833 goto err_request;
835 } 834 }
836 835
837
838 return 0; 836 return 0;
839 837
840err_request: 838err_request:
841 platform_set_drvdata(pdev, NULL);
842 v4l2_device_unregister(&lw->v4l2_dev); 839 v4l2_device_unregister(&lw->v4l2_dev);
843err_register: 840err_register:
844 kfree(lw); 841 kfree(lw);
@@ -858,8 +855,6 @@ static int timblogiw_remove(struct platform_device *pdev)
858 855
859 kfree(lw); 856 kfree(lw);
860 857
861 platform_set_drvdata(pdev, NULL);
862
863 return 0; 858 return 0;
864} 859}
865 860
diff --git a/drivers/media/platform/via-camera.c b/drivers/media/platform/via-camera.c
index a794cd6c4441..b4f9d03636e3 100644
--- a/drivers/media/platform/via-camera.c
+++ b/drivers/media/platform/via-camera.c
@@ -17,7 +17,6 @@
17#include <linux/videodev2.h> 17#include <linux/videodev2.h>
18#include <media/v4l2-device.h> 18#include <media/v4l2-device.h>
19#include <media/v4l2-ioctl.h> 19#include <media/v4l2-ioctl.h>
20#include <media/v4l2-chip-ident.h>
21#include <media/v4l2-ctrls.h> 20#include <media/v4l2-ctrls.h>
22#include <media/ov7670.h> 21#include <media/ov7670.h>
23#include <media/videobuf-dma-sg.h> 22#include <media/videobuf-dma-sg.h>
@@ -805,20 +804,6 @@ static const struct v4l2_file_operations viacam_fops = {
805 * The long list of v4l2 ioctl ops 804 * The long list of v4l2 ioctl ops
806 */ 805 */
807 806
808static int viacam_g_chip_ident(struct file *file, void *priv,
809 struct v4l2_dbg_chip_ident *ident)
810{
811 struct via_camera *cam = priv;
812
813 ident->ident = V4L2_IDENT_NONE;
814 ident->revision = 0;
815 if (v4l2_chip_match_host(&ident->match)) {
816 ident->ident = V4L2_IDENT_VIA_VX855;
817 return 0;
818 }
819 return sensor_call(cam, core, g_chip_ident, ident);
820}
821
822/* 807/*
823 * Only one input. 808 * Only one input.
824 */ 809 */
@@ -852,6 +837,12 @@ static int viacam_s_std(struct file *filp, void *priv, v4l2_std_id std)
852 return 0; 837 return 0;
853} 838}
854 839
840static int viacam_g_std(struct file *filp, void *priv, v4l2_std_id *std)
841{
842 *std = V4L2_STD_NTSC_M;
843 return 0;
844}
845
855/* 846/*
856 * Video format stuff. Here is our default format until 847 * Video format stuff. Here is our default format until
857 * user space messes with things. 848 * user space messes with things.
@@ -1174,11 +1165,11 @@ static int viacam_enum_frameintervals(struct file *filp, void *priv,
1174 1165
1175 1166
1176static const struct v4l2_ioctl_ops viacam_ioctl_ops = { 1167static const struct v4l2_ioctl_ops viacam_ioctl_ops = {
1177 .vidioc_g_chip_ident = viacam_g_chip_ident,
1178 .vidioc_enum_input = viacam_enum_input, 1168 .vidioc_enum_input = viacam_enum_input,
1179 .vidioc_g_input = viacam_g_input, 1169 .vidioc_g_input = viacam_g_input,
1180 .vidioc_s_input = viacam_s_input, 1170 .vidioc_s_input = viacam_s_input,
1181 .vidioc_s_std = viacam_s_std, 1171 .vidioc_s_std = viacam_s_std,
1172 .vidioc_g_std = viacam_g_std,
1182 .vidioc_enum_fmt_vid_cap = viacam_enum_fmt_vid_cap, 1173 .vidioc_enum_fmt_vid_cap = viacam_enum_fmt_vid_cap,
1183 .vidioc_try_fmt_vid_cap = viacam_try_fmt_vid_cap, 1174 .vidioc_try_fmt_vid_cap = viacam_try_fmt_vid_cap,
1184 .vidioc_g_fmt_vid_cap = viacam_g_fmt_vid_cap, 1175 .vidioc_g_fmt_vid_cap = viacam_g_fmt_vid_cap,
@@ -1266,7 +1257,6 @@ static struct video_device viacam_v4l_template = {
1266 .name = "via-camera", 1257 .name = "via-camera",
1267 .minor = -1, 1258 .minor = -1,
1268 .tvnorms = V4L2_STD_NTSC_M, 1259 .tvnorms = V4L2_STD_NTSC_M,
1269 .current_norm = V4L2_STD_NTSC_M,
1270 .fops = &viacam_fops, 1260 .fops = &viacam_fops,
1271 .ioctl_ops = &viacam_ioctl_ops, 1261 .ioctl_ops = &viacam_ioctl_ops,
1272 .release = video_device_release_empty, /* Check this */ 1262 .release = video_device_release_empty, /* Check this */
diff --git a/drivers/media/radio/radio-keene.c b/drivers/media/radio/radio-keene.c
index 4c9ae767fb31..21db23b196be 100644
--- a/drivers/media/radio/radio-keene.c
+++ b/drivers/media/radio/radio-keene.c
@@ -93,7 +93,7 @@ static int keene_cmd_main(struct keene_device *radio, unsigned freq, bool play)
93 /* If bit 4 is set, then tune to the frequency. 93 /* If bit 4 is set, then tune to the frequency.
94 If bit 3 is set, then unmute; if bit 2 is set, then mute. 94 If bit 3 is set, then unmute; if bit 2 is set, then mute.
95 If bit 1 is set, then enter idle mode; if bit 0 is set, 95 If bit 1 is set, then enter idle mode; if bit 0 is set,
96 then enter transit mode. 96 then enter transmit mode.
97 */ 97 */
98 radio->buffer[5] = (radio->muted ? 4 : 8) | (play ? 1 : 2) | 98 radio->buffer[5] = (radio->muted ? 4 : 8) | (play ? 1 : 2) |
99 (freq ? 0x10 : 0); 99 (freq ? 0x10 : 0);
@@ -350,7 +350,6 @@ static int usb_keene_probe(struct usb_interface *intf,
350 radio->pa = 118; 350 radio->pa = 118;
351 radio->tx = 0x32; 351 radio->tx = 0x32;
352 radio->stereo = true; 352 radio->stereo = true;
353 radio->curfreq = 95.16 * FREQ_MUL;
354 if (hdl->error) { 353 if (hdl->error) {
355 retval = hdl->error; 354 retval = hdl->error;
356 355
@@ -383,6 +382,10 @@ static int usb_keene_probe(struct usb_interface *intf,
383 video_set_drvdata(&radio->vdev, radio); 382 video_set_drvdata(&radio->vdev, radio);
384 set_bit(V4L2_FL_USE_FH_PRIO, &radio->vdev.flags); 383 set_bit(V4L2_FL_USE_FH_PRIO, &radio->vdev.flags);
385 384
385 /* at least 11ms is needed in order to settle hardware */
386 msleep(20);
387 keene_cmd_main(radio, 95.16 * FREQ_MUL, false);
388
386 retval = video_register_device(&radio->vdev, VFL_TYPE_RADIO, -1); 389 retval = video_register_device(&radio->vdev, VFL_TYPE_RADIO, -1);
387 if (retval < 0) { 390 if (retval < 0) {
388 dev_err(&intf->dev, "could not register video device\n"); 391 dev_err(&intf->dev, "could not register video device\n");
diff --git a/drivers/media/radio/radio-sf16fmi.c b/drivers/media/radio/radio-sf16fmi.c
index adfcc61bdf0b..6f4318ff0db3 100644
--- a/drivers/media/radio/radio-sf16fmi.c
+++ b/drivers/media/radio/radio-sf16fmi.c
@@ -27,6 +27,8 @@
27#include <linux/io.h> /* outb, outb_p */ 27#include <linux/io.h> /* outb, outb_p */
28#include <media/v4l2-device.h> 28#include <media/v4l2-device.h>
29#include <media/v4l2-ioctl.h> 29#include <media/v4l2-ioctl.h>
30#include <media/v4l2-ctrls.h>
31#include <media/v4l2-event.h>
30#include "lm7000.h" 32#include "lm7000.h"
31 33
32MODULE_AUTHOR("Petr Vandrovec, vandrove@vc.cvut.cz and M. Kirkwood"); 34MODULE_AUTHOR("Petr Vandrovec, vandrove@vc.cvut.cz and M. Kirkwood");
@@ -44,10 +46,11 @@ module_param(radio_nr, int, 0);
44struct fmi 46struct fmi
45{ 47{
46 struct v4l2_device v4l2_dev; 48 struct v4l2_device v4l2_dev;
49 struct v4l2_ctrl_handler hdl;
47 struct video_device vdev; 50 struct video_device vdev;
48 int io; 51 int io;
49 bool mute; 52 bool mute;
50 unsigned long curfreq; /* freq in kHz */ 53 u32 curfreq; /* freq in kHz */
51 struct mutex lock; 54 struct mutex lock;
52}; 55};
53 56
@@ -55,8 +58,8 @@ static struct fmi fmi_card;
55static struct pnp_dev *dev; 58static struct pnp_dev *dev;
56bool pnp_attached; 59bool pnp_attached;
57 60
58#define RSF16_MINFREQ (87 * 16000) 61#define RSF16_MINFREQ (87U * 16000)
59#define RSF16_MAXFREQ (108 * 16000) 62#define RSF16_MAXFREQ (108U * 16000)
60 63
61#define FMI_BIT_TUN_CE (1 << 0) 64#define FMI_BIT_TUN_CE (1 << 0)
62#define FMI_BIT_TUN_CLK (1 << 1) 65#define FMI_BIT_TUN_CLK (1 << 1)
@@ -115,13 +118,22 @@ static inline int fmi_getsigstr(struct fmi *fmi)
115 return (res & 2) ? 0 : 0xFFFF; 118 return (res & 2) ? 0 : 0xFFFF;
116} 119}
117 120
121static void fmi_set_freq(struct fmi *fmi)
122{
123 fmi->curfreq = clamp(fmi->curfreq, RSF16_MINFREQ, RSF16_MAXFREQ);
124 /* rounding in steps of 800 to match the freq
125 that will be used */
126 lm7000_set_freq((fmi->curfreq / 800) * 800, fmi, fmi_set_pins);
127}
128
118static int vidioc_querycap(struct file *file, void *priv, 129static int vidioc_querycap(struct file *file, void *priv,
119 struct v4l2_capability *v) 130 struct v4l2_capability *v)
120{ 131{
121 strlcpy(v->driver, "radio-sf16fmi", sizeof(v->driver)); 132 strlcpy(v->driver, "radio-sf16fmi", sizeof(v->driver));
122 strlcpy(v->card, "SF16-FMI/FMP/FMD radio", sizeof(v->card)); 133 strlcpy(v->card, "SF16-FMI/FMP/FMD radio", sizeof(v->card));
123 strlcpy(v->bus_info, "ISA", sizeof(v->bus_info)); 134 strlcpy(v->bus_info, "ISA:radio-sf16fmi", sizeof(v->bus_info));
124 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO; 135 v->device_caps = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
136 v->capabilities = v->device_caps | V4L2_CAP_DEVICE_CAPS;
125 return 0; 137 return 0;
126} 138}
127 139
@@ -157,12 +169,10 @@ static int vidioc_s_frequency(struct file *file, void *priv,
157 169
158 if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO) 170 if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
159 return -EINVAL; 171 return -EINVAL;
160 if (f->frequency < RSF16_MINFREQ || 172
161 f->frequency > RSF16_MAXFREQ) 173 fmi->curfreq = f->frequency;
162 return -EINVAL; 174 fmi_set_freq(fmi);
163 /* rounding in steps of 800 to match the freq 175
164 that will be used */
165 lm7000_set_freq((f->frequency / 800) * 800, fmi, fmi_set_pins);
166 return 0; 176 return 0;
167} 177}
168 178
@@ -178,74 +188,31 @@ static int vidioc_g_frequency(struct file *file, void *priv,
178 return 0; 188 return 0;
179} 189}
180 190
181static int vidioc_queryctrl(struct file *file, void *priv, 191static int fmi_s_ctrl(struct v4l2_ctrl *ctrl)
182 struct v4l2_queryctrl *qc)
183{ 192{
184 switch (qc->id) { 193 struct fmi *fmi = container_of(ctrl->handler, struct fmi, hdl);
185 case V4L2_CID_AUDIO_MUTE:
186 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
187 }
188 return -EINVAL;
189}
190
191static int vidioc_g_ctrl(struct file *file, void *priv,
192 struct v4l2_control *ctrl)
193{
194 struct fmi *fmi = video_drvdata(file);
195 194
196 switch (ctrl->id) { 195 switch (ctrl->id) {
197 case V4L2_CID_AUDIO_MUTE: 196 case V4L2_CID_AUDIO_MUTE:
198 ctrl->value = fmi->mute; 197 if (ctrl->val)
199 return 0;
200 }
201 return -EINVAL;
202}
203
204static int vidioc_s_ctrl(struct file *file, void *priv,
205 struct v4l2_control *ctrl)
206{
207 struct fmi *fmi = video_drvdata(file);
208
209 switch (ctrl->id) {
210 case V4L2_CID_AUDIO_MUTE:
211 if (ctrl->value)
212 fmi_mute(fmi); 198 fmi_mute(fmi);
213 else 199 else
214 fmi_unmute(fmi); 200 fmi_unmute(fmi);
215 fmi->mute = ctrl->value; 201 fmi->mute = ctrl->val;
216 return 0; 202 return 0;
217 } 203 }
218 return -EINVAL; 204 return -EINVAL;
219} 205}
220 206
221static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i) 207static const struct v4l2_ctrl_ops fmi_ctrl_ops = {
222{ 208 .s_ctrl = fmi_s_ctrl,
223 *i = 0; 209};
224 return 0;
225}
226
227static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
228{
229 return i ? -EINVAL : 0;
230}
231
232static int vidioc_g_audio(struct file *file, void *priv,
233 struct v4l2_audio *a)
234{
235 a->index = 0;
236 strlcpy(a->name, "Radio", sizeof(a->name));
237 a->capability = V4L2_AUDCAP_STEREO;
238 return 0;
239}
240
241static int vidioc_s_audio(struct file *file, void *priv,
242 const struct v4l2_audio *a)
243{
244 return a->index ? -EINVAL : 0;
245}
246 210
247static const struct v4l2_file_operations fmi_fops = { 211static const struct v4l2_file_operations fmi_fops = {
248 .owner = THIS_MODULE, 212 .owner = THIS_MODULE,
213 .open = v4l2_fh_open,
214 .release = v4l2_fh_release,
215 .poll = v4l2_ctrl_poll,
249 .unlocked_ioctl = video_ioctl2, 216 .unlocked_ioctl = video_ioctl2,
250}; 217};
251 218
@@ -253,15 +220,11 @@ static const struct v4l2_ioctl_ops fmi_ioctl_ops = {
253 .vidioc_querycap = vidioc_querycap, 220 .vidioc_querycap = vidioc_querycap,
254 .vidioc_g_tuner = vidioc_g_tuner, 221 .vidioc_g_tuner = vidioc_g_tuner,
255 .vidioc_s_tuner = vidioc_s_tuner, 222 .vidioc_s_tuner = vidioc_s_tuner,
256 .vidioc_g_audio = vidioc_g_audio,
257 .vidioc_s_audio = vidioc_s_audio,
258 .vidioc_g_input = vidioc_g_input,
259 .vidioc_s_input = vidioc_s_input,
260 .vidioc_g_frequency = vidioc_g_frequency, 223 .vidioc_g_frequency = vidioc_g_frequency,
261 .vidioc_s_frequency = vidioc_s_frequency, 224 .vidioc_s_frequency = vidioc_s_frequency,
262 .vidioc_queryctrl = vidioc_queryctrl, 225 .vidioc_log_status = v4l2_ctrl_log_status,
263 .vidioc_g_ctrl = vidioc_g_ctrl, 226 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
264 .vidioc_s_ctrl = vidioc_s_ctrl, 227 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
265}; 228};
266 229
267/* ladis: this is my card. does any other types exist? */ 230/* ladis: this is my card. does any other types exist? */
@@ -311,6 +274,7 @@ static int __init fmi_init(void)
311{ 274{
312 struct fmi *fmi = &fmi_card; 275 struct fmi *fmi = &fmi_card;
313 struct v4l2_device *v4l2_dev = &fmi->v4l2_dev; 276 struct v4l2_device *v4l2_dev = &fmi->v4l2_dev;
277 struct v4l2_ctrl_handler *hdl = &fmi->hdl;
314 int res, i; 278 int res, i;
315 int probe_ports[] = { 0, 0x284, 0x384 }; 279 int probe_ports[] = { 0, 0x284, 0x384 };
316 280
@@ -363,19 +327,35 @@ static int __init fmi_init(void)
363 return res; 327 return res;
364 } 328 }
365 329
330 v4l2_ctrl_handler_init(hdl, 1);
331 v4l2_ctrl_new_std(hdl, &fmi_ctrl_ops,
332 V4L2_CID_AUDIO_MUTE, 0, 1, 1, 1);
333 v4l2_dev->ctrl_handler = hdl;
334 if (hdl->error) {
335 res = hdl->error;
336 v4l2_err(v4l2_dev, "Could not register controls\n");
337 v4l2_ctrl_handler_free(hdl);
338 v4l2_device_unregister(v4l2_dev);
339 return res;
340 }
341
366 strlcpy(fmi->vdev.name, v4l2_dev->name, sizeof(fmi->vdev.name)); 342 strlcpy(fmi->vdev.name, v4l2_dev->name, sizeof(fmi->vdev.name));
367 fmi->vdev.v4l2_dev = v4l2_dev; 343 fmi->vdev.v4l2_dev = v4l2_dev;
368 fmi->vdev.fops = &fmi_fops; 344 fmi->vdev.fops = &fmi_fops;
369 fmi->vdev.ioctl_ops = &fmi_ioctl_ops; 345 fmi->vdev.ioctl_ops = &fmi_ioctl_ops;
370 fmi->vdev.release = video_device_release_empty; 346 fmi->vdev.release = video_device_release_empty;
347 set_bit(V4L2_FL_USE_FH_PRIO, &fmi->vdev.flags);
371 video_set_drvdata(&fmi->vdev, fmi); 348 video_set_drvdata(&fmi->vdev, fmi);
372 349
373 mutex_init(&fmi->lock); 350 mutex_init(&fmi->lock);
374 351
375 /* mute card - prevents noisy bootups */ 352 /* mute card and set default frequency */
376 fmi_mute(fmi); 353 fmi->mute = 1;
354 fmi->curfreq = RSF16_MINFREQ;
355 fmi_set_freq(fmi);
377 356
378 if (video_register_device(&fmi->vdev, VFL_TYPE_RADIO, radio_nr) < 0) { 357 if (video_register_device(&fmi->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
358 v4l2_ctrl_handler_free(hdl);
379 v4l2_device_unregister(v4l2_dev); 359 v4l2_device_unregister(v4l2_dev);
380 release_region(fmi->io, 2); 360 release_region(fmi->io, 2);
381 if (pnp_attached) 361 if (pnp_attached)
@@ -391,6 +371,7 @@ static void __exit fmi_exit(void)
391{ 371{
392 struct fmi *fmi = &fmi_card; 372 struct fmi *fmi = &fmi_card;
393 373
374 v4l2_ctrl_handler_free(&fmi->hdl);
394 video_unregister_device(&fmi->vdev); 375 video_unregister_device(&fmi->vdev);
395 v4l2_device_unregister(&fmi->v4l2_dev); 376 v4l2_device_unregister(&fmi->v4l2_dev);
396 release_region(fmi->io, 2); 377 release_region(fmi->io, 2);
diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
index 9dc8bafe6486..9c9084cb99f7 100644
--- a/drivers/media/radio/radio-si476x.c
+++ b/drivers/media/radio/radio-si476x.c
@@ -1018,16 +1018,6 @@ static int si476x_radio_s_ctrl(struct v4l2_ctrl *ctrl)
1018 return retval; 1018 return retval;
1019} 1019}
1020 1020
1021static int si476x_radio_g_chip_ident(struct file *file, void *fh,
1022 struct v4l2_dbg_chip_ident *chip)
1023{
1024 if (chip->match.type == V4L2_CHIP_MATCH_HOST &&
1025 v4l2_chip_match_host(&chip->match))
1026 return 0;
1027 return -EINVAL;
1028}
1029
1030
1031#ifdef CONFIG_VIDEO_ADV_DEBUG 1021#ifdef CONFIG_VIDEO_ADV_DEBUG
1032static int si476x_radio_g_register(struct file *file, void *fh, 1022static int si476x_radio_g_register(struct file *file, void *fh,
1033 struct v4l2_dbg_register *reg) 1023 struct v4l2_dbg_register *reg)
@@ -1203,7 +1193,6 @@ static const struct v4l2_ioctl_ops si4761_ioctl_ops = {
1203 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, 1193 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1204 .vidioc_unsubscribe_event = v4l2_event_unsubscribe, 1194 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1205 1195
1206 .vidioc_g_chip_ident = si476x_radio_g_chip_ident,
1207#ifdef CONFIG_VIDEO_ADV_DEBUG 1196#ifdef CONFIG_VIDEO_ADV_DEBUG
1208 .vidioc_g_register = si476x_radio_g_register, 1197 .vidioc_g_register = si476x_radio_g_register,
1209 .vidioc_s_register = si476x_radio_s_register, 1198 .vidioc_s_register = si476x_radio_s_register,
diff --git a/drivers/media/radio/radio-tea5764.c b/drivers/media/radio/radio-tea5764.c
index 38d563d62595..036e2f54f4db 100644
--- a/drivers/media/radio/radio-tea5764.c
+++ b/drivers/media/radio/radio-tea5764.c
@@ -39,6 +39,9 @@
39#include <linux/i2c.h> /* I2C */ 39#include <linux/i2c.h> /* I2C */
40#include <media/v4l2-common.h> 40#include <media/v4l2-common.h>
41#include <media/v4l2-ioctl.h> 41#include <media/v4l2-ioctl.h>
42#include <media/v4l2-device.h>
43#include <media/v4l2-ctrls.h>
44#include <media/v4l2-event.h>
42 45
43#define DRIVER_VERSION "0.0.2" 46#define DRIVER_VERSION "0.0.2"
44 47
@@ -57,8 +60,8 @@
57 60
58/* Frequency limits in MHz -- these are European values. For Japanese 61/* Frequency limits in MHz -- these are European values. For Japanese
59devices, that would be 76000 and 91000. */ 62devices, that would be 76000 and 91000. */
60#define FREQ_MIN 87500 63#define FREQ_MIN 87500U
61#define FREQ_MAX 108000 64#define FREQ_MAX 108000U
62#define FREQ_MUL 16 65#define FREQ_MUL 16
63 66
64/* TEA5764 registers */ 67/* TEA5764 registers */
@@ -138,8 +141,10 @@ static int radio_nr = -1;
138static int use_xtal = RADIO_TEA5764_XTAL; 141static int use_xtal = RADIO_TEA5764_XTAL;
139 142
140struct tea5764_device { 143struct tea5764_device {
144 struct v4l2_device v4l2_dev;
145 struct v4l2_ctrl_handler ctrl_handler;
141 struct i2c_client *i2c_client; 146 struct i2c_client *i2c_client;
142 struct video_device *videodev; 147 struct video_device vdev;
143 struct tea5764_regs regs; 148 struct tea5764_regs regs;
144 struct mutex mutex; 149 struct mutex mutex;
145}; 150};
@@ -187,18 +192,6 @@ static int tea5764_i2c_write(struct tea5764_device *radio)
187 return 0; 192 return 0;
188} 193}
189 194
190/* V4L2 code related */
191static struct v4l2_queryctrl radio_qctrl[] = {
192 {
193 .id = V4L2_CID_AUDIO_MUTE,
194 .name = "Mute",
195 .minimum = 0,
196 .maximum = 1,
197 .default_value = 1,
198 .type = V4L2_CTRL_TYPE_BOOLEAN,
199 }
200};
201
202static void tea5764_power_up(struct tea5764_device *radio) 195static void tea5764_power_up(struct tea5764_device *radio)
203{ 196{
204 struct tea5764_regs *r = &radio->regs; 197 struct tea5764_regs *r = &radio->regs;
@@ -291,23 +284,19 @@ static void tea5764_mute(struct tea5764_device *radio, int on)
291 tea5764_i2c_write(radio); 284 tea5764_i2c_write(radio);
292} 285}
293 286
294static int tea5764_is_muted(struct tea5764_device *radio)
295{
296 return radio->regs.tnctrl & TEA5764_TNCTRL_MU;
297}
298
299/* V4L2 vidioc */ 287/* V4L2 vidioc */
300static int vidioc_querycap(struct file *file, void *priv, 288static int vidioc_querycap(struct file *file, void *priv,
301 struct v4l2_capability *v) 289 struct v4l2_capability *v)
302{ 290{
303 struct tea5764_device *radio = video_drvdata(file); 291 struct tea5764_device *radio = video_drvdata(file);
304 struct video_device *dev = radio->videodev; 292 struct video_device *dev = &radio->vdev;
305 293
306 strlcpy(v->driver, dev->dev.driver->name, sizeof(v->driver)); 294 strlcpy(v->driver, dev->dev.driver->name, sizeof(v->driver));
307 strlcpy(v->card, dev->name, sizeof(v->card)); 295 strlcpy(v->card, dev->name, sizeof(v->card));
308 snprintf(v->bus_info, sizeof(v->bus_info), 296 snprintf(v->bus_info, sizeof(v->bus_info),
309 "I2C:%s", dev_name(&dev->dev)); 297 "I2C:%s", dev_name(&dev->dev));
310 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO; 298 v->device_caps = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
299 v->capabilities = v->device_caps | V4L2_CAP_DEVICE_CAPS;
311 return 0; 300 return 0;
312} 301}
313 302
@@ -320,8 +309,7 @@ static int vidioc_g_tuner(struct file *file, void *priv,
320 if (v->index > 0) 309 if (v->index > 0)
321 return -EINVAL; 310 return -EINVAL;
322 311
323 memset(v, 0, sizeof(*v)); 312 strlcpy(v->name, "FM", sizeof(v->name));
324 strcpy(v->name, "FM");
325 v->type = V4L2_TUNER_RADIO; 313 v->type = V4L2_TUNER_RADIO;
326 tea5764_i2c_read(radio); 314 tea5764_i2c_read(radio);
327 v->rangelow = FREQ_MIN * FREQ_MUL; 315 v->rangelow = FREQ_MIN * FREQ_MUL;
@@ -354,19 +342,23 @@ static int vidioc_s_frequency(struct file *file, void *priv,
354 const struct v4l2_frequency *f) 342 const struct v4l2_frequency *f)
355{ 343{
356 struct tea5764_device *radio = video_drvdata(file); 344 struct tea5764_device *radio = video_drvdata(file);
345 unsigned freq = f->frequency;
357 346
358 if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO) 347 if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
359 return -EINVAL; 348 return -EINVAL;
360 if (f->frequency == 0) { 349 if (freq == 0) {
361 /* We special case this as a power down control. */ 350 /* We special case this as a power down control. */
362 tea5764_power_down(radio); 351 tea5764_power_down(radio);
363 } 352 /* Yes, that's what is returned in this case. This
364 if (f->frequency < (FREQ_MIN * FREQ_MUL)) 353 whole special case is non-compliant and should really
365 return -EINVAL; 354 be replaced with something better, but changing this
366 if (f->frequency > (FREQ_MAX * FREQ_MUL)) 355 might well break code that depends on this behavior.
356 So we keep it as-is. */
367 return -EINVAL; 357 return -EINVAL;
358 }
359 clamp(freq, FREQ_MIN * FREQ_MUL, FREQ_MAX * FREQ_MUL);
368 tea5764_power_up(radio); 360 tea5764_power_up(radio);
369 tea5764_tune(radio, (f->frequency * 125) / 2); 361 tea5764_tune(radio, (freq * 125) / 2);
370 return 0; 362 return 0;
371} 363}
372 364
@@ -379,7 +371,6 @@ static int vidioc_g_frequency(struct file *file, void *priv,
379 if (f->tuner != 0) 371 if (f->tuner != 0)
380 return -EINVAL; 372 return -EINVAL;
381 tea5764_i2c_read(radio); 373 tea5764_i2c_read(radio);
382 memset(f, 0, sizeof(*f));
383 f->type = V4L2_TUNER_RADIO; 374 f->type = V4L2_TUNER_RADIO;
384 if (r->tnctrl & TEA5764_TNCTRL_PUPD0) 375 if (r->tnctrl & TEA5764_TNCTRL_PUPD0)
385 f->frequency = (tea5764_get_freq(radio) * 2) / 125; 376 f->frequency = (tea5764_get_freq(radio) * 2) / 125;
@@ -389,83 +380,29 @@ static int vidioc_g_frequency(struct file *file, void *priv,
389 return 0; 380 return 0;
390} 381}
391 382
392static int vidioc_queryctrl(struct file *file, void *priv, 383static int tea5764_s_ctrl(struct v4l2_ctrl *ctrl)
393 struct v4l2_queryctrl *qc)
394{ 384{
395 int i; 385 struct tea5764_device *radio =
396 386 container_of(ctrl->handler, struct tea5764_device, ctrl_handler);
397 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) {
398 if (qc->id && qc->id == radio_qctrl[i].id) {
399 memcpy(qc, &(radio_qctrl[i]), sizeof(*qc));
400 return 0;
401 }
402 }
403 return -EINVAL;
404}
405
406static int vidioc_g_ctrl(struct file *file, void *priv,
407 struct v4l2_control *ctrl)
408{
409 struct tea5764_device *radio = video_drvdata(file);
410
411 switch (ctrl->id) {
412 case V4L2_CID_AUDIO_MUTE:
413 tea5764_i2c_read(radio);
414 ctrl->value = tea5764_is_muted(radio) ? 1 : 0;
415 return 0;
416 }
417 return -EINVAL;
418}
419
420static int vidioc_s_ctrl(struct file *file, void *priv,
421 struct v4l2_control *ctrl)
422{
423 struct tea5764_device *radio = video_drvdata(file);
424 387
425 switch (ctrl->id) { 388 switch (ctrl->id) {
426 case V4L2_CID_AUDIO_MUTE: 389 case V4L2_CID_AUDIO_MUTE:
427 tea5764_mute(radio, ctrl->value); 390 tea5764_mute(radio, ctrl->val);
428 return 0; 391 return 0;
429 } 392 }
430 return -EINVAL; 393 return -EINVAL;
431} 394}
432 395
433static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i) 396static const struct v4l2_ctrl_ops tea5764_ctrl_ops = {
434{ 397 .s_ctrl = tea5764_s_ctrl,
435 *i = 0; 398};
436 return 0;
437}
438
439static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
440{
441 if (i != 0)
442 return -EINVAL;
443 return 0;
444}
445
446static int vidioc_g_audio(struct file *file, void *priv,
447 struct v4l2_audio *a)
448{
449 if (a->index > 1)
450 return -EINVAL;
451
452 strcpy(a->name, "Radio");
453 a->capability = V4L2_AUDCAP_STEREO;
454 return 0;
455}
456
457static int vidioc_s_audio(struct file *file, void *priv,
458 const struct v4l2_audio *a)
459{
460 if (a->index != 0)
461 return -EINVAL;
462
463 return 0;
464}
465 399
466/* File system interface */ 400/* File system interface */
467static const struct v4l2_file_operations tea5764_fops = { 401static const struct v4l2_file_operations tea5764_fops = {
468 .owner = THIS_MODULE, 402 .owner = THIS_MODULE,
403 .open = v4l2_fh_open,
404 .release = v4l2_fh_release,
405 .poll = v4l2_ctrl_poll,
469 .unlocked_ioctl = video_ioctl2, 406 .unlocked_ioctl = video_ioctl2,
470}; 407};
471 408
@@ -473,15 +410,11 @@ static const struct v4l2_ioctl_ops tea5764_ioctl_ops = {
473 .vidioc_querycap = vidioc_querycap, 410 .vidioc_querycap = vidioc_querycap,
474 .vidioc_g_tuner = vidioc_g_tuner, 411 .vidioc_g_tuner = vidioc_g_tuner,
475 .vidioc_s_tuner = vidioc_s_tuner, 412 .vidioc_s_tuner = vidioc_s_tuner,
476 .vidioc_g_audio = vidioc_g_audio,
477 .vidioc_s_audio = vidioc_s_audio,
478 .vidioc_g_input = vidioc_g_input,
479 .vidioc_s_input = vidioc_s_input,
480 .vidioc_g_frequency = vidioc_g_frequency, 413 .vidioc_g_frequency = vidioc_g_frequency,
481 .vidioc_s_frequency = vidioc_s_frequency, 414 .vidioc_s_frequency = vidioc_s_frequency,
482 .vidioc_queryctrl = vidioc_queryctrl, 415 .vidioc_log_status = v4l2_ctrl_log_status,
483 .vidioc_g_ctrl = vidioc_g_ctrl, 416 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
484 .vidioc_s_ctrl = vidioc_s_ctrl, 417 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
485}; 418};
486 419
487/* V4L2 interface */ 420/* V4L2 interface */
@@ -489,7 +422,7 @@ static struct video_device tea5764_radio_template = {
489 .name = "TEA5764 FM-Radio", 422 .name = "TEA5764 FM-Radio",
490 .fops = &tea5764_fops, 423 .fops = &tea5764_fops,
491 .ioctl_ops = &tea5764_ioctl_ops, 424 .ioctl_ops = &tea5764_ioctl_ops,
492 .release = video_device_release, 425 .release = video_device_release_empty,
493}; 426};
494 427
495/* I2C probe: check if the device exists and register with v4l if it is */ 428/* I2C probe: check if the device exists and register with v4l if it is */
@@ -497,6 +430,8 @@ static int tea5764_i2c_probe(struct i2c_client *client,
497 const struct i2c_device_id *id) 430 const struct i2c_device_id *id)
498{ 431{
499 struct tea5764_device *radio; 432 struct tea5764_device *radio;
433 struct v4l2_device *v4l2_dev;
434 struct v4l2_ctrl_handler *hdl;
500 struct tea5764_regs *r; 435 struct tea5764_regs *r;
501 int ret; 436 int ret;
502 437
@@ -505,31 +440,45 @@ static int tea5764_i2c_probe(struct i2c_client *client,
505 if (!radio) 440 if (!radio)
506 return -ENOMEM; 441 return -ENOMEM;
507 442
443 v4l2_dev = &radio->v4l2_dev;
444 ret = v4l2_device_register(&client->dev, v4l2_dev);
445 if (ret < 0) {
446 v4l2_err(v4l2_dev, "could not register v4l2_device\n");
447 goto errfr;
448 }
449
450 hdl = &radio->ctrl_handler;
451 v4l2_ctrl_handler_init(hdl, 1);
452 v4l2_ctrl_new_std(hdl, &tea5764_ctrl_ops,
453 V4L2_CID_AUDIO_MUTE, 0, 1, 1, 1);
454 v4l2_dev->ctrl_handler = hdl;
455 if (hdl->error) {
456 ret = hdl->error;
457 v4l2_err(v4l2_dev, "Could not register controls\n");
458 goto errunreg;
459 }
460
508 mutex_init(&radio->mutex); 461 mutex_init(&radio->mutex);
509 radio->i2c_client = client; 462 radio->i2c_client = client;
510 ret = tea5764_i2c_read(radio); 463 ret = tea5764_i2c_read(radio);
511 if (ret) 464 if (ret)
512 goto errfr; 465 goto errunreg;
513 r = &radio->regs; 466 r = &radio->regs;
514 PDEBUG("chipid = %04X, manid = %04X", r->chipid, r->manid); 467 PDEBUG("chipid = %04X, manid = %04X", r->chipid, r->manid);
515 if (r->chipid != TEA5764_CHIPID || 468 if (r->chipid != TEA5764_CHIPID ||
516 (r->manid & 0x0fff) != TEA5764_MANID) { 469 (r->manid & 0x0fff) != TEA5764_MANID) {
517 PWARN("This chip is not a TEA5764!"); 470 PWARN("This chip is not a TEA5764!");
518 ret = -EINVAL; 471 ret = -EINVAL;
519 goto errfr; 472 goto errunreg;
520 } 473 }
521 474
522 radio->videodev = video_device_alloc(); 475 radio->vdev = tea5764_radio_template;
523 if (!(radio->videodev)) {
524 ret = -ENOMEM;
525 goto errfr;
526 }
527 memcpy(radio->videodev, &tea5764_radio_template,
528 sizeof(tea5764_radio_template));
529 476
530 i2c_set_clientdata(client, radio); 477 i2c_set_clientdata(client, radio);
531 video_set_drvdata(radio->videodev, radio); 478 video_set_drvdata(&radio->vdev, radio);
532 radio->videodev->lock = &radio->mutex; 479 radio->vdev.lock = &radio->mutex;
480 radio->vdev.v4l2_dev = v4l2_dev;
481 set_bit(V4L2_FL_USE_FH_PRIO, &radio->vdev.flags);
533 482
534 /* initialize and power off the chip */ 483 /* initialize and power off the chip */
535 tea5764_i2c_read(radio); 484 tea5764_i2c_read(radio);
@@ -537,16 +486,17 @@ static int tea5764_i2c_probe(struct i2c_client *client,
537 tea5764_mute(radio, 1); 486 tea5764_mute(radio, 1);
538 tea5764_power_down(radio); 487 tea5764_power_down(radio);
539 488
540 ret = video_register_device(radio->videodev, VFL_TYPE_RADIO, radio_nr); 489 ret = video_register_device(&radio->vdev, VFL_TYPE_RADIO, radio_nr);
541 if (ret < 0) { 490 if (ret < 0) {
542 PWARN("Could not register video device!"); 491 PWARN("Could not register video device!");
543 goto errrel; 492 goto errunreg;
544 } 493 }
545 494
546 PINFO("registered."); 495 PINFO("registered.");
547 return 0; 496 return 0;
548errrel: 497errunreg:
549 video_device_release(radio->videodev); 498 v4l2_ctrl_handler_free(hdl);
499 v4l2_device_unregister(v4l2_dev);
550errfr: 500errfr:
551 kfree(radio); 501 kfree(radio);
552 return ret; 502 return ret;
@@ -559,7 +509,9 @@ static int tea5764_i2c_remove(struct i2c_client *client)
559 PDEBUG("remove"); 509 PDEBUG("remove");
560 if (radio) { 510 if (radio) {
561 tea5764_power_down(radio); 511 tea5764_power_down(radio);
562 video_unregister_device(radio->videodev); 512 video_unregister_device(&radio->vdev);
513 v4l2_ctrl_handler_free(&radio->ctrl_handler);
514 v4l2_device_unregister(&radio->v4l2_dev);
563 kfree(radio); 515 kfree(radio);
564 } 516 }
565 return 0; 517 return 0;
diff --git a/drivers/media/radio/radio-timb.c b/drivers/media/radio/radio-timb.c
index bb7b143b65d1..0817964d9172 100644
--- a/drivers/media/radio/radio-timb.c
+++ b/drivers/media/radio/radio-timb.c
@@ -19,6 +19,8 @@
19#include <linux/io.h> 19#include <linux/io.h>
20#include <media/v4l2-ioctl.h> 20#include <media/v4l2-ioctl.h>
21#include <media/v4l2-device.h> 21#include <media/v4l2-device.h>
22#include <media/v4l2-ctrls.h>
23#include <media/v4l2-event.h>
22#include <linux/platform_device.h> 24#include <linux/platform_device.h>
23#include <linux/interrupt.h> 25#include <linux/interrupt.h>
24#include <linux/slab.h> 26#include <linux/slab.h>
@@ -44,7 +46,8 @@ static int timbradio_vidioc_querycap(struct file *file, void *priv,
44 strlcpy(v->driver, DRIVER_NAME, sizeof(v->driver)); 46 strlcpy(v->driver, DRIVER_NAME, sizeof(v->driver));
45 strlcpy(v->card, "Timberdale Radio", sizeof(v->card)); 47 strlcpy(v->card, "Timberdale Radio", sizeof(v->card));
46 snprintf(v->bus_info, sizeof(v->bus_info), "platform:"DRIVER_NAME); 48 snprintf(v->bus_info, sizeof(v->bus_info), "platform:"DRIVER_NAME);
47 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO; 49 v->device_caps = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
50 v->capabilities = v->device_caps | V4L2_CAP_DEVICE_CAPS;
48 return 0; 51 return 0;
49} 52}
50 53
@@ -62,34 +65,6 @@ static int timbradio_vidioc_s_tuner(struct file *file, void *priv,
62 return v4l2_subdev_call(tr->sd_tuner, tuner, s_tuner, v); 65 return v4l2_subdev_call(tr->sd_tuner, tuner, s_tuner, v);
63} 66}
64 67
65static int timbradio_vidioc_g_input(struct file *filp, void *priv,
66 unsigned int *i)
67{
68 *i = 0;
69 return 0;
70}
71
72static int timbradio_vidioc_s_input(struct file *filp, void *priv,
73 unsigned int i)
74{
75 return i ? -EINVAL : 0;
76}
77
78static int timbradio_vidioc_g_audio(struct file *file, void *priv,
79 struct v4l2_audio *a)
80{
81 a->index = 0;
82 strlcpy(a->name, "Radio", sizeof(a->name));
83 a->capability = V4L2_AUDCAP_STEREO;
84 return 0;
85}
86
87static int timbradio_vidioc_s_audio(struct file *file, void *priv,
88 const struct v4l2_audio *a)
89{
90 return a->index ? -EINVAL : 0;
91}
92
93static int timbradio_vidioc_s_frequency(struct file *file, void *priv, 68static int timbradio_vidioc_s_frequency(struct file *file, void *priv,
94 const struct v4l2_frequency *f) 69 const struct v4l2_frequency *f)
95{ 70{
@@ -104,44 +79,22 @@ static int timbradio_vidioc_g_frequency(struct file *file, void *priv,
104 return v4l2_subdev_call(tr->sd_tuner, tuner, g_frequency, f); 79 return v4l2_subdev_call(tr->sd_tuner, tuner, g_frequency, f);
105} 80}
106 81
107static int timbradio_vidioc_queryctrl(struct file *file, void *priv,
108 struct v4l2_queryctrl *qc)
109{
110 struct timbradio *tr = video_drvdata(file);
111 return v4l2_subdev_call(tr->sd_dsp, core, queryctrl, qc);
112}
113
114static int timbradio_vidioc_g_ctrl(struct file *file, void *priv,
115 struct v4l2_control *ctrl)
116{
117 struct timbradio *tr = video_drvdata(file);
118 return v4l2_subdev_call(tr->sd_dsp, core, g_ctrl, ctrl);
119}
120
121static int timbradio_vidioc_s_ctrl(struct file *file, void *priv,
122 struct v4l2_control *ctrl)
123{
124 struct timbradio *tr = video_drvdata(file);
125 return v4l2_subdev_call(tr->sd_dsp, core, s_ctrl, ctrl);
126}
127
128static const struct v4l2_ioctl_ops timbradio_ioctl_ops = { 82static const struct v4l2_ioctl_ops timbradio_ioctl_ops = {
129 .vidioc_querycap = timbradio_vidioc_querycap, 83 .vidioc_querycap = timbradio_vidioc_querycap,
130 .vidioc_g_tuner = timbradio_vidioc_g_tuner, 84 .vidioc_g_tuner = timbradio_vidioc_g_tuner,
131 .vidioc_s_tuner = timbradio_vidioc_s_tuner, 85 .vidioc_s_tuner = timbradio_vidioc_s_tuner,
132 .vidioc_g_frequency = timbradio_vidioc_g_frequency, 86 .vidioc_g_frequency = timbradio_vidioc_g_frequency,
133 .vidioc_s_frequency = timbradio_vidioc_s_frequency, 87 .vidioc_s_frequency = timbradio_vidioc_s_frequency,
134 .vidioc_g_input = timbradio_vidioc_g_input, 88 .vidioc_log_status = v4l2_ctrl_log_status,
135 .vidioc_s_input = timbradio_vidioc_s_input, 89 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
136 .vidioc_g_audio = timbradio_vidioc_g_audio, 90 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
137 .vidioc_s_audio = timbradio_vidioc_s_audio,
138 .vidioc_queryctrl = timbradio_vidioc_queryctrl,
139 .vidioc_g_ctrl = timbradio_vidioc_g_ctrl,
140 .vidioc_s_ctrl = timbradio_vidioc_s_ctrl
141}; 91};
142 92
143static const struct v4l2_file_operations timbradio_fops = { 93static const struct v4l2_file_operations timbradio_fops = {
144 .owner = THIS_MODULE, 94 .owner = THIS_MODULE,
95 .open = v4l2_fh_open,
96 .release = v4l2_fh_release,
97 .poll = v4l2_ctrl_poll,
145 .unlocked_ioctl = video_ioctl2, 98 .unlocked_ioctl = video_ioctl2,
146}; 99};
147 100
@@ -173,6 +126,7 @@ static int timbradio_probe(struct platform_device *pdev)
173 tr->video_dev.release = video_device_release_empty; 126 tr->video_dev.release = video_device_release_empty;
174 tr->video_dev.minor = -1; 127 tr->video_dev.minor = -1;
175 tr->video_dev.lock = &tr->lock; 128 tr->video_dev.lock = &tr->lock;
129 set_bit(V4L2_FL_USE_FH_PRIO, &tr->video_dev.flags);
176 130
177 strlcpy(tr->v4l2_dev.name, DRIVER_NAME, sizeof(tr->v4l2_dev.name)); 131 strlcpy(tr->v4l2_dev.name, DRIVER_NAME, sizeof(tr->v4l2_dev.name));
178 err = v4l2_device_register(NULL, &tr->v4l2_dev); 132 err = v4l2_device_register(NULL, &tr->v4l2_dev);
@@ -181,6 +135,15 @@ static int timbradio_probe(struct platform_device *pdev)
181 135
182 tr->video_dev.v4l2_dev = &tr->v4l2_dev; 136 tr->video_dev.v4l2_dev = &tr->v4l2_dev;
183 137
138 tr->sd_tuner = v4l2_i2c_new_subdev_board(&tr->v4l2_dev,
139 i2c_get_adapter(pdata->i2c_adapter), pdata->tuner, NULL);
140 tr->sd_dsp = v4l2_i2c_new_subdev_board(&tr->v4l2_dev,
141 i2c_get_adapter(pdata->i2c_adapter), pdata->dsp, NULL);
142 if (tr->sd_tuner == NULL || tr->sd_dsp == NULL)
143 goto err_video_req;
144
145 tr->v4l2_dev.ctrl_handler = tr->sd_dsp->ctrl_handler;
146
184 err = video_register_device(&tr->video_dev, VFL_TYPE_RADIO, -1); 147 err = video_register_device(&tr->video_dev, VFL_TYPE_RADIO, -1);
185 if (err) { 148 if (err) {
186 dev_err(&pdev->dev, "Error reg video\n"); 149 dev_err(&pdev->dev, "Error reg video\n");
@@ -193,7 +156,6 @@ static int timbradio_probe(struct platform_device *pdev)
193 return 0; 156 return 0;
194 157
195err_video_req: 158err_video_req:
196 video_device_release_empty(&tr->video_dev);
197 v4l2_device_unregister(&tr->v4l2_dev); 159 v4l2_device_unregister(&tr->v4l2_dev);
198err: 160err:
199 dev_err(&pdev->dev, "Failed to register: %d\n", err); 161 dev_err(&pdev->dev, "Failed to register: %d\n", err);
@@ -206,10 +168,7 @@ static int timbradio_remove(struct platform_device *pdev)
206 struct timbradio *tr = platform_get_drvdata(pdev); 168 struct timbradio *tr = platform_get_drvdata(pdev);
207 169
208 video_unregister_device(&tr->video_dev); 170 video_unregister_device(&tr->video_dev);
209 video_device_release_empty(&tr->video_dev);
210
211 v4l2_device_unregister(&tr->v4l2_dev); 171 v4l2_device_unregister(&tr->v4l2_dev);
212
213 return 0; 172 return 0;
214} 173}
215 174
diff --git a/drivers/media/radio/saa7706h.c b/drivers/media/radio/saa7706h.c
index 06c06cc9ff25..ec805b09c608 100644
--- a/drivers/media/radio/saa7706h.c
+++ b/drivers/media/radio/saa7706h.c
@@ -25,7 +25,7 @@
25#include <linux/i2c.h> 25#include <linux/i2c.h>
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <media/v4l2-device.h> 27#include <media/v4l2-device.h>
28#include <media/v4l2-chip-ident.h> 28#include <media/v4l2-ctrls.h>
29 29
30#define DRIVER_NAME "saa7706h" 30#define DRIVER_NAME "saa7706h"
31 31
@@ -127,6 +127,7 @@
127 127
128struct saa7706h_state { 128struct saa7706h_state {
129 struct v4l2_subdev sd; 129 struct v4l2_subdev sd;
130 struct v4l2_ctrl_handler hdl;
130 unsigned muted; 131 unsigned muted;
131}; 132};
132 133
@@ -317,51 +318,32 @@ static int saa7706h_mute(struct v4l2_subdev *sd)
317 return err; 318 return err;
318} 319}
319 320
320static int saa7706h_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc) 321static int saa7706h_s_ctrl(struct v4l2_ctrl *ctrl)
321{ 322{
322 switch (qc->id) { 323 struct saa7706h_state *state =
323 case V4L2_CID_AUDIO_MUTE: 324 container_of(ctrl->handler, struct saa7706h_state, hdl);
324 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
325 }
326 return -EINVAL;
327}
328
329static int saa7706h_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
330{
331 struct saa7706h_state *state = to_state(sd);
332 325
333 switch (ctrl->id) { 326 switch (ctrl->id) {
334 case V4L2_CID_AUDIO_MUTE: 327 case V4L2_CID_AUDIO_MUTE:
335 ctrl->value = state->muted; 328 if (ctrl->val)
336 return 0; 329 return saa7706h_mute(&state->sd);
330 return saa7706h_unmute(&state->sd);
337 } 331 }
338 return -EINVAL; 332 return -EINVAL;
339} 333}
340 334
341static int saa7706h_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 335static const struct v4l2_ctrl_ops saa7706h_ctrl_ops = {
342{ 336 .s_ctrl = saa7706h_s_ctrl,
343 switch (ctrl->id) { 337};
344 case V4L2_CID_AUDIO_MUTE:
345 if (ctrl->value)
346 return saa7706h_mute(sd);
347 return saa7706h_unmute(sd);
348 }
349 return -EINVAL;
350}
351
352static int saa7706h_g_chip_ident(struct v4l2_subdev *sd,
353 struct v4l2_dbg_chip_ident *chip)
354{
355 struct i2c_client *client = v4l2_get_subdevdata(sd);
356
357 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_SAA7706H, 0);
358}
359 338
360static const struct v4l2_subdev_core_ops saa7706h_core_ops = { 339static const struct v4l2_subdev_core_ops saa7706h_core_ops = {
361 .g_chip_ident = saa7706h_g_chip_ident, 340 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls,
362 .queryctrl = saa7706h_queryctrl, 341 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls,
363 .g_ctrl = saa7706h_g_ctrl, 342 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls,
364 .s_ctrl = saa7706h_s_ctrl, 343 .g_ctrl = v4l2_subdev_g_ctrl,
344 .s_ctrl = v4l2_subdev_s_ctrl,
345 .queryctrl = v4l2_subdev_queryctrl,
346 .querymenu = v4l2_subdev_querymenu,
365}; 347};
366 348
367static const struct v4l2_subdev_ops saa7706h_ops = { 349static const struct v4l2_subdev_ops saa7706h_ops = {
@@ -393,13 +375,20 @@ static int saa7706h_probe(struct i2c_client *client,
393 sd = &state->sd; 375 sd = &state->sd;
394 v4l2_i2c_subdev_init(sd, client, &saa7706h_ops); 376 v4l2_i2c_subdev_init(sd, client, &saa7706h_ops);
395 377
378 v4l2_ctrl_handler_init(&state->hdl, 4);
379 v4l2_ctrl_new_std(&state->hdl, &saa7706h_ctrl_ops,
380 V4L2_CID_AUDIO_MUTE, 0, 1, 1, 1);
381 sd->ctrl_handler = &state->hdl;
382 err = state->hdl.error;
383 if (err)
384 goto err;
385
396 /* check the rom versions */ 386 /* check the rom versions */
397 err = saa7706h_get_reg16(sd, SAA7706H_DSP1_ROM_VER); 387 err = saa7706h_get_reg16(sd, SAA7706H_DSP1_ROM_VER);
398 if (err < 0) 388 if (err < 0)
399 goto err; 389 goto err;
400 if (err != SUPPORTED_DSP1_ROM_VER) 390 if (err != SUPPORTED_DSP1_ROM_VER)
401 v4l2_warn(sd, "Unknown DSP1 ROM code version: 0x%x\n", err); 391 v4l2_warn(sd, "Unknown DSP1 ROM code version: 0x%x\n", err);
402
403 state->muted = 1; 392 state->muted = 1;
404 393
405 /* startup in a muted state */ 394 /* startup in a muted state */
@@ -411,6 +400,7 @@ static int saa7706h_probe(struct i2c_client *client,
411 400
412err: 401err:
413 v4l2_device_unregister_subdev(sd); 402 v4l2_device_unregister_subdev(sd);
403 v4l2_ctrl_handler_free(&state->hdl);
414 kfree(to_state(sd)); 404 kfree(to_state(sd));
415 405
416 printk(KERN_ERR DRIVER_NAME ": Failed to probe: %d\n", err); 406 printk(KERN_ERR DRIVER_NAME ": Failed to probe: %d\n", err);
@@ -421,9 +411,11 @@ err:
421static int saa7706h_remove(struct i2c_client *client) 411static int saa7706h_remove(struct i2c_client *client)
422{ 412{
423 struct v4l2_subdev *sd = i2c_get_clientdata(client); 413 struct v4l2_subdev *sd = i2c_get_clientdata(client);
414 struct saa7706h_state *state = to_state(sd);
424 415
425 saa7706h_mute(sd); 416 saa7706h_mute(sd);
426 v4l2_device_unregister_subdev(sd); 417 v4l2_device_unregister_subdev(sd);
418 v4l2_ctrl_handler_free(&state->hdl);
427 kfree(to_state(sd)); 419 kfree(to_state(sd));
428 return 0; 420 return 0;
429} 421}
diff --git a/drivers/media/radio/tef6862.c b/drivers/media/radio/tef6862.c
index 82c6c9475d7c..06ac69245ca1 100644
--- a/drivers/media/radio/tef6862.c
+++ b/drivers/media/radio/tef6862.c
@@ -25,14 +25,13 @@
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <media/v4l2-ioctl.h> 26#include <media/v4l2-ioctl.h>
27#include <media/v4l2-device.h> 27#include <media/v4l2-device.h>
28#include <media/v4l2-chip-ident.h>
29 28
30#define DRIVER_NAME "tef6862" 29#define DRIVER_NAME "tef6862"
31 30
32#define FREQ_MUL 16000 31#define FREQ_MUL 16000
33 32
34#define TEF6862_LO_FREQ (875 * FREQ_MUL / 10) 33#define TEF6862_LO_FREQ (875U * FREQ_MUL / 10)
35#define TEF6862_HI_FREQ (108 * FREQ_MUL) 34#define TEF6862_HI_FREQ (108U * FREQ_MUL)
36 35
37/* Write mode sub addresses */ 36/* Write mode sub addresses */
38#define WM_SUB_BANDWIDTH 0x0 37#define WM_SUB_BANDWIDTH 0x0
@@ -105,6 +104,7 @@ static int tef6862_s_frequency(struct v4l2_subdev *sd, const struct v4l2_frequen
105{ 104{
106 struct tef6862_state *state = to_state(sd); 105 struct tef6862_state *state = to_state(sd);
107 struct i2c_client *client = v4l2_get_subdevdata(sd); 106 struct i2c_client *client = v4l2_get_subdevdata(sd);
107 unsigned freq = f->frequency;
108 u16 pll; 108 u16 pll;
109 u8 i2cmsg[3]; 109 u8 i2cmsg[3];
110 int err; 110 int err;
@@ -112,7 +112,8 @@ static int tef6862_s_frequency(struct v4l2_subdev *sd, const struct v4l2_frequen
112 if (f->tuner != 0) 112 if (f->tuner != 0)
113 return -EINVAL; 113 return -EINVAL;
114 114
115 pll = 1964 + ((f->frequency - TEF6862_LO_FREQ) * 20) / FREQ_MUL; 115 clamp(freq, TEF6862_LO_FREQ, TEF6862_HI_FREQ);
116 pll = 1964 + ((freq - TEF6862_LO_FREQ) * 20) / FREQ_MUL;
116 i2cmsg[0] = (MODE_PRESET << MODE_SHIFT) | WM_SUB_PLLM; 117 i2cmsg[0] = (MODE_PRESET << MODE_SHIFT) | WM_SUB_PLLM;
117 i2cmsg[1] = (pll >> 8) & 0xff; 118 i2cmsg[1] = (pll >> 8) & 0xff;
118 i2cmsg[2] = pll & 0xff; 119 i2cmsg[2] = pll & 0xff;
@@ -121,7 +122,7 @@ static int tef6862_s_frequency(struct v4l2_subdev *sd, const struct v4l2_frequen
121 if (err != sizeof(i2cmsg)) 122 if (err != sizeof(i2cmsg))
122 return err < 0 ? err : -EIO; 123 return err < 0 ? err : -EIO;
123 124
124 state->freq = f->frequency; 125 state->freq = freq;
125 return 0; 126 return 0;
126} 127}
127 128
@@ -136,14 +137,6 @@ static int tef6862_g_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *f)
136 return 0; 137 return 0;
137} 138}
138 139
139static int tef6862_g_chip_ident(struct v4l2_subdev *sd,
140 struct v4l2_dbg_chip_ident *chip)
141{
142 struct i2c_client *client = v4l2_get_subdevdata(sd);
143
144 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_TEF6862, 0);
145}
146
147static const struct v4l2_subdev_tuner_ops tef6862_tuner_ops = { 140static const struct v4l2_subdev_tuner_ops tef6862_tuner_ops = {
148 .g_tuner = tef6862_g_tuner, 141 .g_tuner = tef6862_g_tuner,
149 .s_tuner = tef6862_s_tuner, 142 .s_tuner = tef6862_s_tuner,
@@ -151,12 +144,7 @@ static const struct v4l2_subdev_tuner_ops tef6862_tuner_ops = {
151 .g_frequency = tef6862_g_frequency, 144 .g_frequency = tef6862_g_frequency,
152}; 145};
153 146
154static const struct v4l2_subdev_core_ops tef6862_core_ops = {
155 .g_chip_ident = tef6862_g_chip_ident,
156};
157
158static const struct v4l2_subdev_ops tef6862_ops = { 147static const struct v4l2_subdev_ops tef6862_ops = {
159 .core = &tef6862_core_ops,
160 .tuner = &tef6862_tuner_ops, 148 .tuner = &tef6862_tuner_ops,
161}; 149};
162 150
diff --git a/drivers/media/radio/wl128x/fmdrv.h b/drivers/media/radio/wl128x/fmdrv.h
index aac0f025f767..a587c9bac930 100644
--- a/drivers/media/radio/wl128x/fmdrv.h
+++ b/drivers/media/radio/wl128x/fmdrv.h
@@ -30,6 +30,7 @@
30#include <linux/timer.h> 30#include <linux/timer.h>
31#include <media/v4l2-ioctl.h> 31#include <media/v4l2-ioctl.h>
32#include <media/v4l2-common.h> 32#include <media/v4l2-common.h>
33#include <media/v4l2-device.h>
33#include <media/v4l2-ctrls.h> 34#include <media/v4l2-ctrls.h>
34 35
35#define FM_DRV_VERSION "0.1.1" 36#define FM_DRV_VERSION "0.1.1"
@@ -202,6 +203,7 @@ struct fmtx_data {
202/* FM driver operation structure */ 203/* FM driver operation structure */
203struct fmdev { 204struct fmdev {
204 struct video_device *radio_dev; /* V4L2 video device pointer */ 205 struct video_device *radio_dev; /* V4L2 video device pointer */
206 struct v4l2_device v4l2_dev; /* V4L2 top level struct */
205 struct snd_card *card; /* Card which holds FM mixer controls */ 207 struct snd_card *card; /* Card which holds FM mixer controls */
206 u16 asci_id; 208 u16 asci_id;
207 spinlock_t rds_buff_lock; /* To protect access to RDS buffer */ 209 spinlock_t rds_buff_lock; /* To protect access to RDS buffer */
diff --git a/drivers/media/radio/wl128x/fmdrv_common.c b/drivers/media/radio/wl128x/fmdrv_common.c
index a002234ed5de..253f307f0b37 100644
--- a/drivers/media/radio/wl128x/fmdrv_common.c
+++ b/drivers/media/radio/wl128x/fmdrv_common.c
@@ -715,7 +715,7 @@ static void fm_irq_handle_rdsdata_getcmd_resp(struct fmdev *fmdev)
715 struct fm_rdsdata_format rds_fmt; 715 struct fm_rdsdata_format rds_fmt;
716 struct fm_rds *rds = &fmdev->rx.rds; 716 struct fm_rds *rds = &fmdev->rx.rds;
717 unsigned long group_idx, flags; 717 unsigned long group_idx, flags;
718 u8 *rds_data, meta_data, tmpbuf[3]; 718 u8 *rds_data, meta_data, tmpbuf[FM_RDS_BLK_SIZE];
719 u8 type, blk_idx; 719 u8 type, blk_idx;
720 u16 cur_picode; 720 u16 cur_picode;
721 u32 rds_len; 721 u32 rds_len;
@@ -1073,6 +1073,7 @@ int fmc_transfer_rds_from_internal_buff(struct fmdev *fmdev, struct file *file,
1073 u8 __user *buf, size_t count) 1073 u8 __user *buf, size_t count)
1074{ 1074{
1075 u32 block_count; 1075 u32 block_count;
1076 u8 tmpbuf[FM_RDS_BLK_SIZE];
1076 unsigned long flags; 1077 unsigned long flags;
1077 int ret; 1078 int ret;
1078 1079
@@ -1087,29 +1088,32 @@ int fmc_transfer_rds_from_internal_buff(struct fmdev *fmdev, struct file *file,
1087 } 1088 }
1088 1089
1089 /* Calculate block count from byte count */ 1090 /* Calculate block count from byte count */
1090 count /= 3; 1091 count /= FM_RDS_BLK_SIZE;
1091 block_count = 0; 1092 block_count = 0;
1092 ret = 0; 1093 ret = 0;
1093 1094
1094 spin_lock_irqsave(&fmdev->rds_buff_lock, flags);
1095
1096 while (block_count < count) { 1095 while (block_count < count) {
1097 if (fmdev->rx.rds.wr_idx == fmdev->rx.rds.rd_idx) 1096 spin_lock_irqsave(&fmdev->rds_buff_lock, flags);
1098 break;
1099 1097
1100 if (copy_to_user(buf, &fmdev->rx.rds.buff[fmdev->rx.rds.rd_idx], 1098 if (fmdev->rx.rds.wr_idx == fmdev->rx.rds.rd_idx) {
1101 FM_RDS_BLK_SIZE)) 1099 spin_unlock_irqrestore(&fmdev->rds_buff_lock, flags);
1102 break; 1100 break;
1103 1101 }
1102 memcpy(tmpbuf, &fmdev->rx.rds.buff[fmdev->rx.rds.rd_idx],
1103 FM_RDS_BLK_SIZE);
1104 fmdev->rx.rds.rd_idx += FM_RDS_BLK_SIZE; 1104 fmdev->rx.rds.rd_idx += FM_RDS_BLK_SIZE;
1105 if (fmdev->rx.rds.rd_idx >= fmdev->rx.rds.buf_size) 1105 if (fmdev->rx.rds.rd_idx >= fmdev->rx.rds.buf_size)
1106 fmdev->rx.rds.rd_idx = 0; 1106 fmdev->rx.rds.rd_idx = 0;
1107 1107
1108 spin_unlock_irqrestore(&fmdev->rds_buff_lock, flags);
1109
1110 if (copy_to_user(buf, tmpbuf, FM_RDS_BLK_SIZE))
1111 break;
1112
1108 block_count++; 1113 block_count++;
1109 buf += FM_RDS_BLK_SIZE; 1114 buf += FM_RDS_BLK_SIZE;
1110 ret += FM_RDS_BLK_SIZE; 1115 ret += FM_RDS_BLK_SIZE;
1111 } 1116 }
1112 spin_unlock_irqrestore(&fmdev->rds_buff_lock, flags);
1113 return ret; 1117 return ret;
1114} 1118}
1115 1119
diff --git a/drivers/media/radio/wl128x/fmdrv_v4l2.c b/drivers/media/radio/wl128x/fmdrv_v4l2.c
index 5dec323f4247..b55012c11842 100644
--- a/drivers/media/radio/wl128x/fmdrv_v4l2.c
+++ b/drivers/media/radio/wl128x/fmdrv_v4l2.c
@@ -533,6 +533,11 @@ int fm_v4l2_init_video_device(struct fmdev *fmdev, int radio_nr)
533 struct v4l2_ctrl *ctrl; 533 struct v4l2_ctrl *ctrl;
534 int ret; 534 int ret;
535 535
536 strlcpy(fmdev->v4l2_dev.name, FM_DRV_NAME, sizeof(fmdev->v4l2_dev.name));
537 ret = v4l2_device_register(NULL, &fmdev->v4l2_dev);
538 if (ret < 0)
539 return ret;
540
536 /* Init mutex for core locking */ 541 /* Init mutex for core locking */
537 mutex_init(&fmdev->mutex); 542 mutex_init(&fmdev->mutex);
538 543
@@ -549,6 +554,7 @@ int fm_v4l2_init_video_device(struct fmdev *fmdev, int radio_nr)
549 video_set_drvdata(gradio_dev, fmdev); 554 video_set_drvdata(gradio_dev, fmdev);
550 555
551 gradio_dev->lock = &fmdev->mutex; 556 gradio_dev->lock = &fmdev->mutex;
557 gradio_dev->v4l2_dev = &fmdev->v4l2_dev;
552 558
553 /* Register with V4L2 subsystem as RADIO device */ 559 /* Register with V4L2 subsystem as RADIO device */
554 if (video_register_device(gradio_dev, VFL_TYPE_RADIO, radio_nr)) { 560 if (video_register_device(gradio_dev, VFL_TYPE_RADIO, radio_nr)) {
@@ -611,5 +617,7 @@ void *fm_v4l2_deinit_video_device(void)
611 /* Unregister RADIO device from V4L2 subsystem */ 617 /* Unregister RADIO device from V4L2 subsystem */
612 video_unregister_device(gradio_dev); 618 video_unregister_device(gradio_dev);
613 619
620 v4l2_device_unregister(&fmdev->v4l2_dev);
621
614 return fmdev; 622 return fmdev;
615} 623}
diff --git a/drivers/media/rc/gpio-ir-recv.c b/drivers/media/rc/gpio-ir-recv.c
index 8b82ae9bd686..07aacfa5903d 100644
--- a/drivers/media/rc/gpio-ir-recv.c
+++ b/drivers/media/rc/gpio-ir-recv.c
@@ -178,7 +178,6 @@ static int gpio_ir_recv_probe(struct platform_device *pdev)
178 return 0; 178 return 0;
179 179
180err_request_irq: 180err_request_irq:
181 platform_set_drvdata(pdev, NULL);
182 rc_unregister_device(rcdev); 181 rc_unregister_device(rcdev);
183 rcdev = NULL; 182 rcdev = NULL;
184err_register_rc_device: 183err_register_rc_device:
@@ -196,7 +195,6 @@ static int gpio_ir_recv_remove(struct platform_device *pdev)
196 struct gpio_rc_dev *gpio_dev = platform_get_drvdata(pdev); 195 struct gpio_rc_dev *gpio_dev = platform_get_drvdata(pdev);
197 196
198 free_irq(gpio_to_irq(gpio_dev->gpio_nr), gpio_dev); 197 free_irq(gpio_to_irq(gpio_dev->gpio_nr), gpio_dev);
199 platform_set_drvdata(pdev, NULL);
200 rc_unregister_device(gpio_dev->rcdev); 198 rc_unregister_device(gpio_dev->rcdev);
201 gpio_free(gpio_dev->gpio_nr); 199 gpio_free(gpio_dev->gpio_nr);
202 kfree(gpio_dev); 200 kfree(gpio_dev);
diff --git a/drivers/media/rc/keymaps/Makefile b/drivers/media/rc/keymaps/Makefile
index 5ab94ea4bc28..b1cde8c0422b 100644
--- a/drivers/media/rc/keymaps/Makefile
+++ b/drivers/media/rc/keymaps/Makefile
@@ -20,6 +20,7 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \
20 rc-budget-ci-old.o \ 20 rc-budget-ci-old.o \
21 rc-cinergy-1400.o \ 21 rc-cinergy-1400.o \
22 rc-cinergy.o \ 22 rc-cinergy.o \
23 rc-delock-61959.o \
23 rc-dib0700-nec.o \ 24 rc-dib0700-nec.o \
24 rc-dib0700-rc5.o \ 25 rc-dib0700-rc5.o \
25 rc-digitalnow-tinytwin.o \ 26 rc-digitalnow-tinytwin.o \
diff --git a/drivers/media/rc/keymaps/rc-delock-61959.c b/drivers/media/rc/keymaps/rc-delock-61959.c
new file mode 100644
index 000000000000..01bed864f09d
--- /dev/null
+++ b/drivers/media/rc/keymaps/rc-delock-61959.c
@@ -0,0 +1,83 @@
1/* rc-delock-61959.c - Keytable for Delock
2 *
3 * Copyright (c) 2013 by Jakob Haufe <sur5r@sur5r.net>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 */
10
11#include <media/rc-map.h>
12#include <linux/module.h>
13
14/*
15 * Keytable for remote provided with Delock 61959
16 */
17static struct rc_map_table delock_61959[] = {
18 { 0x866b16, KEY_POWER2 }, /* Power */
19 { 0x866b0c, KEY_POWER }, /* Shut Down */
20
21 { 0x866b00, KEY_1},
22 { 0x866b01, KEY_2},
23 { 0x866b02, KEY_3},
24 { 0x866b03, KEY_4},
25 { 0x866b04, KEY_5},
26 { 0x866b05, KEY_6},
27 { 0x866b06, KEY_7},
28 { 0x866b07, KEY_8},
29 { 0x866b08, KEY_9},
30 { 0x866b14, KEY_0},
31
32 { 0x866b0a, KEY_ZOOM}, /* Full Screen */
33 { 0x866b10, KEY_CAMERA}, /* Photo */
34 { 0x866b0e, KEY_CHANNEL}, /* circular arrow / Recall */
35 { 0x866b13, KEY_ESC}, /* Back */
36
37 { 0x866b20, KEY_UP},
38 { 0x866b21, KEY_DOWN},
39 { 0x866b42, KEY_LEFT},
40 { 0x866b43, KEY_RIGHT},
41 { 0x866b0b, KEY_OK},
42
43 { 0x866b11, KEY_CHANNELUP},
44 { 0x866b1b, KEY_CHANNELDOWN},
45
46 { 0x866b12, KEY_VOLUMEUP},
47 { 0x866b48, KEY_VOLUMEDOWN},
48 { 0x866b44, KEY_MUTE},
49
50 { 0x866b1a, KEY_RECORD},
51 { 0x866b41, KEY_PLAY},
52 { 0x866b40, KEY_STOP},
53 { 0x866b19, KEY_PAUSE},
54 { 0x866b1c, KEY_FASTFORWARD}, /* >> / FWD */
55 { 0x866b1e, KEY_REWIND}, /* << / REW */
56
57};
58
59static struct rc_map_list delock_61959_map = {
60 .map = {
61 .scan = delock_61959,
62 .size = ARRAY_SIZE(delock_61959),
63 .rc_type = RC_TYPE_NEC,
64 .name = RC_MAP_DELOCK_61959,
65 }
66};
67
68static int __init init_rc_map_delock_61959(void)
69{
70 return rc_map_register(&delock_61959_map);
71}
72
73static void __exit exit_rc_map_delock_61959(void)
74{
75 rc_map_unregister(&delock_61959_map);
76}
77
78module_init(init_rc_map_delock_61959)
79module_exit(exit_rc_map_delock_61959)
80
81MODULE_LICENSE("GPL");
82MODULE_AUTHOR("Jakob Haufe <sur5r@sur5r.net>");
83MODULE_DESCRIPTION("Delock 61959 remote keytable");
diff --git a/drivers/media/tuners/r820t.c b/drivers/media/tuners/r820t.c
index 4835021aa3b6..1c23666468cf 100644
--- a/drivers/media/tuners/r820t.c
+++ b/drivers/media/tuners/r820t.c
@@ -364,8 +364,8 @@ static void shadow_store(struct r820t_priv *priv, u8 reg, const u8 *val,
364 } 364 }
365 if (len <= 0) 365 if (len <= 0)
366 return; 366 return;
367 if (len > NUM_REGS) 367 if (len > NUM_REGS - r)
368 len = NUM_REGS; 368 len = NUM_REGS - r;
369 369
370 tuner_dbg("%s: prev reg=%02x len=%d: %*ph\n", 370 tuner_dbg("%s: prev reg=%02x len=%d: %*ph\n",
371 __func__, r + REG_SHADOW_START, len, len, val); 371 __func__, r + REG_SHADOW_START, len, len, val);
@@ -1857,9 +1857,9 @@ static int r820t_imr(struct r820t_priv *priv, unsigned imr_mem, bool im_flag)
1857 int reg18, reg19, reg1f; 1857 int reg18, reg19, reg1f;
1858 1858
1859 if (priv->cfg->xtal > 24000000) 1859 if (priv->cfg->xtal > 24000000)
1860 ring_ref = priv->cfg->xtal / 2; 1860 ring_ref = priv->cfg->xtal / 2000;
1861 else 1861 else
1862 ring_ref = priv->cfg->xtal; 1862 ring_ref = priv->cfg->xtal / 1000;
1863 1863
1864 n_ring = 15; 1864 n_ring = 15;
1865 for (n = 0; n < 16; n++) { 1865 for (n = 0; n < 16; n++) {
@@ -2256,7 +2256,6 @@ static int r820t_release(struct dvb_frontend *fe)
2256 2256
2257 mutex_unlock(&r820t_list_mutex); 2257 mutex_unlock(&r820t_list_mutex);
2258 2258
2259 kfree(fe->tuner_priv);
2260 fe->tuner_priv = NULL; 2259 fe->tuner_priv = NULL;
2261 2260
2262 return 0; 2261 return 0;
@@ -2311,8 +2310,6 @@ struct dvb_frontend *r820t_attach(struct dvb_frontend *fe,
2311 break; 2310 break;
2312 } 2311 }
2313 2312
2314 memcpy(&fe->ops.tuner_ops, &r820t_tuner_ops, sizeof(r820t_tuner_ops));
2315
2316 if (fe->ops.i2c_gate_ctrl) 2313 if (fe->ops.i2c_gate_ctrl)
2317 fe->ops.i2c_gate_ctrl(fe, 1); 2314 fe->ops.i2c_gate_ctrl(fe, 1);
2318 2315
@@ -2327,15 +2324,14 @@ struct dvb_frontend *r820t_attach(struct dvb_frontend *fe,
2327 2324
2328 tuner_info("Rafael Micro r820t successfully identified\n"); 2325 tuner_info("Rafael Micro r820t successfully identified\n");
2329 2326
2330 fe->tuner_priv = priv;
2331 memcpy(&fe->ops.tuner_ops, &r820t_tuner_ops,
2332 sizeof(struct dvb_tuner_ops));
2333
2334 if (fe->ops.i2c_gate_ctrl) 2327 if (fe->ops.i2c_gate_ctrl)
2335 fe->ops.i2c_gate_ctrl(fe, 0); 2328 fe->ops.i2c_gate_ctrl(fe, 0);
2336 2329
2337 mutex_unlock(&r820t_list_mutex); 2330 mutex_unlock(&r820t_list_mutex);
2338 2331
2332 memcpy(&fe->ops.tuner_ops, &r820t_tuner_ops,
2333 sizeof(struct dvb_tuner_ops));
2334
2339 return fe; 2335 return fe;
2340err: 2336err:
2341 if (fe->ops.i2c_gate_ctrl) 2337 if (fe->ops.i2c_gate_ctrl)
diff --git a/drivers/media/usb/Kconfig b/drivers/media/usb/Kconfig
index 0a7d520636a9..cfe8056b91aa 100644
--- a/drivers/media/usb/Kconfig
+++ b/drivers/media/usb/Kconfig
@@ -1,6 +1,7 @@
1if USB && MEDIA_SUPPORT
2
1menuconfig MEDIA_USB_SUPPORT 3menuconfig MEDIA_USB_SUPPORT
2 bool "Media USB Adapters" 4 bool "Media USB Adapters"
3 depends on USB && MEDIA_SUPPORT
4 help 5 help
5 Enable media drivers for USB bus. 6 Enable media drivers for USB bus.
6 If you have such devices, say Y. 7 If you have such devices, say Y.
@@ -17,6 +18,7 @@ source "drivers/media/usb/zr364xx/Kconfig"
17source "drivers/media/usb/stkwebcam/Kconfig" 18source "drivers/media/usb/stkwebcam/Kconfig"
18source "drivers/media/usb/s2255/Kconfig" 19source "drivers/media/usb/s2255/Kconfig"
19source "drivers/media/usb/sn9c102/Kconfig" 20source "drivers/media/usb/sn9c102/Kconfig"
21source "drivers/media/usb/usbtv/Kconfig"
20endif 22endif
21 23
22if MEDIA_ANALOG_TV_SUPPORT 24if MEDIA_ANALOG_TV_SUPPORT
@@ -52,3 +54,4 @@ source "drivers/media/usb/em28xx/Kconfig"
52endif 54endif
53 55
54endif #MEDIA_USB_SUPPORT 56endif #MEDIA_USB_SUPPORT
57endif #USB
diff --git a/drivers/media/usb/Makefile b/drivers/media/usb/Makefile
index 7f51d7e5f739..0935f47497a6 100644
--- a/drivers/media/usb/Makefile
+++ b/drivers/media/usb/Makefile
@@ -20,3 +20,4 @@ obj-$(CONFIG_VIDEO_STK1160) += stk1160/
20obj-$(CONFIG_VIDEO_CX231XX) += cx231xx/ 20obj-$(CONFIG_VIDEO_CX231XX) += cx231xx/
21obj-$(CONFIG_VIDEO_TM6000) += tm6000/ 21obj-$(CONFIG_VIDEO_TM6000) += tm6000/
22obj-$(CONFIG_VIDEO_EM28XX) += em28xx/ 22obj-$(CONFIG_VIDEO_EM28XX) += em28xx/
23obj-$(CONFIG_VIDEO_USBTV) += usbtv/
diff --git a/drivers/media/usb/au0828/au0828-video.c b/drivers/media/usb/au0828/au0828-video.c
index 75ac9947cdac..f6154546b5c0 100644
--- a/drivers/media/usb/au0828/au0828-video.c
+++ b/drivers/media/usb/au0828/au0828-video.c
@@ -36,7 +36,6 @@
36#include <media/v4l2-common.h> 36#include <media/v4l2-common.h>
37#include <media/v4l2-ioctl.h> 37#include <media/v4l2-ioctl.h>
38#include <media/v4l2-event.h> 38#include <media/v4l2-event.h>
39#include <media/v4l2-chip-ident.h>
40#include <media/tuner.h> 39#include <media/tuner.h>
41#include "au0828.h" 40#include "au0828.h"
42#include "au0828-reg.h" 41#include "au0828-reg.h"
@@ -1638,26 +1637,6 @@ static int vidioc_g_fmt_vbi_cap(struct file *file, void *priv,
1638 return 0; 1637 return 0;
1639} 1638}
1640 1639
1641static int vidioc_g_chip_ident(struct file *file, void *priv,
1642 struct v4l2_dbg_chip_ident *chip)
1643{
1644 struct au0828_fh *fh = priv;
1645 struct au0828_dev *dev = fh->dev;
1646 chip->ident = V4L2_IDENT_NONE;
1647 chip->revision = 0;
1648
1649 if (v4l2_chip_match_host(&chip->match)) {
1650 chip->ident = V4L2_IDENT_AU0828;
1651 return 0;
1652 }
1653
1654 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_chip_ident, chip);
1655 if (chip->ident == V4L2_IDENT_NONE)
1656 return -EINVAL;
1657
1658 return 0;
1659}
1660
1661static int vidioc_cropcap(struct file *file, void *priv, 1640static int vidioc_cropcap(struct file *file, void *priv,
1662 struct v4l2_cropcap *cc) 1641 struct v4l2_cropcap *cc)
1663{ 1642{
@@ -1779,16 +1758,8 @@ static int vidioc_g_register(struct file *file, void *priv,
1779 struct au0828_fh *fh = priv; 1758 struct au0828_fh *fh = priv;
1780 struct au0828_dev *dev = fh->dev; 1759 struct au0828_dev *dev = fh->dev;
1781 1760
1782 switch (reg->match.type) {
1783 case V4L2_CHIP_MATCH_I2C_DRIVER:
1784 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_register, reg);
1785 return 0;
1786 default:
1787 if (!v4l2_chip_match_host(&reg->match))
1788 return -EINVAL;
1789 }
1790
1791 reg->val = au0828_read(dev, reg->reg); 1761 reg->val = au0828_read(dev, reg->reg);
1762 reg->size = 1;
1792 return 0; 1763 return 0;
1793} 1764}
1794 1765
@@ -1798,14 +1769,6 @@ static int vidioc_s_register(struct file *file, void *priv,
1798 struct au0828_fh *fh = priv; 1769 struct au0828_fh *fh = priv;
1799 struct au0828_dev *dev = fh->dev; 1770 struct au0828_dev *dev = fh->dev;
1800 1771
1801 switch (reg->match.type) {
1802 case V4L2_CHIP_MATCH_I2C_DRIVER:
1803 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_register, reg);
1804 return 0;
1805 default:
1806 if (!v4l2_chip_match_host(&reg->match))
1807 return -EINVAL;
1808 }
1809 return au0828_writereg(dev, reg->reg, reg->val); 1772 return au0828_writereg(dev, reg->reg, reg->val);
1810} 1773}
1811#endif 1774#endif
@@ -1943,7 +1906,6 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
1943 .vidioc_g_register = vidioc_g_register, 1906 .vidioc_g_register = vidioc_g_register,
1944 .vidioc_s_register = vidioc_s_register, 1907 .vidioc_s_register = vidioc_s_register,
1945#endif 1908#endif
1946 .vidioc_g_chip_ident = vidioc_g_chip_ident,
1947 .vidioc_log_status = vidioc_log_status, 1909 .vidioc_log_status = vidioc_log_status,
1948 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, 1910 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1949 .vidioc_unsubscribe_event = v4l2_event_unsubscribe, 1911 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
diff --git a/drivers/media/usb/cx231xx/cx231xx-417.c b/drivers/media/usb/cx231xx/cx231xx-417.c
index f548db8043d4..2f63029e7a36 100644
--- a/drivers/media/usb/cx231xx/cx231xx-417.c
+++ b/drivers/media/usb/cx231xx/cx231xx-417.c
@@ -1840,7 +1840,6 @@ static const struct v4l2_ioctl_ops mpeg_ioctl_ops = {
1840 .vidioc_streamon = vidioc_streamon, 1840 .vidioc_streamon = vidioc_streamon,
1841 .vidioc_streamoff = vidioc_streamoff, 1841 .vidioc_streamoff = vidioc_streamoff,
1842 .vidioc_log_status = vidioc_log_status, 1842 .vidioc_log_status = vidioc_log_status,
1843 .vidioc_g_chip_ident = cx231xx_g_chip_ident,
1844#ifdef CONFIG_VIDEO_ADV_DEBUG 1843#ifdef CONFIG_VIDEO_ADV_DEBUG
1845 .vidioc_g_register = cx231xx_g_register, 1844 .vidioc_g_register = cx231xx_g_register,
1846 .vidioc_s_register = cx231xx_s_register, 1845 .vidioc_s_register = cx231xx_s_register,
diff --git a/drivers/media/usb/cx231xx/cx231xx-avcore.c b/drivers/media/usb/cx231xx/cx231xx-avcore.c
index 235ba657d52e..89de00bf4f82 100644
--- a/drivers/media/usb/cx231xx/cx231xx-avcore.c
+++ b/drivers/media/usb/cx231xx/cx231xx-avcore.c
@@ -35,7 +35,6 @@
35 35
36#include <media/v4l2-common.h> 36#include <media/v4l2-common.h>
37#include <media/v4l2-ioctl.h> 37#include <media/v4l2-ioctl.h>
38#include <media/v4l2-chip-ident.h>
39 38
40#include "cx231xx.h" 39#include "cx231xx.h"
41#include "cx231xx-dif.h" 40#include "cx231xx-dif.h"
diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c b/drivers/media/usb/cx231xx/cx231xx-cards.c
index 13249e5a7891..27948e1798eb 100644
--- a/drivers/media/usb/cx231xx/cx231xx-cards.c
+++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
@@ -29,7 +29,6 @@
29#include <media/tuner.h> 29#include <media/tuner.h>
30#include <media/tveeprom.h> 30#include <media/tveeprom.h>
31#include <media/v4l2-common.h> 31#include <media/v4l2-common.h>
32#include <media/v4l2-chip-ident.h>
33 32
34#include <media/cx25840.h> 33#include <media/cx25840.h>
35#include "dvb-usb-ids.h" 34#include "dvb-usb-ids.h"
diff --git a/drivers/media/usb/cx231xx/cx231xx-vbi.c b/drivers/media/usb/cx231xx/cx231xx-vbi.c
index 1340ff268817..c02794274f51 100644
--- a/drivers/media/usb/cx231xx/cx231xx-vbi.c
+++ b/drivers/media/usb/cx231xx/cx231xx-vbi.c
@@ -32,7 +32,6 @@
32 32
33#include <media/v4l2-common.h> 33#include <media/v4l2-common.h>
34#include <media/v4l2-ioctl.h> 34#include <media/v4l2-ioctl.h>
35#include <media/v4l2-chip-ident.h>
36#include <media/msp3400.h> 35#include <media/msp3400.h>
37#include <media/tuner.h> 36#include <media/tuner.h>
38 37
diff --git a/drivers/media/usb/cx231xx/cx231xx-video.c b/drivers/media/usb/cx231xx/cx231xx-video.c
index cd221474e1b9..990626101718 100644
--- a/drivers/media/usb/cx231xx/cx231xx-video.c
+++ b/drivers/media/usb/cx231xx/cx231xx-video.c
@@ -36,7 +36,6 @@
36#include <media/v4l2-common.h> 36#include <media/v4l2-common.h>
37#include <media/v4l2-ioctl.h> 37#include <media/v4l2-ioctl.h>
38#include <media/v4l2-event.h> 38#include <media/v4l2-event.h>
39#include <media/v4l2-chip-ident.h>
40#include <media/msp3400.h> 39#include <media/msp3400.h>
41#include <media/tuner.h> 40#include <media/tuner.h>
42 41
@@ -1228,179 +1227,93 @@ int cx231xx_s_frequency(struct file *file, void *priv,
1228 return rc; 1227 return rc;
1229} 1228}
1230 1229
1231int cx231xx_g_chip_ident(struct file *file, void *fh, 1230#ifdef CONFIG_VIDEO_ADV_DEBUG
1232 struct v4l2_dbg_chip_ident *chip) 1231
1232int cx231xx_g_chip_info(struct file *file, void *fh,
1233 struct v4l2_dbg_chip_info *chip)
1233{ 1234{
1234 chip->ident = V4L2_IDENT_NONE; 1235 switch (chip->match.addr) {
1235 chip->revision = 0; 1236 case 0: /* Cx231xx - internal registers */
1236 if (chip->match.type == V4L2_CHIP_MATCH_HOST) { 1237 return 0;
1237 if (v4l2_chip_match_host(&chip->match)) 1238 case 1: /* AFE - read byte */
1238 chip->ident = V4L2_IDENT_CX23100; 1239 strlcpy(chip->name, "AFE (byte)", sizeof(chip->name));
1240 return 0;
1241 case 2: /* Video Block - read byte */
1242 strlcpy(chip->name, "Video (byte)", sizeof(chip->name));
1243 return 0;
1244 case 3: /* I2S block - read byte */
1245 strlcpy(chip->name, "I2S (byte)", sizeof(chip->name));
1246 return 0;
1247 case 4: /* AFE - read dword */
1248 strlcpy(chip->name, "AFE (dword)", sizeof(chip->name));
1249 return 0;
1250 case 5: /* Video Block - read dword */
1251 strlcpy(chip->name, "Video (dword)", sizeof(chip->name));
1252 return 0;
1253 case 6: /* I2S Block - read dword */
1254 strlcpy(chip->name, "I2S (dword)", sizeof(chip->name));
1239 return 0; 1255 return 0;
1240 } 1256 }
1241 return -EINVAL; 1257 return -EINVAL;
1242} 1258}
1243 1259
1244#ifdef CONFIG_VIDEO_ADV_DEBUG
1245
1246/*
1247 -R, --list-registers=type=<host/i2cdrv/i2caddr>,
1248 chip=<chip>[,min=<addr>,max=<addr>]
1249 dump registers from <min> to <max> [VIDIOC_DBG_G_REGISTER]
1250 -r, --set-register=type=<host/i2cdrv/i2caddr>,
1251 chip=<chip>,reg=<addr>,val=<val>
1252 set the register [VIDIOC_DBG_S_REGISTER]
1253
1254 if type == host, then <chip> is the hosts chip ID (default 0)
1255 if type == i2cdrv (default), then <chip> is the I2C driver name or ID
1256 if type == i2caddr, then <chip> is the 7-bit I2C address
1257*/
1258
1259int cx231xx_g_register(struct file *file, void *priv, 1260int cx231xx_g_register(struct file *file, void *priv,
1260 struct v4l2_dbg_register *reg) 1261 struct v4l2_dbg_register *reg)
1261{ 1262{
1262 struct cx231xx_fh *fh = priv; 1263 struct cx231xx_fh *fh = priv;
1263 struct cx231xx *dev = fh->dev; 1264 struct cx231xx *dev = fh->dev;
1264 int ret = 0; 1265 int ret;
1265 u8 value[4] = { 0, 0, 0, 0 }; 1266 u8 value[4] = { 0, 0, 0, 0 };
1266 u32 data = 0; 1267 u32 data = 0;
1267 1268
1268 switch (reg->match.type) { 1269 switch (reg->match.addr) {
1269 case V4L2_CHIP_MATCH_HOST: 1270 case 0: /* Cx231xx - internal registers */
1270 switch (reg->match.addr) { 1271 ret = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER,
1271 case 0: /* Cx231xx - internal registers */ 1272 (u16)reg->reg, value, 4);
1272 ret = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, 1273 reg->val = value[0] | value[1] << 8 |
1273 (u16)reg->reg, value, 4); 1274 value[2] << 16 | value[3] << 24;
1274 reg->val = value[0] | value[1] << 8 | 1275 reg->size = 4;
1275 value[2] << 16 | value[3] << 24; 1276 break;
1276 break; 1277 case 1: /* AFE - read byte */
1277 case 1: /* AFE - read byte */ 1278 ret = cx231xx_read_i2c_data(dev, AFE_DEVICE_ADDRESS,
1278 ret = cx231xx_read_i2c_data(dev, AFE_DEVICE_ADDRESS, 1279 (u16)reg->reg, 2, &data, 1);
1279 (u16)reg->reg, 2, &data, 1); 1280 reg->val = data;
1280 reg->val = le32_to_cpu(data & 0xff); 1281 reg->size = 1;
1281 break; 1282 break;
1282 case 14: /* AFE - read dword */ 1283 case 2: /* Video Block - read byte */
1283 ret = cx231xx_read_i2c_data(dev, AFE_DEVICE_ADDRESS, 1284 ret = cx231xx_read_i2c_data(dev, VID_BLK_I2C_ADDRESS,
1284 (u16)reg->reg, 2, &data, 4); 1285 (u16)reg->reg, 2, &data, 1);
1285 reg->val = le32_to_cpu(data); 1286 reg->val = data;
1286 break; 1287 reg->size = 1;
1287 case 2: /* Video Block - read byte */ 1288 break;
1288 ret = cx231xx_read_i2c_data(dev, VID_BLK_I2C_ADDRESS, 1289 case 3: /* I2S block - read byte */
1289 (u16)reg->reg, 2, &data, 1); 1290 ret = cx231xx_read_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS,
1290 reg->val = le32_to_cpu(data & 0xff); 1291 (u16)reg->reg, 1, &data, 1);
1291 break; 1292 reg->val = data;
1292 case 24: /* Video Block - read dword */ 1293 reg->size = 1;
1293 ret = cx231xx_read_i2c_data(dev, VID_BLK_I2C_ADDRESS, 1294 break;
1294 (u16)reg->reg, 2, &data, 4); 1295 case 4: /* AFE - read dword */
1295 reg->val = le32_to_cpu(data); 1296 ret = cx231xx_read_i2c_data(dev, AFE_DEVICE_ADDRESS,
1296 break; 1297 (u16)reg->reg, 2, &data, 4);
1297 case 3: /* I2S block - read byte */ 1298 reg->val = data;
1298 ret = cx231xx_read_i2c_data(dev, 1299 reg->size = 4;
1299 I2S_BLK_DEVICE_ADDRESS, 1300 break;
1300 (u16)reg->reg, 1, 1301 case 5: /* Video Block - read dword */
1301 &data, 1); 1302 ret = cx231xx_read_i2c_data(dev, VID_BLK_I2C_ADDRESS,
1302 reg->val = le32_to_cpu(data & 0xff); 1303 (u16)reg->reg, 2, &data, 4);
1303 break; 1304 reg->val = data;
1304 case 34: /* I2S Block - read dword */ 1305 reg->size = 4;
1305 ret = 1306 break;
1306 cx231xx_read_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS, 1307 case 6: /* I2S Block - read dword */
1307 (u16)reg->reg, 1, &data, 4); 1308 ret = cx231xx_read_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS,
1308 reg->val = le32_to_cpu(data); 1309 (u16)reg->reg, 1, &data, 4);
1309 break; 1310 reg->val = data;
1310 } 1311 reg->size = 4;
1311 return ret < 0 ? ret : 0; 1312 break;
1312
1313 case V4L2_CHIP_MATCH_I2C_DRIVER:
1314 call_all(dev, core, g_register, reg);
1315 return 0;
1316 case V4L2_CHIP_MATCH_I2C_ADDR:/*for register debug*/
1317 switch (reg->match.addr) {
1318 case 0: /* Cx231xx - internal registers */
1319 ret = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER,
1320 (u16)reg->reg, value, 4);
1321 reg->val = value[0] | value[1] << 8 |
1322 value[2] << 16 | value[3] << 24;
1323
1324 break;
1325 case 0x600:/* AFE - read byte */
1326 ret = cx231xx_read_i2c_master(dev, AFE_DEVICE_ADDRESS,
1327 (u16)reg->reg, 2,
1328 &data, 1 , 0);
1329 reg->val = le32_to_cpu(data & 0xff);
1330 break;
1331
1332 case 0x880:/* Video Block - read byte */
1333 if (reg->reg < 0x0b) {
1334 ret = cx231xx_read_i2c_master(dev,
1335 VID_BLK_I2C_ADDRESS,
1336 (u16)reg->reg, 2,
1337 &data, 1 , 0);
1338 reg->val = le32_to_cpu(data & 0xff);
1339 } else {
1340 ret = cx231xx_read_i2c_master(dev,
1341 VID_BLK_I2C_ADDRESS,
1342 (u16)reg->reg, 2,
1343 &data, 4 , 0);
1344 reg->val = le32_to_cpu(data);
1345 }
1346 break;
1347 case 0x980:
1348 ret = cx231xx_read_i2c_master(dev,
1349 I2S_BLK_DEVICE_ADDRESS,
1350 (u16)reg->reg, 1,
1351 &data, 1 , 0);
1352 reg->val = le32_to_cpu(data & 0xff);
1353 break;
1354 case 0x400:
1355 ret =
1356 cx231xx_read_i2c_master(dev, 0x40,
1357 (u16)reg->reg, 1,
1358 &data, 1 , 0);
1359 reg->val = le32_to_cpu(data & 0xff);
1360 break;
1361 case 0xc01:
1362 ret =
1363 cx231xx_read_i2c_master(dev, 0xc0,
1364 (u16)reg->reg, 2,
1365 &data, 38, 1);
1366 reg->val = le32_to_cpu(data);
1367 break;
1368 case 0x022:
1369 ret =
1370 cx231xx_read_i2c_master(dev, 0x02,
1371 (u16)reg->reg, 1,
1372 &data, 1, 2);
1373 reg->val = le32_to_cpu(data & 0xff);
1374 break;
1375 case 0x322:
1376 ret = cx231xx_read_i2c_master(dev,
1377 0x32,
1378 (u16)reg->reg, 1,
1379 &data, 4 , 2);
1380 reg->val = le32_to_cpu(data);
1381 break;
1382 case 0x342:
1383 ret = cx231xx_read_i2c_master(dev,
1384 0x34,
1385 (u16)reg->reg, 1,
1386 &data, 4 , 2);
1387 reg->val = le32_to_cpu(data);
1388 break;
1389
1390 default:
1391 cx231xx_info("no match device address!!\n");
1392 break;
1393 }
1394 return ret < 0 ? ret : 0;
1395 /*return -EINVAL;*/
1396 default: 1313 default:
1397 if (!v4l2_chip_match_host(&reg->match)) 1314 return -EINVAL;
1398 return -EINVAL;
1399 } 1315 }
1400 1316 return ret < 0 ? ret : 0;
1401 call_all(dev, core, g_register, reg);
1402
1403 return ret;
1404} 1317}
1405 1318
1406int cx231xx_s_register(struct file *file, void *priv, 1319int cx231xx_s_register(struct file *file, void *priv,
@@ -1408,165 +1321,46 @@ int cx231xx_s_register(struct file *file, void *priv,
1408{ 1321{
1409 struct cx231xx_fh *fh = priv; 1322 struct cx231xx_fh *fh = priv;
1410 struct cx231xx *dev = fh->dev; 1323 struct cx231xx *dev = fh->dev;
1411 int ret = 0; 1324 int ret;
1412 __le64 buf;
1413 u32 value;
1414 u8 data[4] = { 0, 0, 0, 0 }; 1325 u8 data[4] = { 0, 0, 0, 0 };
1415 1326
1416 buf = cpu_to_le64(reg->val); 1327 switch (reg->match.addr) {
1417 1328 case 0: /* cx231xx internal registers */
1418 switch (reg->match.type) { 1329 data[0] = (u8) reg->val;
1419 case V4L2_CHIP_MATCH_HOST: 1330 data[1] = (u8) (reg->val >> 8);
1420 { 1331 data[2] = (u8) (reg->val >> 16);
1421 value = (u32) buf & 0xffffffff; 1332 data[3] = (u8) (reg->val >> 24);
1422 1333 ret = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER,
1423 switch (reg->match.addr) { 1334 (u16)reg->reg, data, 4);
1424 case 0: /* cx231xx internal registers */ 1335 break;
1425 data[0] = (u8) value; 1336 case 1: /* AFE - write byte */
1426 data[1] = (u8) (value >> 8); 1337 ret = cx231xx_write_i2c_data(dev, AFE_DEVICE_ADDRESS,
1427 data[2] = (u8) (value >> 16); 1338 (u16)reg->reg, 2, reg->val, 1);
1428 data[3] = (u8) (value >> 24); 1339 break;
1429 ret = cx231xx_write_ctrl_reg(dev, 1340 case 2: /* Video Block - write byte */
1430 VRT_SET_REGISTER, 1341 ret = cx231xx_write_i2c_data(dev, VID_BLK_I2C_ADDRESS,
1431 (u16)reg->reg, data, 1342 (u16)reg->reg, 2, reg->val, 1);
1432 4); 1343 break;
1433 break; 1344 case 3: /* I2S block - write byte */
1434 case 1: /* AFE - read byte */ 1345 ret = cx231xx_write_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS,
1435 ret = cx231xx_write_i2c_data(dev, 1346 (u16)reg->reg, 1, reg->val, 1);
1436 AFE_DEVICE_ADDRESS, 1347 break;
1437 (u16)reg->reg, 2, 1348 case 4: /* AFE - write dword */
1438 value, 1); 1349 ret = cx231xx_write_i2c_data(dev, AFE_DEVICE_ADDRESS,
1439 break; 1350 (u16)reg->reg, 2, reg->val, 4);
1440 case 14: /* AFE - read dword */ 1351 break;
1441 ret = cx231xx_write_i2c_data(dev, 1352 case 5: /* Video Block - write dword */
1442 AFE_DEVICE_ADDRESS, 1353 ret = cx231xx_write_i2c_data(dev, VID_BLK_I2C_ADDRESS,
1443 (u16)reg->reg, 2, 1354 (u16)reg->reg, 2, reg->val, 4);
1444 value, 4);
1445 break;
1446 case 2: /* Video Block - read byte */
1447 ret =
1448 cx231xx_write_i2c_data(dev,
1449 VID_BLK_I2C_ADDRESS,
1450 (u16)reg->reg, 2,
1451 value, 1);
1452 break;
1453 case 24: /* Video Block - read dword */
1454 ret =
1455 cx231xx_write_i2c_data(dev,
1456 VID_BLK_I2C_ADDRESS,
1457 (u16)reg->reg, 2,
1458 value, 4);
1459 break;
1460 case 3: /* I2S block - read byte */
1461 ret =
1462 cx231xx_write_i2c_data(dev,
1463 I2S_BLK_DEVICE_ADDRESS,
1464 (u16)reg->reg, 1,
1465 value, 1);
1466 break;
1467 case 34: /* I2S block - read dword */
1468 ret =
1469 cx231xx_write_i2c_data(dev,
1470 I2S_BLK_DEVICE_ADDRESS,
1471 (u16)reg->reg, 1,
1472 value, 4);
1473 break;
1474 }
1475 }
1476 return ret < 0 ? ret : 0;
1477 case V4L2_CHIP_MATCH_I2C_ADDR:
1478 {
1479 value = (u32) buf & 0xffffffff;
1480
1481 switch (reg->match.addr) {
1482 case 0:/*cx231xx internal registers*/
1483 data[0] = (u8) value;
1484 data[1] = (u8) (value >> 8);
1485 data[2] = (u8) (value >> 16);
1486 data[3] = (u8) (value >> 24);
1487 ret = cx231xx_write_ctrl_reg(dev,
1488 VRT_SET_REGISTER,
1489 (u16)reg->reg, data,
1490 4);
1491 break;
1492 case 0x600:/* AFE - read byte */
1493 ret = cx231xx_write_i2c_master(dev,
1494 AFE_DEVICE_ADDRESS,
1495 (u16)reg->reg, 2,
1496 value, 1 , 0);
1497 break;
1498
1499 case 0x880:/* Video Block - read byte */
1500 if (reg->reg < 0x0b)
1501 cx231xx_write_i2c_master(dev,
1502 VID_BLK_I2C_ADDRESS,
1503 (u16)reg->reg, 2,
1504 value, 1, 0);
1505 else
1506 cx231xx_write_i2c_master(dev,
1507 VID_BLK_I2C_ADDRESS,
1508 (u16)reg->reg, 2,
1509 value, 4, 0);
1510 break;
1511 case 0x980:
1512 ret =
1513 cx231xx_write_i2c_master(dev,
1514 I2S_BLK_DEVICE_ADDRESS,
1515 (u16)reg->reg, 1,
1516 value, 1, 0);
1517 break;
1518 case 0x400:
1519 ret =
1520 cx231xx_write_i2c_master(dev,
1521 0x40,
1522 (u16)reg->reg, 1,
1523 value, 1, 0);
1524 break;
1525 case 0xc01:
1526 ret =
1527 cx231xx_write_i2c_master(dev,
1528 0xc0,
1529 (u16)reg->reg, 1,
1530 value, 1, 1);
1531 break;
1532
1533 case 0x022:
1534 ret =
1535 cx231xx_write_i2c_master(dev,
1536 0x02,
1537 (u16)reg->reg, 1,
1538 value, 1, 2);
1539 break;
1540 case 0x322:
1541 ret =
1542 cx231xx_write_i2c_master(dev,
1543 0x32,
1544 (u16)reg->reg, 1,
1545 value, 4, 2);
1546 break;
1547
1548 case 0x342:
1549 ret =
1550 cx231xx_write_i2c_master(dev,
1551 0x34,
1552 (u16)reg->reg, 1,
1553 value, 4, 2);
1554 break;
1555 default:
1556 cx231xx_info("no match device address, "
1557 "the value is %x\n", reg->match.addr);
1558 break;
1559
1560 }
1561
1562 }
1563 default:
1564 break; 1355 break;
1356 case 6: /* I2S block - write dword */
1357 ret = cx231xx_write_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS,
1358 (u16)reg->reg, 1, reg->val, 4);
1359 break;
1360 default:
1361 return -EINVAL;
1565 } 1362 }
1566 1363 return ret < 0 ? ret : 0;
1567 call_all(dev, core, s_register, reg);
1568
1569 return ret;
1570} 1364}
1571#endif 1365#endif
1572 1366
@@ -2208,8 +2002,8 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
2208 .vidioc_s_tuner = cx231xx_s_tuner, 2002 .vidioc_s_tuner = cx231xx_s_tuner,
2209 .vidioc_g_frequency = cx231xx_g_frequency, 2003 .vidioc_g_frequency = cx231xx_g_frequency,
2210 .vidioc_s_frequency = cx231xx_s_frequency, 2004 .vidioc_s_frequency = cx231xx_s_frequency,
2211 .vidioc_g_chip_ident = cx231xx_g_chip_ident,
2212#ifdef CONFIG_VIDEO_ADV_DEBUG 2005#ifdef CONFIG_VIDEO_ADV_DEBUG
2006 .vidioc_g_chip_info = cx231xx_g_chip_info,
2213 .vidioc_g_register = cx231xx_g_register, 2007 .vidioc_g_register = cx231xx_g_register,
2214 .vidioc_s_register = cx231xx_s_register, 2008 .vidioc_s_register = cx231xx_s_register,
2215#endif 2009#endif
@@ -2240,8 +2034,8 @@ static const struct v4l2_ioctl_ops radio_ioctl_ops = {
2240 .vidioc_s_tuner = radio_s_tuner, 2034 .vidioc_s_tuner = radio_s_tuner,
2241 .vidioc_g_frequency = cx231xx_g_frequency, 2035 .vidioc_g_frequency = cx231xx_g_frequency,
2242 .vidioc_s_frequency = cx231xx_s_frequency, 2036 .vidioc_s_frequency = cx231xx_s_frequency,
2243 .vidioc_g_chip_ident = cx231xx_g_chip_ident,
2244#ifdef CONFIG_VIDEO_ADV_DEBUG 2037#ifdef CONFIG_VIDEO_ADV_DEBUG
2038 .vidioc_g_chip_info = cx231xx_g_chip_info,
2245 .vidioc_g_register = cx231xx_g_register, 2039 .vidioc_g_register = cx231xx_g_register,
2246 .vidioc_s_register = cx231xx_s_register, 2040 .vidioc_s_register = cx231xx_s_register,
2247#endif 2041#endif
diff --git a/drivers/media/usb/cx231xx/cx231xx.h b/drivers/media/usb/cx231xx/cx231xx.h
index 5ad9fd61d3c8..e812119ea7a8 100644
--- a/drivers/media/usb/cx231xx/cx231xx.h
+++ b/drivers/media/usb/cx231xx/cx231xx.h
@@ -945,7 +945,7 @@ int cx231xx_enum_input(struct file *file, void *priv,
945 struct v4l2_input *i); 945 struct v4l2_input *i);
946int cx231xx_g_input(struct file *file, void *priv, unsigned int *i); 946int cx231xx_g_input(struct file *file, void *priv, unsigned int *i);
947int cx231xx_s_input(struct file *file, void *priv, unsigned int i); 947int cx231xx_s_input(struct file *file, void *priv, unsigned int i);
948int cx231xx_g_chip_ident(struct file *file, void *fh, struct v4l2_dbg_chip_ident *chip); 948int cx231xx_g_chip_info(struct file *file, void *fh, struct v4l2_dbg_chip_info *chip);
949int cx231xx_g_register(struct file *file, void *priv, 949int cx231xx_g_register(struct file *file, void *priv,
950 struct v4l2_dbg_register *reg); 950 struct v4l2_dbg_register *reg);
951int cx231xx_s_register(struct file *file, void *priv, 951int cx231xx_s_register(struct file *file, void *priv,
diff --git a/drivers/media/usb/dvb-usb-v2/af9035.c b/drivers/media/usb/dvb-usb-v2/af9035.c
index b638fc1cd574..1ea17dc2a76e 100644
--- a/drivers/media/usb/dvb-usb-v2/af9035.c
+++ b/drivers/media/usb/dvb-usb-v2/af9035.c
@@ -55,7 +55,7 @@ static int af9035_ctrl_msg(struct dvb_usb_device *d, struct usb_req *req)
55 if (req->wlen > (BUF_LEN - REQ_HDR_LEN - CHECKSUM_LEN) || 55 if (req->wlen > (BUF_LEN - REQ_HDR_LEN - CHECKSUM_LEN) ||
56 req->rlen > (BUF_LEN - ACK_HDR_LEN - CHECKSUM_LEN)) { 56 req->rlen > (BUF_LEN - ACK_HDR_LEN - CHECKSUM_LEN)) {
57 dev_err(&d->udev->dev, "%s: too much data wlen=%d rlen=%d\n", 57 dev_err(&d->udev->dev, "%s: too much data wlen=%d rlen=%d\n",
58 __func__, req->wlen, req->rlen); 58 KBUILD_MODNAME, req->wlen, req->rlen);
59 ret = -EINVAL; 59 ret = -EINVAL;
60 goto exit; 60 goto exit;
61 } 61 }
@@ -91,9 +91,10 @@ static int af9035_ctrl_msg(struct dvb_usb_device *d, struct usb_req *req)
91 checksum = af9035_checksum(state->buf, rlen - 2); 91 checksum = af9035_checksum(state->buf, rlen - 2);
92 tmp_checksum = (state->buf[rlen - 2] << 8) | state->buf[rlen - 1]; 92 tmp_checksum = (state->buf[rlen - 2] << 8) | state->buf[rlen - 1];
93 if (tmp_checksum != checksum) { 93 if (tmp_checksum != checksum) {
94 dev_err(&d->udev->dev, "%s: command=%02x checksum mismatch " \ 94 dev_err(&d->udev->dev,
95 "(%04x != %04x)\n", KBUILD_MODNAME, req->cmd, 95 "%s: command=%02x checksum mismatch (%04x != %04x)\n",
96 tmp_checksum, checksum); 96 KBUILD_MODNAME, req->cmd, tmp_checksum,
97 checksum);
97 ret = -EIO; 98 ret = -EIO;
98 goto exit; 99 goto exit;
99 } 100 }
@@ -268,11 +269,29 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap,
268 memcpy(&buf[5], msg[0].buf, msg[0].len); 269 memcpy(&buf[5], msg[0].buf, msg[0].len);
269 ret = af9035_ctrl_msg(d, &req); 270 ret = af9035_ctrl_msg(d, &req);
270 } 271 }
272 } else if (num == 1 && (msg[0].flags & I2C_M_RD)) {
273 if (msg[0].len > 40) {
274 /* TODO: correct limits > 40 */
275 ret = -EOPNOTSUPP;
276 } else {
277 /* I2C */
278 u8 buf[5];
279 struct usb_req req = { CMD_I2C_RD, 0, sizeof(buf),
280 buf, msg[0].len, msg[0].buf };
281 req.mbox |= ((msg[0].addr & 0x80) >> 3);
282 buf[0] = msg[0].len;
283 buf[1] = msg[0].addr << 1;
284 buf[2] = 0x00; /* reg addr len */
285 buf[3] = 0x00; /* reg addr MSB */
286 buf[4] = 0x00; /* reg addr LSB */
287 ret = af9035_ctrl_msg(d, &req);
288 }
271 } else { 289 } else {
272 /* 290 /*
273 * We support only two kind of I2C transactions: 291 * We support only three kind of I2C transactions:
274 * 1) 1 x read + 1 x write 292 * 1) 1 x read + 1 x write (repeated start)
275 * 2) 1 x write 293 * 2) 1 x write
294 * 3) 1 x read
276 */ 295 */
277 ret = -EOPNOTSUPP; 296 ret = -EOPNOTSUPP;
278 } 297 }
@@ -317,8 +336,8 @@ static int af9035_identify_state(struct dvb_usb_device *d, const char **name)
317 336
318 dev_info(&d->udev->dev, 337 dev_info(&d->udev->dev,
319 "%s: prechip_version=%02x chip_version=%02x chip_type=%04x\n", 338 "%s: prechip_version=%02x chip_version=%02x chip_type=%04x\n",
320 __func__, state->prechip_version, state->chip_version, 339 KBUILD_MODNAME, state->prechip_version,
321 state->chip_type); 340 state->chip_version, state->chip_type);
322 341
323 if (state->chip_type == 0x9135) { 342 if (state->chip_type == 0x9135) {
324 if (state->chip_version == 0x02) 343 if (state->chip_version == 0x02)
@@ -382,9 +401,10 @@ static int af9035_download_firmware_old(struct dvb_usb_device *d,
382 hdr_checksum = fw->data[fw->size - i + 5] << 8; 401 hdr_checksum = fw->data[fw->size - i + 5] << 8;
383 hdr_checksum |= fw->data[fw->size - i + 6] << 0; 402 hdr_checksum |= fw->data[fw->size - i + 6] << 0;
384 403
385 dev_dbg(&d->udev->dev, "%s: core=%d addr=%04x data_len=%d " \ 404 dev_dbg(&d->udev->dev,
386 "checksum=%04x\n", __func__, hdr_core, hdr_addr, 405 "%s: core=%d addr=%04x data_len=%d checksum=%04x\n",
387 hdr_data_len, hdr_checksum); 406 __func__, hdr_core, hdr_addr, hdr_data_len,
407 hdr_checksum);
388 408
389 if (((hdr_core != 1) && (hdr_core != 2)) || 409 if (((hdr_core != 1) && (hdr_core != 2)) ||
390 (hdr_data_len > i)) { 410 (hdr_data_len > i)) {
@@ -489,7 +509,7 @@ static int af9035_download_firmware(struct dvb_usb_device *d,
489 u8 rbuf[4]; 509 u8 rbuf[4];
490 u8 tmp; 510 u8 tmp;
491 struct usb_req req = { 0, 0, 0, NULL, 0, NULL }; 511 struct usb_req req = { 0, 0, 0, NULL, 0, NULL };
492 struct usb_req req_fw_ver = { CMD_FW_QUERYINFO, 0, 1, wbuf, 4, rbuf } ; 512 struct usb_req req_fw_ver = { CMD_FW_QUERYINFO, 0, 1, wbuf, 4, rbuf };
493 dev_dbg(&d->udev->dev, "%s:\n", __func__); 513 dev_dbg(&d->udev->dev, "%s:\n", __func__);
494 514
495 /* 515 /*
@@ -498,11 +518,11 @@ static int af9035_download_firmware(struct dvb_usb_device *d,
498 * which is done by master demod. 518 * which is done by master demod.
499 * Master feeds also clock and controls power via GPIO. 519 * Master feeds also clock and controls power via GPIO.
500 */ 520 */
501 ret = af9035_rd_reg(d, state->eeprom_addr + EEPROM_DUAL_MODE, &tmp); 521 ret = af9035_rd_reg(d, state->eeprom_addr + EEPROM_TS_MODE, &tmp);
502 if (ret < 0) 522 if (ret < 0)
503 goto err; 523 goto err;
504 524
505 if (tmp) { 525 if (tmp == 1 || tmp == 3) {
506 /* configure gpioh1, reset & power slave demod */ 526 /* configure gpioh1, reset & power slave demod */
507 ret = af9035_wr_reg_mask(d, 0x00d8b0, 0x01, 0x01); 527 ret = af9035_wr_reg_mask(d, 0x00d8b0, 0x01, 0x01);
508 if (ret < 0) 528 if (ret < 0)
@@ -620,13 +640,15 @@ static int af9035_read_config(struct dvb_usb_device *d)
620 } 640 }
621 641
622 /* check if there is dual tuners */ 642 /* check if there is dual tuners */
623 ret = af9035_rd_reg(d, state->eeprom_addr + EEPROM_DUAL_MODE, &tmp); 643 ret = af9035_rd_reg(d, state->eeprom_addr + EEPROM_TS_MODE, &tmp);
624 if (ret < 0) 644 if (ret < 0)
625 goto err; 645 goto err;
626 646
627 state->dual_mode = tmp; 647 if (tmp == 1 || tmp == 3)
628 dev_dbg(&d->udev->dev, "%s: dual mode=%d\n", __func__, 648 state->dual_mode = true;
629 state->dual_mode); 649
650 dev_dbg(&d->udev->dev, "%s: ts mode=%d dual mode=%d\n", __func__,
651 tmp, state->dual_mode);
630 652
631 if (state->dual_mode) { 653 if (state->dual_mode) {
632 /* read 2nd demodulator I2C address */ 654 /* read 2nd demodulator I2C address */
@@ -1200,9 +1222,9 @@ static int af9035_init(struct dvb_usb_device *d)
1200 { 0x80f9a4, 0x00, 0x01 }, 1222 { 0x80f9a4, 0x00, 0x01 },
1201 }; 1223 };
1202 1224
1203 dev_dbg(&d->udev->dev, "%s: USB speed=%d frame_size=%04x " \ 1225 dev_dbg(&d->udev->dev,
1204 "packet_size=%02x\n", __func__, 1226 "%s: USB speed=%d frame_size=%04x packet_size=%02x\n",
1205 d->udev->speed, frame_size, packet_size); 1227 __func__, d->udev->speed, frame_size, packet_size);
1206 1228
1207 /* init endpoints */ 1229 /* init endpoints */
1208 for (i = 0; i < ARRAY_SIZE(tab); i++) { 1230 for (i = 0; i < ARRAY_SIZE(tab); i++) {
@@ -1477,7 +1499,7 @@ static const struct usb_device_id af9035_id_table[] = {
1477 &af9035_props, "AVerMedia Twinstar (A825)", NULL) }, 1499 &af9035_props, "AVerMedia Twinstar (A825)", NULL) },
1478 { DVB_USB_DEVICE(USB_VID_ASUS, USB_PID_ASUS_U3100MINI_PLUS, 1500 { DVB_USB_DEVICE(USB_VID_ASUS, USB_PID_ASUS_U3100MINI_PLUS,
1479 &af9035_props, "Asus U3100Mini Plus", NULL) }, 1501 &af9035_props, "Asus U3100Mini Plus", NULL) },
1480 { DVB_USB_DEVICE(USB_VID_TERRATEC, 0x00aa, 1502 { DVB_USB_DEVICE(USB_VID_TERRATEC, 0x00aa,
1481 &af9035_props, "TerraTec Cinergy T Stick (rev. 2)", NULL) }, 1503 &af9035_props, "TerraTec Cinergy T Stick (rev. 2)", NULL) },
1482 /* IT9135 devices */ 1504 /* IT9135 devices */
1483#if 0 1505#if 0
diff --git a/drivers/media/usb/dvb-usb-v2/af9035.h b/drivers/media/usb/dvb-usb-v2/af9035.h
index b5827ca3a01e..a1c68d829b8c 100644
--- a/drivers/media/usb/dvb-usb-v2/af9035.h
+++ b/drivers/media/usb/dvb-usb-v2/af9035.h
@@ -100,8 +100,13 @@ static const u32 clock_lut_it9135[] = {
100 * eeprom is memory mapped as read only. Writing that memory mapped address 100 * eeprom is memory mapped as read only. Writing that memory mapped address
101 * will not corrupt eeprom. 101 * will not corrupt eeprom.
102 * 102 *
103 * eeprom has value 0x00 single mode and 0x03 for dual mode as far as I have 103 * TS mode:
104 * seen to this day. 104 * 0 TS
105 * 1 DCA + PIP
106 * 3 PIP
107 * n DCA
108 *
109 * Values 0 and 3 are seen to this day. 0 for single TS and 3 for dual TS.
105 */ 110 */
106 111
107#define EEPROM_BASE_AF9035 0x42fd 112#define EEPROM_BASE_AF9035 0x42fd
@@ -109,7 +114,7 @@ static const u32 clock_lut_it9135[] = {
109#define EEPROM_SHIFT 0x10 114#define EEPROM_SHIFT 0x10
110 115
111#define EEPROM_IR_MODE 0x10 116#define EEPROM_IR_MODE 0x10
112#define EEPROM_DUAL_MODE 0x29 117#define EEPROM_TS_MODE 0x29
113#define EEPROM_2ND_DEMOD_ADDR 0x2a 118#define EEPROM_2ND_DEMOD_ADDR 0x2a
114#define EEPROM_IR_TYPE 0x2c 119#define EEPROM_IR_TYPE 0x2c
115#define EEPROM_1_IF_L 0x30 120#define EEPROM_1_IF_L 0x30
diff --git a/drivers/media/usb/dvb-usb-v2/dvb_usb.h b/drivers/media/usb/dvb-usb-v2/dvb_usb.h
index 658c6d47fdff..399916bd588f 100644
--- a/drivers/media/usb/dvb-usb-v2/dvb_usb.h
+++ b/drivers/media/usb/dvb-usb-v2/dvb_usb.h
@@ -140,7 +140,7 @@ struct dvb_usb_rc {
140 int (*change_protocol)(struct rc_dev *dev, u64 *rc_type); 140 int (*change_protocol)(struct rc_dev *dev, u64 *rc_type);
141 int (*query) (struct dvb_usb_device *d); 141 int (*query) (struct dvb_usb_device *d);
142 unsigned int interval; 142 unsigned int interval;
143 const enum rc_driver_type driver_type; 143 enum rc_driver_type driver_type;
144 bool bulk_mode; 144 bool bulk_mode;
145}; 145};
146 146
diff --git a/drivers/media/usb/dvb-usb-v2/it913x.c b/drivers/media/usb/dvb-usb-v2/it913x.c
index e48cdeb9df41..1cb6899cf797 100644
--- a/drivers/media/usb/dvb-usb-v2/it913x.c
+++ b/drivers/media/usb/dvb-usb-v2/it913x.c
@@ -45,7 +45,7 @@ MODULE_PARM_DESC(debug, "set debugging level (1=info (or-able)).");
45 45
46static int dvb_usb_it913x_firmware; 46static int dvb_usb_it913x_firmware;
47module_param_named(firmware, dvb_usb_it913x_firmware, int, 0644); 47module_param_named(firmware, dvb_usb_it913x_firmware, int, 0644);
48MODULE_PARM_DESC(firmware, "set firmware 0=auto"\ 48MODULE_PARM_DESC(firmware, "set firmware 0=auto "\
49 "1=IT9137 2=IT9135 V1 3=IT9135 V2"); 49 "1=IT9137 2=IT9135 V1 3=IT9135 V2");
50#define FW_IT9137 "dvb-usb-it9137-01.fw" 50#define FW_IT9137 "dvb-usb-it9137-01.fw"
51#define FW_IT9135_V1 "dvb-usb-it9135-01.fw" 51#define FW_IT9135_V1 "dvb-usb-it9135-01.fw"
@@ -796,6 +796,9 @@ static const struct usb_device_id it913x_id_table[] = {
796 { DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A835B_4835, 796 { DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A835B_4835,
797 &it913x_properties, "Avermedia A835B(4835)", 797 &it913x_properties, "Avermedia A835B(4835)",
798 RC_MAP_IT913X_V2) }, 798 RC_MAP_IT913X_V2) },
799 { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_CTVDIGDUAL_V2,
800 &it913x_properties, "Digital Dual TV Receiver CTVDIGDUAL_V2",
801 RC_MAP_IT913X_V1) },
799 {} /* Terminating entry */ 802 {} /* Terminating entry */
800}; 803};
801 804
diff --git a/drivers/media/usb/dvb-usb-v2/mxl111sf-tuner.c b/drivers/media/usb/dvb-usb-v2/mxl111sf-tuner.c
index ef4c65fcbb73..879c529640f7 100644
--- a/drivers/media/usb/dvb-usb-v2/mxl111sf-tuner.c
+++ b/drivers/media/usb/dvb-usb-v2/mxl111sf-tuner.c
@@ -31,8 +31,6 @@ MODULE_PARM_DESC(debug, "set debugging level (1=info (or-able)).");
31 if (mxl111sf_tuner_debug) \ 31 if (mxl111sf_tuner_debug) \
32 mxl_printk(KERN_DEBUG, fmt, ##arg) 32 mxl_printk(KERN_DEBUG, fmt, ##arg)
33 33
34#define err pr_err
35
36/* ------------------------------------------------------------------------ */ 34/* ------------------------------------------------------------------------ */
37 35
38struct mxl111sf_tuner_state { 36struct mxl111sf_tuner_state {
@@ -113,7 +111,7 @@ static struct mxl111sf_reg_ctrl_info *mxl111sf_calc_phy_tune_regs(u32 freq,
113 filt_bw = 63; 111 filt_bw = 63;
114 break; 112 break;
115 default: 113 default:
116 err("%s: invalid bandwidth setting!", __func__); 114 pr_err("%s: invalid bandwidth setting!", __func__);
117 return NULL; 115 return NULL;
118 } 116 }
119 117
@@ -304,12 +302,12 @@ static int mxl111sf_tuner_set_params(struct dvb_frontend *fe)
304 bw = 8; 302 bw = 8;
305 break; 303 break;
306 default: 304 default:
307 err("%s: bandwidth not set!", __func__); 305 pr_err("%s: bandwidth not set!", __func__);
308 return -EINVAL; 306 return -EINVAL;
309 } 307 }
310 break; 308 break;
311 default: 309 default:
312 err("%s: modulation type not supported!", __func__); 310 pr_err("%s: modulation type not supported!", __func__);
313 return -EINVAL; 311 return -EINVAL;
314 } 312 }
315 ret = mxl1x1sf_tune_rf(fe, c->frequency, bw); 313 ret = mxl1x1sf_tune_rf(fe, c->frequency, bw);
diff --git a/drivers/media/usb/dvb-usb-v2/mxl111sf.c b/drivers/media/usb/dvb-usb-v2/mxl111sf.c
index efdcb15358f1..e97964ef7f56 100644
--- a/drivers/media/usb/dvb-usb-v2/mxl111sf.c
+++ b/drivers/media/usb/dvb-usb-v2/mxl111sf.c
@@ -52,12 +52,6 @@ MODULE_PARM_DESC(rfswitch, "force rf switch position (0=auto, 1=ext, 2=int).");
52 52
53DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); 53DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
54 54
55#define deb_info pr_debug
56#define deb_reg pr_debug
57#define deb_adv pr_debug
58#define err pr_err
59#define info pr_info
60
61int mxl111sf_ctrl_msg(struct dvb_usb_device *d, 55int mxl111sf_ctrl_msg(struct dvb_usb_device *d,
62 u8 cmd, u8 *wbuf, int wlen, u8 *rbuf, int rlen) 56 u8 cmd, u8 *wbuf, int wlen, u8 *rbuf, int rlen)
63{ 57{
@@ -65,7 +59,7 @@ int mxl111sf_ctrl_msg(struct dvb_usb_device *d,
65 int ret; 59 int ret;
66 u8 sndbuf[1+wlen]; 60 u8 sndbuf[1+wlen];
67 61
68 deb_adv("%s(wlen = %d, rlen = %d)\n", __func__, wlen, rlen); 62 pr_debug("%s(wlen = %d, rlen = %d)\n", __func__, wlen, rlen);
69 63
70 memset(sndbuf, 0, 1+wlen); 64 memset(sndbuf, 0, 1+wlen);
71 65
@@ -98,12 +92,12 @@ int mxl111sf_read_reg(struct mxl111sf_state *state, u8 addr, u8 *data)
98 if (buf[0] == addr) 92 if (buf[0] == addr)
99 *data = buf[1]; 93 *data = buf[1];
100 else { 94 else {
101 err("invalid response reading reg: 0x%02x != 0x%02x, 0x%02x", 95 pr_err("invalid response reading reg: 0x%02x != 0x%02x, 0x%02x",
102 addr, buf[0], buf[1]); 96 addr, buf[0], buf[1]);
103 ret = -EINVAL; 97 ret = -EINVAL;
104 } 98 }
105 99
106 deb_reg("R: (0x%02x, 0x%02x)\n", addr, *data); 100 pr_debug("R: (0x%02x, 0x%02x)\n", addr, *data);
107fail: 101fail:
108 return ret; 102 return ret;
109} 103}
@@ -113,11 +107,11 @@ int mxl111sf_write_reg(struct mxl111sf_state *state, u8 addr, u8 data)
113 u8 buf[] = { addr, data }; 107 u8 buf[] = { addr, data };
114 int ret; 108 int ret;
115 109
116 deb_reg("W: (0x%02x, 0x%02x)\n", addr, data); 110 pr_debug("W: (0x%02x, 0x%02x)\n", addr, data);
117 111
118 ret = mxl111sf_ctrl_msg(state->d, MXL_CMD_REG_WRITE, buf, 2, NULL, 0); 112 ret = mxl111sf_ctrl_msg(state->d, MXL_CMD_REG_WRITE, buf, 2, NULL, 0);
119 if (mxl_fail(ret)) 113 if (mxl_fail(ret))
120 err("error writing reg: 0x%02x, val: 0x%02x", addr, data); 114 pr_err("error writing reg: 0x%02x, val: 0x%02x", addr, data);
121 return ret; 115 return ret;
122} 116}
123 117
@@ -134,7 +128,7 @@ int mxl111sf_write_reg_mask(struct mxl111sf_state *state,
134#if 1 128#if 1
135 /* dont know why this usually errors out on the first try */ 129 /* dont know why this usually errors out on the first try */
136 if (mxl_fail(ret)) 130 if (mxl_fail(ret))
137 err("error writing addr: 0x%02x, mask: 0x%02x, " 131 pr_err("error writing addr: 0x%02x, mask: 0x%02x, "
138 "data: 0x%02x, retrying...", addr, mask, data); 132 "data: 0x%02x, retrying...", addr, mask, data);
139 133
140 ret = mxl111sf_read_reg(state, addr, &val); 134 ret = mxl111sf_read_reg(state, addr, &val);
@@ -167,7 +161,7 @@ int mxl111sf_ctrl_program_regs(struct mxl111sf_state *state,
167 ctrl_reg_info[i].mask, 161 ctrl_reg_info[i].mask,
168 ctrl_reg_info[i].data); 162 ctrl_reg_info[i].data);
169 if (mxl_fail(ret)) { 163 if (mxl_fail(ret)) {
170 err("failed on reg #%d (0x%02x)", i, 164 pr_err("failed on reg #%d (0x%02x)", i,
171 ctrl_reg_info[i].addr); 165 ctrl_reg_info[i].addr);
172 break; 166 break;
173 } 167 }
@@ -225,7 +219,7 @@ static int mxl1x1sf_get_chip_info(struct mxl111sf_state *state)
225 mxl_rev = "UNKNOWN REVISION"; 219 mxl_rev = "UNKNOWN REVISION";
226 break; 220 break;
227 } 221 }
228 info("%s detected, %s (0x%x)", mxl_chip, mxl_rev, ver); 222 pr_info("%s detected, %s (0x%x)", mxl_chip, mxl_rev, ver);
229fail: 223fail:
230 return ret; 224 return ret;
231} 225}
@@ -239,7 +233,7 @@ fail:
239 " on first probe attempt"); \ 233 " on first probe attempt"); \
240 ___ret = mxl1x1sf_get_chip_info(state); \ 234 ___ret = mxl1x1sf_get_chip_info(state); \
241 if (mxl_fail(___ret)) \ 235 if (mxl_fail(___ret)) \
242 err("failed to get chip info during probe"); \ 236 pr_err("failed to get chip info during probe"); \
243 else \ 237 else \
244 mxl_debug("probe needed a retry " \ 238 mxl_debug("probe needed a retry " \
245 "in order to succeed."); \ 239 "in order to succeed."); \
@@ -270,14 +264,14 @@ static int mxl111sf_adap_fe_init(struct dvb_frontend *fe)
270 goto fail; 264 goto fail;
271 } 265 }
272 266
273 deb_info("%s()\n", __func__); 267 pr_debug("%s()\n", __func__);
274 268
275 mutex_lock(&state->fe_lock); 269 mutex_lock(&state->fe_lock);
276 270
277 state->alt_mode = adap_state->alt_mode; 271 state->alt_mode = adap_state->alt_mode;
278 272
279 if (usb_set_interface(d->udev, 0, state->alt_mode) < 0) 273 if (usb_set_interface(d->udev, 0, state->alt_mode) < 0)
280 err("set interface failed"); 274 pr_err("set interface failed");
281 275
282 err = mxl1x1sf_soft_reset(state); 276 err = mxl1x1sf_soft_reset(state);
283 mxl_fail(err); 277 mxl_fail(err);
@@ -326,7 +320,7 @@ static int mxl111sf_adap_fe_sleep(struct dvb_frontend *fe)
326 goto fail; 320 goto fail;
327 } 321 }
328 322
329 deb_info("%s()\n", __func__); 323 pr_debug("%s()\n", __func__);
330 324
331 err = (adap_state->fe_sleep) ? adap_state->fe_sleep(fe) : 0; 325 err = (adap_state->fe_sleep) ? adap_state->fe_sleep(fe) : 0;
332 326
@@ -344,7 +338,7 @@ static int mxl111sf_ep6_streaming_ctrl(struct dvb_frontend *fe, int onoff)
344 struct mxl111sf_adap_state *adap_state = &state->adap_state[fe->id]; 338 struct mxl111sf_adap_state *adap_state = &state->adap_state[fe->id];
345 int ret = 0; 339 int ret = 0;
346 340
347 deb_info("%s(%d)\n", __func__, onoff); 341 pr_debug("%s(%d)\n", __func__, onoff);
348 342
349 if (onoff) { 343 if (onoff) {
350 ret = mxl111sf_enable_usb_output(state); 344 ret = mxl111sf_enable_usb_output(state);
@@ -368,7 +362,7 @@ static int mxl111sf_ep5_streaming_ctrl(struct dvb_frontend *fe, int onoff)
368 struct mxl111sf_state *state = fe_to_priv(fe); 362 struct mxl111sf_state *state = fe_to_priv(fe);
369 int ret = 0; 363 int ret = 0;
370 364
371 deb_info("%s(%d)\n", __func__, onoff); 365 pr_debug("%s(%d)\n", __func__, onoff);
372 366
373 if (onoff) { 367 if (onoff) {
374 ret = mxl111sf_enable_usb_output(state); 368 ret = mxl111sf_enable_usb_output(state);
@@ -394,7 +388,7 @@ static int mxl111sf_ep4_streaming_ctrl(struct dvb_frontend *fe, int onoff)
394 struct mxl111sf_state *state = fe_to_priv(fe); 388 struct mxl111sf_state *state = fe_to_priv(fe);
395 int ret = 0; 389 int ret = 0;
396 390
397 deb_info("%s(%d)\n", __func__, onoff); 391 pr_debug("%s(%d)\n", __func__, onoff);
398 392
399 if (onoff) { 393 if (onoff) {
400 ret = mxl111sf_enable_usb_output(state); 394 ret = mxl111sf_enable_usb_output(state);
@@ -424,7 +418,7 @@ static int mxl111sf_lgdt3305_frontend_attach(struct dvb_usb_adapter *adap, u8 fe
424 struct mxl111sf_adap_state *adap_state = &state->adap_state[fe_id]; 418 struct mxl111sf_adap_state *adap_state = &state->adap_state[fe_id];
425 int ret; 419 int ret;
426 420
427 deb_adv("%s()\n", __func__); 421 pr_debug("%s()\n", __func__);
428 422
429 /* save a pointer to the dvb_usb_device in device state */ 423 /* save a pointer to the dvb_usb_device in device state */
430 state->d = d; 424 state->d = d;
@@ -432,7 +426,7 @@ static int mxl111sf_lgdt3305_frontend_attach(struct dvb_usb_adapter *adap, u8 fe
432 state->alt_mode = adap_state->alt_mode; 426 state->alt_mode = adap_state->alt_mode;
433 427
434 if (usb_set_interface(d->udev, 0, state->alt_mode) < 0) 428 if (usb_set_interface(d->udev, 0, state->alt_mode) < 0)
435 err("set interface failed"); 429 pr_err("set interface failed");
436 430
437 state->gpio_mode = MXL111SF_GPIO_MOD_ATSC; 431 state->gpio_mode = MXL111SF_GPIO_MOD_ATSC;
438 adap_state->gpio_mode = state->gpio_mode; 432 adap_state->gpio_mode = state->gpio_mode;
@@ -495,7 +489,7 @@ static int mxl111sf_lg2160_frontend_attach(struct dvb_usb_adapter *adap, u8 fe_i
495 struct mxl111sf_adap_state *adap_state = &state->adap_state[fe_id]; 489 struct mxl111sf_adap_state *adap_state = &state->adap_state[fe_id];
496 int ret; 490 int ret;
497 491
498 deb_adv("%s()\n", __func__); 492 pr_debug("%s()\n", __func__);
499 493
500 /* save a pointer to the dvb_usb_device in device state */ 494 /* save a pointer to the dvb_usb_device in device state */
501 state->d = d; 495 state->d = d;
@@ -503,7 +497,7 @@ static int mxl111sf_lg2160_frontend_attach(struct dvb_usb_adapter *adap, u8 fe_i
503 state->alt_mode = adap_state->alt_mode; 497 state->alt_mode = adap_state->alt_mode;
504 498
505 if (usb_set_interface(d->udev, 0, state->alt_mode) < 0) 499 if (usb_set_interface(d->udev, 0, state->alt_mode) < 0)
506 err("set interface failed"); 500 pr_err("set interface failed");
507 501
508 state->gpio_mode = MXL111SF_GPIO_MOD_MH; 502 state->gpio_mode = MXL111SF_GPIO_MOD_MH;
509 adap_state->gpio_mode = state->gpio_mode; 503 adap_state->gpio_mode = state->gpio_mode;
@@ -580,7 +574,7 @@ static int mxl111sf_lg2161_frontend_attach(struct dvb_usb_adapter *adap, u8 fe_i
580 struct mxl111sf_adap_state *adap_state = &state->adap_state[fe_id]; 574 struct mxl111sf_adap_state *adap_state = &state->adap_state[fe_id];
581 int ret; 575 int ret;
582 576
583 deb_adv("%s()\n", __func__); 577 pr_debug("%s()\n", __func__);
584 578
585 /* save a pointer to the dvb_usb_device in device state */ 579 /* save a pointer to the dvb_usb_device in device state */
586 state->d = d; 580 state->d = d;
@@ -588,7 +582,7 @@ static int mxl111sf_lg2161_frontend_attach(struct dvb_usb_adapter *adap, u8 fe_i
588 state->alt_mode = adap_state->alt_mode; 582 state->alt_mode = adap_state->alt_mode;
589 583
590 if (usb_set_interface(d->udev, 0, state->alt_mode) < 0) 584 if (usb_set_interface(d->udev, 0, state->alt_mode) < 0)
591 err("set interface failed"); 585 pr_err("set interface failed");
592 586
593 state->gpio_mode = MXL111SF_GPIO_MOD_MH; 587 state->gpio_mode = MXL111SF_GPIO_MOD_MH;
594 adap_state->gpio_mode = state->gpio_mode; 588 adap_state->gpio_mode = state->gpio_mode;
@@ -667,7 +661,7 @@ static int mxl111sf_lg2161_ep6_frontend_attach(struct dvb_usb_adapter *adap, u8
667 struct mxl111sf_adap_state *adap_state = &state->adap_state[fe_id]; 661 struct mxl111sf_adap_state *adap_state = &state->adap_state[fe_id];
668 int ret; 662 int ret;
669 663
670 deb_adv("%s()\n", __func__); 664 pr_debug("%s()\n", __func__);
671 665
672 /* save a pointer to the dvb_usb_device in device state */ 666 /* save a pointer to the dvb_usb_device in device state */
673 state->d = d; 667 state->d = d;
@@ -675,7 +669,7 @@ static int mxl111sf_lg2161_ep6_frontend_attach(struct dvb_usb_adapter *adap, u8
675 state->alt_mode = adap_state->alt_mode; 669 state->alt_mode = adap_state->alt_mode;
676 670
677 if (usb_set_interface(d->udev, 0, state->alt_mode) < 0) 671 if (usb_set_interface(d->udev, 0, state->alt_mode) < 0)
678 err("set interface failed"); 672 pr_err("set interface failed");
679 673
680 state->gpio_mode = MXL111SF_GPIO_MOD_MH; 674 state->gpio_mode = MXL111SF_GPIO_MOD_MH;
681 adap_state->gpio_mode = state->gpio_mode; 675 adap_state->gpio_mode = state->gpio_mode;
@@ -742,7 +736,7 @@ static int mxl111sf_attach_demod(struct dvb_usb_adapter *adap, u8 fe_id)
742 struct mxl111sf_adap_state *adap_state = &state->adap_state[fe_id]; 736 struct mxl111sf_adap_state *adap_state = &state->adap_state[fe_id];
743 int ret; 737 int ret;
744 738
745 deb_adv("%s()\n", __func__); 739 pr_debug("%s()\n", __func__);
746 740
747 /* save a pointer to the dvb_usb_device in device state */ 741 /* save a pointer to the dvb_usb_device in device state */
748 state->d = d; 742 state->d = d;
@@ -750,7 +744,7 @@ static int mxl111sf_attach_demod(struct dvb_usb_adapter *adap, u8 fe_id)
750 state->alt_mode = adap_state->alt_mode; 744 state->alt_mode = adap_state->alt_mode;
751 745
752 if (usb_set_interface(d->udev, 0, state->alt_mode) < 0) 746 if (usb_set_interface(d->udev, 0, state->alt_mode) < 0)
753 err("set interface failed"); 747 pr_err("set interface failed");
754 748
755 state->gpio_mode = MXL111SF_GPIO_MOD_DVBT; 749 state->gpio_mode = MXL111SF_GPIO_MOD_DVBT;
756 adap_state->gpio_mode = state->gpio_mode; 750 adap_state->gpio_mode = state->gpio_mode;
@@ -802,7 +796,7 @@ static inline int mxl111sf_set_ant_path(struct mxl111sf_state *state,
802} 796}
803 797
804#define DbgAntHunt(x, pwr0, pwr1, pwr2, pwr3) \ 798#define DbgAntHunt(x, pwr0, pwr1, pwr2, pwr3) \
805 err("%s(%d) FINAL input set to %s rxPwr:%d|%d|%d|%d\n", \ 799 pr_err("%s(%d) FINAL input set to %s rxPwr:%d|%d|%d|%d\n", \
806 __func__, __LINE__, \ 800 __func__, __LINE__, \
807 (ANT_PATH_EXTERNAL == x) ? "EXTERNAL" : "INTERNAL", \ 801 (ANT_PATH_EXTERNAL == x) ? "EXTERNAL" : "INTERNAL", \
808 pwr0, pwr1, pwr2, pwr3) 802 pwr0, pwr1, pwr2, pwr3)
@@ -868,7 +862,7 @@ static int mxl111sf_attach_tuner(struct dvb_usb_adapter *adap)
868 struct mxl111sf_state *state = adap_to_priv(adap); 862 struct mxl111sf_state *state = adap_to_priv(adap);
869 int i; 863 int i;
870 864
871 deb_adv("%s()\n", __func__); 865 pr_debug("%s()\n", __func__);
872 866
873 for (i = 0; i < state->num_frontends; i++) { 867 for (i = 0; i < state->num_frontends; i++) {
874 if (dvb_attach(mxl111sf_tuner_attach, adap->fe[i], state, 868 if (dvb_attach(mxl111sf_tuner_attach, adap->fe[i], state,
@@ -902,7 +896,7 @@ static int mxl111sf_init(struct dvb_usb_device *d)
902 896
903 ret = get_chip_info(state); 897 ret = get_chip_info(state);
904 if (mxl_fail(ret)) 898 if (mxl_fail(ret))
905 err("failed to get chip info during probe"); 899 pr_err("failed to get chip info during probe");
906 900
907 mutex_init(&state->fe_lock); 901 mutex_init(&state->fe_lock);
908 902
@@ -950,7 +944,7 @@ static int mxl111sf_frontend_attach_mh(struct dvb_usb_adapter *adap)
950static int mxl111sf_frontend_attach_atsc_mh(struct dvb_usb_adapter *adap) 944static int mxl111sf_frontend_attach_atsc_mh(struct dvb_usb_adapter *adap)
951{ 945{
952 int ret; 946 int ret;
953 deb_info("%s\n", __func__); 947 pr_debug("%s\n", __func__);
954 948
955 ret = mxl111sf_lgdt3305_frontend_attach(adap, 0); 949 ret = mxl111sf_lgdt3305_frontend_attach(adap, 0);
956 if (ret < 0) 950 if (ret < 0)
@@ -970,7 +964,7 @@ static int mxl111sf_frontend_attach_atsc_mh(struct dvb_usb_adapter *adap)
970static int mxl111sf_frontend_attach_mercury(struct dvb_usb_adapter *adap) 964static int mxl111sf_frontend_attach_mercury(struct dvb_usb_adapter *adap)
971{ 965{
972 int ret; 966 int ret;
973 deb_info("%s\n", __func__); 967 pr_debug("%s\n", __func__);
974 968
975 ret = mxl111sf_lgdt3305_frontend_attach(adap, 0); 969 ret = mxl111sf_lgdt3305_frontend_attach(adap, 0);
976 if (ret < 0) 970 if (ret < 0)
@@ -990,7 +984,7 @@ static int mxl111sf_frontend_attach_mercury(struct dvb_usb_adapter *adap)
990static int mxl111sf_frontend_attach_mercury_mh(struct dvb_usb_adapter *adap) 984static int mxl111sf_frontend_attach_mercury_mh(struct dvb_usb_adapter *adap)
991{ 985{
992 int ret; 986 int ret;
993 deb_info("%s\n", __func__); 987 pr_debug("%s\n", __func__);
994 988
995 ret = mxl111sf_attach_demod(adap, 0); 989 ret = mxl111sf_attach_demod(adap, 0);
996 if (ret < 0) 990 if (ret < 0)
@@ -1006,7 +1000,7 @@ static int mxl111sf_frontend_attach_mercury_mh(struct dvb_usb_adapter *adap)
1006 1000
1007static void mxl111sf_stream_config_bulk(struct usb_data_stream_properties *stream, u8 endpoint) 1001static void mxl111sf_stream_config_bulk(struct usb_data_stream_properties *stream, u8 endpoint)
1008{ 1002{
1009 deb_info("%s: endpoint=%d size=8192\n", __func__, endpoint); 1003 pr_debug("%s: endpoint=%d size=8192\n", __func__, endpoint);
1010 stream->type = USB_BULK; 1004 stream->type = USB_BULK;
1011 stream->count = 5; 1005 stream->count = 5;
1012 stream->endpoint = endpoint; 1006 stream->endpoint = endpoint;
@@ -1016,7 +1010,7 @@ static void mxl111sf_stream_config_bulk(struct usb_data_stream_properties *strea
1016static void mxl111sf_stream_config_isoc(struct usb_data_stream_properties *stream, 1010static void mxl111sf_stream_config_isoc(struct usb_data_stream_properties *stream,
1017 u8 endpoint, int framesperurb, int framesize) 1011 u8 endpoint, int framesperurb, int framesize)
1018{ 1012{
1019 deb_info("%s: endpoint=%d size=%d\n", __func__, endpoint, 1013 pr_debug("%s: endpoint=%d size=%d\n", __func__, endpoint,
1020 framesperurb * framesize); 1014 framesperurb * framesize);
1021 stream->type = USB_ISOC; 1015 stream->type = USB_ISOC;
1022 stream->count = 5; 1016 stream->count = 5;
@@ -1035,7 +1029,7 @@ static void mxl111sf_stream_config_isoc(struct usb_data_stream_properties *strea
1035static int mxl111sf_get_stream_config_dvbt(struct dvb_frontend *fe, 1029static int mxl111sf_get_stream_config_dvbt(struct dvb_frontend *fe,
1036 u8 *ts_type, struct usb_data_stream_properties *stream) 1030 u8 *ts_type, struct usb_data_stream_properties *stream)
1037{ 1031{
1038 deb_info("%s: fe=%d\n", __func__, fe->id); 1032 pr_debug("%s: fe=%d\n", __func__, fe->id);
1039 1033
1040 *ts_type = DVB_USB_FE_TS_TYPE_188; 1034 *ts_type = DVB_USB_FE_TS_TYPE_188;
1041 if (dvb_usb_mxl111sf_isoc) 1035 if (dvb_usb_mxl111sf_isoc)
@@ -1076,7 +1070,7 @@ static struct dvb_usb_device_properties mxl111sf_props_dvbt = {
1076static int mxl111sf_get_stream_config_atsc(struct dvb_frontend *fe, 1070static int mxl111sf_get_stream_config_atsc(struct dvb_frontend *fe,
1077 u8 *ts_type, struct usb_data_stream_properties *stream) 1071 u8 *ts_type, struct usb_data_stream_properties *stream)
1078{ 1072{
1079 deb_info("%s: fe=%d\n", __func__, fe->id); 1073 pr_debug("%s: fe=%d\n", __func__, fe->id);
1080 1074
1081 *ts_type = DVB_USB_FE_TS_TYPE_188; 1075 *ts_type = DVB_USB_FE_TS_TYPE_188;
1082 if (dvb_usb_mxl111sf_isoc) 1076 if (dvb_usb_mxl111sf_isoc)
@@ -1117,7 +1111,7 @@ static struct dvb_usb_device_properties mxl111sf_props_atsc = {
1117static int mxl111sf_get_stream_config_mh(struct dvb_frontend *fe, 1111static int mxl111sf_get_stream_config_mh(struct dvb_frontend *fe,
1118 u8 *ts_type, struct usb_data_stream_properties *stream) 1112 u8 *ts_type, struct usb_data_stream_properties *stream)
1119{ 1113{
1120 deb_info("%s: fe=%d\n", __func__, fe->id); 1114 pr_debug("%s: fe=%d\n", __func__, fe->id);
1121 1115
1122 *ts_type = DVB_USB_FE_TS_TYPE_RAW; 1116 *ts_type = DVB_USB_FE_TS_TYPE_RAW;
1123 if (dvb_usb_mxl111sf_isoc) 1117 if (dvb_usb_mxl111sf_isoc)
@@ -1158,7 +1152,7 @@ static struct dvb_usb_device_properties mxl111sf_props_mh = {
1158static int mxl111sf_get_stream_config_atsc_mh(struct dvb_frontend *fe, 1152static int mxl111sf_get_stream_config_atsc_mh(struct dvb_frontend *fe,
1159 u8 *ts_type, struct usb_data_stream_properties *stream) 1153 u8 *ts_type, struct usb_data_stream_properties *stream)
1160{ 1154{
1161 deb_info("%s: fe=%d\n", __func__, fe->id); 1155 pr_debug("%s: fe=%d\n", __func__, fe->id);
1162 1156
1163 if (fe->id == 0) { 1157 if (fe->id == 0) {
1164 *ts_type = DVB_USB_FE_TS_TYPE_188; 1158 *ts_type = DVB_USB_FE_TS_TYPE_188;
@@ -1184,7 +1178,7 @@ static int mxl111sf_get_stream_config_atsc_mh(struct dvb_frontend *fe,
1184 1178
1185static int mxl111sf_streaming_ctrl_atsc_mh(struct dvb_frontend *fe, int onoff) 1179static int mxl111sf_streaming_ctrl_atsc_mh(struct dvb_frontend *fe, int onoff)
1186{ 1180{
1187 deb_info("%s: fe=%d onoff=%d\n", __func__, fe->id, onoff); 1181 pr_debug("%s: fe=%d onoff=%d\n", __func__, fe->id, onoff);
1188 1182
1189 if (fe->id == 0) 1183 if (fe->id == 0)
1190 return mxl111sf_ep6_streaming_ctrl(fe, onoff); 1184 return mxl111sf_ep6_streaming_ctrl(fe, onoff);
@@ -1228,7 +1222,7 @@ static struct dvb_usb_device_properties mxl111sf_props_atsc_mh = {
1228static int mxl111sf_get_stream_config_mercury(struct dvb_frontend *fe, 1222static int mxl111sf_get_stream_config_mercury(struct dvb_frontend *fe,
1229 u8 *ts_type, struct usb_data_stream_properties *stream) 1223 u8 *ts_type, struct usb_data_stream_properties *stream)
1230{ 1224{
1231 deb_info("%s: fe=%d\n", __func__, fe->id); 1225 pr_debug("%s: fe=%d\n", __func__, fe->id);
1232 1226
1233 if (fe->id == 0) { 1227 if (fe->id == 0) {
1234 *ts_type = DVB_USB_FE_TS_TYPE_188; 1228 *ts_type = DVB_USB_FE_TS_TYPE_188;
@@ -1260,7 +1254,7 @@ static int mxl111sf_get_stream_config_mercury(struct dvb_frontend *fe,
1260 1254
1261static int mxl111sf_streaming_ctrl_mercury(struct dvb_frontend *fe, int onoff) 1255static int mxl111sf_streaming_ctrl_mercury(struct dvb_frontend *fe, int onoff)
1262{ 1256{
1263 deb_info("%s: fe=%d onoff=%d\n", __func__, fe->id, onoff); 1257 pr_debug("%s: fe=%d onoff=%d\n", __func__, fe->id, onoff);
1264 1258
1265 if (fe->id == 0) 1259 if (fe->id == 0)
1266 return mxl111sf_ep6_streaming_ctrl(fe, onoff); 1260 return mxl111sf_ep6_streaming_ctrl(fe, onoff);
@@ -1306,7 +1300,7 @@ static struct dvb_usb_device_properties mxl111sf_props_mercury = {
1306static int mxl111sf_get_stream_config_mercury_mh(struct dvb_frontend *fe, 1300static int mxl111sf_get_stream_config_mercury_mh(struct dvb_frontend *fe,
1307 u8 *ts_type, struct usb_data_stream_properties *stream) 1301 u8 *ts_type, struct usb_data_stream_properties *stream)
1308{ 1302{
1309 deb_info("%s: fe=%d\n", __func__, fe->id); 1303 pr_debug("%s: fe=%d\n", __func__, fe->id);
1310 1304
1311 if (fe->id == 0) { 1305 if (fe->id == 0) {
1312 *ts_type = DVB_USB_FE_TS_TYPE_188; 1306 *ts_type = DVB_USB_FE_TS_TYPE_188;
@@ -1332,7 +1326,7 @@ static int mxl111sf_get_stream_config_mercury_mh(struct dvb_frontend *fe,
1332 1326
1333static int mxl111sf_streaming_ctrl_mercury_mh(struct dvb_frontend *fe, int onoff) 1327static int mxl111sf_streaming_ctrl_mercury_mh(struct dvb_frontend *fe, int onoff)
1334{ 1328{
1335 deb_info("%s: fe=%d onoff=%d\n", __func__, fe->id, onoff); 1329 pr_debug("%s: fe=%d onoff=%d\n", __func__, fe->id, onoff);
1336 1330
1337 if (fe->id == 0) 1331 if (fe->id == 0)
1338 return mxl111sf_ep4_streaming_ctrl(fe, onoff); 1332 return mxl111sf_ep4_streaming_ctrl(fe, onoff);
diff --git a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
index 2cc8ec70e3b6..c0cd0848631b 100644
--- a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
+++ b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
@@ -1041,67 +1041,34 @@ err:
1041static int rtl2832u_power_ctrl(struct dvb_usb_device *d, int onoff) 1041static int rtl2832u_power_ctrl(struct dvb_usb_device *d, int onoff)
1042{ 1042{
1043 int ret; 1043 int ret;
1044 u8 val;
1045 1044
1046 dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff); 1045 dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff);
1047 1046
1048 if (onoff) { 1047 if (onoff) {
1049 /* set output values */ 1048 /* GPIO3=1, GPIO4=0 */
1050 ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &val); 1049 ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x08, 0x18);
1051 if (ret) 1050 if (ret)
1052 goto err; 1051 goto err;
1053 1052
1054 val |= 0x08; 1053 /* suspend? */
1055 val &= 0xef; 1054 ret = rtl28xx_wr_reg_mask(d, SYS_DEMOD_CTL1, 0x00, 0x10);
1056
1057 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, val);
1058 if (ret) 1055 if (ret)
1059 goto err; 1056 goto err;
1060 1057
1061 /* demod_ctl_1 */ 1058 /* enable PLL */
1062 ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL1, &val); 1059 ret = rtl28xx_wr_reg_mask(d, SYS_DEMOD_CTL, 0x80, 0x80);
1063 if (ret) 1060 if (ret)
1064 goto err; 1061 goto err;
1065 1062
1066 val &= 0xef; 1063 /* disable reset */
1067 1064 ret = rtl28xx_wr_reg_mask(d, SYS_DEMOD_CTL, 0x20, 0x20);
1068 ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL1, val);
1069 if (ret)
1070 goto err;
1071
1072 /* demod control */
1073 /* PLL enable */
1074 ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val);
1075 if (ret)
1076 goto err;
1077
1078 /* bit 7 to 1 */
1079 val |= 0x80;
1080
1081 ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val);
1082 if (ret)
1083 goto err;
1084
1085 ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val);
1086 if (ret)
1087 goto err;
1088
1089 val |= 0x20;
1090
1091 ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val);
1092 if (ret) 1065 if (ret)
1093 goto err; 1066 goto err;
1094 1067
1095 mdelay(5); 1068 mdelay(5);
1096 1069
1097 /*enable ADC_Q and ADC_I */ 1070 /* enable ADC */
1098 ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val); 1071 ret = rtl28xx_wr_reg_mask(d, SYS_DEMOD_CTL, 0x48, 0x48);
1099 if (ret)
1100 goto err;
1101
1102 val |= 0x48;
1103
1104 ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val);
1105 if (ret) 1072 if (ret)
1106 goto err; 1073 goto err;
1107 1074
@@ -1114,36 +1081,18 @@ static int rtl2832u_power_ctrl(struct dvb_usb_device *d, int onoff)
1114 if (ret) 1081 if (ret)
1115 goto err; 1082 goto err;
1116 } else { 1083 } else {
1117 /* demod_ctl_1 */ 1084 /* GPIO4=1 */
1118 ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL1, &val); 1085 ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x10, 0x10);
1119 if (ret)
1120 goto err;
1121
1122 val |= 0x0c;
1123
1124 ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL1, val);
1125 if (ret)
1126 goto err;
1127
1128 /* set output values */
1129 ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &val);
1130 if (ret)
1131 goto err;
1132
1133 val |= 0x10;
1134
1135 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, val);
1136 if (ret) 1086 if (ret)
1137 goto err; 1087 goto err;
1138 1088
1139 /* demod control */ 1089 /* disable ADC */
1140 ret = rtl28xx_rd_reg(d, SYS_DEMOD_CTL, &val); 1090 ret = rtl28xx_wr_reg_mask(d, SYS_DEMOD_CTL, 0x00, 0x48);
1141 if (ret) 1091 if (ret)
1142 goto err; 1092 goto err;
1143 1093
1144 val &= 0x37; 1094 /* disable PLL */
1145 1095 ret = rtl28xx_wr_reg_mask(d, SYS_DEMOD_CTL, 0x00, 0x80);
1146 ret = rtl28xx_wr_reg(d, SYS_DEMOD_CTL, val);
1147 if (ret) 1096 if (ret)
1148 goto err; 1097 goto err;
1149 1098
@@ -1242,42 +1191,47 @@ static int rtl2831u_get_rc_config(struct dvb_usb_device *d,
1242 1191
1243 return 0; 1192 return 0;
1244} 1193}
1245#else
1246 #define rtl2831u_get_rc_config NULL
1247#endif
1248 1194
1249#if IS_ENABLED(CONFIG_RC_CORE)
1250static int rtl2832u_rc_query(struct dvb_usb_device *d) 1195static int rtl2832u_rc_query(struct dvb_usb_device *d)
1251{ 1196{
1252 int ret, i; 1197 int ret, i, len;
1253 struct rtl28xxu_priv *priv = d->priv; 1198 struct rtl28xxu_priv *priv = d->priv;
1199 struct ir_raw_event ev;
1254 u8 buf[128]; 1200 u8 buf[128];
1255 int len; 1201 static const struct rtl28xxu_reg_val_mask refresh_tab[] = {
1256 struct rtl28xxu_reg_val rc_nec_tab[] = { 1202 {IR_RX_IF, 0x03, 0xff},
1257 { IR_RX_CTRL, 0x20 }, 1203 {IR_RX_BUF_CTRL, 0x80, 0xff},
1258 { IR_RX_BUF_CTRL, 0x80 }, 1204 {IR_RX_CTRL, 0x80, 0xff},
1259 { IR_RX_IF, 0xff },
1260 { IR_RX_IE, 0xff },
1261 { IR_MAX_DURATION0, 0xd0 },
1262 { IR_MAX_DURATION1, 0x07 },
1263 { IR_IDLE_LEN0, 0xc0 },
1264 { IR_IDLE_LEN1, 0x00 },
1265 { IR_GLITCH_LEN, 0x03 },
1266 { IR_RX_CLK, 0x09 },
1267 { IR_RX_CFG, 0x1c },
1268 { IR_MAX_H_TOL_LEN, 0x1e },
1269 { IR_MAX_L_TOL_LEN, 0x1e },
1270 { IR_RX_CTRL, 0x80 },
1271 }; 1205 };
1272 1206
1273 /* init remote controller */ 1207 /* init remote controller */
1274 if (!priv->rc_active) { 1208 if (!priv->rc_active) {
1275 for (i = 0; i < ARRAY_SIZE(rc_nec_tab); i++) { 1209 static const struct rtl28xxu_reg_val_mask init_tab[] = {
1276 ret = rtl28xx_wr_reg(d, rc_nec_tab[i].reg, 1210 {SYS_DEMOD_CTL1, 0x00, 0x04},
1277 rc_nec_tab[i].val); 1211 {SYS_DEMOD_CTL1, 0x00, 0x08},
1212 {USB_CTRL, 0x20, 0x20},
1213 {SYS_GPIO_DIR, 0x00, 0x08},
1214 {SYS_GPIO_OUT_EN, 0x08, 0x08},
1215 {SYS_GPIO_OUT_VAL, 0x08, 0x08},
1216 {IR_MAX_DURATION0, 0xd0, 0xff},
1217 {IR_MAX_DURATION1, 0x07, 0xff},
1218 {IR_IDLE_LEN0, 0xc0, 0xff},
1219 {IR_IDLE_LEN1, 0x00, 0xff},
1220 {IR_GLITCH_LEN, 0x03, 0xff},
1221 {IR_RX_CLK, 0x09, 0xff},
1222 {IR_RX_CFG, 0x1c, 0xff},
1223 {IR_MAX_H_TOL_LEN, 0x1e, 0xff},
1224 {IR_MAX_L_TOL_LEN, 0x1e, 0xff},
1225 {IR_RX_CTRL, 0x80, 0xff},
1226 };
1227
1228 for (i = 0; i < ARRAY_SIZE(init_tab); i++) {
1229 ret = rtl28xx_wr_reg_mask(d, init_tab[i].reg,
1230 init_tab[i].val, init_tab[i].mask);
1278 if (ret) 1231 if (ret)
1279 goto err; 1232 goto err;
1280 } 1233 }
1234
1281 priv->rc_active = true; 1235 priv->rc_active = true;
1282 } 1236 }
1283 1237
@@ -1293,14 +1247,32 @@ static int rtl2832u_rc_query(struct dvb_usb_device *d)
1293 goto err; 1247 goto err;
1294 1248
1295 len = buf[0]; 1249 len = buf[0];
1250
1251 /* read raw code from hw */
1296 ret = rtl2831_rd_regs(d, IR_RX_BUF, buf, len); 1252 ret = rtl2831_rd_regs(d, IR_RX_BUF, buf, len);
1253 if (ret)
1254 goto err;
1297 1255
1298 /* TODO: pass raw IR to Kernel IR decoder */ 1256 /* let hw receive new code */
1257 for (i = 0; i < ARRAY_SIZE(refresh_tab); i++) {
1258 ret = rtl28xx_wr_reg_mask(d, refresh_tab[i].reg,
1259 refresh_tab[i].val, refresh_tab[i].mask);
1260 if (ret)
1261 goto err;
1262 }
1299 1263
1300 ret = rtl28xx_wr_reg(d, IR_RX_IF, 0x03); 1264 /* pass data to Kernel IR decoder */
1301 ret = rtl28xx_wr_reg(d, IR_RX_BUF_CTRL, 0x80); 1265 init_ir_raw_event(&ev);
1302 ret = rtl28xx_wr_reg(d, IR_RX_CTRL, 0x80);
1303 1266
1267 for (i = 0; i < len; i++) {
1268 ev.pulse = buf[i] >> 7;
1269 ev.duration = 50800 * (buf[i] & 0x7f);
1270 ir_raw_event_store_with_filter(d->rc_dev, &ev);
1271 }
1272
1273 /* 'flush' ir_raw_event_store_with_filter() */
1274 ir_raw_event_set_idle(d->rc_dev, true);
1275 ir_raw_event_handle(d->rc_dev);
1304exit: 1276exit:
1305 return ret; 1277 return ret;
1306err: 1278err:
@@ -1311,15 +1283,19 @@ err:
1311static int rtl2832u_get_rc_config(struct dvb_usb_device *d, 1283static int rtl2832u_get_rc_config(struct dvb_usb_device *d,
1312 struct dvb_usb_rc *rc) 1284 struct dvb_usb_rc *rc)
1313{ 1285{
1314 rc->map_name = RC_MAP_EMPTY; 1286 /* load empty to enable rc */
1315 rc->allowed_protos = RC_BIT_NEC; 1287 if (!rc->map_name)
1288 rc->map_name = RC_MAP_EMPTY;
1289 rc->allowed_protos = RC_BIT_ALL;
1290 rc->driver_type = RC_DRIVER_IR_RAW;
1316 rc->query = rtl2832u_rc_query; 1291 rc->query = rtl2832u_rc_query;
1317 rc->interval = 400; 1292 rc->interval = 400;
1318 1293
1319 return 0; 1294 return 0;
1320} 1295}
1321#else 1296#else
1322 #define rtl2832u_get_rc_config NULL 1297#define rtl2831u_get_rc_config NULL
1298#define rtl2832u_get_rc_config NULL
1323#endif 1299#endif
1324 1300
1325static const struct dvb_usb_device_properties rtl2831u_props = { 1301static const struct dvb_usb_device_properties rtl2831u_props = {
@@ -1379,7 +1355,7 @@ static const struct usb_device_id rtl28xxu_id_table[] = {
1379 { DVB_USB_DEVICE(USB_VID_REALTEK, 0x2838, 1355 { DVB_USB_DEVICE(USB_VID_REALTEK, 0x2838,
1380 &rtl2832u_props, "Realtek RTL2832U reference design", NULL) }, 1356 &rtl2832u_props, "Realtek RTL2832U reference design", NULL) },
1381 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK_BLACK_REV1, 1357 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK_BLACK_REV1,
1382 &rtl2832u_props, "TerraTec Cinergy T Stick Black", NULL) }, 1358 &rtl2832u_props, "TerraTec Cinergy T Stick Black", RC_MAP_TERRATEC_SLIM) },
1383 { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_DELOCK_USB2_DVBT, 1359 { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_DELOCK_USB2_DVBT,
1384 &rtl2832u_props, "G-Tek Electronics Group Lifeview LV5TDLX DVB-T", NULL) }, 1360 &rtl2832u_props, "G-Tek Electronics Group Lifeview LV5TDLX DVB-T", NULL) },
1385 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK, 1361 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK,
@@ -1403,11 +1379,15 @@ static const struct usb_device_id rtl28xxu_id_table[] = {
1403 { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd393, 1379 { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd393,
1404 &rtl2832u_props, "GIGABYTE U7300", NULL) }, 1380 &rtl2832u_props, "GIGABYTE U7300", NULL) },
1405 { DVB_USB_DEVICE(USB_VID_DEXATEK, 0x1104, 1381 { DVB_USB_DEVICE(USB_VID_DEXATEK, 0x1104,
1406 &rtl2832u_props, "Digivox Micro Hd", NULL) }, 1382 &rtl2832u_props, "MSI DIGIVOX Micro HD", NULL) },
1407 { DVB_USB_DEVICE(USB_VID_COMPRO, 0x0620, 1383 { DVB_USB_DEVICE(USB_VID_COMPRO, 0x0620,
1408 &rtl2832u_props, "Compro VideoMate U620F", NULL) }, 1384 &rtl2832u_props, "Compro VideoMate U620F", NULL) },
1409 { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd394, 1385 { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd394,
1410 &rtl2832u_props, "MaxMedia HU394-T", NULL) }, 1386 &rtl2832u_props, "MaxMedia HU394-T", NULL) },
1387 { DVB_USB_DEVICE(USB_VID_LEADTEK, 0x6a03,
1388 &rtl2832u_props, "Leadtek WinFast DTV Dongle mini", NULL) },
1389 { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_CPYTO_REDI_PC50A,
1390 &rtl2832u_props, "Crypto ReDi PC 50 A", NULL) },
1411 { } 1391 { }
1412}; 1392};
1413MODULE_DEVICE_TABLE(usb, rtl28xxu_id_table); 1393MODULE_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 533a33127289..729b3540c2f9 100644
--- a/drivers/media/usb/dvb-usb-v2/rtl28xxu.h
+++ b/drivers/media/usb/dvb-usb-v2/rtl28xxu.h
@@ -97,6 +97,12 @@ struct rtl28xxu_reg_val {
97 u8 val; 97 u8 val;
98}; 98};
99 99
100struct rtl28xxu_reg_val_mask {
101 u16 reg;
102 u8 val;
103 u8 mask;
104};
105
100/* 106/*
101 * memory map 107 * memory map
102 * 108 *
diff --git a/drivers/media/usb/dvb-usb/az6027.c b/drivers/media/usb/dvb-usb/az6027.c
index 91e0119e8a87..ea2d5ee86576 100644
--- a/drivers/media/usb/dvb-usb/az6027.c
+++ b/drivers/media/usb/dvb-usb/az6027.c
@@ -264,7 +264,7 @@ struct stb0899_config az6027_stb0899_config = {
264 .demod_address = 0xd0, /* 0x68, 0xd0 >> 1 */ 264 .demod_address = 0xd0, /* 0x68, 0xd0 >> 1 */
265 265
266 .xtal_freq = 27000000, 266 .xtal_freq = 27000000,
267 .inversion = IQ_SWAP_ON, /* 1 */ 267 .inversion = IQ_SWAP_ON,
268 268
269 .lo_clk = 76500000, 269 .lo_clk = 76500000,
270 .hi_clk = 99000000, 270 .hi_clk = 99000000,
diff --git a/drivers/media/usb/dvb-usb/pctv452e.c b/drivers/media/usb/dvb-usb/pctv452e.c
index d1ddfa13de86..449a99605a87 100644
--- a/drivers/media/usb/dvb-usb/pctv452e.c
+++ b/drivers/media/usb/dvb-usb/pctv452e.c
@@ -828,7 +828,7 @@ static struct stb0899_config stb0899_config = {
828 .block_sync_mode = STB0899_SYNC_FORCED, /* ? */ 828 .block_sync_mode = STB0899_SYNC_FORCED, /* ? */
829 829
830 .xtal_freq = 27000000, /* Assume Hz ? */ 830 .xtal_freq = 27000000, /* Assume Hz ? */
831 .inversion = IQ_SWAP_ON, /* ? */ 831 .inversion = IQ_SWAP_ON,
832 832
833 .lo_clk = 76500000, 833 .lo_clk = 76500000,
834 .hi_clk = 99000000, 834 .hi_clk = 99000000,
diff --git a/drivers/media/usb/em28xx/em28xx-cards.c b/drivers/media/usb/em28xx/em28xx-cards.c
index 83bfbe4c980f..dc65742c4bbc 100644
--- a/drivers/media/usb/em28xx/em28xx-cards.c
+++ b/drivers/media/usb/em28xx/em28xx-cards.c
@@ -37,7 +37,6 @@
37#include <media/i2c-addr.h> 37#include <media/i2c-addr.h>
38#include <media/tveeprom.h> 38#include <media/tveeprom.h>
39#include <media/v4l2-common.h> 39#include <media/v4l2-common.h>
40#include <media/v4l2-chip-ident.h>
41 40
42#include "em28xx.h" 41#include "em28xx.h"
43 42
@@ -83,26 +82,26 @@ static void em28xx_pre_card_setup(struct em28xx *dev);
83 82
84/* Reset for the most [analog] boards */ 83/* Reset for the most [analog] boards */
85static struct em28xx_reg_seq default_analog[] = { 84static struct em28xx_reg_seq default_analog[] = {
86 {EM28XX_R08_GPIO, 0x6d, ~EM_GPIO_4, 10}, 85 {EM2820_R08_GPIO_CTRL, 0x6d, ~EM_GPIO_4, 10},
87 { -1, -1, -1, -1}, 86 { -1, -1, -1, -1},
88}; 87};
89 88
90/* Reset for the most [digital] boards */ 89/* Reset for the most [digital] boards */
91static struct em28xx_reg_seq default_digital[] = { 90static struct em28xx_reg_seq default_digital[] = {
92 {EM28XX_R08_GPIO, 0x6e, ~EM_GPIO_4, 10}, 91 {EM2820_R08_GPIO_CTRL, 0x6e, ~EM_GPIO_4, 10},
93 { -1, -1, -1, -1}, 92 { -1, -1, -1, -1},
94}; 93};
95 94
96/* Board Hauppauge WinTV HVR 900 analog */ 95/* Board Hauppauge WinTV HVR 900 analog */
97static struct em28xx_reg_seq hauppauge_wintv_hvr_900_analog[] = { 96static struct em28xx_reg_seq hauppauge_wintv_hvr_900_analog[] = {
98 {EM28XX_R08_GPIO, 0x2d, ~EM_GPIO_4, 10}, 97 {EM2820_R08_GPIO_CTRL, 0x2d, ~EM_GPIO_4, 10},
99 {0x05, 0xff, 0x10, 10}, 98 {0x05, 0xff, 0x10, 10},
100 { -1, -1, -1, -1}, 99 { -1, -1, -1, -1},
101}; 100};
102 101
103/* Board Hauppauge WinTV HVR 900 digital */ 102/* Board Hauppauge WinTV HVR 900 digital */
104static struct em28xx_reg_seq hauppauge_wintv_hvr_900_digital[] = { 103static struct em28xx_reg_seq hauppauge_wintv_hvr_900_digital[] = {
105 {EM28XX_R08_GPIO, 0x2e, ~EM_GPIO_4, 10}, 104 {EM2820_R08_GPIO_CTRL, 0x2e, ~EM_GPIO_4, 10},
106 {EM2880_R04_GPO, 0x04, 0x0f, 10}, 105 {EM2880_R04_GPO, 0x04, 0x0f, 10},
107 {EM2880_R04_GPO, 0x0c, 0x0f, 10}, 106 {EM2880_R04_GPO, 0x0c, 0x0f, 10},
108 { -1, -1, -1, -1}, 107 { -1, -1, -1, -1},
@@ -110,14 +109,14 @@ static struct em28xx_reg_seq hauppauge_wintv_hvr_900_digital[] = {
110 109
111/* Board Hauppauge WinTV HVR 900 (R2) digital */ 110/* Board Hauppauge WinTV HVR 900 (R2) digital */
112static struct em28xx_reg_seq hauppauge_wintv_hvr_900R2_digital[] = { 111static struct em28xx_reg_seq hauppauge_wintv_hvr_900R2_digital[] = {
113 {EM28XX_R08_GPIO, 0x2e, ~EM_GPIO_4, 10}, 112 {EM2820_R08_GPIO_CTRL, 0x2e, ~EM_GPIO_4, 10},
114 {EM2880_R04_GPO, 0x0c, 0x0f, 10}, 113 {EM2880_R04_GPO, 0x0c, 0x0f, 10},
115 { -1, -1, -1, -1}, 114 { -1, -1, -1, -1},
116}; 115};
117 116
118/* Boards - EM2880 MSI DIGIVOX AD and EM2880_BOARD_MSI_DIGIVOX_AD_II */ 117/* Boards - EM2880 MSI DIGIVOX AD and EM2880_BOARD_MSI_DIGIVOX_AD_II */
119static struct em28xx_reg_seq em2880_msi_digivox_ad_analog[] = { 118static struct em28xx_reg_seq em2880_msi_digivox_ad_analog[] = {
120 {EM28XX_R08_GPIO, 0x69, ~EM_GPIO_4, 10}, 119 {EM2820_R08_GPIO_CTRL, 0x69, ~EM_GPIO_4, 10},
121 { -1, -1, -1, -1}, 120 { -1, -1, -1, -1},
122}; 121};
123 122
@@ -128,11 +127,11 @@ static struct em28xx_reg_seq em2880_msi_digivox_ad_analog[] = {
128 127
129/* Board - EM2882 Kworld 315U digital */ 128/* Board - EM2882 Kworld 315U digital */
130static struct em28xx_reg_seq em2882_kworld_315u_digital[] = { 129static struct em28xx_reg_seq em2882_kworld_315u_digital[] = {
131 {EM28XX_R08_GPIO, 0xff, 0xff, 10}, 130 {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
132 {EM28XX_R08_GPIO, 0xfe, 0xff, 10}, 131 {EM2820_R08_GPIO_CTRL, 0xfe, 0xff, 10},
133 {EM2880_R04_GPO, 0x04, 0xff, 10}, 132 {EM2880_R04_GPO, 0x04, 0xff, 10},
134 {EM2880_R04_GPO, 0x0c, 0xff, 10}, 133 {EM2880_R04_GPO, 0x0c, 0xff, 10},
135 {EM28XX_R08_GPIO, 0x7e, 0xff, 10}, 134 {EM2820_R08_GPIO_CTRL, 0x7e, 0xff, 10},
136 { -1, -1, -1, -1}, 135 { -1, -1, -1, -1},
137}; 136};
138 137
@@ -145,13 +144,13 @@ static struct em28xx_reg_seq em2882_kworld_315u_tuner_gpio[] = {
145}; 144};
146 145
147static struct em28xx_reg_seq kworld_330u_analog[] = { 146static struct em28xx_reg_seq kworld_330u_analog[] = {
148 {EM28XX_R08_GPIO, 0x6d, ~EM_GPIO_4, 10}, 147 {EM2820_R08_GPIO_CTRL, 0x6d, ~EM_GPIO_4, 10},
149 {EM2880_R04_GPO, 0x00, 0xff, 10}, 148 {EM2880_R04_GPO, 0x00, 0xff, 10},
150 { -1, -1, -1, -1}, 149 { -1, -1, -1, -1},
151}; 150};
152 151
153static struct em28xx_reg_seq kworld_330u_digital[] = { 152static struct em28xx_reg_seq kworld_330u_digital[] = {
154 {EM28XX_R08_GPIO, 0x6e, ~EM_GPIO_4, 10}, 153 {EM2820_R08_GPIO_CTRL, 0x6e, ~EM_GPIO_4, 10},
155 {EM2880_R04_GPO, 0x08, 0xff, 10}, 154 {EM2880_R04_GPO, 0x08, 0xff, 10},
156 { -1, -1, -1, -1}, 155 { -1, -1, -1, -1},
157}; 156};
@@ -163,12 +162,12 @@ static struct em28xx_reg_seq kworld_330u_digital[] = {
163 GOP3 - s5h1409 reset 162 GOP3 - s5h1409 reset
164 */ 163 */
165static struct em28xx_reg_seq evga_indtube_analog[] = { 164static struct em28xx_reg_seq evga_indtube_analog[] = {
166 {EM28XX_R08_GPIO, 0x79, 0xff, 60}, 165 {EM2820_R08_GPIO_CTRL, 0x79, 0xff, 60},
167 { -1, -1, -1, -1}, 166 { -1, -1, -1, -1},
168}; 167};
169 168
170static struct em28xx_reg_seq evga_indtube_digital[] = { 169static struct em28xx_reg_seq evga_indtube_digital[] = {
171 {EM28XX_R08_GPIO, 0x7a, 0xff, 1}, 170 {EM2820_R08_GPIO_CTRL, 0x7a, 0xff, 1},
172 {EM2880_R04_GPO, 0x04, 0xff, 10}, 171 {EM2880_R04_GPO, 0x04, 0xff, 10},
173 {EM2880_R04_GPO, 0x0c, 0xff, 1}, 172 {EM2880_R04_GPO, 0x0c, 0xff, 1},
174 { -1, -1, -1, -1}, 173 { -1, -1, -1, -1},
@@ -186,31 +185,31 @@ static struct em28xx_reg_seq evga_indtube_digital[] = {
186 * EM_GPIO_7 - currently unknown 185 * EM_GPIO_7 - currently unknown
187 */ 186 */
188static struct em28xx_reg_seq kworld_a340_digital[] = { 187static struct em28xx_reg_seq kworld_a340_digital[] = {
189 {EM28XX_R08_GPIO, 0x6d, ~EM_GPIO_4, 10}, 188 {EM2820_R08_GPIO_CTRL, 0x6d, ~EM_GPIO_4, 10},
190 { -1, -1, -1, -1}, 189 { -1, -1, -1, -1},
191}; 190};
192 191
193/* Pinnacle Hybrid Pro eb1a:2881 */ 192/* Pinnacle Hybrid Pro eb1a:2881 */
194static struct em28xx_reg_seq pinnacle_hybrid_pro_analog[] = { 193static struct em28xx_reg_seq pinnacle_hybrid_pro_analog[] = {
195 {EM28XX_R08_GPIO, 0xfd, ~EM_GPIO_4, 10}, 194 {EM2820_R08_GPIO_CTRL, 0xfd, ~EM_GPIO_4, 10},
196 { -1, -1, -1, -1}, 195 { -1, -1, -1, -1},
197}; 196};
198 197
199static struct em28xx_reg_seq pinnacle_hybrid_pro_digital[] = { 198static struct em28xx_reg_seq pinnacle_hybrid_pro_digital[] = {
200 {EM28XX_R08_GPIO, 0x6e, ~EM_GPIO_4, 10}, 199 {EM2820_R08_GPIO_CTRL, 0x6e, ~EM_GPIO_4, 10},
201 {EM2880_R04_GPO, 0x04, 0xff, 100},/* zl10353 reset */ 200 {EM2880_R04_GPO, 0x04, 0xff, 100},/* zl10353 reset */
202 {EM2880_R04_GPO, 0x0c, 0xff, 1}, 201 {EM2880_R04_GPO, 0x0c, 0xff, 1},
203 { -1, -1, -1, -1}, 202 { -1, -1, -1, -1},
204}; 203};
205 204
206static struct em28xx_reg_seq terratec_cinergy_USB_XS_FR_analog[] = { 205static struct em28xx_reg_seq terratec_cinergy_USB_XS_FR_analog[] = {
207 {EM28XX_R08_GPIO, 0x6d, ~EM_GPIO_4, 10}, 206 {EM2820_R08_GPIO_CTRL, 0x6d, ~EM_GPIO_4, 10},
208 {EM2880_R04_GPO, 0x00, 0xff, 10}, 207 {EM2880_R04_GPO, 0x00, 0xff, 10},
209 { -1, -1, -1, -1}, 208 { -1, -1, -1, -1},
210}; 209};
211 210
212static struct em28xx_reg_seq terratec_cinergy_USB_XS_FR_digital[] = { 211static struct em28xx_reg_seq terratec_cinergy_USB_XS_FR_digital[] = {
213 {EM28XX_R08_GPIO, 0x6e, ~EM_GPIO_4, 10}, 212 {EM2820_R08_GPIO_CTRL, 0x6e, ~EM_GPIO_4, 10},
214 {EM2880_R04_GPO, 0x08, 0xff, 10}, 213 {EM2880_R04_GPO, 0x08, 0xff, 10},
215 { -1, -1, -1, -1}, 214 { -1, -1, -1, -1},
216}; 215};
@@ -219,66 +218,66 @@ static struct em28xx_reg_seq terratec_cinergy_USB_XS_FR_digital[] = {
219 GPIO4 - CU1216L NIM 218 GPIO4 - CU1216L NIM
220 Other GPIOs seems to be don't care. */ 219 Other GPIOs seems to be don't care. */
221static struct em28xx_reg_seq reddo_dvb_c_usb_box[] = { 220static struct em28xx_reg_seq reddo_dvb_c_usb_box[] = {
222 {EM28XX_R08_GPIO, 0xfe, 0xff, 10}, 221 {EM2820_R08_GPIO_CTRL, 0xfe, 0xff, 10},
223 {EM28XX_R08_GPIO, 0xde, 0xff, 10}, 222 {EM2820_R08_GPIO_CTRL, 0xde, 0xff, 10},
224 {EM28XX_R08_GPIO, 0xfe, 0xff, 10}, 223 {EM2820_R08_GPIO_CTRL, 0xfe, 0xff, 10},
225 {EM28XX_R08_GPIO, 0xff, 0xff, 10}, 224 {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
226 {EM28XX_R08_GPIO, 0x7f, 0xff, 10}, 225 {EM2820_R08_GPIO_CTRL, 0x7f, 0xff, 10},
227 {EM28XX_R08_GPIO, 0x6f, 0xff, 10}, 226 {EM2820_R08_GPIO_CTRL, 0x6f, 0xff, 10},
228 {EM28XX_R08_GPIO, 0xff, 0xff, 10}, 227 {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
229 {-1, -1, -1, -1}, 228 {-1, -1, -1, -1},
230}; 229};
231 230
232/* Callback for the most boards */ 231/* Callback for the most boards */
233static struct em28xx_reg_seq default_tuner_gpio[] = { 232static struct em28xx_reg_seq default_tuner_gpio[] = {
234 {EM28XX_R08_GPIO, EM_GPIO_4, EM_GPIO_4, 10}, 233 {EM2820_R08_GPIO_CTRL, EM_GPIO_4, EM_GPIO_4, 10},
235 {EM28XX_R08_GPIO, 0, EM_GPIO_4, 10}, 234 {EM2820_R08_GPIO_CTRL, 0, EM_GPIO_4, 10},
236 {EM28XX_R08_GPIO, EM_GPIO_4, EM_GPIO_4, 10}, 235 {EM2820_R08_GPIO_CTRL, EM_GPIO_4, EM_GPIO_4, 10},
237 { -1, -1, -1, -1}, 236 { -1, -1, -1, -1},
238}; 237};
239 238
240/* Mute/unmute */ 239/* Mute/unmute */
241static struct em28xx_reg_seq compro_unmute_tv_gpio[] = { 240static struct em28xx_reg_seq compro_unmute_tv_gpio[] = {
242 {EM28XX_R08_GPIO, 5, 7, 10}, 241 {EM2820_R08_GPIO_CTRL, 5, 7, 10},
243 { -1, -1, -1, -1}, 242 { -1, -1, -1, -1},
244}; 243};
245 244
246static struct em28xx_reg_seq compro_unmute_svid_gpio[] = { 245static struct em28xx_reg_seq compro_unmute_svid_gpio[] = {
247 {EM28XX_R08_GPIO, 4, 7, 10}, 246 {EM2820_R08_GPIO_CTRL, 4, 7, 10},
248 { -1, -1, -1, -1}, 247 { -1, -1, -1, -1},
249}; 248};
250 249
251static struct em28xx_reg_seq compro_mute_gpio[] = { 250static struct em28xx_reg_seq compro_mute_gpio[] = {
252 {EM28XX_R08_GPIO, 6, 7, 10}, 251 {EM2820_R08_GPIO_CTRL, 6, 7, 10},
253 { -1, -1, -1, -1}, 252 { -1, -1, -1, -1},
254}; 253};
255 254
256/* Terratec AV350 */ 255/* Terratec AV350 */
257static struct em28xx_reg_seq terratec_av350_mute_gpio[] = { 256static struct em28xx_reg_seq terratec_av350_mute_gpio[] = {
258 {EM28XX_R08_GPIO, 0xff, 0x7f, 10}, 257 {EM2820_R08_GPIO_CTRL, 0xff, 0x7f, 10},
259 { -1, -1, -1, -1}, 258 { -1, -1, -1, -1},
260}; 259};
261 260
262static struct em28xx_reg_seq terratec_av350_unmute_gpio[] = { 261static struct em28xx_reg_seq terratec_av350_unmute_gpio[] = {
263 {EM28XX_R08_GPIO, 0xff, 0xff, 10}, 262 {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
264 { -1, -1, -1, -1}, 263 { -1, -1, -1, -1},
265}; 264};
266 265
267static struct em28xx_reg_seq silvercrest_reg_seq[] = { 266static struct em28xx_reg_seq silvercrest_reg_seq[] = {
268 {EM28XX_R08_GPIO, 0xff, 0xff, 10}, 267 {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
269 {EM28XX_R08_GPIO, 0x01, 0xf7, 10}, 268 {EM2820_R08_GPIO_CTRL, 0x01, 0xf7, 10},
270 { -1, -1, -1, -1}, 269 { -1, -1, -1, -1},
271}; 270};
272 271
273static struct em28xx_reg_seq vc211a_enable[] = { 272static struct em28xx_reg_seq vc211a_enable[] = {
274 {EM28XX_R08_GPIO, 0xff, 0x07, 10}, 273 {EM2820_R08_GPIO_CTRL, 0xff, 0x07, 10},
275 {EM28XX_R08_GPIO, 0xff, 0x0f, 10}, 274 {EM2820_R08_GPIO_CTRL, 0xff, 0x0f, 10},
276 {EM28XX_R08_GPIO, 0xff, 0x0b, 10}, 275 {EM2820_R08_GPIO_CTRL, 0xff, 0x0b, 10},
277 { -1, -1, -1, -1}, 276 { -1, -1, -1, -1},
278}; 277};
279 278
280static struct em28xx_reg_seq dikom_dk300_digital[] = { 279static struct em28xx_reg_seq dikom_dk300_digital[] = {
281 {EM28XX_R08_GPIO, 0x6e, ~EM_GPIO_4, 10}, 280 {EM2820_R08_GPIO_CTRL, 0x6e, ~EM_GPIO_4, 10},
282 {EM2880_R04_GPO, 0x08, 0xff, 10}, 281 {EM2880_R04_GPO, 0x08, 0xff, 10},
283 { -1, -1, -1, -1}, 282 { -1, -1, -1, -1},
284}; 283};
@@ -286,14 +285,14 @@ static struct em28xx_reg_seq dikom_dk300_digital[] = {
286 285
287/* Reset for the most [digital] boards */ 286/* Reset for the most [digital] boards */
288static struct em28xx_reg_seq leadership_digital[] = { 287static struct em28xx_reg_seq leadership_digital[] = {
289 {EM2874_R80_GPIO, 0x70, 0xff, 10}, 288 {EM2874_R80_GPIO_P0_CTRL, 0x70, 0xff, 10},
290 { -1, -1, -1, -1}, 289 { -1, -1, -1, -1},
291}; 290};
292 291
293static struct em28xx_reg_seq leadership_reset[] = { 292static struct em28xx_reg_seq leadership_reset[] = {
294 {EM2874_R80_GPIO, 0xf0, 0xff, 10}, 293 {EM2874_R80_GPIO_P0_CTRL, 0xf0, 0xff, 10},
295 {EM2874_R80_GPIO, 0xb0, 0xff, 10}, 294 {EM2874_R80_GPIO_P0_CTRL, 0xb0, 0xff, 10},
296 {EM2874_R80_GPIO, 0xf0, 0xff, 10}, 295 {EM2874_R80_GPIO_P0_CTRL, 0xf0, 0xff, 10},
297 { -1, -1, -1, -1}, 296 { -1, -1, -1, -1},
298}; 297};
299 298
@@ -302,25 +301,25 @@ static struct em28xx_reg_seq leadership_reset[] = {
302 * GPIO_7 - LED 301 * GPIO_7 - LED
303 */ 302 */
304static struct em28xx_reg_seq pctv_290e[] = { 303static struct em28xx_reg_seq pctv_290e[] = {
305 {EM2874_R80_GPIO, 0x00, 0xff, 80}, 304 {EM2874_R80_GPIO_P0_CTRL, 0x00, 0xff, 80},
306 {EM2874_R80_GPIO, 0x40, 0xff, 80}, /* GPIO_6 = 1 */ 305 {EM2874_R80_GPIO_P0_CTRL, 0x40, 0xff, 80}, /* GPIO_6 = 1 */
307 {EM2874_R80_GPIO, 0xc0, 0xff, 80}, /* GPIO_7 = 1 */ 306 {EM2874_R80_GPIO_P0_CTRL, 0xc0, 0xff, 80}, /* GPIO_7 = 1 */
308 {-1, -1, -1, -1}, 307 {-1, -1, -1, -1},
309}; 308};
310 309
311#if 0 310#if 0
312static struct em28xx_reg_seq terratec_h5_gpio[] = { 311static struct em28xx_reg_seq terratec_h5_gpio[] = {
313 {EM28XX_R08_GPIO, 0xff, 0xff, 10}, 312 {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
314 {EM2874_R80_GPIO, 0xf6, 0xff, 100}, 313 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
315 {EM2874_R80_GPIO, 0xf2, 0xff, 50}, 314 {EM2874_R80_GPIO_P0_CTRL, 0xf2, 0xff, 50},
316 {EM2874_R80_GPIO, 0xf6, 0xff, 50}, 315 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 50},
317 { -1, -1, -1, -1}, 316 { -1, -1, -1, -1},
318}; 317};
319 318
320static struct em28xx_reg_seq terratec_h5_digital[] = { 319static struct em28xx_reg_seq terratec_h5_digital[] = {
321 {EM2874_R80_GPIO, 0xf6, 0xff, 10}, 320 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 10},
322 {EM2874_R80_GPIO, 0xe6, 0xff, 100}, 321 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
323 {EM2874_R80_GPIO, 0xa6, 0xff, 10}, 322 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 10},
324 { -1, -1, -1, -1}, 323 { -1, -1, -1, -1},
325}; 324};
326#endif 325#endif
@@ -336,51 +335,52 @@ static struct em28xx_reg_seq terratec_h5_digital[] = {
336 * GPIO_7 - LED (green LED) 335 * GPIO_7 - LED (green LED)
337 */ 336 */
338static struct em28xx_reg_seq pctv_460e[] = { 337static struct em28xx_reg_seq pctv_460e[] = {
339 {EM2874_R80_GPIO, 0x01, 0xff, 50}, 338 {EM2874_R80_GPIO_P0_CTRL, 0x01, 0xff, 50},
340 {0x0d, 0xff, 0xff, 50}, 339 {0x0d, 0xff, 0xff, 50},
341 {EM2874_R80_GPIO, 0x41, 0xff, 50}, /* GPIO_6=1 */ 340 {EM2874_R80_GPIO_P0_CTRL, 0x41, 0xff, 50}, /* GPIO_6=1 */
342 {0x0d, 0x42, 0xff, 50}, 341 {0x0d, 0x42, 0xff, 50},
343 {EM2874_R80_GPIO, 0x61, 0xff, 50}, /* GPIO_5=1 */ 342 {EM2874_R80_GPIO_P0_CTRL, 0x61, 0xff, 50}, /* GPIO_5=1 */
344 { -1, -1, -1, -1}, 343 { -1, -1, -1, -1},
345}; 344};
346 345
347static struct em28xx_reg_seq c3tech_digital_duo_digital[] = { 346static struct em28xx_reg_seq c3tech_digital_duo_digital[] = {
348 {EM2874_R80_GPIO, 0xff, 0xff, 10}, 347 {EM2874_R80_GPIO_P0_CTRL, 0xff, 0xff, 10},
349 {EM2874_R80_GPIO, 0xfd, 0xff, 10}, /* xc5000 reset */ 348 {EM2874_R80_GPIO_P0_CTRL, 0xfd, 0xff, 10}, /* xc5000 reset */
350 {EM2874_R80_GPIO, 0xf9, 0xff, 35}, 349 {EM2874_R80_GPIO_P0_CTRL, 0xf9, 0xff, 35},
351 {EM2874_R80_GPIO, 0xfd, 0xff, 10}, 350 {EM2874_R80_GPIO_P0_CTRL, 0xfd, 0xff, 10},
352 {EM2874_R80_GPIO, 0xff, 0xff, 10}, 351 {EM2874_R80_GPIO_P0_CTRL, 0xff, 0xff, 10},
353 {EM2874_R80_GPIO, 0xfe, 0xff, 10}, 352 {EM2874_R80_GPIO_P0_CTRL, 0xfe, 0xff, 10},
354 {EM2874_R80_GPIO, 0xbe, 0xff, 10}, 353 {EM2874_R80_GPIO_P0_CTRL, 0xbe, 0xff, 10},
355 {EM2874_R80_GPIO, 0xfe, 0xff, 20}, 354 {EM2874_R80_GPIO_P0_CTRL, 0xfe, 0xff, 20},
356 { -1, -1, -1, -1}, 355 { -1, -1, -1, -1},
357}; 356};
358 357
359#if 0 358#if 0
360static struct em28xx_reg_seq hauppauge_930c_gpio[] = { 359static struct em28xx_reg_seq hauppauge_930c_gpio[] = {
361 {EM2874_R80_GPIO, 0x6f, 0xff, 10}, 360 {EM2874_R80_GPIO_P0_CTRL, 0x6f, 0xff, 10},
362 {EM2874_R80_GPIO, 0x4f, 0xff, 10}, /* xc5000 reset */ 361 {EM2874_R80_GPIO_P0_CTRL, 0x4f, 0xff, 10}, /* xc5000 reset */
363 {EM2874_R80_GPIO, 0x6f, 0xff, 10}, 362 {EM2874_R80_GPIO_P0_CTRL, 0x6f, 0xff, 10},
364 {EM2874_R80_GPIO, 0x4f, 0xff, 10}, 363 {EM2874_R80_GPIO_P0_CTRL, 0x4f, 0xff, 10},
365 { -1, -1, -1, -1}, 364 { -1, -1, -1, -1},
366}; 365};
367 366
368static struct em28xx_reg_seq hauppauge_930c_digital[] = { 367static struct em28xx_reg_seq hauppauge_930c_digital[] = {
369 {EM2874_R80_GPIO, 0xf6, 0xff, 10}, 368 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 10},
370 {EM2874_R80_GPIO, 0xe6, 0xff, 100}, 369 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
371 {EM2874_R80_GPIO, 0xa6, 0xff, 10}, 370 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 10},
372 { -1, -1, -1, -1}, 371 { -1, -1, -1, -1},
373}; 372};
374#endif 373#endif
375 374
376/* 1b80:e425 MaxMedia UB425-TC 375/* 1b80:e425 MaxMedia UB425-TC
376 * 1b80:e1cc Delock 61959
377 * GPIO_6 - demod reset, 0=active 377 * GPIO_6 - demod reset, 0=active
378 * GPIO_7 - LED, 0=active 378 * GPIO_7 - LED, 0=active
379 */ 379 */
380static struct em28xx_reg_seq maxmedia_ub425_tc[] = { 380static struct em28xx_reg_seq maxmedia_ub425_tc[] = {
381 {EM2874_R80_GPIO, 0x83, 0xff, 100}, 381 {EM2874_R80_GPIO_P0_CTRL, 0x83, 0xff, 100},
382 {EM2874_R80_GPIO, 0xc3, 0xff, 100}, /* GPIO_6 = 1 */ 382 {EM2874_R80_GPIO_P0_CTRL, 0xc3, 0xff, 100}, /* GPIO_6 = 1 */
383 {EM2874_R80_GPIO, 0x43, 0xff, 000}, /* GPIO_7 = 0 */ 383 {EM2874_R80_GPIO_P0_CTRL, 0x43, 0xff, 000}, /* GPIO_7 = 0 */
384 {-1, -1, -1, -1}, 384 {-1, -1, -1, -1},
385}; 385};
386 386
@@ -391,9 +391,9 @@ static struct em28xx_reg_seq maxmedia_ub425_tc[] = {
391 * GPIO_7: LED, 1=active 391 * GPIO_7: LED, 1=active
392 */ 392 */
393static struct em28xx_reg_seq pctv_510e[] = { 393static struct em28xx_reg_seq pctv_510e[] = {
394 {EM2874_R80_GPIO, 0x10, 0xff, 100}, 394 {EM2874_R80_GPIO_P0_CTRL, 0x10, 0xff, 100},
395 {EM2874_R80_GPIO, 0x14, 0xff, 100}, /* GPIO_2 = 1 */ 395 {EM2874_R80_GPIO_P0_CTRL, 0x14, 0xff, 100}, /* GPIO_2 = 1 */
396 {EM2874_R80_GPIO, 0x54, 0xff, 050}, /* GPIO_6 = 1 */ 396 {EM2874_R80_GPIO_P0_CTRL, 0x54, 0xff, 050}, /* GPIO_6 = 1 */
397 { -1, -1, -1, -1}, 397 { -1, -1, -1, -1},
398}; 398};
399 399
@@ -404,10 +404,10 @@ static struct em28xx_reg_seq pctv_510e[] = {
404 * GPIO_7: LED, 1=active 404 * GPIO_7: LED, 1=active
405 */ 405 */
406static struct em28xx_reg_seq pctv_520e[] = { 406static struct em28xx_reg_seq pctv_520e[] = {
407 {EM2874_R80_GPIO, 0x10, 0xff, 100}, 407 {EM2874_R80_GPIO_P0_CTRL, 0x10, 0xff, 100},
408 {EM2874_R80_GPIO, 0x14, 0xff, 100}, /* GPIO_2 = 1 */ 408 {EM2874_R80_GPIO_P0_CTRL, 0x14, 0xff, 100}, /* GPIO_2 = 1 */
409 {EM2874_R80_GPIO, 0x54, 0xff, 050}, /* GPIO_6 = 1 */ 409 {EM2874_R80_GPIO_P0_CTRL, 0x54, 0xff, 050}, /* GPIO_6 = 1 */
410 {EM2874_R80_GPIO, 0xd4, 0xff, 000}, /* GPIO_7 = 1 */ 410 {EM2874_R80_GPIO_P0_CTRL, 0xd4, 0xff, 000}, /* GPIO_7 = 1 */
411 { -1, -1, -1, -1}, 411 { -1, -1, -1, -1},
412}; 412};
413 413
@@ -2017,6 +2017,19 @@ struct em28xx_board em28xx_boards[] = {
2017 .i2c_speed = EM28XX_I2C_CLK_WAIT_ENABLE | 2017 .i2c_speed = EM28XX_I2C_CLK_WAIT_ENABLE |
2018 EM28XX_I2C_FREQ_400_KHZ, 2018 EM28XX_I2C_FREQ_400_KHZ,
2019 }, 2019 },
2020 /* 1b80:e1cc Delock 61959
2021 * Empia EM2874B + Micronas DRX 3913KA2 + NXP TDA18271HDC2
2022 * mostly the same as MaxMedia UB-425-TC but different remote */
2023 [EM2874_BOARD_DELOCK_61959] = {
2024 .name = "Delock 61959",
2025 .tuner_type = TUNER_ABSENT,
2026 .tuner_gpio = maxmedia_ub425_tc,
2027 .has_dvb = 1,
2028 .ir_codes = RC_MAP_DELOCK_61959,
2029 .def_i2c_bus = 1,
2030 .i2c_speed = EM28XX_I2C_CLK_WAIT_ENABLE |
2031 EM28XX_I2C_FREQ_400_KHZ,
2032 },
2020}; 2033};
2021const unsigned int em28xx_bcount = ARRAY_SIZE(em28xx_boards); 2034const unsigned int em28xx_bcount = ARRAY_SIZE(em28xx_boards);
2022 2035
@@ -2178,6 +2191,8 @@ struct usb_device_id em28xx_id_table[] = {
2178 .driver_info = EM2884_BOARD_PCTV_510E }, 2191 .driver_info = EM2884_BOARD_PCTV_510E },
2179 { USB_DEVICE(0x2013, 0x0251), 2192 { USB_DEVICE(0x2013, 0x0251),
2180 .driver_info = EM2884_BOARD_PCTV_520E }, 2193 .driver_info = EM2884_BOARD_PCTV_520E },
2194 { USB_DEVICE(0x1b80, 0xe1cc),
2195 .driver_info = EM2874_BOARD_DELOCK_61959 },
2181 { }, 2196 { },
2182}; 2197};
2183MODULE_DEVICE_TABLE(usb, em28xx_id_table); 2198MODULE_DEVICE_TABLE(usb, em28xx_id_table);
@@ -2284,9 +2299,9 @@ static void em28xx_pre_card_setup(struct em28xx *dev)
2284 break; 2299 break;
2285 case EM2861_BOARD_KWORLD_PVRTV_300U: 2300 case EM2861_BOARD_KWORLD_PVRTV_300U:
2286 case EM2880_BOARD_KWORLD_DVB_305U: 2301 case EM2880_BOARD_KWORLD_DVB_305U:
2287 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0x6d); 2302 em28xx_write_reg(dev, EM2820_R08_GPIO_CTRL, 0x6d);
2288 msleep(10); 2303 msleep(10);
2289 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0x7d); 2304 em28xx_write_reg(dev, EM2820_R08_GPIO_CTRL, 0x7d);
2290 msleep(10); 2305 msleep(10);
2291 break; 2306 break;
2292 case EM2870_BOARD_COMPRO_VIDEOMATE: 2307 case EM2870_BOARD_COMPRO_VIDEOMATE:
@@ -2296,45 +2311,45 @@ static void em28xx_pre_card_setup(struct em28xx *dev)
2296 msleep(10); 2311 msleep(10);
2297 em28xx_write_reg(dev, EM2880_R04_GPO, 0x01); 2312 em28xx_write_reg(dev, EM2880_R04_GPO, 0x01);
2298 msleep(10); 2313 msleep(10);
2299 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfd); 2314 em28xx_write_reg(dev, EM2820_R08_GPIO_CTRL, 0xfd);
2300 mdelay(70); 2315 mdelay(70);
2301 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfc); 2316 em28xx_write_reg(dev, EM2820_R08_GPIO_CTRL, 0xfc);
2302 mdelay(70); 2317 mdelay(70);
2303 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xdc); 2318 em28xx_write_reg(dev, EM2820_R08_GPIO_CTRL, 0xdc);
2304 mdelay(70); 2319 mdelay(70);
2305 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfc); 2320 em28xx_write_reg(dev, EM2820_R08_GPIO_CTRL, 0xfc);
2306 mdelay(70); 2321 mdelay(70);
2307 break; 2322 break;
2308 case EM2870_BOARD_TERRATEC_XS_MT2060: 2323 case EM2870_BOARD_TERRATEC_XS_MT2060:
2309 /* this device needs some gpio writes to get the DVB-T 2324 /* this device needs some gpio writes to get the DVB-T
2310 demod work */ 2325 demod work */
2311 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfe); 2326 em28xx_write_reg(dev, EM2820_R08_GPIO_CTRL, 0xfe);
2312 mdelay(70); 2327 mdelay(70);
2313 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xde); 2328 em28xx_write_reg(dev, EM2820_R08_GPIO_CTRL, 0xde);
2314 mdelay(70); 2329 mdelay(70);
2315 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfe); 2330 em28xx_write_reg(dev, EM2820_R08_GPIO_CTRL, 0xfe);
2316 mdelay(70); 2331 mdelay(70);
2317 break; 2332 break;
2318 case EM2870_BOARD_PINNACLE_PCTV_DVB: 2333 case EM2870_BOARD_PINNACLE_PCTV_DVB:
2319 /* this device needs some gpio writes to get the 2334 /* this device needs some gpio writes to get the
2320 DVB-T demod work */ 2335 DVB-T demod work */
2321 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfe); 2336 em28xx_write_reg(dev, EM2820_R08_GPIO_CTRL, 0xfe);
2322 mdelay(70); 2337 mdelay(70);
2323 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xde); 2338 em28xx_write_reg(dev, EM2820_R08_GPIO_CTRL, 0xde);
2324 mdelay(70); 2339 mdelay(70);
2325 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfe); 2340 em28xx_write_reg(dev, EM2820_R08_GPIO_CTRL, 0xfe);
2326 mdelay(70); 2341 mdelay(70);
2327 break; 2342 break;
2328 case EM2820_BOARD_GADMEI_UTV310: 2343 case EM2820_BOARD_GADMEI_UTV310:
2329 case EM2820_BOARD_MSI_VOX_USB_2: 2344 case EM2820_BOARD_MSI_VOX_USB_2:
2330 /* enables audio for that devices */ 2345 /* enables audio for that devices */
2331 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfd); 2346 em28xx_write_reg(dev, EM2820_R08_GPIO_CTRL, 0xfd);
2332 break; 2347 break;
2333 2348
2334 case EM2882_BOARD_KWORLD_ATSC_315U: 2349 case EM2882_BOARD_KWORLD_ATSC_315U:
2335 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xff); 2350 em28xx_write_reg(dev, EM2820_R08_GPIO_CTRL, 0xff);
2336 msleep(10); 2351 msleep(10);
2337 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfe); 2352 em28xx_write_reg(dev, EM2820_R08_GPIO_CTRL, 0xfe);
2338 msleep(10); 2353 msleep(10);
2339 em28xx_write_reg(dev, EM2880_R04_GPO, 0x00); 2354 em28xx_write_reg(dev, EM2880_R04_GPO, 0x00);
2340 msleep(10); 2355 msleep(10);
@@ -2360,13 +2375,13 @@ static void em28xx_pre_card_setup(struct em28xx *dev)
2360 break; 2375 break;
2361 2376
2362 case EM2820_BOARD_IODATA_GVMVP_SZ: 2377 case EM2820_BOARD_IODATA_GVMVP_SZ:
2363 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xff); 2378 em28xx_write_reg(dev, EM2820_R08_GPIO_CTRL, 0xff);
2364 msleep(70); 2379 msleep(70);
2365 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xf7); 2380 em28xx_write_reg(dev, EM2820_R08_GPIO_CTRL, 0xf7);
2366 msleep(10); 2381 msleep(10);
2367 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfe); 2382 em28xx_write_reg(dev, EM2820_R08_GPIO_CTRL, 0xfe);
2368 msleep(70); 2383 msleep(70);
2369 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfd); 2384 em28xx_write_reg(dev, EM2820_R08_GPIO_CTRL, 0xfd);
2370 msleep(70); 2385 msleep(70);
2371 break; 2386 break;
2372 } 2387 }
@@ -2653,7 +2668,7 @@ static void em28xx_card_setup(struct em28xx *dev)
2653 2668
2654 dev->tuner_type = tv.tuner_type; 2669 dev->tuner_type = tv.tuner_type;
2655 2670
2656 if (tv.audio_processor == V4L2_IDENT_MSPX4XX) { 2671 if (tv.audio_processor == TVEEPROM_AUDPROC_MSP) {
2657 dev->i2s_speed = 2048000; 2672 dev->i2s_speed = 2048000;
2658 dev->board.has_msp34xx = 1; 2673 dev->board.has_msp34xx = 1;
2659 } 2674 }
@@ -2662,12 +2677,12 @@ static void em28xx_card_setup(struct em28xx *dev)
2662 case EM2882_BOARD_KWORLD_ATSC_315U: 2677 case EM2882_BOARD_KWORLD_ATSC_315U:
2663 em28xx_write_reg(dev, 0x0d, 0x42); 2678 em28xx_write_reg(dev, 0x0d, 0x42);
2664 msleep(10); 2679 msleep(10);
2665 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xfd); 2680 em28xx_write_reg(dev, EM2820_R08_GPIO_CTRL, 0xfd);
2666 msleep(10); 2681 msleep(10);
2667 break; 2682 break;
2668 case EM2820_BOARD_KWORLD_PVRTV2800RF: 2683 case EM2820_BOARD_KWORLD_PVRTV2800RF:
2669 /* GPIO enables sound on KWORLD PVR TV 2800RF */ 2684 /* GPIO enables sound on KWORLD PVR TV 2800RF */
2670 em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xf9); 2685 em28xx_write_reg(dev, EM2820_R08_GPIO_CTRL, 0xf9);
2671 break; 2686 break;
2672 case EM2820_BOARD_UNKNOWN: 2687 case EM2820_BOARD_UNKNOWN:
2673 case EM2800_BOARD_UNKNOWN: 2688 case EM2800_BOARD_UNKNOWN:
@@ -2881,10 +2896,6 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev,
2881 2896
2882 em28xx_set_model(dev); 2897 em28xx_set_model(dev);
2883 2898
2884 /* Set the default GPO/GPIO for legacy devices */
2885 dev->reg_gpo_num = EM2880_R04_GPO;
2886 dev->reg_gpio_num = EM28XX_R08_GPIO;
2887
2888 dev->wait_after_write = 5; 2899 dev->wait_after_write = 5;
2889 2900
2890 /* Based on the Chip ID, set the device configuration */ 2901 /* Based on the Chip ID, set the device configuration */
@@ -2932,13 +2943,11 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev,
2932 break; 2943 break;
2933 case CHIP_ID_EM2874: 2944 case CHIP_ID_EM2874:
2934 chip_name = "em2874"; 2945 chip_name = "em2874";
2935 dev->reg_gpio_num = EM2874_R80_GPIO;
2936 dev->wait_after_write = 0; 2946 dev->wait_after_write = 0;
2937 dev->eeprom_addrwidth_16bit = 1; 2947 dev->eeprom_addrwidth_16bit = 1;
2938 break; 2948 break;
2939 case CHIP_ID_EM28174: 2949 case CHIP_ID_EM28174:
2940 chip_name = "em28174"; 2950 chip_name = "em28174";
2941 dev->reg_gpio_num = EM2874_R80_GPIO;
2942 dev->wait_after_write = 0; 2951 dev->wait_after_write = 0;
2943 dev->eeprom_addrwidth_16bit = 1; 2952 dev->eeprom_addrwidth_16bit = 1;
2944 break; 2953 break;
@@ -2948,7 +2957,6 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev,
2948 break; 2957 break;
2949 case CHIP_ID_EM2884: 2958 case CHIP_ID_EM2884:
2950 chip_name = "em2884"; 2959 chip_name = "em2884";
2951 dev->reg_gpio_num = EM2874_R80_GPIO;
2952 dev->wait_after_write = 0; 2960 dev->wait_after_write = 0;
2953 dev->eeprom_addrwidth_16bit = 1; 2961 dev->eeprom_addrwidth_16bit = 1;
2954 break; 2962 break;
@@ -2977,11 +2985,6 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev,
2977 return 0; 2985 return 0;
2978 } 2986 }
2979 2987
2980 /* Prepopulate cached GPO register content */
2981 retval = em28xx_read_reg(dev, dev->reg_gpo_num);
2982 if (retval >= 0)
2983 dev->reg_gpo = retval;
2984
2985 em28xx_pre_card_setup(dev); 2988 em28xx_pre_card_setup(dev);
2986 2989
2987 if (!dev->board.is_em2800) { 2990 if (!dev->board.is_em2800) {
@@ -3071,7 +3074,7 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev,
3071 3074
3072 if (dev->board.has_msp34xx) { 3075 if (dev->board.has_msp34xx) {
3073 /* Send a reset to other chips via gpio */ 3076 /* Send a reset to other chips via gpio */
3074 retval = em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xf7); 3077 retval = em28xx_write_reg(dev, EM2820_R08_GPIO_CTRL, 0xf7);
3075 if (retval < 0) { 3078 if (retval < 0) {
3076 em28xx_errdev("%s: em28xx_write_reg - " 3079 em28xx_errdev("%s: em28xx_write_reg - "
3077 "msp34xx(1) failed! error [%d]\n", 3080 "msp34xx(1) failed! error [%d]\n",
@@ -3080,7 +3083,7 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev,
3080 } 3083 }
3081 msleep(3); 3084 msleep(3);
3082 3085
3083 retval = em28xx_write_reg(dev, EM28XX_R08_GPIO, 0xff); 3086 retval = em28xx_write_reg(dev, EM2820_R08_GPIO_CTRL, 0xff);
3084 if (retval < 0) { 3087 if (retval < 0) {
3085 em28xx_errdev("%s: em28xx_write_reg - " 3088 em28xx_errdev("%s: em28xx_write_reg - "
3086 "msp34xx(2) failed! error [%d]\n", 3089 "msp34xx(2) failed! error [%d]\n",
diff --git a/drivers/media/usb/em28xx/em28xx-core.c b/drivers/media/usb/em28xx/em28xx-core.c
index a802128ce9c5..fc157af5234a 100644
--- a/drivers/media/usb/em28xx/em28xx-core.c
+++ b/drivers/media/usb/em28xx/em28xx-core.c
@@ -193,23 +193,7 @@ int em28xx_write_regs_req(struct em28xx *dev, u8 req, u16 reg, char *buf,
193 193
194int em28xx_write_regs(struct em28xx *dev, u16 reg, char *buf, int len) 194int em28xx_write_regs(struct em28xx *dev, u16 reg, char *buf, int len)
195{ 195{
196 int rc; 196 return em28xx_write_regs_req(dev, USB_REQ_GET_STATUS, reg, buf, len);
197
198 rc = em28xx_write_regs_req(dev, USB_REQ_GET_STATUS, reg, buf, len);
199
200 /* Stores GPO/GPIO values at the cache, if changed
201 Only write values should be stored, since input on a GPIO
202 register will return the input bits.
203 Not sure what happens on reading GPO register.
204 */
205 if (rc >= 0) {
206 if (reg == dev->reg_gpo_num)
207 dev->reg_gpo = buf[0];
208 else if (reg == dev->reg_gpio_num)
209 dev->reg_gpio = buf[0];
210 }
211
212 return rc;
213} 197}
214EXPORT_SYMBOL_GPL(em28xx_write_regs); 198EXPORT_SYMBOL_GPL(em28xx_write_regs);
215 199
@@ -231,14 +215,7 @@ int em28xx_write_reg_bits(struct em28xx *dev, u16 reg, u8 val,
231 int oldval; 215 int oldval;
232 u8 newval; 216 u8 newval;
233 217
234 /* Uses cache for gpo/gpio registers */ 218 oldval = em28xx_read_reg(dev, reg);
235 if (reg == dev->reg_gpo_num)
236 oldval = dev->reg_gpo;
237 else if (reg == dev->reg_gpio_num)
238 oldval = dev->reg_gpio;
239 else
240 oldval = em28xx_read_reg(dev, reg);
241
242 if (oldval < 0) 219 if (oldval < 0)
243 return oldval; 220 return oldval;
244 221
diff --git a/drivers/media/usb/em28xx/em28xx-dvb.c b/drivers/media/usb/em28xx/em28xx-dvb.c
index b22f8fed8127..bb1e8dca80cd 100644
--- a/drivers/media/usb/em28xx/em28xx-dvb.c
+++ b/drivers/media/usb/em28xx/em28xx-dvb.c
@@ -421,23 +421,23 @@ static void hauppauge_hvr930c_init(struct em28xx *dev)
421 int i; 421 int i;
422 422
423 struct em28xx_reg_seq hauppauge_hvr930c_init[] = { 423 struct em28xx_reg_seq hauppauge_hvr930c_init[] = {
424 {EM2874_R80_GPIO, 0xff, 0xff, 0x65}, 424 {EM2874_R80_GPIO_P0_CTRL, 0xff, 0xff, 0x65},
425 {EM2874_R80_GPIO, 0xfb, 0xff, 0x32}, 425 {EM2874_R80_GPIO_P0_CTRL, 0xfb, 0xff, 0x32},
426 {EM2874_R80_GPIO, 0xff, 0xff, 0xb8}, 426 {EM2874_R80_GPIO_P0_CTRL, 0xff, 0xff, 0xb8},
427 { -1, -1, -1, -1}, 427 { -1, -1, -1, -1},
428 }; 428 };
429 struct em28xx_reg_seq hauppauge_hvr930c_end[] = { 429 struct em28xx_reg_seq hauppauge_hvr930c_end[] = {
430 {EM2874_R80_GPIO, 0xef, 0xff, 0x01}, 430 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x01},
431 {EM2874_R80_GPIO, 0xaf, 0xff, 0x65}, 431 {EM2874_R80_GPIO_P0_CTRL, 0xaf, 0xff, 0x65},
432 {EM2874_R80_GPIO, 0xef, 0xff, 0x76}, 432 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x76},
433 {EM2874_R80_GPIO, 0xef, 0xff, 0x01}, 433 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x01},
434 {EM2874_R80_GPIO, 0xcf, 0xff, 0x0b}, 434 {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x0b},
435 {EM2874_R80_GPIO, 0xef, 0xff, 0x40}, 435 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x40},
436 436
437 {EM2874_R80_GPIO, 0xcf, 0xff, 0x65}, 437 {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x65},
438 {EM2874_R80_GPIO, 0xef, 0xff, 0x65}, 438 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x65},
439 {EM2874_R80_GPIO, 0xcf, 0xff, 0x0b}, 439 {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x0b},
440 {EM2874_R80_GPIO, 0xef, 0xff, 0x65}, 440 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x65},
441 441
442 { -1, -1, -1, -1}, 442 { -1, -1, -1, -1},
443 }; 443 };
@@ -487,16 +487,16 @@ static void terratec_h5_init(struct em28xx *dev)
487{ 487{
488 int i; 488 int i;
489 struct em28xx_reg_seq terratec_h5_init[] = { 489 struct em28xx_reg_seq terratec_h5_init[] = {
490 {EM28XX_R08_GPIO, 0xff, 0xff, 10}, 490 {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
491 {EM2874_R80_GPIO, 0xf6, 0xff, 100}, 491 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
492 {EM2874_R80_GPIO, 0xf2, 0xff, 50}, 492 {EM2874_R80_GPIO_P0_CTRL, 0xf2, 0xff, 50},
493 {EM2874_R80_GPIO, 0xf6, 0xff, 100}, 493 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
494 { -1, -1, -1, -1}, 494 { -1, -1, -1, -1},
495 }; 495 };
496 struct em28xx_reg_seq terratec_h5_end[] = { 496 struct em28xx_reg_seq terratec_h5_end[] = {
497 {EM2874_R80_GPIO, 0xe6, 0xff, 100}, 497 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
498 {EM2874_R80_GPIO, 0xa6, 0xff, 50}, 498 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 50},
499 {EM2874_R80_GPIO, 0xe6, 0xff, 100}, 499 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
500 { -1, -1, -1, -1}, 500 { -1, -1, -1, -1},
501 }; 501 };
502 struct { 502 struct {
@@ -543,15 +543,15 @@ static void terratec_htc_stick_init(struct em28xx *dev)
543 * 0xb6: unknown (does not affect DVB-T). 543 * 0xb6: unknown (does not affect DVB-T).
544 */ 544 */
545 struct em28xx_reg_seq terratec_htc_stick_init[] = { 545 struct em28xx_reg_seq terratec_htc_stick_init[] = {
546 {EM28XX_R08_GPIO, 0xff, 0xff, 10}, 546 {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
547 {EM2874_R80_GPIO, 0xf6, 0xff, 100}, 547 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
548 {EM2874_R80_GPIO, 0xe6, 0xff, 50}, 548 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 50},
549 {EM2874_R80_GPIO, 0xf6, 0xff, 100}, 549 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
550 { -1, -1, -1, -1}, 550 { -1, -1, -1, -1},
551 }; 551 };
552 struct em28xx_reg_seq terratec_htc_stick_end[] = { 552 struct em28xx_reg_seq terratec_htc_stick_end[] = {
553 {EM2874_R80_GPIO, 0xb6, 0xff, 100}, 553 {EM2874_R80_GPIO_P0_CTRL, 0xb6, 0xff, 100},
554 {EM2874_R80_GPIO, 0xf6, 0xff, 50}, 554 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 50},
555 { -1, -1, -1, -1}, 555 { -1, -1, -1, -1},
556 }; 556 };
557 557
@@ -590,16 +590,16 @@ static void terratec_htc_usb_xs_init(struct em28xx *dev)
590 int i; 590 int i;
591 591
592 struct em28xx_reg_seq terratec_htc_usb_xs_init[] = { 592 struct em28xx_reg_seq terratec_htc_usb_xs_init[] = {
593 {EM28XX_R08_GPIO, 0xff, 0xff, 10}, 593 {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
594 {EM2874_R80_GPIO, 0xb2, 0xff, 100}, 594 {EM2874_R80_GPIO_P0_CTRL, 0xb2, 0xff, 100},
595 {EM2874_R80_GPIO, 0xb2, 0xff, 50}, 595 {EM2874_R80_GPIO_P0_CTRL, 0xb2, 0xff, 50},
596 {EM2874_R80_GPIO, 0xb6, 0xff, 100}, 596 {EM2874_R80_GPIO_P0_CTRL, 0xb6, 0xff, 100},
597 { -1, -1, -1, -1}, 597 { -1, -1, -1, -1},
598 }; 598 };
599 struct em28xx_reg_seq terratec_htc_usb_xs_end[] = { 599 struct em28xx_reg_seq terratec_htc_usb_xs_end[] = {
600 {EM2874_R80_GPIO, 0xa6, 0xff, 100}, 600 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 100},
601 {EM2874_R80_GPIO, 0xa6, 0xff, 50}, 601 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 50},
602 {EM2874_R80_GPIO, 0xe6, 0xff, 100}, 602 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
603 { -1, -1, -1, -1}, 603 { -1, -1, -1, -1},
604 }; 604 };
605 605
@@ -1216,6 +1216,7 @@ static int em28xx_dvb_init(struct em28xx *dev)
1216 dvb_attach(a8293_attach, dvb->fe[0], &dev->i2c_adap[dev->def_i2c_bus], 1216 dvb_attach(a8293_attach, dvb->fe[0], &dev->i2c_adap[dev->def_i2c_bus],
1217 &em28xx_a8293_config); 1217 &em28xx_a8293_config);
1218 break; 1218 break;
1219 case EM2874_BOARD_DELOCK_61959:
1219 case EM2874_BOARD_MAXMEDIA_UB425_TC: 1220 case EM2874_BOARD_MAXMEDIA_UB425_TC:
1220 /* attach demodulator */ 1221 /* attach demodulator */
1221 dvb->fe[0] = dvb_attach(drxk_attach, &maxmedia_ub425_tc_drxk, 1222 dvb->fe[0] = dvb_attach(drxk_attach, &maxmedia_ub425_tc_drxk,
@@ -1235,8 +1236,8 @@ static int em28xx_dvb_init(struct em28xx *dev)
1235 } 1236 }
1236 1237
1237 /* TODO: we need drx-3913k firmware in order to support DVB-T */ 1238 /* TODO: we need drx-3913k firmware in order to support DVB-T */
1238 em28xx_info("MaxMedia UB425-TC: only DVB-C supported by that " \ 1239 em28xx_info("MaxMedia UB425-TC/Delock 61959: only DVB-C " \
1239 "driver version\n"); 1240 "supported by that driver version\n");
1240 1241
1241 break; 1242 break;
1242 case EM2884_BOARD_PCTV_510E: 1243 case EM2884_BOARD_PCTV_510E:
diff --git a/drivers/media/usb/em28xx/em28xx-input.c b/drivers/media/usb/em28xx/em28xx-input.c
index 466b19d0d767..ea181e4b68c5 100644
--- a/drivers/media/usb/em28xx/em28xx-input.c
+++ b/drivers/media/usb/em28xx/em28xx-input.c
@@ -32,7 +32,6 @@
32 32
33#define EM28XX_SNAPSHOT_KEY KEY_CAMERA 33#define EM28XX_SNAPSHOT_KEY KEY_CAMERA
34#define EM28XX_SBUTTON_QUERY_INTERVAL 500 34#define EM28XX_SBUTTON_QUERY_INTERVAL 500
35#define EM28XX_R0C_USBSUSP_SNAPSHOT 0x20
36 35
37static unsigned int ir_debug; 36static unsigned int ir_debug;
38module_param(ir_debug, int, 0644); 37module_param(ir_debug, int, 0644);
diff --git a/drivers/media/usb/em28xx/em28xx-reg.h b/drivers/media/usb/em28xx/em28xx-reg.h
index 622871db04aa..0e0477847965 100644
--- a/drivers/media/usb/em28xx/em28xx-reg.h
+++ b/drivers/media/usb/em28xx/em28xx-reg.h
@@ -49,8 +49,9 @@
49 49
50 50
51/* GPIO/GPO registers */ 51/* GPIO/GPO registers */
52#define EM2880_R04_GPO 0x04 /* em2880-em2883 only */ 52#define EM2880_R04_GPO 0x04 /* em2880-em2883 only */
53#define EM28XX_R08_GPIO 0x08 /* em2820 or upper */ 53#define EM2820_R08_GPIO_CTRL 0x08 /* em2820-em2873/83 only */
54#define EM2820_R09_GPIO_STATE 0x09 /* em2820-em2873/83 only */
54 55
55#define EM28XX_R06_I2C_CLK 0x06 56#define EM28XX_R06_I2C_CLK 0x06
56 57
@@ -67,7 +68,8 @@
67 68
68 69
69#define EM28XX_R0A_CHIPID 0x0a 70#define EM28XX_R0A_CHIPID 0x0a
70#define EM28XX_R0C_USBSUSP 0x0c /* */ 71#define EM28XX_R0C_USBSUSP 0x0c
72#define EM28XX_R0C_USBSUSP_SNAPSHOT 0x20 /* 1=button pressed, needs reset */
71 73
72#define EM28XX_R0E_AUDIOSRC 0x0e 74#define EM28XX_R0E_AUDIOSRC 0x0e
73#define EM28XX_R0F_XCLK 0x0f 75#define EM28XX_R0F_XCLK 0x0f
@@ -193,7 +195,20 @@
193#define EM2874_R50_IR_CONFIG 0x50 195#define EM2874_R50_IR_CONFIG 0x50
194#define EM2874_R51_IR 0x51 196#define EM2874_R51_IR 0x51
195#define EM2874_R5F_TS_ENABLE 0x5f 197#define EM2874_R5F_TS_ENABLE 0x5f
196#define EM2874_R80_GPIO 0x80 198
199/* em2874/174/84, em25xx, em276x/7x/8x GPIO registers */
200/*
201 * NOTE: not all ports are bonded out;
202 * Some ports are multiplexed with special function I/O
203 */
204#define EM2874_R80_GPIO_P0_CTRL 0x80
205#define EM2874_R81_GPIO_P1_CTRL 0x81
206#define EM2874_R82_GPIO_P2_CTRL 0x82
207#define EM2874_R83_GPIO_P3_CTRL 0x83
208#define EM2874_R84_GPIO_P0_STATE 0x84
209#define EM2874_R85_GPIO_P1_STATE 0x85
210#define EM2874_R86_GPIO_P2_STATE 0x86
211#define EM2874_R87_GPIO_P3_STATE 0x87
197 212
198/* em2874 IR config register (0x50) */ 213/* em2874 IR config register (0x50) */
199#define EM2874_IR_NEC 0x00 214#define EM2874_IR_NEC 0x00
diff --git a/drivers/media/usb/em28xx/em28xx-video.c b/drivers/media/usb/em28xx/em28xx-video.c
index 32d60e5546bc..1a577ed8ea0c 100644
--- a/drivers/media/usb/em28xx/em28xx-video.c
+++ b/drivers/media/usb/em28xx/em28xx-video.c
@@ -41,7 +41,6 @@
41#include <media/v4l2-common.h> 41#include <media/v4l2-common.h>
42#include <media/v4l2-ioctl.h> 42#include <media/v4l2-ioctl.h>
43#include <media/v4l2-event.h> 43#include <media/v4l2-event.h>
44#include <media/v4l2-chip-ident.h>
45#include <media/msp3400.h> 44#include <media/msp3400.h>
46#include <media/tuner.h> 45#include <media/tuner.h>
47 46
@@ -1309,28 +1308,6 @@ static int vidioc_s_frequency(struct file *file, void *priv,
1309 return 0; 1308 return 0;
1310} 1309}
1311 1310
1312static int vidioc_g_chip_ident(struct file *file, void *priv,
1313 struct v4l2_dbg_chip_ident *chip)
1314{
1315 struct em28xx_fh *fh = priv;
1316 struct em28xx *dev = fh->dev;
1317
1318 chip->ident = V4L2_IDENT_NONE;
1319 chip->revision = 0;
1320 if (chip->match.type == V4L2_CHIP_MATCH_BRIDGE) {
1321 if (chip->match.addr > 1)
1322 return -EINVAL;
1323 return 0;
1324 }
1325 if (chip->match.type != V4L2_CHIP_MATCH_I2C_DRIVER &&
1326 chip->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
1327 return -EINVAL;
1328
1329 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_chip_ident, chip);
1330
1331 return 0;
1332}
1333
1334#ifdef CONFIG_VIDEO_ADV_DEBUG 1311#ifdef CONFIG_VIDEO_ADV_DEBUG
1335static int vidioc_g_chip_info(struct file *file, void *priv, 1312static int vidioc_g_chip_info(struct file *file, void *priv,
1336 struct v4l2_dbg_chip_info *chip) 1313 struct v4l2_dbg_chip_info *chip)
@@ -1366,14 +1343,9 @@ static int vidioc_g_register(struct file *file, void *priv,
1366 struct em28xx *dev = fh->dev; 1343 struct em28xx *dev = fh->dev;
1367 int ret; 1344 int ret;
1368 1345
1369 switch (reg->match.type) { 1346 if (reg->match.addr > 1)
1370 case V4L2_CHIP_MATCH_BRIDGE: 1347 return -EINVAL;
1371 if (reg->match.addr > 1) 1348 if (reg->match.addr) {
1372 return -EINVAL;
1373 if (!reg->match.addr)
1374 break;
1375 /* fall-through */
1376 case V4L2_CHIP_MATCH_AC97:
1377 ret = em28xx_read_ac97(dev, reg->reg); 1349 ret = em28xx_read_ac97(dev, reg->reg);
1378 if (ret < 0) 1350 if (ret < 0)
1379 return ret; 1351 return ret;
@@ -1381,15 +1353,6 @@ static int vidioc_g_register(struct file *file, void *priv,
1381 reg->val = ret; 1353 reg->val = ret;
1382 reg->size = 1; 1354 reg->size = 1;
1383 return 0; 1355 return 0;
1384 case V4L2_CHIP_MATCH_I2C_DRIVER:
1385 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_register, reg);
1386 return 0;
1387 case V4L2_CHIP_MATCH_I2C_ADDR:
1388 /* TODO: is this correct? */
1389 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_register, reg);
1390 return 0;
1391 default:
1392 return -EINVAL;
1393 } 1356 }
1394 1357
1395 /* Match host */ 1358 /* Match host */
@@ -1421,25 +1384,10 @@ static int vidioc_s_register(struct file *file, void *priv,
1421 struct em28xx *dev = fh->dev; 1384 struct em28xx *dev = fh->dev;
1422 __le16 buf; 1385 __le16 buf;
1423 1386
1424 switch (reg->match.type) { 1387 if (reg->match.addr > 1)
1425 case V4L2_CHIP_MATCH_BRIDGE:
1426 if (reg->match.addr > 1)
1427 return -EINVAL;
1428 if (!reg->match.addr)
1429 break;
1430 /* fall-through */
1431 case V4L2_CHIP_MATCH_AC97:
1432 return em28xx_write_ac97(dev, reg->reg, reg->val);
1433 case V4L2_CHIP_MATCH_I2C_DRIVER:
1434 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_register, reg);
1435 return 0;
1436 case V4L2_CHIP_MATCH_I2C_ADDR:
1437 /* TODO: is this correct? */
1438 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_register, reg);
1439 return 0;
1440 default:
1441 return -EINVAL; 1388 return -EINVAL;
1442 } 1389 if (reg->match.addr)
1390 return em28xx_write_ac97(dev, reg->reg, reg->val);
1443 1391
1444 /* Match host */ 1392 /* Match host */
1445 buf = cpu_to_le16(reg->val); 1393 buf = cpu_to_le16(reg->val);
@@ -1795,7 +1743,6 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
1795 .vidioc_s_frequency = vidioc_s_frequency, 1743 .vidioc_s_frequency = vidioc_s_frequency,
1796 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, 1744 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1797 .vidioc_unsubscribe_event = v4l2_event_unsubscribe, 1745 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1798 .vidioc_g_chip_ident = vidioc_g_chip_ident,
1799#ifdef CONFIG_VIDEO_ADV_DEBUG 1746#ifdef CONFIG_VIDEO_ADV_DEBUG
1800 .vidioc_g_chip_info = vidioc_g_chip_info, 1747 .vidioc_g_chip_info = vidioc_g_chip_info,
1801 .vidioc_g_register = vidioc_g_register, 1748 .vidioc_g_register = vidioc_g_register,
@@ -1826,7 +1773,6 @@ static const struct v4l2_ioctl_ops radio_ioctl_ops = {
1826 .vidioc_s_frequency = vidioc_s_frequency, 1773 .vidioc_s_frequency = vidioc_s_frequency,
1827 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, 1774 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1828 .vidioc_unsubscribe_event = v4l2_event_unsubscribe, 1775 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1829 .vidioc_g_chip_ident = vidioc_g_chip_ident,
1830#ifdef CONFIG_VIDEO_ADV_DEBUG 1776#ifdef CONFIG_VIDEO_ADV_DEBUG
1831 .vidioc_g_chip_info = vidioc_g_chip_info, 1777 .vidioc_g_chip_info = vidioc_g_chip_info,
1832 .vidioc_g_register = vidioc_g_register, 1778 .vidioc_g_register = vidioc_g_register,
diff --git a/drivers/media/usb/em28xx/em28xx.h b/drivers/media/usb/em28xx/em28xx.h
index a9323b63d8e5..205e9038b1c0 100644
--- a/drivers/media/usb/em28xx/em28xx.h
+++ b/drivers/media/usb/em28xx/em28xx.h
@@ -130,6 +130,7 @@
130#define EM2884_BOARD_PCTV_520E 86 130#define EM2884_BOARD_PCTV_520E 86
131#define EM2884_BOARD_TERRATEC_HTC_USB_XS 87 131#define EM2884_BOARD_TERRATEC_HTC_USB_XS 87
132#define EM2884_BOARD_C3TECH_DIGITAL_DUO 88 132#define EM2884_BOARD_C3TECH_DIGITAL_DUO 88
133#define EM2874_BOARD_DELOCK_61959 89
133 134
134/* Limits minimum and default number of buffers */ 135/* Limits minimum and default number of buffers */
135#define EM28XX_MIN_BUF 4 136#define EM28XX_MIN_BUF 4
@@ -636,12 +637,6 @@ struct em28xx {
636 637
637 enum em28xx_mode mode; 638 enum em28xx_mode mode;
638 639
639 /* register numbers for GPO/GPIO registers */
640 u16 reg_gpo_num, reg_gpio_num;
641
642 /* Caches GPO and GPIO registers */
643 unsigned char reg_gpo, reg_gpio;
644
645 /* Snapshot button */ 640 /* Snapshot button */
646 char snapshot_button_path[30]; /* path of the input dev */ 641 char snapshot_button_path[30]; /* path of the input dev */
647 struct input_dev *sbutton_input_dev; 642 struct input_dev *sbutton_input_dev;
diff --git a/drivers/media/usb/gspca/gspca.c b/drivers/media/usb/gspca/gspca.c
index 5995ec4de6bc..b7ae8721b847 100644
--- a/drivers/media/usb/gspca/gspca.c
+++ b/drivers/media/usb/gspca/gspca.c
@@ -1029,33 +1029,35 @@ static int gspca_get_mode(struct gspca_dev *gspca_dev,
1029} 1029}
1030 1030
1031#ifdef CONFIG_VIDEO_ADV_DEBUG 1031#ifdef CONFIG_VIDEO_ADV_DEBUG
1032static int vidioc_g_register(struct file *file, void *priv, 1032static int vidioc_g_chip_info(struct file *file, void *priv,
1033 struct v4l2_dbg_register *reg) 1033 struct v4l2_dbg_chip_info *chip)
1034{ 1034{
1035 struct gspca_dev *gspca_dev = video_drvdata(file); 1035 struct gspca_dev *gspca_dev = video_drvdata(file);
1036 1036
1037 gspca_dev->usb_err = 0; 1037 gspca_dev->usb_err = 0;
1038 return gspca_dev->sd_desc->get_register(gspca_dev, reg); 1038 if (gspca_dev->sd_desc->get_chip_info)
1039 return gspca_dev->sd_desc->get_chip_info(gspca_dev, chip);
1040 return chip->match.addr ? -EINVAL : 0;
1039} 1041}
1040 1042
1041static int vidioc_s_register(struct file *file, void *priv, 1043static int vidioc_g_register(struct file *file, void *priv,
1042 const struct v4l2_dbg_register *reg) 1044 struct v4l2_dbg_register *reg)
1043{ 1045{
1044 struct gspca_dev *gspca_dev = video_drvdata(file); 1046 struct gspca_dev *gspca_dev = video_drvdata(file);
1045 1047
1046 gspca_dev->usb_err = 0; 1048 gspca_dev->usb_err = 0;
1047 return gspca_dev->sd_desc->set_register(gspca_dev, reg); 1049 return gspca_dev->sd_desc->get_register(gspca_dev, reg);
1048} 1050}
1049#endif
1050 1051
1051static int vidioc_g_chip_ident(struct file *file, void *priv, 1052static int vidioc_s_register(struct file *file, void *priv,
1052 struct v4l2_dbg_chip_ident *chip) 1053 const struct v4l2_dbg_register *reg)
1053{ 1054{
1054 struct gspca_dev *gspca_dev = video_drvdata(file); 1055 struct gspca_dev *gspca_dev = video_drvdata(file);
1055 1056
1056 gspca_dev->usb_err = 0; 1057 gspca_dev->usb_err = 0;
1057 return gspca_dev->sd_desc->get_chip_ident(gspca_dev, chip); 1058 return gspca_dev->sd_desc->set_register(gspca_dev, reg);
1058} 1059}
1060#endif
1059 1061
1060static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv, 1062static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
1061 struct v4l2_fmtdesc *fmtdesc) 1063 struct v4l2_fmtdesc *fmtdesc)
@@ -1974,10 +1976,10 @@ static const struct v4l2_ioctl_ops dev_ioctl_ops = {
1974 .vidioc_enum_framesizes = vidioc_enum_framesizes, 1976 .vidioc_enum_framesizes = vidioc_enum_framesizes,
1975 .vidioc_enum_frameintervals = vidioc_enum_frameintervals, 1977 .vidioc_enum_frameintervals = vidioc_enum_frameintervals,
1976#ifdef CONFIG_VIDEO_ADV_DEBUG 1978#ifdef CONFIG_VIDEO_ADV_DEBUG
1979 .vidioc_g_chip_info = vidioc_g_chip_info,
1977 .vidioc_g_register = vidioc_g_register, 1980 .vidioc_g_register = vidioc_g_register,
1978 .vidioc_s_register = vidioc_s_register, 1981 .vidioc_s_register = vidioc_s_register,
1979#endif 1982#endif
1980 .vidioc_g_chip_ident = vidioc_g_chip_ident,
1981 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, 1983 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1982 .vidioc_unsubscribe_event = v4l2_event_unsubscribe, 1984 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1983}; 1985};
@@ -2086,14 +2088,10 @@ int gspca_dev_probe2(struct usb_interface *intf,
2086 v4l2_disable_ioctl_locking(&gspca_dev->vdev, VIDIOC_DQBUF); 2088 v4l2_disable_ioctl_locking(&gspca_dev->vdev, VIDIOC_DQBUF);
2087 v4l2_disable_ioctl_locking(&gspca_dev->vdev, VIDIOC_QBUF); 2089 v4l2_disable_ioctl_locking(&gspca_dev->vdev, VIDIOC_QBUF);
2088 v4l2_disable_ioctl_locking(&gspca_dev->vdev, VIDIOC_QUERYBUF); 2090 v4l2_disable_ioctl_locking(&gspca_dev->vdev, VIDIOC_QUERYBUF);
2089 if (!gspca_dev->sd_desc->get_chip_ident)
2090 v4l2_disable_ioctl(&gspca_dev->vdev, VIDIOC_DBG_G_CHIP_IDENT);
2091#ifdef CONFIG_VIDEO_ADV_DEBUG 2091#ifdef CONFIG_VIDEO_ADV_DEBUG
2092 if (!gspca_dev->sd_desc->get_chip_ident || 2092 if (!gspca_dev->sd_desc->get_register)
2093 !gspca_dev->sd_desc->get_register)
2094 v4l2_disable_ioctl(&gspca_dev->vdev, VIDIOC_DBG_G_REGISTER); 2093 v4l2_disable_ioctl(&gspca_dev->vdev, VIDIOC_DBG_G_REGISTER);
2095 if (!gspca_dev->sd_desc->get_chip_ident || 2094 if (!gspca_dev->sd_desc->set_register)
2096 !gspca_dev->sd_desc->set_register)
2097 v4l2_disable_ioctl(&gspca_dev->vdev, VIDIOC_DBG_S_REGISTER); 2095 v4l2_disable_ioctl(&gspca_dev->vdev, VIDIOC_DBG_S_REGISTER);
2098#endif 2096#endif
2099 if (!gspca_dev->sd_desc->get_jcomp) 2097 if (!gspca_dev->sd_desc->get_jcomp)
diff --git a/drivers/media/usb/gspca/gspca.h b/drivers/media/usb/gspca/gspca.h
index ef8efeb80070..ac0b11f46f50 100644
--- a/drivers/media/usb/gspca/gspca.h
+++ b/drivers/media/usb/gspca/gspca.h
@@ -78,8 +78,8 @@ typedef int (*cam_get_reg_op) (struct gspca_dev *,
78 struct v4l2_dbg_register *); 78 struct v4l2_dbg_register *);
79typedef int (*cam_set_reg_op) (struct gspca_dev *, 79typedef int (*cam_set_reg_op) (struct gspca_dev *,
80 const struct v4l2_dbg_register *); 80 const struct v4l2_dbg_register *);
81typedef int (*cam_ident_op) (struct gspca_dev *, 81typedef int (*cam_chip_info_op) (struct gspca_dev *,
82 struct v4l2_dbg_chip_ident *); 82 struct v4l2_dbg_chip_info *);
83typedef void (*cam_streamparm_op) (struct gspca_dev *, 83typedef void (*cam_streamparm_op) (struct gspca_dev *,
84 struct v4l2_streamparm *); 84 struct v4l2_streamparm *);
85typedef void (*cam_pkt_op) (struct gspca_dev *gspca_dev, 85typedef void (*cam_pkt_op) (struct gspca_dev *gspca_dev,
@@ -112,8 +112,8 @@ struct sd_desc {
112#ifdef CONFIG_VIDEO_ADV_DEBUG 112#ifdef CONFIG_VIDEO_ADV_DEBUG
113 cam_set_reg_op set_register; 113 cam_set_reg_op set_register;
114 cam_get_reg_op get_register; 114 cam_get_reg_op get_register;
115 cam_chip_info_op get_chip_info;
115#endif 116#endif
116 cam_ident_op get_chip_ident;
117#if IS_ENABLED(CONFIG_INPUT) 117#if IS_ENABLED(CONFIG_INPUT)
118 cam_int_pkt_op int_pkt_scan; 118 cam_int_pkt_op int_pkt_scan;
119 /* other_input makes the gspca core create gspca_dev->input even when 119 /* other_input makes the gspca core create gspca_dev->input even when
diff --git a/drivers/media/usb/gspca/pac7302.c b/drivers/media/usb/gspca/pac7302.c
index 6008c8d546a3..a91509643563 100644
--- a/drivers/media/usb/gspca/pac7302.c
+++ b/drivers/media/usb/gspca/pac7302.c
@@ -93,7 +93,6 @@
93#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 93#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
94 94
95#include <linux/input.h> 95#include <linux/input.h>
96#include <media/v4l2-chip-ident.h>
97#include "gspca.h" 96#include "gspca.h"
98/* Include pac common sof detection functions */ 97/* Include pac common sof detection functions */
99#include "pac_common.h" 98#include "pac_common.h"
@@ -849,8 +848,7 @@ static int sd_dbg_s_register(struct gspca_dev *gspca_dev,
849 * reg->reg: bit0..15: reserved for register index (wIndex is 16bit 848 * reg->reg: bit0..15: reserved for register index (wIndex is 16bit
850 * long on the USB bus) 849 * long on the USB bus)
851 */ 850 */
852 if (reg->match.type == V4L2_CHIP_MATCH_HOST && 851 if (reg->match.addr == 0 &&
853 reg->match.addr == 0 &&
854 (reg->reg < 0x000000ff) && 852 (reg->reg < 0x000000ff) &&
855 (reg->val <= 0x000000ff) 853 (reg->val <= 0x000000ff)
856 ) { 854 ) {
@@ -871,20 +869,6 @@ static int sd_dbg_s_register(struct gspca_dev *gspca_dev,
871 } 869 }
872 return gspca_dev->usb_err; 870 return gspca_dev->usb_err;
873} 871}
874
875static int sd_chip_ident(struct gspca_dev *gspca_dev,
876 struct v4l2_dbg_chip_ident *chip)
877{
878 int ret = -EINVAL;
879
880 if (chip->match.type == V4L2_CHIP_MATCH_HOST &&
881 chip->match.addr == 0) {
882 chip->revision = 0;
883 chip->ident = V4L2_IDENT_UNKNOWN;
884 ret = 0;
885 }
886 return ret;
887}
888#endif 872#endif
889 873
890#if IS_ENABLED(CONFIG_INPUT) 874#if IS_ENABLED(CONFIG_INPUT)
@@ -931,7 +915,6 @@ static const struct sd_desc sd_desc = {
931 .dq_callback = do_autogain, 915 .dq_callback = do_autogain,
932#ifdef CONFIG_VIDEO_ADV_DEBUG 916#ifdef CONFIG_VIDEO_ADV_DEBUG
933 .set_register = sd_dbg_s_register, 917 .set_register = sd_dbg_s_register,
934 .get_chip_ident = sd_chip_ident,
935#endif 918#endif
936#if IS_ENABLED(CONFIG_INPUT) 919#if IS_ENABLED(CONFIG_INPUT)
937 .int_pkt_scan = sd_int_pkt_scan, 920 .int_pkt_scan = sd_int_pkt_scan,
diff --git a/drivers/media/usb/gspca/sn9c20x.c b/drivers/media/usb/gspca/sn9c20x.c
index ead9a1f58513..f4453d52801b 100644
--- a/drivers/media/usb/gspca/sn9c20x.c
+++ b/drivers/media/usb/gspca/sn9c20x.c
@@ -27,7 +27,6 @@
27#include "gspca.h" 27#include "gspca.h"
28#include "jpeg.h" 28#include "jpeg.h"
29 29
30#include <media/v4l2-chip-ident.h>
31#include <linux/dmi.h> 30#include <linux/dmi.h>
32 31
33MODULE_AUTHOR("Brian Johnson <brijohn@gmail.com>, " 32MODULE_AUTHOR("Brian Johnson <brijohn@gmail.com>, "
@@ -582,22 +581,6 @@ static const s16 hsv_blue_y[] = {
582 4, 2, 0, -1, -3, -5, -7, -9, -11 581 4, 2, 0, -1, -3, -5, -7, -9, -11
583}; 582};
584 583
585static const u16 i2c_ident[] = {
586 V4L2_IDENT_OV9650,
587 V4L2_IDENT_OV9655,
588 V4L2_IDENT_SOI968,
589 V4L2_IDENT_OV7660,
590 V4L2_IDENT_OV7670,
591 V4L2_IDENT_MT9V011,
592 V4L2_IDENT_MT9V111,
593 V4L2_IDENT_MT9V112,
594 V4L2_IDENT_MT9M001C12ST,
595 V4L2_IDENT_MT9M111,
596 V4L2_IDENT_MT9M112,
597 V4L2_IDENT_HV7131R,
598[SENSOR_MT9VPRB] = V4L2_IDENT_UNKNOWN,
599};
600
601static const u16 bridge_init[][2] = { 584static const u16 bridge_init[][2] = {
602 {0x1000, 0x78}, {0x1001, 0x40}, {0x1002, 0x1c}, 585 {0x1000, 0x78}, {0x1001, 0x40}, {0x1002, 0x1c},
603 {0x1020, 0x80}, {0x1061, 0x01}, {0x1067, 0x40}, 586 {0x1020, 0x80}, {0x1061, 0x01}, {0x1067, 0x40},
@@ -1574,21 +1557,19 @@ static int sd_dbg_g_register(struct gspca_dev *gspca_dev,
1574{ 1557{
1575 struct sd *sd = (struct sd *) gspca_dev; 1558 struct sd *sd = (struct sd *) gspca_dev;
1576 1559
1577 switch (reg->match.type) { 1560 reg->size = 1;
1578 case V4L2_CHIP_MATCH_HOST: 1561 switch (reg->match.addr) {
1579 if (reg->match.addr != 0) 1562 case 0:
1580 return -EINVAL;
1581 if (reg->reg < 0x1000 || reg->reg > 0x11ff) 1563 if (reg->reg < 0x1000 || reg->reg > 0x11ff)
1582 return -EINVAL; 1564 return -EINVAL;
1583 reg_r(gspca_dev, reg->reg, 1); 1565 reg_r(gspca_dev, reg->reg, 1);
1584 reg->val = gspca_dev->usb_buf[0]; 1566 reg->val = gspca_dev->usb_buf[0];
1585 return gspca_dev->usb_err; 1567 return gspca_dev->usb_err;
1586 case V4L2_CHIP_MATCH_I2C_ADDR: 1568 case 1:
1587 if (reg->match.addr != sd->i2c_addr)
1588 return -EINVAL;
1589 if (sd->sensor >= SENSOR_MT9V011 && 1569 if (sd->sensor >= SENSOR_MT9V011 &&
1590 sd->sensor <= SENSOR_MT9M112) { 1570 sd->sensor <= SENSOR_MT9M112) {
1591 i2c_r2(gspca_dev, reg->reg, (u16 *) &reg->val); 1571 i2c_r2(gspca_dev, reg->reg, (u16 *) &reg->val);
1572 reg->size = 2;
1592 } else { 1573 } else {
1593 i2c_r1(gspca_dev, reg->reg, (u8 *) &reg->val); 1574 i2c_r1(gspca_dev, reg->reg, (u8 *) &reg->val);
1594 } 1575 }
@@ -1602,17 +1583,13 @@ static int sd_dbg_s_register(struct gspca_dev *gspca_dev,
1602{ 1583{
1603 struct sd *sd = (struct sd *) gspca_dev; 1584 struct sd *sd = (struct sd *) gspca_dev;
1604 1585
1605 switch (reg->match.type) { 1586 switch (reg->match.addr) {
1606 case V4L2_CHIP_MATCH_HOST: 1587 case 0:
1607 if (reg->match.addr != 0)
1608 return -EINVAL;
1609 if (reg->reg < 0x1000 || reg->reg > 0x11ff) 1588 if (reg->reg < 0x1000 || reg->reg > 0x11ff)
1610 return -EINVAL; 1589 return -EINVAL;
1611 reg_w1(gspca_dev, reg->reg, reg->val); 1590 reg_w1(gspca_dev, reg->reg, reg->val);
1612 return gspca_dev->usb_err; 1591 return gspca_dev->usb_err;
1613 case V4L2_CHIP_MATCH_I2C_ADDR: 1592 case 1:
1614 if (reg->match.addr != sd->i2c_addr)
1615 return -EINVAL;
1616 if (sd->sensor >= SENSOR_MT9V011 && 1593 if (sd->sensor >= SENSOR_MT9V011 &&
1617 sd->sensor <= SENSOR_MT9M112) { 1594 sd->sensor <= SENSOR_MT9M112) {
1618 i2c_w2(gspca_dev, reg->reg, reg->val); 1595 i2c_w2(gspca_dev, reg->reg, reg->val);
@@ -1623,29 +1600,17 @@ static int sd_dbg_s_register(struct gspca_dev *gspca_dev,
1623 } 1600 }
1624 return -EINVAL; 1601 return -EINVAL;
1625} 1602}
1626#endif
1627 1603
1628static int sd_chip_ident(struct gspca_dev *gspca_dev, 1604static int sd_chip_info(struct gspca_dev *gspca_dev,
1629 struct v4l2_dbg_chip_ident *chip) 1605 struct v4l2_dbg_chip_info *chip)
1630{ 1606{
1631 struct sd *sd = (struct sd *) gspca_dev; 1607 if (chip->match.addr > 1)
1632 1608 return -EINVAL;
1633 switch (chip->match.type) { 1609 if (chip->match.addr == 1)
1634 case V4L2_CHIP_MATCH_HOST: 1610 strlcpy(chip->name, "sensor", sizeof(chip->name));
1635 if (chip->match.addr != 0) 1611 return 0;
1636 return -EINVAL;
1637 chip->revision = 0;
1638 chip->ident = V4L2_IDENT_SN9C20X;
1639 return 0;
1640 case V4L2_CHIP_MATCH_I2C_ADDR:
1641 if (chip->match.addr != sd->i2c_addr)
1642 return -EINVAL;
1643 chip->revision = 0;
1644 chip->ident = i2c_ident[sd->sensor];
1645 return 0;
1646 }
1647 return -EINVAL;
1648} 1612}
1613#endif
1649 1614
1650static int sd_config(struct gspca_dev *gspca_dev, 1615static int sd_config(struct gspca_dev *gspca_dev,
1651 const struct usb_device_id *id) 1616 const struct usb_device_id *id)
@@ -2356,8 +2321,8 @@ static const struct sd_desc sd_desc = {
2356#ifdef CONFIG_VIDEO_ADV_DEBUG 2321#ifdef CONFIG_VIDEO_ADV_DEBUG
2357 .set_register = sd_dbg_s_register, 2322 .set_register = sd_dbg_s_register,
2358 .get_register = sd_dbg_g_register, 2323 .get_register = sd_dbg_g_register,
2324 .get_chip_info = sd_chip_info,
2359#endif 2325#endif
2360 .get_chip_ident = sd_chip_ident,
2361}; 2326};
2362 2327
2363#define SN9C20X(sensor, i2c_addr, flags) \ 2328#define SN9C20X(sensor, i2c_addr, flags) \
diff --git a/drivers/media/usb/hdpvr/Kconfig b/drivers/media/usb/hdpvr/Kconfig
index de247f3c7d05..d73d9a1952b4 100644
--- a/drivers/media/usb/hdpvr/Kconfig
+++ b/drivers/media/usb/hdpvr/Kconfig
@@ -1,7 +1,7 @@
1 1
2config VIDEO_HDPVR 2config VIDEO_HDPVR
3 tristate "Hauppauge HD PVR support" 3 tristate "Hauppauge HD PVR support"
4 depends on VIDEO_DEV 4 depends on VIDEO_DEV && VIDEO_V4L2
5 ---help--- 5 ---help---
6 This is a video4linux driver for Hauppauge's HD PVR USB device. 6 This is a video4linux driver for Hauppauge's HD PVR USB device.
7 7
diff --git a/drivers/media/usb/hdpvr/hdpvr-control.c b/drivers/media/usb/hdpvr/hdpvr-control.c
index ae8f229d1141..6053661dc04b 100644
--- a/drivers/media/usb/hdpvr/hdpvr-control.c
+++ b/drivers/media/usb/hdpvr/hdpvr-control.c
@@ -45,20 +45,11 @@ int hdpvr_config_call(struct hdpvr_device *dev, uint value, u8 valbuf)
45 return ret < 0 ? ret : 0; 45 return ret < 0 ? ret : 0;
46} 46}
47 47
48struct hdpvr_video_info *get_video_info(struct hdpvr_device *dev) 48int get_video_info(struct hdpvr_device *dev, struct hdpvr_video_info *vidinf)
49{ 49{
50 struct hdpvr_video_info *vidinf = NULL;
51#ifdef HDPVR_DEBUG
52 char print_buf[15];
53#endif
54 int ret; 50 int ret;
55 51
56 vidinf = kzalloc(sizeof(struct hdpvr_video_info), GFP_KERNEL); 52 vidinf->valid = false;
57 if (!vidinf) {
58 v4l2_err(&dev->v4l2_dev, "out of memory\n");
59 goto err;
60 }
61
62 mutex_lock(&dev->usbc_mutex); 53 mutex_lock(&dev->usbc_mutex);
63 ret = usb_control_msg(dev->udev, 54 ret = usb_control_msg(dev->udev,
64 usb_rcvctrlpipe(dev->udev, 0), 55 usb_rcvctrlpipe(dev->udev, 0),
@@ -66,14 +57,10 @@ struct hdpvr_video_info *get_video_info(struct hdpvr_device *dev)
66 0x1400, 0x0003, 57 0x1400, 0x0003,
67 dev->usbc_buf, 5, 58 dev->usbc_buf, 5,
68 1000); 59 1000);
69 if (ret == 5) {
70 vidinf->width = dev->usbc_buf[1] << 8 | dev->usbc_buf[0];
71 vidinf->height = dev->usbc_buf[3] << 8 | dev->usbc_buf[2];
72 vidinf->fps = dev->usbc_buf[4];
73 }
74 60
75#ifdef HDPVR_DEBUG 61#ifdef HDPVR_DEBUG
76 if (hdpvr_debug & MSG_INFO) { 62 if (hdpvr_debug & MSG_INFO) {
63 char print_buf[15];
77 hex_dump_to_buffer(dev->usbc_buf, 5, 16, 1, print_buf, 64 hex_dump_to_buffer(dev->usbc_buf, 5, 16, 1, print_buf,
78 sizeof(print_buf), 0); 65 sizeof(print_buf), 0);
79 v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev, 66 v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev,
@@ -82,12 +69,15 @@ struct hdpvr_video_info *get_video_info(struct hdpvr_device *dev)
82#endif 69#endif
83 mutex_unlock(&dev->usbc_mutex); 70 mutex_unlock(&dev->usbc_mutex);
84 71
85 if (!vidinf->width || !vidinf->height || !vidinf->fps) { 72 if (ret < 0)
86 kfree(vidinf); 73 return ret;
87 vidinf = NULL; 74
88 } 75 vidinf->width = dev->usbc_buf[1] << 8 | dev->usbc_buf[0];
89err: 76 vidinf->height = dev->usbc_buf[3] << 8 | dev->usbc_buf[2];
90 return vidinf; 77 vidinf->fps = dev->usbc_buf[4];
78 vidinf->valid = vidinf->width && vidinf->height && vidinf->fps;
79
80 return 0;
91} 81}
92 82
93int get_input_lines_info(struct hdpvr_device *dev) 83int get_input_lines_info(struct hdpvr_device *dev)
diff --git a/drivers/media/usb/hdpvr/hdpvr-core.c b/drivers/media/usb/hdpvr/hdpvr-core.c
index 8247c19d6260..cb694055ba7d 100644
--- a/drivers/media/usb/hdpvr/hdpvr-core.c
+++ b/drivers/media/usb/hdpvr/hdpvr-core.c
@@ -220,7 +220,6 @@ static int hdpvr_device_init(struct hdpvr_device *dev)
220{ 220{
221 int ret; 221 int ret;
222 u8 *buf; 222 u8 *buf;
223 struct hdpvr_video_info *vidinf;
224 223
225 if (device_authorization(dev)) 224 if (device_authorization(dev))
226 return -EACCES; 225 return -EACCES;
@@ -242,13 +241,6 @@ static int hdpvr_device_init(struct hdpvr_device *dev)
242 "control request returned %d\n", ret); 241 "control request returned %d\n", ret);
243 mutex_unlock(&dev->usbc_mutex); 242 mutex_unlock(&dev->usbc_mutex);
244 243
245 vidinf = get_video_info(dev);
246 if (!vidinf)
247 v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev,
248 "no valid video signal or device init failed\n");
249 else
250 kfree(vidinf);
251
252 /* enable fan and bling leds */ 244 /* enable fan and bling leds */
253 mutex_lock(&dev->usbc_mutex); 245 mutex_lock(&dev->usbc_mutex);
254 buf[0] = 0x1; 246 buf[0] = 0x1;
diff --git a/drivers/media/usb/hdpvr/hdpvr-video.c b/drivers/media/usb/hdpvr/hdpvr-video.c
index 774ba0e820be..4f8567aa99d8 100644
--- a/drivers/media/usb/hdpvr/hdpvr-video.c
+++ b/drivers/media/usb/hdpvr/hdpvr-video.c
@@ -277,44 +277,50 @@ error:
277static int hdpvr_start_streaming(struct hdpvr_device *dev) 277static int hdpvr_start_streaming(struct hdpvr_device *dev)
278{ 278{
279 int ret; 279 int ret;
280 struct hdpvr_video_info *vidinf; 280 struct hdpvr_video_info vidinf;
281 281
282 if (dev->status == STATUS_STREAMING) 282 if (dev->status == STATUS_STREAMING)
283 return 0; 283 return 0;
284 else if (dev->status != STATUS_IDLE) 284 if (dev->status != STATUS_IDLE)
285 return -EAGAIN; 285 return -EAGAIN;
286 286
287 vidinf = get_video_info(dev); 287 ret = get_video_info(dev, &vidinf);
288 if (ret < 0)
289 return ret;
288 290
289 if (vidinf) { 291 if (!vidinf.valid) {
290 v4l2_dbg(MSG_BUFFER, hdpvr_debug, &dev->v4l2_dev, 292 msleep(250);
291 "video signal: %dx%d@%dhz\n", vidinf->width, 293 v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev,
292 vidinf->height, vidinf->fps); 294 "no video signal at input %d\n", dev->options.video_input);
293 kfree(vidinf); 295 return -EAGAIN;
294 296 }
295 /* start streaming 2 request */
296 ret = usb_control_msg(dev->udev,
297 usb_sndctrlpipe(dev->udev, 0),
298 0xb8, 0x38, 0x1, 0, NULL, 0, 8000);
299 v4l2_dbg(MSG_BUFFER, hdpvr_debug, &dev->v4l2_dev,
300 "encoder start control request returned %d\n", ret);
301 297
302 hdpvr_config_call(dev, CTRL_START_STREAMING_VALUE, 0x00); 298 v4l2_dbg(MSG_BUFFER, hdpvr_debug, &dev->v4l2_dev,
299 "video signal: %dx%d@%dhz\n", vidinf.width,
300 vidinf.height, vidinf.fps);
303 301
304 dev->status = STATUS_STREAMING; 302 /* start streaming 2 request */
303 ret = usb_control_msg(dev->udev,
304 usb_sndctrlpipe(dev->udev, 0),
305 0xb8, 0x38, 0x1, 0, NULL, 0, 8000);
306 v4l2_dbg(MSG_BUFFER, hdpvr_debug, &dev->v4l2_dev,
307 "encoder start control request returned %d\n", ret);
308 if (ret < 0)
309 return ret;
305 310
306 INIT_WORK(&dev->worker, hdpvr_transmit_buffers); 311 ret = hdpvr_config_call(dev, CTRL_START_STREAMING_VALUE, 0x00);
307 queue_work(dev->workqueue, &dev->worker); 312 if (ret)
313 return ret;
308 314
309 v4l2_dbg(MSG_BUFFER, hdpvr_debug, &dev->v4l2_dev, 315 dev->status = STATUS_STREAMING;
310 "streaming started\n");
311 316
312 return 0; 317 INIT_WORK(&dev->worker, hdpvr_transmit_buffers);
313 } 318 queue_work(dev->workqueue, &dev->worker);
314 msleep(250); 319
315 v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev, 320 v4l2_dbg(MSG_BUFFER, hdpvr_debug, &dev->v4l2_dev,
316 "no video signal at input %d\n", dev->options.video_input); 321 "streaming started\n");
317 return -EAGAIN; 322
323 return 0;
318} 324}
319 325
320 326
@@ -606,22 +612,20 @@ static int vidioc_g_std(struct file *file, void *_fh,
606static int vidioc_querystd(struct file *file, void *_fh, v4l2_std_id *a) 612static int vidioc_querystd(struct file *file, void *_fh, v4l2_std_id *a)
607{ 613{
608 struct hdpvr_device *dev = video_drvdata(file); 614 struct hdpvr_device *dev = video_drvdata(file);
609 struct hdpvr_video_info *vid_info; 615 struct hdpvr_video_info vid_info;
610 struct hdpvr_fh *fh = _fh; 616 struct hdpvr_fh *fh = _fh;
617 int ret;
611 618
612 *a = V4L2_STD_ALL; 619 *a = V4L2_STD_UNKNOWN;
613 if (dev->options.video_input == HDPVR_COMPONENT) 620 if (dev->options.video_input == HDPVR_COMPONENT)
614 return fh->legacy_mode ? 0 : -ENODATA; 621 return fh->legacy_mode ? 0 : -ENODATA;
615 vid_info = get_video_info(dev); 622 ret = get_video_info(dev, &vid_info);
616 if (vid_info == NULL) 623 if (vid_info.valid && vid_info.width == 720 &&
617 return 0; 624 (vid_info.height == 480 || vid_info.height == 576)) {
618 if (vid_info->width == 720 && 625 *a = (vid_info.height == 480) ?
619 (vid_info->height == 480 || vid_info->height == 576)) {
620 *a = (vid_info->height == 480) ?
621 V4L2_STD_525_60 : V4L2_STD_625_50; 626 V4L2_STD_525_60 : V4L2_STD_625_50;
622 } 627 }
623 kfree(vid_info); 628 return ret;
624 return 0;
625} 629}
626 630
627static int vidioc_s_dv_timings(struct file *file, void *_fh, 631static int vidioc_s_dv_timings(struct file *file, void *_fh,
@@ -665,7 +669,7 @@ static int vidioc_query_dv_timings(struct file *file, void *_fh,
665{ 669{
666 struct hdpvr_device *dev = video_drvdata(file); 670 struct hdpvr_device *dev = video_drvdata(file);
667 struct hdpvr_fh *fh = _fh; 671 struct hdpvr_fh *fh = _fh;
668 struct hdpvr_video_info *vid_info; 672 struct hdpvr_video_info vid_info;
669 bool interlaced; 673 bool interlaced;
670 int ret = 0; 674 int ret = 0;
671 int i; 675 int i;
@@ -673,10 +677,12 @@ static int vidioc_query_dv_timings(struct file *file, void *_fh,
673 fh->legacy_mode = false; 677 fh->legacy_mode = false;
674 if (dev->options.video_input) 678 if (dev->options.video_input)
675 return -ENODATA; 679 return -ENODATA;
676 vid_info = get_video_info(dev); 680 ret = get_video_info(dev, &vid_info);
677 if (vid_info == NULL) 681 if (ret)
682 return ret;
683 if (!vid_info.valid)
678 return -ENOLCK; 684 return -ENOLCK;
679 interlaced = vid_info->fps <= 30; 685 interlaced = vid_info.fps <= 30;
680 for (i = 0; i < ARRAY_SIZE(hdpvr_dv_timings); i++) { 686 for (i = 0; i < ARRAY_SIZE(hdpvr_dv_timings); i++) {
681 const struct v4l2_bt_timings *bt = &hdpvr_dv_timings[i].bt; 687 const struct v4l2_bt_timings *bt = &hdpvr_dv_timings[i].bt;
682 unsigned hsize; 688 unsigned hsize;
@@ -688,17 +694,17 @@ static int vidioc_query_dv_timings(struct file *file, void *_fh,
688 bt->il_vfrontporch + bt->il_vsync + bt->il_vbackporch + 694 bt->il_vfrontporch + bt->il_vsync + bt->il_vbackporch +
689 bt->height; 695 bt->height;
690 fps = (unsigned)bt->pixelclock / (hsize * vsize); 696 fps = (unsigned)bt->pixelclock / (hsize * vsize);
691 if (bt->width != vid_info->width || 697 if (bt->width != vid_info.width ||
692 bt->height != vid_info->height || 698 bt->height != vid_info.height ||
693 bt->interlaced != interlaced || 699 bt->interlaced != interlaced ||
694 (fps != vid_info->fps && fps + 1 != vid_info->fps)) 700 (fps != vid_info.fps && fps + 1 != vid_info.fps))
695 continue; 701 continue;
696 *timings = hdpvr_dv_timings[i]; 702 *timings = hdpvr_dv_timings[i];
697 break; 703 break;
698 } 704 }
699 if (i == ARRAY_SIZE(hdpvr_dv_timings)) 705 if (i == ARRAY_SIZE(hdpvr_dv_timings))
700 ret = -ERANGE; 706 ret = -ERANGE;
701 kfree(vid_info); 707
702 return ret; 708 return ret;
703} 709}
704 710
@@ -988,6 +994,7 @@ static int vidioc_g_fmt_vid_cap(struct file *file, void *_fh,
988{ 994{
989 struct hdpvr_device *dev = video_drvdata(file); 995 struct hdpvr_device *dev = video_drvdata(file);
990 struct hdpvr_fh *fh = _fh; 996 struct hdpvr_fh *fh = _fh;
997 int ret;
991 998
992 /* 999 /*
993 * The original driver would always returns the current detected 1000 * The original driver would always returns the current detected
@@ -1000,14 +1007,15 @@ static int vidioc_g_fmt_vid_cap(struct file *file, void *_fh,
1000 * last set format. 1007 * last set format.
1001 */ 1008 */
1002 if (fh->legacy_mode) { 1009 if (fh->legacy_mode) {
1003 struct hdpvr_video_info *vid_info; 1010 struct hdpvr_video_info vid_info;
1004 1011
1005 vid_info = get_video_info(dev); 1012 ret = get_video_info(dev, &vid_info);
1006 if (!vid_info) 1013 if (ret < 0)
1014 return ret;
1015 if (!vid_info.valid)
1007 return -EFAULT; 1016 return -EFAULT;
1008 f->fmt.pix.width = vid_info->width; 1017 f->fmt.pix.width = vid_info.width;
1009 f->fmt.pix.height = vid_info->height; 1018 f->fmt.pix.height = vid_info.height;
1010 kfree(vid_info);
1011 } else { 1019 } else {
1012 f->fmt.pix.width = dev->width; 1020 f->fmt.pix.width = dev->width;
1013 f->fmt.pix.height = dev->height; 1021 f->fmt.pix.height = dev->height;
diff --git a/drivers/media/usb/hdpvr/hdpvr.h b/drivers/media/usb/hdpvr/hdpvr.h
index 1478f3d57630..dc685d44cb3e 100644
--- a/drivers/media/usb/hdpvr/hdpvr.h
+++ b/drivers/media/usb/hdpvr/hdpvr.h
@@ -154,6 +154,7 @@ struct hdpvr_video_info {
154 u16 width; 154 u16 width;
155 u16 height; 155 u16 height;
156 u8 fps; 156 u8 fps;
157 bool valid;
157}; 158};
158 159
159enum { 160enum {
@@ -303,7 +304,7 @@ int hdpvr_set_audio(struct hdpvr_device *dev, u8 input,
303int hdpvr_config_call(struct hdpvr_device *dev, uint value, 304int hdpvr_config_call(struct hdpvr_device *dev, uint value,
304 unsigned char valbuf); 305 unsigned char valbuf);
305 306
306struct hdpvr_video_info *get_video_info(struct hdpvr_device *dev); 307int get_video_info(struct hdpvr_device *dev, struct hdpvr_video_info *vid_info);
307 308
308/* :0 s b8 81 1800 0003 0003 3 < */ 309/* :0 s b8 81 1800 0003 0003 3 < */
309/* :0 0 3 = 0301ff */ 310/* :0 0 3 = 0301ff */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-hdw.c b/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
index e11267f35d87..c4d51d78f837 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
@@ -2704,6 +2704,10 @@ static void pvr2_hdw_remove_usb_stuff(struct pvr2_hdw *hdw)
2704 pvr2_hdw_render_useless(hdw); 2704 pvr2_hdw_render_useless(hdw);
2705} 2705}
2706 2706
2707void pvr2_hdw_set_v4l2_dev(struct pvr2_hdw *hdw, struct video_device *vdev)
2708{
2709 vdev->v4l2_dev = &hdw->v4l2_dev;
2710}
2707 2711
2708/* Destroy hardware interaction structure */ 2712/* Destroy hardware interaction structure */
2709void pvr2_hdw_destroy(struct pvr2_hdw *hdw) 2713void pvr2_hdw_destroy(struct pvr2_hdw *hdw)
@@ -5162,41 +5166,3 @@ static int pvr2_hdw_get_eeprom_addr(struct pvr2_hdw *hdw)
5162 } while(0); LOCK_GIVE(hdw->ctl_lock); 5166 } while(0); LOCK_GIVE(hdw->ctl_lock);
5163 return result; 5167 return result;
5164} 5168}
5165
5166
5167int pvr2_hdw_register_access(struct pvr2_hdw *hdw,
5168 const struct v4l2_dbg_match *match, u64 reg_id,
5169 int setFl, u64 *val_ptr)
5170{
5171#ifdef CONFIG_VIDEO_ADV_DEBUG
5172 struct v4l2_dbg_register req;
5173 int stat = 0;
5174 int okFl = 0;
5175
5176 if (!capable(CAP_SYS_ADMIN)) return -EPERM;
5177
5178 req.match = *match;
5179 req.reg = reg_id;
5180 if (setFl) req.val = *val_ptr;
5181 /* It would be nice to know if a sub-device answered the request */
5182 v4l2_device_call_all(&hdw->v4l2_dev, 0, core, g_register, &req);
5183 if (!setFl) *val_ptr = req.val;
5184 if (okFl) {
5185 return stat;
5186 }
5187 return -EINVAL;
5188#else
5189 return -ENOSYS;
5190#endif
5191}
5192
5193
5194/*
5195 Stuff for Emacs to see, in order to encourage consistent editing style:
5196 *** Local Variables: ***
5197 *** mode: c ***
5198 *** fill-column: 75 ***
5199 *** tab-width: 8 ***
5200 *** c-basic-offset: 8 ***
5201 *** End: ***
5202 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-hdw.h b/drivers/media/usb/pvrusb2/pvrusb2-hdw.h
index 91bae930cd79..41847076f51a 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-hdw.h
+++ b/drivers/media/usb/pvrusb2/pvrusb2-hdw.h
@@ -22,6 +22,7 @@
22 22
23#include <linux/usb.h> 23#include <linux/usb.h>
24#include <linux/videodev2.h> 24#include <linux/videodev2.h>
25#include <media/v4l2-dev.h>
25#include "pvrusb2-io.h" 26#include "pvrusb2-io.h"
26#include "pvrusb2-ctrl.h" 27#include "pvrusb2-ctrl.h"
27 28
@@ -138,6 +139,9 @@ const char *pvr2_hdw_get_device_identifier(struct pvr2_hdw *);
138/* Called when hardware has been unplugged */ 139/* Called when hardware has been unplugged */
139void pvr2_hdw_disconnect(struct pvr2_hdw *); 140void pvr2_hdw_disconnect(struct pvr2_hdw *);
140 141
142/* Sets v4l2_dev of a video_device struct */
143void pvr2_hdw_set_v4l2_dev(struct pvr2_hdw *, struct video_device *);
144
141/* Get the number of defined controls */ 145/* Get the number of defined controls */
142unsigned int pvr2_hdw_get_ctrl_count(struct pvr2_hdw *); 146unsigned int pvr2_hdw_get_ctrl_count(struct pvr2_hdw *);
143 147
@@ -234,15 +238,6 @@ int pvr2_hdw_v4l_get_minor_number(struct pvr2_hdw *,enum pvr2_v4l_type index);
234void pvr2_hdw_v4l_store_minor_number(struct pvr2_hdw *, 238void pvr2_hdw_v4l_store_minor_number(struct pvr2_hdw *,
235 enum pvr2_v4l_type index,int); 239 enum pvr2_v4l_type index,int);
236 240
237/* Direct read/write access to chip's registers:
238 match - specify criteria to identify target chip (this is a v4l dbg struct)
239 reg_id - register number to access
240 setFl - true to set the register, false to read it
241 val_ptr - storage location for source / result. */
242int pvr2_hdw_register_access(struct pvr2_hdw *,
243 const struct v4l2_dbg_match *match, u64 reg_id,
244 int setFl, u64 *val_ptr);
245
246/* The following entry points are all lower level things you normally don't 241/* The following entry points are all lower level things you normally don't
247 want to worry about. */ 242 want to worry about. */
248 243
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-io.c b/drivers/media/usb/pvrusb2/pvrusb2-io.c
index 20b6ae0bb40d..1e354747de3f 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-io.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-io.c
@@ -354,9 +354,9 @@ static int pvr2_stream_buffer_count(struct pvr2_stream *sp,unsigned int cnt)
354 if (scnt < sp->buffer_slot_count) { 354 if (scnt < sp->buffer_slot_count) {
355 struct pvr2_buffer **nb = NULL; 355 struct pvr2_buffer **nb = NULL;
356 if (scnt) { 356 if (scnt) {
357 nb = kmalloc(scnt * sizeof(*nb),GFP_KERNEL); 357 nb = kmemdup(sp->buffers, scnt * sizeof(*nb),
358 GFP_KERNEL);
358 if (!nb) return -ENOMEM; 359 if (!nb) return -ENOMEM;
359 memcpy(nb,sp->buffers,scnt * sizeof(*nb));
360 } 360 }
361 kfree(sp->buffers); 361 kfree(sp->buffers);
362 sp->buffers = nb; 362 sp->buffers = nb;
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c b/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c
index a8a65fa57930..7c280f35eea9 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c
@@ -31,6 +31,7 @@
31#include <linux/videodev2.h> 31#include <linux/videodev2.h>
32#include <linux/module.h> 32#include <linux/module.h>
33#include <media/v4l2-dev.h> 33#include <media/v4l2-dev.h>
34#include <media/v4l2-device.h>
34#include <media/v4l2-common.h> 35#include <media/v4l2-common.h>
35#include <media/v4l2-ioctl.h> 36#include <media/v4l2-ioctl.h>
36 37
@@ -800,36 +801,6 @@ static int pvr2_log_status(struct file *file, void *priv)
800 return 0; 801 return 0;
801} 802}
802 803
803#ifdef CONFIG_VIDEO_ADV_DEBUG
804static int pvr2_g_register(struct file *file, void *priv, struct v4l2_dbg_register *req)
805{
806 struct pvr2_v4l2_fh *fh = file->private_data;
807 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
808 u64 val;
809 int ret;
810
811 ret = pvr2_hdw_register_access(
812 hdw, &req->match, req->reg,
813 0, &val);
814 req->val = val;
815 return ret;
816}
817
818static int pvr2_s_register(struct file *file, void *priv, const struct v4l2_dbg_register *req)
819{
820 struct pvr2_v4l2_fh *fh = file->private_data;
821 struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
822 u64 val;
823 int ret;
824
825 val = req->val;
826 ret = pvr2_hdw_register_access(
827 hdw, &req->match, req->reg,
828 1, &val);
829 return ret;
830}
831#endif
832
833static const struct v4l2_ioctl_ops pvr2_ioctl_ops = { 804static const struct v4l2_ioctl_ops pvr2_ioctl_ops = {
834 .vidioc_querycap = pvr2_querycap, 805 .vidioc_querycap = pvr2_querycap,
835 .vidioc_g_priority = pvr2_g_priority, 806 .vidioc_g_priority = pvr2_g_priority,
@@ -864,10 +835,6 @@ static const struct v4l2_ioctl_ops pvr2_ioctl_ops = {
864 .vidioc_g_ext_ctrls = pvr2_g_ext_ctrls, 835 .vidioc_g_ext_ctrls = pvr2_g_ext_ctrls,
865 .vidioc_s_ext_ctrls = pvr2_s_ext_ctrls, 836 .vidioc_s_ext_ctrls = pvr2_s_ext_ctrls,
866 .vidioc_try_ext_ctrls = pvr2_try_ext_ctrls, 837 .vidioc_try_ext_ctrls = pvr2_try_ext_ctrls,
867#ifdef CONFIG_VIDEO_ADV_DEBUG
868 .vidioc_g_register = pvr2_g_register,
869 .vidioc_s_register = pvr2_s_register,
870#endif
871}; 838};
872 839
873static void pvr2_v4l2_dev_destroy(struct pvr2_v4l2_dev *dip) 840static void pvr2_v4l2_dev_destroy(struct pvr2_v4l2_dev *dip)
@@ -904,8 +871,8 @@ static void pvr2_v4l2_dev_destroy(struct pvr2_v4l2_dev *dip)
904static void pvr2_v4l2_dev_disassociate_parent(struct pvr2_v4l2_dev *dip) 871static void pvr2_v4l2_dev_disassociate_parent(struct pvr2_v4l2_dev *dip)
905{ 872{
906 if (!dip) return; 873 if (!dip) return;
907 if (!dip->devbase.parent) return; 874 if (!dip->devbase.v4l2_dev->dev) return;
908 dip->devbase.parent = NULL; 875 dip->devbase.v4l2_dev->dev = NULL;
909 device_move(&dip->devbase.dev, NULL, DPM_ORDER_NONE); 876 device_move(&dip->devbase.dev, NULL, DPM_ORDER_NONE);
910} 877}
911 878
@@ -1298,7 +1265,6 @@ static void pvr2_v4l2_dev_init(struct pvr2_v4l2_dev *dip,
1298 struct pvr2_v4l2 *vp, 1265 struct pvr2_v4l2 *vp,
1299 int v4l_type) 1266 int v4l_type)
1300{ 1267{
1301 struct usb_device *usbdev;
1302 int mindevnum; 1268 int mindevnum;
1303 int unit_number; 1269 int unit_number;
1304 struct pvr2_hdw *hdw; 1270 struct pvr2_hdw *hdw;
@@ -1306,7 +1272,6 @@ static void pvr2_v4l2_dev_init(struct pvr2_v4l2_dev *dip,
1306 dip->v4lp = vp; 1272 dip->v4lp = vp;
1307 1273
1308 hdw = vp->channel.mc_head->hdw; 1274 hdw = vp->channel.mc_head->hdw;
1309 usbdev = pvr2_hdw_get_dev(hdw);
1310 dip->v4l_type = v4l_type; 1275 dip->v4l_type = v4l_type;
1311 switch (v4l_type) { 1276 switch (v4l_type) {
1312 case VFL_TYPE_GRABBER: 1277 case VFL_TYPE_GRABBER:
@@ -1355,7 +1320,7 @@ static void pvr2_v4l2_dev_init(struct pvr2_v4l2_dev *dip,
1355 if (nr_ptr && (unit_number >= 0) && (unit_number < PVR_NUM)) { 1320 if (nr_ptr && (unit_number >= 0) && (unit_number < PVR_NUM)) {
1356 mindevnum = nr_ptr[unit_number]; 1321 mindevnum = nr_ptr[unit_number];
1357 } 1322 }
1358 dip->devbase.parent = &usbdev->dev; 1323 pvr2_hdw_set_v4l2_dev(hdw, &dip->devbase);
1359 if ((video_register_device(&dip->devbase, 1324 if ((video_register_device(&dip->devbase,
1360 dip->v4l_type, mindevnum) < 0) && 1325 dip->v4l_type, mindevnum) < 0) &&
1361 (video_register_device(&dip->devbase, 1326 (video_register_device(&dip->devbase,
diff --git a/drivers/media/usb/sn9c102/sn9c102.h b/drivers/media/usb/sn9c102/sn9c102.h
index 2bc153e869be..8a917f060503 100644
--- a/drivers/media/usb/sn9c102/sn9c102.h
+++ b/drivers/media/usb/sn9c102/sn9c102.h
@@ -25,6 +25,7 @@
25#include <linux/videodev2.h> 25#include <linux/videodev2.h>
26#include <media/v4l2-common.h> 26#include <media/v4l2-common.h>
27#include <media/v4l2-ioctl.h> 27#include <media/v4l2-ioctl.h>
28#include <media/v4l2-device.h>
28#include <linux/device.h> 29#include <linux/device.h>
29#include <linux/list.h> 30#include <linux/list.h>
30#include <linux/spinlock.h> 31#include <linux/spinlock.h>
@@ -100,6 +101,8 @@ static DECLARE_RWSEM(sn9c102_dev_lock);
100struct sn9c102_device { 101struct sn9c102_device {
101 struct video_device* v4ldev; 102 struct video_device* v4ldev;
102 103
104 struct v4l2_device v4l2_dev;
105
103 enum sn9c102_bridge bridge; 106 enum sn9c102_bridge bridge;
104 struct sn9c102_sensor sensor; 107 struct sn9c102_sensor sensor;
105 108
diff --git a/drivers/media/usb/sn9c102/sn9c102_core.c b/drivers/media/usb/sn9c102/sn9c102_core.c
index c957e9aa6077..2cb44de2b92c 100644
--- a/drivers/media/usb/sn9c102/sn9c102_core.c
+++ b/drivers/media/usb/sn9c102/sn9c102_core.c
@@ -1737,6 +1737,7 @@ static void sn9c102_release_resources(struct kref *kref)
1737 video_device_node_name(cam->v4ldev)); 1737 video_device_node_name(cam->v4ldev));
1738 video_set_drvdata(cam->v4ldev, NULL); 1738 video_set_drvdata(cam->v4ldev, NULL);
1739 video_unregister_device(cam->v4ldev); 1739 video_unregister_device(cam->v4ldev);
1740 v4l2_device_unregister(&cam->v4l2_dev);
1740 usb_put_dev(cam->usbdev); 1741 usb_put_dev(cam->usbdev);
1741 kfree(cam->control_buffer); 1742 kfree(cam->control_buffer);
1742 kfree(cam); 1743 kfree(cam);
@@ -3254,6 +3255,13 @@ sn9c102_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
3254 3255
3255 cam->usbdev = udev; 3256 cam->usbdev = udev;
3256 3257
3258 /* register v4l2_device early so it can be used for printks */
3259 if (v4l2_device_register(&intf->dev, &cam->v4l2_dev)) {
3260 dev_err(&intf->dev, "v4l2_device_register failed\n");
3261 err = -ENOMEM;
3262 goto fail;
3263 }
3264
3257 if (!(cam->control_buffer = kzalloc(8, GFP_KERNEL))) { 3265 if (!(cam->control_buffer = kzalloc(8, GFP_KERNEL))) {
3258 DBG(1, "kzalloc() failed"); 3266 DBG(1, "kzalloc() failed");
3259 err = -ENOMEM; 3267 err = -ENOMEM;
@@ -3325,7 +3333,7 @@ sn9c102_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
3325 strcpy(cam->v4ldev->name, "SN9C1xx PC Camera"); 3333 strcpy(cam->v4ldev->name, "SN9C1xx PC Camera");
3326 cam->v4ldev->fops = &sn9c102_fops; 3334 cam->v4ldev->fops = &sn9c102_fops;
3327 cam->v4ldev->release = video_device_release; 3335 cam->v4ldev->release = video_device_release;
3328 cam->v4ldev->parent = &udev->dev; 3336 cam->v4ldev->v4l2_dev = &cam->v4l2_dev;
3329 3337
3330 init_completion(&cam->probe); 3338 init_completion(&cam->probe);
3331 3339
@@ -3377,6 +3385,7 @@ fail:
3377 kfree(cam->control_buffer); 3385 kfree(cam->control_buffer);
3378 if (cam->v4ldev) 3386 if (cam->v4ldev)
3379 video_device_release(cam->v4ldev); 3387 video_device_release(cam->v4ldev);
3388 v4l2_device_unregister(&cam->v4l2_dev);
3380 kfree(cam); 3389 kfree(cam);
3381 } 3390 }
3382 return err; 3391 return err;
@@ -3407,6 +3416,8 @@ static void sn9c102_usb_disconnect(struct usb_interface* intf)
3407 3416
3408 wake_up_interruptible_all(&cam->wait_open); 3417 wake_up_interruptible_all(&cam->wait_open);
3409 3418
3419 v4l2_device_disconnect(&cam->v4l2_dev);
3420
3410 kref_put(&cam->kref, sn9c102_release_resources); 3421 kref_put(&cam->kref, sn9c102_release_resources);
3411 3422
3412 up_write(&sn9c102_dev_lock); 3423 up_write(&sn9c102_dev_lock);
diff --git a/drivers/media/usb/stk1160/stk1160-v4l.c b/drivers/media/usb/stk1160/stk1160-v4l.c
index a59153d2f8bf..876fc26565e3 100644
--- a/drivers/media/usb/stk1160/stk1160-v4l.c
+++ b/drivers/media/usb/stk1160/stk1160-v4l.c
@@ -31,7 +31,6 @@
31#include <media/v4l2-ioctl.h> 31#include <media/v4l2-ioctl.h>
32#include <media/v4l2-fh.h> 32#include <media/v4l2-fh.h>
33#include <media/v4l2-event.h> 33#include <media/v4l2-event.h>
34#include <media/v4l2-chip-ident.h>
35#include <media/videobuf2-vmalloc.h> 34#include <media/videobuf2-vmalloc.h>
36 35
37#include <media/saa7115.h> 36#include <media/saa7115.h>
@@ -454,19 +453,6 @@ static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
454 return 0; 453 return 0;
455} 454}
456 455
457static int vidioc_g_chip_ident(struct file *file, void *priv,
458 struct v4l2_dbg_chip_ident *chip)
459{
460 switch (chip->match.type) {
461 case V4L2_CHIP_MATCH_BRIDGE:
462 chip->ident = V4L2_IDENT_NONE;
463 chip->revision = 0;
464 return 0;
465 default:
466 return -EINVAL;
467 }
468}
469
470#ifdef CONFIG_VIDEO_ADV_DEBUG 456#ifdef CONFIG_VIDEO_ADV_DEBUG
471static int vidioc_g_register(struct file *file, void *priv, 457static int vidioc_g_register(struct file *file, void *priv,
472 struct v4l2_dbg_register *reg) 458 struct v4l2_dbg_register *reg)
@@ -475,19 +461,6 @@ static int vidioc_g_register(struct file *file, void *priv,
475 int rc; 461 int rc;
476 u8 val; 462 u8 val;
477 463
478 switch (reg->match.type) {
479 case V4L2_CHIP_MATCH_I2C_DRIVER:
480 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_register, reg);
481 return 0;
482 case V4L2_CHIP_MATCH_I2C_ADDR:
483 /* TODO: is this correct? */
484 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_register, reg);
485 return 0;
486 default:
487 if (!v4l2_chip_match_host(&reg->match))
488 return -EINVAL;
489 }
490
491 /* Match host */ 464 /* Match host */
492 rc = stk1160_read_reg(dev, reg->reg, &val); 465 rc = stk1160_read_reg(dev, reg->reg, &val);
493 reg->val = val; 466 reg->val = val;
@@ -501,19 +474,6 @@ static int vidioc_s_register(struct file *file, void *priv,
501{ 474{
502 struct stk1160 *dev = video_drvdata(file); 475 struct stk1160 *dev = video_drvdata(file);
503 476
504 switch (reg->match.type) {
505 case V4L2_CHIP_MATCH_I2C_DRIVER:
506 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_register, reg);
507 return 0;
508 case V4L2_CHIP_MATCH_I2C_ADDR:
509 /* TODO: is this correct? */
510 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_register, reg);
511 return 0;
512 default:
513 if (!v4l2_chip_match_host(&reg->match))
514 return -EINVAL;
515 }
516
517 /* Match host */ 477 /* Match host */
518 return stk1160_write_reg(dev, reg->reg, cpu_to_le16(reg->val)); 478 return stk1160_write_reg(dev, reg->reg, cpu_to_le16(reg->val));
519} 479}
@@ -543,7 +503,6 @@ static const struct v4l2_ioctl_ops stk1160_ioctl_ops = {
543 .vidioc_log_status = v4l2_ctrl_log_status, 503 .vidioc_log_status = v4l2_ctrl_log_status,
544 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, 504 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
545 .vidioc_unsubscribe_event = v4l2_event_unsubscribe, 505 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
546 .vidioc_g_chip_ident = vidioc_g_chip_ident,
547 506
548#ifdef CONFIG_VIDEO_ADV_DEBUG 507#ifdef CONFIG_VIDEO_ADV_DEBUG
549 .vidioc_g_register = vidioc_g_register, 508 .vidioc_g_register = vidioc_g_register,
diff --git a/drivers/media/usb/tm6000/tm6000-cards.c b/drivers/media/usb/tm6000/tm6000-cards.c
index 307d8c5fb7cd..1ccaaddaa307 100644
--- a/drivers/media/usb/tm6000/tm6000-cards.c
+++ b/drivers/media/usb/tm6000/tm6000-cards.c
@@ -1114,7 +1114,7 @@ static int tm6000_init_dev(struct tm6000_core *dev)
1114 /* Default values for STD and resolutions */ 1114 /* Default values for STD and resolutions */
1115 dev->width = 720; 1115 dev->width = 720;
1116 dev->height = 480; 1116 dev->height = 480;
1117 dev->norm = V4L2_STD_PAL_M; 1117 dev->norm = V4L2_STD_NTSC_M;
1118 1118
1119 /* Configure tuner */ 1119 /* Configure tuner */
1120 tm6000_config_tuner(dev); 1120 tm6000_config_tuner(dev);
diff --git a/drivers/media/usb/tm6000/tm6000-video.c b/drivers/media/usb/tm6000/tm6000-video.c
index a78de1d1bc9e..cc1aa14996ff 100644
--- a/drivers/media/usb/tm6000/tm6000-video.c
+++ b/drivers/media/usb/tm6000/tm6000-video.c
@@ -1076,6 +1076,15 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id norm)
1076 return 0; 1076 return 0;
1077} 1077}
1078 1078
1079static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *norm)
1080{
1081 struct tm6000_fh *fh = priv;
1082 struct tm6000_core *dev = fh->dev;
1083
1084 *norm = dev->norm;
1085 return 0;
1086}
1087
1079static const char *iname[] = { 1088static const char *iname[] = {
1080 [TM6000_INPUT_TV] = "Television", 1089 [TM6000_INPUT_TV] = "Television",
1081 [TM6000_INPUT_COMPOSITE1] = "Composite 1", 1090 [TM6000_INPUT_COMPOSITE1] = "Composite 1",
@@ -1134,7 +1143,7 @@ static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
1134 1143
1135 dev->input = i; 1144 dev->input = i;
1136 1145
1137 rc = vidioc_s_std(file, priv, dev->vfd->current_norm); 1146 rc = vidioc_s_std(file, priv, dev->norm);
1138 1147
1139 return rc; 1148 return rc;
1140} 1149}
@@ -1547,6 +1556,7 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
1547 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap, 1556 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
1548 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, 1557 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
1549 .vidioc_s_std = vidioc_s_std, 1558 .vidioc_s_std = vidioc_s_std,
1559 .vidioc_g_std = vidioc_g_std,
1550 .vidioc_enum_input = vidioc_enum_input, 1560 .vidioc_enum_input = vidioc_enum_input,
1551 .vidioc_g_input = vidioc_g_input, 1561 .vidioc_g_input = vidioc_g_input,
1552 .vidioc_s_input = vidioc_s_input, 1562 .vidioc_s_input = vidioc_s_input,
@@ -1570,7 +1580,6 @@ static struct video_device tm6000_template = {
1570 .ioctl_ops = &video_ioctl_ops, 1580 .ioctl_ops = &video_ioctl_ops,
1571 .release = video_device_release, 1581 .release = video_device_release,
1572 .tvnorms = TM6000_STD, 1582 .tvnorms = TM6000_STD,
1573 .current_norm = V4L2_STD_NTSC_M,
1574}; 1583};
1575 1584
1576static const struct v4l2_file_operations radio_fops = { 1585static const struct v4l2_file_operations radio_fops = {
diff --git a/drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c b/drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c
index 21b9049c7b3f..f8a60c197534 100644
--- a/drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c
+++ b/drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c
@@ -1768,6 +1768,8 @@ err_i2c_del_adapter:
1768 i2c_del_adapter(&ttusb->i2c_adap); 1768 i2c_del_adapter(&ttusb->i2c_adap);
1769err_unregister_adapter: 1769err_unregister_adapter:
1770 dvb_unregister_adapter (&ttusb->adapter); 1770 dvb_unregister_adapter (&ttusb->adapter);
1771 ttusb_free_iso_urbs(ttusb);
1772 kfree(ttusb);
1771 return result; 1773 return result;
1772} 1774}
1773 1775
diff --git a/drivers/media/usb/usbtv/Kconfig b/drivers/media/usb/usbtv/Kconfig
new file mode 100644
index 000000000000..8864436464bf
--- /dev/null
+++ b/drivers/media/usb/usbtv/Kconfig
@@ -0,0 +1,10 @@
1config VIDEO_USBTV
2 tristate "USBTV007 video capture support"
3 depends on VIDEO_DEV
4 select VIDEOBUF2_VMALLOC
5
6 ---help---
7 This is a video4linux2 driver for USBTV007 based video capture devices.
8
9 To compile this driver as a module, choose M here: the
10 module will be called usbtv
diff --git a/drivers/media/usb/usbtv/Makefile b/drivers/media/usb/usbtv/Makefile
new file mode 100644
index 000000000000..28b872fa94e1
--- /dev/null
+++ b/drivers/media/usb/usbtv/Makefile
@@ -0,0 +1 @@
obj-$(CONFIG_VIDEO_USBTV) += usbtv.o
diff --git a/drivers/media/usb/usbtv/usbtv.c b/drivers/media/usb/usbtv/usbtv.c
new file mode 100644
index 000000000000..bf43f874685e
--- /dev/null
+++ b/drivers/media/usb/usbtv/usbtv.c
@@ -0,0 +1,696 @@
1/*
2 * Fushicai USBTV007 Video Grabber Driver
3 *
4 * Product web site:
5 * http://www.fushicai.com/products_detail/&productId=d05449ee-b690-42f9-a661-aa7353894bed.html
6 *
7 * Following LWN articles were very useful in construction of this driver:
8 * Video4Linux2 API series: http://lwn.net/Articles/203924/
9 * videobuf2 API explanation: http://lwn.net/Articles/447435/
10 * Thanks go to Jonathan Corbet for providing this quality documentation.
11 * He is awesome.
12 *
13 * Copyright (c) 2013 Lubomir Rintel
14 * All rights reserved.
15 * No physical hardware was harmed running Windows during the
16 * reverse-engineering activity
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
20 * are met:
21 * 1. Redistributions of source code must retain the above copyright
22 * notice, this list of conditions, and the following disclaimer,
23 * without modification.
24 * 2. The name of the author may not be used to endorse or promote products
25 * derived from this software without specific prior written permission.
26 *
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL").
29 */
30
31#include <linux/init.h>
32#include <linux/list.h>
33#include <linux/module.h>
34#include <linux/slab.h>
35#include <linux/usb.h>
36#include <linux/version.h>
37#include <linux/videodev2.h>
38
39#include <media/v4l2-device.h>
40#include <media/v4l2-ioctl.h>
41#include <media/videobuf2-core.h>
42#include <media/videobuf2-vmalloc.h>
43
44/* Hardware. */
45#define USBTV_VIDEO_ENDP 0x81
46#define USBTV_BASE 0xc000
47#define USBTV_REQUEST_REG 12
48
49/* Number of concurrent isochronous urbs submitted.
50 * Higher numbers was seen to overly saturate the USB bus. */
51#define USBTV_ISOC_TRANSFERS 16
52#define USBTV_ISOC_PACKETS 8
53
54#define USBTV_WIDTH 720
55#define USBTV_HEIGHT 480
56
57#define USBTV_CHUNK_SIZE 256
58#define USBTV_CHUNK 240
59#define USBTV_CHUNKS (USBTV_WIDTH * USBTV_HEIGHT \
60 / 2 / USBTV_CHUNK)
61
62/* Chunk header. */
63#define USBTV_MAGIC_OK(chunk) ((be32_to_cpu(chunk[0]) & 0xff000000) \
64 == 0x88000000)
65#define USBTV_FRAME_ID(chunk) ((be32_to_cpu(chunk[0]) & 0x00ff0000) >> 16)
66#define USBTV_ODD(chunk) ((be32_to_cpu(chunk[0]) & 0x0000f000) >> 15)
67#define USBTV_CHUNK_NO(chunk) (be32_to_cpu(chunk[0]) & 0x00000fff)
68
69/* A single videobuf2 frame buffer. */
70struct usbtv_buf {
71 struct vb2_buffer vb;
72 struct list_head list;
73};
74
75/* Per-device structure. */
76struct usbtv {
77 struct device *dev;
78 struct usb_device *udev;
79 struct v4l2_device v4l2_dev;
80 struct video_device vdev;
81 struct vb2_queue vb2q;
82 struct mutex v4l2_lock;
83 struct mutex vb2q_lock;
84
85 /* List of videobuf2 buffers protected by a lock. */
86 spinlock_t buflock;
87 struct list_head bufs;
88
89 /* Number of currently processed frame, useful find
90 * out when a new one begins. */
91 u32 frame_id;
92
93 int iso_size;
94 unsigned int sequence;
95 struct urb *isoc_urbs[USBTV_ISOC_TRANSFERS];
96};
97
98static int usbtv_setup_capture(struct usbtv *usbtv)
99{
100 int ret;
101 int pipe = usb_rcvctrlpipe(usbtv->udev, 0);
102 int i;
103 static const u16 protoregs[][2] = {
104 /* These seem to enable the device. */
105 { USBTV_BASE + 0x0008, 0x0001 },
106 { USBTV_BASE + 0x01d0, 0x00ff },
107 { USBTV_BASE + 0x01d9, 0x0002 },
108
109 /* These seem to influence color parameters, such as
110 * brightness, etc. */
111 { USBTV_BASE + 0x0239, 0x0040 },
112 { USBTV_BASE + 0x0240, 0x0000 },
113 { USBTV_BASE + 0x0241, 0x0000 },
114 { USBTV_BASE + 0x0242, 0x0002 },
115 { USBTV_BASE + 0x0243, 0x0080 },
116 { USBTV_BASE + 0x0244, 0x0012 },
117 { USBTV_BASE + 0x0245, 0x0090 },
118 { USBTV_BASE + 0x0246, 0x0000 },
119
120 { USBTV_BASE + 0x0278, 0x002d },
121 { USBTV_BASE + 0x0279, 0x000a },
122 { USBTV_BASE + 0x027a, 0x0032 },
123 { 0xf890, 0x000c },
124 { 0xf894, 0x0086 },
125
126 { USBTV_BASE + 0x00ac, 0x00c0 },
127 { USBTV_BASE + 0x00ad, 0x0000 },
128 { USBTV_BASE + 0x00a2, 0x0012 },
129 { USBTV_BASE + 0x00a3, 0x00e0 },
130 { USBTV_BASE + 0x00a4, 0x0028 },
131 { USBTV_BASE + 0x00a5, 0x0082 },
132 { USBTV_BASE + 0x00a7, 0x0080 },
133 { USBTV_BASE + 0x0000, 0x0014 },
134 { USBTV_BASE + 0x0006, 0x0003 },
135 { USBTV_BASE + 0x0090, 0x0099 },
136 { USBTV_BASE + 0x0091, 0x0090 },
137 { USBTV_BASE + 0x0094, 0x0068 },
138 { USBTV_BASE + 0x0095, 0x0070 },
139 { USBTV_BASE + 0x009c, 0x0030 },
140 { USBTV_BASE + 0x009d, 0x00c0 },
141 { USBTV_BASE + 0x009e, 0x00e0 },
142 { USBTV_BASE + 0x0019, 0x0006 },
143 { USBTV_BASE + 0x008c, 0x00ba },
144 { USBTV_BASE + 0x0101, 0x00ff },
145 { USBTV_BASE + 0x010c, 0x00b3 },
146 { USBTV_BASE + 0x01b2, 0x0080 },
147 { USBTV_BASE + 0x01b4, 0x00a0 },
148 { USBTV_BASE + 0x014c, 0x00ff },
149 { USBTV_BASE + 0x014d, 0x00ca },
150 { USBTV_BASE + 0x0113, 0x0053 },
151 { USBTV_BASE + 0x0119, 0x008a },
152 { USBTV_BASE + 0x013c, 0x0003 },
153 { USBTV_BASE + 0x0150, 0x009c },
154 { USBTV_BASE + 0x0151, 0x0071 },
155 { USBTV_BASE + 0x0152, 0x00c6 },
156 { USBTV_BASE + 0x0153, 0x0084 },
157 { USBTV_BASE + 0x0154, 0x00bc },
158 { USBTV_BASE + 0x0155, 0x00a0 },
159 { USBTV_BASE + 0x0156, 0x00a0 },
160 { USBTV_BASE + 0x0157, 0x009c },
161 { USBTV_BASE + 0x0158, 0x001f },
162 { USBTV_BASE + 0x0159, 0x0006 },
163 { USBTV_BASE + 0x015d, 0x0000 },
164
165 { USBTV_BASE + 0x0284, 0x0088 },
166 { USBTV_BASE + 0x0003, 0x0004 },
167 { USBTV_BASE + 0x001a, 0x0079 },
168 { USBTV_BASE + 0x0100, 0x00d3 },
169 { USBTV_BASE + 0x010e, 0x0068 },
170 { USBTV_BASE + 0x010f, 0x009c },
171 { USBTV_BASE + 0x0112, 0x00f0 },
172 { USBTV_BASE + 0x0115, 0x0015 },
173 { USBTV_BASE + 0x0117, 0x0000 },
174 { USBTV_BASE + 0x0118, 0x00fc },
175 { USBTV_BASE + 0x012d, 0x0004 },
176 { USBTV_BASE + 0x012f, 0x0008 },
177 { USBTV_BASE + 0x0220, 0x002e },
178 { USBTV_BASE + 0x0225, 0x0008 },
179 { USBTV_BASE + 0x024e, 0x0002 },
180 { USBTV_BASE + 0x024f, 0x0001 },
181 { USBTV_BASE + 0x0254, 0x005f },
182 { USBTV_BASE + 0x025a, 0x0012 },
183 { USBTV_BASE + 0x025b, 0x0001 },
184 { USBTV_BASE + 0x0263, 0x001c },
185 { USBTV_BASE + 0x0266, 0x0011 },
186 { USBTV_BASE + 0x0267, 0x0005 },
187 { USBTV_BASE + 0x024e, 0x0002 },
188 { USBTV_BASE + 0x024f, 0x0002 },
189 };
190
191 for (i = 0; i < ARRAY_SIZE(protoregs); i++) {
192 u16 index = protoregs[i][0];
193 u16 value = protoregs[i][1];
194
195 ret = usb_control_msg(usbtv->udev, pipe, USBTV_REQUEST_REG,
196 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
197 value, index, NULL, 0, 0);
198 if (ret < 0)
199 return ret;
200 }
201
202 return 0;
203}
204
205/* Called for each 256-byte image chunk.
206 * First word identifies the chunk, followed by 240 words of image
207 * data and padding. */
208static void usbtv_image_chunk(struct usbtv *usbtv, u32 *chunk)
209{
210 int frame_id, odd, chunk_no;
211 u32 *frame;
212 struct usbtv_buf *buf;
213 unsigned long flags;
214
215 /* Ignore corrupted lines. */
216 if (!USBTV_MAGIC_OK(chunk))
217 return;
218 frame_id = USBTV_FRAME_ID(chunk);
219 odd = USBTV_ODD(chunk);
220 chunk_no = USBTV_CHUNK_NO(chunk);
221
222 /* Deinterlace. TODO: Use interlaced frame format. */
223 chunk_no = (chunk_no - chunk_no % 3) * 2 + chunk_no % 3;
224 chunk_no += !odd * 3;
225
226 if (chunk_no >= USBTV_CHUNKS)
227 return;
228
229 /* Beginning of a frame. */
230 if (chunk_no == 0)
231 usbtv->frame_id = frame_id;
232
233 spin_lock_irqsave(&usbtv->buflock, flags);
234 if (list_empty(&usbtv->bufs)) {
235 /* No free buffers. Userspace likely too slow. */
236 spin_unlock_irqrestore(&usbtv->buflock, flags);
237 return;
238 }
239
240 /* First available buffer. */
241 buf = list_first_entry(&usbtv->bufs, struct usbtv_buf, list);
242 frame = vb2_plane_vaddr(&buf->vb, 0);
243
244 /* Copy the chunk. */
245 memcpy(&frame[chunk_no * USBTV_CHUNK], &chunk[1],
246 USBTV_CHUNK * sizeof(chunk[1]));
247
248 /* Last chunk in a frame, signalling an end */
249 if (usbtv->frame_id && chunk_no == USBTV_CHUNKS-1) {
250 int size = vb2_plane_size(&buf->vb, 0);
251
252 buf->vb.v4l2_buf.field = V4L2_FIELD_INTERLACED;
253 buf->vb.v4l2_buf.sequence = usbtv->sequence++;
254 v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp);
255 vb2_set_plane_payload(&buf->vb, 0, size);
256 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_DONE);
257 list_del(&buf->list);
258 }
259
260 spin_unlock_irqrestore(&usbtv->buflock, flags);
261}
262
263/* Got image data. Each packet contains a number of 256-word chunks we
264 * compose the image from. */
265static void usbtv_iso_cb(struct urb *ip)
266{
267 int ret;
268 int i;
269 struct usbtv *usbtv = (struct usbtv *)ip->context;
270
271 switch (ip->status) {
272 /* All fine. */
273 case 0:
274 break;
275 /* Device disconnected or capture stopped? */
276 case -ENODEV:
277 case -ENOENT:
278 case -ECONNRESET:
279 case -ESHUTDOWN:
280 return;
281 /* Unknown error. Retry. */
282 default:
283 dev_warn(usbtv->dev, "Bad response for ISO request.\n");
284 goto resubmit;
285 }
286
287 for (i = 0; i < ip->number_of_packets; i++) {
288 int size = ip->iso_frame_desc[i].actual_length;
289 unsigned char *data = ip->transfer_buffer +
290 ip->iso_frame_desc[i].offset;
291 int offset;
292
293 for (offset = 0; USBTV_CHUNK_SIZE * offset < size; offset++)
294 usbtv_image_chunk(usbtv,
295 (u32 *)&data[USBTV_CHUNK_SIZE * offset]);
296 }
297
298resubmit:
299 ret = usb_submit_urb(ip, GFP_ATOMIC);
300 if (ret < 0)
301 dev_warn(usbtv->dev, "Could not resubmit ISO URB\n");
302}
303
304static struct urb *usbtv_setup_iso_transfer(struct usbtv *usbtv)
305{
306 struct urb *ip;
307 int size = usbtv->iso_size;
308 int i;
309
310 ip = usb_alloc_urb(USBTV_ISOC_PACKETS, GFP_KERNEL);
311 if (ip == NULL)
312 return NULL;
313
314 ip->dev = usbtv->udev;
315 ip->context = usbtv;
316 ip->pipe = usb_rcvisocpipe(usbtv->udev, USBTV_VIDEO_ENDP);
317 ip->interval = 1;
318 ip->transfer_flags = URB_ISO_ASAP;
319 ip->transfer_buffer = kzalloc(size * USBTV_ISOC_PACKETS,
320 GFP_KERNEL);
321 ip->complete = usbtv_iso_cb;
322 ip->number_of_packets = USBTV_ISOC_PACKETS;
323 ip->transfer_buffer_length = size * USBTV_ISOC_PACKETS;
324 for (i = 0; i < USBTV_ISOC_PACKETS; i++) {
325 ip->iso_frame_desc[i].offset = size * i;
326 ip->iso_frame_desc[i].length = size;
327 }
328
329 return ip;
330}
331
332static void usbtv_stop(struct usbtv *usbtv)
333{
334 int i;
335 unsigned long flags;
336
337 /* Cancel running transfers. */
338 for (i = 0; i < USBTV_ISOC_TRANSFERS; i++) {
339 struct urb *ip = usbtv->isoc_urbs[i];
340 if (ip == NULL)
341 continue;
342 usb_kill_urb(ip);
343 kfree(ip->transfer_buffer);
344 usb_free_urb(ip);
345 usbtv->isoc_urbs[i] = NULL;
346 }
347
348 /* Return buffers to userspace. */
349 spin_lock_irqsave(&usbtv->buflock, flags);
350 while (!list_empty(&usbtv->bufs)) {
351 struct usbtv_buf *buf = list_first_entry(&usbtv->bufs,
352 struct usbtv_buf, list);
353 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
354 list_del(&buf->list);
355 }
356 spin_unlock_irqrestore(&usbtv->buflock, flags);
357}
358
359static int usbtv_start(struct usbtv *usbtv)
360{
361 int i;
362 int ret;
363
364 ret = usb_set_interface(usbtv->udev, 0, 0);
365 if (ret < 0)
366 return ret;
367
368 ret = usbtv_setup_capture(usbtv);
369 if (ret < 0)
370 return ret;
371
372 ret = usb_set_interface(usbtv->udev, 0, 1);
373 if (ret < 0)
374 return ret;
375
376 for (i = 0; i < USBTV_ISOC_TRANSFERS; i++) {
377 struct urb *ip;
378
379 ip = usbtv_setup_iso_transfer(usbtv);
380 if (ip == NULL) {
381 ret = -ENOMEM;
382 goto start_fail;
383 }
384 usbtv->isoc_urbs[i] = ip;
385
386 ret = usb_submit_urb(ip, GFP_KERNEL);
387 if (ret < 0)
388 goto start_fail;
389 }
390
391 return 0;
392
393start_fail:
394 usbtv_stop(usbtv);
395 return ret;
396}
397
398struct usb_device_id usbtv_id_table[] = {
399 { USB_DEVICE(0x1b71, 0x3002) },
400 {}
401};
402MODULE_DEVICE_TABLE(usb, usbtv_id_table);
403
404static int usbtv_querycap(struct file *file, void *priv,
405 struct v4l2_capability *cap)
406{
407 struct usbtv *dev = video_drvdata(file);
408
409 strlcpy(cap->driver, "usbtv", sizeof(cap->driver));
410 strlcpy(cap->card, "usbtv", sizeof(cap->card));
411 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info));
412 cap->device_caps = V4L2_CAP_VIDEO_CAPTURE;
413 cap->device_caps |= V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
414 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
415 return 0;
416}
417
418static int usbtv_enum_input(struct file *file, void *priv,
419 struct v4l2_input *i)
420{
421 if (i->index > 0)
422 return -EINVAL;
423
424 strlcpy(i->name, "Composite", sizeof(i->name));
425 i->type = V4L2_INPUT_TYPE_CAMERA;
426 i->std = V4L2_STD_525_60;
427 return 0;
428}
429
430static int usbtv_enum_fmt_vid_cap(struct file *file, void *priv,
431 struct v4l2_fmtdesc *f)
432{
433 if (f->index > 0)
434 return -EINVAL;
435
436 strlcpy(f->description, "16 bpp YUY2, 4:2:2, packed",
437 sizeof(f->description));
438 f->pixelformat = V4L2_PIX_FMT_YUYV;
439 return 0;
440}
441
442static int usbtv_fmt_vid_cap(struct file *file, void *priv,
443 struct v4l2_format *f)
444{
445 f->fmt.pix.width = USBTV_WIDTH;
446 f->fmt.pix.height = USBTV_HEIGHT;
447 f->fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
448 f->fmt.pix.field = V4L2_FIELD_INTERLACED;
449 f->fmt.pix.bytesperline = USBTV_WIDTH * 2;
450 f->fmt.pix.sizeimage = (f->fmt.pix.bytesperline * f->fmt.pix.height);
451 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
452 f->fmt.pix.priv = 0;
453 return 0;
454}
455
456static int usbtv_g_std(struct file *file, void *priv, v4l2_std_id *norm)
457{
458 *norm = V4L2_STD_525_60;
459 return 0;
460}
461
462static int usbtv_g_input(struct file *file, void *priv, unsigned int *i)
463{
464 *i = 0;
465 return 0;
466}
467
468static int usbtv_s_input(struct file *file, void *priv, unsigned int i)
469{
470 if (i > 0)
471 return -EINVAL;
472 return 0;
473}
474
475static int usbtv_s_std(struct file *file, void *priv, v4l2_std_id norm)
476{
477 if (norm & V4L2_STD_525_60)
478 return 0;
479 return -EINVAL;
480}
481
482struct v4l2_ioctl_ops usbtv_ioctl_ops = {
483 .vidioc_querycap = usbtv_querycap,
484 .vidioc_enum_input = usbtv_enum_input,
485 .vidioc_enum_fmt_vid_cap = usbtv_enum_fmt_vid_cap,
486 .vidioc_g_fmt_vid_cap = usbtv_fmt_vid_cap,
487 .vidioc_try_fmt_vid_cap = usbtv_fmt_vid_cap,
488 .vidioc_s_fmt_vid_cap = usbtv_fmt_vid_cap,
489 .vidioc_g_std = usbtv_g_std,
490 .vidioc_s_std = usbtv_s_std,
491 .vidioc_g_input = usbtv_g_input,
492 .vidioc_s_input = usbtv_s_input,
493
494 .vidioc_reqbufs = vb2_ioctl_reqbufs,
495 .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
496 .vidioc_querybuf = vb2_ioctl_querybuf,
497 .vidioc_create_bufs = vb2_ioctl_create_bufs,
498 .vidioc_qbuf = vb2_ioctl_qbuf,
499 .vidioc_dqbuf = vb2_ioctl_dqbuf,
500 .vidioc_streamon = vb2_ioctl_streamon,
501 .vidioc_streamoff = vb2_ioctl_streamoff,
502};
503
504struct v4l2_file_operations usbtv_fops = {
505 .owner = THIS_MODULE,
506 .unlocked_ioctl = video_ioctl2,
507 .mmap = vb2_fop_mmap,
508 .open = v4l2_fh_open,
509 .release = vb2_fop_release,
510 .read = vb2_fop_read,
511 .poll = vb2_fop_poll,
512};
513
514static int usbtv_queue_setup(struct vb2_queue *vq,
515 const struct v4l2_format *v4l_fmt, unsigned int *nbuffers,
516 unsigned int *nplanes, unsigned int sizes[], void *alloc_ctxs[])
517{
518 if (*nbuffers < 2)
519 *nbuffers = 2;
520 *nplanes = 1;
521 sizes[0] = USBTV_CHUNK * USBTV_CHUNKS * sizeof(u32);
522
523 return 0;
524}
525
526static void usbtv_buf_queue(struct vb2_buffer *vb)
527{
528 struct usbtv *usbtv = vb2_get_drv_priv(vb->vb2_queue);
529 struct usbtv_buf *buf = container_of(vb, struct usbtv_buf, vb);
530 unsigned long flags;
531
532 if (usbtv->udev == NULL) {
533 vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
534 return;
535 }
536
537 spin_lock_irqsave(&usbtv->buflock, flags);
538 list_add_tail(&buf->list, &usbtv->bufs);
539 spin_unlock_irqrestore(&usbtv->buflock, flags);
540}
541
542static int usbtv_start_streaming(struct vb2_queue *vq, unsigned int count)
543{
544 struct usbtv *usbtv = vb2_get_drv_priv(vq);
545
546 if (usbtv->udev == NULL)
547 return -ENODEV;
548
549 return usbtv_start(usbtv);
550}
551
552static int usbtv_stop_streaming(struct vb2_queue *vq)
553{
554 struct usbtv *usbtv = vb2_get_drv_priv(vq);
555
556 if (usbtv->udev == NULL)
557 return -ENODEV;
558
559 usbtv_stop(usbtv);
560 return 0;
561}
562
563struct vb2_ops usbtv_vb2_ops = {
564 .queue_setup = usbtv_queue_setup,
565 .buf_queue = usbtv_buf_queue,
566 .start_streaming = usbtv_start_streaming,
567 .stop_streaming = usbtv_stop_streaming,
568};
569
570static void usbtv_release(struct v4l2_device *v4l2_dev)
571{
572 struct usbtv *usbtv = container_of(v4l2_dev, struct usbtv, v4l2_dev);
573
574 v4l2_device_unregister(&usbtv->v4l2_dev);
575 vb2_queue_release(&usbtv->vb2q);
576 kfree(usbtv);
577}
578
579static int usbtv_probe(struct usb_interface *intf,
580 const struct usb_device_id *id)
581{
582 int ret;
583 int size;
584 struct device *dev = &intf->dev;
585 struct usbtv *usbtv;
586
587 /* Checks that the device is what we think it is. */
588 if (intf->num_altsetting != 2)
589 return -ENODEV;
590 if (intf->altsetting[1].desc.bNumEndpoints != 4)
591 return -ENODEV;
592
593 /* Packet size is split into 11 bits of base size and count of
594 * extra multiplies of it.*/
595 size = usb_endpoint_maxp(&intf->altsetting[1].endpoint[0].desc);
596 size = (size & 0x07ff) * (((size & 0x1800) >> 11) + 1);
597
598 /* Device structure */
599 usbtv = kzalloc(sizeof(struct usbtv), GFP_KERNEL);
600 if (usbtv == NULL)
601 return -ENOMEM;
602 usbtv->dev = dev;
603 usbtv->udev = usb_get_dev(interface_to_usbdev(intf));
604 usbtv->iso_size = size;
605 spin_lock_init(&usbtv->buflock);
606 mutex_init(&usbtv->v4l2_lock);
607 mutex_init(&usbtv->vb2q_lock);
608 INIT_LIST_HEAD(&usbtv->bufs);
609
610 /* videobuf2 structure */
611 usbtv->vb2q.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
612 usbtv->vb2q.io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ;
613 usbtv->vb2q.drv_priv = usbtv;
614 usbtv->vb2q.buf_struct_size = sizeof(struct usbtv_buf);
615 usbtv->vb2q.ops = &usbtv_vb2_ops;
616 usbtv->vb2q.mem_ops = &vb2_vmalloc_memops;
617 usbtv->vb2q.timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
618 usbtv->vb2q.lock = &usbtv->vb2q_lock;
619 ret = vb2_queue_init(&usbtv->vb2q);
620 if (ret < 0) {
621 dev_warn(dev, "Could not initialize videobuf2 queue\n");
622 goto usbtv_fail;
623 }
624
625 /* v4l2 structure */
626 usbtv->v4l2_dev.release = usbtv_release;
627 ret = v4l2_device_register(dev, &usbtv->v4l2_dev);
628 if (ret < 0) {
629 dev_warn(dev, "Could not register v4l2 device\n");
630 goto v4l2_fail;
631 }
632
633 usb_set_intfdata(intf, usbtv);
634
635 /* Video structure */
636 strlcpy(usbtv->vdev.name, "usbtv", sizeof(usbtv->vdev.name));
637 usbtv->vdev.v4l2_dev = &usbtv->v4l2_dev;
638 usbtv->vdev.release = video_device_release_empty;
639 usbtv->vdev.fops = &usbtv_fops;
640 usbtv->vdev.ioctl_ops = &usbtv_ioctl_ops;
641 usbtv->vdev.tvnorms = V4L2_STD_525_60;
642 usbtv->vdev.queue = &usbtv->vb2q;
643 usbtv->vdev.lock = &usbtv->v4l2_lock;
644 set_bit(V4L2_FL_USE_FH_PRIO, &usbtv->vdev.flags);
645 video_set_drvdata(&usbtv->vdev, usbtv);
646 ret = video_register_device(&usbtv->vdev, VFL_TYPE_GRABBER, -1);
647 if (ret < 0) {
648 dev_warn(dev, "Could not register video device\n");
649 goto vdev_fail;
650 }
651
652 dev_info(dev, "Fushicai USBTV007 Video Grabber\n");
653 return 0;
654
655vdev_fail:
656 v4l2_device_unregister(&usbtv->v4l2_dev);
657v4l2_fail:
658 vb2_queue_release(&usbtv->vb2q);
659usbtv_fail:
660 kfree(usbtv);
661
662 return ret;
663}
664
665static void usbtv_disconnect(struct usb_interface *intf)
666{
667 struct usbtv *usbtv = usb_get_intfdata(intf);
668
669 mutex_lock(&usbtv->vb2q_lock);
670 mutex_lock(&usbtv->v4l2_lock);
671
672 usbtv_stop(usbtv);
673 usb_set_intfdata(intf, NULL);
674 video_unregister_device(&usbtv->vdev);
675 v4l2_device_disconnect(&usbtv->v4l2_dev);
676 usb_put_dev(usbtv->udev);
677 usbtv->udev = NULL;
678
679 mutex_unlock(&usbtv->v4l2_lock);
680 mutex_unlock(&usbtv->vb2q_lock);
681
682 v4l2_device_put(&usbtv->v4l2_dev);
683}
684
685MODULE_AUTHOR("Lubomir Rintel");
686MODULE_DESCRIPTION("Fushicai USBTV007 Video Grabber Driver");
687MODULE_LICENSE("Dual BSD/GPL");
688
689struct usb_driver usbtv_usb_driver = {
690 .name = "usbtv",
691 .id_table = usbtv_id_table,
692 .probe = usbtv_probe,
693 .disconnect = usbtv_disconnect,
694};
695
696module_usb_driver(usbtv_usb_driver);
diff --git a/drivers/media/usb/usbvision/usbvision-video.c b/drivers/media/usb/usbvision/usbvision-video.c
index d34c2afe2c24..5c9e3123ad2e 100644
--- a/drivers/media/usb/usbvision/usbvision-video.c
+++ b/drivers/media/usb/usbvision/usbvision-video.c
@@ -467,8 +467,6 @@ static int vidioc_g_register(struct file *file, void *priv,
467 struct usb_usbvision *usbvision = video_drvdata(file); 467 struct usb_usbvision *usbvision = video_drvdata(file);
468 int err_code; 468 int err_code;
469 469
470 if (!v4l2_chip_match_host(&reg->match))
471 return -EINVAL;
472 /* NT100x has a 8-bit register space */ 470 /* NT100x has a 8-bit register space */
473 err_code = usbvision_read_reg(usbvision, reg->reg&0xff); 471 err_code = usbvision_read_reg(usbvision, reg->reg&0xff);
474 if (err_code < 0) { 472 if (err_code < 0) {
@@ -488,8 +486,6 @@ static int vidioc_s_register(struct file *file, void *priv,
488 struct usb_usbvision *usbvision = video_drvdata(file); 486 struct usb_usbvision *usbvision = video_drvdata(file);
489 int err_code; 487 int err_code;
490 488
491 if (!v4l2_chip_match_host(&reg->match))
492 return -EINVAL;
493 /* NT100x has a 8-bit register space */ 489 /* NT100x has a 8-bit register space */
494 err_code = usbvision_write_reg(usbvision, reg->reg & 0xff, reg->val); 490 err_code = usbvision_write_reg(usbvision, reg->reg & 0xff, reg->val);
495 if (err_code < 0) { 491 if (err_code < 0) {
@@ -608,6 +604,14 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id id)
608 return 0; 604 return 0;
609} 605}
610 606
607static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *id)
608{
609 struct usb_usbvision *usbvision = video_drvdata(file);
610
611 *id = usbvision->tvnorm_id;
612 return 0;
613}
614
611static int vidioc_g_tuner(struct file *file, void *priv, 615static int vidioc_g_tuner(struct file *file, void *priv,
612 struct v4l2_tuner *vt) 616 struct v4l2_tuner *vt)
613{ 617{
@@ -1248,6 +1252,7 @@ static const struct v4l2_ioctl_ops usbvision_ioctl_ops = {
1248 .vidioc_qbuf = vidioc_qbuf, 1252 .vidioc_qbuf = vidioc_qbuf,
1249 .vidioc_dqbuf = vidioc_dqbuf, 1253 .vidioc_dqbuf = vidioc_dqbuf,
1250 .vidioc_s_std = vidioc_s_std, 1254 .vidioc_s_std = vidioc_s_std,
1255 .vidioc_g_std = vidioc_g_std,
1251 .vidioc_enum_input = vidioc_enum_input, 1256 .vidioc_enum_input = vidioc_enum_input,
1252 .vidioc_g_input = vidioc_g_input, 1257 .vidioc_g_input = vidioc_g_input,
1253 .vidioc_s_input = vidioc_s_input, 1258 .vidioc_s_input = vidioc_s_input,
@@ -1274,7 +1279,6 @@ static struct video_device usbvision_video_template = {
1274 .name = "usbvision-video", 1279 .name = "usbvision-video",
1275 .release = video_device_release, 1280 .release = video_device_release,
1276 .tvnorms = USBVISION_NORMS, 1281 .tvnorms = USBVISION_NORMS,
1277 .current_norm = V4L2_STD_PAL
1278}; 1282};
1279 1283
1280 1284
@@ -1307,9 +1311,6 @@ static struct video_device usbvision_radio_template = {
1307 .name = "usbvision-radio", 1311 .name = "usbvision-radio",
1308 .release = video_device_release, 1312 .release = video_device_release,
1309 .ioctl_ops = &usbvision_radio_ioctl_ops, 1313 .ioctl_ops = &usbvision_radio_ioctl_ops,
1310
1311 .tvnorms = USBVISION_NORMS,
1312 .current_norm = V4L2_STD_PAL
1313}; 1314};
1314 1315
1315 1316
@@ -1459,6 +1460,7 @@ static void usbvision_release(struct usb_usbvision *usbvision)
1459 1460
1460 usbvision_remove_sysfs(usbvision->vdev); 1461 usbvision_remove_sysfs(usbvision->vdev);
1461 usbvision_unregister_video(usbvision); 1462 usbvision_unregister_video(usbvision);
1463 kfree(usbvision->alt_max_pkt_size);
1462 1464
1463 usb_free_urb(usbvision->ctrl_urb); 1465 usb_free_urb(usbvision->ctrl_urb);
1464 1466
@@ -1574,6 +1576,7 @@ static int usbvision_probe(struct usb_interface *intf,
1574 usbvision->alt_max_pkt_size = kmalloc(32 * usbvision->num_alt, GFP_KERNEL); 1576 usbvision->alt_max_pkt_size = kmalloc(32 * usbvision->num_alt, GFP_KERNEL);
1575 if (usbvision->alt_max_pkt_size == NULL) { 1577 if (usbvision->alt_max_pkt_size == NULL) {
1576 dev_err(&intf->dev, "usbvision: out of memory!\n"); 1578 dev_err(&intf->dev, "usbvision: out of memory!\n");
1579 usbvision_release(usbvision);
1577 return -ENOMEM; 1580 return -ENOMEM;
1578 } 1581 }
1579 1582
diff --git a/drivers/media/usb/uvc/Kconfig b/drivers/media/usb/uvc/Kconfig
index 541c9f1e4c6a..6ed85efabcaa 100644
--- a/drivers/media/usb/uvc/Kconfig
+++ b/drivers/media/usb/uvc/Kconfig
@@ -1,5 +1,6 @@
1config USB_VIDEO_CLASS 1config USB_VIDEO_CLASS
2 tristate "USB Video Class (UVC)" 2 tristate "USB Video Class (UVC)"
3 depends on VIDEO_V4L2
3 select VIDEOBUF2_VMALLOC 4 select VIDEOBUF2_VMALLOC
4 ---help--- 5 ---help---
5 Support for the USB Video Class (UVC). Currently only video 6 Support for the USB Video Class (UVC). Currently only video
diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c
index 5dbefa68b1d2..81695d48c13e 100644
--- a/drivers/media/usb/uvc/uvc_driver.c
+++ b/drivers/media/usb/uvc/uvc_driver.c
@@ -1836,8 +1836,8 @@ static int uvc_probe(struct usb_interface *intf,
1836 INIT_LIST_HEAD(&dev->chains); 1836 INIT_LIST_HEAD(&dev->chains);
1837 INIT_LIST_HEAD(&dev->streams); 1837 INIT_LIST_HEAD(&dev->streams);
1838 atomic_set(&dev->nstreams, 0); 1838 atomic_set(&dev->nstreams, 0);
1839 atomic_set(&dev->users, 0);
1840 atomic_set(&dev->nmappings, 0); 1839 atomic_set(&dev->nmappings, 0);
1840 mutex_init(&dev->lock);
1841 1841
1842 dev->udev = usb_get_dev(udev); 1842 dev->udev = usb_get_dev(udev);
1843 dev->intf = usb_get_intf(intf); 1843 dev->intf = usb_get_intf(intf);
@@ -1950,8 +1950,13 @@ static int uvc_suspend(struct usb_interface *intf, pm_message_t message)
1950 1950
1951 /* Controls are cached on the fly so they don't need to be saved. */ 1951 /* Controls are cached on the fly so they don't need to be saved. */
1952 if (intf->cur_altsetting->desc.bInterfaceSubClass == 1952 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
1953 UVC_SC_VIDEOCONTROL) 1953 UVC_SC_VIDEOCONTROL) {
1954 return uvc_status_suspend(dev); 1954 mutex_lock(&dev->lock);
1955 if (dev->users)
1956 uvc_status_stop(dev);
1957 mutex_unlock(&dev->lock);
1958 return 0;
1959 }
1955 1960
1956 list_for_each_entry(stream, &dev->streams, list) { 1961 list_for_each_entry(stream, &dev->streams, list) {
1957 if (stream->intf == intf) 1962 if (stream->intf == intf)
@@ -1973,14 +1978,20 @@ static int __uvc_resume(struct usb_interface *intf, int reset)
1973 1978
1974 if (intf->cur_altsetting->desc.bInterfaceSubClass == 1979 if (intf->cur_altsetting->desc.bInterfaceSubClass ==
1975 UVC_SC_VIDEOCONTROL) { 1980 UVC_SC_VIDEOCONTROL) {
1976 if (reset) { 1981 int ret = 0;
1977 int ret = uvc_ctrl_resume_device(dev);
1978 1982
1983 if (reset) {
1984 ret = uvc_ctrl_resume_device(dev);
1979 if (ret < 0) 1985 if (ret < 0)
1980 return ret; 1986 return ret;
1981 } 1987 }
1982 1988
1983 return uvc_status_resume(dev); 1989 mutex_lock(&dev->lock);
1990 if (dev->users)
1991 ret = uvc_status_start(dev, GFP_NOIO);
1992 mutex_unlock(&dev->lock);
1993
1994 return ret;
1984 } 1995 }
1985 1996
1986 list_for_each_entry(stream, &dev->streams, list) { 1997 list_for_each_entry(stream, &dev->streams, list) {
@@ -2163,6 +2174,24 @@ static struct usb_device_id uvc_ids[] = {
2163 .bInterfaceSubClass = 1, 2174 .bInterfaceSubClass = 1,
2164 .bInterfaceProtocol = 0, 2175 .bInterfaceProtocol = 0,
2165 .driver_info = UVC_QUIRK_PROBE_DEF }, 2176 .driver_info = UVC_QUIRK_PROBE_DEF },
2177 /* Dell Alienware X51 */
2178 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2179 | USB_DEVICE_ID_MATCH_INT_INFO,
2180 .idVendor = 0x05a9,
2181 .idProduct = 0x2643,
2182 .bInterfaceClass = USB_CLASS_VIDEO,
2183 .bInterfaceSubClass = 1,
2184 .bInterfaceProtocol = 0,
2185 .driver_info = UVC_QUIRK_PROBE_DEF },
2186 /* Dell Studio Hybrid 140g (OmniVision webcam) */
2187 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2188 | USB_DEVICE_ID_MATCH_INT_INFO,
2189 .idVendor = 0x05a9,
2190 .idProduct = 0x264a,
2191 .bInterfaceClass = USB_CLASS_VIDEO,
2192 .bInterfaceSubClass = 1,
2193 .bInterfaceProtocol = 0,
2194 .driver_info = UVC_QUIRK_PROBE_DEF },
2166 /* Apple Built-In iSight */ 2195 /* Apple Built-In iSight */
2167 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 2196 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2168 | USB_DEVICE_ID_MATCH_INT_INFO, 2197 | USB_DEVICE_ID_MATCH_INT_INFO,
diff --git a/drivers/media/usb/uvc/uvc_status.c b/drivers/media/usb/uvc/uvc_status.c
index b7492775e6ae..f552ab997956 100644
--- a/drivers/media/usb/uvc/uvc_status.c
+++ b/drivers/media/usb/uvc/uvc_status.c
@@ -206,32 +206,15 @@ void uvc_status_cleanup(struct uvc_device *dev)
206 uvc_input_cleanup(dev); 206 uvc_input_cleanup(dev);
207} 207}
208 208
209int uvc_status_start(struct uvc_device *dev) 209int uvc_status_start(struct uvc_device *dev, gfp_t flags)
210{ 210{
211 if (dev->int_urb == NULL) 211 if (dev->int_urb == NULL)
212 return 0; 212 return 0;
213 213
214 return usb_submit_urb(dev->int_urb, GFP_KERNEL); 214 return usb_submit_urb(dev->int_urb, flags);
215} 215}
216 216
217void uvc_status_stop(struct uvc_device *dev) 217void uvc_status_stop(struct uvc_device *dev)
218{ 218{
219 usb_kill_urb(dev->int_urb); 219 usb_kill_urb(dev->int_urb);
220} 220}
221
222int uvc_status_suspend(struct uvc_device *dev)
223{
224 if (atomic_read(&dev->users))
225 usb_kill_urb(dev->int_urb);
226
227 return 0;
228}
229
230int uvc_status_resume(struct uvc_device *dev)
231{
232 if (dev->int_urb == NULL || atomic_read(&dev->users) == 0)
233 return 0;
234
235 return usb_submit_urb(dev->int_urb, GFP_NOIO);
236}
237
diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c
index b2dc32623a71..3afff92804d3 100644
--- a/drivers/media/usb/uvc/uvc_v4l2.c
+++ b/drivers/media/usb/uvc/uvc_v4l2.c
@@ -498,16 +498,20 @@ static int uvc_v4l2_open(struct file *file)
498 return -ENOMEM; 498 return -ENOMEM;
499 } 499 }
500 500
501 if (atomic_inc_return(&stream->dev->users) == 1) { 501 mutex_lock(&stream->dev->lock);
502 ret = uvc_status_start(stream->dev); 502 if (stream->dev->users == 0) {
503 ret = uvc_status_start(stream->dev, GFP_KERNEL);
503 if (ret < 0) { 504 if (ret < 0) {
504 atomic_dec(&stream->dev->users); 505 mutex_unlock(&stream->dev->lock);
505 usb_autopm_put_interface(stream->dev->intf); 506 usb_autopm_put_interface(stream->dev->intf);
506 kfree(handle); 507 kfree(handle);
507 return ret; 508 return ret;
508 } 509 }
509 } 510 }
510 511
512 stream->dev->users++;
513 mutex_unlock(&stream->dev->lock);
514
511 v4l2_fh_init(&handle->vfh, stream->vdev); 515 v4l2_fh_init(&handle->vfh, stream->vdev);
512 v4l2_fh_add(&handle->vfh); 516 v4l2_fh_add(&handle->vfh);
513 handle->chain = stream->chain; 517 handle->chain = stream->chain;
@@ -538,8 +542,10 @@ static int uvc_v4l2_release(struct file *file)
538 kfree(handle); 542 kfree(handle);
539 file->private_data = NULL; 543 file->private_data = NULL;
540 544
541 if (atomic_dec_return(&stream->dev->users) == 0) 545 mutex_lock(&stream->dev->lock);
546 if (--stream->dev->users == 0)
542 uvc_status_stop(stream->dev); 547 uvc_status_stop(stream->dev);
548 mutex_unlock(&stream->dev->lock);
543 549
544 usb_autopm_put_interface(stream->dev->intf); 550 usb_autopm_put_interface(stream->dev->intf);
545 return 0; 551 return 0;
diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h
index af505fdd9b3f..9e35982d099a 100644
--- a/drivers/media/usb/uvc/uvcvideo.h
+++ b/drivers/media/usb/uvc/uvcvideo.h
@@ -514,7 +514,8 @@ struct uvc_device {
514 char name[32]; 514 char name[32];
515 515
516 enum uvc_device_state state; 516 enum uvc_device_state state;
517 atomic_t users; 517 struct mutex lock; /* Protects users */
518 unsigned int users;
518 atomic_t nmappings; 519 atomic_t nmappings;
519 520
520 /* Video control interface */ 521 /* Video control interface */
@@ -660,10 +661,8 @@ void uvc_video_clock_update(struct uvc_streaming *stream,
660/* Status */ 661/* Status */
661extern int uvc_status_init(struct uvc_device *dev); 662extern int uvc_status_init(struct uvc_device *dev);
662extern void uvc_status_cleanup(struct uvc_device *dev); 663extern void uvc_status_cleanup(struct uvc_device *dev);
663extern int uvc_status_start(struct uvc_device *dev); 664extern int uvc_status_start(struct uvc_device *dev, gfp_t flags);
664extern void uvc_status_stop(struct uvc_device *dev); 665extern void uvc_status_stop(struct uvc_device *dev);
665extern int uvc_status_suspend(struct uvc_device *dev);
666extern int uvc_status_resume(struct uvc_device *dev);
667 666
668/* Controls */ 667/* Controls */
669extern const struct v4l2_subscribed_event_ops uvc_ctrl_sub_ev_ops; 668extern const struct v4l2_subscribed_event_ops uvc_ctrl_sub_ev_ops;
diff --git a/drivers/media/v4l2-core/Makefile b/drivers/media/v4l2-core/Makefile
index aa50c46314b7..4c33b8d6520c 100644
--- a/drivers/media/v4l2-core/Makefile
+++ b/drivers/media/v4l2-core/Makefile
@@ -5,7 +5,8 @@
5tuner-objs := tuner-core.o 5tuner-objs := tuner-core.o
6 6
7videodev-objs := v4l2-dev.o v4l2-ioctl.o v4l2-device.o v4l2-fh.o \ 7videodev-objs := v4l2-dev.o v4l2-ioctl.o v4l2-device.o v4l2-fh.o \
8 v4l2-event.o v4l2-ctrls.o v4l2-subdev.o 8 v4l2-event.o v4l2-ctrls.o v4l2-subdev.o v4l2-clk.o \
9 v4l2-async.o
9ifeq ($(CONFIG_COMPAT),y) 10ifeq ($(CONFIG_COMPAT),y)
10 videodev-objs += v4l2-compat-ioctl32.o 11 videodev-objs += v4l2-compat-ioctl32.o
11endif 12endif
diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c
new file mode 100644
index 000000000000..aae241730caa
--- /dev/null
+++ b/drivers/media/v4l2-core/v4l2-async.c
@@ -0,0 +1,284 @@
1/*
2 * V4L2 asynchronous subdevice registration API
3 *
4 * Copyright (C) 2012-2013, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#include <linux/device.h>
12#include <linux/err.h>
13#include <linux/i2c.h>
14#include <linux/list.h>
15#include <linux/module.h>
16#include <linux/mutex.h>
17#include <linux/platform_device.h>
18#include <linux/slab.h>
19#include <linux/types.h>
20
21#include <media/v4l2-async.h>
22#include <media/v4l2-device.h>
23#include <media/v4l2-subdev.h>
24
25static bool match_i2c(struct device *dev, struct v4l2_async_subdev *asd)
26{
27#if IS_ENABLED(CONFIG_I2C)
28 struct i2c_client *client = i2c_verify_client(dev);
29 return client &&
30 asd->bus_type == V4L2_ASYNC_BUS_I2C &&
31 asd->match.i2c.adapter_id == client->adapter->nr &&
32 asd->match.i2c.address == client->addr;
33#else
34 return false;
35#endif
36}
37
38static bool match_platform(struct device *dev, struct v4l2_async_subdev *asd)
39{
40 return asd->bus_type == V4L2_ASYNC_BUS_PLATFORM &&
41 !strcmp(asd->match.platform.name, dev_name(dev));
42}
43
44static LIST_HEAD(subdev_list);
45static LIST_HEAD(notifier_list);
46static DEFINE_MUTEX(list_lock);
47
48static struct v4l2_async_subdev *v4l2_async_belongs(struct v4l2_async_notifier *notifier,
49 struct v4l2_async_subdev_list *asdl)
50{
51 struct v4l2_subdev *sd = v4l2_async_to_subdev(asdl);
52 struct v4l2_async_subdev *asd;
53 bool (*match)(struct device *,
54 struct v4l2_async_subdev *);
55
56 list_for_each_entry(asd, &notifier->waiting, list) {
57 /* bus_type has been verified valid before */
58 switch (asd->bus_type) {
59 case V4L2_ASYNC_BUS_CUSTOM:
60 match = asd->match.custom.match;
61 if (!match)
62 /* Match always */
63 return asd;
64 break;
65 case V4L2_ASYNC_BUS_PLATFORM:
66 match = match_platform;
67 break;
68 case V4L2_ASYNC_BUS_I2C:
69 match = match_i2c;
70 break;
71 default:
72 /* Cannot happen, unless someone breaks us */
73 WARN_ON(true);
74 return NULL;
75 }
76
77 /* match cannot be NULL here */
78 if (match(sd->dev, asd))
79 return asd;
80 }
81
82 return NULL;
83}
84
85static int v4l2_async_test_notify(struct v4l2_async_notifier *notifier,
86 struct v4l2_async_subdev_list *asdl,
87 struct v4l2_async_subdev *asd)
88{
89 struct v4l2_subdev *sd = v4l2_async_to_subdev(asdl);
90 int ret;
91
92 /* Remove from the waiting list */
93 list_del(&asd->list);
94 asdl->asd = asd;
95 asdl->notifier = notifier;
96
97 if (notifier->bound) {
98 ret = notifier->bound(notifier, sd, asd);
99 if (ret < 0)
100 return ret;
101 }
102 /* Move from the global subdevice list to notifier's done */
103 list_move(&asdl->list, &notifier->done);
104
105 ret = v4l2_device_register_subdev(notifier->v4l2_dev, sd);
106 if (ret < 0) {
107 if (notifier->unbind)
108 notifier->unbind(notifier, sd, asd);
109 return ret;
110 }
111
112 if (list_empty(&notifier->waiting) && notifier->complete)
113 return notifier->complete(notifier);
114
115 return 0;
116}
117
118static void v4l2_async_cleanup(struct v4l2_async_subdev_list *asdl)
119{
120 struct v4l2_subdev *sd = v4l2_async_to_subdev(asdl);
121
122 v4l2_device_unregister_subdev(sd);
123 /* Subdevice driver will reprobe and put asdl back onto the list */
124 list_del_init(&asdl->list);
125 asdl->asd = NULL;
126 sd->dev = NULL;
127}
128
129int v4l2_async_notifier_register(struct v4l2_device *v4l2_dev,
130 struct v4l2_async_notifier *notifier)
131{
132 struct v4l2_async_subdev_list *asdl, *tmp;
133 struct v4l2_async_subdev *asd;
134 int i;
135
136 if (!notifier->num_subdevs || notifier->num_subdevs > V4L2_MAX_SUBDEVS)
137 return -EINVAL;
138
139 notifier->v4l2_dev = v4l2_dev;
140 INIT_LIST_HEAD(&notifier->waiting);
141 INIT_LIST_HEAD(&notifier->done);
142
143 for (i = 0; i < notifier->num_subdevs; i++) {
144 asd = notifier->subdev[i];
145
146 switch (asd->bus_type) {
147 case V4L2_ASYNC_BUS_CUSTOM:
148 case V4L2_ASYNC_BUS_PLATFORM:
149 case V4L2_ASYNC_BUS_I2C:
150 break;
151 default:
152 dev_err(notifier->v4l2_dev ? notifier->v4l2_dev->dev : NULL,
153 "Invalid bus-type %u on %p\n",
154 asd->bus_type, asd);
155 return -EINVAL;
156 }
157 list_add_tail(&asd->list, &notifier->waiting);
158 }
159
160 mutex_lock(&list_lock);
161
162 /* Keep also completed notifiers on the list */
163 list_add(&notifier->list, &notifier_list);
164
165 list_for_each_entry_safe(asdl, tmp, &subdev_list, list) {
166 int ret;
167
168 asd = v4l2_async_belongs(notifier, asdl);
169 if (!asd)
170 continue;
171
172 ret = v4l2_async_test_notify(notifier, asdl, asd);
173 if (ret < 0) {
174 mutex_unlock(&list_lock);
175 return ret;
176 }
177 }
178
179 mutex_unlock(&list_lock);
180
181 return 0;
182}
183EXPORT_SYMBOL(v4l2_async_notifier_register);
184
185void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier)
186{
187 struct v4l2_async_subdev_list *asdl, *tmp;
188 unsigned int notif_n_subdev = notifier->num_subdevs;
189 unsigned int n_subdev = min(notif_n_subdev, V4L2_MAX_SUBDEVS);
190 struct device *dev[n_subdev];
191 int i = 0;
192
193 mutex_lock(&list_lock);
194
195 list_del(&notifier->list);
196
197 list_for_each_entry_safe(asdl, tmp, &notifier->done, list) {
198 struct v4l2_subdev *sd = v4l2_async_to_subdev(asdl);
199
200 dev[i] = get_device(sd->dev);
201
202 v4l2_async_cleanup(asdl);
203
204 /* If we handled USB devices, we'd have to lock the parent too */
205 device_release_driver(dev[i++]);
206
207 if (notifier->unbind)
208 notifier->unbind(notifier, sd, sd->asdl.asd);
209 }
210
211 mutex_unlock(&list_lock);
212
213 while (i--) {
214 struct device *d = dev[i];
215
216 if (d && device_attach(d) < 0) {
217 const char *name = "(none)";
218 int lock = device_trylock(d);
219
220 if (lock && d->driver)
221 name = d->driver->name;
222 dev_err(d, "Failed to re-probe to %s\n", name);
223 if (lock)
224 device_unlock(d);
225 }
226 put_device(d);
227 }
228 /*
229 * Don't care about the waiting list, it is initialised and populated
230 * upon notifier registration.
231 */
232}
233EXPORT_SYMBOL(v4l2_async_notifier_unregister);
234
235int v4l2_async_register_subdev(struct v4l2_subdev *sd)
236{
237 struct v4l2_async_subdev_list *asdl = &sd->asdl;
238 struct v4l2_async_notifier *notifier;
239
240 mutex_lock(&list_lock);
241
242 INIT_LIST_HEAD(&asdl->list);
243
244 list_for_each_entry(notifier, &notifier_list, list) {
245 struct v4l2_async_subdev *asd = v4l2_async_belongs(notifier, asdl);
246 if (asd) {
247 int ret = v4l2_async_test_notify(notifier, asdl, asd);
248 mutex_unlock(&list_lock);
249 return ret;
250 }
251 }
252
253 /* None matched, wait for hot-plugging */
254 list_add(&asdl->list, &subdev_list);
255
256 mutex_unlock(&list_lock);
257
258 return 0;
259}
260EXPORT_SYMBOL(v4l2_async_register_subdev);
261
262void v4l2_async_unregister_subdev(struct v4l2_subdev *sd)
263{
264 struct v4l2_async_subdev_list *asdl = &sd->asdl;
265 struct v4l2_async_notifier *notifier = asdl->notifier;
266
267 if (!asdl->asd) {
268 if (!list_empty(&asdl->list))
269 v4l2_async_cleanup(asdl);
270 return;
271 }
272
273 mutex_lock(&list_lock);
274
275 list_add(&asdl->asd->list, &notifier->waiting);
276
277 v4l2_async_cleanup(asdl);
278
279 if (notifier->unbind)
280 notifier->unbind(notifier, sd, sd->asdl.asd);
281
282 mutex_unlock(&list_lock);
283}
284EXPORT_SYMBOL(v4l2_async_unregister_subdev);
diff --git a/drivers/media/v4l2-core/v4l2-clk.c b/drivers/media/v4l2-core/v4l2-clk.c
new file mode 100644
index 000000000000..b67de8642b5a
--- /dev/null
+++ b/drivers/media/v4l2-core/v4l2-clk.c
@@ -0,0 +1,242 @@
1/*
2 * V4L2 clock service
3 *
4 * Copyright (C) 2012-2013, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#include <linux/atomic.h>
12#include <linux/device.h>
13#include <linux/errno.h>
14#include <linux/list.h>
15#include <linux/module.h>
16#include <linux/mutex.h>
17#include <linux/slab.h>
18#include <linux/string.h>
19
20#include <media/v4l2-clk.h>
21#include <media/v4l2-subdev.h>
22
23static DEFINE_MUTEX(clk_lock);
24static LIST_HEAD(clk_list);
25
26static struct v4l2_clk *v4l2_clk_find(const char *dev_id, const char *id)
27{
28 struct v4l2_clk *clk;
29
30 list_for_each_entry(clk, &clk_list, list) {
31 if (strcmp(dev_id, clk->dev_id))
32 continue;
33
34 if (!id || !clk->id || !strcmp(clk->id, id))
35 return clk;
36 }
37
38 return ERR_PTR(-ENODEV);
39}
40
41struct v4l2_clk *v4l2_clk_get(struct device *dev, const char *id)
42{
43 struct v4l2_clk *clk;
44
45 mutex_lock(&clk_lock);
46 clk = v4l2_clk_find(dev_name(dev), id);
47
48 if (!IS_ERR(clk))
49 atomic_inc(&clk->use_count);
50 mutex_unlock(&clk_lock);
51
52 return clk;
53}
54EXPORT_SYMBOL(v4l2_clk_get);
55
56void v4l2_clk_put(struct v4l2_clk *clk)
57{
58 struct v4l2_clk *tmp;
59
60 if (IS_ERR(clk))
61 return;
62
63 mutex_lock(&clk_lock);
64
65 list_for_each_entry(tmp, &clk_list, list)
66 if (tmp == clk)
67 atomic_dec(&clk->use_count);
68
69 mutex_unlock(&clk_lock);
70}
71EXPORT_SYMBOL(v4l2_clk_put);
72
73static int v4l2_clk_lock_driver(struct v4l2_clk *clk)
74{
75 struct v4l2_clk *tmp;
76 int ret = -ENODEV;
77
78 mutex_lock(&clk_lock);
79
80 list_for_each_entry(tmp, &clk_list, list)
81 if (tmp == clk) {
82 ret = !try_module_get(clk->ops->owner);
83 if (ret)
84 ret = -EFAULT;
85 break;
86 }
87
88 mutex_unlock(&clk_lock);
89
90 return ret;
91}
92
93static void v4l2_clk_unlock_driver(struct v4l2_clk *clk)
94{
95 module_put(clk->ops->owner);
96}
97
98int v4l2_clk_enable(struct v4l2_clk *clk)
99{
100 int ret = v4l2_clk_lock_driver(clk);
101
102 if (ret < 0)
103 return ret;
104
105 mutex_lock(&clk->lock);
106
107 if (++clk->enable == 1 && clk->ops->enable) {
108 ret = clk->ops->enable(clk);
109 if (ret < 0)
110 clk->enable--;
111 }
112
113 mutex_unlock(&clk->lock);
114
115 return ret;
116}
117EXPORT_SYMBOL(v4l2_clk_enable);
118
119/*
120 * You might Oops if you try to disabled a disabled clock, because then the
121 * driver isn't locked and could have been unloaded by now, so, don't do that
122 */
123void v4l2_clk_disable(struct v4l2_clk *clk)
124{
125 int enable;
126
127 mutex_lock(&clk->lock);
128
129 enable = --clk->enable;
130 if (WARN(enable < 0, "Unbalanced %s() on %s:%s!\n", __func__,
131 clk->dev_id, clk->id))
132 clk->enable++;
133 else if (!enable && clk->ops->disable)
134 clk->ops->disable(clk);
135
136 mutex_unlock(&clk->lock);
137
138 v4l2_clk_unlock_driver(clk);
139}
140EXPORT_SYMBOL(v4l2_clk_disable);
141
142unsigned long v4l2_clk_get_rate(struct v4l2_clk *clk)
143{
144 int ret = v4l2_clk_lock_driver(clk);
145
146 if (ret < 0)
147 return ret;
148
149 mutex_lock(&clk->lock);
150 if (!clk->ops->get_rate)
151 ret = -ENOSYS;
152 else
153 ret = clk->ops->get_rate(clk);
154 mutex_unlock(&clk->lock);
155
156 v4l2_clk_unlock_driver(clk);
157
158 return ret;
159}
160EXPORT_SYMBOL(v4l2_clk_get_rate);
161
162int v4l2_clk_set_rate(struct v4l2_clk *clk, unsigned long rate)
163{
164 int ret = v4l2_clk_lock_driver(clk);
165
166 if (ret < 0)
167 return ret;
168
169 mutex_lock(&clk->lock);
170 if (!clk->ops->set_rate)
171 ret = -ENOSYS;
172 else
173 ret = clk->ops->set_rate(clk, rate);
174 mutex_unlock(&clk->lock);
175
176 v4l2_clk_unlock_driver(clk);
177
178 return ret;
179}
180EXPORT_SYMBOL(v4l2_clk_set_rate);
181
182struct v4l2_clk *v4l2_clk_register(const struct v4l2_clk_ops *ops,
183 const char *dev_id,
184 const char *id, void *priv)
185{
186 struct v4l2_clk *clk;
187 int ret;
188
189 if (!ops || !dev_id)
190 return ERR_PTR(-EINVAL);
191
192 clk = kzalloc(sizeof(struct v4l2_clk), GFP_KERNEL);
193 if (!clk)
194 return ERR_PTR(-ENOMEM);
195
196 clk->id = kstrdup(id, GFP_KERNEL);
197 clk->dev_id = kstrdup(dev_id, GFP_KERNEL);
198 if ((id && !clk->id) || !clk->dev_id) {
199 ret = -ENOMEM;
200 goto ealloc;
201 }
202 clk->ops = ops;
203 clk->priv = priv;
204 atomic_set(&clk->use_count, 0);
205 mutex_init(&clk->lock);
206
207 mutex_lock(&clk_lock);
208 if (!IS_ERR(v4l2_clk_find(dev_id, id))) {
209 mutex_unlock(&clk_lock);
210 ret = -EEXIST;
211 goto eexist;
212 }
213 list_add_tail(&clk->list, &clk_list);
214 mutex_unlock(&clk_lock);
215
216 return clk;
217
218eexist:
219ealloc:
220 kfree(clk->id);
221 kfree(clk->dev_id);
222 kfree(clk);
223 return ERR_PTR(ret);
224}
225EXPORT_SYMBOL(v4l2_clk_register);
226
227void v4l2_clk_unregister(struct v4l2_clk *clk)
228{
229 if (WARN(atomic_read(&clk->use_count),
230 "%s(): Refusing to unregister ref-counted %s:%s clock!\n",
231 __func__, clk->dev_id, clk->id))
232 return;
233
234 mutex_lock(&clk_lock);
235 list_del(&clk->list);
236 mutex_unlock(&clk_lock);
237
238 kfree(clk->id);
239 kfree(clk->dev_id);
240 kfree(clk);
241}
242EXPORT_SYMBOL(v4l2_clk_unregister);
diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-core/v4l2-common.c
index 3fed63f4e026..a95e5e23403f 100644
--- a/drivers/media/v4l2-core/v4l2-common.c
+++ b/drivers/media/v4l2-core/v4l2-common.c
@@ -61,7 +61,6 @@
61#include <media/v4l2-common.h> 61#include <media/v4l2-common.h>
62#include <media/v4l2-device.h> 62#include <media/v4l2-device.h>
63#include <media/v4l2-ctrls.h> 63#include <media/v4l2-ctrls.h>
64#include <media/v4l2-chip-ident.h>
65 64
66#include <linux/videodev2.h> 65#include <linux/videodev2.h>
67 66
@@ -227,62 +226,9 @@ u32 v4l2_ctrl_next(const u32 * const * ctrl_classes, u32 id)
227} 226}
228EXPORT_SYMBOL(v4l2_ctrl_next); 227EXPORT_SYMBOL(v4l2_ctrl_next);
229 228
230int v4l2_chip_match_host(const struct v4l2_dbg_match *match)
231{
232 switch (match->type) {
233 case V4L2_CHIP_MATCH_BRIDGE:
234 return match->addr == 0;
235 default:
236 return 0;
237 }
238}
239EXPORT_SYMBOL(v4l2_chip_match_host);
240
241#if IS_ENABLED(CONFIG_I2C)
242int v4l2_chip_match_i2c_client(struct i2c_client *c, const struct v4l2_dbg_match *match)
243{
244 int len;
245
246 if (c == NULL || match == NULL)
247 return 0;
248
249 switch (match->type) {
250 case V4L2_CHIP_MATCH_I2C_DRIVER:
251 if (c->driver == NULL || c->driver->driver.name == NULL)
252 return 0;
253 len = strlen(c->driver->driver.name);
254 return len && !strncmp(c->driver->driver.name, match->name, len);
255 case V4L2_CHIP_MATCH_I2C_ADDR:
256 return c->addr == match->addr;
257 case V4L2_CHIP_MATCH_SUBDEV:
258 return 1;
259 default:
260 return 0;
261 }
262}
263EXPORT_SYMBOL(v4l2_chip_match_i2c_client);
264
265int v4l2_chip_ident_i2c_client(struct i2c_client *c, struct v4l2_dbg_chip_ident *chip,
266 u32 ident, u32 revision)
267{
268 if (!v4l2_chip_match_i2c_client(c, &chip->match))
269 return 0;
270 if (chip->ident == V4L2_IDENT_NONE) {
271 chip->ident = ident;
272 chip->revision = revision;
273 }
274 else {
275 chip->ident = V4L2_IDENT_AMBIGUOUS;
276 chip->revision = 0;
277 }
278 return 0;
279}
280EXPORT_SYMBOL(v4l2_chip_ident_i2c_client);
281
282/* ----------------------------------------------------------------- */
283
284/* I2C Helper functions */ 229/* I2C Helper functions */
285 230
231#if IS_ENABLED(CONFIG_I2C)
286 232
287void v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client, 233void v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client,
288 const struct v4l2_subdev_ops *ops) 234 const struct v4l2_subdev_ops *ops)
@@ -291,6 +237,7 @@ void v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client,
291 sd->flags |= V4L2_SUBDEV_FL_IS_I2C; 237 sd->flags |= V4L2_SUBDEV_FL_IS_I2C;
292 /* the owner is the same as the i2c_client's driver owner */ 238 /* the owner is the same as the i2c_client's driver owner */
293 sd->owner = client->driver->driver.owner; 239 sd->owner = client->driver->driver.owner;
240 sd->dev = &client->dev;
294 /* i2c_client and v4l2_subdev point to one another */ 241 /* i2c_client and v4l2_subdev point to one another */
295 v4l2_set_subdevdata(sd, client); 242 v4l2_set_subdevdata(sd, client);
296 i2c_set_clientdata(client, sd); 243 i2c_set_clientdata(client, sd);
@@ -301,8 +248,6 @@ void v4l2_i2c_subdev_init(struct v4l2_subdev *sd, struct i2c_client *client,
301} 248}
302EXPORT_SYMBOL_GPL(v4l2_i2c_subdev_init); 249EXPORT_SYMBOL_GPL(v4l2_i2c_subdev_init);
303 250
304
305
306/* Load an i2c sub-device. */ 251/* Load an i2c sub-device. */
307struct v4l2_subdev *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev, 252struct v4l2_subdev *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev,
308 struct i2c_adapter *adapter, struct i2c_board_info *info, 253 struct i2c_adapter *adapter, struct i2c_board_info *info,
@@ -426,6 +371,7 @@ void v4l2_spi_subdev_init(struct v4l2_subdev *sd, struct spi_device *spi,
426 sd->flags |= V4L2_SUBDEV_FL_IS_SPI; 371 sd->flags |= V4L2_SUBDEV_FL_IS_SPI;
427 /* the owner is the same as the spi_device's driver owner */ 372 /* the owner is the same as the spi_device's driver owner */
428 sd->owner = spi->dev.driver->owner; 373 sd->owner = spi->dev.driver->owner;
374 sd->dev = &spi->dev;
429 /* spi_device and v4l2_subdev point to one another */ 375 /* spi_device and v4l2_subdev point to one another */
430 v4l2_set_subdevdata(sd, spi); 376 v4l2_set_subdevdata(sd, spi);
431 spi_set_drvdata(spi, sd); 377 spi_set_drvdata(spi, sd);
diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
index f1295519f285..8f7a6a454a4c 100644
--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
@@ -1074,7 +1074,6 @@ long v4l2_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg)
1074 case VIDIOC_TRY_DECODER_CMD: 1074 case VIDIOC_TRY_DECODER_CMD:
1075 case VIDIOC_DBG_S_REGISTER: 1075 case VIDIOC_DBG_S_REGISTER:
1076 case VIDIOC_DBG_G_REGISTER: 1076 case VIDIOC_DBG_G_REGISTER:
1077 case VIDIOC_DBG_G_CHIP_IDENT:
1078 case VIDIOC_S_HW_FREQ_SEEK: 1077 case VIDIOC_S_HW_FREQ_SEEK:
1079 case VIDIOC_S_DV_TIMINGS: 1078 case VIDIOC_S_DV_TIMINGS:
1080 case VIDIOC_G_DV_TIMINGS: 1079 case VIDIOC_G_DV_TIMINGS:
diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c
index 5923c5dfacd5..c8859d6ff6ad 100644
--- a/drivers/media/v4l2-core/v4l2-dev.c
+++ b/drivers/media/v4l2-core/v4l2-dev.c
@@ -495,8 +495,8 @@ static const struct file_operations v4l2_fops = {
495}; 495};
496 496
497/** 497/**
498 * get_index - assign stream index number based on parent device 498 * get_index - assign stream index number based on v4l2_dev
499 * @vdev: video_device to assign index number to, vdev->parent should be assigned 499 * @vdev: video_device to assign index number to, vdev->v4l2_dev should be assigned
500 * 500 *
501 * Note that when this is called the new device has not yet been registered 501 * Note that when this is called the new device has not yet been registered
502 * in the video_device array, but it was able to obtain a minor number. 502 * in the video_device array, but it was able to obtain a minor number.
@@ -514,15 +514,11 @@ static int get_index(struct video_device *vdev)
514 static DECLARE_BITMAP(used, VIDEO_NUM_DEVICES); 514 static DECLARE_BITMAP(used, VIDEO_NUM_DEVICES);
515 int i; 515 int i;
516 516
517 /* Some drivers do not set the parent. In that case always return 0. */
518 if (vdev->parent == NULL)
519 return 0;
520
521 bitmap_zero(used, VIDEO_NUM_DEVICES); 517 bitmap_zero(used, VIDEO_NUM_DEVICES);
522 518
523 for (i = 0; i < VIDEO_NUM_DEVICES; i++) { 519 for (i = 0; i < VIDEO_NUM_DEVICES; i++) {
524 if (video_device[i] != NULL && 520 if (video_device[i] != NULL &&
525 video_device[i]->parent == vdev->parent) { 521 video_device[i]->v4l2_dev == vdev->v4l2_dev) {
526 set_bit(video_device[i]->index, used); 522 set_bit(video_device[i]->index, used);
527 } 523 }
528 } 524 }
@@ -596,7 +592,6 @@ static void determine_valid_ioctls(struct video_device *vdev)
596 set_bit(_IOC_NR(VIDIOC_DBG_G_REGISTER), valid_ioctls); 592 set_bit(_IOC_NR(VIDIOC_DBG_G_REGISTER), valid_ioctls);
597 set_bit(_IOC_NR(VIDIOC_DBG_S_REGISTER), valid_ioctls); 593 set_bit(_IOC_NR(VIDIOC_DBG_S_REGISTER), valid_ioctls);
598#endif 594#endif
599 SET_VALID_IOCTL(ops, VIDIOC_DBG_G_CHIP_IDENT, vidioc_g_chip_ident);
600 /* yes, really vidioc_subscribe_event */ 595 /* yes, really vidioc_subscribe_event */
601 SET_VALID_IOCTL(ops, VIDIOC_DQEVENT, vidioc_subscribe_event); 596 SET_VALID_IOCTL(ops, VIDIOC_DQEVENT, vidioc_subscribe_event);
602 SET_VALID_IOCTL(ops, VIDIOC_SUBSCRIBE_EVENT, vidioc_subscribe_event); 597 SET_VALID_IOCTL(ops, VIDIOC_SUBSCRIBE_EVENT, vidioc_subscribe_event);
@@ -675,9 +670,8 @@ static void determine_valid_ioctls(struct video_device *vdev)
675 SET_VALID_IOCTL(ops, VIDIOC_PREPARE_BUF, vidioc_prepare_buf); 670 SET_VALID_IOCTL(ops, VIDIOC_PREPARE_BUF, vidioc_prepare_buf);
676 if (ops->vidioc_s_std) 671 if (ops->vidioc_s_std)
677 set_bit(_IOC_NR(VIDIOC_ENUMSTD), valid_ioctls); 672 set_bit(_IOC_NR(VIDIOC_ENUMSTD), valid_ioctls);
678 if (ops->vidioc_g_std || vdev->current_norm)
679 set_bit(_IOC_NR(VIDIOC_G_STD), valid_ioctls);
680 SET_VALID_IOCTL(ops, VIDIOC_S_STD, vidioc_s_std); 673 SET_VALID_IOCTL(ops, VIDIOC_S_STD, vidioc_s_std);
674 SET_VALID_IOCTL(ops, VIDIOC_G_STD, vidioc_g_std);
681 if (is_rx) { 675 if (is_rx) {
682 SET_VALID_IOCTL(ops, VIDIOC_QUERYSTD, vidioc_querystd); 676 SET_VALID_IOCTL(ops, VIDIOC_QUERYSTD, vidioc_querystd);
683 SET_VALID_IOCTL(ops, VIDIOC_ENUMINPUT, vidioc_enum_input); 677 SET_VALID_IOCTL(ops, VIDIOC_ENUMINPUT, vidioc_enum_input);
@@ -705,7 +699,7 @@ static void determine_valid_ioctls(struct video_device *vdev)
705 if (ops->vidioc_cropcap || ops->vidioc_g_selection) 699 if (ops->vidioc_cropcap || ops->vidioc_g_selection)
706 set_bit(_IOC_NR(VIDIOC_CROPCAP), valid_ioctls); 700 set_bit(_IOC_NR(VIDIOC_CROPCAP), valid_ioctls);
707 if (ops->vidioc_g_parm || (vdev->vfl_type == VFL_TYPE_GRABBER && 701 if (ops->vidioc_g_parm || (vdev->vfl_type == VFL_TYPE_GRABBER &&
708 (ops->vidioc_g_std || vdev->current_norm))) 702 ops->vidioc_g_std))
709 set_bit(_IOC_NR(VIDIOC_G_PARM), valid_ioctls); 703 set_bit(_IOC_NR(VIDIOC_G_PARM), valid_ioctls);
710 SET_VALID_IOCTL(ops, VIDIOC_S_PARM, vidioc_s_parm); 704 SET_VALID_IOCTL(ops, VIDIOC_S_PARM, vidioc_s_parm);
711 SET_VALID_IOCTL(ops, VIDIOC_S_DV_TIMINGS, vidioc_s_dv_timings); 705 SET_VALID_IOCTL(ops, VIDIOC_S_DV_TIMINGS, vidioc_s_dv_timings);
@@ -777,6 +771,9 @@ int __video_register_device(struct video_device *vdev, int type, int nr,
777 /* the release callback MUST be present */ 771 /* the release callback MUST be present */
778 if (WARN_ON(!vdev->release)) 772 if (WARN_ON(!vdev->release))
779 return -EINVAL; 773 return -EINVAL;
774 /* the v4l2_dev pointer MUST be present */
775 if (WARN_ON(!vdev->v4l2_dev))
776 return -EINVAL;
780 777
781 /* v4l2_fh support */ 778 /* v4l2_fh support */
782 spin_lock_init(&vdev->fh_lock); 779 spin_lock_init(&vdev->fh_lock);
@@ -804,16 +801,14 @@ int __video_register_device(struct video_device *vdev, int type, int nr,
804 801
805 vdev->vfl_type = type; 802 vdev->vfl_type = type;
806 vdev->cdev = NULL; 803 vdev->cdev = NULL;
807 if (vdev->v4l2_dev) { 804 if (vdev->dev_parent == NULL)
808 if (vdev->v4l2_dev->dev) 805 vdev->dev_parent = vdev->v4l2_dev->dev;
809 vdev->parent = vdev->v4l2_dev->dev; 806 if (vdev->ctrl_handler == NULL)
810 if (vdev->ctrl_handler == NULL) 807 vdev->ctrl_handler = vdev->v4l2_dev->ctrl_handler;
811 vdev->ctrl_handler = vdev->v4l2_dev->ctrl_handler; 808 /* If the prio state pointer is NULL, then use the v4l2_device
812 /* If the prio state pointer is NULL, then use the v4l2_device 809 prio state. */
813 prio state. */ 810 if (vdev->prio == NULL)
814 if (vdev->prio == NULL) 811 vdev->prio = &vdev->v4l2_dev->prio;
815 vdev->prio = &vdev->v4l2_dev->prio;
816 }
817 812
818 /* Part 2: find a free minor, device node number and device index. */ 813 /* Part 2: find a free minor, device node number and device index. */
819#ifdef CONFIG_VIDEO_FIXED_MINOR_RANGES 814#ifdef CONFIG_VIDEO_FIXED_MINOR_RANGES
@@ -898,8 +893,7 @@ int __video_register_device(struct video_device *vdev, int type, int nr,
898 /* Part 4: register the device with sysfs */ 893 /* Part 4: register the device with sysfs */
899 vdev->dev.class = &video_class; 894 vdev->dev.class = &video_class;
900 vdev->dev.devt = MKDEV(VIDEO_MAJOR, vdev->minor); 895 vdev->dev.devt = MKDEV(VIDEO_MAJOR, vdev->minor);
901 if (vdev->parent) 896 vdev->dev.parent = vdev->dev_parent;
902 vdev->dev.parent = vdev->parent;
903 dev_set_name(&vdev->dev, "%s%d", name_base, vdev->num); 897 dev_set_name(&vdev->dev, "%s%d", name_base, vdev->num);
904 ret = device_register(&vdev->dev); 898 ret = device_register(&vdev->dev);
905 if (ret < 0) { 899 if (ret < 0) {
diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
index 8ed5da2170bf..02d1b6327117 100644
--- a/drivers/media/v4l2-core/v4l2-device.c
+++ b/drivers/media/v4l2-core/v4l2-device.c
@@ -44,7 +44,8 @@ int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev)
44 v4l2_dev->dev = dev; 44 v4l2_dev->dev = dev;
45 if (dev == NULL) { 45 if (dev == NULL) {
46 /* If dev == NULL, then name must be filled in by the caller */ 46 /* If dev == NULL, then name must be filled in by the caller */
47 WARN_ON(!v4l2_dev->name[0]); 47 if (WARN_ON(!v4l2_dev->name[0]))
48 return -EINVAL;
48 return 0; 49 return 0;
49 } 50 }
50 51
@@ -105,7 +106,9 @@ void v4l2_device_unregister(struct v4l2_device *v4l2_dev)
105{ 106{
106 struct v4l2_subdev *sd, *next; 107 struct v4l2_subdev *sd, *next;
107 108
108 if (v4l2_dev == NULL) 109 /* Just return if v4l2_dev is NULL or if it was already
110 * unregistered before. */
111 if (v4l2_dev == NULL || !v4l2_dev->name[0])
109 return; 112 return;
110 v4l2_device_disconnect(v4l2_dev); 113 v4l2_device_disconnect(v4l2_dev);
111 114
@@ -135,6 +138,8 @@ void v4l2_device_unregister(struct v4l2_device *v4l2_dev)
135 } 138 }
136#endif 139#endif
137 } 140 }
141 /* Mark as unregistered, thus preventing duplicate unregistrations */
142 v4l2_dev->name[0] = '\0';
138} 143}
139EXPORT_SYMBOL_GPL(v4l2_device_unregister); 144EXPORT_SYMBOL_GPL(v4l2_device_unregister);
140 145
@@ -269,8 +274,10 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev *sd)
269 sd->v4l2_dev = NULL; 274 sd->v4l2_dev = NULL;
270 275
271#if defined(CONFIG_MEDIA_CONTROLLER) 276#if defined(CONFIG_MEDIA_CONTROLLER)
272 if (v4l2_dev->mdev) 277 if (v4l2_dev->mdev) {
278 media_entity_remove_links(&sd->entity);
273 media_device_unregister_entity(&sd->entity); 279 media_device_unregister_entity(&sd->entity);
280 }
274#endif 281#endif
275 video_unregister_device(sd->devnode); 282 video_unregister_device(sd->devnode);
276 module_put(sd->owner); 283 module_put(sd->owner);
diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
index 7658586fe5f4..68e6b5e912ff 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -26,7 +26,6 @@
26#include <media/v4l2-fh.h> 26#include <media/v4l2-fh.h>
27#include <media/v4l2-event.h> 27#include <media/v4l2-event.h>
28#include <media/v4l2-device.h> 28#include <media/v4l2-device.h>
29#include <media/v4l2-chip-ident.h>
30#include <media/videobuf2-core.h> 29#include <media/videobuf2-core.h>
31 30
32/* Zero out the end of the struct pointed to by p. Everything after, but 31/* Zero out the end of the struct pointed to by p. Everything after, but
@@ -619,20 +618,6 @@ static void v4l_print_decoder_cmd(const void *arg, bool write_only)
619 pr_info("pts=%llu\n", p->stop.pts); 618 pr_info("pts=%llu\n", p->stop.pts);
620} 619}
621 620
622static void v4l_print_dbg_chip_ident(const void *arg, bool write_only)
623{
624 const struct v4l2_dbg_chip_ident *p = arg;
625
626 pr_cont("type=%u, ", p->match.type);
627 if (p->match.type == V4L2_CHIP_MATCH_I2C_DRIVER)
628 pr_cont("name=%.*s, ",
629 (int)sizeof(p->match.name), p->match.name);
630 else
631 pr_cont("addr=%u, ", p->match.addr);
632 pr_cont("chip_ident=%u, revision=0x%x\n",
633 p->ident, p->revision);
634}
635
636static void v4l_print_dbg_chip_info(const void *arg, bool write_only) 621static void v4l_print_dbg_chip_info(const void *arg, bool write_only)
637{ 622{
638 const struct v4l2_dbg_chip_info *p = arg; 623 const struct v4l2_dbg_chip_info *p = arg;
@@ -1359,40 +1344,18 @@ static int v4l_enumstd(const struct v4l2_ioctl_ops *ops,
1359 return 0; 1344 return 0;
1360} 1345}
1361 1346
1362static int v4l_g_std(const struct v4l2_ioctl_ops *ops,
1363 struct file *file, void *fh, void *arg)
1364{
1365 struct video_device *vfd = video_devdata(file);
1366 v4l2_std_id *id = arg;
1367
1368 /* Calls the specific handler */
1369 if (ops->vidioc_g_std)
1370 return ops->vidioc_g_std(file, fh, arg);
1371 if (vfd->current_norm) {
1372 *id = vfd->current_norm;
1373 return 0;
1374 }
1375 return -ENOTTY;
1376}
1377
1378static int v4l_s_std(const struct v4l2_ioctl_ops *ops, 1347static int v4l_s_std(const struct v4l2_ioctl_ops *ops,
1379 struct file *file, void *fh, void *arg) 1348 struct file *file, void *fh, void *arg)
1380{ 1349{
1381 struct video_device *vfd = video_devdata(file); 1350 struct video_device *vfd = video_devdata(file);
1382 v4l2_std_id id = *(v4l2_std_id *)arg, norm; 1351 v4l2_std_id id = *(v4l2_std_id *)arg, norm;
1383 int ret;
1384 1352
1385 norm = id & vfd->tvnorms; 1353 norm = id & vfd->tvnorms;
1386 if (vfd->tvnorms && !norm) /* Check if std is supported */ 1354 if (vfd->tvnorms && !norm) /* Check if std is supported */
1387 return -EINVAL; 1355 return -EINVAL;
1388 1356
1389 /* Calls the specific handler */ 1357 /* Calls the specific handler */
1390 ret = ops->vidioc_s_std(file, fh, norm); 1358 return ops->vidioc_s_std(file, fh, norm);
1391
1392 /* Updates standard information */
1393 if (ret >= 0)
1394 vfd->current_norm = norm;
1395 return ret;
1396} 1359}
1397 1360
1398static int v4l_querystd(const struct v4l2_ioctl_ops *ops, 1361static int v4l_querystd(const struct v4l2_ioctl_ops *ops,
@@ -1402,10 +1365,10 @@ static int v4l_querystd(const struct v4l2_ioctl_ops *ops,
1402 v4l2_std_id *p = arg; 1365 v4l2_std_id *p = arg;
1403 1366
1404 /* 1367 /*
1405 * If nothing detected, it should return all supported 1368 * If no signal is detected, then the driver should return
1406 * standard. 1369 * V4L2_STD_UNKNOWN. Otherwise it should return tvnorms with
1407 * Drivers just need to mask the std argument, in order 1370 * any standards that do not apply removed.
1408 * to remove the standards that don't apply from the mask. 1371 *
1409 * This means that tuners, audio and video decoders can join 1372 * This means that tuners, audio and video decoders can join
1410 * their efforts to improve the standards detection. 1373 * their efforts to improve the standards detection.
1411 */ 1374 */
@@ -1495,7 +1458,6 @@ static int v4l_prepare_buf(const struct v4l2_ioctl_ops *ops,
1495static int v4l_g_parm(const struct v4l2_ioctl_ops *ops, 1458static int v4l_g_parm(const struct v4l2_ioctl_ops *ops,
1496 struct file *file, void *fh, void *arg) 1459 struct file *file, void *fh, void *arg)
1497{ 1460{
1498 struct video_device *vfd = video_devdata(file);
1499 struct v4l2_streamparm *p = arg; 1461 struct v4l2_streamparm *p = arg;
1500 v4l2_std_id std; 1462 v4l2_std_id std;
1501 int ret = check_fmt(file, p->type); 1463 int ret = check_fmt(file, p->type);
@@ -1504,16 +1466,13 @@ static int v4l_g_parm(const struct v4l2_ioctl_ops *ops,
1504 return ret; 1466 return ret;
1505 if (ops->vidioc_g_parm) 1467 if (ops->vidioc_g_parm)
1506 return ops->vidioc_g_parm(file, fh, p); 1468 return ops->vidioc_g_parm(file, fh, p);
1507 std = vfd->current_norm;
1508 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE && 1469 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
1509 p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) 1470 p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
1510 return -EINVAL; 1471 return -EINVAL;
1511 p->parm.capture.readbuffers = 2; 1472 p->parm.capture.readbuffers = 2;
1512 if (is_valid_ioctl(vfd, VIDIOC_G_STD) && ops->vidioc_g_std) 1473 ret = ops->vidioc_g_std(file, fh, &std);
1513 ret = ops->vidioc_g_std(file, fh, &std);
1514 if (ret == 0) 1474 if (ret == 0)
1515 v4l2_video_std_frame_period(std, 1475 v4l2_video_std_frame_period(std, &p->parm.capture.timeperframe);
1516 &p->parm.capture.timeperframe);
1517 return ret; 1476 return ret;
1518} 1477}
1519 1478
@@ -1802,7 +1761,8 @@ static int v4l_dbg_g_register(const struct v4l2_ioctl_ops *ops,
1802 return v4l2_subdev_call(sd, core, g_register, p); 1761 return v4l2_subdev_call(sd, core, g_register, p);
1803 return -EINVAL; 1762 return -EINVAL;
1804 } 1763 }
1805 if (ops->vidioc_g_register) 1764 if (ops->vidioc_g_register && p->match.type == V4L2_CHIP_MATCH_BRIDGE &&
1765 (ops->vidioc_g_chip_info || p->match.addr == 0))
1806 return ops->vidioc_g_register(file, fh, p); 1766 return ops->vidioc_g_register(file, fh, p);
1807 return -EINVAL; 1767 return -EINVAL;
1808#else 1768#else
@@ -1829,7 +1789,8 @@ static int v4l_dbg_s_register(const struct v4l2_ioctl_ops *ops,
1829 return v4l2_subdev_call(sd, core, s_register, p); 1789 return v4l2_subdev_call(sd, core, s_register, p);
1830 return -EINVAL; 1790 return -EINVAL;
1831 } 1791 }
1832 if (ops->vidioc_s_register) 1792 if (ops->vidioc_s_register && p->match.type == V4L2_CHIP_MATCH_BRIDGE &&
1793 (ops->vidioc_g_chip_info || p->match.addr == 0))
1833 return ops->vidioc_s_register(file, fh, p); 1794 return ops->vidioc_s_register(file, fh, p);
1834 return -EINVAL; 1795 return -EINVAL;
1835#else 1796#else
@@ -1837,18 +1798,6 @@ static int v4l_dbg_s_register(const struct v4l2_ioctl_ops *ops,
1837#endif 1798#endif
1838} 1799}
1839 1800
1840static int v4l_dbg_g_chip_ident(const struct v4l2_ioctl_ops *ops,
1841 struct file *file, void *fh, void *arg)
1842{
1843 struct v4l2_dbg_chip_ident *p = arg;
1844
1845 p->ident = V4L2_IDENT_NONE;
1846 p->revision = 0;
1847 if (p->match.type == V4L2_CHIP_MATCH_SUBDEV)
1848 return -EINVAL;
1849 return ops->vidioc_g_chip_ident(file, fh, p);
1850}
1851
1852static int v4l_dbg_g_chip_info(const struct v4l2_ioctl_ops *ops, 1801static int v4l_dbg_g_chip_info(const struct v4l2_ioctl_ops *ops,
1853 struct file *file, void *fh, void *arg) 1802 struct file *file, void *fh, void *arg)
1854{ 1803{
@@ -1864,12 +1813,7 @@ static int v4l_dbg_g_chip_info(const struct v4l2_ioctl_ops *ops,
1864 p->flags |= V4L2_CHIP_FL_WRITABLE; 1813 p->flags |= V4L2_CHIP_FL_WRITABLE;
1865 if (ops->vidioc_g_register) 1814 if (ops->vidioc_g_register)
1866 p->flags |= V4L2_CHIP_FL_READABLE; 1815 p->flags |= V4L2_CHIP_FL_READABLE;
1867 if (vfd->v4l2_dev) 1816 strlcpy(p->name, vfd->v4l2_dev->name, sizeof(p->name));
1868 strlcpy(p->name, vfd->v4l2_dev->name, sizeof(p->name));
1869 else if (vfd->parent)
1870 strlcpy(p->name, vfd->parent->driver->name, sizeof(p->name));
1871 else
1872 strlcpy(p->name, "bridge", sizeof(p->name));
1873 if (ops->vidioc_g_chip_info) 1817 if (ops->vidioc_g_chip_info)
1874 return ops->vidioc_g_chip_info(file, fh, arg); 1818 return ops->vidioc_g_chip_info(file, fh, arg);
1875 if (p->match.addr) 1819 if (p->match.addr)
@@ -2048,7 +1992,7 @@ static struct v4l2_ioctl_info v4l2_ioctls[] = {
2048 IOCTL_INFO_FNC(VIDIOC_STREAMOFF, v4l_streamoff, v4l_print_buftype, INFO_FL_PRIO | INFO_FL_QUEUE), 1992 IOCTL_INFO_FNC(VIDIOC_STREAMOFF, v4l_streamoff, v4l_print_buftype, INFO_FL_PRIO | INFO_FL_QUEUE),
2049 IOCTL_INFO_FNC(VIDIOC_G_PARM, v4l_g_parm, v4l_print_streamparm, INFO_FL_CLEAR(v4l2_streamparm, type)), 1993 IOCTL_INFO_FNC(VIDIOC_G_PARM, v4l_g_parm, v4l_print_streamparm, INFO_FL_CLEAR(v4l2_streamparm, type)),
2050 IOCTL_INFO_FNC(VIDIOC_S_PARM, v4l_s_parm, v4l_print_streamparm, INFO_FL_PRIO), 1994 IOCTL_INFO_FNC(VIDIOC_S_PARM, v4l_s_parm, v4l_print_streamparm, INFO_FL_PRIO),
2051 IOCTL_INFO_FNC(VIDIOC_G_STD, v4l_g_std, v4l_print_std, 0), 1995 IOCTL_INFO_STD(VIDIOC_G_STD, vidioc_g_std, v4l_print_std, 0),
2052 IOCTL_INFO_FNC(VIDIOC_S_STD, v4l_s_std, v4l_print_std, INFO_FL_PRIO), 1996 IOCTL_INFO_FNC(VIDIOC_S_STD, v4l_s_std, v4l_print_std, INFO_FL_PRIO),
2053 IOCTL_INFO_FNC(VIDIOC_ENUMSTD, v4l_enumstd, v4l_print_standard, INFO_FL_CLEAR(v4l2_standard, index)), 1997 IOCTL_INFO_FNC(VIDIOC_ENUMSTD, v4l_enumstd, v4l_print_standard, INFO_FL_CLEAR(v4l2_standard, index)),
2054 IOCTL_INFO_FNC(VIDIOC_ENUMINPUT, v4l_enuminput, v4l_print_enuminput, INFO_FL_CLEAR(v4l2_input, index)), 1998 IOCTL_INFO_FNC(VIDIOC_ENUMINPUT, v4l_enuminput, v4l_print_enuminput, INFO_FL_CLEAR(v4l2_input, index)),
@@ -2098,7 +2042,6 @@ static struct v4l2_ioctl_info v4l2_ioctls[] = {
2098 IOCTL_INFO_STD(VIDIOC_TRY_DECODER_CMD, vidioc_try_decoder_cmd, v4l_print_decoder_cmd, 0), 2042 IOCTL_INFO_STD(VIDIOC_TRY_DECODER_CMD, vidioc_try_decoder_cmd, v4l_print_decoder_cmd, 0),
2099 IOCTL_INFO_FNC(VIDIOC_DBG_S_REGISTER, v4l_dbg_s_register, v4l_print_dbg_register, 0), 2043 IOCTL_INFO_FNC(VIDIOC_DBG_S_REGISTER, v4l_dbg_s_register, v4l_print_dbg_register, 0),
2100 IOCTL_INFO_FNC(VIDIOC_DBG_G_REGISTER, v4l_dbg_g_register, v4l_print_dbg_register, 0), 2044 IOCTL_INFO_FNC(VIDIOC_DBG_G_REGISTER, v4l_dbg_g_register, v4l_print_dbg_register, 0),
2101 IOCTL_INFO_FNC(VIDIOC_DBG_G_CHIP_IDENT, v4l_dbg_g_chip_ident, v4l_print_dbg_chip_ident, 0),
2102 IOCTL_INFO_FNC(VIDIOC_S_HW_FREQ_SEEK, v4l_s_hw_freq_seek, v4l_print_hw_freq_seek, INFO_FL_PRIO), 2045 IOCTL_INFO_FNC(VIDIOC_S_HW_FREQ_SEEK, v4l_s_hw_freq_seek, v4l_print_hw_freq_seek, INFO_FL_PRIO),
2103 IOCTL_INFO_STD(VIDIOC_S_DV_TIMINGS, vidioc_s_dv_timings, v4l_print_dv_timings, INFO_FL_PRIO), 2046 IOCTL_INFO_STD(VIDIOC_S_DV_TIMINGS, vidioc_s_dv_timings, v4l_print_dv_timings, INFO_FL_PRIO),
2104 IOCTL_INFO_STD(VIDIOC_G_DV_TIMINGS, vidioc_g_dv_timings, v4l_print_dv_timings, 0), 2047 IOCTL_INFO_STD(VIDIOC_G_DV_TIMINGS, vidioc_g_dv_timings, v4l_print_dv_timings, 0),
diff --git a/drivers/media/v4l2-core/videobuf-dma-contig.c b/drivers/media/v4l2-core/videobuf-dma-contig.c
index 67f572c3fba2..65411adcd0ea 100644
--- a/drivers/media/v4l2-core/videobuf-dma-contig.c
+++ b/drivers/media/v4l2-core/videobuf-dma-contig.c
@@ -66,11 +66,14 @@ static void __videobuf_dc_free(struct device *dev,
66static void videobuf_vm_open(struct vm_area_struct *vma) 66static void videobuf_vm_open(struct vm_area_struct *vma)
67{ 67{
68 struct videobuf_mapping *map = vma->vm_private_data; 68 struct videobuf_mapping *map = vma->vm_private_data;
69 struct videobuf_queue *q = map->q;
69 70
70 dev_dbg(map->q->dev, "vm_open %p [count=%u,vma=%08lx-%08lx]\n", 71 dev_dbg(q->dev, "vm_open %p [count=%u,vma=%08lx-%08lx]\n",
71 map, map->count, vma->vm_start, vma->vm_end); 72 map, map->count, vma->vm_start, vma->vm_end);
72 73
74 videobuf_queue_lock(q);
73 map->count++; 75 map->count++;
76 videobuf_queue_unlock(q);
74} 77}
75 78
76static void videobuf_vm_close(struct vm_area_struct *vma) 79static void videobuf_vm_close(struct vm_area_struct *vma)
@@ -82,12 +85,11 @@ static void videobuf_vm_close(struct vm_area_struct *vma)
82 dev_dbg(q->dev, "vm_close %p [count=%u,vma=%08lx-%08lx]\n", 85 dev_dbg(q->dev, "vm_close %p [count=%u,vma=%08lx-%08lx]\n",
83 map, map->count, vma->vm_start, vma->vm_end); 86 map, map->count, vma->vm_start, vma->vm_end);
84 87
85 map->count--; 88 videobuf_queue_lock(q);
86 if (0 == map->count) { 89 if (!--map->count) {
87 struct videobuf_dma_contig_memory *mem; 90 struct videobuf_dma_contig_memory *mem;
88 91
89 dev_dbg(q->dev, "munmap %p q=%p\n", map, q); 92 dev_dbg(q->dev, "munmap %p q=%p\n", map, q);
90 videobuf_queue_lock(q);
91 93
92 /* We need first to cancel streams, before unmapping */ 94 /* We need first to cancel streams, before unmapping */
93 if (q->streaming) 95 if (q->streaming)
@@ -126,8 +128,8 @@ static void videobuf_vm_close(struct vm_area_struct *vma)
126 128
127 kfree(map); 129 kfree(map);
128 130
129 videobuf_queue_unlock(q);
130 } 131 }
132 videobuf_queue_unlock(q);
131} 133}
132 134
133static const struct vm_operations_struct videobuf_vm_ops = { 135static const struct vm_operations_struct videobuf_vm_ops = {
@@ -303,14 +305,9 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
303 goto error; 305 goto error;
304 306
305 /* Try to remap memory */ 307 /* Try to remap memory */
306
307 size = vma->vm_end - vma->vm_start; 308 size = vma->vm_end - vma->vm_start;
308 size = (size < mem->size) ? size : mem->size;
309
310 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); 309 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
311 retval = remap_pfn_range(vma, vma->vm_start, 310 retval = vm_iomap_memory(vma, vma->vm_start, size);
312 mem->dma_handle >> PAGE_SHIFT,
313 size, vma->vm_page_prot);
314 if (retval) { 311 if (retval) {
315 dev_err(q->dev, "mmap: remap failed with error %d. ", 312 dev_err(q->dev, "mmap: remap failed with error %d. ",
316 retval); 313 retval);
diff --git a/drivers/media/v4l2-core/videobuf-dma-sg.c b/drivers/media/v4l2-core/videobuf-dma-sg.c
index 828e7c10bd70..9db674ccdc68 100644
--- a/drivers/media/v4l2-core/videobuf-dma-sg.c
+++ b/drivers/media/v4l2-core/videobuf-dma-sg.c
@@ -338,11 +338,14 @@ EXPORT_SYMBOL_GPL(videobuf_dma_free);
338static void videobuf_vm_open(struct vm_area_struct *vma) 338static void videobuf_vm_open(struct vm_area_struct *vma)
339{ 339{
340 struct videobuf_mapping *map = vma->vm_private_data; 340 struct videobuf_mapping *map = vma->vm_private_data;
341 struct videobuf_queue *q = map->q;
341 342
342 dprintk(2, "vm_open %p [count=%d,vma=%08lx-%08lx]\n", map, 343 dprintk(2, "vm_open %p [count=%d,vma=%08lx-%08lx]\n", map,
343 map->count, vma->vm_start, vma->vm_end); 344 map->count, vma->vm_start, vma->vm_end);
344 345
346 videobuf_queue_lock(q);
345 map->count++; 347 map->count++;
348 videobuf_queue_unlock(q);
346} 349}
347 350
348static void videobuf_vm_close(struct vm_area_struct *vma) 351static void videobuf_vm_close(struct vm_area_struct *vma)
@@ -355,10 +358,9 @@ static void videobuf_vm_close(struct vm_area_struct *vma)
355 dprintk(2, "vm_close %p [count=%d,vma=%08lx-%08lx]\n", map, 358 dprintk(2, "vm_close %p [count=%d,vma=%08lx-%08lx]\n", map,
356 map->count, vma->vm_start, vma->vm_end); 359 map->count, vma->vm_start, vma->vm_end);
357 360
358 map->count--; 361 videobuf_queue_lock(q);
359 if (0 == map->count) { 362 if (!--map->count) {
360 dprintk(1, "munmap %p q=%p\n", map, q); 363 dprintk(1, "munmap %p q=%p\n", map, q);
361 videobuf_queue_lock(q);
362 for (i = 0; i < VIDEO_MAX_FRAME; i++) { 364 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
363 if (NULL == q->bufs[i]) 365 if (NULL == q->bufs[i])
364 continue; 366 continue;
@@ -374,9 +376,9 @@ static void videobuf_vm_close(struct vm_area_struct *vma)
374 q->bufs[i]->baddr = 0; 376 q->bufs[i]->baddr = 0;
375 q->ops->buf_release(q, q->bufs[i]); 377 q->ops->buf_release(q, q->bufs[i]);
376 } 378 }
377 videobuf_queue_unlock(q);
378 kfree(map); 379 kfree(map);
379 } 380 }
381 videobuf_queue_unlock(q);
380 return; 382 return;
381} 383}
382 384
diff --git a/drivers/media/v4l2-core/videobuf-vmalloc.c b/drivers/media/v4l2-core/videobuf-vmalloc.c
index 2ff7fcc77b11..1365c651c177 100644
--- a/drivers/media/v4l2-core/videobuf-vmalloc.c
+++ b/drivers/media/v4l2-core/videobuf-vmalloc.c
@@ -54,11 +54,14 @@ MODULE_LICENSE("GPL");
54static void videobuf_vm_open(struct vm_area_struct *vma) 54static void videobuf_vm_open(struct vm_area_struct *vma)
55{ 55{
56 struct videobuf_mapping *map = vma->vm_private_data; 56 struct videobuf_mapping *map = vma->vm_private_data;
57 struct videobuf_queue *q = map->q;
57 58
58 dprintk(2, "vm_open %p [count=%u,vma=%08lx-%08lx]\n", map, 59 dprintk(2, "vm_open %p [count=%u,vma=%08lx-%08lx]\n", map,
59 map->count, vma->vm_start, vma->vm_end); 60 map->count, vma->vm_start, vma->vm_end);
60 61
62 videobuf_queue_lock(q);
61 map->count++; 63 map->count++;
64 videobuf_queue_unlock(q);
62} 65}
63 66
64static void videobuf_vm_close(struct vm_area_struct *vma) 67static void videobuf_vm_close(struct vm_area_struct *vma)
@@ -70,12 +73,11 @@ static void videobuf_vm_close(struct vm_area_struct *vma)
70 dprintk(2, "vm_close %p [count=%u,vma=%08lx-%08lx]\n", map, 73 dprintk(2, "vm_close %p [count=%u,vma=%08lx-%08lx]\n", map,
71 map->count, vma->vm_start, vma->vm_end); 74 map->count, vma->vm_start, vma->vm_end);
72 75
73 map->count--; 76 videobuf_queue_lock(q);
74 if (0 == map->count) { 77 if (!--map->count) {
75 struct videobuf_vmalloc_memory *mem; 78 struct videobuf_vmalloc_memory *mem;
76 79
77 dprintk(1, "munmap %p q=%p\n", map, q); 80 dprintk(1, "munmap %p q=%p\n", map, q);
78 videobuf_queue_lock(q);
79 81
80 /* We need first to cancel streams, before unmapping */ 82 /* We need first to cancel streams, before unmapping */
81 if (q->streaming) 83 if (q->streaming)
@@ -114,8 +116,8 @@ static void videobuf_vm_close(struct vm_area_struct *vma)
114 116
115 kfree(map); 117 kfree(map);
116 118
117 videobuf_queue_unlock(q);
118 } 119 }
120 videobuf_queue_unlock(q);
119 121
120 return; 122 return;
121} 123}
diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c
index e3bdc3be91e1..9fc4bab2da97 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -2194,8 +2194,10 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
2194 */ 2194 */
2195 for (i = 0; i < q->num_buffers; i++) { 2195 for (i = 0; i < q->num_buffers; i++) {
2196 fileio->bufs[i].vaddr = vb2_plane_vaddr(q->bufs[i], 0); 2196 fileio->bufs[i].vaddr = vb2_plane_vaddr(q->bufs[i], 0);
2197 if (fileio->bufs[i].vaddr == NULL) 2197 if (fileio->bufs[i].vaddr == NULL) {
2198 ret = -EINVAL;
2198 goto err_reqbufs; 2199 goto err_reqbufs;
2200 }
2199 fileio->bufs[i].size = vb2_plane_size(q->bufs[i], 0); 2201 fileio->bufs[i].size = vb2_plane_size(q->bufs[i], 0);
2200 } 2202 }
2201 2203
diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipe.c b/drivers/staging/media/davinci_vpfe/dm365_ipipe.c
index 05673ed45ce4..766a071b0a22 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_ipipe.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_ipipe.c
@@ -1751,10 +1751,10 @@ static const struct media_entity_operations ipipe_media_ops = {
1751 */ 1751 */
1752void vpfe_ipipe_unregister_entities(struct vpfe_ipipe_device *vpfe_ipipe) 1752void vpfe_ipipe_unregister_entities(struct vpfe_ipipe_device *vpfe_ipipe)
1753{ 1753{
1754 /* cleanup entity */
1755 media_entity_cleanup(&vpfe_ipipe->subdev.entity);
1756 /* unregister subdev */ 1754 /* unregister subdev */
1757 v4l2_device_unregister_subdev(&vpfe_ipipe->subdev); 1755 v4l2_device_unregister_subdev(&vpfe_ipipe->subdev);
1756 /* cleanup entity */
1757 media_entity_cleanup(&vpfe_ipipe->subdev.entity);
1758} 1758}
1759 1759
1760/* 1760/*
diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c b/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
index b2f4ef84f3db..59540cd4bb98 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
@@ -947,10 +947,10 @@ void vpfe_ipipeif_unregister_entities(struct vpfe_ipipeif_device *ipipeif)
947 /* unregister video device */ 947 /* unregister video device */
948 vpfe_video_unregister(&ipipeif->video_in); 948 vpfe_video_unregister(&ipipeif->video_in);
949 949
950 /* cleanup entity */
951 media_entity_cleanup(&ipipeif->subdev.entity);
952 /* unregister subdev */ 950 /* unregister subdev */
953 v4l2_device_unregister_subdev(&ipipeif->subdev); 951 v4l2_device_unregister_subdev(&ipipeif->subdev);
952 /* cleanup entity */
953 media_entity_cleanup(&ipipeif->subdev.entity);
954} 954}
955 955
956int 956int
diff --git a/drivers/staging/media/davinci_vpfe/dm365_isif.c b/drivers/staging/media/davinci_vpfe/dm365_isif.c
index 5829360f74c9..ff48fce94fcb 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_isif.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_isif.c
@@ -1750,10 +1750,10 @@ static const struct media_entity_operations isif_media_ops = {
1750void vpfe_isif_unregister_entities(struct vpfe_isif_device *isif) 1750void vpfe_isif_unregister_entities(struct vpfe_isif_device *isif)
1751{ 1751{
1752 vpfe_video_unregister(&isif->video_out); 1752 vpfe_video_unregister(&isif->video_out);
1753 /* cleanup entity */
1754 media_entity_cleanup(&isif->subdev.entity);
1755 /* unregister subdev */ 1753 /* unregister subdev */
1756 v4l2_device_unregister_subdev(&isif->subdev); 1754 v4l2_device_unregister_subdev(&isif->subdev);
1755 /* cleanup entity */
1756 media_entity_cleanup(&isif->subdev.entity);
1757} 1757}
1758 1758
1759static void isif_restore_defaults(struct vpfe_isif_device *isif) 1759static void isif_restore_defaults(struct vpfe_isif_device *isif)
diff --git a/drivers/staging/media/davinci_vpfe/dm365_resizer.c b/drivers/staging/media/davinci_vpfe/dm365_resizer.c
index 126f84c4cb64..8e13bd494c98 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_resizer.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_resizer.c
@@ -1777,14 +1777,14 @@ void vpfe_resizer_unregister_entities(struct vpfe_resizer_device *vpfe_rsz)
1777 vpfe_video_unregister(&vpfe_rsz->resizer_a.video_out); 1777 vpfe_video_unregister(&vpfe_rsz->resizer_a.video_out);
1778 vpfe_video_unregister(&vpfe_rsz->resizer_b.video_out); 1778 vpfe_video_unregister(&vpfe_rsz->resizer_b.video_out);
1779 1779
1780 /* cleanup entity */
1781 media_entity_cleanup(&vpfe_rsz->crop_resizer.subdev.entity);
1782 media_entity_cleanup(&vpfe_rsz->resizer_a.subdev.entity);
1783 media_entity_cleanup(&vpfe_rsz->resizer_b.subdev.entity);
1784 /* unregister subdev */ 1780 /* unregister subdev */
1785 v4l2_device_unregister_subdev(&vpfe_rsz->crop_resizer.subdev); 1781 v4l2_device_unregister_subdev(&vpfe_rsz->crop_resizer.subdev);
1786 v4l2_device_unregister_subdev(&vpfe_rsz->resizer_a.subdev); 1782 v4l2_device_unregister_subdev(&vpfe_rsz->resizer_a.subdev);
1787 v4l2_device_unregister_subdev(&vpfe_rsz->resizer_b.subdev); 1783 v4l2_device_unregister_subdev(&vpfe_rsz->resizer_b.subdev);
1784 /* cleanup entity */
1785 media_entity_cleanup(&vpfe_rsz->crop_resizer.subdev.entity);
1786 media_entity_cleanup(&vpfe_rsz->resizer_a.subdev.entity);
1787 media_entity_cleanup(&vpfe_rsz->resizer_b.subdev.entity);
1788} 1788}
1789 1789
1790/* 1790/*
@@ -1865,12 +1865,12 @@ out_create_link:
1865 vpfe_video_unregister(&resizer->resizer_b.video_out); 1865 vpfe_video_unregister(&resizer->resizer_b.video_out);
1866out_video_out2_register: 1866out_video_out2_register:
1867 vpfe_video_unregister(&resizer->resizer_a.video_out); 1867 vpfe_video_unregister(&resizer->resizer_a.video_out);
1868 media_entity_cleanup(&resizer->crop_resizer.subdev.entity);
1869 media_entity_cleanup(&resizer->resizer_a.subdev.entity);
1870 media_entity_cleanup(&resizer->resizer_b.subdev.entity);
1871 v4l2_device_unregister_subdev(&resizer->crop_resizer.subdev); 1868 v4l2_device_unregister_subdev(&resizer->crop_resizer.subdev);
1872 v4l2_device_unregister_subdev(&resizer->resizer_a.subdev); 1869 v4l2_device_unregister_subdev(&resizer->resizer_a.subdev);
1873 v4l2_device_unregister_subdev(&resizer->resizer_b.subdev); 1870 v4l2_device_unregister_subdev(&resizer->resizer_b.subdev);
1871 media_entity_cleanup(&resizer->crop_resizer.subdev.entity);
1872 media_entity_cleanup(&resizer->resizer_a.subdev.entity);
1873 media_entity_cleanup(&resizer->resizer_b.subdev.entity);
1874 return ret; 1874 return ret;
1875} 1875}
1876 1876
diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
index ba913f1d955b..24d98a6866bb 100644
--- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
+++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
@@ -39,7 +39,7 @@ static struct media_entity *vpfe_get_input_entity
39 struct vpfe_device *vpfe_dev = video->vpfe_dev; 39 struct vpfe_device *vpfe_dev = video->vpfe_dev;
40 struct media_pad *remote; 40 struct media_pad *remote;
41 41
42 remote = media_entity_remote_source(&vpfe_dev->vpfe_isif.pads[0]); 42 remote = media_entity_remote_pad(&vpfe_dev->vpfe_isif.pads[0]);
43 if (remote == NULL) { 43 if (remote == NULL) {
44 pr_err("Invalid media connection to isif/ccdc\n"); 44 pr_err("Invalid media connection to isif/ccdc\n");
45 return NULL; 45 return NULL;
@@ -56,7 +56,7 @@ static int vpfe_update_current_ext_subdev(struct vpfe_video_device *video)
56 struct media_pad *remote; 56 struct media_pad *remote;
57 int i; 57 int i;
58 58
59 remote = media_entity_remote_source(&vpfe_dev->vpfe_isif.pads[0]); 59 remote = media_entity_remote_pad(&vpfe_dev->vpfe_isif.pads[0]);
60 if (remote == NULL) { 60 if (remote == NULL) {
61 pr_err("Invalid media connection to isif/ccdc\n"); 61 pr_err("Invalid media connection to isif/ccdc\n");
62 return -EINVAL; 62 return -EINVAL;
@@ -89,7 +89,7 @@ static int vpfe_update_current_ext_subdev(struct vpfe_video_device *video)
89static struct v4l2_subdev * 89static struct v4l2_subdev *
90vpfe_video_remote_subdev(struct vpfe_video_device *video, u32 *pad) 90vpfe_video_remote_subdev(struct vpfe_video_device *video, u32 *pad)
91{ 91{
92 struct media_pad *remote = media_entity_remote_source(&video->pad); 92 struct media_pad *remote = media_entity_remote_pad(&video->pad);
93 93
94 if (remote == NULL || remote->entity->type != MEDIA_ENT_T_V4L2_SUBDEV) 94 if (remote == NULL || remote->entity->type != MEDIA_ENT_T_V4L2_SUBDEV)
95 return NULL; 95 return NULL;
@@ -114,7 +114,7 @@ __vpfe_video_get_format(struct vpfe_video_device *video,
114 return -EINVAL; 114 return -EINVAL;
115 115
116 fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE; 116 fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
117 remote = media_entity_remote_source(&video->pad); 117 remote = media_entity_remote_pad(&video->pad);
118 fmt.pad = remote->index; 118 fmt.pad = remote->index;
119 119
120 ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &fmt); 120 ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &fmt);
@@ -245,7 +245,7 @@ static int vpfe_video_validate_pipeline(struct vpfe_pipeline *pipe)
245 return -EPIPE; 245 return -EPIPE;
246 246
247 /* Retrieve the source format */ 247 /* Retrieve the source format */
248 pad = media_entity_remote_source(pad); 248 pad = media_entity_remote_pad(pad);
249 if (pad == NULL || 249 if (pad == NULL ||
250 pad->entity->type != MEDIA_ENT_T_V4L2_SUBDEV) 250 pad->entity->type != MEDIA_ENT_T_V4L2_SUBDEV)
251 break; 251 break;
@@ -667,7 +667,7 @@ static int vpfe_enum_fmt(struct file *file, void *priv,
667 return -EINVAL; 667 return -EINVAL;
668 } 668 }
669 /* get the remote pad */ 669 /* get the remote pad */
670 remote = media_entity_remote_source(&video->pad); 670 remote = media_entity_remote_pad(&video->pad);
671 if (remote == NULL) { 671 if (remote == NULL) {
672 v4l2_err(&vpfe_dev->v4l2_dev, 672 v4l2_err(&vpfe_dev->v4l2_dev,
673 "invalid remote pad for video node\n"); 673 "invalid remote pad for video node\n");
@@ -1614,7 +1614,7 @@ int vpfe_video_register(struct vpfe_video_device *video,
1614void vpfe_video_unregister(struct vpfe_video_device *video) 1614void vpfe_video_unregister(struct vpfe_video_device *video)
1615{ 1615{
1616 if (video_is_registered(&video->video_dev)) { 1616 if (video_is_registered(&video->video_dev)) {
1617 media_entity_cleanup(&video->video_dev.entity);
1618 video_unregister_device(&video->video_dev); 1617 video_unregister_device(&video->video_dev);
1618 media_entity_cleanup(&video->video_dev.entity);
1619 } 1619 }
1620} 1620}
diff --git a/drivers/staging/media/dt3155v4l/dt3155v4l.c b/drivers/staging/media/dt3155v4l/dt3155v4l.c
index c32e0acde4f4..90d6ac469355 100644
--- a/drivers/staging/media/dt3155v4l/dt3155v4l.c
+++ b/drivers/staging/media/dt3155v4l/dt3155v4l.c
@@ -829,7 +829,6 @@ static struct video_device dt3155_vdev = {
829 .minor = -1, 829 .minor = -1,
830 .release = video_device_release, 830 .release = video_device_release,
831 .tvnorms = DT3155_CURRENT_NORM, 831 .tvnorms = DT3155_CURRENT_NORM,
832 .current_norm = DT3155_CURRENT_NORM,
833}; 832};
834 833
835/* same as in drivers/base/dma-coherent.c */ 834/* same as in drivers/base/dma-coherent.c */
diff --git a/drivers/staging/media/go7007/go7007-usb.c b/drivers/staging/media/go7007/go7007-usb.c
index 50066e01a6ed..46ed83245035 100644
--- a/drivers/staging/media/go7007/go7007-usb.c
+++ b/drivers/staging/media/go7007/go7007-usb.c
@@ -1124,7 +1124,7 @@ static int go7007_usb_probe(struct usb_interface *intf,
1124 case GO7007_BOARDID_LIFEVIEW_LR192: 1124 case GO7007_BOARDID_LIFEVIEW_LR192:
1125 printk(KERN_ERR "go7007-usb: The Lifeview TV Walker Ultra " 1125 printk(KERN_ERR "go7007-usb: The Lifeview TV Walker Ultra "
1126 "is not supported. Sorry!\n"); 1126 "is not supported. Sorry!\n");
1127 return 0; 1127 return -ENODEV;
1128 name = "Lifeview TV Walker Ultra"; 1128 name = "Lifeview TV Walker Ultra";
1129 board = &board_lifeview_lr192; 1129 board = &board_lifeview_lr192;
1130 break; 1130 break;
@@ -1140,7 +1140,7 @@ static int go7007_usb_probe(struct usb_interface *intf,
1140 default: 1140 default:
1141 printk(KERN_ERR "go7007-usb: unknown board ID %d!\n", 1141 printk(KERN_ERR "go7007-usb: unknown board ID %d!\n",
1142 (unsigned int)id->driver_info); 1142 (unsigned int)id->driver_info);
1143 return 0; 1143 return -ENODEV;
1144 } 1144 }
1145 1145
1146 go = go7007_alloc(&board->main_info, &intf->dev); 1146 go = go7007_alloc(&board->main_info, &intf->dev);
diff --git a/drivers/staging/media/lirc/lirc_imon.c b/drivers/staging/media/lirc/lirc_imon.c
index 0a2c45dd4475..4afa7da11f37 100644
--- a/drivers/staging/media/lirc/lirc_imon.c
+++ b/drivers/staging/media/lirc/lirc_imon.c
@@ -911,8 +911,8 @@ static int imon_probe(struct usb_interface *interface,
911 if (retval) { 911 if (retval) {
912 dev_err(dev, "%s: usb_submit_urb failed for intf0 (%d)\n", 912 dev_err(dev, "%s: usb_submit_urb failed for intf0 (%d)\n",
913 __func__, retval); 913 __func__, retval);
914 mutex_unlock(&context->ctx_lock); 914 alloc_status = 8;
915 goto exit; 915 goto unlock;
916 } 916 }
917 917
918 usb_set_intfdata(interface, context); 918 usb_set_intfdata(interface, context);
@@ -937,6 +937,8 @@ unlock:
937alloc_status_switch: 937alloc_status_switch:
938 938
939 switch (alloc_status) { 939 switch (alloc_status) {
940 case 8:
941 lirc_unregister_driver(driver->minor);
940 case 7: 942 case 7:
941 usb_free_urb(tx_urb); 943 usb_free_urb(tx_urb);
942 case 6: 944 case 6:
@@ -959,7 +961,6 @@ alloc_status_switch:
959 retval = 0; 961 retval = 0;
960 } 962 }
961 963
962exit:
963 mutex_unlock(&driver_lock); 964 mutex_unlock(&driver_lock);
964 965
965 return retval; 966 return retval;
diff --git a/drivers/staging/media/solo6x10/solo6x10-tw28.c b/drivers/staging/media/solo6x10/solo6x10-tw28.c
index ad00e2b60323..af65ea655f15 100644
--- a/drivers/staging/media/solo6x10/solo6x10-tw28.c
+++ b/drivers/staging/media/solo6x10/solo6x10-tw28.c
@@ -513,62 +513,82 @@ static int tw2815_setup(struct solo_dev *solo_dev, u8 dev_addr)
513#define FIRST_ACTIVE_LINE 0x0008 513#define FIRST_ACTIVE_LINE 0x0008
514#define LAST_ACTIVE_LINE 0x0102 514#define LAST_ACTIVE_LINE 0x0102
515 515
516static void saa7128_setup(struct solo_dev *solo_dev) 516static void saa712x_write_regs(struct solo_dev *dev, const uint8_t *vals,
517 int start, int n)
517{ 518{
518 int i; 519 for (;start < n; start++, vals++) {
519 unsigned char regs[128] = { 520 /* Skip read-only registers */
520 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 521 switch (start) {
521 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 522 /* case 0x00 ... 0x25: */
522 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 523 case 0x2e ... 0x37:
524 case 0x60:
525 case 0x7d:
526 continue;
527 }
528 solo_i2c_writebyte(dev, SOLO_I2C_SAA, 0x46, start, *vals);
529 }
530}
531
532#define SAA712x_reg7c (0x80 | ((LAST_ACTIVE_LINE & 0x100) >> 2) \
533 | ((FIRST_ACTIVE_LINE & 0x100) >> 4))
534
535static void saa712x_setup(struct solo_dev *dev)
536{
537 const int reg_start = 0x26;
538 const uint8_t saa7128_regs_ntsc[] = {
539 /* :0x26 */
540 0x0d, 0x00,
541 /* :0x28 */
542 0x59, 0x1d, 0x75, 0x3f, 0x06, 0x3f,
543 /* :0x2e XXX: read-only */
544 0x00, 0x00,
523 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 545 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
524 0x1C, 0x2B, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x00, 546 /* :0x38 */
525 0x59, 0x1d, 0x75, 0x3f, 0x06, 0x3f, 0x00, 0x00,
526 0x1c, 0x33, 0x00, 0x3f, 0x00, 0x00, 0x3f, 0x00,
527 0x1a, 0x1a, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 547 0x1a, 0x1a, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00,
548 /* :0x40 */
528 0x00, 0x00, 0x00, 0x68, 0x10, 0x97, 0x4c, 0x18, 549 0x00, 0x00, 0x00, 0x68, 0x10, 0x97, 0x4c, 0x18,
529 0x9b, 0x93, 0x9f, 0xff, 0x7c, 0x34, 0x3f, 0x3f, 550 0x9b, 0x93, 0x9f, 0xff, 0x7c, 0x34, 0x3f, 0x3f,
551 /* :0x50 */
530 0x3f, 0x83, 0x83, 0x80, 0x0d, 0x0f, 0xc3, 0x06, 552 0x3f, 0x83, 0x83, 0x80, 0x0d, 0x0f, 0xc3, 0x06,
531 0x02, 0x80, 0x71, 0x77, 0xa7, 0x67, 0x66, 0x2e, 553 0x02, 0x80, 0x71, 0x77, 0xa7, 0x67, 0x66, 0x2e,
554 /* :0x60 */
532 0x7b, 0x11, 0x4f, 0x1f, 0x7c, 0xf0, 0x21, 0x77, 555 0x7b, 0x11, 0x4f, 0x1f, 0x7c, 0xf0, 0x21, 0x77,
533 0x41, 0x88, 0x41, 0x12, 0xed, 0x10, 0x10, 0x00, 556 0x41, 0x88, 0x41, 0x52, 0xed, 0x10, 0x10, 0x00,
557 /* :0x70 */
558 0x41, 0xc3, 0x00, 0x3e, 0xb8, 0x02, 0x00, 0x00,
559 0x00, 0x00, FIRST_ACTIVE_LINE, LAST_ACTIVE_LINE & 0xff,
560 SAA712x_reg7c, 0x00, 0xff, 0xff,
561 }, saa7128_regs_pal[] = {
562 /* :0x26 */
563 0x0d, 0x00,
564 /* :0x28 */
565 0xe1, 0x1d, 0x75, 0x3f, 0x06, 0x3f,
566 /* :0x2e XXX: read-only */
567 0x00, 0x00,
568 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
569 /* :0x38 */
570 0x1a, 0x1a, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00,
571 /* :0x40 */
572 0x00, 0x00, 0x00, 0x68, 0x10, 0x97, 0x4c, 0x18,
573 0x9b, 0x93, 0x9f, 0xff, 0x7c, 0x34, 0x3f, 0x3f,
574 /* :0x50 */
575 0x3f, 0x83, 0x83, 0x80, 0x0d, 0x0f, 0xc3, 0x06,
576 0x02, 0x80, 0x0f, 0x77, 0xa7, 0x67, 0x66, 0x2e,
577 /* :0x60 */
578 0x7b, 0x02, 0x35, 0xcb, 0x8a, 0x09, 0x2a, 0x77,
579 0x41, 0x88, 0x41, 0x52, 0xf1, 0x10, 0x20, 0x00,
580 /* :0x70 */
534 0x41, 0xc3, 0x00, 0x3e, 0xb8, 0x02, 0x00, 0x00, 581 0x41, 0xc3, 0x00, 0x3e, 0xb8, 0x02, 0x00, 0x00,
535 0x00, 0x00, 0x08, 0xff, 0x80, 0x00, 0xff, 0xff, 582 0x00, 0x00, 0x12, 0x30,
583 SAA712x_reg7c | 0x40, 0x00, 0xff, 0xff,
536 }; 584 };
537 585
538 regs[0x7A] = FIRST_ACTIVE_LINE & 0xff; 586 if (dev->video_type == SOLO_VO_FMT_TYPE_PAL)
539 regs[0x7B] = LAST_ACTIVE_LINE & 0xff; 587 saa712x_write_regs(dev, saa7128_regs_pal, reg_start,
540 regs[0x7C] = ((1 << 7) | 588 sizeof(saa7128_regs_pal));
541 (((LAST_ACTIVE_LINE >> 8) & 1) << 6) | 589 else
542 (((FIRST_ACTIVE_LINE >> 8) & 1) << 4)); 590 saa712x_write_regs(dev, saa7128_regs_ntsc, reg_start,
543 591 sizeof(saa7128_regs_ntsc));
544 /* PAL: XXX: We could do a second set of regs to avoid this */
545 if (solo_dev->video_type != SOLO_VO_FMT_TYPE_NTSC) {
546 regs[0x28] = 0xE1;
547
548 regs[0x5A] = 0x0F;
549 regs[0x61] = 0x02;
550 regs[0x62] = 0x35;
551 regs[0x63] = 0xCB;
552 regs[0x64] = 0x8A;
553 regs[0x65] = 0x09;
554 regs[0x66] = 0x2A;
555
556 regs[0x6C] = 0xf1;
557 regs[0x6E] = 0x20;
558
559 regs[0x7A] = 0x06 + 12;
560 regs[0x7b] = 0x24 + 12;
561 regs[0x7c] |= 1 << 6;
562 }
563
564 /* First 0x25 bytes are read-only? */
565 for (i = 0x26; i < 128; i++) {
566 if (i == 0x60 || i == 0x7D)
567 continue;
568 solo_i2c_writebyte(solo_dev, SOLO_I2C_SAA, 0x46, i, regs[i]);
569 }
570
571 return;
572} 592}
573 593
574int solo_tw28_init(struct solo_dev *solo_dev) 594int solo_tw28_init(struct solo_dev *solo_dev)
@@ -609,7 +629,7 @@ int solo_tw28_init(struct solo_dev *solo_dev)
609 return -EINVAL; 629 return -EINVAL;
610 } 630 }
611 631
612 saa7128_setup(solo_dev); 632 saa712x_setup(solo_dev);
613 633
614 for (i = 0; i < solo_dev->tw28_cnt; i++) { 634 for (i = 0; i < solo_dev->tw28_cnt; i++) {
615 if ((solo_dev->tw2865 & (1 << i))) 635 if ((solo_dev->tw2865 & (1 << i)))
diff --git a/drivers/staging/media/solo6x10/solo6x10-v4l2-enc.c b/drivers/staging/media/solo6x10/solo6x10-v4l2-enc.c
index 98e2902afd74..a4c589604b02 100644
--- a/drivers/staging/media/solo6x10/solo6x10-v4l2-enc.c
+++ b/drivers/staging/media/solo6x10/solo6x10-v4l2-enc.c
@@ -996,12 +996,11 @@ static int solo_g_parm(struct file *file, void *priv,
996 struct v4l2_streamparm *sp) 996 struct v4l2_streamparm *sp)
997{ 997{
998 struct solo_enc_dev *solo_enc = video_drvdata(file); 998 struct solo_enc_dev *solo_enc = video_drvdata(file);
999 struct solo_dev *solo_dev = solo_enc->solo_dev;
1000 struct v4l2_captureparm *cp = &sp->parm.capture; 999 struct v4l2_captureparm *cp = &sp->parm.capture;
1001 1000
1002 cp->capability = V4L2_CAP_TIMEPERFRAME; 1001 cp->capability = V4L2_CAP_TIMEPERFRAME;
1003 cp->timeperframe.numerator = solo_enc->interval; 1002 cp->timeperframe.numerator = solo_enc->interval;
1004 cp->timeperframe.denominator = solo_dev->fps; 1003 cp->timeperframe.denominator = solo_enc->solo_dev->fps;
1005 cp->capturemode = 0; 1004 cp->capturemode = 0;
1006 /* XXX: Shouldn't we be able to get/set this from videobuf? */ 1005 /* XXX: Shouldn't we be able to get/set this from videobuf? */
1007 cp->readbuffers = 2; 1006 cp->readbuffers = 2;
@@ -1009,36 +1008,29 @@ static int solo_g_parm(struct file *file, void *priv,
1009 return 0; 1008 return 0;
1010} 1009}
1011 1010
1011static inline int calc_interval(u8 fps, u32 n, u32 d)
1012{
1013 if (!n || !d)
1014 return 1;
1015 if (d == fps)
1016 return n;
1017 n *= fps;
1018 return min(15U, n / d + (n % d >= (fps >> 1)));
1019}
1020
1012static int solo_s_parm(struct file *file, void *priv, 1021static int solo_s_parm(struct file *file, void *priv,
1013 struct v4l2_streamparm *sp) 1022 struct v4l2_streamparm *sp)
1014{ 1023{
1015 struct solo_enc_dev *solo_enc = video_drvdata(file); 1024 struct solo_enc_dev *solo_enc = video_drvdata(file);
1016 struct solo_dev *solo_dev = solo_enc->solo_dev; 1025 struct v4l2_fract *t = &sp->parm.capture.timeperframe;
1017 struct v4l2_captureparm *cp = &sp->parm.capture; 1026 u8 fps = solo_enc->solo_dev->fps;
1018 1027
1019 if (vb2_is_streaming(&solo_enc->vidq)) 1028 if (vb2_is_streaming(&solo_enc->vidq))
1020 return -EBUSY; 1029 return -EBUSY;
1021 1030
1022 if ((cp->timeperframe.numerator == 0) || 1031 solo_enc->interval = calc_interval(fps, t->numerator, t->denominator);
1023 (cp->timeperframe.denominator == 0)) {
1024 /* reset framerate */
1025 cp->timeperframe.numerator = 1;
1026 cp->timeperframe.denominator = solo_dev->fps;
1027 }
1028
1029 if (cp->timeperframe.denominator != solo_dev->fps)
1030 cp->timeperframe.denominator = solo_dev->fps;
1031
1032 if (cp->timeperframe.numerator > 15)
1033 cp->timeperframe.numerator = 15;
1034
1035 solo_enc->interval = cp->timeperframe.numerator;
1036
1037 cp->capability = V4L2_CAP_TIMEPERFRAME;
1038 cp->readbuffers = 2;
1039
1040 solo_update_mode(solo_enc); 1032 solo_update_mode(solo_enc);
1041 return 0; 1033 return solo_g_parm(file, priv, sp);
1042} 1034}
1043 1035
1044static long solo_enc_default(struct file *file, void *fh, 1036static long solo_enc_default(struct file *file, void *fh,
diff --git a/drivers/usb/gadget/f_uvc.c b/drivers/usb/gadget/f_uvc.c
index 5f91c7a59946..e2a1f50bd93c 100644
--- a/drivers/usb/gadget/f_uvc.c
+++ b/drivers/usb/gadget/f_uvc.c
@@ -406,7 +406,7 @@ uvc_register_video(struct uvc_device *uvc)
406 if (video == NULL) 406 if (video == NULL)
407 return -ENOMEM; 407 return -ENOMEM;
408 408
409 video->parent = &cdev->gadget->dev; 409 video->v4l2_dev = &uvc->v4l2_dev;
410 video->fops = &uvc_v4l2_fops; 410 video->fops = &uvc_v4l2_fops;
411 video->release = video_device_release; 411 video->release = video_device_release;
412 strlcpy(video->name, cdev->gadget->name, sizeof(video->name)); 412 strlcpy(video->name, cdev->gadget->name, sizeof(video->name));
@@ -563,6 +563,7 @@ uvc_function_unbind(struct usb_configuration *c, struct usb_function *f)
563 INFO(cdev, "uvc_function_unbind\n"); 563 INFO(cdev, "uvc_function_unbind\n");
564 564
565 video_unregister_device(uvc->vdev); 565 video_unregister_device(uvc->vdev);
566 v4l2_device_unregister(&uvc->v4l2_dev);
566 uvc->control_ep->driver_data = NULL; 567 uvc->control_ep->driver_data = NULL;
567 uvc->video.ep->driver_data = NULL; 568 uvc->video.ep->driver_data = NULL;
568 569
@@ -690,6 +691,11 @@ uvc_function_bind(struct usb_configuration *c, struct usb_function *f)
690 if ((ret = usb_function_deactivate(f)) < 0) 691 if ((ret = usb_function_deactivate(f)) < 0)
691 goto error; 692 goto error;
692 693
694 if (v4l2_device_register(&cdev->gadget->dev, &uvc->v4l2_dev)) {
695 printk(KERN_INFO "v4l2_device_register failed\n");
696 goto error;
697 }
698
693 /* Initialise video. */ 699 /* Initialise video. */
694 ret = uvc_video_init(&uvc->video); 700 ret = uvc_video_init(&uvc->video);
695 if (ret < 0) 701 if (ret < 0)
@@ -705,6 +711,7 @@ uvc_function_bind(struct usb_configuration *c, struct usb_function *f)
705 return 0; 711 return 0;
706 712
707error: 713error:
714 v4l2_device_unregister(&uvc->v4l2_dev);
708 if (uvc->vdev) 715 if (uvc->vdev)
709 video_device_release(uvc->vdev); 716 video_device_release(uvc->vdev);
710 717
diff --git a/drivers/usb/gadget/uvc.h b/drivers/usb/gadget/uvc.h
index 817e9e19cecf..7a9111de8054 100644
--- a/drivers/usb/gadget/uvc.h
+++ b/drivers/usb/gadget/uvc.h
@@ -57,6 +57,7 @@ struct uvc_event
57#include <linux/videodev2.h> 57#include <linux/videodev2.h>
58#include <linux/version.h> 58#include <linux/version.h>
59#include <media/v4l2-fh.h> 59#include <media/v4l2-fh.h>
60#include <media/v4l2-device.h>
60 61
61#include "uvc_queue.h" 62#include "uvc_queue.h"
62 63
@@ -145,6 +146,7 @@ enum uvc_state
145struct uvc_device 146struct uvc_device
146{ 147{
147 struct video_device *vdev; 148 struct video_device *vdev;
149 struct v4l2_device v4l2_dev;
148 enum uvc_state state; 150 enum uvc_state state;
149 struct usb_function func; 151 struct usb_function func;
150 struct uvc_video video; 152 struct uvc_video video;
diff --git a/include/media/davinci/vpbe_osd.h b/include/media/davinci/vpbe_osd.h
index 42628fcfe1bd..de59364d7ed2 100644
--- a/include/media/davinci/vpbe_osd.h
+++ b/include/media/davinci/vpbe_osd.h
@@ -82,9 +82,9 @@ enum osd_pix_format {
82 PIXFMT_4BPP, 82 PIXFMT_4BPP,
83 PIXFMT_8BPP, 83 PIXFMT_8BPP,
84 PIXFMT_RGB565, 84 PIXFMT_RGB565,
85 PIXFMT_YCbCrI, 85 PIXFMT_YCBCRI,
86 PIXFMT_RGB888, 86 PIXFMT_RGB888,
87 PIXFMT_YCrCbI, 87 PIXFMT_YCRCBI,
88 PIXFMT_NV12, 88 PIXFMT_NV12,
89 PIXFMT_OSD_ATTR, 89 PIXFMT_OSD_ATTR,
90}; 90};
diff --git a/include/media/media-device.h b/include/media/media-device.h
index eaade9815bb6..12155a9596c4 100644
--- a/include/media/media-device.h
+++ b/include/media/media-device.h
@@ -45,6 +45,7 @@ struct device;
45 * @entities: List of registered entities 45 * @entities: List of registered entities
46 * @lock: Entities list lock 46 * @lock: Entities list lock
47 * @graph_mutex: Entities graph operation lock 47 * @graph_mutex: Entities graph operation lock
48 * @link_notify: Link state change notification callback
48 * 49 *
49 * This structure represents an abstract high-level media device. It allows easy 50 * This structure represents an abstract high-level media device. It allows easy
50 * access to entities and provides basic media device-level support. The 51 * access to entities and provides basic media device-level support. The
@@ -75,10 +76,14 @@ struct media_device {
75 /* Serializes graph operations. */ 76 /* Serializes graph operations. */
76 struct mutex graph_mutex; 77 struct mutex graph_mutex;
77 78
78 int (*link_notify)(struct media_pad *source, 79 int (*link_notify)(struct media_link *link, u32 flags,
79 struct media_pad *sink, u32 flags); 80 unsigned int notification);
80}; 81};
81 82
83/* Supported link_notify @notification values. */
84#define MEDIA_DEV_NOTIFY_PRE_LINK_CH 0
85#define MEDIA_DEV_NOTIFY_POST_LINK_CH 1
86
82/* media_devnode to media_device */ 87/* media_devnode to media_device */
83#define to_media_device(node) container_of(node, struct media_device, devnode) 88#define to_media_device(node) container_of(node, struct media_device, devnode)
84 89
diff --git a/include/media/media-entity.h b/include/media/media-entity.h
index 0c16f518ee09..06bacf937d61 100644
--- a/include/media/media-entity.h
+++ b/include/media/media-entity.h
@@ -128,11 +128,14 @@ void media_entity_cleanup(struct media_entity *entity);
128 128
129int media_entity_create_link(struct media_entity *source, u16 source_pad, 129int media_entity_create_link(struct media_entity *source, u16 source_pad,
130 struct media_entity *sink, u16 sink_pad, u32 flags); 130 struct media_entity *sink, u16 sink_pad, u32 flags);
131void __media_entity_remove_links(struct media_entity *entity);
132void media_entity_remove_links(struct media_entity *entity);
133
131int __media_entity_setup_link(struct media_link *link, u32 flags); 134int __media_entity_setup_link(struct media_link *link, u32 flags);
132int media_entity_setup_link(struct media_link *link, u32 flags); 135int media_entity_setup_link(struct media_link *link, u32 flags);
133struct media_link *media_entity_find_link(struct media_pad *source, 136struct media_link *media_entity_find_link(struct media_pad *source,
134 struct media_pad *sink); 137 struct media_pad *sink);
135struct media_pad *media_entity_remote_source(struct media_pad *pad); 138struct media_pad *media_entity_remote_pad(struct media_pad *pad);
136 139
137struct media_entity *media_entity_get(struct media_entity *entity); 140struct media_entity *media_entity_get(struct media_entity *entity);
138void media_entity_put(struct media_entity *entity); 141void media_entity_put(struct media_entity *entity);
diff --git a/include/media/rc-map.h b/include/media/rc-map.h
index 5d5d3a30f04a..6628f5d01f52 100644
--- a/include/media/rc-map.h
+++ b/include/media/rc-map.h
@@ -111,6 +111,7 @@ void rc_map_init(void);
111#define RC_MAP_BUDGET_CI_OLD "rc-budget-ci-old" 111#define RC_MAP_BUDGET_CI_OLD "rc-budget-ci-old"
112#define RC_MAP_CINERGY_1400 "rc-cinergy-1400" 112#define RC_MAP_CINERGY_1400 "rc-cinergy-1400"
113#define RC_MAP_CINERGY "rc-cinergy" 113#define RC_MAP_CINERGY "rc-cinergy"
114#define RC_MAP_DELOCK_61959 "rc-delock-61959"
114#define RC_MAP_DIB0700_NEC_TABLE "rc-dib0700-nec" 115#define RC_MAP_DIB0700_NEC_TABLE "rc-dib0700-nec"
115#define RC_MAP_DIB0700_RC5_TABLE "rc-dib0700-rc5" 116#define RC_MAP_DIB0700_RC5_TABLE "rc-dib0700-rc5"
116#define RC_MAP_DIGITALNOW_TINYTWIN "rc-digitalnow-tinytwin" 117#define RC_MAP_DIGITALNOW_TINYTWIN "rc-digitalnow-tinytwin"
diff --git a/include/media/s5p_fimc.h b/include/media/s5p_fimc.h
index f50969025ef3..b975c285c8a9 100644
--- a/include/media/s5p_fimc.h
+++ b/include/media/s5p_fimc.h
@@ -13,6 +13,7 @@
13#define S5P_FIMC_H_ 13#define S5P_FIMC_H_
14 14
15#include <media/media-entity.h> 15#include <media/media-entity.h>
16#include <media/v4l2-dev.h>
16#include <media/v4l2-mediabus.h> 17#include <media/v4l2-mediabus.h>
17 18
18/* 19/*
@@ -115,6 +116,7 @@ struct s5p_platform_fimc {
115 * @color: the driver's private color format id 116 * @color: the driver's private color format id
116 * @memplanes: number of physically non-contiguous data planes 117 * @memplanes: number of physically non-contiguous data planes
117 * @colplanes: number of physically contiguous data planes 118 * @colplanes: number of physically contiguous data planes
119 * @colorspace: v4l2 colorspace (V4L2_COLORSPACE_*)
118 * @depth: per plane driver's private 'number of bits per pixel' 120 * @depth: per plane driver's private 'number of bits per pixel'
119 * @mdataplanes: bitmask indicating meta data plane(s), (1 << plane_no) 121 * @mdataplanes: bitmask indicating meta data plane(s), (1 << plane_no)
120 * @flags: flags indicating which operation mode format applies to 122 * @flags: flags indicating which operation mode format applies to
@@ -126,6 +128,7 @@ struct fimc_fmt {
126 u32 color; 128 u32 color;
127 u16 memplanes; 129 u16 memplanes;
128 u16 colplanes; 130 u16 colplanes;
131 u8 colorspace;
129 u8 depth[FIMC_MAX_PLANES]; 132 u8 depth[FIMC_MAX_PLANES];
130 u16 mdataplanes; 133 u16 mdataplanes;
131 u16 flags; 134 u16 flags;
@@ -140,37 +143,40 @@ struct fimc_fmt {
140#define FMT_FLAGS_YUV (1 << 7) 143#define FMT_FLAGS_YUV (1 << 7)
141}; 144};
142 145
143enum fimc_subdev_index { 146struct exynos_media_pipeline;
144 IDX_SENSOR,
145 IDX_CSIS,
146 IDX_FLITE,
147 IDX_IS_ISP,
148 IDX_FIMC,
149 IDX_MAX,
150};
151 147
152struct media_pipeline; 148/*
153struct v4l2_subdev; 149 * Media pipeline operations to be called from within a video node, i.e. the
150 * last entity within the pipeline. Implemented by related media device driver.
151 */
152struct exynos_media_pipeline_ops {
153 int (*prepare)(struct exynos_media_pipeline *p,
154 struct media_entity *me);
155 int (*unprepare)(struct exynos_media_pipeline *p);
156 int (*open)(struct exynos_media_pipeline *p, struct media_entity *me,
157 bool resume);
158 int (*close)(struct exynos_media_pipeline *p);
159 int (*set_stream)(struct exynos_media_pipeline *p, bool state);
160};
154 161
155struct fimc_pipeline { 162struct exynos_video_entity {
156 struct v4l2_subdev *subdevs[IDX_MAX]; 163 struct video_device vdev;
157 struct media_pipeline *m_pipeline; 164 struct exynos_media_pipeline *pipe;
158}; 165};
159 166
160/* 167struct exynos_media_pipeline {
161 * Media pipeline operations to be called from within the fimc(-lite) 168 struct media_pipeline mp;
162 * video node when it is the last entity of the pipeline. Implemented 169 const struct exynos_media_pipeline_ops *ops;
163 * by corresponding media device driver.
164 */
165struct fimc_pipeline_ops {
166 int (*open)(struct fimc_pipeline *p, struct media_entity *me,
167 bool resume);
168 int (*close)(struct fimc_pipeline *p);
169 int (*set_stream)(struct fimc_pipeline *p, bool state);
170}; 170};
171 171
172#define fimc_pipeline_call(f, op, p, args...) \ 172static inline struct exynos_video_entity *vdev_to_exynos_video_entity(
173 (!(f) ? -ENODEV : (((f)->pipeline_ops && (f)->pipeline_ops->op) ? \ 173 struct video_device *vdev)
174 (f)->pipeline_ops->op((p), ##args) : -ENOIOCTLCMD)) 174{
175 return container_of(vdev, struct exynos_video_entity, vdev);
176}
177
178#define fimc_pipeline_call(ent, op, args...) \
179 (!(ent) ? -ENOENT : (((ent)->pipe->ops && (ent)->pipe->ops->op) ? \
180 (ent)->pipe->ops->op(((ent)->pipe), ##args) : -ENOIOCTLCMD)) \
175 181
176#endif /* S5P_FIMC_H_ */ 182#endif /* S5P_FIMC_H_ */
diff --git a/include/media/sh_mobile_ceu.h b/include/media/sh_mobile_ceu.h
index 6fdb6adf6b2b..7f57056c22ba 100644
--- a/include/media/sh_mobile_ceu.h
+++ b/include/media/sh_mobile_ceu.h
@@ -22,6 +22,8 @@ struct sh_mobile_ceu_info {
22 int max_width; 22 int max_width;
23 int max_height; 23 int max_height;
24 struct sh_mobile_ceu_companion *csi2; 24 struct sh_mobile_ceu_companion *csi2;
25 struct v4l2_async_subdev **asd; /* Flat array, arranged in groups */
26 unsigned int *asd_sizes; /* 0-terminated array pf asd group sizes */
25}; 27};
26 28
27#endif /* __ASM_SH_MOBILE_CEU_H__ */ 29#endif /* __ASM_SH_MOBILE_CEU_H__ */
diff --git a/include/media/sh_mobile_csi2.h b/include/media/sh_mobile_csi2.h
index c586c4f7f16b..14030db51f13 100644
--- a/include/media/sh_mobile_csi2.h
+++ b/include/media/sh_mobile_csi2.h
@@ -33,6 +33,7 @@ struct sh_csi2_client_config {
33 unsigned char lanes; /* bitmask[3:0] */ 33 unsigned char lanes; /* bitmask[3:0] */
34 unsigned char channel; /* 0..3 */ 34 unsigned char channel; /* 0..3 */
35 struct platform_device *pdev; /* client platform device */ 35 struct platform_device *pdev; /* client platform device */
36 const char *name; /* async matching: client name */
36}; 37};
37 38
38struct v4l2_device; 39struct v4l2_device;
@@ -42,7 +43,6 @@ struct sh_csi2_pdata {
42 unsigned int flags; 43 unsigned int flags;
43 struct sh_csi2_client_config *clients; 44 struct sh_csi2_client_config *clients;
44 int num_clients; 45 int num_clients;
45 struct v4l2_device *v4l2_dev;
46}; 46};
47 47
48#endif 48#endif
diff --git a/include/media/soc_camera.h b/include/media/soc_camera.h
index ff77d08c30fd..34d2414f2b8c 100644
--- a/include/media/soc_camera.h
+++ b/include/media/soc_camera.h
@@ -19,11 +19,13 @@
19#include <linux/videodev2.h> 19#include <linux/videodev2.h>
20#include <media/videobuf-core.h> 20#include <media/videobuf-core.h>
21#include <media/videobuf2-core.h> 21#include <media/videobuf2-core.h>
22#include <media/v4l2-async.h>
22#include <media/v4l2-ctrls.h> 23#include <media/v4l2-ctrls.h>
23#include <media/v4l2-device.h> 24#include <media/v4l2-device.h>
24 25
25struct file; 26struct file;
26struct soc_camera_desc; 27struct soc_camera_desc;
28struct soc_camera_async_client;
27 29
28struct soc_camera_device { 30struct soc_camera_device {
29 struct list_head list; /* list of all registered devices */ 31 struct list_head list; /* list of all registered devices */
@@ -49,6 +51,10 @@ struct soc_camera_device {
49 /* soc_camera.c private count. Only accessed with .host_lock held */ 51 /* soc_camera.c private count. Only accessed with .host_lock held */
50 int use_count; 52 int use_count;
51 struct file *streamer; /* stream owner */ 53 struct file *streamer; /* stream owner */
54 struct v4l2_clk *clk;
55 /* Asynchronous subdevice management */
56 struct soc_camera_async_client *sasc;
57 /* video buffer queue */
52 union { 58 union {
53 struct videobuf_queue vb_vidq; 59 struct videobuf_queue vb_vidq;
54 struct vb2_queue vb2_vidq; 60 struct vb2_queue vb2_vidq;
@@ -58,21 +64,38 @@ struct soc_camera_device {
58/* Host supports programmable stride */ 64/* Host supports programmable stride */
59#define SOCAM_HOST_CAP_STRIDE (1 << 0) 65#define SOCAM_HOST_CAP_STRIDE (1 << 0)
60 66
67enum soc_camera_subdev_role {
68 SOCAM_SUBDEV_DATA_SOURCE = 1,
69 SOCAM_SUBDEV_DATA_SINK,
70 SOCAM_SUBDEV_DATA_PROCESSOR,
71};
72
73struct soc_camera_async_subdev {
74 struct v4l2_async_subdev asd;
75 enum soc_camera_subdev_role role;
76};
77
61struct soc_camera_host { 78struct soc_camera_host {
62 struct v4l2_device v4l2_dev; 79 struct v4l2_device v4l2_dev;
63 struct list_head list; 80 struct list_head list;
64 struct mutex host_lock; /* Protect pipeline modifications */ 81 struct mutex host_lock; /* Main synchronisation lock */
82 struct mutex clk_lock; /* Protect pipeline modifications */
65 unsigned char nr; /* Host number */ 83 unsigned char nr; /* Host number */
66 u32 capabilities; 84 u32 capabilities;
85 struct soc_camera_device *icd; /* Currently attached client */
67 void *priv; 86 void *priv;
68 const char *drv_name; 87 const char *drv_name;
69 struct soc_camera_host_ops *ops; 88 struct soc_camera_host_ops *ops;
89 struct v4l2_async_subdev **asd; /* Flat array, arranged in groups */
90 unsigned int *asd_sizes; /* 0-terminated array of asd group sizes */
70}; 91};
71 92
72struct soc_camera_host_ops { 93struct soc_camera_host_ops {
73 struct module *owner; 94 struct module *owner;
74 int (*add)(struct soc_camera_device *); 95 int (*add)(struct soc_camera_device *);
75 void (*remove)(struct soc_camera_device *); 96 void (*remove)(struct soc_camera_device *);
97 int (*clock_start)(struct soc_camera_host *);
98 void (*clock_stop)(struct soc_camera_host *);
76 /* 99 /*
77 * .get_formats() is called for each client device format, but 100 * .get_formats() is called for each client device format, but
78 * .put_formats() is only called once. Further, if any of the calls to 101 * .put_formats() is only called once. Further, if any of the calls to
@@ -157,6 +180,7 @@ struct soc_camera_host_desc {
157}; 180};
158 181
159/* 182/*
183 * Platform data for "soc-camera-pdrv"
160 * This MUST be kept binary-identical to struct soc_camera_link below, until 184 * This MUST be kept binary-identical to struct soc_camera_link below, until
161 * it is completely replaced by this one, after which we can split it into its 185 * it is completely replaced by this one, after which we can split it into its
162 * two components. 186 * two components.
@@ -322,14 +346,17 @@ static inline void soc_camera_limit_side(int *start, int *length,
322unsigned long soc_camera_apply_board_flags(struct soc_camera_subdev_desc *ssdd, 346unsigned long soc_camera_apply_board_flags(struct soc_camera_subdev_desc *ssdd,
323 const struct v4l2_mbus_config *cfg); 347 const struct v4l2_mbus_config *cfg);
324 348
325int soc_camera_power_on(struct device *dev, struct soc_camera_subdev_desc *ssdd); 349int soc_camera_power_init(struct device *dev, struct soc_camera_subdev_desc *ssdd);
326int soc_camera_power_off(struct device *dev, struct soc_camera_subdev_desc *ssdd); 350int soc_camera_power_on(struct device *dev, struct soc_camera_subdev_desc *ssdd,
351 struct v4l2_clk *clk);
352int soc_camera_power_off(struct device *dev, struct soc_camera_subdev_desc *ssdd,
353 struct v4l2_clk *clk);
327 354
328static inline int soc_camera_set_power(struct device *dev, 355static inline int soc_camera_set_power(struct device *dev,
329 struct soc_camera_subdev_desc *ssdd, bool on) 356 struct soc_camera_subdev_desc *ssdd, struct v4l2_clk *clk, bool on)
330{ 357{
331 return on ? soc_camera_power_on(dev, ssdd) 358 return on ? soc_camera_power_on(dev, ssdd, clk)
332 : soc_camera_power_off(dev, ssdd); 359 : soc_camera_power_off(dev, ssdd, clk);
333} 360}
334 361
335/* This is only temporary here - until v4l2-subdev begins to link to video_device */ 362/* This is only temporary here - until v4l2-subdev begins to link to video_device */
@@ -346,9 +373,9 @@ static inline struct soc_camera_subdev_desc *soc_camera_i2c_to_desc(const struct
346 return client->dev.platform_data; 373 return client->dev.platform_data;
347} 374}
348 375
349static inline struct v4l2_subdev *soc_camera_vdev_to_subdev(const struct video_device *vdev) 376static inline struct v4l2_subdev *soc_camera_vdev_to_subdev(struct video_device *vdev)
350{ 377{
351 struct soc_camera_device *icd = dev_get_drvdata(vdev->parent); 378 struct soc_camera_device *icd = video_get_drvdata(vdev);
352 return soc_camera_to_subdev(icd); 379 return soc_camera_to_subdev(icd);
353} 380}
354 381
diff --git a/include/media/ths7303.h b/include/media/ths7303.h
index 980ec51d574d..a7b49297da82 100644
--- a/include/media/ths7303.h
+++ b/include/media/ths7303.h
@@ -30,13 +30,11 @@
30 * @ch_1: Bias value for channel one. 30 * @ch_1: Bias value for channel one.
31 * @ch_2: Bias value for channel two. 31 * @ch_2: Bias value for channel two.
32 * @ch_3: Bias value for channel three. 32 * @ch_3: Bias value for channel three.
33 * @init_enable: initalize on init.
34 */ 33 */
35struct ths7303_platform_data { 34struct ths7303_platform_data {
36 u8 ch_1; 35 u8 ch_1;
37 u8 ch_2; 36 u8 ch_2;
38 u8 ch_3; 37 u8 ch_3;
39 u8 init_enable;
40}; 38};
41 39
42#endif 40#endif
diff --git a/include/media/tveeprom.h b/include/media/tveeprom.h
index a8ad75a9152a..4a1191abd936 100644
--- a/include/media/tveeprom.h
+++ b/include/media/tveeprom.h
@@ -1,6 +1,17 @@
1/* 1/*
2 */ 2 */
3 3
4enum tveeprom_audio_processor {
5 /* No audio processor present */
6 TVEEPROM_AUDPROC_NONE,
7 /* The audio processor is internal to the video processor */
8 TVEEPROM_AUDPROC_INTERNAL,
9 /* The audio processor is a MSPXXXX device */
10 TVEEPROM_AUDPROC_MSP,
11 /* The audio processor is another device */
12 TVEEPROM_AUDPROC_OTHER,
13};
14
4struct tveeprom { 15struct tveeprom {
5 u32 has_radio; 16 u32 has_radio;
6 /* If has_ir == 0, then it is unknown what the IR capabilities are, 17 /* If has_ir == 0, then it is unknown what the IR capabilities are,
diff --git a/include/media/tvp7002.h b/include/media/tvp7002.h
index ee4353459ef5..fadb6afe9ef0 100644
--- a/include/media/tvp7002.h
+++ b/include/media/tvp7002.h
@@ -26,31 +26,29 @@
26#ifndef _TVP7002_H_ 26#ifndef _TVP7002_H_
27#define _TVP7002_H_ 27#define _TVP7002_H_
28 28
29/* Platform-dependent data 29#define TVP7002_MODULE_NAME "tvp7002"
30 * 30
31 * clk_polarity: 31/**
32 * 0 -> data clocked out on rising edge of DATACLK signal 32 * struct tvp7002_config - Platform dependent data
33 * 1 -> data clocked out on falling edge of DATACLK signal 33 *@clk_polarity: Clock polarity
34 * hs_polarity: 34 * 0 - Data clocked out on rising edge of DATACLK signal
35 * 0 -> active low HSYNC output 35 * 1 - Data clocked out on falling edge of DATACLK signal
36 * 1 -> active high HSYNC output 36 *@hs_polarity: HSYNC polarity
37 * sog_polarity: 37 * 0 - Active low HSYNC output, 1 - Active high HSYNC output
38 * 0 -> normal operation 38 *@vs_polarity: VSYNC Polarity
39 * 1 -> operation with polarity inverted 39 * 0 - Active low VSYNC output, 1 - Active high VSYNC output
40 * vs_polarity: 40 *@fid_polarity: Active-high Field ID polarity.
41 * 0 -> active low VSYNC output 41 * 0 - The field ID output is set to logic 1 for an odd field
42 * 1 -> active high VSYNC output 42 * (field 1) and set to logic 0 for an even field (field 0).
43 * fid_polarity: 43 * 1 - Operation with polarity inverted.
44 * 0 -> the field ID output is set to logic 1 for an odd 44 *@sog_polarity: Active high Sync on Green output polarity.
45 * field (field 1) and set to logic 0 for an even 45 * 0 - Normal operation, 1 - Operation with polarity inverted
46 * field (field 0).
47 * 1 -> operation with polarity inverted.
48 */ 46 */
49struct tvp7002_config { 47struct tvp7002_config {
50 u8 clk_polarity; 48 bool clk_polarity;
51 u8 hs_polarity; 49 bool hs_polarity;
52 u8 vs_polarity; 50 bool vs_polarity;
53 u8 fid_polarity; 51 bool fid_polarity;
54 u8 sog_polarity; 52 bool sog_polarity;
55}; 53};
56#endif 54#endif
diff --git a/include/media/v4l2-async.h b/include/media/v4l2-async.h
new file mode 100644
index 000000000000..c3ec6ac75f7e
--- /dev/null
+++ b/include/media/v4l2-async.h
@@ -0,0 +1,105 @@
1/*
2 * V4L2 asynchronous subdevice registration API
3 *
4 * Copyright (C) 2012-2013, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#ifndef V4L2_ASYNC_H
12#define V4L2_ASYNC_H
13
14#include <linux/list.h>
15#include <linux/mutex.h>
16
17struct device;
18struct v4l2_device;
19struct v4l2_subdev;
20struct v4l2_async_notifier;
21
22/* A random max subdevice number, used to allocate an array on stack */
23#define V4L2_MAX_SUBDEVS 128U
24
25enum v4l2_async_bus_type {
26 V4L2_ASYNC_BUS_CUSTOM,
27 V4L2_ASYNC_BUS_PLATFORM,
28 V4L2_ASYNC_BUS_I2C,
29};
30
31/**
32 * struct v4l2_async_subdev - sub-device descriptor, as known to a bridge
33 * @bus_type: subdevice bus type to select the appropriate matching method
34 * @match: union of per-bus type matching data sets
35 * @list: used to link struct v4l2_async_subdev objects, waiting to be
36 * probed, to a notifier->waiting list
37 */
38struct v4l2_async_subdev {
39 enum v4l2_async_bus_type bus_type;
40 union {
41 struct {
42 const char *name;
43 } platform;
44 struct {
45 int adapter_id;
46 unsigned short address;
47 } i2c;
48 struct {
49 bool (*match)(struct device *,
50 struct v4l2_async_subdev *);
51 void *priv;
52 } custom;
53 } match;
54
55 /* v4l2-async core private: not to be used by drivers */
56 struct list_head list;
57};
58
59/**
60 * v4l2_async_subdev_list - provided by subdevices
61 * @list: links struct v4l2_async_subdev_list objects to a global list
62 * before probing, and onto notifier->done after probing
63 * @asd: pointer to respective struct v4l2_async_subdev
64 * @notifier: pointer to managing notifier
65 */
66struct v4l2_async_subdev_list {
67 struct list_head list;
68 struct v4l2_async_subdev *asd;
69 struct v4l2_async_notifier *notifier;
70};
71
72/**
73 * v4l2_async_notifier - v4l2_device notifier data
74 * @num_subdevs:number of subdevices
75 * @subdev: array of pointers to subdevice descriptors
76 * @v4l2_dev: pointer to struct v4l2_device
77 * @waiting: list of struct v4l2_async_subdev, waiting for their drivers
78 * @done: list of struct v4l2_async_subdev_list, already probed
79 * @list: member in a global list of notifiers
80 * @bound: a subdevice driver has successfully probed one of subdevices
81 * @complete: all subdevices have been probed successfully
82 * @unbind: a subdevice is leaving
83 */
84struct v4l2_async_notifier {
85 unsigned int num_subdevs;
86 struct v4l2_async_subdev **subdev;
87 struct v4l2_device *v4l2_dev;
88 struct list_head waiting;
89 struct list_head done;
90 struct list_head list;
91 int (*bound)(struct v4l2_async_notifier *notifier,
92 struct v4l2_subdev *subdev,
93 struct v4l2_async_subdev *asd);
94 int (*complete)(struct v4l2_async_notifier *notifier);
95 void (*unbind)(struct v4l2_async_notifier *notifier,
96 struct v4l2_subdev *subdev,
97 struct v4l2_async_subdev *asd);
98};
99
100int v4l2_async_notifier_register(struct v4l2_device *v4l2_dev,
101 struct v4l2_async_notifier *notifier);
102void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier);
103int v4l2_async_register_subdev(struct v4l2_subdev *sd);
104void v4l2_async_unregister_subdev(struct v4l2_subdev *sd);
105#endif
diff --git a/include/media/v4l2-chip-ident.h b/include/media/v4l2-chip-ident.h
deleted file mode 100644
index c259b36bf1e9..000000000000
--- a/include/media/v4l2-chip-ident.h
+++ /dev/null
@@ -1,352 +0,0 @@
1/*
2 v4l2 chip identifiers header
3
4 This header provides a list of chip identifiers that can be returned
5 through the VIDIOC_DBG_G_CHIP_IDENT ioctl.
6
7 Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl>
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24#ifndef V4L2_CHIP_IDENT_H_
25#define V4L2_CHIP_IDENT_H_
26
27/* VIDIOC_DBG_G_CHIP_IDENT: identifies the actual chip installed on the board */
28
29/* KEEP THIS LIST ORDERED BY ID!
30 Otherwise it will be hard to see which ranges are already in use when
31 adding support to a new chip family. */
32enum {
33 /* general idents: reserved range 0-49 */
34 V4L2_IDENT_NONE = 0, /* No chip matched */
35 V4L2_IDENT_AMBIGUOUS = 1, /* Match too general, multiple chips matched */
36 V4L2_IDENT_UNKNOWN = 2, /* Chip found, but cannot identify */
37
38 /* module tvaudio: reserved range 50-99 */
39 V4L2_IDENT_TVAUDIO = 50, /* A tvaudio chip, unknown which it is exactly */
40
41 /* Sony IMX074 */
42 V4L2_IDENT_IMX074 = 74,
43
44 /* module saa7110: just ident 100 */
45 V4L2_IDENT_SAA7110 = 100,
46
47 /* module saa7115: reserved range 101-149 */
48 V4L2_IDENT_SAA7111 = 101,
49 V4L2_IDENT_SAA7111A = 102,
50 V4L2_IDENT_SAA7113 = 103,
51 V4L2_IDENT_SAA7114 = 104,
52 V4L2_IDENT_SAA7115 = 105,
53 V4L2_IDENT_SAA7118 = 108,
54
55 /* module saa7127: reserved range 150-199 */
56 V4L2_IDENT_SAA7127 = 157,
57 V4L2_IDENT_SAA7129 = 159,
58
59 /* module cx25840: reserved range 200-249 */
60 V4L2_IDENT_CX25836 = 236,
61 V4L2_IDENT_CX25837 = 237,
62 V4L2_IDENT_CX25840 = 240,
63 V4L2_IDENT_CX25841 = 241,
64 V4L2_IDENT_CX25842 = 242,
65 V4L2_IDENT_CX25843 = 243,
66
67 /* OmniVision sensors: reserved range 250-299 */
68 V4L2_IDENT_OV7670 = 250,
69 V4L2_IDENT_OV7720 = 251,
70 V4L2_IDENT_OV7725 = 252,
71 V4L2_IDENT_OV7660 = 253,
72 V4L2_IDENT_OV9650 = 254,
73 V4L2_IDENT_OV9655 = 255,
74 V4L2_IDENT_SOI968 = 256,
75 V4L2_IDENT_OV9640 = 257,
76 V4L2_IDENT_OV6650 = 258,
77 V4L2_IDENT_OV2640 = 259,
78 V4L2_IDENT_OV9740 = 260,
79 V4L2_IDENT_OV5642 = 261,
80
81 /* module saa7146: reserved range 300-309 */
82 V4L2_IDENT_SAA7146 = 300,
83
84 /* Conexant MPEG encoder/decoders: reserved range 400-420 */
85 V4L2_IDENT_CX23418_843 = 403, /* Integrated A/V Decoder on the '418 */
86 V4L2_IDENT_CX23415 = 415,
87 V4L2_IDENT_CX23416 = 416,
88 V4L2_IDENT_CX23417 = 417,
89 V4L2_IDENT_CX23418 = 418,
90
91 /* module bt819: reserved range 810-819 */
92 V4L2_IDENT_BT815A = 815,
93 V4L2_IDENT_BT817A = 817,
94 V4L2_IDENT_BT819A = 819,
95
96 /* module au0828 */
97 V4L2_IDENT_AU0828 = 828,
98
99 /* module bttv: ident 848 + 849 */
100 V4L2_IDENT_BT848 = 848,
101 V4L2_IDENT_BT849 = 849,
102
103 /* module bt856: just ident 856 */
104 V4L2_IDENT_BT856 = 856,
105
106 /* module bt866: just ident 866 */
107 V4L2_IDENT_BT866 = 866,
108
109 /* module bttv: ident 878 + 879 */
110 V4L2_IDENT_BT878 = 878,
111 V4L2_IDENT_BT879 = 879,
112
113 /* module ks0127: reserved range 1120-1129 */
114 V4L2_IDENT_KS0122S = 1122,
115 V4L2_IDENT_KS0127 = 1127,
116 V4L2_IDENT_KS0127B = 1128,
117
118 /* module indycam: just ident 2000 */
119 V4L2_IDENT_INDYCAM = 2000,
120
121 /* module vp27smpx: just ident 2700 */
122 V4L2_IDENT_VP27SMPX = 2700,
123
124 /* module vpx3220: reserved range: 3210-3229 */
125 V4L2_IDENT_VPX3214C = 3214,
126 V4L2_IDENT_VPX3216B = 3216,
127 V4L2_IDENT_VPX3220A = 3220,
128
129 /* VX855 just ident 3409 */
130 /* Other via devs could use 3314, 3324, 3327, 3336, 3364, 3353 */
131 V4L2_IDENT_VIA_VX855 = 3409,
132
133 /* module tvp5150 */
134 V4L2_IDENT_TVP5150 = 5150,
135
136 /* module saa5246a: just ident 5246 */
137 V4L2_IDENT_SAA5246A = 5246,
138
139 /* module saa5249: just ident 5249 */
140 V4L2_IDENT_SAA5249 = 5249,
141
142 /* module cs5345: just ident 5345 */
143 V4L2_IDENT_CS5345 = 5345,
144
145 /* module tea6415c: just ident 6415 */
146 V4L2_IDENT_TEA6415C = 6415,
147
148 /* module tea6420: just ident 6420 */
149 V4L2_IDENT_TEA6420 = 6420,
150
151 /* module saa6588: just ident 6588 */
152 V4L2_IDENT_SAA6588 = 6588,
153
154 /* module vs6624: just ident 6624 */
155 V4L2_IDENT_VS6624 = 6624,
156
157 /* module saa6752hs: reserved range 6750-6759 */
158 V4L2_IDENT_SAA6752HS = 6752,
159 V4L2_IDENT_SAA6752HS_AC3 = 6753,
160
161 /* modules tef6862: just ident 6862 */
162 V4L2_IDENT_TEF6862 = 6862,
163
164 /* module tvp7002: just ident 7002 */
165 V4L2_IDENT_TVP7002 = 7002,
166
167 /* module adv7170: just ident 7170 */
168 V4L2_IDENT_ADV7170 = 7170,
169
170 /* module adv7175: just ident 7175 */
171 V4L2_IDENT_ADV7175 = 7175,
172
173 /* module adv7180: just ident 7180 */
174 V4L2_IDENT_ADV7180 = 7180,
175
176 /* module adv7183: just ident 7183 */
177 V4L2_IDENT_ADV7183 = 7183,
178
179 /* module saa7185: just ident 7185 */
180 V4L2_IDENT_SAA7185 = 7185,
181
182 /* module saa7191: just ident 7191 */
183 V4L2_IDENT_SAA7191 = 7191,
184
185 /* module ths7303: just ident 7303 */
186 V4L2_IDENT_THS7303 = 7303,
187
188 /* module adv7343: just ident 7343 */
189 V4L2_IDENT_ADV7343 = 7343,
190
191 /* module ths7353: just ident 7353 */
192 V4L2_IDENT_THS7353 = 7353,
193
194 /* module adv7393: just ident 7393 */
195 V4L2_IDENT_ADV7393 = 7393,
196
197 /* module adv7604: just ident 7604 */
198 V4L2_IDENT_ADV7604 = 7604,
199
200 /* module saa7706h: just ident 7706 */
201 V4L2_IDENT_SAA7706H = 7706,
202
203 /* module mt9v011, just ident 8243 */
204 V4L2_IDENT_MT9V011 = 8243,
205
206 /* module wm8739: just ident 8739 */
207 V4L2_IDENT_WM8739 = 8739,
208
209 /* module wm8775: just ident 8775 */
210 V4L2_IDENT_WM8775 = 8775,
211
212 /* Marvell controllers starting at 8801 */
213 V4L2_IDENT_CAFE = 8801,
214 V4L2_IDENT_ARMADA610 = 8802,
215
216 /* AKM AK8813/AK8814 */
217 V4L2_IDENT_AK8813 = 8813,
218 V4L2_IDENT_AK8814 = 8814,
219
220 /* module cx23885 and cx25840 */
221 V4L2_IDENT_CX23885 = 8850,
222 V4L2_IDENT_CX23885_AV = 8851, /* Integrated A/V decoder */
223 V4L2_IDENT_CX23887 = 8870,
224 V4L2_IDENT_CX23887_AV = 8871, /* Integrated A/V decoder */
225 V4L2_IDENT_CX23888 = 8880,
226 V4L2_IDENT_CX23888_AV = 8881, /* Integrated A/V decoder */
227 V4L2_IDENT_CX23888_IR = 8882, /* Integrated infrared controller */
228
229 /* module ad9389b: just ident 9389 */
230 V4L2_IDENT_AD9389B = 9389,
231
232 /* module tda9840: just ident 9840 */
233 V4L2_IDENT_TDA9840 = 9840,
234
235 /* module tw9910: just ident 9910 */
236 V4L2_IDENT_TW9910 = 9910,
237
238 /* module sn9c20x: just ident 10000 */
239 V4L2_IDENT_SN9C20X = 10000,
240
241 /* module cx231xx and cx25840 */
242 V4L2_IDENT_CX2310X_AV = 23099, /* Integrated A/V decoder; not in '100 */
243 V4L2_IDENT_CX23100 = 23100,
244 V4L2_IDENT_CX23101 = 23101,
245 V4L2_IDENT_CX23102 = 23102,
246
247 /* module msp3400: reserved range 34000-34999 for msp34xx */
248 V4L2_IDENT_MSPX4XX = 34000, /* generic MSPX4XX identifier, only
249 use internally (tveeprom.c). */
250
251 V4L2_IDENT_MSP3400B = 34002,
252 V4L2_IDENT_MSP3400C = 34003,
253 V4L2_IDENT_MSP3400D = 34004,
254 V4L2_IDENT_MSP3400G = 34007,
255 V4L2_IDENT_MSP3401G = 34017,
256 V4L2_IDENT_MSP3402G = 34027,
257 V4L2_IDENT_MSP3405D = 34054,
258 V4L2_IDENT_MSP3405G = 34057,
259 V4L2_IDENT_MSP3407D = 34074,
260 V4L2_IDENT_MSP3407G = 34077,
261
262 V4L2_IDENT_MSP3410B = 34102,
263 V4L2_IDENT_MSP3410C = 34103,
264 V4L2_IDENT_MSP3410D = 34104,
265 V4L2_IDENT_MSP3410G = 34107,
266 V4L2_IDENT_MSP3411G = 34117,
267 V4L2_IDENT_MSP3412G = 34127,
268 V4L2_IDENT_MSP3415D = 34154,
269 V4L2_IDENT_MSP3415G = 34157,
270 V4L2_IDENT_MSP3417D = 34174,
271 V4L2_IDENT_MSP3417G = 34177,
272
273 V4L2_IDENT_MSP3420G = 34207,
274 V4L2_IDENT_MSP3421G = 34217,
275 V4L2_IDENT_MSP3422G = 34227,
276 V4L2_IDENT_MSP3425G = 34257,
277 V4L2_IDENT_MSP3427G = 34277,
278
279 V4L2_IDENT_MSP3430G = 34307,
280 V4L2_IDENT_MSP3431G = 34317,
281 V4L2_IDENT_MSP3435G = 34357,
282 V4L2_IDENT_MSP3437G = 34377,
283
284 V4L2_IDENT_MSP3440G = 34407,
285 V4L2_IDENT_MSP3441G = 34417,
286 V4L2_IDENT_MSP3442G = 34427,
287 V4L2_IDENT_MSP3445G = 34457,
288 V4L2_IDENT_MSP3447G = 34477,
289
290 V4L2_IDENT_MSP3450G = 34507,
291 V4L2_IDENT_MSP3451G = 34517,
292 V4L2_IDENT_MSP3452G = 34527,
293 V4L2_IDENT_MSP3455G = 34557,
294 V4L2_IDENT_MSP3457G = 34577,
295
296 V4L2_IDENT_MSP3460G = 34607,
297 V4L2_IDENT_MSP3461G = 34617,
298 V4L2_IDENT_MSP3465G = 34657,
299 V4L2_IDENT_MSP3467G = 34677,
300
301 /* module msp3400: reserved range 44000-44999 for msp44xx */
302 V4L2_IDENT_MSP4400G = 44007,
303 V4L2_IDENT_MSP4408G = 44087,
304 V4L2_IDENT_MSP4410G = 44107,
305 V4L2_IDENT_MSP4418G = 44187,
306 V4L2_IDENT_MSP4420G = 44207,
307 V4L2_IDENT_MSP4428G = 44287,
308 V4L2_IDENT_MSP4440G = 44407,
309 V4L2_IDENT_MSP4448G = 44487,
310 V4L2_IDENT_MSP4450G = 44507,
311 V4L2_IDENT_MSP4458G = 44587,
312
313 /* Micron CMOS sensor chips: 45000-45099 */
314 V4L2_IDENT_MT9M001C12ST = 45000,
315 V4L2_IDENT_MT9M001C12STM = 45005,
316 V4L2_IDENT_MT9M111 = 45007,
317 V4L2_IDENT_MT9M112 = 45008,
318 V4L2_IDENT_MT9V022IX7ATC = 45010, /* No way to detect "normal" I77ATx */
319 V4L2_IDENT_MT9V022IX7ATM = 45015, /* and "lead free" IA7ATx chips */
320 V4L2_IDENT_MT9T031 = 45020,
321 V4L2_IDENT_MT9T111 = 45021,
322 V4L2_IDENT_MT9T112 = 45022,
323 V4L2_IDENT_MT9V111 = 45031,
324 V4L2_IDENT_MT9V112 = 45032,
325
326 /* HV7131R CMOS sensor: just ident 46000 */
327 V4L2_IDENT_HV7131R = 46000,
328
329 /* Sharp RJ54N1CB0C, 0xCB0C = 51980 */
330 V4L2_IDENT_RJ54N1CB0C = 51980,
331
332 /* module m52790: just ident 52790 */
333 V4L2_IDENT_M52790 = 52790,
334
335 /* module cs53132a: just ident 53132 */
336 V4L2_IDENT_CS53l32A = 53132,
337
338 /* modules upd61151 MPEG2 encoder: just ident 54000 */
339 V4L2_IDENT_UPD61161 = 54000,
340 /* modules upd61152 MPEG2 encoder with AC3: just ident 54001 */
341 V4L2_IDENT_UPD61162 = 54001,
342
343 /* module upd64031a: just ident 64031 */
344 V4L2_IDENT_UPD64031A = 64031,
345
346 /* module upd64083: just ident 64083 */
347 V4L2_IDENT_UPD64083 = 64083,
348
349 /* Don't just add new IDs at the end: KEEP THIS LIST ORDERED BY ID! */
350};
351
352#endif
diff --git a/include/media/v4l2-clk.h b/include/media/v4l2-clk.h
new file mode 100644
index 000000000000..0503a90b48bb
--- /dev/null
+++ b/include/media/v4l2-clk.h
@@ -0,0 +1,54 @@
1/*
2 * V4L2 clock service
3 *
4 * Copyright (C) 2012-2013, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ATTENTION: This is a temporary API and it shall be replaced by the generic
11 * clock API, when the latter becomes widely available.
12 */
13
14#ifndef MEDIA_V4L2_CLK_H
15#define MEDIA_V4L2_CLK_H
16
17#include <linux/atomic.h>
18#include <linux/list.h>
19#include <linux/mutex.h>
20
21struct module;
22struct device;
23
24struct v4l2_clk {
25 struct list_head list;
26 const struct v4l2_clk_ops *ops;
27 const char *dev_id;
28 const char *id;
29 int enable;
30 struct mutex lock; /* Protect the enable count */
31 atomic_t use_count;
32 void *priv;
33};
34
35struct v4l2_clk_ops {
36 struct module *owner;
37 int (*enable)(struct v4l2_clk *clk);
38 void (*disable)(struct v4l2_clk *clk);
39 unsigned long (*get_rate)(struct v4l2_clk *clk);
40 int (*set_rate)(struct v4l2_clk *clk, unsigned long);
41};
42
43struct v4l2_clk *v4l2_clk_register(const struct v4l2_clk_ops *ops,
44 const char *dev_name,
45 const char *name, void *priv);
46void v4l2_clk_unregister(struct v4l2_clk *clk);
47struct v4l2_clk *v4l2_clk_get(struct device *dev, const char *id);
48void v4l2_clk_put(struct v4l2_clk *clk);
49int v4l2_clk_enable(struct v4l2_clk *clk);
50void v4l2_clk_disable(struct v4l2_clk *clk);
51unsigned long v4l2_clk_get_rate(struct v4l2_clk *clk);
52int v4l2_clk_set_rate(struct v4l2_clk *clk, unsigned long rate);
53
54#endif
diff --git a/include/media/v4l2-common.h b/include/media/v4l2-common.h
index 1d93c48cb371..015ff82da73c 100644
--- a/include/media/v4l2-common.h
+++ b/include/media/v4l2-common.h
@@ -100,16 +100,6 @@ u32 v4l2_ctrl_next(const u32 * const *ctrl_classes, u32 id);
100 100
101/* ------------------------------------------------------------------------- */ 101/* ------------------------------------------------------------------------- */
102 102
103/* Register/chip ident helper function */
104
105struct i2c_client; /* forward reference */
106int v4l2_chip_match_i2c_client(struct i2c_client *c, const struct v4l2_dbg_match *match);
107int v4l2_chip_ident_i2c_client(struct i2c_client *c, struct v4l2_dbg_chip_ident *chip,
108 u32 ident, u32 revision);
109int v4l2_chip_match_host(const struct v4l2_dbg_match *match);
110
111/* ------------------------------------------------------------------------- */
112
113/* I2C Helper functions */ 103/* I2C Helper functions */
114 104
115struct i2c_driver; 105struct i2c_driver;
diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
index 95d1c91770f4..c768c9f8abc2 100644
--- a/include/media/v4l2-dev.h
+++ b/include/media/v4l2-dev.h
@@ -96,9 +96,9 @@ struct video_device
96 struct device dev; /* v4l device */ 96 struct device dev; /* v4l device */
97 struct cdev *cdev; /* character device */ 97 struct cdev *cdev; /* character device */
98 98
99 /* Set either parent or v4l2_dev if your driver uses v4l2_device */
100 struct device *parent; /* device parent */
101 struct v4l2_device *v4l2_dev; /* v4l2_device parent */ 99 struct v4l2_device *v4l2_dev; /* v4l2_device parent */
100 /* Only set parent if that can't be deduced from v4l2_dev */
101 struct device *dev_parent; /* device parent */
102 102
103 /* Control handler associated with this device node. May be NULL. */ 103 /* Control handler associated with this device node. May be NULL. */
104 struct v4l2_ctrl_handler *ctrl_handler; 104 struct v4l2_ctrl_handler *ctrl_handler;
@@ -129,7 +129,6 @@ struct video_device
129 129
130 /* Video standard vars */ 130 /* Video standard vars */
131 v4l2_std_id tvnorms; /* Supported tv norms */ 131 v4l2_std_id tvnorms; /* Supported tv norms */
132 v4l2_std_id current_norm; /* Current tvnorm */
133 132
134 /* callbacks */ 133 /* callbacks */
135 void (*release)(struct video_device *vdev); 134 void (*release)(struct video_device *vdev);
diff --git a/include/media/v4l2-int-device.h b/include/media/v4l2-int-device.h
index e6aa2318367b..0286c95814ff 100644
--- a/include/media/v4l2-int-device.h
+++ b/include/media/v4l2-int-device.h
@@ -220,8 +220,6 @@ enum v4l2_int_ioctl_num {
220 vidioc_int_reset_num, 220 vidioc_int_reset_num,
221 /* VIDIOC_INT_INIT */ 221 /* VIDIOC_INT_INIT */
222 vidioc_int_init_num, 222 vidioc_int_init_num,
223 /* VIDIOC_DBG_G_CHIP_IDENT */
224 vidioc_int_g_chip_ident_num,
225 223
226 /* 224 /*
227 * 225 *
@@ -303,6 +301,5 @@ V4L2_INT_WRAPPER_1(enum_frameintervals, struct v4l2_frmivalenum, *);
303 301
304V4L2_INT_WRAPPER_0(reset); 302V4L2_INT_WRAPPER_0(reset);
305V4L2_INT_WRAPPER_0(init); 303V4L2_INT_WRAPPER_0(init);
306V4L2_INT_WRAPPER_1(g_chip_ident, int, *);
307 304
308#endif 305#endif
diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
index 931652f0e2af..e0b74a430b3a 100644
--- a/include/media/v4l2-ioctl.h
+++ b/include/media/v4l2-ioctl.h
@@ -247,8 +247,6 @@ struct v4l2_ioctl_ops {
247 int (*vidioc_g_chip_info) (struct file *file, void *fh, 247 int (*vidioc_g_chip_info) (struct file *file, void *fh,
248 struct v4l2_dbg_chip_info *chip); 248 struct v4l2_dbg_chip_info *chip);
249#endif 249#endif
250 int (*vidioc_g_chip_ident) (struct file *file, void *fh,
251 struct v4l2_dbg_chip_ident *chip);
252 250
253 int (*vidioc_enum_framesizes) (struct file *file, void *fh, 251 int (*vidioc_enum_framesizes) (struct file *file, void *fh,
254 struct v4l2_frmsizeenum *fsize); 252 struct v4l2_frmsizeenum *fsize);
diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
index 5298d678d0f3..3250cc5e7925 100644
--- a/include/media/v4l2-subdev.h
+++ b/include/media/v4l2-subdev.h
@@ -24,6 +24,7 @@
24#include <linux/types.h> 24#include <linux/types.h>
25#include <linux/v4l2-subdev.h> 25#include <linux/v4l2-subdev.h>
26#include <media/media-entity.h> 26#include <media/media-entity.h>
27#include <media/v4l2-async.h>
27#include <media/v4l2-common.h> 28#include <media/v4l2-common.h>
28#include <media/v4l2-dev.h> 29#include <media/v4l2-dev.h>
29#include <media/v4l2-fh.h> 30#include <media/v4l2-fh.h>
@@ -88,7 +89,6 @@ struct v4l2_decode_vbi_line {
88 89
89/* Core ops: it is highly recommended to implement at least these ops: 90/* Core ops: it is highly recommended to implement at least these ops:
90 91
91 g_chip_ident
92 log_status 92 log_status
93 g_register 93 g_register
94 s_register 94 s_register
@@ -145,7 +145,6 @@ struct v4l2_subdev_io_pin_config {
145 performed later. It must not sleep. *Called from an IRQ context*. 145 performed later. It must not sleep. *Called from an IRQ context*.
146 */ 146 */
147struct v4l2_subdev_core_ops { 147struct v4l2_subdev_core_ops {
148 int (*g_chip_ident)(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip);
149 int (*log_status)(struct v4l2_subdev *sd); 148 int (*log_status)(struct v4l2_subdev *sd);
150 int (*s_io_pin_config)(struct v4l2_subdev *sd, size_t n, 149 int (*s_io_pin_config)(struct v4l2_subdev *sd, size_t n,
151 struct v4l2_subdev_io_pin_config *pincfg); 150 struct v4l2_subdev_io_pin_config *pincfg);
@@ -585,8 +584,17 @@ struct v4l2_subdev {
585 void *host_priv; 584 void *host_priv;
586 /* subdev device node */ 585 /* subdev device node */
587 struct video_device *devnode; 586 struct video_device *devnode;
587 /* pointer to the physical device, if any */
588 struct device *dev;
589 struct v4l2_async_subdev_list asdl;
588}; 590};
589 591
592static inline struct v4l2_subdev *v4l2_async_to_subdev(
593 struct v4l2_async_subdev_list *asdl)
594{
595 return container_of(asdl, struct v4l2_subdev, asdl);
596}
597
590#define media_entity_to_v4l2_subdev(ent) \ 598#define media_entity_to_v4l2_subdev(ent) \
591 container_of(ent, struct v4l2_subdev, entity) 599 container_of(ent, struct v4l2_subdev, entity)
592#define vdev_to_v4l2_subdev(vdev) \ 600#define vdev_to_v4l2_subdev(vdev) \
@@ -660,7 +668,7 @@ void v4l2_subdev_init(struct v4l2_subdev *sd,
660/* Call an ops of a v4l2_subdev, doing the right checks against 668/* Call an ops of a v4l2_subdev, doing the right checks against
661 NULL pointers. 669 NULL pointers.
662 670
663 Example: err = v4l2_subdev_call(sd, core, g_chip_ident, &chip); 671 Example: err = v4l2_subdev_call(sd, core, s_std, norm);
664 */ 672 */
665#define v4l2_subdev_call(sd, o, f, args...) \ 673#define v4l2_subdev_call(sd, o, f, args...) \
666 (!(sd) ? -ENODEV : (((sd)->ops->o && (sd)->ops->o->f) ? \ 674 (!(sd) ? -ENODEV : (((sd)->ops->o && (sd)->ops->o->f) ? \
diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h
index 69bd5bb0d5af..e90a88a8708f 100644
--- a/include/uapi/linux/v4l2-controls.h
+++ b/include/uapi/linux/v4l2-controls.h
@@ -53,13 +53,13 @@
53#define V4L2_CTRL_CLASS_USER 0x00980000 /* Old-style 'user' controls */ 53#define V4L2_CTRL_CLASS_USER 0x00980000 /* Old-style 'user' controls */
54#define V4L2_CTRL_CLASS_MPEG 0x00990000 /* MPEG-compression controls */ 54#define V4L2_CTRL_CLASS_MPEG 0x00990000 /* MPEG-compression controls */
55#define V4L2_CTRL_CLASS_CAMERA 0x009a0000 /* Camera class controls */ 55#define V4L2_CTRL_CLASS_CAMERA 0x009a0000 /* Camera class controls */
56#define V4L2_CTRL_CLASS_FM_TX 0x009b0000 /* FM Modulator control class */ 56#define V4L2_CTRL_CLASS_FM_TX 0x009b0000 /* FM Modulator controls */
57#define V4L2_CTRL_CLASS_FLASH 0x009c0000 /* Camera flash controls */ 57#define V4L2_CTRL_CLASS_FLASH 0x009c0000 /* Camera flash controls */
58#define V4L2_CTRL_CLASS_JPEG 0x009d0000 /* JPEG-compression controls */ 58#define V4L2_CTRL_CLASS_JPEG 0x009d0000 /* JPEG-compression controls */
59#define V4L2_CTRL_CLASS_IMAGE_SOURCE 0x009e0000 /* Image source controls */ 59#define V4L2_CTRL_CLASS_IMAGE_SOURCE 0x009e0000 /* Image source controls */
60#define V4L2_CTRL_CLASS_IMAGE_PROC 0x009f0000 /* Image processing controls */ 60#define V4L2_CTRL_CLASS_IMAGE_PROC 0x009f0000 /* Image processing controls */
61#define V4L2_CTRL_CLASS_DV 0x00a00000 /* Digital Video controls */ 61#define V4L2_CTRL_CLASS_DV 0x00a00000 /* Digital Video controls */
62#define V4L2_CTRL_CLASS_FM_RX 0x00a10000 /* Digital Video controls */ 62#define V4L2_CTRL_CLASS_FM_RX 0x00a10000 /* FM Receiver controls */
63 63
64/* User-class control IDs */ 64/* User-class control IDs */
65 65
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index f40b41c7e108..95ef4551edc1 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -395,7 +395,7 @@ struct v4l2_pix_format {
395#define V4L2_PIX_FMT_H263 v4l2_fourcc('H', '2', '6', '3') /* H263 */ 395#define V4L2_PIX_FMT_H263 v4l2_fourcc('H', '2', '6', '3') /* H263 */
396#define V4L2_PIX_FMT_MPEG1 v4l2_fourcc('M', 'P', 'G', '1') /* MPEG-1 ES */ 396#define V4L2_PIX_FMT_MPEG1 v4l2_fourcc('M', 'P', 'G', '1') /* MPEG-1 ES */
397#define V4L2_PIX_FMT_MPEG2 v4l2_fourcc('M', 'P', 'G', '2') /* MPEG-2 ES */ 397#define V4L2_PIX_FMT_MPEG2 v4l2_fourcc('M', 'P', 'G', '2') /* MPEG-2 ES */
398#define V4L2_PIX_FMT_MPEG4 v4l2_fourcc('M', 'P', 'G', '4') /* MPEG-4 ES */ 398#define V4L2_PIX_FMT_MPEG4 v4l2_fourcc('M', 'P', 'G', '4') /* MPEG-4 part 2 ES */
399#define V4L2_PIX_FMT_XVID v4l2_fourcc('X', 'V', 'I', 'D') /* Xvid */ 399#define V4L2_PIX_FMT_XVID v4l2_fourcc('X', 'V', 'I', 'D') /* Xvid */
400#define V4L2_PIX_FMT_VC1_ANNEX_G v4l2_fourcc('V', 'C', '1', 'G') /* SMPTE 421M Annex G compliant stream */ 400#define V4L2_PIX_FMT_VC1_ANNEX_G v4l2_fourcc('V', 'C', '1', 'G') /* SMPTE 421M Annex G compliant stream */
401#define V4L2_PIX_FMT_VC1_ANNEX_L v4l2_fourcc('V', 'C', '1', 'L') /* SMPTE 421M Annex L compliant stream */ 401#define V4L2_PIX_FMT_VC1_ANNEX_L v4l2_fourcc('V', 'C', '1', 'L') /* SMPTE 421M Annex L compliant stream */
@@ -555,7 +555,7 @@ struct v4l2_jpegcompression {
555 __u32 jpeg_markers; /* Which markers should go into the JPEG 555 __u32 jpeg_markers; /* Which markers should go into the JPEG
556 * output. Unless you exactly know what 556 * output. Unless you exactly know what
557 * you do, leave them untouched. 557 * you do, leave them untouched.
558 * Inluding less markers will make the 558 * Including less markers will make the
559 * resulting code smaller, but there will 559 * resulting code smaller, but there will
560 * be fewer applications which can read it. 560 * be fewer applications which can read it.
561 * The presence of the APP and COM marker 561 * The presence of the APP and COM marker
@@ -567,7 +567,7 @@ struct v4l2_jpegcompression {
567#define V4L2_JPEG_MARKER_DRI (1<<5) /* Define Restart Interval */ 567#define V4L2_JPEG_MARKER_DRI (1<<5) /* Define Restart Interval */
568#define V4L2_JPEG_MARKER_COM (1<<6) /* Comment segment */ 568#define V4L2_JPEG_MARKER_COM (1<<6) /* Comment segment */
569#define V4L2_JPEG_MARKER_APP (1<<7) /* App segment, driver will 569#define V4L2_JPEG_MARKER_APP (1<<7) /* App segment, driver will
570 * allways use APP0 */ 570 * always use APP0 */
571}; 571};
572 572
573/* 573/*
@@ -900,7 +900,7 @@ typedef __u64 v4l2_std_id;
900/* 900/*
901 * "Common" PAL - This macro is there to be compatible with the old 901 * "Common" PAL - This macro is there to be compatible with the old
902 * V4L1 concept of "PAL": /BGDKHI. 902 * V4L1 concept of "PAL": /BGDKHI.
903 * Several PAL standards are mising here: /M, /N and /Nc 903 * Several PAL standards are missing here: /M, /N and /Nc
904 */ 904 */
905#define V4L2_STD_PAL (V4L2_STD_PAL_BG |\ 905#define V4L2_STD_PAL (V4L2_STD_PAL_BG |\
906 V4L2_STD_PAL_DK |\ 906 V4L2_STD_PAL_DK |\
@@ -1787,11 +1787,13 @@ struct v4l2_event_subscription {
1787/* VIDIOC_DBG_G_REGISTER and VIDIOC_DBG_S_REGISTER */ 1787/* VIDIOC_DBG_G_REGISTER and VIDIOC_DBG_S_REGISTER */
1788 1788
1789#define V4L2_CHIP_MATCH_BRIDGE 0 /* Match against chip ID on the bridge (0 for the bridge) */ 1789#define V4L2_CHIP_MATCH_BRIDGE 0 /* Match against chip ID on the bridge (0 for the bridge) */
1790#define V4L2_CHIP_MATCH_SUBDEV 4 /* Match against subdev index */
1791
1792/* The following four defines are no longer in use */
1790#define V4L2_CHIP_MATCH_HOST V4L2_CHIP_MATCH_BRIDGE 1793#define V4L2_CHIP_MATCH_HOST V4L2_CHIP_MATCH_BRIDGE
1791#define V4L2_CHIP_MATCH_I2C_DRIVER 1 /* Match against I2C driver name */ 1794#define V4L2_CHIP_MATCH_I2C_DRIVER 1 /* Match against I2C driver name */
1792#define V4L2_CHIP_MATCH_I2C_ADDR 2 /* Match against I2C 7-bit address */ 1795#define V4L2_CHIP_MATCH_I2C_ADDR 2 /* Match against I2C 7-bit address */
1793#define V4L2_CHIP_MATCH_AC97 3 /* Match against anciliary AC97 chip */ 1796#define V4L2_CHIP_MATCH_AC97 3 /* Match against ancillary AC97 chip */
1794#define V4L2_CHIP_MATCH_SUBDEV 4 /* Match against subdev index */
1795 1797
1796struct v4l2_dbg_match { 1798struct v4l2_dbg_match {
1797 __u32 type; /* Match type */ 1799 __u32 type; /* Match type */
@@ -1808,13 +1810,6 @@ struct v4l2_dbg_register {
1808 __u64 val; 1810 __u64 val;
1809} __attribute__ ((packed)); 1811} __attribute__ ((packed));
1810 1812
1811/* VIDIOC_DBG_G_CHIP_IDENT */
1812struct v4l2_dbg_chip_ident {
1813 struct v4l2_dbg_match match;
1814 __u32 ident; /* chip identifier as specified in <media/v4l2-chip-ident.h> */
1815 __u32 revision; /* chip revision, chip specific */
1816} __attribute__ ((packed));
1817
1818#define V4L2_CHIP_FL_READABLE (1 << 0) 1813#define V4L2_CHIP_FL_READABLE (1 << 0)
1819#define V4L2_CHIP_FL_WRITABLE (1 << 1) 1814#define V4L2_CHIP_FL_WRITABLE (1 << 1)
1820 1815
@@ -1915,12 +1910,6 @@ struct v4l2_create_buffers {
1915#define VIDIOC_DBG_S_REGISTER _IOW('V', 79, struct v4l2_dbg_register) 1910#define VIDIOC_DBG_S_REGISTER _IOW('V', 79, struct v4l2_dbg_register)
1916#define VIDIOC_DBG_G_REGISTER _IOWR('V', 80, struct v4l2_dbg_register) 1911#define VIDIOC_DBG_G_REGISTER _IOWR('V', 80, struct v4l2_dbg_register)
1917 1912
1918/* Experimental, meant for debugging, testing and internal use.
1919 Never use this ioctl in applications!
1920 Note: this ioctl is deprecated in favor of VIDIOC_DBG_G_CHIP_INFO and
1921 will go away in the future. */
1922#define VIDIOC_DBG_G_CHIP_IDENT _IOWR('V', 81, struct v4l2_dbg_chip_ident)
1923
1924#define VIDIOC_S_HW_FREQ_SEEK _IOW('V', 82, struct v4l2_hw_freq_seek) 1913#define VIDIOC_S_HW_FREQ_SEEK _IOW('V', 82, struct v4l2_hw_freq_seek)
1925 1914
1926#define VIDIOC_S_DV_TIMINGS _IOWR('V', 87, struct v4l2_dv_timings) 1915#define VIDIOC_S_DV_TIMINGS _IOWR('V', 87, struct v4l2_dv_timings)