aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-02-24 20:35:10 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-02-24 20:35:10 -0500
commit21fbd5809ad126b949206d78e0a0e07ec872ea11 (patch)
treea824045df99fc1f0690095a925cceb50207e332b
parentd9978ec5680059d727b39d6c706777c6973587f2 (diff)
parented72d37a33fdf43dc47787fe220532cdec9da528 (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: - Some cleanups at V4L2 documentation - new drivers: ts2020 frontend, ov9650 sensor, s5c73m3 sensor, sh-mobile veu mem2mem driver, radio-ma901, davinci_vpfe staging driver - Lots of missing MAINTAINERS entries added - several em28xx driver improvements, including its conversion to videobuf2 - several fixups on drivers to make them to better comply with the API - DVB core: add support for DVBv5 stats, allowing the implementation of statistics for new standards like ISDB - mb86a20s: add statistics to the driver - lots of new board additions, cleanups, and driver improvements. * 'v4l_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-media: (596 commits) [media] media: Add 0x3009 USB PID to ttusb2 driver (fixed diff) [media] rtl28xxu: Add USB IDs for Compro VideoMate U620F [media] em28xx: add usb id for terratec h5 rev. 3 [media] media: rc: gpio-ir-recv: add support for device tree parsing [media] mceusb: move check earlier to make smatch happy [media] radio-si470x doc: add info about v4l2-ctl and sox+alsa [media] staging: media: Remove unnecessary OOM messages [media] sh_vou: Use vou_dev instead of vou_file wherever possible [media] sh_vou: Use video_drvdata() [media] drivers/media/platform/soc_camera/pxa_camera.c: use devm_ functions [media] mt9t112: mt9t111 format set up differs from mt9t112 [media] sh-mobile-ceu-camera: fix SHARPNESS control default Revert "[media] fc0011: Return early, if the frequency is already tuned" [media] cx18/ivtv: fix regression: remove __init from a non-init function [media] em28xx: fix analog streaming with USB bulk transfers [media] stv0900: remove unnecessary null pointer check [media] fc0011: Return early, if the frequency is already tuned [media] fc0011: Add some sanity checks and cleanups [media] fc0011: Fix xin value clamping Revert "[media] [PATH,1/2] mxl5007 move reset to attach" ...
-rw-r--r--Documentation/DocBook/media/dvb/dvbapi.xml2
-rw-r--r--Documentation/DocBook/media/dvb/dvbproperty.xml180
-rw-r--r--Documentation/DocBook/media/dvb/frontend.xml2
-rw-r--r--Documentation/DocBook/media/v4l/common.xml2
-rw-r--r--Documentation/DocBook/media/v4l/compat.xml16
-rw-r--r--Documentation/DocBook/media/v4l/controls.xml23
-rw-r--r--Documentation/DocBook/media/v4l/io.xml59
-rw-r--r--Documentation/DocBook/media/v4l/pixfmt-nv12m.xml2
-rw-r--r--Documentation/DocBook/media/v4l/pixfmt-srggb10alaw8.xml34
-rw-r--r--Documentation/DocBook/media/v4l/pixfmt-uv8.xml62
-rw-r--r--Documentation/DocBook/media/v4l/pixfmt.xml2
-rw-r--r--Documentation/DocBook/media/v4l/subdev-formats.xml926
-rw-r--r--Documentation/DocBook/media/v4l/v4l2.xml12
-rw-r--r--Documentation/DocBook/media/v4l/vidioc-dqevent.xml6
-rw-r--r--Documentation/DocBook/media/v4l/vidioc-expbuf.xml28
-rw-r--r--Documentation/DocBook/media/v4l/vidioc-g-ctrl.xml8
-rw-r--r--Documentation/DocBook/media/v4l/vidioc-g-ext-ctrls.xml57
-rw-r--r--Documentation/DocBook/media/v4l/vidioc-querycap.xml2
-rw-r--r--Documentation/DocBook/media_api.tmpl1
-rw-r--r--Documentation/devicetree/bindings/media/gpio-ir-receiver.txt16
-rwxr-xr-xDocumentation/dvb/get_dvb_firmware17
-rw-r--r--Documentation/media-framework.txt2
-rw-r--r--Documentation/video4linux/CARDLIST.au08282
-rw-r--r--Documentation/video4linux/CARDLIST.cx238852
-rw-r--r--Documentation/video4linux/CARDLIST.em28xx3
-rw-r--r--Documentation/video4linux/CARDLIST.saa71341
-rw-r--r--Documentation/video4linux/et61x251.txt315
-rwxr-xr-x[-rw-r--r--]Documentation/video4linux/extract_xc3028.pl0
-rw-r--r--Documentation/video4linux/fimc.txt2
-rw-r--r--Documentation/video4linux/ibmcam.txt323
-rw-r--r--Documentation/video4linux/m5602.txt12
-rw-r--r--Documentation/video4linux/ov511.txt288
-rw-r--r--Documentation/video4linux/se401.txt54
-rw-r--r--Documentation/video4linux/si470x.txt7
-rw-r--r--Documentation/video4linux/soc-camera.txt146
-rw-r--r--Documentation/video4linux/stv680.txt53
-rw-r--r--Documentation/video4linux/v4l2-controls.txt22
-rw-r--r--Documentation/video4linux/v4l2-framework.txt3
-rw-r--r--Documentation/video4linux/w9968cf.txt458
-rw-r--r--Documentation/video4linux/zc0301.txt270
-rw-r--r--MAINTAINERS262
-rw-r--r--arch/arm/mach-davinci/board-da850-evm.c13
-rw-r--r--arch/arm/mach-davinci/board-dm644x-evm.c8
-rw-r--r--arch/arm/mach-davinci/dm644x.c10
-rw-r--r--arch/arm/mach-exynos/mach-nuri.c8
-rw-r--r--arch/arm/mach-exynos/mach-universal_c210.c8
-rw-r--r--arch/arm/mach-s5pv210/mach-goni.c6
-rw-r--r--drivers/hid/hid-core.c1
-rw-r--r--drivers/hid/hid-ids.h3
-rw-r--r--drivers/media/Kconfig19
-rw-r--r--drivers/media/common/Kconfig11
-rw-r--r--drivers/media/common/Makefile3
-rw-r--r--drivers/media/common/btcx-risc.c (renamed from drivers/media/i2c/btcx-risc.c)0
-rw-r--r--drivers/media/common/btcx-risc.h (renamed from drivers/media/i2c/btcx-risc.h)0
-rw-r--r--drivers/media/common/cx2341x.c (renamed from drivers/media/i2c/cx2341x.c)0
-rw-r--r--drivers/media/common/saa7146/saa7146_fops.c5
-rw-r--r--drivers/media/common/tveeprom.c (renamed from drivers/media/i2c/tveeprom.c)290
-rw-r--r--drivers/media/dvb-core/dvb-usb-ids.h6
-rw-r--r--drivers/media/dvb-core/dvb_ca_en50221.c16
-rw-r--r--drivers/media/dvb-core/dvb_frontend.c59
-rw-r--r--drivers/media/dvb-core/dvb_frontend.h10
-rw-r--r--drivers/media/dvb-core/dvb_net.c71
-rw-r--r--drivers/media/dvb-core/dvb_net.h1
-rw-r--r--drivers/media/dvb-core/dvbdev.c2
-rw-r--r--drivers/media/dvb-frontends/Kconfig7
-rw-r--r--drivers/media/dvb-frontends/Makefile1
-rw-r--r--drivers/media/dvb-frontends/af9033.c18
-rw-r--r--drivers/media/dvb-frontends/af9033.h1
-rw-r--r--drivers/media/dvb-frontends/af9033_priv.h132
-rw-r--r--drivers/media/dvb-frontends/bcm3510.h2
-rw-r--r--drivers/media/dvb-frontends/cx22700.h2
-rw-r--r--drivers/media/dvb-frontends/cx24110.h2
-rw-r--r--drivers/media/dvb-frontends/cx24116.c2
-rw-r--r--drivers/media/dvb-frontends/dib0070.h2
-rw-r--r--drivers/media/dvb-frontends/dib0090.h2
-rw-r--r--drivers/media/dvb-frontends/dib3000.h2
-rw-r--r--drivers/media/dvb-frontends/dib8000.h2
-rw-r--r--drivers/media/dvb-frontends/dib9000.h2
-rw-r--r--drivers/media/dvb-frontends/drxd_hard.c9
-rw-r--r--drivers/media/dvb-frontends/ds3000.c261
-rw-r--r--drivers/media/dvb-frontends/ds3000.h10
-rw-r--r--drivers/media/dvb-frontends/dvb-pll.h2
-rw-r--r--drivers/media/dvb-frontends/isl6405.h2
-rw-r--r--drivers/media/dvb-frontends/isl6421.h2
-rw-r--r--drivers/media/dvb-frontends/isl6423.h2
-rw-r--r--drivers/media/dvb-frontends/itd1000.h2
-rw-r--r--drivers/media/dvb-frontends/ix2505v.c2
-rw-r--r--drivers/media/dvb-frontends/l64781.h2
-rw-r--r--drivers/media/dvb-frontends/lgdt330x.h2
-rw-r--r--drivers/media/dvb-frontends/m88rs2000.c422
-rw-r--r--drivers/media/dvb-frontends/m88rs2000.h6
-rw-r--r--drivers/media/dvb-frontends/mb86a16.h2
-rw-r--r--drivers/media/dvb-frontends/mb86a20s.c1790
-rw-r--r--drivers/media/dvb-frontends/mt312.h2
-rw-r--r--drivers/media/dvb-frontends/mt352.h2
-rw-r--r--drivers/media/dvb-frontends/nxt200x.h2
-rw-r--r--drivers/media/dvb-frontends/nxt6000.h2
-rw-r--r--drivers/media/dvb-frontends/or51132.h2
-rw-r--r--drivers/media/dvb-frontends/or51211.c99
-rw-r--r--drivers/media/dvb-frontends/or51211.h2
-rw-r--r--drivers/media/dvb-frontends/s5h1420.h2
-rw-r--r--drivers/media/dvb-frontends/sp8870.h2
-rw-r--r--drivers/media/dvb-frontends/sp887x.h2
-rw-r--r--drivers/media/dvb-frontends/stb0899_drv.h2
-rw-r--r--drivers/media/dvb-frontends/stb6100.h2
-rw-r--r--drivers/media/dvb-frontends/stv0297.h2
-rw-r--r--drivers/media/dvb-frontends/stv0299.c2
-rw-r--r--drivers/media/dvb-frontends/stv0299.h2
-rw-r--r--drivers/media/dvb-frontends/stv0900_core.c40
-rw-r--r--drivers/media/dvb-frontends/stv0900_reg.h3
-rw-r--r--drivers/media/dvb-frontends/stv0900_sw.c7
-rw-r--r--drivers/media/dvb-frontends/stv090x.c141
-rw-r--r--drivers/media/dvb-frontends/stv090x.h2
-rw-r--r--drivers/media/dvb-frontends/stv6110x.h2
-rw-r--r--drivers/media/dvb-frontends/tda1002x.h5
-rw-r--r--drivers/media/dvb-frontends/tda1004x.h2
-rw-r--r--drivers/media/dvb-frontends/tda10071.c22
-rw-r--r--drivers/media/dvb-frontends/tda10071.h8
-rw-r--r--drivers/media/dvb-frontends/tda10086.h2
-rw-r--r--drivers/media/dvb-frontends/tda665x.h2
-rw-r--r--drivers/media/dvb-frontends/tda8083.h2
-rw-r--r--drivers/media/dvb-frontends/tda8261.h2
-rw-r--r--drivers/media/dvb-frontends/tda8261_cfg.h2
-rw-r--r--drivers/media/dvb-frontends/tda826x.h2
-rw-r--r--drivers/media/dvb-frontends/ts2020.c373
-rw-r--r--drivers/media/dvb-frontends/ts2020.h50
-rw-r--r--drivers/media/dvb-frontends/tua6100.h2
-rw-r--r--drivers/media/dvb-frontends/ves1820.h2
-rw-r--r--drivers/media/dvb-frontends/ves1x93.h2
-rw-r--r--drivers/media/dvb-frontends/zl10353.h2
-rw-r--r--drivers/media/i2c/Kconfig42
-rw-r--r--drivers/media/i2c/Makefile5
-rw-r--r--drivers/media/i2c/adv7180.c3
-rw-r--r--drivers/media/i2c/adv7343.c45
-rw-r--r--drivers/media/i2c/cx25840/cx25840-ir.c6
-rw-r--r--drivers/media/i2c/mt9v011.c223
-rw-r--r--drivers/media/i2c/noon010pc30.c7
-rw-r--r--drivers/media/i2c/ov7670.c589
-rw-r--r--drivers/media/i2c/ov9650.c1562
-rw-r--r--drivers/media/i2c/s5c73m3/Makefile2
-rw-r--r--drivers/media/i2c/s5c73m3/s5c73m3-core.c1704
-rw-r--r--drivers/media/i2c/s5c73m3/s5c73m3-ctrls.c563
-rw-r--r--drivers/media/i2c/s5c73m3/s5c73m3-spi.c156
-rw-r--r--drivers/media/i2c/s5c73m3/s5c73m3.h459
-rw-r--r--drivers/media/i2c/s5k6aa.c7
-rw-r--r--drivers/media/i2c/soc_camera/imx074.c27
-rw-r--r--drivers/media/i2c/soc_camera/mt9m001.c52
-rw-r--r--drivers/media/i2c/soc_camera/mt9m111.c36
-rw-r--r--drivers/media/i2c/soc_camera/mt9t031.c36
-rw-r--r--drivers/media/i2c/soc_camera/mt9t112.c45
-rw-r--r--drivers/media/i2c/soc_camera/mt9v022.c45
-rw-r--r--drivers/media/i2c/soc_camera/ov2640.c29
-rw-r--r--drivers/media/i2c/soc_camera/ov5642.c31
-rw-r--r--drivers/media/i2c/soc_camera/ov6650.c30
-rw-r--r--drivers/media/i2c/soc_camera/ov772x.c36
-rw-r--r--drivers/media/i2c/soc_camera/ov9640.c27
-rw-r--r--drivers/media/i2c/soc_camera/ov9740.c29
-rw-r--r--drivers/media/i2c/soc_camera/rj54n1cb0c.c39
-rw-r--r--drivers/media/i2c/soc_camera/tw9910.c30
-rw-r--r--drivers/media/i2c/ths7303.c3
-rw-r--r--drivers/media/i2c/tvaudio.c238
-rw-r--r--drivers/media/i2c/tvp514x.c4
-rw-r--r--drivers/media/i2c/tvp5150.c7
-rw-r--r--drivers/media/i2c/tvp7002.c18
-rw-r--r--drivers/media/parport/Kconfig1
-rw-r--r--drivers/media/parport/bw-qcam.c165
-rw-r--r--drivers/media/pci/bt8xx/Makefile1
-rw-r--r--drivers/media/pci/bt8xx/bttv-driver.c6
-rw-r--r--drivers/media/pci/bt8xx/bttv-i2c.c5
-rw-r--r--drivers/media/pci/bt8xx/dst_ca.c4
-rw-r--r--drivers/media/pci/cx18/cx18-alsa-main.c2
-rw-r--r--drivers/media/pci/cx18/cx18-alsa-pcm.h2
-rw-r--r--drivers/media/pci/cx18/cx18-i2c.c9
-rw-r--r--drivers/media/pci/cx18/cx18-vbi.c2
-rw-r--r--drivers/media/pci/cx23885/Kconfig3
-rw-r--r--drivers/media/pci/cx23885/Makefile1
-rw-r--r--drivers/media/pci/cx23885/cx23885-cards.c114
-rw-r--r--drivers/media/pci/cx23885/cx23885-core.c2
-rw-r--r--drivers/media/pci/cx23885/cx23885-dvb.c66
-rw-r--r--drivers/media/pci/cx23885/cx23885-input.c9
-rw-r--r--drivers/media/pci/cx23885/cx23885-video.c20
-rw-r--r--drivers/media/pci/cx23885/cx23885.h2
-rw-r--r--drivers/media/pci/cx23885/cx23888-ir.c6
-rw-r--r--drivers/media/pci/cx25821/Makefile1
-rw-r--r--drivers/media/pci/cx25821/cx25821-video.c2
-rw-r--r--drivers/media/pci/cx88/Kconfig2
-rw-r--r--drivers/media/pci/cx88/Makefile1
-rw-r--r--drivers/media/pci/cx88/cx88-cards.c2
-rw-r--r--drivers/media/pci/cx88/cx88-core.c2
-rw-r--r--drivers/media/pci/cx88/cx88-dvb.c15
-rw-r--r--drivers/media/pci/cx88/cx88-i2c.c3
-rw-r--r--drivers/media/pci/cx88/cx88-vp3054-i2c.c3
-rw-r--r--drivers/media/pci/cx88/cx88-vp3054-i2c.h2
-rw-r--r--drivers/media/pci/cx88/cx88.h10
-rw-r--r--drivers/media/pci/dm1105/Kconfig1
-rw-r--r--drivers/media/pci/dm1105/dm1105.c11
-rw-r--r--drivers/media/pci/ivtv/ivtv-alsa-main.c2
-rw-r--r--drivers/media/pci/ivtv/ivtv-alsa-pcm.h2
-rw-r--r--drivers/media/pci/ivtv/ivtv-driver.c2
-rw-r--r--drivers/media/pci/ivtv/ivtv-i2c.c14
-rw-r--r--drivers/media/pci/ivtv/ivtv-vbi.c4
-rw-r--r--drivers/media/pci/mantis/mantis_ca.c5
-rw-r--r--drivers/media/pci/meye/meye.c286
-rw-r--r--drivers/media/pci/meye/meye.h2
-rw-r--r--drivers/media/pci/ngene/ngene-cards.c9
-rw-r--r--drivers/media/pci/saa7134/saa7134-cards.c17
-rw-r--r--drivers/media/pci/saa7134/saa7134-core.c2
-rw-r--r--drivers/media/pci/saa7134/saa7134-dvb.c3
-rw-r--r--drivers/media/pci/saa7134/saa7134-video.c13
-rw-r--r--drivers/media/pci/saa7134/saa7134.h7
-rw-r--r--drivers/media/pci/saa7164/saa7164-encoder.c2
-rw-r--r--drivers/media/pci/sta2x11/Kconfig2
-rw-r--r--drivers/media/pci/sta2x11/sta2x11_vip.c1073
-rw-r--r--drivers/media/pci/ttpci/Kconfig5
-rw-r--r--drivers/media/pci/ttpci/av7110.c12
-rw-r--r--drivers/media/pci/ttpci/av7110.h2
-rw-r--r--drivers/media/pci/ttpci/av7110_av.c8
-rw-r--r--drivers/media/pci/ttpci/av7110_ca.c24
-rw-r--r--drivers/media/pci/zoran/zoran_card.c3
-rw-r--r--drivers/media/pci/zoran/zoran_device.c4
-rw-r--r--drivers/media/pci/zoran/zoran_driver.c2
-rw-r--r--drivers/media/platform/Kconfig11
-rw-r--r--drivers/media/platform/Makefile2
-rw-r--r--drivers/media/platform/blackfin/Kconfig7
-rw-r--r--drivers/media/platform/blackfin/Makefile4
-rw-r--r--drivers/media/platform/blackfin/bfin_capture.c189
-rw-r--r--drivers/media/platform/blackfin/ppi.c90
-rw-r--r--drivers/media/platform/coda.c32
-rw-r--r--drivers/media/platform/davinci/Kconfig22
-rw-r--r--drivers/media/platform/davinci/Makefile4
-rw-r--r--drivers/media/platform/davinci/dm355_ccdc.c2
-rw-r--r--drivers/media/platform/davinci/vpbe.c12
-rw-r--r--drivers/media/platform/davinci/vpbe_display.c9
-rw-r--r--drivers/media/platform/davinci/vpbe_osd.c35
-rw-r--r--drivers/media/platform/davinci/vpbe_venc.c65
-rw-r--r--drivers/media/platform/davinci/vpfe_capture.c5
-rw-r--r--drivers/media/platform/davinci/vpif_capture.c2
-rw-r--r--drivers/media/platform/davinci/vpif_display.c6
-rw-r--r--drivers/media/platform/davinci/vpss.c70
-rw-r--r--drivers/media/platform/exynos-gsc/gsc-core.c48
-rw-r--r--drivers/media/platform/exynos-gsc/gsc-core.h5
-rw-r--r--drivers/media/platform/exynos-gsc/gsc-m2m.c34
-rw-r--r--drivers/media/platform/exynos-gsc/gsc-regs.c6
-rw-r--r--drivers/media/platform/fsl-viu.c2
-rw-r--r--drivers/media/platform/m2m-deinterlace.c6
-rw-r--r--drivers/media/platform/marvell-ccic/mcam-core.c84
-rw-r--r--drivers/media/platform/marvell-ccic/mcam-core.h17
-rw-r--r--drivers/media/platform/omap/Kconfig2
-rw-r--r--drivers/media/platform/omap/omap_vout.c36
-rw-r--r--drivers/media/platform/omap24xxcam.c2
-rw-r--r--drivers/media/platform/omap3isp/isp.c74
-rw-r--r--drivers/media/platform/omap3isp/ispccp2.c8
-rw-r--r--drivers/media/platform/omap3isp/ispcsiphy.c13
-rw-r--r--drivers/media/platform/omap3isp/isph3a_aewb.c28
-rw-r--r--drivers/media/platform/omap3isp/isph3a_af.c28
-rw-r--r--drivers/media/platform/omap3isp/isphist.c21
-rw-r--r--drivers/media/platform/omap3isp/isppreview.c40
-rw-r--r--drivers/media/platform/omap3isp/ispqueue.c5
-rw-r--r--drivers/media/platform/s3c-camif/camif-core.c1
-rw-r--r--drivers/media/platform/s5p-fimc/fimc-capture.c190
-rw-r--r--drivers/media/platform/s5p-fimc/fimc-core.c165
-rw-r--r--drivers/media/platform/s5p-fimc/fimc-core.h17
-rw-r--r--drivers/media/platform/s5p-fimc/fimc-lite-reg.c16
-rw-r--r--drivers/media/platform/s5p-fimc/fimc-lite-reg.h4
-rw-r--r--drivers/media/platform/s5p-fimc/fimc-lite.c192
-rw-r--r--drivers/media/platform/s5p-fimc/fimc-lite.h9
-rw-r--r--drivers/media/platform/s5p-fimc/fimc-m2m.c136
-rw-r--r--drivers/media/platform/s5p-fimc/fimc-mdevice.c400
-rw-r--r--drivers/media/platform/s5p-fimc/fimc-mdevice.h14
-rw-r--r--drivers/media/platform/s5p-fimc/fimc-reg.c82
-rw-r--r--drivers/media/platform/s5p-fimc/fimc-reg.h10
-rw-r--r--drivers/media/platform/s5p-fimc/mipi-csis.c101
-rw-r--r--drivers/media/platform/s5p-g2d/g2d-hw.c16
-rw-r--r--drivers/media/platform/s5p-g2d/g2d-regs.h7
-rw-r--r--drivers/media/platform/s5p-g2d/g2d.c35
-rw-r--r--drivers/media/platform/s5p-g2d/g2d.h17
-rw-r--r--drivers/media/platform/s5p-jpeg/jpeg-core.h2
-rw-r--r--drivers/media/platform/s5p-mfc/s5p_mfc.c165
-rw-r--r--drivers/media/platform/s5p-mfc/s5p_mfc_common.h31
-rw-r--r--drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c149
-rw-r--r--drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.h3
-rw-r--r--drivers/media/platform/s5p-mfc/s5p_mfc_dec.c15
-rw-r--r--drivers/media/platform/s5p-mfc/s5p_mfc_enc.c2
-rw-r--r--drivers/media/platform/s5p-mfc/s5p_mfc_opr.c30
-rw-r--r--drivers/media/platform/s5p-mfc/s5p_mfc_opr.h5
-rw-r--r--drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c197
-rw-r--r--drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c148
-rw-r--r--drivers/media/platform/s5p-mfc/s5p_mfc_pm.c2
-rw-r--r--drivers/media/platform/s5p-tv/hdmi_drv.c18
-rw-r--r--drivers/media/platform/s5p-tv/hdmiphy_drv.c2
-rw-r--r--drivers/media/platform/s5p-tv/mixer.h1
-rw-r--r--drivers/media/platform/s5p-tv/mixer_drv.c14
-rw-r--r--drivers/media/platform/s5p-tv/mixer_reg.c6
-rw-r--r--drivers/media/platform/s5p-tv/mixer_video.c19
-rw-r--r--drivers/media/platform/s5p-tv/sdo_drv.c29
-rw-r--r--drivers/media/platform/s5p-tv/sii9234_drv.c6
-rw-r--r--drivers/media/platform/sh_veu.c1266
-rw-r--r--drivers/media/platform/sh_vou.c123
-rw-r--r--drivers/media/platform/soc_camera/Kconfig7
-rw-r--r--drivers/media/platform/soc_camera/atmel-isi.c6
-rw-r--r--drivers/media/platform/soc_camera/mx1_camera.c5
-rw-r--r--drivers/media/platform/soc_camera/mx2_camera.c529
-rw-r--r--drivers/media/platform/soc_camera/mx3_camera.c6
-rw-r--r--drivers/media/platform/soc_camera/omap1_camera.c6
-rw-r--r--drivers/media/platform/soc_camera/pxa_camera.c73
-rw-r--r--drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c44
-rw-r--r--drivers/media/platform/soc_camera/sh_mobile_csi2.c23
-rw-r--r--drivers/media/platform/soc_camera/soc_camera.c172
-rw-r--r--drivers/media/platform/soc_camera/soc_camera_platform.c6
-rw-r--r--drivers/media/platform/soc_camera/soc_mediabus.c6
-rw-r--r--drivers/media/platform/timblogiw.c2
-rw-r--r--drivers/media/platform/via-camera.c60
-rw-r--r--drivers/media/platform/vino.c11
-rw-r--r--drivers/media/platform/vivi.c224
-rw-r--r--drivers/media/radio/Kconfig12
-rw-r--r--drivers/media/radio/Makefile1
-rw-r--r--drivers/media/radio/radio-ma901.c460
-rw-r--r--drivers/media/radio/radio-miropcm20.c173
-rw-r--r--drivers/media/radio/radio-wl1273.c3
-rw-r--r--drivers/media/radio/si470x/radio-si470x.h4
-rw-r--r--drivers/media/radio/wl128x/fmdrv_common.c3
-rw-r--r--drivers/media/rc/ati_remote.c27
-rw-r--r--drivers/media/rc/ene_ir.c28
-rw-r--r--drivers/media/rc/fintek-cir.c24
-rw-r--r--drivers/media/rc/gpio-ir-recv.c55
-rw-r--r--drivers/media/rc/iguanair.c26
-rw-r--r--drivers/media/rc/imon.c4
-rw-r--r--drivers/media/rc/ir-raw.c17
-rw-r--r--drivers/media/rc/ite-cir.c26
-rw-r--r--drivers/media/rc/keymaps/Makefile1
-rw-r--r--drivers/media/rc/keymaps/rc-total-media-in-hand-02.c86
-rw-r--r--drivers/media/rc/mceusb.c37
-rw-r--r--drivers/media/rc/nuvoton-cir.c41
-rw-r--r--drivers/media/rc/rc-core-priv.h16
-rw-r--r--drivers/media/rc/rc-main.c7
-rw-r--r--drivers/media/rc/redrat3.c18
-rw-r--r--drivers/media/rc/ttusbir.c10
-rw-r--r--drivers/media/rc/winbond-cir.c41
-rw-r--r--drivers/media/tuners/fc0011.c19
-rw-r--r--drivers/media/tuners/fc0012-priv.h13
-rw-r--r--drivers/media/tuners/fc0012.c113
-rw-r--r--drivers/media/tuners/fc0012.h32
-rw-r--r--drivers/media/tuners/mt2060.h2
-rw-r--r--drivers/media/tuners/mt2063.h2
-rw-r--r--drivers/media/tuners/mt20xx.h2
-rw-r--r--drivers/media/tuners/mt2131.h2
-rw-r--r--drivers/media/tuners/mt2266.h2
-rw-r--r--drivers/media/tuners/mxl5007t.h2
-rw-r--r--drivers/media/tuners/qt1010.h2
-rw-r--r--drivers/media/tuners/tda18212.c6
-rw-r--r--drivers/media/tuners/tda18218.c6
-rw-r--r--drivers/media/tuners/tda18271-fe.c2
-rw-r--r--drivers/media/tuners/tda18271-maps.c6
-rw-r--r--drivers/media/tuners/tda18271.h2
-rw-r--r--drivers/media/tuners/tda827x.h2
-rw-r--r--drivers/media/tuners/tda8290.h2
-rw-r--r--drivers/media/tuners/tda9887.h2
-rw-r--r--drivers/media/tuners/tea5761.h2
-rw-r--r--drivers/media/tuners/tea5767.h2
-rw-r--r--drivers/media/tuners/tuner-simple.h2
-rw-r--r--drivers/media/tuners/tuner-xc2028.c2
-rw-r--r--drivers/media/tuners/tuner-xc2028.h2
-rw-r--r--drivers/media/tuners/xc4000.c2
-rw-r--r--drivers/media/tuners/xc4000.h2
-rw-r--r--drivers/media/tuners/xc5000.c1
-rw-r--r--drivers/media/usb/Kconfig2
-rw-r--r--drivers/media/usb/au0828/Kconfig17
-rw-r--r--drivers/media/usb/au0828/Makefile6
-rw-r--r--drivers/media/usb/au0828/au0828-cards.c24
-rw-r--r--drivers/media/usb/au0828/au0828-core.c13
-rw-r--r--drivers/media/usb/au0828/au0828-i2c.c13
-rw-r--r--drivers/media/usb/au0828/au0828-video.c4
-rw-r--r--drivers/media/usb/au0828/au0828.h2
-rw-r--r--drivers/media/usb/cpia2/cpia2_usb.c2
-rw-r--r--drivers/media/usb/cpia2/cpia2_v4l.c5
-rw-r--r--drivers/media/usb/cx231xx/cx231xx-417.c4
-rw-r--r--drivers/media/usb/cx231xx/cx231xx-cards.c31
-rw-r--r--drivers/media/usb/cx231xx/cx231xx-vbi.c2
-rw-r--r--drivers/media/usb/cx231xx/cx231xx-video.c6
-rw-r--r--drivers/media/usb/cx231xx/cx231xx.h1
-rw-r--r--drivers/media/usb/dvb-usb-v2/Kconfig4
-rw-r--r--drivers/media/usb/dvb-usb-v2/af9015.c4
-rw-r--r--drivers/media/usb/dvb-usb-v2/af9035.c289
-rw-r--r--drivers/media/usb/dvb-usb-v2/af9035.h3
-rw-r--r--drivers/media/usb/dvb-usb-v2/anysee.c4
-rw-r--r--drivers/media/usb/dvb-usb-v2/az6007.c26
-rw-r--r--drivers/media/usb/dvb-usb-v2/dvb_usb.h3
-rw-r--r--drivers/media/usb/dvb-usb-v2/dvb_usb_core.c15
-rw-r--r--drivers/media/usb/dvb-usb-v2/it913x.c54
-rw-r--r--drivers/media/usb/dvb-usb-v2/lmedm04.c38
-rw-r--r--drivers/media/usb/dvb-usb-v2/rtl28xxu.c30
-rw-r--r--drivers/media/usb/dvb-usb/Kconfig8
-rw-r--r--drivers/media/usb/dvb-usb/dib0700_core.c5
-rw-r--r--drivers/media/usb/dvb-usb/dvb-usb-init.c60
-rw-r--r--drivers/media/usb/dvb-usb/dw2102.c179
-rw-r--r--drivers/media/usb/dvb-usb/friio-fe.c5
-rw-r--r--drivers/media/usb/dvb-usb/m920x.c277
-rw-r--r--drivers/media/usb/dvb-usb/ttusb2.c8
-rw-r--r--drivers/media/usb/em28xx/Kconfig8
-rw-r--r--drivers/media/usb/em28xx/em28xx-cards.c270
-rw-r--r--drivers/media/usb/em28xx/em28xx-core.c296
-rw-r--r--drivers/media/usb/em28xx/em28xx-dvb.c96
-rw-r--r--drivers/media/usb/em28xx/em28xx-i2c.c293
-rw-r--r--drivers/media/usb/em28xx/em28xx-input.c359
-rw-r--r--drivers/media/usb/em28xx/em28xx-reg.h5
-rw-r--r--drivers/media/usb/em28xx/em28xx-vbi.c123
-rw-r--r--drivers/media/usb/em28xx/em28xx-video.c1689
-rw-r--r--drivers/media/usb/em28xx/em28xx.h149
-rw-r--r--drivers/media/usb/gspca/cpia1.c6
-rw-r--r--drivers/media/usb/gspca/gspca.c10
-rw-r--r--drivers/media/usb/gspca/gspca.h6
-rw-r--r--drivers/media/usb/gspca/jl2005bcd.c18
-rw-r--r--drivers/media/usb/gspca/konica.c6
-rw-r--r--drivers/media/usb/gspca/ov519.c6
-rw-r--r--drivers/media/usb/gspca/pac207.c36
-rw-r--r--drivers/media/usb/gspca/pac7302.c4
-rw-r--r--drivers/media/usb/gspca/pac7311.c4
-rw-r--r--drivers/media/usb/gspca/se401.c4
-rw-r--r--drivers/media/usb/gspca/sn9c20x.c4
-rw-r--r--drivers/media/usb/gspca/sonixb.c6
-rw-r--r--drivers/media/usb/gspca/sonixj.c4
-rw-r--r--drivers/media/usb/gspca/spca561.c6
-rw-r--r--drivers/media/usb/gspca/stv06xx/stv06xx.c4
-rw-r--r--drivers/media/usb/gspca/stv06xx/stv06xx_vv6410.c17
-rw-r--r--drivers/media/usb/gspca/t613.c8
-rw-r--r--drivers/media/usb/gspca/xirlink_cit.c8
-rw-r--r--drivers/media/usb/gspca/zc3xx.c4
-rw-r--r--drivers/media/usb/hdpvr/hdpvr-core.c6
-rw-r--r--drivers/media/usb/hdpvr/hdpvr-i2c.c5
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-encoder.c3
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-i2c-core.c4
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-v4l2.c2
-rw-r--r--drivers/media/usb/pwc/pwc-if.c5
-rw-r--r--drivers/media/usb/pwc/pwc-v4l.c7
-rw-r--r--drivers/media/usb/s2255/s2255drv.c6
-rw-r--r--drivers/media/usb/sn9c102/sn9c102_core.c9
-rw-r--r--drivers/media/usb/stk1160/stk1160-video.c4
-rw-r--r--drivers/media/usb/stkwebcam/stk-webcam.c59
-rw-r--r--drivers/media/usb/tlg2300/pd-video.c2
-rw-r--r--drivers/media/usb/tm6000/tm6000-core.c9
-rw-r--r--drivers/media/usb/tm6000/tm6000-dvb.c4
-rw-r--r--drivers/media/usb/tm6000/tm6000-video.c542
-rw-r--r--drivers/media/usb/tm6000/tm6000.h10
-rw-r--r--drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c7
-rw-r--r--drivers/media/usb/usbvision/usbvision-core.c2
-rw-r--r--drivers/media/usb/usbvision/usbvision-i2c.c3
-rw-r--r--drivers/media/usb/usbvision/usbvision-video.c5
-rw-r--r--drivers/media/usb/uvc/uvc_ctrl.c2
-rw-r--r--drivers/media/usb/uvc/uvc_queue.c16
-rw-r--r--drivers/media/usb/uvc/uvc_v4l2.c8
-rw-r--r--drivers/media/usb/zr364xx/zr364xx.c6
-rw-r--r--drivers/media/v4l2-core/Kconfig11
-rw-r--r--drivers/media/v4l2-core/Makefile3
-rw-r--r--drivers/media/v4l2-core/tuner-core.c17
-rw-r--r--drivers/media/v4l2-core/v4l2-common.c14
-rw-r--r--drivers/media/v4l2-core/v4l2-ctrls.c179
-rw-r--r--drivers/media/v4l2-core/v4l2-dev.c14
-rw-r--r--drivers/media/v4l2-core/v4l2-device.c32
-rw-r--r--drivers/media/v4l2-core/v4l2-event.c7
-rw-r--r--drivers/media/v4l2-core/v4l2-mem2mem.c4
-rw-r--r--drivers/media/v4l2-core/videobuf-core.c2
-rw-r--r--drivers/media/v4l2-core/videobuf2-core.c15
-rw-r--r--drivers/staging/media/Kconfig2
-rw-r--r--drivers/staging/media/Makefile1
-rw-r--r--drivers/staging/media/as102/as102_usb_drv.c4
-rw-r--r--drivers/staging/media/as102/as10x_cmd_cfg.c2
-rw-r--r--drivers/staging/media/cxd2099/cxd2099.c29
-rw-r--r--drivers/staging/media/cxd2099/cxd2099.h2
-rw-r--r--drivers/staging/media/davinci_vpfe/Kconfig9
-rw-r--r--drivers/staging/media/davinci_vpfe/Makefile3
-rw-r--r--drivers/staging/media/davinci_vpfe/TODO37
-rw-r--r--drivers/staging/media/davinci_vpfe/davinci-vpfe-mc.txt154
-rw-r--r--drivers/staging/media/davinci_vpfe/davinci_vpfe_user.h1290
-rw-r--r--drivers/staging/media/davinci_vpfe/dm365_ipipe.c1863
-rw-r--r--drivers/staging/media/davinci_vpfe/dm365_ipipe.h179
-rw-r--r--drivers/staging/media/davinci_vpfe/dm365_ipipe_hw.c1048
-rw-r--r--drivers/staging/media/davinci_vpfe/dm365_ipipe_hw.h559
-rw-r--r--drivers/staging/media/davinci_vpfe/dm365_ipipeif.c1071
-rw-r--r--drivers/staging/media/davinci_vpfe/dm365_ipipeif.h233
-rw-r--r--drivers/staging/media/davinci_vpfe/dm365_ipipeif_user.h93
-rw-r--r--drivers/staging/media/davinci_vpfe/dm365_isif.c2104
-rw-r--r--drivers/staging/media/davinci_vpfe/dm365_isif.h203
-rw-r--r--drivers/staging/media/davinci_vpfe/dm365_isif_regs.h294
-rw-r--r--drivers/staging/media/davinci_vpfe/dm365_resizer.c1999
-rw-r--r--drivers/staging/media/davinci_vpfe/dm365_resizer.h244
-rw-r--r--drivers/staging/media/davinci_vpfe/vpfe.h86
-rw-r--r--drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c740
-rw-r--r--drivers/staging/media/davinci_vpfe/vpfe_mc_capture.h97
-rw-r--r--drivers/staging/media/davinci_vpfe/vpfe_video.c1620
-rw-r--r--drivers/staging/media/davinci_vpfe/vpfe_video.h155
-rw-r--r--drivers/staging/media/dt3155v4l/dt3155v4l.c2
-rw-r--r--drivers/staging/media/go7007/go7007-driver.c15
-rw-r--r--drivers/staging/media/go7007/go7007-fw.c24
-rw-r--r--drivers/staging/media/go7007/go7007-i2c.c10
-rw-r--r--drivers/staging/media/go7007/go7007-usb.c5
-rw-r--r--drivers/staging/media/go7007/go7007-v4l2.c11
-rw-r--r--drivers/staging/media/go7007/s2250-board.c32
-rw-r--r--drivers/staging/media/go7007/s2250-loader.c38
-rw-r--r--drivers/staging/media/go7007/wis-saa7113.c2
-rw-r--r--drivers/staging/media/go7007/wis-sony-tuner.c86
-rw-r--r--drivers/staging/media/go7007/wis-tw2804.c24
-rw-r--r--drivers/staging/media/go7007/wis-tw9903.c12
-rw-r--r--drivers/staging/media/go7007/wis-uda1342.c7
-rw-r--r--drivers/staging/media/lirc/lirc_bt829.c15
-rw-r--r--drivers/staging/media/lirc/lirc_igorplugusb.c12
-rw-r--r--drivers/staging/media/lirc/lirc_imon.c31
-rw-r--r--drivers/staging/media/lirc/lirc_parallel.c49
-rw-r--r--drivers/staging/media/lirc/lirc_sasem.c73
-rw-r--r--drivers/staging/media/lirc/lirc_serial.c70
-rw-r--r--drivers/staging/media/lirc/lirc_sir.c36
-rw-r--r--drivers/staging/media/solo6x10/p2m.c8
-rw-r--r--drivers/staging/media/solo6x10/v4l2-enc.c4
-rw-r--r--drivers/staging/media/solo6x10/v4l2.c5
-rw-r--r--include/media/adv7343.h52
-rw-r--r--include/media/blackfin/bfin_capture.h5
-rw-r--r--include/media/blackfin/ppi.h36
-rw-r--r--include/media/davinci/vpbe_osd.h5
-rw-r--r--include/media/davinci/vpbe_venc.h5
-rw-r--r--include/media/davinci/vpss.h16
-rw-r--r--include/media/ov7670.h2
-rw-r--r--include/media/ov9650.h27
-rw-r--r--include/media/rc-map.h1
-rw-r--r--include/media/s5c73m3.h55
-rw-r--r--include/media/s5p_fimc.h49
-rw-r--r--include/media/soc_camera.h107
-rw-r--r--include/media/soc_camera_platform.h10
-rw-r--r--include/media/tvp514x.h7
-rw-r--r--include/media/v4l2-common.h2
-rw-r--r--include/media/v4l2-ctrls.h53
-rw-r--r--include/media/v4l2-event.h4
-rw-r--r--include/media/v4l2-image-sizes.h34
-rw-r--r--include/media/v4l2-mem2mem.h2
-rw-r--r--include/uapi/linux/dvb/frontend.h79
-rw-r--r--include/uapi/linux/dvb/version.h2
-rw-r--r--include/uapi/linux/meye.h8
-rw-r--r--include/uapi/linux/v4l2-controls.h33
-rw-r--r--include/uapi/linux/v4l2-mediabus.h11
-rw-r--r--include/uapi/linux/videodev2.h35
538 files changed, 32957 insertions, 11039 deletions
diff --git a/Documentation/DocBook/media/dvb/dvbapi.xml b/Documentation/DocBook/media/dvb/dvbapi.xml
index 757488b24f4f..0197bcc7842d 100644
--- a/Documentation/DocBook/media/dvb/dvbapi.xml
+++ b/Documentation/DocBook/media/dvb/dvbapi.xml
@@ -84,7 +84,7 @@ Added ISDB-T test originally written by Patrick Boettcher
84 84
85 85
86<title>LINUX DVB API</title> 86<title>LINUX DVB API</title>
87<subtitle>Version 5.8</subtitle> 87<subtitle>Version 5.10</subtitle>
88<!-- ADD THE CHAPTERS HERE --> 88<!-- ADD THE CHAPTERS HERE -->
89 <chapter id="dvb_introdution"> 89 <chapter id="dvb_introdution">
90 &sub-intro; 90 &sub-intro;
diff --git a/Documentation/DocBook/media/dvb/dvbproperty.xml b/Documentation/DocBook/media/dvb/dvbproperty.xml
index 957e3acaae8e..4a5eaeed0b9e 100644
--- a/Documentation/DocBook/media/dvb/dvbproperty.xml
+++ b/Documentation/DocBook/media/dvb/dvbproperty.xml
@@ -7,14 +7,41 @@ the capability ioctls weren't implemented yet via the new way.</para>
7<para>The typical usage for the <constant>FE_GET_PROPERTY/FE_SET_PROPERTY</constant> 7<para>The typical usage for the <constant>FE_GET_PROPERTY/FE_SET_PROPERTY</constant>
8API is to replace the ioctl's were the <link linkend="dvb-frontend-parameters"> 8API is to replace the ioctl's were the <link linkend="dvb-frontend-parameters">
9struct <constant>dvb_frontend_parameters</constant></link> were used.</para> 9struct <constant>dvb_frontend_parameters</constant></link> were used.</para>
10<section id="dtv-stats">
11<title>DTV stats type</title>
12<programlisting>
13struct dtv_stats {
14 __u8 scale; /* enum fecap_scale_params type */
15 union {
16 __u64 uvalue; /* for counters and relative scales */
17 __s64 svalue; /* for 1/1000 dB measures */
18 };
19} __packed;
20</programlisting>
21</section>
22<section id="dtv-fe-stats">
23<title>DTV stats type</title>
24<programlisting>
25#define MAX_DTV_STATS 4
26
27struct dtv_fe_stats {
28 __u8 len;
29 struct dtv_stats stat[MAX_DTV_STATS];
30} __packed;
31</programlisting>
32</section>
33
10<section id="dtv-property"> 34<section id="dtv-property">
11<title>DTV property type</title> 35<title>DTV property type</title>
12<programlisting> 36<programlisting>
13/* Reserved fields should be set to 0 */ 37/* Reserved fields should be set to 0 */
38
14struct dtv_property { 39struct dtv_property {
15 __u32 cmd; 40 __u32 cmd;
41 __u32 reserved[3];
16 union { 42 union {
17 __u32 data; 43 __u32 data;
44 struct dtv_fe_stats st;
18 struct { 45 struct {
19 __u8 data[32]; 46 __u8 data[32];
20 __u32 len; 47 __u32 len;
@@ -440,7 +467,7 @@ typedef enum fe_delivery_system {
440 <title><constant>DTV-ISDBT-LAYER*</constant> parameters</title> 467 <title><constant>DTV-ISDBT-LAYER*</constant> parameters</title>
441 <para>ISDB-T channels can be coded hierarchically. As opposed to DVB-T in 468 <para>ISDB-T channels can be coded hierarchically. As opposed to DVB-T in
442 ISDB-T hierarchical layers can be decoded simultaneously. For that 469 ISDB-T hierarchical layers can be decoded simultaneously. For that
443 reason a ISDB-T demodulator has 3 viterbi and 3 reed-solomon-decoders.</para> 470 reason a ISDB-T demodulator has 3 Viterbi and 3 Reed-Solomon decoders.</para>
444 <para>ISDB-T has 3 hierarchical layers which each can use a part of the 471 <para>ISDB-T has 3 hierarchical layers which each can use a part of the
445 available segments. The total number of segments over all layers has 472 available segments. The total number of segments over all layers has
446 to 13 in ISDB-T.</para> 473 to 13 in ISDB-T.</para>
@@ -850,6 +877,147 @@ enum fe_interleaving {
850 <para>use the special macro LNA_AUTO to set LNA auto</para> 877 <para>use the special macro LNA_AUTO to set LNA auto</para>
851 </section> 878 </section>
852</section> 879</section>
880
881 <section id="frontend-stat-properties">
882 <title>Frontend statistics indicators</title>
883 <para>The values are returned via <constant>dtv_property.stat</constant>.
884 If the property is supported, <constant>dtv_property.stat.len</constant> is bigger than zero.</para>
885 <para>For most delivery systems, <constant>dtv_property.stat.len</constant>
886 will be 1 if the stats is supported, and the properties will
887 return a single value for each parameter.</para>
888 <para>It should be noticed, however, that new OFDM delivery systems
889 like ISDB can use different modulation types for each group of
890 carriers. On such standards, up to 3 groups of statistics can be
891 provided, and <constant>dtv_property.stat.len</constant> is updated
892 to reflect the "global" metrics, plus one metric per each carrier
893 group (called "layer" on ISDB).</para>
894 <para>So, in order to be consistent with other delivery systems, the first
895 value at <link linkend="dtv-stats"><constant>dtv_property.stat.dtv_stats</constant></link>
896 array refers to the global metric. The other elements of the array
897 represent each layer, starting from layer A(index 1),
898 layer B (index 2) and so on.</para>
899 <para>The number of filled elements are stored at <constant>dtv_property.stat.len</constant>.</para>
900 <para>Each element of the <constant>dtv_property.stat.dtv_stats</constant> array consists on two elements:</para>
901 <itemizedlist mark='opencircle'>
902 <listitem><para><constant>svalue</constant> or <constant>uvalue</constant>, where
903 <constant>svalue</constant> is for signed values of the measure (dB measures)
904 and <constant>uvalue</constant> is for unsigned values (counters, relative scale)</para></listitem>
905 <listitem><para><constant>scale</constant> - Scale for the value. It can be:</para>
906 <section id = "fecap-scale-params">
907 <itemizedlist mark='bullet'>
908 <listitem><para><constant>FE_SCALE_NOT_AVAILABLE</constant> - The parameter is supported by the frontend, but it was not possible to collect it (could be a transitory or permanent condition)</para></listitem>
909 <listitem><para><constant>FE_SCALE_DECIBEL</constant> - parameter is a signed value, measured in 1/1000 dB</para></listitem>
910 <listitem><para><constant>FE_SCALE_RELATIVE</constant> - parameter is a unsigned value, where 0 means 0% and 65535 means 100%.</para></listitem>
911 <listitem><para><constant>FE_SCALE_COUNTER</constant> - parameter is a unsigned value that counts the occurrence of an event, like bit error, block error, or lapsed time.</para></listitem>
912 </itemizedlist>
913 </section>
914 </listitem>
915 </itemizedlist>
916 <section id="DTV-STAT-SIGNAL-STRENGTH">
917 <title><constant>DTV_STAT_SIGNAL_STRENGTH</constant></title>
918 <para>Indicates the signal strength level at the analog part of the tuner or of the demod.</para>
919 <para>Possible scales for this metric are:</para>
920 <itemizedlist mark='bullet'>
921 <listitem><constant>FE_SCALE_NOT_AVAILABLE</constant> - it failed to measure it, or the measurement was not complete yet.</listitem>
922 <listitem><constant>FE_SCALE_DECIBEL</constant> - signal strength is in 0.0001 dBm units, power measured in miliwatts. This value is generally negative.</listitem>
923 <listitem><constant>FE_SCALE_RELATIVE</constant> - The frontend provides a 0% to 100% measurement for power (actually, 0 to 65535).</listitem>
924 </itemizedlist>
925 </section>
926 <section id="DTV-STAT-CNR">
927 <title><constant>DTV_STAT_CNR</constant></title>
928 <para>Indicates the Signal to Noise ratio for the main carrier.</para>
929 <para>Possible scales for this metric are:</para>
930 <itemizedlist mark='bullet'>
931 <listitem><constant>FE_SCALE_NOT_AVAILABLE</constant> - it failed to measure it, or the measurement was not complete yet.</listitem>
932 <listitem><constant>FE_SCALE_DECIBEL</constant> - Signal/Noise ratio is in 0.0001 dB units.</listitem>
933 <listitem><constant>FE_SCALE_RELATIVE</constant> - The frontend provides a 0% to 100% measurement for Signal/Noise (actually, 0 to 65535).</listitem>
934 </itemizedlist>
935 </section>
936 <section id="DTV-STAT-PRE-ERROR-BIT-COUNT">
937 <title><constant>DTV_STAT_PRE_ERROR_BIT_COUNT</constant></title>
938 <para>Measures the number of bit errors before the forward error correction (FEC) on the inner coding block (before Viterbi, LDPC or other inner code).</para>
939 <para>This measure is taken during the same interval as <constant>DTV_STAT_PRE_TOTAL_BIT_COUNT</constant>.</para>
940 <para>In order to get the BER (Bit Error Rate) measurement, it should be divided by
941 <link linkend="DTV-STAT-PRE-TOTAL-BIT-COUNT"><constant>DTV_STAT_PRE_TOTAL_BIT_COUNT</constant></link>.</para>
942 <para>This measurement is monotonically increased, as the frontend gets more bit count measurements.
943 The frontend may reset it when a channel/transponder is tuned.</para>
944 <para>Possible scales for this metric are:</para>
945 <itemizedlist mark='bullet'>
946 <listitem><constant>FE_SCALE_NOT_AVAILABLE</constant> - it failed to measure it, or the measurement was not complete yet.</listitem>
947 <listitem><constant>FE_SCALE_COUNTER</constant> - Number of error bits counted before the inner coding.</listitem>
948 </itemizedlist>
949 </section>
950 <section id="DTV-STAT-PRE-TOTAL-BIT-COUNT">
951 <title><constant>DTV_STAT_PRE_TOTAL_BIT_COUNT</constant></title>
952 <para>Measures the amount of bits received before the inner code block, during the same period as
953 <link linkend="DTV-STAT-PRE-ERROR-BIT-COUNT"><constant>DTV_STAT_PRE_ERROR_BIT_COUNT</constant></link> measurement was taken.</para>
954 <para>It should be noticed that this measurement can be smaller than the total amount of bits on the transport stream,
955 as the frontend may need to manually restart the measurement, loosing some data between each measurement interval.</para>
956 <para>This measurement is monotonically increased, as the frontend gets more bit count measurements.
957 The frontend may reset it when a channel/transponder is tuned.</para>
958 <para>Possible scales for this metric are:</para>
959 <itemizedlist mark='bullet'>
960 <listitem><constant>FE_SCALE_NOT_AVAILABLE</constant> - it failed to measure it, or the measurement was not complete yet.</listitem>
961 <listitem><constant>FE_SCALE_COUNTER</constant> - Number of bits counted while measuring
962 <link linkend="DTV-STAT-PRE-ERROR-BIT-COUNT"><constant>DTV_STAT_PRE_ERROR_BIT_COUNT</constant></link>.</listitem>
963 </itemizedlist>
964 </section>
965 <section id="DTV-STAT-POST-ERROR-BIT-COUNT">
966 <title><constant>DTV_STAT_POST_ERROR_BIT_COUNT</constant></title>
967 <para>Measures the number of bit errors after the forward error correction (FEC) done by inner code block (after Viterbi, LDPC or other inner code).</para>
968 <para>This measure is taken during the same interval as <constant>DTV_STAT_POST_TOTAL_BIT_COUNT</constant>.</para>
969 <para>In order to get the BER (Bit Error Rate) measurement, it should be divided by
970 <link linkend="DTV-STAT-POST-TOTAL-BIT-COUNT"><constant>DTV_STAT_POST_TOTAL_BIT_COUNT</constant></link>.</para>
971 <para>This measurement is monotonically increased, as the frontend gets more bit count measurements.
972 The frontend may reset it when a channel/transponder is tuned.</para>
973 <para>Possible scales for this metric are:</para>
974 <itemizedlist mark='bullet'>
975 <listitem><constant>FE_SCALE_NOT_AVAILABLE</constant> - it failed to measure it, or the measurement was not complete yet.</listitem>
976 <listitem><constant>FE_SCALE_COUNTER</constant> - Number of error bits counted after the inner coding.</listitem>
977 </itemizedlist>
978 </section>
979 <section id="DTV-STAT-POST-TOTAL-BIT-COUNT">
980 <title><constant>DTV_STAT_POST_TOTAL_BIT_COUNT</constant></title>
981 <para>Measures the amount of bits received after the inner coding, during the same period as
982 <link linkend="DTV-STAT-POST-ERROR-BIT-COUNT"><constant>DTV_STAT_POST_ERROR_BIT_COUNT</constant></link> measurement was taken.</para>
983 <para>It should be noticed that this measurement can be smaller than the total amount of bits on the transport stream,
984 as the frontend may need to manually restart the measurement, loosing some data between each measurement interval.</para>
985 <para>This measurement is monotonically increased, as the frontend gets more bit count measurements.
986 The frontend may reset it when a channel/transponder is tuned.</para>
987 <para>Possible scales for this metric are:</para>
988 <itemizedlist mark='bullet'>
989 <listitem><constant>FE_SCALE_NOT_AVAILABLE</constant> - it failed to measure it, or the measurement was not complete yet.</listitem>
990 <listitem><constant>FE_SCALE_COUNTER</constant> - Number of bits counted while measuring
991 <link linkend="DTV-STAT-POST-ERROR-BIT-COUNT"><constant>DTV_STAT_POST_ERROR_BIT_COUNT</constant></link>.</listitem>
992 </itemizedlist>
993 </section>
994 <section id="DTV-STAT-ERROR-BLOCK-COUNT">
995 <title><constant>DTV_STAT_ERROR_BLOCK_COUNT</constant></title>
996 <para>Measures the number of block errors after the outer forward error correction coding (after Reed-Solomon or other outer code).</para>
997 <para>This measurement is monotonically increased, as the frontend gets more bit count measurements.
998 The frontend may reset it when a channel/transponder is tuned.</para>
999 <para>Possible scales for this metric are:</para>
1000 <itemizedlist mark='bullet'>
1001 <listitem><constant>FE_SCALE_NOT_AVAILABLE</constant> - it failed to measure it, or the measurement was not complete yet.</listitem>
1002 <listitem><constant>FE_SCALE_COUNTER</constant> - Number of error blocks counted after the outer coding.</listitem>
1003 </itemizedlist>
1004 </section>
1005 <section id="DTV-STAT-TOTAL-BLOCK-COUNT">
1006 <title><constant>DTV-STAT_TOTAL_BLOCK_COUNT</constant></title>
1007 <para>Measures the total number of blocks received during the same period as
1008 <link linkend="DTV-STAT-ERROR-BLOCK-COUNT"><constant>DTV_STAT_ERROR_BLOCK_COUNT</constant></link> measurement was taken.</para>
1009 <para>It can be used to calculate the PER indicator, by dividing
1010 <link linkend="DTV-STAT-ERROR-BLOCK-COUNT"><constant>DTV_STAT_ERROR_BLOCK_COUNT</constant></link>
1011 by <link linkend="DTV-STAT-TOTAL-BLOCK-COUNT"><constant>DTV-STAT-TOTAL-BLOCK-COUNT</constant></link>.</para>
1012 <para>Possible scales for this metric are:</para>
1013 <itemizedlist mark='bullet'>
1014 <listitem><constant>FE_SCALE_NOT_AVAILABLE</constant> - it failed to measure it, or the measurement was not complete yet.</listitem>
1015 <listitem><constant>FE_SCALE_COUNTER</constant> - Number of blocks counted while measuring
1016 <link linkend="DTV-STAT-ERROR-BLOCK-COUNT"><constant>DTV_STAT_ERROR_BLOCK_COUNT</constant></link>.</listitem>
1017 </itemizedlist>
1018 </section>
1019 </section>
1020
853 <section id="frontend-property-terrestrial-systems"> 1021 <section id="frontend-property-terrestrial-systems">
854 <title>Properties used on terrestrial delivery systems</title> 1022 <title>Properties used on terrestrial delivery systems</title>
855 <section id="dvbt-params"> 1023 <section id="dvbt-params">
@@ -871,6 +1039,7 @@ enum fe_interleaving {
871 <listitem><para><link linkend="DTV-HIERARCHY"><constant>DTV_HIERARCHY</constant></link></para></listitem> 1039 <listitem><para><link linkend="DTV-HIERARCHY"><constant>DTV_HIERARCHY</constant></link></para></listitem>
872 <listitem><para><link linkend="DTV-LNA"><constant>DTV_LNA</constant></link></para></listitem> 1040 <listitem><para><link linkend="DTV-LNA"><constant>DTV_LNA</constant></link></para></listitem>
873 </itemizedlist> 1041 </itemizedlist>
1042 <para>In addition, the <link linkend="frontend-stat-properties">DTV QoS statistics</link> are also valid.</para>
874 </section> 1043 </section>
875 <section id="dvbt2-params"> 1044 <section id="dvbt2-params">
876 <title>DVB-T2 delivery system</title> 1045 <title>DVB-T2 delivery system</title>
@@ -895,6 +1064,7 @@ enum fe_interleaving {
895 <listitem><para><link linkend="DTV-STREAM-ID"><constant>DTV_STREAM_ID</constant></link></para></listitem> 1064 <listitem><para><link linkend="DTV-STREAM-ID"><constant>DTV_STREAM_ID</constant></link></para></listitem>
896 <listitem><para><link linkend="DTV-LNA"><constant>DTV_LNA</constant></link></para></listitem> 1065 <listitem><para><link linkend="DTV-LNA"><constant>DTV_LNA</constant></link></para></listitem>
897 </itemizedlist> 1066 </itemizedlist>
1067 <para>In addition, the <link linkend="frontend-stat-properties">DTV QoS statistics</link> are also valid.</para>
898 </section> 1068 </section>
899 <section id="isdbt"> 1069 <section id="isdbt">
900 <title>ISDB-T delivery system</title> 1070 <title>ISDB-T delivery system</title>
@@ -948,6 +1118,7 @@ enum fe_interleaving {
948 <listitem><para><link linkend="DTV-ISDBT-LAYER-SEGMENT-COUNT"><constant>DTV_ISDBT_LAYERC_SEGMENT_COUNT</constant></link></para></listitem> 1118 <listitem><para><link linkend="DTV-ISDBT-LAYER-SEGMENT-COUNT"><constant>DTV_ISDBT_LAYERC_SEGMENT_COUNT</constant></link></para></listitem>
949 <listitem><para><link linkend="DTV-ISDBT-LAYER-TIME-INTERLEAVING"><constant>DTV_ISDBT_LAYERC_TIME_INTERLEAVING</constant></link></para></listitem> 1119 <listitem><para><link linkend="DTV-ISDBT-LAYER-TIME-INTERLEAVING"><constant>DTV_ISDBT_LAYERC_TIME_INTERLEAVING</constant></link></para></listitem>
950 </itemizedlist> 1120 </itemizedlist>
1121 <para>In addition, the <link linkend="frontend-stat-properties">DTV QoS statistics</link> are also valid.</para>
951 </section> 1122 </section>
952 <section id="atsc-params"> 1123 <section id="atsc-params">
953 <title>ATSC delivery system</title> 1124 <title>ATSC delivery system</title>
@@ -961,6 +1132,7 @@ enum fe_interleaving {
961 <listitem><para><link linkend="DTV-MODULATION"><constant>DTV_MODULATION</constant></link></para></listitem> 1132 <listitem><para><link linkend="DTV-MODULATION"><constant>DTV_MODULATION</constant></link></para></listitem>
962 <listitem><para><link linkend="DTV-BANDWIDTH-HZ"><constant>DTV_BANDWIDTH_HZ</constant></link></para></listitem> 1133 <listitem><para><link linkend="DTV-BANDWIDTH-HZ"><constant>DTV_BANDWIDTH_HZ</constant></link></para></listitem>
963 </itemizedlist> 1134 </itemizedlist>
1135 <para>In addition, the <link linkend="frontend-stat-properties">DTV QoS statistics</link> are also valid.</para>
964 </section> 1136 </section>
965 <section id="atscmh-params"> 1137 <section id="atscmh-params">
966 <title>ATSC-MH delivery system</title> 1138 <title>ATSC-MH delivery system</title>
@@ -988,6 +1160,7 @@ enum fe_interleaving {
988 <listitem><para><link linkend="DTV-ATSCMH-SCCC-CODE-MODE-C"><constant>DTV_ATSCMH_SCCC_CODE_MODE_C</constant></link></para></listitem> 1160 <listitem><para><link linkend="DTV-ATSCMH-SCCC-CODE-MODE-C"><constant>DTV_ATSCMH_SCCC_CODE_MODE_C</constant></link></para></listitem>
989 <listitem><para><link linkend="DTV-ATSCMH-SCCC-CODE-MODE-D"><constant>DTV_ATSCMH_SCCC_CODE_MODE_D</constant></link></para></listitem> 1161 <listitem><para><link linkend="DTV-ATSCMH-SCCC-CODE-MODE-D"><constant>DTV_ATSCMH_SCCC_CODE_MODE_D</constant></link></para></listitem>
990 </itemizedlist> 1162 </itemizedlist>
1163 <para>In addition, the <link linkend="frontend-stat-properties">DTV QoS statistics</link> are also valid.</para>
991 </section> 1164 </section>
992 <section id="dtmb-params"> 1165 <section id="dtmb-params">
993 <title>DTMB delivery system</title> 1166 <title>DTMB delivery system</title>
@@ -1007,6 +1180,7 @@ enum fe_interleaving {
1007 <listitem><para><link linkend="DTV-INTERLEAVING"><constant>DTV_INTERLEAVING</constant></link></para></listitem> 1180 <listitem><para><link linkend="DTV-INTERLEAVING"><constant>DTV_INTERLEAVING</constant></link></para></listitem>
1008 <listitem><para><link linkend="DTV-LNA"><constant>DTV_LNA</constant></link></para></listitem> 1181 <listitem><para><link linkend="DTV-LNA"><constant>DTV_LNA</constant></link></para></listitem>
1009 </itemizedlist> 1182 </itemizedlist>
1183 <para>In addition, the <link linkend="frontend-stat-properties">DTV QoS statistics</link> are also valid.</para>
1010 </section> 1184 </section>
1011 </section> 1185 </section>
1012 <section id="frontend-property-cable-systems"> 1186 <section id="frontend-property-cable-systems">
@@ -1028,6 +1202,7 @@ enum fe_interleaving {
1028 <listitem><para><link linkend="DTV-INNER-FEC"><constant>DTV_INNER_FEC</constant></link></para></listitem> 1202 <listitem><para><link linkend="DTV-INNER-FEC"><constant>DTV_INNER_FEC</constant></link></para></listitem>
1029 <listitem><para><link linkend="DTV-LNA"><constant>DTV_LNA</constant></link></para></listitem> 1203 <listitem><para><link linkend="DTV-LNA"><constant>DTV_LNA</constant></link></para></listitem>
1030 </itemizedlist> 1204 </itemizedlist>
1205 <para>In addition, the <link linkend="frontend-stat-properties">DTV QoS statistics</link> are also valid.</para>
1031 </section> 1206 </section>
1032 <section id="dvbc-annex-b-params"> 1207 <section id="dvbc-annex-b-params">
1033 <title>DVB-C Annex B delivery system</title> 1208 <title>DVB-C Annex B delivery system</title>
@@ -1043,6 +1218,7 @@ enum fe_interleaving {
1043 <listitem><para><link linkend="DTV-INVERSION"><constant>DTV_INVERSION</constant></link></para></listitem> 1218 <listitem><para><link linkend="DTV-INVERSION"><constant>DTV_INVERSION</constant></link></para></listitem>
1044 <listitem><para><link linkend="DTV-LNA"><constant>DTV_LNA</constant></link></para></listitem> 1219 <listitem><para><link linkend="DTV-LNA"><constant>DTV_LNA</constant></link></para></listitem>
1045 </itemizedlist> 1220 </itemizedlist>
1221 <para>In addition, the <link linkend="frontend-stat-properties">DTV QoS statistics</link> are also valid.</para>
1046 </section> 1222 </section>
1047 </section> 1223 </section>
1048 <section id="frontend-property-satellital-systems"> 1224 <section id="frontend-property-satellital-systems">
@@ -1062,6 +1238,7 @@ enum fe_interleaving {
1062 <listitem><para><link linkend="DTV-VOLTAGE"><constant>DTV_VOLTAGE</constant></link></para></listitem> 1238 <listitem><para><link linkend="DTV-VOLTAGE"><constant>DTV_VOLTAGE</constant></link></para></listitem>
1063 <listitem><para><link linkend="DTV-TONE"><constant>DTV_TONE</constant></link></para></listitem> 1239 <listitem><para><link linkend="DTV-TONE"><constant>DTV_TONE</constant></link></para></listitem>
1064 </itemizedlist> 1240 </itemizedlist>
1241 <para>In addition, the <link linkend="frontend-stat-properties">DTV QoS statistics</link> are also valid.</para>
1065 <para>Future implementations might add those two missing parameters:</para> 1242 <para>Future implementations might add those two missing parameters:</para>
1066 <itemizedlist mark='opencircle'> 1243 <itemizedlist mark='opencircle'>
1067 <listitem><para><link linkend="DTV-DISEQC-MASTER"><constant>DTV_DISEQC_MASTER</constant></link></para></listitem> 1244 <listitem><para><link linkend="DTV-DISEQC-MASTER"><constant>DTV_DISEQC_MASTER</constant></link></para></listitem>
@@ -1077,6 +1254,7 @@ enum fe_interleaving {
1077 <listitem><para><link linkend="DTV-ROLLOFF"><constant>DTV_ROLLOFF</constant></link></para></listitem> 1254 <listitem><para><link linkend="DTV-ROLLOFF"><constant>DTV_ROLLOFF</constant></link></para></listitem>
1078 <listitem><para><link linkend="DTV-STREAM-ID"><constant>DTV_STREAM_ID</constant></link></para></listitem> 1255 <listitem><para><link linkend="DTV-STREAM-ID"><constant>DTV_STREAM_ID</constant></link></para></listitem>
1079 </itemizedlist> 1256 </itemizedlist>
1257 <para>In addition, the <link linkend="frontend-stat-properties">DTV QoS statistics</link> are also valid.</para>
1080 </section> 1258 </section>
1081 <section id="turbo-params"> 1259 <section id="turbo-params">
1082 <title>Turbo code delivery system</title> 1260 <title>Turbo code delivery system</title>
diff --git a/Documentation/DocBook/media/dvb/frontend.xml b/Documentation/DocBook/media/dvb/frontend.xml
index 426c2526a454..df39ba395df0 100644
--- a/Documentation/DocBook/media/dvb/frontend.xml
+++ b/Documentation/DocBook/media/dvb/frontend.xml
@@ -230,7 +230,7 @@ typedef enum fe_status {
230<entry align="char">The frontend has found a DVB signal</entry> 230<entry align="char">The frontend has found a DVB signal</entry>
231</row><row> 231</row><row>
232<entry align="char">FE_HAS_VITERBI</entry> 232<entry align="char">FE_HAS_VITERBI</entry>
233<entry align="char">The frontend FEC code is stable</entry> 233<entry align="char">The frontend FEC inner coding (Viterbi, LDPC or other inner code) is stable</entry>
234</row><row> 234</row><row>
235<entry align="char">FE_HAS_SYNC</entry> 235<entry align="char">FE_HAS_SYNC</entry>
236<entry align="char">Syncronization bytes was found</entry> 236<entry align="char">Syncronization bytes was found</entry>
diff --git a/Documentation/DocBook/media/v4l/common.xml b/Documentation/DocBook/media/v4l/common.xml
index 73c6847436c9..ae06afbbb3a9 100644
--- a/Documentation/DocBook/media/v4l/common.xml
+++ b/Documentation/DocBook/media/v4l/common.xml
@@ -609,7 +609,7 @@ to zero and the <constant>VIDIOC_G_STD</constant>,
609 <para>Applications can make use of the <xref linkend="input-capabilities" /> and 609 <para>Applications can make use of the <xref linkend="input-capabilities" /> and
610<xref linkend="output-capabilities"/> flags to determine whether the video standard ioctls 610<xref linkend="output-capabilities"/> flags to determine whether the video standard ioctls
611are available for the device.</para> 611are available for the device.</para>
612&ENOTTY;. 612
613 <para>See <xref linkend="buffer" /> for a rationale. Probably 613 <para>See <xref linkend="buffer" /> for a rationale. Probably
614even USB cameras follow some well known video standard. It might have 614even USB cameras follow some well known video standard. It might have
615been better to explicitly indicate elsewhere if a device cannot live 615been better to explicitly indicate elsewhere if a device cannot live
diff --git a/Documentation/DocBook/media/v4l/compat.xml b/Documentation/DocBook/media/v4l/compat.xml
index 3dd9e78815d1..104a1a2b8849 100644
--- a/Documentation/DocBook/media/v4l/compat.xml
+++ b/Documentation/DocBook/media/v4l/compat.xml
@@ -2477,6 +2477,22 @@ that used it. It was originally scheduled for removal in 2.6.35.
2477 </orderedlist> 2477 </orderedlist>
2478 </section> 2478 </section>
2479 2479
2480 <section>
2481 <title>V4L2 in Linux 3.9</title>
2482 <orderedlist>
2483 <listitem>
2484 <para>Added timestamp types to
2485 <structfield>flags</structfield> field in
2486 <structname>v4l2_buffer</structname>. See <xref
2487 linkend="buffer-flags" />.</para>
2488 </listitem>
2489 <listitem>
2490 <para>Added <constant>V4L2_EVENT_CTRL_CH_RANGE</constant> control event
2491 changes flag. See <xref linkend="changes-flags"/>.</para>
2492 </listitem>
2493 </orderedlist>
2494 </section>
2495
2480 <section id="other"> 2496 <section id="other">
2481 <title>Relation of V4L2 to other Linux multimedia APIs</title> 2497 <title>Relation of V4L2 to other Linux multimedia APIs</title>
2482 2498
diff --git a/Documentation/DocBook/media/v4l/controls.xml b/Documentation/DocBook/media/v4l/controls.xml
index 7fe5be1d3bbb..9e8f85498678 100644
--- a/Documentation/DocBook/media/v4l/controls.xml
+++ b/Documentation/DocBook/media/v4l/controls.xml
@@ -203,29 +203,6 @@ and should not be used in new drivers and applications.</entry>
203 <entry>boolean</entry> 203 <entry>boolean</entry>
204 <entry>Mirror the picture vertically.</entry> 204 <entry>Mirror the picture vertically.</entry>
205 </row> 205 </row>
206 <row>
207 <entry><constant>V4L2_CID_HCENTER_DEPRECATED</constant> (formerly <constant>V4L2_CID_HCENTER</constant>)</entry>
208 <entry>integer</entry>
209 <entry>Horizontal image centering. This control is
210deprecated. New drivers and applications should use the <link
211linkend="camera-controls">Camera class controls</link>
212<constant>V4L2_CID_PAN_ABSOLUTE</constant>,
213<constant>V4L2_CID_PAN_RELATIVE</constant> and
214<constant>V4L2_CID_PAN_RESET</constant> instead.</entry>
215 </row>
216 <row>
217 <entry><constant>V4L2_CID_VCENTER_DEPRECATED</constant>
218 (formerly <constant>V4L2_CID_VCENTER</constant>)</entry>
219 <entry>integer</entry>
220 <entry>Vertical image centering. Centering is intended to
221<emphasis>physically</emphasis> adjust cameras. For image cropping see
222<xref linkend="crop" />, for clipping <xref linkend="overlay" />. This
223control is deprecated. New drivers and applications should use the
224<link linkend="camera-controls">Camera class controls</link>
225<constant>V4L2_CID_TILT_ABSOLUTE</constant>,
226<constant>V4L2_CID_TILT_RELATIVE</constant> and
227<constant>V4L2_CID_TILT_RESET</constant> instead.</entry>
228 </row>
229 <row id="v4l2-power-line-frequency"> 206 <row id="v4l2-power-line-frequency">
230 <entry><constant>V4L2_CID_POWER_LINE_FREQUENCY</constant></entry> 207 <entry><constant>V4L2_CID_POWER_LINE_FREQUENCY</constant></entry>
231 <entry>enum</entry> 208 <entry>enum</entry>
diff --git a/Documentation/DocBook/media/v4l/io.xml b/Documentation/DocBook/media/v4l/io.xml
index 388a34032653..e6c58559ca6b 100644
--- a/Documentation/DocBook/media/v4l/io.xml
+++ b/Documentation/DocBook/media/v4l/io.xml
@@ -477,7 +477,7 @@ rest should be evident.</para>
477 477
478 <note> 478 <note>
479 <title>Experimental</title> 479 <title>Experimental</title>
480 <para>This is an <link linkend="experimental"> experimental </link> 480 <para>This is an <link linkend="experimental">experimental</link>
481 interface and may change in the future.</para> 481 interface and may change in the future.</para>
482 </note> 482 </note>
483 483
@@ -488,7 +488,7 @@ DMA buffer from userspace using a file descriptor previously exported for a
488different or the same device (known as the importer role), or both. This 488different or the same device (known as the importer role), or both. This
489section describes the DMABUF importer role API in V4L2.</para> 489section describes the DMABUF importer role API in V4L2.</para>
490 490
491 <para>Refer to <link linked="vidioc-expbuf"> DMABUF exporting </link> for 491 <para>Refer to <link linkend="vidioc-expbuf">DMABUF exporting</link> for
492details about exporting V4L2 buffers as DMABUF file descriptors.</para> 492details about exporting V4L2 buffers as DMABUF file descriptors.</para>
493 493
494<para>Input and output devices support the streaming I/O method when the 494<para>Input and output devices support the streaming I/O method when the
@@ -741,17 +741,19 @@ applications when an output stream.</entry>
741 <entry>struct timeval</entry> 741 <entry>struct timeval</entry>
742 <entry><structfield>timestamp</structfield></entry> 742 <entry><structfield>timestamp</structfield></entry>
743 <entry></entry> 743 <entry></entry>
744 <entry><para>For input streams this is the 744 <entry><para>For input streams this is time when the first data
745system time (as returned by the <function>gettimeofday()</function> 745 byte was captured, as returned by the
746function) when the first data byte was captured. For output streams 746 <function>clock_gettime()</function> function for the relevant
747the data will not be displayed before this time, secondary to the 747 clock id; see <constant>V4L2_BUF_FLAG_TIMESTAMP_*</constant> in
748nominal frame rate determined by the current video standard in 748 <xref linkend="buffer-flags" />. For output streams the data
749enqueued order. Applications can for example zero this field to 749 will not be displayed before this time, secondary to the nominal
750display frames as soon as possible. The driver stores the time at 750 frame rate determined by the current video standard in enqueued
751which the first data byte was actually sent out in the 751 order. Applications can for example zero this field to display
752<structfield>timestamp</structfield> field. This permits 752 frames as soon as possible. The driver stores the time at which
753applications to monitor the drift between the video and system 753 the first data byte was actually sent out in the
754clock.</para></entry> 754 <structfield>timestamp</structfield> field. This permits
755 applications to monitor the drift between the video and system
756 clock.</para></entry>
755 </row> 757 </row>
756 <row> 758 <row>
757 <entry>&v4l2-timecode;</entry> 759 <entry>&v4l2-timecode;</entry>
@@ -903,7 +905,7 @@ should set this to 0.</entry>
903 </row> 905 </row>
904 <row> 906 <row>
905 <entry></entry> 907 <entry></entry>
906 <entry>__unsigned long</entry> 908 <entry>unsigned long</entry>
907 <entry><structfield>userptr</structfield></entry> 909 <entry><structfield>userptr</structfield></entry>
908 <entry>When the memory type in the containing &v4l2-buffer; is 910 <entry>When the memory type in the containing &v4l2-buffer; is
909 <constant>V4L2_MEMORY_USERPTR</constant>, this is a userspace 911 <constant>V4L2_MEMORY_USERPTR</constant>, this is a userspace
@@ -1114,6 +1116,35 @@ Typically applications shall use this flag for output buffers if the data
1114in this buffer has not been created by the CPU but by some DMA-capable unit, 1116in this buffer has not been created by the CPU but by some DMA-capable unit,
1115in which case caches have not been used.</entry> 1117in which case caches have not been used.</entry>
1116 </row> 1118 </row>
1119 <row>
1120 <entry><constant>V4L2_BUF_FLAG_TIMESTAMP_MASK</constant></entry>
1121 <entry>0xe000</entry>
1122 <entry>Mask for timestamp types below. To test the
1123 timestamp type, mask out bits not belonging to timestamp
1124 type by performing a logical and operation with buffer
1125 flags and timestamp mask.</entry>
1126 </row>
1127 <row>
1128 <entry><constant>V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN</constant></entry>
1129 <entry>0x0000</entry>
1130 <entry>Unknown timestamp type. This type is used by
1131 drivers before Linux 3.9 and may be either monotonic (see
1132 below) or realtime (wall clock). Monotonic clock has been
1133 favoured in embedded systems whereas most of the drivers
1134 use the realtime clock. Either kinds of timestamps are
1135 available in user space via
1136 <function>clock_gettime(2)</function> using clock IDs
1137 <constant>CLOCK_MONOTONIC</constant> and
1138 <constant>CLOCK_REALTIME</constant>, respectively.</entry>
1139 </row>
1140 <row>
1141 <entry><constant>V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC</constant></entry>
1142 <entry>0x2000</entry>
1143 <entry>The buffer timestamp has been taken from the
1144 <constant>CLOCK_MONOTONIC</constant> clock. To access the
1145 same clock outside V4L2, use
1146 <function>clock_gettime(2)</function> .</entry>
1147 </row>
1117 </tbody> 1148 </tbody>
1118 </tgroup> 1149 </tgroup>
1119 </table> 1150 </table>
diff --git a/Documentation/DocBook/media/v4l/pixfmt-nv12m.xml b/Documentation/DocBook/media/v4l/pixfmt-nv12m.xml
index a990b34d911a..f3a3d459fcdf 100644
--- a/Documentation/DocBook/media/v4l/pixfmt-nv12m.xml
+++ b/Documentation/DocBook/media/v4l/pixfmt-nv12m.xml
@@ -6,7 +6,7 @@
6 <refnamediv> 6 <refnamediv>
7 <refname id="V4L2-PIX-FMT-NV12M"><constant>V4L2_PIX_FMT_NV12M</constant></refname> 7 <refname id="V4L2-PIX-FMT-NV12M"><constant>V4L2_PIX_FMT_NV12M</constant></refname>
8 <refname id="V4L2-PIX-FMT-NV21M"><constant>V4L2_PIX_FMT_NV21M</constant></refname> 8 <refname id="V4L2-PIX-FMT-NV21M"><constant>V4L2_PIX_FMT_NV21M</constant></refname>
9 <refname id="V4L2-PIX-FMT-NV12MT_16X16"><constant>V4L2_PIX_FMT_NV12MT_16X16</constant></refname> 9 <refname id="V4L2-PIX-FMT-NV12MT-16X16"><constant>V4L2_PIX_FMT_NV12MT_16X16</constant></refname>
10 <refpurpose>Variation of <constant>V4L2_PIX_FMT_NV12</constant> and <constant>V4L2_PIX_FMT_NV21</constant> with planes 10 <refpurpose>Variation of <constant>V4L2_PIX_FMT_NV12</constant> and <constant>V4L2_PIX_FMT_NV21</constant> with planes
11 non contiguous in memory. </refpurpose> 11 non contiguous in memory. </refpurpose>
12 </refnamediv> 12 </refnamediv>
diff --git a/Documentation/DocBook/media/v4l/pixfmt-srggb10alaw8.xml b/Documentation/DocBook/media/v4l/pixfmt-srggb10alaw8.xml
new file mode 100644
index 000000000000..29acc2098cc2
--- /dev/null
+++ b/Documentation/DocBook/media/v4l/pixfmt-srggb10alaw8.xml
@@ -0,0 +1,34 @@
1 <refentry>
2 <refmeta>
3 <refentrytitle>
4 V4L2_PIX_FMT_SBGGR10ALAW8 ('aBA8'),
5 V4L2_PIX_FMT_SGBRG10ALAW8 ('aGA8'),
6 V4L2_PIX_FMT_SGRBG10ALAW8 ('agA8'),
7 V4L2_PIX_FMT_SRGGB10ALAW8 ('aRA8'),
8 </refentrytitle>
9 &manvol;
10 </refmeta>
11 <refnamediv>
12 <refname id="V4L2-PIX-FMT-SBGGR10ALAW8">
13 <constant>V4L2_PIX_FMT_SBGGR10ALAW8</constant>
14 </refname>
15 <refname id="V4L2-PIX-FMT-SGBRG10ALAW8">
16 <constant>V4L2_PIX_FMT_SGBRG10ALAW8</constant>
17 </refname>
18 <refname id="V4L2-PIX-FMT-SGRBG10ALAW8">
19 <constant>V4L2_PIX_FMT_SGRBG10ALAW8</constant>
20 </refname>
21 <refname id="V4L2-PIX-FMT-SRGGB10ALAW8">
22 <constant>V4L2_PIX_FMT_SRGGB10ALAW8</constant>
23 </refname>
24 <refpurpose>10-bit Bayer formats compressed to 8 bits</refpurpose>
25 </refnamediv>
26 <refsect1>
27 <title>Description</title>
28 <para>The following four pixel formats are raw sRGB / Bayer
29 formats with 10 bits per color compressed to 8 bits each,
30 using the A-LAW algorithm. Each color component consumes 8
31 bits of memory. In other respects this format is similar to
32 <xref linkend="V4L2-PIX-FMT-SRGGB8"></xref>.</para>
33 </refsect1>
34 </refentry>
diff --git a/Documentation/DocBook/media/v4l/pixfmt-uv8.xml b/Documentation/DocBook/media/v4l/pixfmt-uv8.xml
new file mode 100644
index 000000000000..c507c1f73cd0
--- /dev/null
+++ b/Documentation/DocBook/media/v4l/pixfmt-uv8.xml
@@ -0,0 +1,62 @@
1 <refentry id="V4L2-PIX-FMT-UV8">
2 <refmeta>
3 <refentrytitle>V4L2_PIX_FMT_UV8 ('UV8')</refentrytitle>
4 &manvol;
5 </refmeta>
6 <refnamediv>
7 <refname><constant>V4L2_PIX_FMT_UV8</constant></refname>
8 <refpurpose>UV plane interleaved</refpurpose>
9 </refnamediv>
10 <refsect1>
11 <title>Description</title>
12 <para>In this format there is no Y plane, Only CbCr plane. ie
13 (UV interleaved)</para>
14 <example>
15 <title>
16 <constant>V4L2_PIX_FMT_UV8</constant>
17 pixel image
18 </title>
19
20 <formalpara>
21 <title>Byte Order.</title>
22 <para>Each cell is one byte.
23 <informaltable frame="none">
24 <tgroup cols="5" align="center">
25 <colspec align="left" colwidth="2*" />
26 <tbody valign="top">
27 <row>
28 <entry>start&nbsp;+&nbsp;0:</entry>
29 <entry>Cb<subscript>00</subscript></entry>
30 <entry>Cr<subscript>00</subscript></entry>
31 <entry>Cb<subscript>01</subscript></entry>
32 <entry>Cr<subscript>01</subscript></entry>
33 </row>
34 <row>
35 <entry>start&nbsp;+&nbsp;4:</entry>
36 <entry>Cb<subscript>10</subscript></entry>
37 <entry>Cr<subscript>10</subscript></entry>
38 <entry>Cb<subscript>11</subscript></entry>
39 <entry>Cr<subscript>11</subscript></entry>
40 </row>
41 <row>
42 <entry>start&nbsp;+&nbsp;8:</entry>
43 <entry>Cb<subscript>20</subscript></entry>
44 <entry>Cr<subscript>20</subscript></entry>
45 <entry>Cb<subscript>21</subscript></entry>
46 <entry>Cr<subscript>21</subscript></entry>
47 </row>
48 <row>
49 <entry>start&nbsp;+&nbsp;12:</entry>
50 <entry>Cb<subscript>30</subscript></entry>
51 <entry>Cr<subscript>30</subscript></entry>
52 <entry>Cb<subscript>31</subscript></entry>
53 <entry>Cr<subscript>31</subscript></entry>
54 </row>
55 </tbody>
56 </tgroup>
57 </informaltable>
58 </para>
59 </formalpara>
60 </example>
61 </refsect1>
62 </refentry>
diff --git a/Documentation/DocBook/media/v4l/pixfmt.xml b/Documentation/DocBook/media/v4l/pixfmt.xml
index bf94f417592c..99b8d2ad6e4f 100644
--- a/Documentation/DocBook/media/v4l/pixfmt.xml
+++ b/Documentation/DocBook/media/v4l/pixfmt.xml
@@ -673,6 +673,7 @@ access the palette, this must be done with ioctls of the Linux framebuffer API.<
673 &sub-srggb8; 673 &sub-srggb8;
674 &sub-sbggr16; 674 &sub-sbggr16;
675 &sub-srggb10; 675 &sub-srggb10;
676 &sub-srggb10alaw8;
676 &sub-srggb10dpcm8; 677 &sub-srggb10dpcm8;
677 &sub-srggb12; 678 &sub-srggb12;
678 </section> 679 </section>
@@ -701,6 +702,7 @@ information.</para>
701 &sub-y12; 702 &sub-y12;
702 &sub-y10b; 703 &sub-y10b;
703 &sub-y16; 704 &sub-y16;
705 &sub-uv8;
704 &sub-yuyv; 706 &sub-yuyv;
705 &sub-uyvy; 707 &sub-uyvy;
706 &sub-yvyu; 708 &sub-yvyu;
diff --git a/Documentation/DocBook/media/v4l/subdev-formats.xml b/Documentation/DocBook/media/v4l/subdev-formats.xml
index a0a936455fae..cc51372ed5e0 100644
--- a/Documentation/DocBook/media/v4l/subdev-formats.xml
+++ b/Documentation/DocBook/media/v4l/subdev-formats.xml
@@ -353,9 +353,9 @@
353 <listitem><para>The number of bits per pixel component. All components are 353 <listitem><para>The number of bits per pixel component. All components are
354 transferred on the same number of bits. Common values are 8, 10 and 12.</para> 354 transferred on the same number of bits. Common values are 8, 10 and 12.</para>
355 </listitem> 355 </listitem>
356 <listitem><para>If the pixel components are DPCM-compressed, a mention of the 356 <listitem><para>The compression (optional). If the pixel components are
357 DPCM compression and the number of bits per compressed pixel component.</para> 357 ALAW- or DPCM-compressed, a mention of the compression scheme and the
358 </listitem> 358 number of bits per compressed pixel component.</para></listitem>
359 <listitem><para>The number of bus samples per pixel. Pixels that are wider than 359 <listitem><para>The number of bus samples per pixel. Pixels that are wider than
360 the bus width must be transferred in multiple samples. Common values are 360 the bus width must be transferred in multiple samples. Common values are
361 1 and 2.</para></listitem> 361 1 and 2.</para></listitem>
@@ -504,6 +504,74 @@
504 <entry>r<subscript>1</subscript></entry> 504 <entry>r<subscript>1</subscript></entry>
505 <entry>r<subscript>0</subscript></entry> 505 <entry>r<subscript>0</subscript></entry>
506 </row> 506 </row>
507 <row id="V4L2-MBUS-FMT-SBGGR10-ALAW8-1X8">
508 <entry>V4L2_MBUS_FMT_SBGGR10_ALAW8_1X8</entry>
509 <entry>0x3015</entry>
510 <entry></entry>
511 <entry>-</entry>
512 <entry>-</entry>
513 <entry>-</entry>
514 <entry>-</entry>
515 <entry>b<subscript>7</subscript></entry>
516 <entry>b<subscript>6</subscript></entry>
517 <entry>b<subscript>5</subscript></entry>
518 <entry>b<subscript>4</subscript></entry>
519 <entry>b<subscript>3</subscript></entry>
520 <entry>b<subscript>2</subscript></entry>
521 <entry>b<subscript>1</subscript></entry>
522 <entry>b<subscript>0</subscript></entry>
523 </row>
524 <row id="V4L2-MBUS-FMT-SGBRG10-ALAW8-1X8">
525 <entry>V4L2_MBUS_FMT_SGBRG10_ALAW8_1X8</entry>
526 <entry>0x3016</entry>
527 <entry></entry>
528 <entry>-</entry>
529 <entry>-</entry>
530 <entry>-</entry>
531 <entry>-</entry>
532 <entry>g<subscript>7</subscript></entry>
533 <entry>g<subscript>6</subscript></entry>
534 <entry>g<subscript>5</subscript></entry>
535 <entry>g<subscript>4</subscript></entry>
536 <entry>g<subscript>3</subscript></entry>
537 <entry>g<subscript>2</subscript></entry>
538 <entry>g<subscript>1</subscript></entry>
539 <entry>g<subscript>0</subscript></entry>
540 </row>
541 <row id="V4L2-MBUS-FMT-SGRBG10-ALAW8-1X8">
542 <entry>V4L2_MBUS_FMT_SGRBG10_ALAW8_1X8</entry>
543 <entry>0x3017</entry>
544 <entry></entry>
545 <entry>-</entry>
546 <entry>-</entry>
547 <entry>-</entry>
548 <entry>-</entry>
549 <entry>g<subscript>7</subscript></entry>
550 <entry>g<subscript>6</subscript></entry>
551 <entry>g<subscript>5</subscript></entry>
552 <entry>g<subscript>4</subscript></entry>
553 <entry>g<subscript>3</subscript></entry>
554 <entry>g<subscript>2</subscript></entry>
555 <entry>g<subscript>1</subscript></entry>
556 <entry>g<subscript>0</subscript></entry>
557 </row>
558 <row id="V4L2-MBUS-FMT-SRGGB10-ALAW8-1X8">
559 <entry>V4L2_MBUS_FMT_SRGGB10_ALAW8_1X8</entry>
560 <entry>0x3018</entry>
561 <entry></entry>
562 <entry>-</entry>
563 <entry>-</entry>
564 <entry>-</entry>
565 <entry>-</entry>
566 <entry>r<subscript>7</subscript></entry>
567 <entry>r<subscript>6</subscript></entry>
568 <entry>r<subscript>5</subscript></entry>
569 <entry>r<subscript>4</subscript></entry>
570 <entry>r<subscript>3</subscript></entry>
571 <entry>r<subscript>2</subscript></entry>
572 <entry>r<subscript>1</subscript></entry>
573 <entry>r<subscript>0</subscript></entry>
574 </row>
507 <row id="V4L2-MBUS-FMT-SBGGR10-DPCM8-1X8"> 575 <row id="V4L2-MBUS-FMT-SBGGR10-DPCM8-1X8">
508 <entry>V4L2_MBUS_FMT_SBGGR10_DPCM8_1X8</entry> 576 <entry>V4L2_MBUS_FMT_SBGGR10_DPCM8_1X8</entry>
509 <entry>0x300b</entry> 577 <entry>0x300b</entry>
@@ -853,10 +921,16 @@
853 <title>Packed YUV Formats</title> 921 <title>Packed YUV Formats</title>
854 922
855 <para>Those data formats transfer pixel data as (possibly downsampled) Y, U 923 <para>Those data formats transfer pixel data as (possibly downsampled) Y, U
856 and V components. The format code is made of the following information. 924 and V components. Some formats include dummy bits in some of their samples
925 and are collectively referred to as "YDYC" (Y-Dummy-Y-Chroma) formats.
926 One cannot rely on the values of these dummy bits as those are undefined.
927 </para>
928 <para>The format code is made of the following information.
857 <itemizedlist> 929 <itemizedlist>
858 <listitem><para>The Y, U and V components order code, as transferred on the 930 <listitem><para>The Y, U and V components order code, as transferred on the
859 bus. Possible values are YUYV, UYVY, YVYU and VYUY.</para></listitem> 931 bus. Possible values are YUYV, UYVY, YVYU and VYUY for formats with no
932 dummy bit, and YDYUYDYV, YDYVYDYU, YUYDYVYD and YVYDYUYD for YDYC formats.
933 </para></listitem>
860 <listitem><para>The number of bits per pixel component. All components are 934 <listitem><para>The number of bits per pixel component. All components are
861 transferred on the same number of bits. Common values are 8, 10 and 12.</para> 935 transferred on the same number of bits. Common values are 8, 10 and 12.</para>
862 </listitem> 936 </listitem>
@@ -877,7 +951,21 @@
877 U, Y, V, Y order will be named <constant>V4L2_MBUS_FMT_UYVY8_2X8</constant>. 951 U, Y, V, Y order will be named <constant>V4L2_MBUS_FMT_UYVY8_2X8</constant>.
878 </para> 952 </para>
879 953
880 <para>The following table lisst existing packet YUV formats.</para> 954 <para><xref linkend="v4l2-mbus-pixelcode-yuv8"/> list existing packet YUV
955 formats and describes the organization of each pixel data in each sample.
956 When a format pattern is split across multiple samples each of the samples
957 in the pattern is described.</para>
958
959 <para>The role of each bit transferred over the bus is identified by one
960 of the following codes.</para>
961
962 <itemizedlist>
963 <listitem><para>y<subscript>x</subscript> for luma component bit number x</para></listitem>
964 <listitem><para>u<subscript>x</subscript> for blue chroma component bit number x</para></listitem>
965 <listitem><para>v<subscript>x</subscript> for red chroma component bit number x</para></listitem>
966 <listitem><para>- for non-available bits (for positions higher than the bus width)</para></listitem>
967 <listitem><para>d for dummy bits</para></listitem>
968 </itemizedlist>
881 969
882 <table pgwide="0" frame="none" id="v4l2-mbus-pixelcode-yuv8"> 970 <table pgwide="0" frame="none" id="v4l2-mbus-pixelcode-yuv8">
883 <title>YUV Formats</title> 971 <title>YUV Formats</title>
@@ -885,27 +973,37 @@
885 <colspec colname="id" align="left" /> 973 <colspec colname="id" align="left" />
886 <colspec colname="code" align="center"/> 974 <colspec colname="code" align="center"/>
887 <colspec colname="bit" /> 975 <colspec colname="bit" />
888 <colspec colnum="4" colname="b19" align="center" /> 976 <colspec colnum="4" colname="b29" align="center" />
889 <colspec colnum="5" colname="b18" align="center" /> 977 <colspec colnum="5" colname="b28" align="center" />
890 <colspec colnum="6" colname="b17" align="center" /> 978 <colspec colnum="6" colname="b27" align="center" />
891 <colspec colnum="7" colname="b16" align="center" /> 979 <colspec colnum="7" colname="b26" align="center" />
892 <colspec colnum="8" colname="b15" align="center" /> 980 <colspec colnum="8" colname="b25" align="center" />
893 <colspec colnum="9" colname="b14" align="center" /> 981 <colspec colnum="9" colname="b24" align="center" />
894 <colspec colnum="10" colname="b13" align="center" /> 982 <colspec colnum="10" colname="b23" align="center" />
895 <colspec colnum="11" colname="b12" align="center" /> 983 <colspec colnum="11" colname="b22" align="center" />
896 <colspec colnum="12" colname="b11" align="center" /> 984 <colspec colnum="12" colname="b21" align="center" />
897 <colspec colnum="13" colname="b10" align="center" /> 985 <colspec colnum="13" colname="b20" align="center" />
898 <colspec colnum="14" colname="b09" align="center" /> 986 <colspec colnum="14" colname="b19" align="center" />
899 <colspec colnum="15" colname="b08" align="center" /> 987 <colspec colnum="15" colname="b18" align="center" />
900 <colspec colnum="16" colname="b07" align="center" /> 988 <colspec colnum="16" colname="b17" align="center" />
901 <colspec colnum="17" colname="b06" align="center" /> 989 <colspec colnum="17" colname="b16" align="center" />
902 <colspec colnum="18" colname="b05" align="center" /> 990 <colspec colnum="18" colname="b15" align="center" />
903 <colspec colnum="19" colname="b04" align="center" /> 991 <colspec colnum="19" colname="b14" align="center" />
904 <colspec colnum="20" colname="b03" align="center" /> 992 <colspec colnum="20" colname="b13" align="center" />
905 <colspec colnum="21" colname="b02" align="center" /> 993 <colspec colnum="21" colname="b12" align="center" />
906 <colspec colnum="22" colname="b01" align="center" /> 994 <colspec colnum="22" colname="b11" align="center" />
907 <colspec colnum="23" colname="b00" align="center" /> 995 <colspec colnum="23" colname="b10" align="center" />
908 <spanspec namest="b19" nameend="b00" spanname="b0" /> 996 <colspec colnum="24" colname="b09" align="center" />
997 <colspec colnum="25" colname="b08" align="center" />
998 <colspec colnum="26" colname="b07" align="center" />
999 <colspec colnum="27" colname="b06" align="center" />
1000 <colspec colnum="28" colname="b05" align="center" />
1001 <colspec colnum="29" colname="b04" align="center" />
1002 <colspec colnum="30" colname="b03" align="center" />
1003 <colspec colnum="31" colname="b02" align="center" />
1004 <colspec colnum="32" colname="b01" align="center" />
1005 <colspec colnum="33" colname="b00" align="center" />
1006 <spanspec namest="b29" nameend="b00" spanname="b0" />
909 <thead> 1007 <thead>
910 <row> 1008 <row>
911 <entry>Identifier</entry> 1009 <entry>Identifier</entry>
@@ -917,6 +1015,16 @@
917 <entry></entry> 1015 <entry></entry>
918 <entry></entry> 1016 <entry></entry>
919 <entry>Bit</entry> 1017 <entry>Bit</entry>
1018 <entry>29</entry>
1019 <entry>28</entry>
1020 <entry>27</entry>
1021 <entry>26</entry>
1022 <entry>25</entry>
1023 <entry>24</entry>
1024 <entry>23</entry>
1025 <entry>22</entry>
1026 <entry>21</entry>
1027 <entry>10</entry>
920 <entry>19</entry> 1028 <entry>19</entry>
921 <entry>18</entry> 1029 <entry>18</entry>
922 <entry>17</entry> 1030 <entry>17</entry>
@@ -944,16 +1052,8 @@
944 <entry>V4L2_MBUS_FMT_Y8_1X8</entry> 1052 <entry>V4L2_MBUS_FMT_Y8_1X8</entry>
945 <entry>0x2001</entry> 1053 <entry>0x2001</entry>
946 <entry></entry> 1054 <entry></entry>
947 <entry>-</entry> 1055 &dash-ent-10;
948 <entry>-</entry> 1056 &dash-ent-10;
949 <entry>-</entry>
950 <entry>-</entry>
951 <entry>-</entry>
952 <entry>-</entry>
953 <entry>-</entry>
954 <entry>-</entry>
955 <entry>-</entry>
956 <entry>-</entry>
957 <entry>-</entry> 1057 <entry>-</entry>
958 <entry>-</entry> 1058 <entry>-</entry>
959 <entry>y<subscript>7</subscript></entry> 1059 <entry>y<subscript>7</subscript></entry>
@@ -965,9 +1065,9 @@
965 <entry>y<subscript>1</subscript></entry> 1065 <entry>y<subscript>1</subscript></entry>
966 <entry>y<subscript>0</subscript></entry> 1066 <entry>y<subscript>0</subscript></entry>
967 </row> 1067 </row>
968 <row id="V4L2-MBUS-FMT-UYVY8-1_5X8"> 1068 <row id="V4L2-MBUS-FMT-UV8-1X8">
969 <entry>V4L2_MBUS_FMT_UYVY8_1_5X8</entry> 1069 <entry>V4L2_MBUS_FMT_UV8_1X8</entry>
970 <entry>0x2002</entry> 1070 <entry>0x2015</entry>
971 <entry></entry> 1071 <entry></entry>
972 <entry>-</entry> 1072 <entry>-</entry>
973 <entry>-</entry> 1073 <entry>-</entry>
@@ -1006,6 +1106,40 @@
1006 <entry>-</entry> 1106 <entry>-</entry>
1007 <entry>-</entry> 1107 <entry>-</entry>
1008 <entry>-</entry> 1108 <entry>-</entry>
1109 <entry>v<subscript>7</subscript></entry>
1110 <entry>v<subscript>6</subscript></entry>
1111 <entry>v<subscript>5</subscript></entry>
1112 <entry>v<subscript>4</subscript></entry>
1113 <entry>v<subscript>3</subscript></entry>
1114 <entry>v<subscript>2</subscript></entry>
1115 <entry>v<subscript>1</subscript></entry>
1116 <entry>v<subscript>0</subscript></entry>
1117 </row>
1118 <row id="V4L2-MBUS-FMT-UYVY8-1_5X8">
1119 <entry>V4L2_MBUS_FMT_UYVY8_1_5X8</entry>
1120 <entry>0x2002</entry>
1121 <entry></entry>
1122 &dash-ent-10;
1123 &dash-ent-10;
1124 <entry>-</entry>
1125 <entry>-</entry>
1126 <entry>u<subscript>7</subscript></entry>
1127 <entry>u<subscript>6</subscript></entry>
1128 <entry>u<subscript>5</subscript></entry>
1129 <entry>u<subscript>4</subscript></entry>
1130 <entry>u<subscript>3</subscript></entry>
1131 <entry>u<subscript>2</subscript></entry>
1132 <entry>u<subscript>1</subscript></entry>
1133 <entry>u<subscript>0</subscript></entry>
1134 </row>
1135 <row>
1136 <entry></entry>
1137 <entry></entry>
1138 <entry></entry>
1139 &dash-ent-10;
1140 &dash-ent-10;
1141 <entry>-</entry>
1142 <entry>-</entry>
1009 <entry>y<subscript>7</subscript></entry> 1143 <entry>y<subscript>7</subscript></entry>
1010 <entry>y<subscript>6</subscript></entry> 1144 <entry>y<subscript>6</subscript></entry>
1011 <entry>y<subscript>5</subscript></entry> 1145 <entry>y<subscript>5</subscript></entry>
@@ -1019,16 +1153,8 @@
1019 <entry></entry> 1153 <entry></entry>
1020 <entry></entry> 1154 <entry></entry>
1021 <entry></entry> 1155 <entry></entry>
1022 <entry>-</entry> 1156 &dash-ent-10;
1023 <entry>-</entry> 1157 &dash-ent-10;
1024 <entry>-</entry>
1025 <entry>-</entry>
1026 <entry>-</entry>
1027 <entry>-</entry>
1028 <entry>-</entry>
1029 <entry>-</entry>
1030 <entry>-</entry>
1031 <entry>-</entry>
1032 <entry>-</entry> 1158 <entry>-</entry>
1033 <entry>-</entry> 1159 <entry>-</entry>
1034 <entry>y<subscript>7</subscript></entry> 1160 <entry>y<subscript>7</subscript></entry>
@@ -1044,16 +1170,8 @@
1044 <entry></entry> 1170 <entry></entry>
1045 <entry></entry> 1171 <entry></entry>
1046 <entry></entry> 1172 <entry></entry>
1047 <entry>-</entry> 1173 &dash-ent-10;
1048 <entry>-</entry> 1174 &dash-ent-10;
1049 <entry>-</entry>
1050 <entry>-</entry>
1051 <entry>-</entry>
1052 <entry>-</entry>
1053 <entry>-</entry>
1054 <entry>-</entry>
1055 <entry>-</entry>
1056 <entry>-</entry>
1057 <entry>-</entry> 1175 <entry>-</entry>
1058 <entry>-</entry> 1176 <entry>-</entry>
1059 <entry>v<subscript>7</subscript></entry> 1177 <entry>v<subscript>7</subscript></entry>
@@ -1069,16 +1187,8 @@
1069 <entry></entry> 1187 <entry></entry>
1070 <entry></entry> 1188 <entry></entry>
1071 <entry></entry> 1189 <entry></entry>
1072 <entry>-</entry> 1190 &dash-ent-10;
1073 <entry>-</entry> 1191 &dash-ent-10;
1074 <entry>-</entry>
1075 <entry>-</entry>
1076 <entry>-</entry>
1077 <entry>-</entry>
1078 <entry>-</entry>
1079 <entry>-</entry>
1080 <entry>-</entry>
1081 <entry>-</entry>
1082 <entry>-</entry> 1192 <entry>-</entry>
1083 <entry>-</entry> 1193 <entry>-</entry>
1084 <entry>y<subscript>7</subscript></entry> 1194 <entry>y<subscript>7</subscript></entry>
@@ -1094,16 +1204,8 @@
1094 <entry></entry> 1204 <entry></entry>
1095 <entry></entry> 1205 <entry></entry>
1096 <entry></entry> 1206 <entry></entry>
1097 <entry>-</entry> 1207 &dash-ent-10;
1098 <entry>-</entry> 1208 &dash-ent-10;
1099 <entry>-</entry>
1100 <entry>-</entry>
1101 <entry>-</entry>
1102 <entry>-</entry>
1103 <entry>-</entry>
1104 <entry>-</entry>
1105 <entry>-</entry>
1106 <entry>-</entry>
1107 <entry>-</entry> 1209 <entry>-</entry>
1108 <entry>-</entry> 1210 <entry>-</entry>
1109 <entry>y<subscript>7</subscript></entry> 1211 <entry>y<subscript>7</subscript></entry>
@@ -1119,16 +1221,8 @@
1119 <entry>V4L2_MBUS_FMT_VYUY8_1_5X8</entry> 1221 <entry>V4L2_MBUS_FMT_VYUY8_1_5X8</entry>
1120 <entry>0x2003</entry> 1222 <entry>0x2003</entry>
1121 <entry></entry> 1223 <entry></entry>
1122 <entry>-</entry> 1224 &dash-ent-10;
1123 <entry>-</entry> 1225 &dash-ent-10;
1124 <entry>-</entry>
1125 <entry>-</entry>
1126 <entry>-</entry>
1127 <entry>-</entry>
1128 <entry>-</entry>
1129 <entry>-</entry>
1130 <entry>-</entry>
1131 <entry>-</entry>
1132 <entry>-</entry> 1226 <entry>-</entry>
1133 <entry>-</entry> 1227 <entry>-</entry>
1134 <entry>v<subscript>7</subscript></entry> 1228 <entry>v<subscript>7</subscript></entry>
@@ -1144,16 +1238,8 @@
1144 <entry></entry> 1238 <entry></entry>
1145 <entry></entry> 1239 <entry></entry>
1146 <entry></entry> 1240 <entry></entry>
1147 <entry>-</entry> 1241 &dash-ent-10;
1148 <entry>-</entry> 1242 &dash-ent-10;
1149 <entry>-</entry>
1150 <entry>-</entry>
1151 <entry>-</entry>
1152 <entry>-</entry>
1153 <entry>-</entry>
1154 <entry>-</entry>
1155 <entry>-</entry>
1156 <entry>-</entry>
1157 <entry>-</entry> 1243 <entry>-</entry>
1158 <entry>-</entry> 1244 <entry>-</entry>
1159 <entry>y<subscript>7</subscript></entry> 1245 <entry>y<subscript>7</subscript></entry>
@@ -1169,16 +1255,8 @@
1169 <entry></entry> 1255 <entry></entry>
1170 <entry></entry> 1256 <entry></entry>
1171 <entry></entry> 1257 <entry></entry>
1172 <entry>-</entry> 1258 &dash-ent-10;
1173 <entry>-</entry> 1259 &dash-ent-10;
1174 <entry>-</entry>
1175 <entry>-</entry>
1176 <entry>-</entry>
1177 <entry>-</entry>
1178 <entry>-</entry>
1179 <entry>-</entry>
1180 <entry>-</entry>
1181 <entry>-</entry>
1182 <entry>-</entry> 1260 <entry>-</entry>
1183 <entry>-</entry> 1261 <entry>-</entry>
1184 <entry>y<subscript>7</subscript></entry> 1262 <entry>y<subscript>7</subscript></entry>
@@ -1194,16 +1272,8 @@
1194 <entry></entry> 1272 <entry></entry>
1195 <entry></entry> 1273 <entry></entry>
1196 <entry></entry> 1274 <entry></entry>
1197 <entry>-</entry> 1275 &dash-ent-10;
1198 <entry>-</entry> 1276 &dash-ent-10;
1199 <entry>-</entry>
1200 <entry>-</entry>
1201 <entry>-</entry>
1202 <entry>-</entry>
1203 <entry>-</entry>
1204 <entry>-</entry>
1205 <entry>-</entry>
1206 <entry>-</entry>
1207 <entry>-</entry> 1277 <entry>-</entry>
1208 <entry>-</entry> 1278 <entry>-</entry>
1209 <entry>u<subscript>7</subscript></entry> 1279 <entry>u<subscript>7</subscript></entry>
@@ -1219,16 +1289,8 @@
1219 <entry></entry> 1289 <entry></entry>
1220 <entry></entry> 1290 <entry></entry>
1221 <entry></entry> 1291 <entry></entry>
1222 <entry>-</entry> 1292 &dash-ent-10;
1223 <entry>-</entry> 1293 &dash-ent-10;
1224 <entry>-</entry>
1225 <entry>-</entry>
1226 <entry>-</entry>
1227 <entry>-</entry>
1228 <entry>-</entry>
1229 <entry>-</entry>
1230 <entry>-</entry>
1231 <entry>-</entry>
1232 <entry>-</entry> 1294 <entry>-</entry>
1233 <entry>-</entry> 1295 <entry>-</entry>
1234 <entry>y<subscript>7</subscript></entry> 1296 <entry>y<subscript>7</subscript></entry>
@@ -1244,16 +1306,8 @@
1244 <entry></entry> 1306 <entry></entry>
1245 <entry></entry> 1307 <entry></entry>
1246 <entry></entry> 1308 <entry></entry>
1247 <entry>-</entry> 1309 &dash-ent-10;
1248 <entry>-</entry> 1310 &dash-ent-10;
1249 <entry>-</entry>
1250 <entry>-</entry>
1251 <entry>-</entry>
1252 <entry>-</entry>
1253 <entry>-</entry>
1254 <entry>-</entry>
1255 <entry>-</entry>
1256 <entry>-</entry>
1257 <entry>-</entry> 1311 <entry>-</entry>
1258 <entry>-</entry> 1312 <entry>-</entry>
1259 <entry>y<subscript>7</subscript></entry> 1313 <entry>y<subscript>7</subscript></entry>
@@ -1269,16 +1323,8 @@
1269 <entry>V4L2_MBUS_FMT_YUYV8_1_5X8</entry> 1323 <entry>V4L2_MBUS_FMT_YUYV8_1_5X8</entry>
1270 <entry>0x2004</entry> 1324 <entry>0x2004</entry>
1271 <entry></entry> 1325 <entry></entry>
1272 <entry>-</entry> 1326 &dash-ent-10;
1273 <entry>-</entry> 1327 &dash-ent-10;
1274 <entry>-</entry>
1275 <entry>-</entry>
1276 <entry>-</entry>
1277 <entry>-</entry>
1278 <entry>-</entry>
1279 <entry>-</entry>
1280 <entry>-</entry>
1281 <entry>-</entry>
1282 <entry>-</entry> 1328 <entry>-</entry>
1283 <entry>-</entry> 1329 <entry>-</entry>
1284 <entry>y<subscript>7</subscript></entry> 1330 <entry>y<subscript>7</subscript></entry>
@@ -1294,16 +1340,8 @@
1294 <entry></entry> 1340 <entry></entry>
1295 <entry></entry> 1341 <entry></entry>
1296 <entry></entry> 1342 <entry></entry>
1297 <entry>-</entry> 1343 &dash-ent-10;
1298 <entry>-</entry> 1344 &dash-ent-10;
1299 <entry>-</entry>
1300 <entry>-</entry>
1301 <entry>-</entry>
1302 <entry>-</entry>
1303 <entry>-</entry>
1304 <entry>-</entry>
1305 <entry>-</entry>
1306 <entry>-</entry>
1307 <entry>-</entry> 1345 <entry>-</entry>
1308 <entry>-</entry> 1346 <entry>-</entry>
1309 <entry>y<subscript>7</subscript></entry> 1347 <entry>y<subscript>7</subscript></entry>
@@ -1319,16 +1357,8 @@
1319 <entry></entry> 1357 <entry></entry>
1320 <entry></entry> 1358 <entry></entry>
1321 <entry></entry> 1359 <entry></entry>
1322 <entry>-</entry> 1360 &dash-ent-10;
1323 <entry>-</entry> 1361 &dash-ent-10;
1324 <entry>-</entry>
1325 <entry>-</entry>
1326 <entry>-</entry>
1327 <entry>-</entry>
1328 <entry>-</entry>
1329 <entry>-</entry>
1330 <entry>-</entry>
1331 <entry>-</entry>
1332 <entry>-</entry> 1362 <entry>-</entry>
1333 <entry>-</entry> 1363 <entry>-</entry>
1334 <entry>u<subscript>7</subscript></entry> 1364 <entry>u<subscript>7</subscript></entry>
@@ -1344,16 +1374,8 @@
1344 <entry></entry> 1374 <entry></entry>
1345 <entry></entry> 1375 <entry></entry>
1346 <entry></entry> 1376 <entry></entry>
1347 <entry>-</entry> 1377 &dash-ent-10;
1348 <entry>-</entry> 1378 &dash-ent-10;
1349 <entry>-</entry>
1350 <entry>-</entry>
1351 <entry>-</entry>
1352 <entry>-</entry>
1353 <entry>-</entry>
1354 <entry>-</entry>
1355 <entry>-</entry>
1356 <entry>-</entry>
1357 <entry>-</entry> 1379 <entry>-</entry>
1358 <entry>-</entry> 1380 <entry>-</entry>
1359 <entry>y<subscript>7</subscript></entry> 1381 <entry>y<subscript>7</subscript></entry>
@@ -1369,16 +1391,8 @@
1369 <entry></entry> 1391 <entry></entry>
1370 <entry></entry> 1392 <entry></entry>
1371 <entry></entry> 1393 <entry></entry>
1372 <entry>-</entry> 1394 &dash-ent-10;
1373 <entry>-</entry> 1395 &dash-ent-10;
1374 <entry>-</entry>
1375 <entry>-</entry>
1376 <entry>-</entry>
1377 <entry>-</entry>
1378 <entry>-</entry>
1379 <entry>-</entry>
1380 <entry>-</entry>
1381 <entry>-</entry>
1382 <entry>-</entry> 1396 <entry>-</entry>
1383 <entry>-</entry> 1397 <entry>-</entry>
1384 <entry>y<subscript>7</subscript></entry> 1398 <entry>y<subscript>7</subscript></entry>
@@ -1394,16 +1408,8 @@
1394 <entry></entry> 1408 <entry></entry>
1395 <entry></entry> 1409 <entry></entry>
1396 <entry></entry> 1410 <entry></entry>
1397 <entry>-</entry> 1411 &dash-ent-10;
1398 <entry>-</entry> 1412 &dash-ent-10;
1399 <entry>-</entry>
1400 <entry>-</entry>
1401 <entry>-</entry>
1402 <entry>-</entry>
1403 <entry>-</entry>
1404 <entry>-</entry>
1405 <entry>-</entry>
1406 <entry>-</entry>
1407 <entry>-</entry> 1413 <entry>-</entry>
1408 <entry>-</entry> 1414 <entry>-</entry>
1409 <entry>v<subscript>7</subscript></entry> 1415 <entry>v<subscript>7</subscript></entry>
@@ -1419,16 +1425,8 @@
1419 <entry>V4L2_MBUS_FMT_YVYU8_1_5X8</entry> 1425 <entry>V4L2_MBUS_FMT_YVYU8_1_5X8</entry>
1420 <entry>0x2005</entry> 1426 <entry>0x2005</entry>
1421 <entry></entry> 1427 <entry></entry>
1422 <entry>-</entry> 1428 &dash-ent-10;
1423 <entry>-</entry> 1429 &dash-ent-10;
1424 <entry>-</entry>
1425 <entry>-</entry>
1426 <entry>-</entry>
1427 <entry>-</entry>
1428 <entry>-</entry>
1429 <entry>-</entry>
1430 <entry>-</entry>
1431 <entry>-</entry>
1432 <entry>-</entry> 1430 <entry>-</entry>
1433 <entry>-</entry> 1431 <entry>-</entry>
1434 <entry>y<subscript>7</subscript></entry> 1432 <entry>y<subscript>7</subscript></entry>
@@ -1444,16 +1442,8 @@
1444 <entry></entry> 1442 <entry></entry>
1445 <entry></entry> 1443 <entry></entry>
1446 <entry></entry> 1444 <entry></entry>
1447 <entry>-</entry> 1445 &dash-ent-10;
1448 <entry>-</entry> 1446 &dash-ent-10;
1449 <entry>-</entry>
1450 <entry>-</entry>
1451 <entry>-</entry>
1452 <entry>-</entry>
1453 <entry>-</entry>
1454 <entry>-</entry>
1455 <entry>-</entry>
1456 <entry>-</entry>
1457 <entry>-</entry> 1447 <entry>-</entry>
1458 <entry>-</entry> 1448 <entry>-</entry>
1459 <entry>y<subscript>7</subscript></entry> 1449 <entry>y<subscript>7</subscript></entry>
@@ -1469,16 +1459,8 @@
1469 <entry></entry> 1459 <entry></entry>
1470 <entry></entry> 1460 <entry></entry>
1471 <entry></entry> 1461 <entry></entry>
1472 <entry>-</entry> 1462 &dash-ent-10;
1473 <entry>-</entry> 1463 &dash-ent-10;
1474 <entry>-</entry>
1475 <entry>-</entry>
1476 <entry>-</entry>
1477 <entry>-</entry>
1478 <entry>-</entry>
1479 <entry>-</entry>
1480 <entry>-</entry>
1481 <entry>-</entry>
1482 <entry>-</entry> 1464 <entry>-</entry>
1483 <entry>-</entry> 1465 <entry>-</entry>
1484 <entry>v<subscript>7</subscript></entry> 1466 <entry>v<subscript>7</subscript></entry>
@@ -1494,16 +1476,8 @@
1494 <entry></entry> 1476 <entry></entry>
1495 <entry></entry> 1477 <entry></entry>
1496 <entry></entry> 1478 <entry></entry>
1497 <entry>-</entry> 1479 &dash-ent-10;
1498 <entry>-</entry> 1480 &dash-ent-10;
1499 <entry>-</entry>
1500 <entry>-</entry>
1501 <entry>-</entry>
1502 <entry>-</entry>
1503 <entry>-</entry>
1504 <entry>-</entry>
1505 <entry>-</entry>
1506 <entry>-</entry>
1507 <entry>-</entry> 1481 <entry>-</entry>
1508 <entry>-</entry> 1482 <entry>-</entry>
1509 <entry>y<subscript>7</subscript></entry> 1483 <entry>y<subscript>7</subscript></entry>
@@ -1519,16 +1493,8 @@
1519 <entry></entry> 1493 <entry></entry>
1520 <entry></entry> 1494 <entry></entry>
1521 <entry></entry> 1495 <entry></entry>
1522 <entry>-</entry> 1496 &dash-ent-10;
1523 <entry>-</entry> 1497 &dash-ent-10;
1524 <entry>-</entry>
1525 <entry>-</entry>
1526 <entry>-</entry>
1527 <entry>-</entry>
1528 <entry>-</entry>
1529 <entry>-</entry>
1530 <entry>-</entry>
1531 <entry>-</entry>
1532 <entry>-</entry> 1498 <entry>-</entry>
1533 <entry>-</entry> 1499 <entry>-</entry>
1534 <entry>y<subscript>7</subscript></entry> 1500 <entry>y<subscript>7</subscript></entry>
@@ -1544,16 +1510,8 @@
1544 <entry></entry> 1510 <entry></entry>
1545 <entry></entry> 1511 <entry></entry>
1546 <entry></entry> 1512 <entry></entry>
1547 <entry>-</entry> 1513 &dash-ent-10;
1548 <entry>-</entry> 1514 &dash-ent-10;
1549 <entry>-</entry>
1550 <entry>-</entry>
1551 <entry>-</entry>
1552 <entry>-</entry>
1553 <entry>-</entry>
1554 <entry>-</entry>
1555 <entry>-</entry>
1556 <entry>-</entry>
1557 <entry>-</entry> 1515 <entry>-</entry>
1558 <entry>-</entry> 1516 <entry>-</entry>
1559 <entry>u<subscript>7</subscript></entry> 1517 <entry>u<subscript>7</subscript></entry>
@@ -1569,16 +1527,8 @@
1569 <entry>V4L2_MBUS_FMT_UYVY8_2X8</entry> 1527 <entry>V4L2_MBUS_FMT_UYVY8_2X8</entry>
1570 <entry>0x2006</entry> 1528 <entry>0x2006</entry>
1571 <entry></entry> 1529 <entry></entry>
1572 <entry>-</entry> 1530 &dash-ent-10;
1573 <entry>-</entry> 1531 &dash-ent-10;
1574 <entry>-</entry>
1575 <entry>-</entry>
1576 <entry>-</entry>
1577 <entry>-</entry>
1578 <entry>-</entry>
1579 <entry>-</entry>
1580 <entry>-</entry>
1581 <entry>-</entry>
1582 <entry>-</entry> 1532 <entry>-</entry>
1583 <entry>-</entry> 1533 <entry>-</entry>
1584 <entry>u<subscript>7</subscript></entry> 1534 <entry>u<subscript>7</subscript></entry>
@@ -1594,16 +1544,8 @@
1594 <entry></entry> 1544 <entry></entry>
1595 <entry></entry> 1545 <entry></entry>
1596 <entry></entry> 1546 <entry></entry>
1597 <entry>-</entry> 1547 &dash-ent-10;
1598 <entry>-</entry> 1548 &dash-ent-10;
1599 <entry>-</entry>
1600 <entry>-</entry>
1601 <entry>-</entry>
1602 <entry>-</entry>
1603 <entry>-</entry>
1604 <entry>-</entry>
1605 <entry>-</entry>
1606 <entry>-</entry>
1607 <entry>-</entry> 1549 <entry>-</entry>
1608 <entry>-</entry> 1550 <entry>-</entry>
1609 <entry>y<subscript>7</subscript></entry> 1551 <entry>y<subscript>7</subscript></entry>
@@ -1619,16 +1561,8 @@
1619 <entry></entry> 1561 <entry></entry>
1620 <entry></entry> 1562 <entry></entry>
1621 <entry></entry> 1563 <entry></entry>
1622 <entry>-</entry> 1564 &dash-ent-10;
1623 <entry>-</entry> 1565 &dash-ent-10;
1624 <entry>-</entry>
1625 <entry>-</entry>
1626 <entry>-</entry>
1627 <entry>-</entry>
1628 <entry>-</entry>
1629 <entry>-</entry>
1630 <entry>-</entry>
1631 <entry>-</entry>
1632 <entry>-</entry> 1566 <entry>-</entry>
1633 <entry>-</entry> 1567 <entry>-</entry>
1634 <entry>v<subscript>7</subscript></entry> 1568 <entry>v<subscript>7</subscript></entry>
@@ -1644,16 +1578,8 @@
1644 <entry></entry> 1578 <entry></entry>
1645 <entry></entry> 1579 <entry></entry>
1646 <entry></entry> 1580 <entry></entry>
1647 <entry>-</entry> 1581 &dash-ent-10;
1648 <entry>-</entry> 1582 &dash-ent-10;
1649 <entry>-</entry>
1650 <entry>-</entry>
1651 <entry>-</entry>
1652 <entry>-</entry>
1653 <entry>-</entry>
1654 <entry>-</entry>
1655 <entry>-</entry>
1656 <entry>-</entry>
1657 <entry>-</entry> 1583 <entry>-</entry>
1658 <entry>-</entry> 1584 <entry>-</entry>
1659 <entry>y<subscript>7</subscript></entry> 1585 <entry>y<subscript>7</subscript></entry>
@@ -1669,16 +1595,8 @@
1669 <entry>V4L2_MBUS_FMT_VYUY8_2X8</entry> 1595 <entry>V4L2_MBUS_FMT_VYUY8_2X8</entry>
1670 <entry>0x2007</entry> 1596 <entry>0x2007</entry>
1671 <entry></entry> 1597 <entry></entry>
1672 <entry>-</entry> 1598 &dash-ent-10;
1673 <entry>-</entry> 1599 &dash-ent-10;
1674 <entry>-</entry>
1675 <entry>-</entry>
1676 <entry>-</entry>
1677 <entry>-</entry>
1678 <entry>-</entry>
1679 <entry>-</entry>
1680 <entry>-</entry>
1681 <entry>-</entry>
1682 <entry>-</entry> 1600 <entry>-</entry>
1683 <entry>-</entry> 1601 <entry>-</entry>
1684 <entry>v<subscript>7</subscript></entry> 1602 <entry>v<subscript>7</subscript></entry>
@@ -1694,16 +1612,8 @@
1694 <entry></entry> 1612 <entry></entry>
1695 <entry></entry> 1613 <entry></entry>
1696 <entry></entry> 1614 <entry></entry>
1697 <entry>-</entry> 1615 &dash-ent-10;
1698 <entry>-</entry> 1616 &dash-ent-10;
1699 <entry>-</entry>
1700 <entry>-</entry>
1701 <entry>-</entry>
1702 <entry>-</entry>
1703 <entry>-</entry>
1704 <entry>-</entry>
1705 <entry>-</entry>
1706 <entry>-</entry>
1707 <entry>-</entry> 1617 <entry>-</entry>
1708 <entry>-</entry> 1618 <entry>-</entry>
1709 <entry>y<subscript>7</subscript></entry> 1619 <entry>y<subscript>7</subscript></entry>
@@ -1719,16 +1629,8 @@
1719 <entry></entry> 1629 <entry></entry>
1720 <entry></entry> 1630 <entry></entry>
1721 <entry></entry> 1631 <entry></entry>
1722 <entry>-</entry> 1632 &dash-ent-10;
1723 <entry>-</entry> 1633 &dash-ent-10;
1724 <entry>-</entry>
1725 <entry>-</entry>
1726 <entry>-</entry>
1727 <entry>-</entry>
1728 <entry>-</entry>
1729 <entry>-</entry>
1730 <entry>-</entry>
1731 <entry>-</entry>
1732 <entry>-</entry> 1634 <entry>-</entry>
1733 <entry>-</entry> 1635 <entry>-</entry>
1734 <entry>u<subscript>7</subscript></entry> 1636 <entry>u<subscript>7</subscript></entry>
@@ -1744,16 +1646,8 @@
1744 <entry></entry> 1646 <entry></entry>
1745 <entry></entry> 1647 <entry></entry>
1746 <entry></entry> 1648 <entry></entry>
1747 <entry>-</entry> 1649 &dash-ent-10;
1748 <entry>-</entry> 1650 &dash-ent-10;
1749 <entry>-</entry>
1750 <entry>-</entry>
1751 <entry>-</entry>
1752 <entry>-</entry>
1753 <entry>-</entry>
1754 <entry>-</entry>
1755 <entry>-</entry>
1756 <entry>-</entry>
1757 <entry>-</entry> 1651 <entry>-</entry>
1758 <entry>-</entry> 1652 <entry>-</entry>
1759 <entry>y<subscript>7</subscript></entry> 1653 <entry>y<subscript>7</subscript></entry>
@@ -1769,16 +1663,8 @@
1769 <entry>V4L2_MBUS_FMT_YUYV8_2X8</entry> 1663 <entry>V4L2_MBUS_FMT_YUYV8_2X8</entry>
1770 <entry>0x2008</entry> 1664 <entry>0x2008</entry>
1771 <entry></entry> 1665 <entry></entry>
1772 <entry>-</entry> 1666 &dash-ent-10;
1773 <entry>-</entry> 1667 &dash-ent-10;
1774 <entry>-</entry>
1775 <entry>-</entry>
1776 <entry>-</entry>
1777 <entry>-</entry>
1778 <entry>-</entry>
1779 <entry>-</entry>
1780 <entry>-</entry>
1781 <entry>-</entry>
1782 <entry>-</entry> 1668 <entry>-</entry>
1783 <entry>-</entry> 1669 <entry>-</entry>
1784 <entry>y<subscript>7</subscript></entry> 1670 <entry>y<subscript>7</subscript></entry>
@@ -1794,16 +1680,8 @@
1794 <entry></entry> 1680 <entry></entry>
1795 <entry></entry> 1681 <entry></entry>
1796 <entry></entry> 1682 <entry></entry>
1797 <entry>-</entry> 1683 &dash-ent-10;
1798 <entry>-</entry> 1684 &dash-ent-10;
1799 <entry>-</entry>
1800 <entry>-</entry>
1801 <entry>-</entry>
1802 <entry>-</entry>
1803 <entry>-</entry>
1804 <entry>-</entry>
1805 <entry>-</entry>
1806 <entry>-</entry>
1807 <entry>-</entry> 1685 <entry>-</entry>
1808 <entry>-</entry> 1686 <entry>-</entry>
1809 <entry>u<subscript>7</subscript></entry> 1687 <entry>u<subscript>7</subscript></entry>
@@ -1819,16 +1697,8 @@
1819 <entry></entry> 1697 <entry></entry>
1820 <entry></entry> 1698 <entry></entry>
1821 <entry></entry> 1699 <entry></entry>
1822 <entry>-</entry> 1700 &dash-ent-10;
1823 <entry>-</entry> 1701 &dash-ent-10;
1824 <entry>-</entry>
1825 <entry>-</entry>
1826 <entry>-</entry>
1827 <entry>-</entry>
1828 <entry>-</entry>
1829 <entry>-</entry>
1830 <entry>-</entry>
1831 <entry>-</entry>
1832 <entry>-</entry> 1702 <entry>-</entry>
1833 <entry>-</entry> 1703 <entry>-</entry>
1834 <entry>y<subscript>7</subscript></entry> 1704 <entry>y<subscript>7</subscript></entry>
@@ -1844,16 +1714,8 @@
1844 <entry></entry> 1714 <entry></entry>
1845 <entry></entry> 1715 <entry></entry>
1846 <entry></entry> 1716 <entry></entry>
1847 <entry>-</entry> 1717 &dash-ent-10;
1848 <entry>-</entry> 1718 &dash-ent-10;
1849 <entry>-</entry>
1850 <entry>-</entry>
1851 <entry>-</entry>
1852 <entry>-</entry>
1853 <entry>-</entry>
1854 <entry>-</entry>
1855 <entry>-</entry>
1856 <entry>-</entry>
1857 <entry>-</entry> 1719 <entry>-</entry>
1858 <entry>-</entry> 1720 <entry>-</entry>
1859 <entry>v<subscript>7</subscript></entry> 1721 <entry>v<subscript>7</subscript></entry>
@@ -1869,16 +1731,8 @@
1869 <entry>V4L2_MBUS_FMT_YVYU8_2X8</entry> 1731 <entry>V4L2_MBUS_FMT_YVYU8_2X8</entry>
1870 <entry>0x2009</entry> 1732 <entry>0x2009</entry>
1871 <entry></entry> 1733 <entry></entry>
1872 <entry>-</entry> 1734 &dash-ent-10;
1873 <entry>-</entry> 1735 &dash-ent-10;
1874 <entry>-</entry>
1875 <entry>-</entry>
1876 <entry>-</entry>
1877 <entry>-</entry>
1878 <entry>-</entry>
1879 <entry>-</entry>
1880 <entry>-</entry>
1881 <entry>-</entry>
1882 <entry>-</entry> 1736 <entry>-</entry>
1883 <entry>-</entry> 1737 <entry>-</entry>
1884 <entry>y<subscript>7</subscript></entry> 1738 <entry>y<subscript>7</subscript></entry>
@@ -1894,16 +1748,8 @@
1894 <entry></entry> 1748 <entry></entry>
1895 <entry></entry> 1749 <entry></entry>
1896 <entry></entry> 1750 <entry></entry>
1897 <entry>-</entry> 1751 &dash-ent-10;
1898 <entry>-</entry> 1752 &dash-ent-10;
1899 <entry>-</entry>
1900 <entry>-</entry>
1901 <entry>-</entry>
1902 <entry>-</entry>
1903 <entry>-</entry>
1904 <entry>-</entry>
1905 <entry>-</entry>
1906 <entry>-</entry>
1907 <entry>-</entry> 1753 <entry>-</entry>
1908 <entry>-</entry> 1754 <entry>-</entry>
1909 <entry>v<subscript>7</subscript></entry> 1755 <entry>v<subscript>7</subscript></entry>
@@ -1919,16 +1765,8 @@
1919 <entry></entry> 1765 <entry></entry>
1920 <entry></entry> 1766 <entry></entry>
1921 <entry></entry> 1767 <entry></entry>
1922 <entry>-</entry> 1768 &dash-ent-10;
1923 <entry>-</entry> 1769 &dash-ent-10;
1924 <entry>-</entry>
1925 <entry>-</entry>
1926 <entry>-</entry>
1927 <entry>-</entry>
1928 <entry>-</entry>
1929 <entry>-</entry>
1930 <entry>-</entry>
1931 <entry>-</entry>
1932 <entry>-</entry> 1770 <entry>-</entry>
1933 <entry>-</entry> 1771 <entry>-</entry>
1934 <entry>y<subscript>7</subscript></entry> 1772 <entry>y<subscript>7</subscript></entry>
@@ -1944,16 +1782,8 @@
1944 <entry></entry> 1782 <entry></entry>
1945 <entry></entry> 1783 <entry></entry>
1946 <entry></entry> 1784 <entry></entry>
1947 <entry>-</entry> 1785 &dash-ent-10;
1948 <entry>-</entry> 1786 &dash-ent-10;
1949 <entry>-</entry>
1950 <entry>-</entry>
1951 <entry>-</entry>
1952 <entry>-</entry>
1953 <entry>-</entry>
1954 <entry>-</entry>
1955 <entry>-</entry>
1956 <entry>-</entry>
1957 <entry>-</entry> 1787 <entry>-</entry>
1958 <entry>-</entry> 1788 <entry>-</entry>
1959 <entry>u<subscript>7</subscript></entry> 1789 <entry>u<subscript>7</subscript></entry>
@@ -1969,16 +1799,8 @@
1969 <entry>V4L2_MBUS_FMT_Y10_1X10</entry> 1799 <entry>V4L2_MBUS_FMT_Y10_1X10</entry>
1970 <entry>0x200a</entry> 1800 <entry>0x200a</entry>
1971 <entry></entry> 1801 <entry></entry>
1972 <entry>-</entry> 1802 &dash-ent-10;
1973 <entry>-</entry> 1803 &dash-ent-10;
1974 <entry>-</entry>
1975 <entry>-</entry>
1976 <entry>-</entry>
1977 <entry>-</entry>
1978 <entry>-</entry>
1979 <entry>-</entry>
1980 <entry>-</entry>
1981 <entry>-</entry>
1982 <entry>y<subscript>9</subscript></entry> 1804 <entry>y<subscript>9</subscript></entry>
1983 <entry>y<subscript>8</subscript></entry> 1805 <entry>y<subscript>8</subscript></entry>
1984 <entry>y<subscript>7</subscript></entry> 1806 <entry>y<subscript>7</subscript></entry>
@@ -1994,16 +1816,8 @@
1994 <entry>V4L2_MBUS_FMT_YUYV10_2X10</entry> 1816 <entry>V4L2_MBUS_FMT_YUYV10_2X10</entry>
1995 <entry>0x200b</entry> 1817 <entry>0x200b</entry>
1996 <entry></entry> 1818 <entry></entry>
1997 <entry>-</entry> 1819 &dash-ent-10;
1998 <entry>-</entry> 1820 &dash-ent-10;
1999 <entry>-</entry>
2000 <entry>-</entry>
2001 <entry>-</entry>
2002 <entry>-</entry>
2003 <entry>-</entry>
2004 <entry>-</entry>
2005 <entry>-</entry>
2006 <entry>-</entry>
2007 <entry>y<subscript>9</subscript></entry> 1821 <entry>y<subscript>9</subscript></entry>
2008 <entry>y<subscript>8</subscript></entry> 1822 <entry>y<subscript>8</subscript></entry>
2009 <entry>y<subscript>7</subscript></entry> 1823 <entry>y<subscript>7</subscript></entry>
@@ -2019,16 +1833,8 @@
2019 <entry></entry> 1833 <entry></entry>
2020 <entry></entry> 1834 <entry></entry>
2021 <entry></entry> 1835 <entry></entry>
2022 <entry>-</entry> 1836 &dash-ent-10;
2023 <entry>-</entry> 1837 &dash-ent-10;
2024 <entry>-</entry>
2025 <entry>-</entry>
2026 <entry>-</entry>
2027 <entry>-</entry>
2028 <entry>-</entry>
2029 <entry>-</entry>
2030 <entry>-</entry>
2031 <entry>-</entry>
2032 <entry>u<subscript>9</subscript></entry> 1838 <entry>u<subscript>9</subscript></entry>
2033 <entry>u<subscript>8</subscript></entry> 1839 <entry>u<subscript>8</subscript></entry>
2034 <entry>u<subscript>7</subscript></entry> 1840 <entry>u<subscript>7</subscript></entry>
@@ -2044,16 +1850,8 @@
2044 <entry></entry> 1850 <entry></entry>
2045 <entry></entry> 1851 <entry></entry>
2046 <entry></entry> 1852 <entry></entry>
2047 <entry>-</entry> 1853 &dash-ent-10;
2048 <entry>-</entry> 1854 &dash-ent-10;
2049 <entry>-</entry>
2050 <entry>-</entry>
2051 <entry>-</entry>
2052 <entry>-</entry>
2053 <entry>-</entry>
2054 <entry>-</entry>
2055 <entry>-</entry>
2056 <entry>-</entry>
2057 <entry>y<subscript>9</subscript></entry> 1855 <entry>y<subscript>9</subscript></entry>
2058 <entry>y<subscript>8</subscript></entry> 1856 <entry>y<subscript>8</subscript></entry>
2059 <entry>y<subscript>7</subscript></entry> 1857 <entry>y<subscript>7</subscript></entry>
@@ -2069,16 +1867,8 @@
2069 <entry></entry> 1867 <entry></entry>
2070 <entry></entry> 1868 <entry></entry>
2071 <entry></entry> 1869 <entry></entry>
2072 <entry>-</entry> 1870 &dash-ent-10;
2073 <entry>-</entry> 1871 &dash-ent-10;
2074 <entry>-</entry>
2075 <entry>-</entry>
2076 <entry>-</entry>
2077 <entry>-</entry>
2078 <entry>-</entry>
2079 <entry>-</entry>
2080 <entry>-</entry>
2081 <entry>-</entry>
2082 <entry>v<subscript>9</subscript></entry> 1872 <entry>v<subscript>9</subscript></entry>
2083 <entry>v<subscript>8</subscript></entry> 1873 <entry>v<subscript>8</subscript></entry>
2084 <entry>v<subscript>7</subscript></entry> 1874 <entry>v<subscript>7</subscript></entry>
@@ -2094,16 +1884,8 @@
2094 <entry>V4L2_MBUS_FMT_YVYU10_2X10</entry> 1884 <entry>V4L2_MBUS_FMT_YVYU10_2X10</entry>
2095 <entry>0x200c</entry> 1885 <entry>0x200c</entry>
2096 <entry></entry> 1886 <entry></entry>
2097 <entry>-</entry> 1887 &dash-ent-10;
2098 <entry>-</entry> 1888 &dash-ent-10;
2099 <entry>-</entry>
2100 <entry>-</entry>
2101 <entry>-</entry>
2102 <entry>-</entry>
2103 <entry>-</entry>
2104 <entry>-</entry>
2105 <entry>-</entry>
2106 <entry>-</entry>
2107 <entry>y<subscript>9</subscript></entry> 1889 <entry>y<subscript>9</subscript></entry>
2108 <entry>y<subscript>8</subscript></entry> 1890 <entry>y<subscript>8</subscript></entry>
2109 <entry>y<subscript>7</subscript></entry> 1891 <entry>y<subscript>7</subscript></entry>
@@ -2119,16 +1901,8 @@
2119 <entry></entry> 1901 <entry></entry>
2120 <entry></entry> 1902 <entry></entry>
2121 <entry></entry> 1903 <entry></entry>
2122 <entry>-</entry> 1904 &dash-ent-10;
2123 <entry>-</entry> 1905 &dash-ent-10;
2124 <entry>-</entry>
2125 <entry>-</entry>
2126 <entry>-</entry>
2127 <entry>-</entry>
2128 <entry>-</entry>
2129 <entry>-</entry>
2130 <entry>-</entry>
2131 <entry>-</entry>
2132 <entry>v<subscript>9</subscript></entry> 1906 <entry>v<subscript>9</subscript></entry>
2133 <entry>v<subscript>8</subscript></entry> 1907 <entry>v<subscript>8</subscript></entry>
2134 <entry>v<subscript>7</subscript></entry> 1908 <entry>v<subscript>7</subscript></entry>
@@ -2144,16 +1918,8 @@
2144 <entry></entry> 1918 <entry></entry>
2145 <entry></entry> 1919 <entry></entry>
2146 <entry></entry> 1920 <entry></entry>
2147 <entry>-</entry> 1921 &dash-ent-10;
2148 <entry>-</entry> 1922 &dash-ent-10;
2149 <entry>-</entry>
2150 <entry>-</entry>
2151 <entry>-</entry>
2152 <entry>-</entry>
2153 <entry>-</entry>
2154 <entry>-</entry>
2155 <entry>-</entry>
2156 <entry>-</entry>
2157 <entry>y<subscript>9</subscript></entry> 1923 <entry>y<subscript>9</subscript></entry>
2158 <entry>y<subscript>8</subscript></entry> 1924 <entry>y<subscript>8</subscript></entry>
2159 <entry>y<subscript>7</subscript></entry> 1925 <entry>y<subscript>7</subscript></entry>
@@ -2169,16 +1935,8 @@
2169 <entry></entry> 1935 <entry></entry>
2170 <entry></entry> 1936 <entry></entry>
2171 <entry></entry> 1937 <entry></entry>
2172 <entry>-</entry> 1938 &dash-ent-10;
2173 <entry>-</entry> 1939 &dash-ent-10;
2174 <entry>-</entry>
2175 <entry>-</entry>
2176 <entry>-</entry>
2177 <entry>-</entry>
2178 <entry>-</entry>
2179 <entry>-</entry>
2180 <entry>-</entry>
2181 <entry>-</entry>
2182 <entry>u<subscript>9</subscript></entry> 1940 <entry>u<subscript>9</subscript></entry>
2183 <entry>u<subscript>8</subscript></entry> 1941 <entry>u<subscript>8</subscript></entry>
2184 <entry>u<subscript>7</subscript></entry> 1942 <entry>u<subscript>7</subscript></entry>
@@ -2194,6 +1952,7 @@
2194 <entry>V4L2_MBUS_FMT_Y12_1X12</entry> 1952 <entry>V4L2_MBUS_FMT_Y12_1X12</entry>
2195 <entry>0x2013</entry> 1953 <entry>0x2013</entry>
2196 <entry></entry> 1954 <entry></entry>
1955 &dash-ent-10;
2197 <entry>-</entry> 1956 <entry>-</entry>
2198 <entry>-</entry> 1957 <entry>-</entry>
2199 <entry>-</entry> 1958 <entry>-</entry>
@@ -2219,6 +1978,7 @@
2219 <entry>V4L2_MBUS_FMT_UYVY8_1X16</entry> 1978 <entry>V4L2_MBUS_FMT_UYVY8_1X16</entry>
2220 <entry>0x200f</entry> 1979 <entry>0x200f</entry>
2221 <entry></entry> 1980 <entry></entry>
1981 &dash-ent-10;
2222 <entry>-</entry> 1982 <entry>-</entry>
2223 <entry>-</entry> 1983 <entry>-</entry>
2224 <entry>-</entry> 1984 <entry>-</entry>
@@ -2244,6 +2004,7 @@
2244 <entry></entry> 2004 <entry></entry>
2245 <entry></entry> 2005 <entry></entry>
2246 <entry></entry> 2006 <entry></entry>
2007 &dash-ent-10;
2247 <entry>-</entry> 2008 <entry>-</entry>
2248 <entry>-</entry> 2009 <entry>-</entry>
2249 <entry>-</entry> 2010 <entry>-</entry>
@@ -2269,6 +2030,7 @@
2269 <entry>V4L2_MBUS_FMT_VYUY8_1X16</entry> 2030 <entry>V4L2_MBUS_FMT_VYUY8_1X16</entry>
2270 <entry>0x2010</entry> 2031 <entry>0x2010</entry>
2271 <entry></entry> 2032 <entry></entry>
2033 &dash-ent-10;
2272 <entry>-</entry> 2034 <entry>-</entry>
2273 <entry>-</entry> 2035 <entry>-</entry>
2274 <entry>-</entry> 2036 <entry>-</entry>
@@ -2294,6 +2056,7 @@
2294 <entry></entry> 2056 <entry></entry>
2295 <entry></entry> 2057 <entry></entry>
2296 <entry></entry> 2058 <entry></entry>
2059 &dash-ent-10;
2297 <entry>-</entry> 2060 <entry>-</entry>
2298 <entry>-</entry> 2061 <entry>-</entry>
2299 <entry>-</entry> 2062 <entry>-</entry>
@@ -2319,6 +2082,7 @@
2319 <entry>V4L2_MBUS_FMT_YUYV8_1X16</entry> 2082 <entry>V4L2_MBUS_FMT_YUYV8_1X16</entry>
2320 <entry>0x2011</entry> 2083 <entry>0x2011</entry>
2321 <entry></entry> 2084 <entry></entry>
2085 &dash-ent-10;
2322 <entry>-</entry> 2086 <entry>-</entry>
2323 <entry>-</entry> 2087 <entry>-</entry>
2324 <entry>-</entry> 2088 <entry>-</entry>
@@ -2344,6 +2108,7 @@
2344 <entry></entry> 2108 <entry></entry>
2345 <entry></entry> 2109 <entry></entry>
2346 <entry></entry> 2110 <entry></entry>
2111 &dash-ent-10;
2347 <entry>-</entry> 2112 <entry>-</entry>
2348 <entry>-</entry> 2113 <entry>-</entry>
2349 <entry>-</entry> 2114 <entry>-</entry>
@@ -2369,6 +2134,7 @@
2369 <entry>V4L2_MBUS_FMT_YVYU8_1X16</entry> 2134 <entry>V4L2_MBUS_FMT_YVYU8_1X16</entry>
2370 <entry>0x2012</entry> 2135 <entry>0x2012</entry>
2371 <entry></entry> 2136 <entry></entry>
2137 &dash-ent-10;
2372 <entry>-</entry> 2138 <entry>-</entry>
2373 <entry>-</entry> 2139 <entry>-</entry>
2374 <entry>-</entry> 2140 <entry>-</entry>
@@ -2394,6 +2160,57 @@
2394 <entry></entry> 2160 <entry></entry>
2395 <entry></entry> 2161 <entry></entry>
2396 <entry></entry> 2162 <entry></entry>
2163 &dash-ent-10;
2164 <entry>-</entry>
2165 <entry>-</entry>
2166 <entry>-</entry>
2167 <entry>-</entry>
2168 <entry>y<subscript>7</subscript></entry>
2169 <entry>y<subscript>6</subscript></entry>
2170 <entry>y<subscript>5</subscript></entry>
2171 <entry>y<subscript>4</subscript></entry>
2172 <entry>y<subscript>3</subscript></entry>
2173 <entry>y<subscript>2</subscript></entry>
2174 <entry>y<subscript>1</subscript></entry>
2175 <entry>y<subscript>0</subscript></entry>
2176 <entry>u<subscript>7</subscript></entry>
2177 <entry>u<subscript>6</subscript></entry>
2178 <entry>u<subscript>5</subscript></entry>
2179 <entry>u<subscript>4</subscript></entry>
2180 <entry>u<subscript>3</subscript></entry>
2181 <entry>u<subscript>2</subscript></entry>
2182 <entry>u<subscript>1</subscript></entry>
2183 <entry>u<subscript>0</subscript></entry>
2184 </row>
2185 <row id="V4L2-MBUS-FMT-YDYUYDYV8-1X16">
2186 <entry>V4L2_MBUS_FMT_YDYUYDYV8_1X16</entry>
2187 <entry>0x2014</entry>
2188 <entry></entry>
2189 <entry>-</entry>
2190 <entry>-</entry>
2191 <entry>-</entry>
2192 <entry>-</entry>
2193 <entry>y<subscript>7</subscript></entry>
2194 <entry>y<subscript>6</subscript></entry>
2195 <entry>y<subscript>5</subscript></entry>
2196 <entry>y<subscript>4</subscript></entry>
2197 <entry>y<subscript>3</subscript></entry>
2198 <entry>y<subscript>2</subscript></entry>
2199 <entry>y<subscript>1</subscript></entry>
2200 <entry>y<subscript>0</subscript></entry>
2201 <entry>d</entry>
2202 <entry>d</entry>
2203 <entry>d</entry>
2204 <entry>d</entry>
2205 <entry>d</entry>
2206 <entry>d</entry>
2207 <entry>d</entry>
2208 <entry>d</entry>
2209 </row>
2210 <row>
2211 <entry></entry>
2212 <entry></entry>
2213 <entry></entry>
2397 <entry>-</entry> 2214 <entry>-</entry>
2398 <entry>-</entry> 2215 <entry>-</entry>
2399 <entry>-</entry> 2216 <entry>-</entry>
@@ -2415,10 +2232,61 @@
2415 <entry>u<subscript>1</subscript></entry> 2232 <entry>u<subscript>1</subscript></entry>
2416 <entry>u<subscript>0</subscript></entry> 2233 <entry>u<subscript>0</subscript></entry>
2417 </row> 2234 </row>
2235 <row>
2236 <entry></entry>
2237 <entry></entry>
2238 <entry></entry>
2239 <entry>-</entry>
2240 <entry>-</entry>
2241 <entry>-</entry>
2242 <entry>-</entry>
2243 <entry>y<subscript>7</subscript></entry>
2244 <entry>y<subscript>6</subscript></entry>
2245 <entry>y<subscript>5</subscript></entry>
2246 <entry>y<subscript>4</subscript></entry>
2247 <entry>y<subscript>3</subscript></entry>
2248 <entry>y<subscript>2</subscript></entry>
2249 <entry>y<subscript>1</subscript></entry>
2250 <entry>y<subscript>0</subscript></entry>
2251 <entry>d</entry>
2252 <entry>d</entry>
2253 <entry>d</entry>
2254 <entry>d</entry>
2255 <entry>d</entry>
2256 <entry>d</entry>
2257 <entry>d</entry>
2258 <entry>d</entry>
2259 </row>
2260 <row>
2261 <entry></entry>
2262 <entry></entry>
2263 <entry></entry>
2264 <entry>-</entry>
2265 <entry>-</entry>
2266 <entry>-</entry>
2267 <entry>-</entry>
2268 <entry>y<subscript>7</subscript></entry>
2269 <entry>y<subscript>6</subscript></entry>
2270 <entry>y<subscript>5</subscript></entry>
2271 <entry>y<subscript>4</subscript></entry>
2272 <entry>y<subscript>3</subscript></entry>
2273 <entry>y<subscript>2</subscript></entry>
2274 <entry>y<subscript>1</subscript></entry>
2275 <entry>y<subscript>0</subscript></entry>
2276 <entry>v<subscript>7</subscript></entry>
2277 <entry>v<subscript>6</subscript></entry>
2278 <entry>v<subscript>5</subscript></entry>
2279 <entry>v<subscript>4</subscript></entry>
2280 <entry>v<subscript>3</subscript></entry>
2281 <entry>v<subscript>2</subscript></entry>
2282 <entry>v<subscript>1</subscript></entry>
2283 <entry>v<subscript>0</subscript></entry>
2284 </row>
2418 <row id="V4L2-MBUS-FMT-YUYV10-1X20"> 2285 <row id="V4L2-MBUS-FMT-YUYV10-1X20">
2419 <entry>V4L2_MBUS_FMT_YUYV10_1X20</entry> 2286 <entry>V4L2_MBUS_FMT_YUYV10_1X20</entry>
2420 <entry>0x200d</entry> 2287 <entry>0x200d</entry>
2421 <entry></entry> 2288 <entry></entry>
2289 &dash-ent-10;
2422 <entry>y<subscript>9</subscript></entry> 2290 <entry>y<subscript>9</subscript></entry>
2423 <entry>y<subscript>8</subscript></entry> 2291 <entry>y<subscript>8</subscript></entry>
2424 <entry>y<subscript>7</subscript></entry> 2292 <entry>y<subscript>7</subscript></entry>
@@ -2444,6 +2312,7 @@
2444 <entry></entry> 2312 <entry></entry>
2445 <entry></entry> 2313 <entry></entry>
2446 <entry></entry> 2314 <entry></entry>
2315 &dash-ent-10;
2447 <entry>y<subscript>9</subscript></entry> 2316 <entry>y<subscript>9</subscript></entry>
2448 <entry>y<subscript>8</subscript></entry> 2317 <entry>y<subscript>8</subscript></entry>
2449 <entry>y<subscript>7</subscript></entry> 2318 <entry>y<subscript>7</subscript></entry>
@@ -2469,6 +2338,7 @@
2469 <entry>V4L2_MBUS_FMT_YVYU10_1X20</entry> 2338 <entry>V4L2_MBUS_FMT_YVYU10_1X20</entry>
2470 <entry>0x200e</entry> 2339 <entry>0x200e</entry>
2471 <entry></entry> 2340 <entry></entry>
2341 &dash-ent-10;
2472 <entry>y<subscript>9</subscript></entry> 2342 <entry>y<subscript>9</subscript></entry>
2473 <entry>y<subscript>8</subscript></entry> 2343 <entry>y<subscript>8</subscript></entry>
2474 <entry>y<subscript>7</subscript></entry> 2344 <entry>y<subscript>7</subscript></entry>
@@ -2494,6 +2364,7 @@
2494 <entry></entry> 2364 <entry></entry>
2495 <entry></entry> 2365 <entry></entry>
2496 <entry></entry> 2366 <entry></entry>
2367 &dash-ent-10;
2497 <entry>y<subscript>9</subscript></entry> 2368 <entry>y<subscript>9</subscript></entry>
2498 <entry>y<subscript>8</subscript></entry> 2369 <entry>y<subscript>8</subscript></entry>
2499 <entry>y<subscript>7</subscript></entry> 2370 <entry>y<subscript>7</subscript></entry>
@@ -2515,6 +2386,41 @@
2515 <entry>u<subscript>1</subscript></entry> 2386 <entry>u<subscript>1</subscript></entry>
2516 <entry>u<subscript>0</subscript></entry> 2387 <entry>u<subscript>0</subscript></entry>
2517 </row> 2388 </row>
2389 <row id="V4L2-MBUS-FMT-YUV10-1X30">
2390 <entry>V4L2_MBUS_FMT_YUV10_1X30</entry>
2391 <entry>0x2014</entry>
2392 <entry></entry>
2393 <entry>y<subscript>9</subscript></entry>
2394 <entry>y<subscript>8</subscript></entry>
2395 <entry>y<subscript>7</subscript></entry>
2396 <entry>y<subscript>6</subscript></entry>
2397 <entry>y<subscript>5</subscript></entry>
2398 <entry>y<subscript>4</subscript></entry>
2399 <entry>y<subscript>3</subscript></entry>
2400 <entry>y<subscript>2</subscript></entry>
2401 <entry>y<subscript>1</subscript></entry>
2402 <entry>y<subscript>0</subscript></entry>
2403 <entry>u<subscript>9</subscript></entry>
2404 <entry>u<subscript>8</subscript></entry>
2405 <entry>u<subscript>7</subscript></entry>
2406 <entry>u<subscript>6</subscript></entry>
2407 <entry>u<subscript>5</subscript></entry>
2408 <entry>u<subscript>4</subscript></entry>
2409 <entry>u<subscript>3</subscript></entry>
2410 <entry>u<subscript>2</subscript></entry>
2411 <entry>u<subscript>1</subscript></entry>
2412 <entry>u<subscript>0</subscript></entry>
2413 <entry>v<subscript>9</subscript></entry>
2414 <entry>v<subscript>8</subscript></entry>
2415 <entry>v<subscript>7</subscript></entry>
2416 <entry>v<subscript>6</subscript></entry>
2417 <entry>v<subscript>5</subscript></entry>
2418 <entry>v<subscript>4</subscript></entry>
2419 <entry>v<subscript>3</subscript></entry>
2420 <entry>v<subscript>2</subscript></entry>
2421 <entry>v<subscript>1</subscript></entry>
2422 <entry>v<subscript>0</subscript></entry>
2423 </row>
2518 </tbody> 2424 </tbody>
2519 </tgroup> 2425 </tgroup>
2520 </table> 2426 </table>
diff --git a/Documentation/DocBook/media/v4l/v4l2.xml b/Documentation/DocBook/media/v4l/v4l2.xml
index 4d110b1ad3e9..a3cce18384e9 100644
--- a/Documentation/DocBook/media/v4l/v4l2.xml
+++ b/Documentation/DocBook/media/v4l/v4l2.xml
@@ -140,6 +140,16 @@ structs, ioctls) must be noted in more detail in the history chapter
140applications. --> 140applications. -->
141 141
142 <revision> 142 <revision>
143 <revnumber>3.9</revnumber>
144 <date>2012-12-03</date>
145 <authorinitials>sa, sn</authorinitials>
146 <revremark>Added timestamp types to v4l2_buffer.
147 Added <constant>V4L2_EVENT_CTRL_CH_RANGE</constant> control
148 event changes flag, see <xref linkend="changes-flags"/>.
149 </revremark>
150 </revision>
151
152 <revision>
143 <revnumber>3.6</revnumber> 153 <revnumber>3.6</revnumber>
144 <date>2012-07-02</date> 154 <date>2012-07-02</date>
145 <authorinitials>hv</authorinitials> 155 <authorinitials>hv</authorinitials>
@@ -472,7 +482,7 @@ and discussions on the V4L mailing list.</revremark>
472</partinfo> 482</partinfo>
473 483
474<title>Video for Linux Two API Specification</title> 484<title>Video for Linux Two API Specification</title>
475 <subtitle>Revision 3.6</subtitle> 485 <subtitle>Revision 3.9</subtitle>
476 486
477 <chapter id="common"> 487 <chapter id="common">
478 &sub-common; 488 &sub-common;
diff --git a/Documentation/DocBook/media/v4l/vidioc-dqevent.xml b/Documentation/DocBook/media/v4l/vidioc-dqevent.xml
index 98a856f9ec30..89891adb928a 100644
--- a/Documentation/DocBook/media/v4l/vidioc-dqevent.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-dqevent.xml
@@ -261,6 +261,12 @@
261 <entry>This control event was triggered because the control flags 261 <entry>This control event was triggered because the control flags
262 changed.</entry> 262 changed.</entry>
263 </row> 263 </row>
264 <row>
265 <entry><constant>V4L2_EVENT_CTRL_CH_RANGE</constant></entry>
266 <entry>0x0004</entry>
267 <entry>This control event was triggered because the minimum,
268 maximum, step or the default value of the control changed.</entry>
269 </row>
264 </tbody> 270 </tbody>
265 </tgroup> 271 </tgroup>
266 </table> 272 </table>
diff --git a/Documentation/DocBook/media/v4l/vidioc-expbuf.xml b/Documentation/DocBook/media/v4l/vidioc-expbuf.xml
index 72dfbd20a802..e287c8fc803b 100644
--- a/Documentation/DocBook/media/v4l/vidioc-expbuf.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-expbuf.xml
@@ -83,15 +83,14 @@ descriptor. The application may pass it to other DMABUF-aware devices. Refer to
83<link linkend="dmabuf">DMABUF importing</link> for details about importing 83<link linkend="dmabuf">DMABUF importing</link> for details about importing
84DMABUF files into V4L2 nodes. It is recommended to close a DMABUF file when it 84DMABUF files into V4L2 nodes. It is recommended to close a DMABUF file when it
85is no longer used to allow the associated memory to be reclaimed. </para> 85is no longer used to allow the associated memory to be reclaimed. </para>
86
87 </refsect1> 86 </refsect1>
87
88 <refsect1> 88 <refsect1>
89 <section> 89 <title>Examples</title>
90 <title>Examples</title>
91 90
92 <example> 91 <example>
93 <title>Exporting a buffer.</title> 92 <title>Exporting a buffer.</title>
94 <programlisting> 93 <programlisting>
95int buffer_export(int v4lfd, &v4l2-buf-type; bt, int index, int *dmafd) 94int buffer_export(int v4lfd, &v4l2-buf-type; bt, int index, int *dmafd)
96{ 95{
97 &v4l2-exportbuffer; expbuf; 96 &v4l2-exportbuffer; expbuf;
@@ -108,12 +107,12 @@ int buffer_export(int v4lfd, &v4l2-buf-type; bt, int index, int *dmafd)
108 107
109 return 0; 108 return 0;
110} 109}
111 </programlisting> 110 </programlisting>
112 </example> 111 </example>
113 112
114 <example> 113 <example>
115 <title>Exporting a buffer using the multi-planar API.</title> 114 <title>Exporting a buffer using the multi-planar API.</title>
116 <programlisting> 115 <programlisting>
117int buffer_export_mp(int v4lfd, &v4l2-buf-type; bt, int index, 116int buffer_export_mp(int v4lfd, &v4l2-buf-type; bt, int index,
118 int dmafd[], int n_planes) 117 int dmafd[], int n_planes)
119{ 118{
@@ -137,12 +136,9 @@ int buffer_export_mp(int v4lfd, &v4l2-buf-type; bt, int index,
137 136
138 return 0; 137 return 0;
139} 138}
140 </programlisting> 139 </programlisting>
141 </example> 140 </example>
142 </section>
143 </refsect1>
144 141
145 <refsect1>
146 <table pgwide="1" frame="none" id="v4l2-exportbuffer"> 142 <table pgwide="1" frame="none" id="v4l2-exportbuffer">
147 <title>struct <structname>v4l2_exportbuffer</structname></title> 143 <title>struct <structname>v4l2_exportbuffer</structname></title>
148 <tgroup cols="3"> 144 <tgroup cols="3">
diff --git a/Documentation/DocBook/media/v4l/vidioc-g-ctrl.xml b/Documentation/DocBook/media/v4l/vidioc-g-ctrl.xml
index 12b1d0503e26..ee2820d6ca66 100644
--- a/Documentation/DocBook/media/v4l/vidioc-g-ctrl.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-g-ctrl.xml
@@ -64,7 +64,9 @@ return an &EINVAL;. When the <structfield>value</structfield> is out
64of bounds drivers can choose to take the closest valid value or return 64of bounds drivers can choose to take the closest valid value or return
65an &ERANGE;, whatever seems more appropriate. However, 65an &ERANGE;, whatever seems more appropriate. However,
66<constant>VIDIOC_S_CTRL</constant> is a write-only ioctl, it does not 66<constant>VIDIOC_S_CTRL</constant> is a write-only ioctl, it does not
67return the actual new value.</para> 67return the actual new value. If the <structfield>value</structfield>
68is inappropriate for the control (e.g. if it refers to an unsupported
69menu index of a menu control), then &EINVAL; is returned as well.</para>
68 70
69 <para>These ioctls work only with user controls. For other 71 <para>These ioctls work only with user controls. For other
70control classes the &VIDIOC-G-EXT-CTRLS;, &VIDIOC-S-EXT-CTRLS; or 72control classes the &VIDIOC-G-EXT-CTRLS;, &VIDIOC-S-EXT-CTRLS; or
@@ -99,7 +101,9 @@ application.</entry>
99 <term><errorcode>EINVAL</errorcode></term> 101 <term><errorcode>EINVAL</errorcode></term>
100 <listitem> 102 <listitem>
101 <para>The &v4l2-control; <structfield>id</structfield> is 103 <para>The &v4l2-control; <structfield>id</structfield> is
102invalid.</para> 104invalid or the <structfield>value</structfield> is inappropriate for
105the given control (i.e. if a menu item is selected that is not supported
106by the driver according to &VIDIOC-QUERYMENU;).</para>
103 </listitem> 107 </listitem>
104 </varlistentry> 108 </varlistentry>
105 <varlistentry> 109 <varlistentry>
diff --git a/Documentation/DocBook/media/v4l/vidioc-g-ext-ctrls.xml b/Documentation/DocBook/media/v4l/vidioc-g-ext-ctrls.xml
index 0a4b90fcf2da..4e16112df992 100644
--- a/Documentation/DocBook/media/v4l/vidioc-g-ext-ctrls.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-g-ext-ctrls.xml
@@ -106,7 +106,9 @@ value or if an error is returned.</para>
106&EINVAL;. When the value is out of bounds drivers can choose to take 106&EINVAL;. When the value is out of bounds drivers can choose to take
107the closest valid value or return an &ERANGE;, whatever seems more 107the closest valid value or return an &ERANGE;, whatever seems more
108appropriate. In the first case the new value is set in 108appropriate. In the first case the new value is set in
109&v4l2-ext-control;.</para> 109&v4l2-ext-control;. If the new control value is inappropriate (e.g. the
110given menu index is not supported by the menu control), then this will
111also result in an &EINVAL; error.</para>
110 112
111 <para>The driver will only set/get these controls if all control 113 <para>The driver will only set/get these controls if all control
112values are correct. This prevents the situation where only some of the 114values are correct. This prevents the situation where only some of the
@@ -199,13 +201,46 @@ also be zero.</entry>
199 <row> 201 <row>
200 <entry>__u32</entry> 202 <entry>__u32</entry>
201 <entry><structfield>error_idx</structfield></entry> 203 <entry><structfield>error_idx</structfield></entry>
202 <entry>Set by the driver in case of an error. If it is equal 204 <entry><para>Set by the driver in case of an error. If the error is
203to <structfield>count</structfield>, then no actual changes were made to 205associated with a particular control, then <structfield>error_idx</structfield>
204controls. In other words, the error was not associated with setting a particular 206is set to the index of that control. If the error is not related to a specific
205control. If it is another value, then only the controls up to <structfield>error_idx-1</structfield> 207control, or the validation step failed (see below), then
206were modified and control <structfield>error_idx</structfield> is the one that 208<structfield>error_idx</structfield> is set to <structfield>count</structfield>.
207caused the error. The <structfield>error_idx</structfield> value is undefined 209The value is undefined if the ioctl returned 0 (success).</para>
208if the ioctl returned 0 (success).</entry> 210
211<para>Before controls are read from/written to hardware a validation step
212takes place: this checks if all controls in the list are valid controls,
213if no attempt is made to write to a read-only control or read from a write-only
214control, and any other up-front checks that can be done without accessing the
215hardware. The exact validations done during this step are driver dependent
216since some checks might require hardware access for some devices, thus making
217it impossible to do those checks up-front. However, drivers should make a
218best-effort to do as many up-front checks as possible.</para>
219
220<para>This check is done to avoid leaving the hardware in an inconsistent state due
221to easy-to-avoid problems. But it leads to another problem: the application needs to
222know whether an error came from the validation step (meaning that the hardware
223was not touched) or from an error during the actual reading from/writing to hardware.</para>
224
225<para>The, in hindsight quite poor, solution for that is to set <structfield>error_idx</structfield>
226to <structfield>count</structfield> if the validation failed. This has the
227unfortunate side-effect that it is not possible to see which control failed the
228validation. If the validation was successful and the error happened while
229accessing the hardware, then <structfield>error_idx</structfield> is less than
230<structfield>count</structfield> and only the controls up to
231<structfield>error_idx-1</structfield> were read or written correctly, and the
232state of the remaining controls is undefined.</para>
233
234<para>Since <constant>VIDIOC_TRY_EXT_CTRLS</constant> does not access hardware
235there is also no need to handle the validation step in this special way,
236so <structfield>error_idx</structfield> will just be set to the control that
237failed the validation step instead of to <structfield>count</structfield>.
238This means that if <constant>VIDIOC_S_EXT_CTRLS</constant> fails with
239<structfield>error_idx</structfield> set to <structfield>count</structfield>,
240then you can call <constant>VIDIOC_TRY_EXT_CTRLS</constant> to try to discover
241the actual control that failed the validation step. Unfortunately, there
242is no <constant>TRY</constant> equivalent for <constant>VIDIOC_G_EXT_CTRLS</constant>.
243</para></entry>
209 </row> 244 </row>
210 <row> 245 <row>
211 <entry>__u32</entry> 246 <entry>__u32</entry>
@@ -298,8 +333,10 @@ These controls are described in <xref
298 <term><errorcode>EINVAL</errorcode></term> 333 <term><errorcode>EINVAL</errorcode></term>
299 <listitem> 334 <listitem>
300 <para>The &v4l2-ext-control; <structfield>id</structfield> 335 <para>The &v4l2-ext-control; <structfield>id</structfield>
301is invalid or the &v4l2-ext-controls; 336is invalid, the &v4l2-ext-controls;
302<structfield>ctrl_class</structfield> is invalid. This error code is 337<structfield>ctrl_class</structfield> is invalid, or the &v4l2-ext-control;
338<structfield>value</structfield> was inappropriate (e.g. the given menu
339index is not supported by the driver). This error code is
303also returned by the <constant>VIDIOC_S_EXT_CTRLS</constant> and 340also returned by the <constant>VIDIOC_S_EXT_CTRLS</constant> and
304<constant>VIDIOC_TRY_EXT_CTRLS</constant> ioctls if two or more 341<constant>VIDIOC_TRY_EXT_CTRLS</constant> ioctls if two or more
305control values are in conflict.</para> 342control values are in conflict.</para>
diff --git a/Documentation/DocBook/media/v4l/vidioc-querycap.xml b/Documentation/DocBook/media/v4l/vidioc-querycap.xml
index 4c70215ae03f..d5a3c97b206a 100644
--- a/Documentation/DocBook/media/v4l/vidioc-querycap.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-querycap.xml
@@ -76,7 +76,7 @@ make sure the strings are properly NUL-terminated.</para></entry>
76 <row> 76 <row>
77 <entry>__u8</entry> 77 <entry>__u8</entry>
78 <entry><structfield>card</structfield>[32]</entry> 78 <entry><structfield>card</structfield>[32]</entry>
79 <entry>Name of the device, a NUL-terminated ASCII string. 79 <entry>Name of the device, a NUL-terminated UTF-8 string.
80For example: "Yoyodyne TV/FM". One driver may support different brands 80For example: "Yoyodyne TV/FM". One driver may support different brands
81or models of video hardware. This information is intended for users, 81or models of video hardware. This information is intended for users,
82for example in a menu of available devices. Since multiple TV cards of 82for example in a menu of available devices. Since multiple TV cards of
diff --git a/Documentation/DocBook/media_api.tmpl b/Documentation/DocBook/media_api.tmpl
index f2413acfe241..1f6593deb995 100644
--- a/Documentation/DocBook/media_api.tmpl
+++ b/Documentation/DocBook/media_api.tmpl
@@ -22,6 +22,7 @@
22 22
23<!-- LinuxTV v4l-dvb repository. --> 23<!-- LinuxTV v4l-dvb repository. -->
24<!ENTITY v4l-dvb "<ulink url='http://linuxtv.org/repo/'>http://linuxtv.org/repo/</ulink>"> 24<!ENTITY v4l-dvb "<ulink url='http://linuxtv.org/repo/'>http://linuxtv.org/repo/</ulink>">
25<!ENTITY dash-ent-10 "<entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry><entry>-</entry>">
25]> 26]>
26 27
27<book id="media_api"> 28<book id="media_api">
diff --git a/Documentation/devicetree/bindings/media/gpio-ir-receiver.txt b/Documentation/devicetree/bindings/media/gpio-ir-receiver.txt
new file mode 100644
index 000000000000..56e726ef4bf2
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/gpio-ir-receiver.txt
@@ -0,0 +1,16 @@
1Device-Tree bindings for GPIO IR receiver
2
3Required properties:
4 - compatible: should be "gpio-ir-receiver".
5 - gpios: specifies GPIO used for IR signal reception.
6
7Optional properties:
8 - linux,rc-map-name: Linux specific remote control map name.
9
10Example node:
11
12 ir: ir-receiver {
13 compatible = "gpio-ir-receiver";
14 gpios = <&gpio0 19 1>;
15 linux,rc-map-name = "rc-rc6-mce";
16 };
diff --git a/Documentation/dvb/get_dvb_firmware b/Documentation/dvb/get_dvb_firmware
index 32bc56b13b1c..5d5ee4c13fa6 100755
--- a/Documentation/dvb/get_dvb_firmware
+++ b/Documentation/dvb/get_dvb_firmware
@@ -23,7 +23,7 @@ use IO::Handle;
23 23
24@components = ( "sp8870", "sp887x", "tda10045", "tda10046", 24@components = ( "sp8870", "sp887x", "tda10045", "tda10046",
25 "tda10046lifeview", "av7110", "dec2000t", "dec2540t", 25 "tda10046lifeview", "av7110", "dec2000t", "dec2540t",
26 "dec3000s", "vp7041", "dibusb", "nxt2002", "nxt2004", 26 "dec3000s", "vp7041", "vp7049", "dibusb", "nxt2002", "nxt2004",
27 "or51211", "or51132_qam", "or51132_vsb", "bluebird", 27 "or51211", "or51132_qam", "or51132_vsb", "bluebird",
28 "opera1", "cx231xx", "cx18", "cx23885", "pvrusb2", "mpc718", 28 "opera1", "cx231xx", "cx18", "cx23885", "pvrusb2", "mpc718",
29 "af9015", "ngene", "az6027", "lme2510_lg", "lme2510c_s7395", 29 "af9015", "ngene", "az6027", "lme2510_lg", "lme2510c_s7395",
@@ -289,6 +289,19 @@ sub vp7041 {
289 $outfile; 289 $outfile;
290} 290}
291 291
292sub vp7049 {
293 my $fwfile = "dvb-usb-vp7049-0.95.fw";
294 my $url = "http://ao2.it/sites/default/files/blog/2012/11/06/linux-support-digicom-digitune-s-vp7049-udtt7049/$fwfile";
295 my $hash = "5609fd295168aea88b25ff43a6f79c36";
296
297 checkstandard();
298
299 wgetfile($fwfile, $url);
300 verify($fwfile, $hash);
301
302 $fwfile;
303}
304
292sub dibusb { 305sub dibusb {
293 my $url = "http://www.linuxtv.org/downloads/firmware/dvb-usb-dibusb-5.0.0.11.fw"; 306 my $url = "http://www.linuxtv.org/downloads/firmware/dvb-usb-dibusb-5.0.0.11.fw";
294 my $outfile = "dvb-dibusb-5.0.0.11.fw"; 307 my $outfile = "dvb-dibusb-5.0.0.11.fw";
@@ -677,7 +690,7 @@ sub drxk_terratec_h5 {
677} 690}
678 691
679sub drxk_terratec_htc_stick { 692sub drxk_terratec_htc_stick {
680 my $url = "http://ftp.terratec.de/Receiver/Cinergy_HTC_Stick/Updates/"; 693 my $url = "http://ftp.terratec.de/Receiver/Cinergy_HTC_Stick/Updates/History/";
681 my $zipfile = "Cinergy_HTC_Stick_Drv_5.09.1202.00_XP_Vista_7.exe"; 694 my $zipfile = "Cinergy_HTC_Stick_Drv_5.09.1202.00_XP_Vista_7.exe";
682 my $hash = "6722a2442a05423b781721fbc069ed5e"; 695 my $hash = "6722a2442a05423b781721fbc069ed5e";
683 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 0); 696 my $tmpdir = tempdir(DIR => "/tmp", CLEANUP => 0);
diff --git a/Documentation/media-framework.txt b/Documentation/media-framework.txt
index 802875413873..77bd0a42f19d 100644
--- a/Documentation/media-framework.txt
+++ b/Documentation/media-framework.txt
@@ -336,7 +336,7 @@ Calls to media_entity_pipeline_start() can be nested. The pipeline pointer must
336be identical for all nested calls to the function. 336be identical for all nested calls to the function.
337 337
338media_entity_pipeline_start() may return an error. In that case, it will 338media_entity_pipeline_start() may return an error. In that case, it will
339clean up any the changes it did by itself. 339clean up any of the changes it did by itself.
340 340
341When stopping the stream, drivers must notify the entities with 341When stopping the stream, drivers must notify the entities with
342 342
diff --git a/Documentation/video4linux/CARDLIST.au0828 b/Documentation/video4linux/CARDLIST.au0828
index a8a65753e544..55a21deab7db 100644
--- a/Documentation/video4linux/CARDLIST.au0828
+++ b/Documentation/video4linux/CARDLIST.au0828
@@ -1,5 +1,5 @@
1 0 -> Unknown board (au0828) 1 0 -> Unknown board (au0828)
2 1 -> Hauppauge HVR950Q (au0828) [2040:7200,2040:7210,2040:7217,2040:721b,2040:721e,2040:721f,2040:7280,0fd9:0008,2040:7260,2040:7213] 2 1 -> Hauppauge HVR950Q (au0828) [2040:7200,2040:7210,2040:7217,2040:721b,2040:721e,2040:721f,2040:7280,0fd9:0008,2040:7260,2040:7213,2040:7270]
3 2 -> Hauppauge HVR850 (au0828) [2040:7240] 3 2 -> Hauppauge HVR850 (au0828) [2040:7240]
4 3 -> DViCO FusionHDTV USB (au0828) [0fe9:d620] 4 3 -> DViCO FusionHDTV USB (au0828) [0fe9:d620]
5 4 -> Hauppauge HVR950Q rev xxF8 (au0828) [2040:7201,2040:7211,2040:7281] 5 4 -> Hauppauge HVR950Q rev xxF8 (au0828) [2040:7201,2040:7211,2040:7281]
diff --git a/Documentation/video4linux/CARDLIST.cx23885 b/Documentation/video4linux/CARDLIST.cx23885
index 1299b5e82d7f..9f056d512e35 100644
--- a/Documentation/video4linux/CARDLIST.cx23885
+++ b/Documentation/video4linux/CARDLIST.cx23885
@@ -36,3 +36,5 @@
36 35 -> TeVii S471 [d471:9022] 36 35 -> TeVii S471 [d471:9022]
37 36 -> Hauppauge WinTV-HVR1255 [0070:2259] 37 36 -> Hauppauge WinTV-HVR1255 [0070:2259]
38 37 -> Prof Revolution DVB-S2 8000 [8000:3034] 38 37 -> Prof Revolution DVB-S2 8000 [8000:3034]
39 38 -> Hauppauge WinTV-HVR4400 [0070:c108,0070:c138,0070:c12a,0070:c1f8]
40 39 -> AVerTV Hybrid Express Slim HC81R [1461:d939]
diff --git a/Documentation/video4linux/CARDLIST.em28xx b/Documentation/video4linux/CARDLIST.em28xx
index d99262dda533..3f12865b2a88 100644
--- a/Documentation/video4linux/CARDLIST.em28xx
+++ b/Documentation/video4linux/CARDLIST.em28xx
@@ -76,7 +76,7 @@
76 76 -> KWorld PlusTV 340U or UB435-Q (ATSC) (em2870) [1b80:a340] 76 76 -> KWorld PlusTV 340U or UB435-Q (ATSC) (em2870) [1b80:a340]
77 77 -> EM2874 Leadership ISDBT (em2874) 77 77 -> EM2874 Leadership ISDBT (em2874)
78 78 -> PCTV nanoStick T2 290e (em28174) 78 78 -> PCTV nanoStick T2 290e (em28174)
79 79 -> Terratec Cinergy H5 (em2884) [0ccd:008e,0ccd:00ac,0ccd:10a2,0ccd:10ad] 79 79 -> Terratec Cinergy H5 (em2884) [0ccd:10a2,0ccd:10ad]
80 80 -> PCTV DVB-S2 Stick (460e) (em28174) 80 80 -> PCTV DVB-S2 Stick (460e) (em28174)
81 81 -> Hauppauge WinTV HVR 930C (em2884) [2040:1605] 81 81 -> Hauppauge WinTV HVR 930C (em2884) [2040:1605]
82 82 -> Terratec Cinergy HTC Stick (em2884) [0ccd:00b2] 82 82 -> Terratec Cinergy HTC Stick (em2884) [0ccd:00b2]
@@ -84,3 +84,4 @@
84 84 -> MaxMedia UB425-TC (em2874) [1b80:e425] 84 84 -> MaxMedia UB425-TC (em2874) [1b80:e425]
85 85 -> PCTV QuatroStick (510e) (em2884) [2304:0242] 85 85 -> PCTV QuatroStick (510e) (em2884) [2304:0242]
86 86 -> PCTV QuatroStick nano (520e) (em2884) [2013:0251] 86 86 -> PCTV QuatroStick nano (520e) (em2884) [2013:0251]
87 87 -> Terratec Cinergy HTC USB XS (em2884) [0ccd:008e,0ccd:00ac]
diff --git a/Documentation/video4linux/CARDLIST.saa7134 b/Documentation/video4linux/CARDLIST.saa7134
index 94d9025aa82d..b3ad68309109 100644
--- a/Documentation/video4linux/CARDLIST.saa7134
+++ b/Documentation/video4linux/CARDLIST.saa7134
@@ -189,3 +189,4 @@
189188 -> Sensoray 811/911 [6000:0811,6000:0911] 189188 -> Sensoray 811/911 [6000:0811,6000:0911]
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
diff --git a/Documentation/video4linux/et61x251.txt b/Documentation/video4linux/et61x251.txt
deleted file mode 100644
index e0cdae491858..000000000000
--- a/Documentation/video4linux/et61x251.txt
+++ /dev/null
@@ -1,315 +0,0 @@
1
2 ET61X[12]51 PC Camera Controllers
3 Driver for Linux
4 =================================
5
6 - Documentation -
7
8
9Index
10=====
111. Copyright
122. Disclaimer
133. License
144. Overview and features
155. Module dependencies
166. Module loading
177. Module parameters
188. Optional device control through "sysfs"
199. Supported devices
2010. Notes for V4L2 application developers
2111. Contact information
22
23
241. Copyright
25============
26Copyright (C) 2006-2007 by Luca Risolia <luca.risolia@studio.unibo.it>
27
28
292. Disclaimer
30=============
31Etoms is a trademark of Etoms Electronics Corp.
32This software is not developed or sponsored by Etoms Electronics.
33
34
353. License
36==========
37This program is free software; you can redistribute it and/or modify
38it under the terms of the GNU General Public License as published by
39the Free Software Foundation; either version 2 of the License, or
40(at your option) any later version.
41
42This program is distributed in the hope that it will be useful,
43but WITHOUT ANY WARRANTY; without even the implied warranty of
44MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45GNU General Public License for more details.
46
47You should have received a copy of the GNU General Public License
48along with this program; if not, write to the Free Software
49Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
50
51
524. Overview and features
53========================
54This driver supports the video interface of the devices mounting the ET61X151
55or ET61X251 PC Camera Controllers.
56
57It's worth to note that Etoms Electronics has never collaborated with the
58author during the development of this project; despite several requests,
59Etoms Electronics also refused to release enough detailed specifications of
60the video compression engine.
61
62The driver relies on the Video4Linux2 and USB core modules. It has been
63designed to run properly on SMP systems as well.
64
65The latest version of the ET61X[12]51 driver can be found at the following URL:
66http://www.linux-projects.org/
67
68Some of the features of the driver are:
69
70- full compliance with the Video4Linux2 API (see also "Notes for V4L2
71 application developers" paragraph);
72- available mmap or read/poll methods for video streaming through isochronous
73 data transfers;
74- automatic detection of image sensor;
75- support for any window resolutions and optional panning within the maximum
76 pixel area of image sensor;
77- image downscaling with arbitrary scaling factors from 1 and 2 in both
78 directions (see "Notes for V4L2 application developers" paragraph);
79- two different video formats for uncompressed or compressed data in low or
80 high compression quality (see also "Notes for V4L2 application developers"
81 paragraph);
82- full support for the capabilities of every possible image sensors that can
83 be connected to the ET61X[12]51 bridges, including, for instance, red, green,
84 blue and global gain adjustments and exposure control (see "Supported
85 devices" paragraph for details);
86- use of default color settings for sunlight conditions;
87- dynamic I/O interface for both ET61X[12]51 and image sensor control (see
88 "Optional device control through 'sysfs'" paragraph);
89- dynamic driver control thanks to various module parameters (see "Module
90 parameters" paragraph);
91- up to 64 cameras can be handled at the same time; they can be connected and
92 disconnected from the host many times without turning off the computer, if
93 the system supports hotplugging;
94- no known bugs.
95
96
975. Module dependencies
98======================
99For it to work properly, the driver needs kernel support for Video4Linux and
100USB.
101
102The following options of the kernel configuration file must be enabled and
103corresponding modules must be compiled:
104
105 # Multimedia devices
106 #
107 CONFIG_VIDEO_DEV=m
108
109To enable advanced debugging functionality on the device through /sysfs:
110
111 # Multimedia devices
112 #
113 CONFIG_VIDEO_ADV_DEBUG=y
114
115 # USB support
116 #
117 CONFIG_USB=m
118
119In addition, depending on the hardware being used, the modules below are
120necessary:
121
122 # USB Host Controller Drivers
123 #
124 CONFIG_USB_EHCI_HCD=m
125 CONFIG_USB_UHCI_HCD=m
126 CONFIG_USB_OHCI_HCD=m
127
128And finally:
129
130 # USB Multimedia devices
131 #
132 CONFIG_USB_ET61X251=m
133
134
1356. Module loading
136=================
137To use the driver, it is necessary to load the "et61x251" module into memory
138after every other module required: "videodev", "v4l2_common", "compat_ioctl32",
139"usbcore" and, depending on the USB host controller you have, "ehci-hcd",
140"uhci-hcd" or "ohci-hcd".
141
142Loading can be done as shown below:
143
144 [root@localhost home]# modprobe et61x251
145
146At this point the devices should be recognized. You can invoke "dmesg" to
147analyze kernel messages and verify that the loading process has gone well:
148
149 [user@localhost home]$ dmesg
150
151
1527. Module parameters
153====================
154Module parameters are listed below:
155-------------------------------------------------------------------------------
156Name: video_nr
157Type: short array (min = 0, max = 64)
158Syntax: <-1|n[,...]>
159Description: Specify V4L2 minor mode number:
160 -1 = use next available
161 n = use minor number n
162 You can specify up to 64 cameras this way.
163 For example:
164 video_nr=-1,2,-1 would assign minor number 2 to the second
165 registered camera and use auto for the first one and for every
166 other camera.
167Default: -1
168-------------------------------------------------------------------------------
169Name: force_munmap
170Type: bool array (min = 0, max = 64)
171Syntax: <0|1[,...]>
172Description: Force the application to unmap previously mapped buffer memory
173 before calling any VIDIOC_S_CROP or VIDIOC_S_FMT ioctl's. Not
174 all the applications support this feature. This parameter is
175 specific for each detected camera.
176 0 = do not force memory unmapping
177 1 = force memory unmapping (save memory)
178Default: 0
179-------------------------------------------------------------------------------
180Name: frame_timeout
181Type: uint array (min = 0, max = 64)
182Syntax: <n[,...]>
183Description: Timeout for a video frame in seconds. This parameter is
184 specific for each detected camera. This parameter can be
185 changed at runtime thanks to the /sys filesystem interface.
186Default: 2
187-------------------------------------------------------------------------------
188Name: debug
189Type: ushort
190Syntax: <n>
191Description: Debugging information level, from 0 to 3:
192 0 = none (use carefully)
193 1 = critical errors
194 2 = significant information
195 3 = more verbose messages
196 Level 3 is useful for testing only, when only one device
197 is used at the same time. It also shows some more information
198 about the hardware being detected. This module parameter can be
199 changed at runtime thanks to the /sys filesystem interface.
200Default: 2
201-------------------------------------------------------------------------------
202
203
2048. Optional device control through "sysfs"
205==========================================
206If the kernel has been compiled with the CONFIG_VIDEO_ADV_DEBUG option enabled,
207it is possible to read and write both the ET61X[12]51 and the image sensor
208registers by using the "sysfs" filesystem interface.
209
210There are four files in the /sys/class/video4linux/videoX directory for each
211registered camera: "reg", "val", "i2c_reg" and "i2c_val". The first two files
212control the ET61X[12]51 bridge, while the other two control the sensor chip.
213"reg" and "i2c_reg" hold the values of the current register index where the
214following reading/writing operations are addressed at through "val" and
215"i2c_val". Their use is not intended for end-users, unless you know what you
216are doing. Remember that you must be logged in as root before writing to them.
217
218As an example, suppose we were to want to read the value contained in the
219register number 1 of the sensor register table - which is usually the product
220identifier - of the camera registered as "/dev/video0":
221
222 [root@localhost #] cd /sys/class/video4linux/video0
223 [root@localhost #] echo 1 > i2c_reg
224 [root@localhost #] cat i2c_val
225
226Note that if the sensor registers cannot be read, "cat" will fail.
227To avoid race conditions, all the I/O accesses to the files are serialized.
228
229
2309. Supported devices
231====================
232None of the names of the companies as well as their products will be mentioned
233here. They have never collaborated with the author, so no advertising.
234
235From the point of view of a driver, what unambiguously identify a device are
236its vendor and product USB identifiers. Below is a list of known identifiers of
237devices mounting the ET61X[12]51 PC camera controllers:
238
239Vendor ID Product ID
240--------- ----------
2410x102c 0x6151
2420x102c 0x6251
2430x102c 0x6253
2440x102c 0x6254
2450x102c 0x6255
2460x102c 0x6256
2470x102c 0x6257
2480x102c 0x6258
2490x102c 0x6259
2500x102c 0x625a
2510x102c 0x625b
2520x102c 0x625c
2530x102c 0x625d
2540x102c 0x625e
2550x102c 0x625f
2560x102c 0x6260
2570x102c 0x6261
2580x102c 0x6262
2590x102c 0x6263
2600x102c 0x6264
2610x102c 0x6265
2620x102c 0x6266
2630x102c 0x6267
2640x102c 0x6268
2650x102c 0x6269
266
267The following image sensors are supported:
268
269Model Manufacturer
270----- ------------
271TAS5130D1B Taiwan Advanced Sensor Corporation
272
273All the available control settings of each image sensor are supported through
274the V4L2 interface.
275
276
27710. Notes for V4L2 application developers
278=========================================
279This driver follows the V4L2 API specifications. In particular, it enforces two
280rules:
281
282- exactly one I/O method, either "mmap" or "read", is associated with each
283file descriptor. Once it is selected, the application must close and reopen the
284device to switch to the other I/O method;
285
286- although it is not mandatory, previously mapped buffer memory should always
287be unmapped before calling any "VIDIOC_S_CROP" or "VIDIOC_S_FMT" ioctl's.
288The same number of buffers as before will be allocated again to match the size
289of the new video frames, so you have to map the buffers again before any I/O
290attempts on them.
291
292Consistently with the hardware limits, this driver also supports image
293downscaling with arbitrary scaling factors from 1 and 2 in both directions.
294However, the V4L2 API specifications don't correctly define how the scaling
295factor can be chosen arbitrarily by the "negotiation" of the "source" and
296"target" rectangles. To work around this flaw, we have added the convention
297that, during the negotiation, whenever the "VIDIOC_S_CROP" ioctl is issued, the
298scaling factor is restored to 1.
299
300This driver supports two different video formats: the first one is the "8-bit
301Sequential Bayer" format and can be used to obtain uncompressed video data
302from the device through the current I/O method, while the second one provides
303"raw" compressed video data (without frame headers not related to the
304compressed data). The current compression quality may vary from 0 to 1 and can
305be selected or queried thanks to the VIDIOC_S_JPEGCOMP and VIDIOC_G_JPEGCOMP
306V4L2 ioctl's.
307
308
30911. Contact information
310=======================
311The author may be contacted by e-mail at <luca.risolia@studio.unibo.it>.
312
313GPG/PGP encrypted e-mail's are accepted. The GPG key ID of the author is
314'FCE635A4'; the public 1024-bit key should be available at any keyserver;
315the fingerprint is: '88E8 F32F 7244 68BA 3958 5D40 99DA 5D2A FCE6 35A4'.
diff --git a/Documentation/video4linux/extract_xc3028.pl b/Documentation/video4linux/extract_xc3028.pl
index 47877deae6d7..47877deae6d7 100644..100755
--- a/Documentation/video4linux/extract_xc3028.pl
+++ b/Documentation/video4linux/extract_xc3028.pl
diff --git a/Documentation/video4linux/fimc.txt b/Documentation/video4linux/fimc.txt
index fd02d9a4930a..25f4d3402722 100644
--- a/Documentation/video4linux/fimc.txt
+++ b/Documentation/video4linux/fimc.txt
@@ -58,7 +58,7 @@ Not currently supported:
584.1. Media device interface 584.1. Media device interface
59 59
60The driver supports Media Controller API as defined at 60The driver supports Media Controller API as defined at
61http://http://linuxtv.org/downloads/v4l-dvb-apis/media_common.html 61http://linuxtv.org/downloads/v4l-dvb-apis/media_common.html
62The media device driver name is "SAMSUNG S5P FIMC". 62The media device driver name is "SAMSUNG S5P FIMC".
63 63
64The purpose of this interface is to allow changing assignment of FIMC instances 64The purpose of this interface is to allow changing assignment of FIMC instances
diff --git a/Documentation/video4linux/ibmcam.txt b/Documentation/video4linux/ibmcam.txt
deleted file mode 100644
index a51055211e62..000000000000
--- a/Documentation/video4linux/ibmcam.txt
+++ /dev/null
@@ -1,323 +0,0 @@
1README for Linux device driver for the IBM "C-It" USB video camera
2
3INTRODUCTION:
4
5This driver does not use all features known to exist in
6the IBM camera. However most of needed features work well.
7
8This driver was developed using logs of observed USB traffic
9which was produced by standard Windows driver (c-it98.sys).
10I did not have data sheets from Xirlink.
11
12Video formats:
13 128x96 [model 1]
14 176x144
15 320x240 [model 2]
16 352x240 [model 2]
17 352x288
18Frame rate: 3 - 30 frames per second (FPS)
19External interface: USB
20Internal interface: Video For Linux (V4L)
21Supported controls:
22- by V4L: Contrast, Brightness, Color, Hue
23- by driver options: frame rate, lighting conditions, video format,
24 default picture settings, sharpness.
25
26SUPPORTED CAMERAS:
27
28Xirlink "C-It" camera, also known as "IBM PC Camera".
29The device uses proprietary ASIC (and compression method);
30it is manufactured by Xirlink. See http://xirlinkwebcam.sourceforge.net,
31http://www.ibmpccamera.com, or http://www.c-itnow.com/ for details and pictures.
32
33This very chipset ("X Chip", as marked at the factory)
34is used in several other cameras, and they are supported
35as well:
36
37- IBM NetCamera
38- Veo Stingray
39
40The Linux driver was developed with camera with following
41model number (or FCC ID): KSX-XVP510. This camera has three
42interfaces, each with one endpoint (control, iso, iso). This
43type of cameras is referred to as "model 1". These cameras are
44no longer manufactured.
45
46Xirlink now manufactures new cameras which are somewhat different.
47In particular, following models [FCC ID] belong to that category:
48
49XVP300 [KSX-X9903]
50XVP600 [KSX-X9902]
51XVP610 [KSX-X9902]
52
53(see http://www.xirlink.com/ibmpccamera/ for updates, they refer
54to these new cameras by Windows driver dated 12-27-99, v3005 BETA)
55These cameras have two interfaces, one endpoint in each (iso, bulk).
56Such type of cameras is referred to as "model 2". They are supported
57(with exception of 352x288 native mode).
58
59Some IBM NetCameras (Model 4) are made to generate only compressed
60video streams. This is great for performance, but unfortunately
61nobody knows how to decompress the stream :-( Therefore, these
62cameras are *unsupported* and if you try to use one of those, all
63you get is random colored horizontal streaks, not the image!
64If you have one of those cameras, you probably should return it
65to the store and get something that is supported.
66
67Tell me more about all that "model" business
68--------------------------------------------
69
70I just invented model numbers to uniquely identify flavors of the
71hardware/firmware that were sold. It was very confusing to use
72brand names or some other internal numbering schemes. So I found
73by experimentation that all Xirlink chipsets fall into four big
74classes, and I called them "models". Each model is programmed in
75its own way, and each model sends back the video in its own way.
76
77Quirks of Model 2 cameras:
78-------------------------
79
80Model 2 does not have hardware contrast control. Corresponding V4L
81control is implemented in software, which is not very nice to your
82CPU, but at least it works.
83
84This driver provides 352x288 mode by switching the camera into
85quasi-352x288 RGB mode (800 Kbits per frame) essentially limiting
86this mode to 10 frames per second or less, in ideal conditions on
87the bus (USB is shared, after all). The frame rate
88has to be programmed very conservatively. Additional concern is that
89frame rate depends on brightness setting; therefore the picture can
90be good at one brightness and broken at another! I did not want to fix
91the frame rate at slowest setting, but I had to move it pretty much down
92the scale (so that framerate option barely matters). I also noticed that
93camera after first powering up produces frames slightly faster than during
94consecutive uses. All this means that if you use 352x288 (which is
95default), be warned - you may encounter broken picture on first connect;
96try to adjust brightness - brighter image is slower, so USB will be able
97to send all data. However if you regularly use Model 2 cameras you may
98prefer 176x144 which makes perfectly good I420, with no scaling and
99lesser demands on USB (300 Kbits per second, or 26 frames per second).
100
101Another strange effect of 352x288 mode is the fine vertical grid visible
102on some colored surfaces. I am sure it is caused by me not understanding
103what the camera is trying to say. Blame trade secrets for that.
104
105The camera that I had also has a hardware quirk: if disconnected,
106it needs few minutes to "relax" before it can be plugged in again
107(poorly designed USB processor reset circuit?)
108
109[Veo Stingray with Product ID 0x800C is also Model 2, but I haven't
110observed this particular flaw in it.]
111
112Model 2 camera can be programmed for very high sensitivity (even starlight
113may be enough), this makes it convenient for tinkering with. The driver
114code has enough comments to help a programmer to tweak the camera
115as s/he feels necessary.
116
117WHAT YOU NEED:
118
119- A supported IBM PC (C-it) camera (model 1 or 2)
120
121- A Linux box with USB support (2.3/2.4; 2.2 w/backport may work)
122
123- A Video4Linux compatible frame grabber program such as xawtv.
124
125HOW TO COMPILE THE DRIVER:
126
127You need to compile the driver only if you are a developer
128or if you want to make changes to the code. Most distributions
129precompile all modules, so you can go directly to the next
130section "HOW TO USE THE DRIVER".
131
132The ibmcam driver uses usbvideo helper library (module),
133so if you are studying the ibmcam code you will be led there.
134
135The driver itself consists of only one file in usb/ directory:
136ibmcam.c. This file is included into the Linux kernel build
137process if you configure the kernel for CONFIG_USB_IBMCAM.
138Run "make xconfig" and in USB section you will find the IBM
139camera driver. Select it, save the configuration and recompile.
140
141HOW TO USE THE DRIVER:
142
143I recommend to compile driver as a module. This gives you an
144easier access to its configuration. The camera has many more
145settings than V4L can operate, so some settings are done using
146module options.
147
148To begin with, on most modern Linux distributions the driver
149will be automatically loaded whenever you plug the supported
150camera in. Therefore, you don't need to do anything. However
151if you want to experiment with some module parameters then
152you can load and unload the driver manually, with camera
153plugged in or unplugged.
154
155Typically module is installed with command 'modprobe', like this:
156
157# modprobe ibmcam framerate=1
158
159Alternatively you can use 'insmod' in similar fashion:
160
161# insmod /lib/modules/2.x.y/usb/ibmcam.o framerate=1
162
163Module can be inserted with camera connected or disconnected.
164
165The driver can have options, though some defaults are provided.
166
167Driver options: (* indicates that option is model-dependent)
168
169Name Type Range [default] Example
170-------------- -------------- -------------- ------------------
171debug Integer 0-9 [0] debug=1
172flags Integer 0-0xFF [0] flags=0x0d
173framerate Integer 0-6 [2] framerate=1
174hue_correction Integer 0-255 [128] hue_correction=115
175init_brightness Integer 0-255 [128] init_brightness=100
176init_contrast Integer 0-255 [192] init_contrast=200
177init_color Integer 0-255 [128] init_color=130
178init_hue Integer 0-255 [128] init_hue=115
179lighting Integer 0-2* [1] lighting=2
180sharpness Integer 0-6* [4] sharpness=3
181size Integer 0-2* [2] size=1
182
183Options for Model 2 only:
184
185Name Type Range [default] Example
186-------------- -------------- -------------- ------------------
187init_model2_rg Integer 0..255 [0x70] init_model2_rg=128
188init_model2_rg2 Integer 0..255 [0x2f] init_model2_rg2=50
189init_model2_sat Integer 0..255 [0x34] init_model2_sat=65
190init_model2_yb Integer 0..255 [0xa0] init_model2_yb=200
191
192debug You don't need this option unless you are a developer.
193 If you are a developer then you will see in the code
194 what values do what. 0=off.
195
196flags This is a bit mask, and you can combine any number of
197 bits to produce what you want. Usually you don't want
198 any of extra features this option provides:
199
200 FLAGS_RETRY_VIDIOCSYNC 1 This bit allows to retry failed
201 VIDIOCSYNC ioctls without failing.
202 Will work with xawtv, will not
203 with xrealproducer. Default is
204 not set.
205 FLAGS_MONOCHROME 2 Activates monochrome (b/w) mode.
206 FLAGS_DISPLAY_HINTS 4 Shows colored pixels which have
207 magic meaning to developers.
208 FLAGS_OVERLAY_STATS 8 Shows tiny numbers on screen,
209 useful only for debugging.
210 FLAGS_FORCE_TESTPATTERN 16 Shows blue screen with numbers.
211 FLAGS_SEPARATE_FRAMES 32 Shows each frame separately, as
212 it was received from the camera.
213 Default (not set) is to mix the
214 preceding frame in to compensate
215 for occasional loss of Isoc data
216 on high frame rates.
217 FLAGS_CLEAN_FRAMES 64 Forces "cleanup" of each frame
218 prior to use; relevant only if
219 FLAGS_SEPARATE_FRAMES is set.
220 Default is not to clean frames,
221 this is a little faster but may
222 produce flicker if frame rate is
223 too high and Isoc data gets lost.
224 FLAGS_NO_DECODING 128 This flag turns the video stream
225 decoder off, and dumps the raw
226 Isoc data from the camera into
227 the reading process. Useful to
228 developers, but not to users.
229
230framerate This setting controls frame rate of the camera. This is
231 an approximate setting (in terms of "worst" ... "best")
232 because camera changes frame rate depending on amount
233 of light available. Setting 0 is slowest, 6 is fastest.
234 Beware - fast settings are very demanding and may not
235 work well with all video sizes. Be conservative.
236
237hue_correction This highly optional setting allows to adjust the
238 hue of the image in a way slightly different from
239 what usual "hue" control does. Both controls affect
240 YUV colorspace: regular "hue" control adjusts only
241 U component, and this "hue_correction" option similarly
242 adjusts only V component. However usually it is enough
243 to tweak only U or V to compensate for colored light or
244 color temperature; this option simply allows more
245 complicated correction when and if it is necessary.
246
247init_brightness These settings specify _initial_ values which will be
248init_contrast used to set up the camera. If your V4L application has
249init_color its own controls to adjust the picture then these
250init_hue controls will be used too. These options allow you to
251 preconfigure the camera when it gets connected, before
252 any V4L application connects to it. Good for webcams.
253
254init_model2_rg These initial settings alter color balance of the
255init_model2_rg2 camera on hardware level. All four settings may be used
256init_model2_sat to tune the camera to specific lighting conditions. These
257init_model2_yb settings only apply to Model 2 cameras.
258
259lighting This option selects one of three hardware-defined
260 photosensitivity settings of the camera. 0=bright light,
261 1=Medium (default), 2=Low light. This setting affects
262 frame rate: the dimmer the lighting the lower the frame
263 rate (because longer exposition time is needed). The
264 Model 2 cameras allow values more than 2 for this option,
265 thus enabling extremely high sensitivity at cost of frame
266 rate, color saturation and imaging sensor noise.
267
268sharpness This option controls smoothing (noise reduction)
269 made by camera. Setting 0 is most smooth, setting 6
270 is most sharp. Be aware that CMOS sensor used in the
271 camera is pretty noisy, so if you choose 6 you will
272 be greeted with "snowy" image. Default is 4. Model 2
273 cameras do not support this feature.
274
275size This setting chooses one of several image sizes that are
276 supported by this driver. Cameras may support more, but
277 it's difficult to reverse-engineer all formats.
278 Following video sizes are supported:
279
280 size=0 128x96 (Model 1 only)
281 size=1 160x120
282 size=2 176x144
283 size=3 320x240 (Model 2 only)
284 size=4 352x240 (Model 2 only)
285 size=5 352x288
286 size=6 640x480 (Model 3 only)
287
288 The 352x288 is the native size of the Model 1 sensor
289 array, so it's the best resolution the camera can
290 yield. The best resolution of Model 2 is 176x144, and
291 larger images are produced by stretching the bitmap.
292 Model 3 has sensor with 640x480 grid, and it works too,
293 but the frame rate will be exceptionally low (1-2 FPS);
294 it may be still OK for some applications, like security.
295 Choose the image size you need. The smaller image can
296 support faster frame rate. Default is 352x288.
297
298For more information and the Troubleshooting FAQ visit this URL:
299
300 http://www.linux-usb.org/ibmcam/
301
302WHAT NEEDS TO BE DONE:
303
304- The button on the camera is not used. I don't know how to get to it.
305 I know now how to read button on Model 2, but what to do with it?
306
307- Camera reports its status back to the driver; however I don't know
308 what returned data means. If camera fails at some initialization
309 stage then something should be done, and I don't do that because
310 I don't even know that some command failed. This is mostly Model 1
311 concern because Model 2 uses different commands which do not return
312 status (and seem to complete successfully every time).
313
314- Some flavors of Model 4 NetCameras produce only compressed video
315 streams, and I don't know how to decode them.
316
317CREDITS:
318
319The code is based in no small part on the CPiA driver by Johannes Erdfelt,
320Randy Dunlap, and others. Big thanks to them for their pioneering work on that
321and the USB stack.
322
323I also thank John Lightsey for his donation of the Veo Stingray camera.
diff --git a/Documentation/video4linux/m5602.txt b/Documentation/video4linux/m5602.txt
deleted file mode 100644
index 4450ab13f37b..000000000000
--- a/Documentation/video4linux/m5602.txt
+++ /dev/null
@@ -1,12 +0,0 @@
1This document describes the ALi m5602 bridge connected
2to the following supported sensors:
3OmniVision OV9650,
4Samsung s5k83a,
5Samsung s5k4aa,
6Micron mt9m111,
7Pixel plus PO1030
8
9This driver mimics the windows drivers, which have a braindead implementation sending bayer-encoded frames at VGA resolution.
10In a perfect world we should be able to reprogram the m5602 and the connected sensor in hardware instead, supporting a range of resolutions and pixelformats
11
12Anyway, have fun and please report any bugs to m560x-driver-devel@lists.sourceforge.net
diff --git a/Documentation/video4linux/ov511.txt b/Documentation/video4linux/ov511.txt
deleted file mode 100644
index b3326b167ada..000000000000
--- a/Documentation/video4linux/ov511.txt
+++ /dev/null
@@ -1,288 +0,0 @@
1-------------------------------------------------------------------------------
2Readme for Linux device driver for the OmniVision OV511 USB to camera bridge IC
3-------------------------------------------------------------------------------
4
5Author: Mark McClelland
6Homepage: http://alpha.dyndns.org/ov511
7
8INTRODUCTION:
9
10This is a driver for the OV511, a USB-only chip used in many "webcam" devices.
11Any camera using the OV511/OV511+ and the OV6620/OV7610/20/20AE should work.
12Video capture devices that use the Philips SAA7111A decoder also work. It
13supports streaming and capture of color or monochrome video via the Video4Linux
14API. Most V4L apps are compatible with it. Most resolutions with a width and
15height that are a multiple of 8 are supported.
16
17If you need more information, please visit the OV511 homepage at the above URL.
18
19WHAT YOU NEED:
20
21- If you want to help with the development, get the chip's specification docs at
22 http://www.ovt.com/omniusbp.html
23
24- A Video4Linux compatible frame grabber program (I recommend vidcat and xawtv)
25 vidcat is part of the w3cam package: http://mpx.freeshell.net/
26 xawtv is available at: http://linux.bytesex.org/xawtv/
27
28HOW TO USE IT:
29
30Note: These are simplified instructions. For complete instructions see:
31 http://alpha.dyndns.org/ov511/install.html
32
33You must have first compiled USB support, support for your specific USB host
34controller (UHCI or OHCI), and Video4Linux support for your kernel (I recommend
35making them modules.) Make sure "Enforce bandwidth allocation" is NOT enabled.
36
37Next, (as root):
38
39 modprobe usbcore
40 modprobe usb-uhci <OR> modprobe usb-ohci
41 modprobe videodev
42 modprobe ov511
43
44If it is not already there (it usually is), create the video device:
45
46 mknod /dev/video0 c 81 0
47
48Optionally, symlink /dev/video to /dev/video0
49
50You will have to set permissions on this device to allow you to read/write
51from it:
52
53 chmod 666 /dev/video
54 chmod 666 /dev/video0 (if necessary)
55
56Now you are ready to run a video app! Both vidcat and xawtv work well for me
57at 640x480.
58
59[Using vidcat:]
60
61 vidcat -s 640x480 -p c > test.jpg
62 xview test.jpg
63
64[Using xawtv:]
65
66From the main xawtv directory:
67
68 make clean
69 ./configure
70 make
71 make install
72
73Now you should be able to run xawtv. Right click for the options dialog.
74
75MODULE PARAMETERS:
76
77 You can set these with: insmod ov511 NAME=VALUE
78 There is currently no way to set these on a per-camera basis.
79
80 NAME: autobright
81 TYPE: integer (Boolean)
82 DEFAULT: 1
83 DESC: Brightness is normally under automatic control and can't be set
84 manually by the video app. Set to 0 for manual control.
85
86 NAME: autogain
87 TYPE: integer (Boolean)
88 DEFAULT: 1
89 DESC: Auto Gain Control enable. This feature is not yet implemented.
90
91 NAME: autoexp
92 TYPE: integer (Boolean)
93 DEFAULT: 1
94 DESC: Auto Exposure Control enable. This feature is not yet implemented.
95
96 NAME: debug
97 TYPE: integer (0-6)
98 DEFAULT: 3
99 DESC: Sets the threshold for printing debug messages. The higher the value,
100 the more is printed. The levels are cumulative, and are as follows:
101 0=no debug messages
102 1=init/detection/unload and other significant messages
103 2=some warning messages
104 3=config/control function calls
105 4=most function calls and data parsing messages
106 5=highly repetitive mesgs
107
108 NAME: snapshot
109 TYPE: integer (Boolean)
110 DEFAULT: 0
111 DESC: Set to 1 to enable snapshot mode. read()/VIDIOCSYNC will block until
112 the snapshot button is pressed. Note: enabling this mode disables
113 /proc/video/ov511/<minor#>/button
114
115 NAME: cams
116 TYPE: integer (1-4 for OV511, 1-31 for OV511+)
117 DEFAULT: 1
118 DESC: Number of cameras allowed to stream simultaneously on a single bus.
119 Values higher than 1 reduce the data rate of each camera, allowing two
120 or more to be used at once. If you have a complicated setup involving
121 both OV511 and OV511+ cameras, trial-and-error may be necessary for
122 finding the optimum setting.
123
124 NAME: compress
125 TYPE: integer (Boolean)
126 DEFAULT: 0
127 DESC: Set this to 1 to turn on the camera's compression engine. This can
128 potentially increase the frame rate at the expense of quality, if you
129 have a fast CPU. You must load the proper compression module for your
130 camera before starting your application (ov511_decomp or ov518_decomp).
131
132 NAME: testpat
133 TYPE: integer (Boolean)
134 DEFAULT: 0
135 DESC: This configures the camera's sensor to transmit a colored test-pattern
136 instead of an image. This does not work correctly yet.
137
138 NAME: dumppix
139 TYPE: integer (0-2)
140 DEFAULT: 0
141 DESC: Dumps raw pixel data and skips post-processing and format conversion.
142 It is for debugging purposes only. Options are:
143 0: Disable (default)
144 1: Dump raw data from camera, excluding headers and trailers
145 2: Dumps data exactly as received from camera
146
147 NAME: led
148 TYPE: integer (0-2)
149 DEFAULT: 1 (Always on)
150 DESC: Controls whether the LED (the little light) on the front of the camera
151 is always off (0), always on (1), or only on when driver is open (2).
152 This is not supported with the OV511, and might only work with certain
153 cameras (ones that actually have the LED wired to the control pin, and
154 not just hard-wired to be on all the time).
155
156 NAME: dump_bridge
157 TYPE: integer (Boolean)
158 DEFAULT: 0
159 DESC: Dumps the bridge (OV511[+] or OV518[+]) register values to the system
160 log. Only useful for serious debugging/development purposes.
161
162 NAME: dump_sensor
163 TYPE: integer (Boolean)
164 DEFAULT: 0
165 DESC: Dumps the sensor register values to the system log. Only useful for
166 serious debugging/development purposes.
167
168 NAME: printph
169 TYPE: integer (Boolean)
170 DEFAULT: 0
171 DESC: Setting this to 1 will dump the first 12 bytes of each isoc frame. This
172 is only useful if you are trying to debug problems with the isoc data
173 stream (i.e.: camera initializes, but vidcat hangs until Ctrl-C). Be
174 warned that this dumps a large number of messages to your kernel log.
175
176 NAME: phy, phuv, pvy, pvuv, qhy, qhuv, qvy, qvuv
177 TYPE: integer (0-63 for phy and phuv, 0-255 for rest)
178 DEFAULT: OV511 default values
179 DESC: These are registers 70h - 77h of the OV511, which control the
180 prediction ranges and quantization thresholds of the compressor, for
181 the Y and UV channels in the horizontal and vertical directions. See
182 the OV511 or OV511+ data sheet for more detailed descriptions. These
183 normally do not need to be changed.
184
185 NAME: lightfreq
186 TYPE: integer (0, 50, or 60)
187 DEFAULT: 0 (use sensor default)
188 DESC: Sets the sensor to match your lighting frequency. This can reduce the
189 appearance of "banding", i.e. horizontal lines or waves of light and
190 dark that are often caused by artificial lighting. Valid values are:
191 0 - Use default (depends on sensor, most likely 60 Hz)
192 50 - For European and Asian 50 Hz power
193 60 - For American 60 Hz power
194
195 NAME: bandingfilter
196 TYPE: integer (Boolean)
197 DEFAULT: 0 (off)
198 DESC: Enables the sensor´s banding filter exposure algorithm. This reduces
199 or stabilizes the "banding" caused by some artificial light sources
200 (especially fluorescent). You might have to set lightfreq correctly for
201 this to work right. As an added bonus, this sometimes makes it
202 possible to capture your monitor´s output.
203
204 NAME: fastset
205 TYPE: integer (Boolean)
206 DEFAULT: 0 (off)
207 DESC: Allows picture settings (brightness, contrast, color, and hue) to take
208 effect immediately, even in the middle of a frame. This reduces the
209 time to change settings, but can ruin frames during the change. Only
210 affects OmniVision sensors.
211
212 NAME: force_palette
213 TYPE: integer (Boolean)
214 DEFAULT: 0 (off)
215 DESC: Forces the palette (color format) to a specific value. If an
216 application requests a different palette, it will be rejected, thereby
217 forcing it to try others until it succeeds. This is useful for forcing
218 greyscale mode with a color camera, for example. Supported modes are:
219 0 (Allows all the following formats)
220 1 VIDEO_PALETTE_GREY (Linear greyscale)
221 10 VIDEO_PALETTE_YUV420 (YUV 4:2:0 Planar)
222 15 VIDEO_PALETTE_YUV420P (YUV 4:2:0 Planar, same as 10)
223
224 NAME: backlight
225 TYPE: integer (Boolean)
226 DEFAULT: 0 (off)
227 DESC: Setting this flag changes the exposure algorithm for OmniVision sensors
228 such that objects in the camera's view (i.e. your head) can be clearly
229 seen when they are illuminated from behind. It reduces or eliminates
230 the sensor's auto-exposure function, so it should only be used when
231 needed. Additionally, it is only supported with the OV6620 and OV7620.
232
233 NAME: unit_video
234 TYPE: Up to 16 comma-separated integers
235 DEFAULT: 0,0,0... (automatically assign the next available minor(s))
236 DESC: You can specify up to 16 minor numbers to be assigned to ov511 devices.
237 For example, "unit_video=1,3" will make the driver use /dev/video1 and
238 /dev/video3 for the first two devices it detects. Additional devices
239 will be assigned automatically starting at the first available device
240 node (/dev/video0 in this case). Note that you cannot specify 0 as a
241 minor number. This feature requires kernel version 2.4.5 or higher.
242
243 NAME: remove_zeros
244 TYPE: integer (Boolean)
245 DEFAULT: 0 (do not skip any incoming data)
246 DESC: Setting this to 1 will remove zero-padding from incoming data. This
247 will compensate for the blocks of corruption that can appear when the
248 camera cannot keep up with the speed of the USB bus (eg. at low frame
249 resolutions). This feature is always enabled when compression is on.
250
251 NAME: mirror
252 TYPE: integer (Boolean)
253 DEFAULT: 0 (off)
254 DESC: Setting this to 1 will reverse ("mirror") the image horizontally. This
255 might be necessary if your camera has a custom lens assembly. This has
256 no effect with video capture devices.
257
258 NAME: ov518_color
259 TYPE: integer (Boolean)
260 DEFAULT: 0 (off)
261 DESC: Enable OV518 color support. This is off by default since it doesn't
262 work most of the time. If you want to try it, you must also load
263 ov518_decomp with the "nouv=0" parameter. If you get improper colors or
264 diagonal lines through the image, restart your video app and try again.
265 Repeat as necessary.
266
267WORKING FEATURES:
268 o Color streaming/capture at most widths and heights that are multiples of 8.
269 o Monochrome (use force_palette=1 to enable)
270 o Setting/getting of saturation, contrast, brightness, and hue (only some of
271 them work the OV7620 and OV7620AE)
272 o /proc status reporting
273 o SAA7111A video capture support at 320x240 and 640x480
274 o Compression support
275 o SMP compatibility
276
277HOW TO CONTACT ME:
278
279You can email me at mark@alpha.dyndns.org . Please prefix the subject line
280with "OV511: " so that I am certain to notice your message.
281
282CREDITS:
283
284The code is based in no small part on the CPiA driver by Johannes Erdfelt,
285Randy Dunlap, and others. Big thanks to them for their pioneering work on that
286and the USB stack. Thanks to Bret Wallach for getting camera reg IO, ISOC, and
287image capture working. Thanks to Orion Sky Lawlor, Kevin Moore, and Claudio
288Matsuoka for their work as well.
diff --git a/Documentation/video4linux/se401.txt b/Documentation/video4linux/se401.txt
deleted file mode 100644
index bd6526ec8dd7..000000000000
--- a/Documentation/video4linux/se401.txt
+++ /dev/null
@@ -1,54 +0,0 @@
1Linux driver for SE401 based USB cameras
2
3Copyright, 2001, Jeroen Vreeken
4
5
6INTRODUCTION:
7
8The SE401 chip is the used in low-cost usb webcams.
9It is produced by Endpoints Inc. (www.endpoints.com).
10It interfaces directly to a cmos image sensor and USB. The only other major
11part in a se401 based camera is a dram chip.
12
13The following cameras are known to work with this driver:
14
15Aox se401 (non-branded) cameras
16Philips PVCV665 USB VGA webcam 'Vesta Fun'
17Kensington VideoCAM PC Camera Model 67014
18Kensington VideoCAM PC Camera Model 67015
19Kensington VideoCAM PC Camera Model 67016
20Kensington VideoCAM PC Camera Model 67017
21
22
23WHAT YOU NEED:
24
25- USB support
26- VIDEO4LINUX support
27
28More information about USB support for linux can be found at:
29http://www.linux-usb.org
30
31
32MODULE OPTIONS:
33
34When the driver is compiled as a module you can also use the 'flickerless'
35option. With it exposure is limited to values that do not interfere with the
36net frequency. Valid options for this option are 0, 50 and 60. (0=disable,
3750=50hz, 60=60hz)
38
39
40KNOWN PROBLEMS:
41
42The driver works fine with the usb-ohci and uhci host controller drivers,
43the default settings also work with usb-uhci. But sending more than one bulk
44transfer at a time with usb-uhci doesn't work yet.
45Users of usb-ohci and uhci can safely enlarge SE401_NUMSBUF in se401.h in
46order to increase the throughput (and thus framerate).
47
48
49HELP:
50
51The latest info on this driver can be found at:
52http://members.chello.nl/~j.vreeken/se401/
53And questions to me can be send to:
54pe1rxq@amsat.org
diff --git a/Documentation/video4linux/si470x.txt b/Documentation/video4linux/si470x.txt
index 3a7823e01b4d..98c32925eb39 100644
--- a/Documentation/video4linux/si470x.txt
+++ b/Documentation/video4linux/si470x.txt
@@ -53,6 +53,9 @@ Testing is usually done with most application under Debian/testing:
53- kradio - Comfortable Radio Application for KDE 53- kradio - Comfortable Radio Application for KDE
54- radio - ncurses-based radio application 54- radio - ncurses-based radio application
55- mplayer - The Ultimate Movie Player For Linux 55- mplayer - The Ultimate Movie Player For Linux
56- v4l2-ctl - Collection of command line video4linux utilities
57For example, you can use:
58v4l2-ctl -d /dev/radio0 --set-ctrl=volume=10,mute=0 --set-freq=95.21 --all
56 59
57There is also a library libv4l, which can be used. It's going to have a function 60There is also a library libv4l, which can be used. It's going to have a function
58for frequency seeking, either by using hardware functionality as in radio-si470x 61for frequency seeking, either by using hardware functionality as in radio-si470x
@@ -75,8 +78,10 @@ commands. Please adjust the audio devices to your needs (/dev/dsp* and hw:x,x).
75If you just want to test audio (very poor quality): 78If you just want to test audio (very poor quality):
76cat /dev/dsp1 > /dev/dsp 79cat /dev/dsp1 > /dev/dsp
77 80
78If you use OSS try: 81If you use sox + OSS try:
79sox -2 --endian little -r 96000 -t oss /dev/dsp1 -t oss /dev/dsp 82sox -2 --endian little -r 96000 -t oss /dev/dsp1 -t oss /dev/dsp
83or using sox + alsa:
84sox --endian little -c 2 -S -r 96000 -t alsa hw:1 -t alsa -r 96000 hw:0
80 85
81If you use arts try: 86If you use arts try:
82arecord -D hw:1,0 -r96000 -c2 -f S16_LE | artsdsp aplay -B - 87arecord -D hw:1,0 -r96000 -c2 -f S16_LE | artsdsp aplay -B -
diff --git a/Documentation/video4linux/soc-camera.txt b/Documentation/video4linux/soc-camera.txt
index 3f87c7da4ca2..f62fcdbc8b9f 100644
--- a/Documentation/video4linux/soc-camera.txt
+++ b/Documentation/video4linux/soc-camera.txt
@@ -9,32 +9,36 @@ The following terms are used in this document:
9 of connecting to a variety of systems and interfaces, typically uses i2c for 9 of connecting to a variety of systems and interfaces, typically uses i2c for
10 control and configuration, and a parallel or a serial bus for data. 10 control and configuration, and a parallel or a serial bus for data.
11 - camera host - an interface, to which a camera is connected. Typically a 11 - camera host - an interface, to which a camera is connected. Typically a
12 specialised interface, present on many SoCs, e.g., PXA27x and PXA3xx, SuperH, 12 specialised interface, present on many SoCs, e.g. PXA27x and PXA3xx, SuperH,
13 AVR32, i.MX27, i.MX31. 13 AVR32, i.MX27, i.MX31.
14 - camera host bus - a connection between a camera host and a camera. Can be 14 - camera host bus - a connection between a camera host and a camera. Can be
15 parallel or serial, consists of data and control lines, e.g., clock, vertical 15 parallel or serial, consists of data and control lines, e.g. clock, vertical
16 and horizontal synchronization signals. 16 and horizontal synchronization signals.
17 17
18Purpose of the soc-camera subsystem 18Purpose of the soc-camera subsystem
19----------------------------------- 19-----------------------------------
20 20
21The soc-camera subsystem provides a unified API between camera host drivers and 21The soc-camera subsystem initially provided a unified API between camera host
22camera sensor drivers. It implements a V4L2 interface to the user, currently 22drivers and camera sensor drivers. Later the soc-camera sensor API has been
23only the mmap method is supported. 23replaced with the V4L2 standard subdev API. This also made camera driver re-use
24with non-soc-camera hosts possible. The camera host API to the soc-camera core
25has been preserved.
24 26
25This subsystem has been written to connect drivers for System-on-Chip (SoC) 27Soc-camera implements a V4L2 interface to the user, currently only the "mmap"
26video capture interfaces with drivers for CMOS camera sensor chips to enable 28method is supported by host drivers. However, the soc-camera core also provides
27the reuse of sensor drivers with various hosts. The subsystem has been designed 29support for the "read" method.
28to support multiple camera host interfaces and multiple cameras per interface, 30
29although most applications have only one camera sensor. 31The subsystem has been designed to support multiple camera host interfaces and
32multiple cameras per interface, although most applications have only one camera
33sensor.
30 34
31Existing drivers 35Existing drivers
32---------------- 36----------------
33 37
34As of 2.6.27-rc4 there are two host drivers in the mainline: pxa_camera.c for 38As of 3.7 there are seven host drivers in the mainline: atmel-isi.c,
35PXA27x SoCs and sh_mobile_ceu_camera.c for SuperH SoCs, and four sensor drivers: 39mx1_camera.c (broken, scheduled for removal), mx2_camera.c, mx3_camera.c,
36mt9m001.c, mt9m111.c, mt9v022.c and a generic soc_camera_platform.c driver. This 40omap1_camera.c, pxa_camera.c, sh_mobile_ceu_camera.c, and multiple sensor
37list is not supposed to be updated, look for more examples in your tree. 41drivers under drivers/media/i2c/soc_camera/.
38 42
39Camera host API 43Camera host API
40--------------- 44---------------
@@ -45,38 +49,37 @@ soc_camera_host_register(struct soc_camera_host *);
45 49
46function. The host object can be initialized as follows: 50function. The host object can be initialized as follows:
47 51
48static struct soc_camera_host pxa_soc_camera_host = { 52 struct soc_camera_host *ici;
49 .drv_name = PXA_CAM_DRV_NAME, 53 ici->drv_name = DRV_NAME;
50 .ops = &pxa_soc_camera_host_ops, 54 ici->ops = &camera_host_ops;
51}; 55 ici->priv = pcdev;
56 ici->v4l2_dev.dev = &pdev->dev;
57 ici->nr = pdev->id;
52 58
53All camera host methods are passed in a struct soc_camera_host_ops: 59All camera host methods are passed in a struct soc_camera_host_ops:
54 60
55static struct soc_camera_host_ops pxa_soc_camera_host_ops = { 61static struct soc_camera_host_ops camera_host_ops = {
56 .owner = THIS_MODULE, 62 .owner = THIS_MODULE,
57 .add = pxa_camera_add_device, 63 .add = camera_add_device,
58 .remove = pxa_camera_remove_device, 64 .remove = camera_remove_device,
59 .suspend = pxa_camera_suspend, 65 .set_fmt = camera_set_fmt_cap,
60 .resume = pxa_camera_resume, 66 .try_fmt = camera_try_fmt_cap,
61 .set_fmt_cap = pxa_camera_set_fmt_cap, 67 .init_videobuf2 = camera_init_videobuf2,
62 .try_fmt_cap = pxa_camera_try_fmt_cap, 68 .poll = camera_poll,
63 .init_videobuf = pxa_camera_init_videobuf, 69 .querycap = camera_querycap,
64 .reqbufs = pxa_camera_reqbufs, 70 .set_bus_param = camera_set_bus_param,
65 .poll = pxa_camera_poll, 71 /* The rest of host operations are optional */
66 .querycap = pxa_camera_querycap,
67 .try_bus_param = pxa_camera_try_bus_param,
68 .set_bus_param = pxa_camera_set_bus_param,
69}; 72};
70 73
71.add and .remove methods are called when a sensor is attached to or detached 74.add and .remove methods are called when a sensor is attached to or detached
72from the host, apart from performing host-internal tasks they shall also call 75from the host. .set_bus_param is used to configure physical connection
73sensor driver's .init and .release methods respectively. .suspend and .resume 76parameters between the host and the sensor. .init_videobuf2 is called by
74methods implement host's power-management functionality and its their 77soc-camera core when a video-device is opened, the host driver would typically
75responsibility to call respective sensor's methods. .try_bus_param and 78call vb2_queue_init() in this method. Further video-buffer management is
76.set_bus_param are used to negotiate physical connection parameters between the 79implemented completely by the specific camera host driver. If the host driver
77host and the sensor. .init_videobuf is called by soc-camera core when a 80supports non-standard pixel format conversion, it should implement a
78video-device is opened, further video-buffer management is implemented completely 81.get_formats and, possibly, a .put_formats operations. See below for more
79by the specific camera host driver. The rest of the methods are called from 82details about format conversion. The rest of the methods are called from
80respective V4L2 operations. 83respective V4L2 operations.
81 84
82Camera API 85Camera API
@@ -84,37 +87,21 @@ Camera API
84 87
85Sensor drivers can use struct soc_camera_link, typically provided by the 88Sensor drivers can use struct soc_camera_link, typically provided by the
86platform, and used to specify to which camera host bus the sensor is connected, 89platform, and used to specify to which camera host bus the sensor is connected,
87and arbitrarily provide platform .power and .reset methods for the camera. 90and optionally provide platform .power and .reset methods for the camera. This
88soc_camera_device_register() and soc_camera_device_unregister() functions are 91struct is provided to the camera driver via the I2C client device platform data
89used to add a sensor driver to or remove one from the system. The registration 92and can be obtained, using the soc_camera_i2c_to_link() macro. Care should be
90function takes a pointer to struct soc_camera_device as the only parameter. 93taken, when using soc_camera_vdev_to_subdev() and when accessing struct
91This struct can be initialized as follows: 94soc_camera_device, using v4l2_get_subdev_hostdata(): both only work, when
92 95running on an soc-camera host. The actual camera driver operation is implemented
93 /* link to driver operations */ 96using the V4L2 subdev API. Additionally soc-camera camera drivers can use
94 icd->ops = &mt9m001_ops; 97auxiliary soc-camera helper functions like soc_camera_power_on() and
95 /* link to the underlying physical (e.g., i2c) device */ 98soc_camera_power_off(), which switch regulators, provided by the platform and call
96 icd->control = &client->dev; 99board-specific power switching methods. soc_camera_apply_board_flags() takes
97 /* window geometry */ 100camera bus configuration capability flags and applies any board transformations,
98 icd->x_min = 20; 101e.g. signal polarity inversion. soc_mbus_get_fmtdesc() can be used to obtain a
99 icd->y_min = 12; 102pixel format descriptor, corresponding to a certain media-bus pixel format code.
100 icd->x_current = 20; 103soc_camera_limit_side() can be used to restrict beginning and length of a frame
101 icd->y_current = 12; 104side, based on camera capabilities.
102 icd->width_min = 48;
103 icd->width_max = 1280;
104 icd->height_min = 32;
105 icd->height_max = 1024;
106 icd->y_skip_top = 1;
107 /* camera bus ID, typically obtained from platform data */
108 icd->iface = icl->bus_id;
109
110struct soc_camera_ops provides .probe and .remove methods, which are called by
111the soc-camera core, when a camera is matched against or removed from a camera
112host bus, .init, .release, .suspend, and .resume are called from the camera host
113driver as discussed above. Other members of this struct provide respective V4L2
114functionality.
115
116struct soc_camera_device also links to an array of struct soc_camera_data_format,
117listing pixel formats, supported by the camera.
118 105
119VIDIOC_S_CROP and VIDIOC_S_FMT behaviour 106VIDIOC_S_CROP and VIDIOC_S_FMT behaviour
120---------------------------------------- 107----------------------------------------
@@ -153,8 +140,25 @@ implemented.
153User window geometry is kept in .user_width and .user_height fields in struct 140User window geometry is kept in .user_width and .user_height fields in struct
154soc_camera_device and used by the soc-camera core and host drivers. The core 141soc_camera_device and used by the soc-camera core and host drivers. The core
155updates these fields upon successful completion of a .s_fmt() call, but if these 142updates these fields upon successful completion of a .s_fmt() call, but if these
156fields change elsewhere, e.g., during .s_crop() processing, the host driver is 143fields change elsewhere, e.g. during .s_crop() processing, the host driver is
157responsible for updating them. 144responsible for updating them.
158 145
146Format conversion
147-----------------
148
149V4L2 distinguishes between pixel formats, as they are stored in memory, and as
150they are transferred over a media bus. Soc-camera provides support to
151conveniently manage these formats. A table of standard transformations is
152maintained by soc-camera core, which describes, what FOURCC pixel format will
153be obtained, if a media-bus pixel format is stored in memory according to
154certain rules. E.g. if V4L2_MBUS_FMT_YUYV8_2X8 data is sampled with 8 bits per
155sample and stored in memory in the little-endian order with no gaps between
156bytes, data in memory will represent the V4L2_PIX_FMT_YUYV FOURCC format. These
157standard transformations will be used by soc-camera or by camera host drivers to
158configure camera drivers to produce the FOURCC format, requested by the user,
159using the VIDIOC_S_FMT ioctl(). Apart from those standard format conversions,
160host drivers can also provide their own conversion rules by implementing a
161.get_formats and, if required, a .put_formats methods.
162
159-- 163--
160Author: Guennadi Liakhovetski <g.liakhovetski@gmx.de> 164Author: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
diff --git a/Documentation/video4linux/stv680.txt b/Documentation/video4linux/stv680.txt
deleted file mode 100644
index e3de33645308..000000000000
--- a/Documentation/video4linux/stv680.txt
+++ /dev/null
@@ -1,53 +0,0 @@
1Linux driver for STV0680 based USB cameras
2
3Copyright, 2001, Kevin Sisson
4
5
6INTRODUCTION:
7
8STMicroelectronics produces the STV0680B chip, which comes in two
9types, -001 and -003. The -003 version allows the recording and downloading
10of sound clips from the camera, and allows a flash attachment. Otherwise,
11it uses the same commands as the -001 version. Both versions support a
12variety of SDRAM sizes and sensors, allowing for a maximum of 26 VGA or 20
13CIF pictures. The STV0680 supports either a serial or a usb interface, and
14video is possible through the usb interface.
15
16The following cameras are known to work with this driver, although any
17camera with Vendor/Product codes of 0553/0202 should work:
18
19Aiptek Pencam (various models)
20Nisis QuickPix 2
21Radio Shack 'Kid's digital camera' (#60-1207)
22At least one Trust Spycam model
23Several other European brand models
24
25WHAT YOU NEED:
26
27- USB support
28- VIDEO4LINUX support
29
30More information about USB support for linux can be found at:
31http://www.linux-usb.org
32
33
34MODULE OPTIONS:
35
36When the driver is compiled as a module, you can set a "swapRGB=1"
37option, if necessary, for those applications that require it
38(such as xawtv). However, the driver should detect and set this
39automatically, so this option should not normally be used.
40
41
42KNOWN PROBLEMS:
43
44The driver seems to work better with the usb-ohci than the usb-uhci host
45controller driver.
46
47HELP:
48
49The latest info on this driver can be found at:
50http://personal.clt.bellsouth.net/~kjsisson or at
51http://stv0680-usb.sourceforge.net
52
53Any questions to me can be send to: kjsisson@bellsouth.net
diff --git a/Documentation/video4linux/v4l2-controls.txt b/Documentation/video4linux/v4l2-controls.txt
index cfe52c798d74..676f87366025 100644
--- a/Documentation/video4linux/v4l2-controls.txt
+++ b/Documentation/video4linux/v4l2-controls.txt
@@ -715,14 +715,20 @@ a control of this type whenever the first control belonging to a new control
715class is added. 715class is added.
716 716
717 717
718Proposals for Extensions 718Adding Notify Callbacks
719======================== 719=======================
720
721Sometimes the platform or bridge driver needs to be notified when a control
722from a sub-device driver changes. You can set a notify callback by calling
723this function:
720 724
721Some ideas for future extensions to the spec: 725void v4l2_ctrl_notify(struct v4l2_ctrl *ctrl,
726 void (*notify)(struct v4l2_ctrl *ctrl, void *priv), void *priv);
722 727
7231) Add a V4L2_CTRL_FLAG_HEX to have values shown as hexadecimal instead of 728Whenever the give control changes value the notify callback will be called
724decimal. Useful for e.g. video_mute_yuv. 729with a pointer to the control and the priv pointer that was passed with
730v4l2_ctrl_notify. Note that the control's handler lock is held when the
731notify function is called.
725 732
7262) It is possible to mark in the controls array which controls have been 733There can be only one notify function per control handler. Any attempt
727successfully written and which failed by for example adding a bit to the 734to set another notify function will cause a WARN_ON.
728control ID. Not sure if it is worth the effort, though.
diff --git a/Documentation/video4linux/v4l2-framework.txt b/Documentation/video4linux/v4l2-framework.txt
index b89567ad04b7..a300b283a1a0 100644
--- a/Documentation/video4linux/v4l2-framework.txt
+++ b/Documentation/video4linux/v4l2-framework.txt
@@ -68,8 +68,7 @@ Structure of the framework
68The framework closely resembles the driver structure: it has a v4l2_device 68The framework closely resembles the driver structure: it has a v4l2_device
69struct for the device instance data, a v4l2_subdev struct to refer to 69struct for the device instance data, a v4l2_subdev struct to refer to
70sub-device instances, the video_device struct stores V4L2 device node data 70sub-device instances, the video_device struct stores V4L2 device node data
71and in the future a v4l2_fh struct will keep track of filehandle instances 71and the v4l2_fh struct keeps track of filehandle instances.
72(this is not yet implemented).
73 72
74The V4L2 framework also optionally integrates with the media framework. If a 73The V4L2 framework also optionally integrates with the media framework. If a
75driver sets the struct v4l2_device mdev field, sub-devices and video nodes 74driver sets the struct v4l2_device mdev field, sub-devices and video nodes
diff --git a/Documentation/video4linux/w9968cf.txt b/Documentation/video4linux/w9968cf.txt
deleted file mode 100644
index 9649450f3b90..000000000000
--- a/Documentation/video4linux/w9968cf.txt
+++ /dev/null
@@ -1,458 +0,0 @@
1
2 W996[87]CF JPEG USB Dual Mode Camera Chip
3 Driver for Linux 2.6 (basic version)
4 =========================================
5
6 - Documentation -
7
8
9Index
10=====
111. Copyright
122. Disclaimer
133. License
144. Overview
155. Supported devices
166. Module dependencies
177. Module loading
188. Module parameters
199. Contact information
2010. Credits
21
22
231. Copyright
24============
25Copyright (C) 2002-2004 by Luca Risolia <luca.risolia@studio.unibo.it>
26
27
282. Disclaimer
29=============
30Winbond is a trademark of Winbond Electronics Corporation.
31This software is not sponsored or developed by Winbond.
32
33
343. License
35==========
36This program is free software; you can redistribute it and/or modify
37it under the terms of the GNU General Public License as published by
38the Free Software Foundation; either version 2 of the License, or
39(at your option) any later version.
40
41This program is distributed in the hope that it will be useful,
42but WITHOUT ANY WARRANTY; without even the implied warranty of
43MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44GNU General Public License for more details.
45
46You should have received a copy of the GNU General Public License
47along with this program; if not, write to the Free Software
48Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
49
50
514. Overview
52===========
53This driver supports the video streaming capabilities of the devices mounting
54Winbond W9967CF and Winbond W9968CF JPEG USB Dual Mode Camera Chips. OV681
55based cameras should be supported as well.
56
57The driver is divided into two modules: the basic one, "w9968cf", is needed for
58the supported devices to work; the second one, "w9968cf-vpp", is an optional
59module, which provides some useful video post-processing functions like video
60decoding, up-scaling and colour conversions.
61
62Note that the official kernels do neither include nor support the second
63module for performance purposes. Therefore, it is always recommended to
64download and install the latest and complete release of the driver,
65replacing the existing one, if present.
66
67The latest and full-featured version of the W996[87]CF driver can be found at:
68http://www.linux-projects.org. Please refer to the documentation included in
69that package, if you are going to use it.
70
71Up to 32 cameras can be handled at the same time. They can be connected and
72disconnected from the host many times without turning off the computer, if
73your system supports the hotplug facility.
74
75To change the default settings for each camera, many parameters can be passed
76through command line when the module is loaded into memory.
77
78The driver relies on the Video4Linux, USB and I2C core modules. It has been
79designed to run properly on SMP systems as well. An additional module,
80"ovcamchip", is mandatory; it provides support for some OmniVision image
81sensors connected to the W996[87]CF chips; if found in the system, the module
82will be automatically loaded by default (provided that the kernel has been
83compiled with the automatic module loading option).
84
85
865. Supported devices
87====================
88At the moment, known W996[87]CF and OV681 based devices are:
89- Aroma Digi Pen VGA Dual Mode ADG-5000 (unknown image sensor)
90- AVerMedia AVerTV USB (SAA7111A, Philips FI1216Mk2 tuner, PT2313L audio chip)
91- Creative Labs Video Blaster WebCam Go (OmniVision OV7610 sensor)
92- Creative Labs Video Blaster WebCam Go Plus (OmniVision OV7620 sensor)
93- Lebon LDC-035A (unknown image sensor)
94- Ezonics EZ-802 EZMega Cam (OmniVision OV8610C sensor)
95- OmniVision OV8610-EDE (OmniVision OV8610 sensor)
96- OPCOM Digi Pen VGA Dual Mode Pen Camera (unknown image sensor)
97- Pretec Digi Pen-II (OmniVision OV7620 sensor)
98- Pretec DigiPen-480 (OmniVision OV8610 sensor)
99
100If you know any other W996[87]CF or OV681 based cameras, please contact me.
101
102The list above does not imply that all those devices work with this driver: up
103until now only webcams that have an image sensor supported by the "ovcamchip"
104module work. Kernel messages will always tell you whether this is case.
105
106Possible external microcontrollers of those webcams are not supported: this
107means that still images cannot be downloaded from the device memory.
108
109Furthermore, it's worth to note that I was only able to run tests on my
110"Creative Labs Video Blaster WebCam Go". Donations of other models, for
111additional testing and full support, would be much appreciated.
112
113
1146. Module dependencies
115======================
116For it to work properly, the driver needs kernel support for Video4Linux, USB
117and I2C, and the "ovcamchip" module for the image sensor. Make sure you are not
118actually using any external "ovcamchip" module, given that the W996[87]CF
119driver depends on the version of the module present in the official kernels.
120
121The following options of the kernel configuration file must be enabled and
122corresponding modules must be compiled:
123
124 # Multimedia devices
125 #
126 CONFIG_VIDEO_DEV=m
127
128 # I2C support
129 #
130 CONFIG_I2C=m
131
132The I2C core module can be compiled statically in the kernel as well.
133
134 # OmniVision Camera Chip support
135 #
136 CONFIG_VIDEO_OVCAMCHIP=m
137
138 # USB support
139 #
140 CONFIG_USB=m
141
142In addition, depending on the hardware being used, only one of the modules
143below is necessary:
144
145 # USB Host Controller Drivers
146 #
147 CONFIG_USB_EHCI_HCD=m
148 CONFIG_USB_UHCI_HCD=m
149 CONFIG_USB_OHCI_HCD=m
150
151And finally:
152
153 # USB Multimedia devices
154 #
155 CONFIG_USB_W9968CF=m
156
157
1587. Module loading
159=================
160To use the driver, it is necessary to load the "w9968cf" module into memory
161after every other module required.
162
163Loading can be done this way, from root:
164
165 [root@localhost home]# modprobe usbcore
166 [root@localhost home]# modprobe i2c-core
167 [root@localhost home]# modprobe videodev
168 [root@localhost home]# modprobe w9968cf
169
170At this point the pertinent devices should be recognized: "dmesg" can be used
171to analyze kernel messages:
172
173 [user@localhost home]$ dmesg
174
175There are a lot of parameters the module can use to change the default
176settings for each device. To list every possible parameter with a brief
177explanation about them and which syntax to use, it is recommended to run the
178"modinfo" command:
179
180 [root@locahost home]# modinfo w9968cf
181
182
1838. Module parameters
184====================
185Module parameters are listed below:
186-------------------------------------------------------------------------------
187Name: ovmod_load
188Type: bool
189Syntax: <0|1>
190Description: Automatic 'ovcamchip' module loading: 0 disabled, 1 enabled.
191 If enabled, 'insmod' searches for the required 'ovcamchip'
192 module in the system, according to its configuration, and
193 loads that module automatically. This action is performed as
194 once soon as the 'w9968cf' module is loaded into memory.
195Default: 1
196-------------------------------------------------------------------------------
197Name: simcams
198Type: int
199Syntax: <n>
200Description: Number of cameras allowed to stream simultaneously.
201 n may vary from 0 to 32.
202Default: 32
203-------------------------------------------------------------------------------
204Name: video_nr
205Type: int array (min = 0, max = 32)
206Syntax: <-1|n[,...]>
207Description: Specify V4L minor mode number.
208 -1 = use next available
209 n = use minor number n
210 You can specify up to 32 cameras this way.
211 For example:
212 video_nr=-1,2,-1 would assign minor number 2 to the second
213 recognized camera and use auto for the first one and for every
214 other camera.
215Default: -1
216-------------------------------------------------------------------------------
217Name: packet_size
218Type: int array (min = 0, max = 32)
219Syntax: <n[,...]>
220Description: Specify the maximum data payload size in bytes for alternate
221 settings, for each device. n is scaled between 63 and 1023.
222Default: 1023
223-------------------------------------------------------------------------------
224Name: max_buffers
225Type: int array (min = 0, max = 32)
226Syntax: <n[,...]>
227Description: For advanced users.
228 Specify the maximum number of video frame buffers to allocate
229 for each device, from 2 to 32.
230Default: 2
231-------------------------------------------------------------------------------
232Name: double_buffer
233Type: bool array (min = 0, max = 32)
234Syntax: <0|1[,...]>
235Description: Hardware double buffering: 0 disabled, 1 enabled.
236 It should be enabled if you want smooth video output: if you
237 obtain out of sync. video, disable it, or try to
238 decrease the 'clockdiv' module parameter value.
239Default: 1 for every device.
240-------------------------------------------------------------------------------
241Name: clamping
242Type: bool array (min = 0, max = 32)
243Syntax: <0|1[,...]>
244Description: Video data clamping: 0 disabled, 1 enabled.
245Default: 0 for every device.
246-------------------------------------------------------------------------------
247Name: filter_type
248Type: int array (min = 0, max = 32)
249Syntax: <0|1|2[,...]>
250Description: Video filter type.
251 0 none, 1 (1-2-1) 3-tap filter, 2 (2-3-6-3-2) 5-tap filter.
252 The filter is used to reduce noise and aliasing artifacts
253 produced by the CCD or CMOS image sensor.
254Default: 0 for every device.
255-------------------------------------------------------------------------------
256Name: largeview
257Type: bool array (min = 0, max = 32)
258Syntax: <0|1[,...]>
259Description: Large view: 0 disabled, 1 enabled.
260Default: 1 for every device.
261-------------------------------------------------------------------------------
262Name: upscaling
263Type: bool array (min = 0, max = 32)
264Syntax: <0|1[,...]>
265Description: Software scaling (for non-compressed video only):
266 0 disabled, 1 enabled.
267 Disable it if you have a slow CPU or you don't have enough
268 memory.
269Default: 0 for every device.
270Note: If 'w9968cf-vpp' is not present, this parameter is set to 0.
271-------------------------------------------------------------------------------
272Name: decompression
273Type: int array (min = 0, max = 32)
274Syntax: <0|1|2[,...]>
275Description: Software video decompression:
276 0 = disables decompression
277 (doesn't allow formats needing decompression).
278 1 = forces decompression
279 (allows formats needing decompression only).
280 2 = allows any permitted formats.
281 Formats supporting (de)compressed video are YUV422P and
282 YUV420P/YUV420 in any resolutions where width and height are
283 multiples of 16.
284Default: 2 for every device.
285Note: If 'w9968cf-vpp' is not present, forcing decompression is not
286 allowed; in this case this parameter is set to 2.
287-------------------------------------------------------------------------------
288Name: force_palette
289Type: int array (min = 0, max = 32)
290Syntax: <0|9|10|13|15|8|7|1|6|3|4|5[,...]>
291Description: Force picture palette.
292 In order:
293 0 = Off - allows any of the following formats:
294 9 = UYVY 16 bpp - Original video, compression disabled
295 10 = YUV420 12 bpp - Original video, compression enabled
296 13 = YUV422P 16 bpp - Original video, compression enabled
297 15 = YUV420P 12 bpp - Original video, compression enabled
298 8 = YUVY 16 bpp - Software conversion from UYVY
299 7 = YUV422 16 bpp - Software conversion from UYVY
300 1 = GREY 8 bpp - Software conversion from UYVY
301 6 = RGB555 16 bpp - Software conversion from UYVY
302 3 = RGB565 16 bpp - Software conversion from UYVY
303 4 = RGB24 24 bpp - Software conversion from UYVY
304 5 = RGB32 32 bpp - Software conversion from UYVY
305 When not 0, this parameter will override 'decompression'.
306Default: 0 for every device. Initial palette is 9 (UYVY).
307Note: If 'w9968cf-vpp' is not present, this parameter is set to 9.
308-------------------------------------------------------------------------------
309Name: force_rgb
310Type: bool array (min = 0, max = 32)
311Syntax: <0|1[,...]>
312Description: Read RGB video data instead of BGR:
313 1 = use RGB component ordering.
314 0 = use BGR component ordering.
315 This parameter has effect when using RGBX palettes only.
316Default: 0 for every device.
317-------------------------------------------------------------------------------
318Name: autobright
319Type: bool array (min = 0, max = 32)
320Syntax: <0|1[,...]>
321Description: Image sensor automatically changes brightness:
322 0 = no, 1 = yes
323Default: 0 for every device.
324-------------------------------------------------------------------------------
325Name: autoexp
326Type: bool array (min = 0, max = 32)
327Syntax: <0|1[,...]>
328Description: Image sensor automatically changes exposure:
329 0 = no, 1 = yes
330Default: 1 for every device.
331-------------------------------------------------------------------------------
332Name: lightfreq
333Type: int array (min = 0, max = 32)
334Syntax: <50|60[,...]>
335Description: Light frequency in Hz:
336 50 for European and Asian lighting, 60 for American lighting.
337Default: 50 for every device.
338-------------------------------------------------------------------------------
339Name: bandingfilter
340Type: bool array (min = 0, max = 32)
341Syntax: <0|1[,...]>
342Description: Banding filter to reduce effects of fluorescent
343 lighting:
344 0 disabled, 1 enabled.
345 This filter tries to reduce the pattern of horizontal
346 light/dark bands caused by some (usually fluorescent) lighting.
347Default: 0 for every device.
348-------------------------------------------------------------------------------
349Name: clockdiv
350Type: int array (min = 0, max = 32)
351Syntax: <-1|n[,...]>
352Description: Force pixel clock divisor to a specific value (for experts):
353 n may vary from 0 to 127.
354 -1 for automatic value.
355 See also the 'double_buffer' module parameter.
356Default: -1 for every device.
357-------------------------------------------------------------------------------
358Name: backlight
359Type: bool array (min = 0, max = 32)
360Syntax: <0|1[,...]>
361Description: Objects are lit from behind:
362 0 = no, 1 = yes
363Default: 0 for every device.
364-------------------------------------------------------------------------------
365Name: mirror
366Type: bool array (min = 0, max = 32)
367Syntax: <0|1[,...]>
368Description: Reverse image horizontally:
369 0 = no, 1 = yes
370Default: 0 for every device.
371-------------------------------------------------------------------------------
372Name: monochrome
373Type: bool array (min = 0, max = 32)
374Syntax: <0|1[,...]>
375Description: The image sensor is monochrome:
376 0 = no, 1 = yes
377Default: 0 for every device.
378-------------------------------------------------------------------------------
379Name: brightness
380Type: long array (min = 0, max = 32)
381Syntax: <n[,...]>
382Description: Set picture brightness (0-65535).
383 This parameter has no effect if 'autobright' is enabled.
384Default: 31000 for every device.
385-------------------------------------------------------------------------------
386Name: hue
387Type: long array (min = 0, max = 32)
388Syntax: <n[,...]>
389Description: Set picture hue (0-65535).
390Default: 32768 for every device.
391-------------------------------------------------------------------------------
392Name: colour
393Type: long array (min = 0, max = 32)
394Syntax: <n[,...]>
395Description: Set picture saturation (0-65535).
396Default: 32768 for every device.
397-------------------------------------------------------------------------------
398Name: contrast
399Type: long array (min = 0, max = 32)
400Syntax: <n[,...]>
401Description: Set picture contrast (0-65535).
402Default: 50000 for every device.
403-------------------------------------------------------------------------------
404Name: whiteness
405Type: long array (min = 0, max = 32)
406Syntax: <n[,...]>
407Description: Set picture whiteness (0-65535).
408Default: 32768 for every device.
409-------------------------------------------------------------------------------
410Name: debug
411Type: int
412Syntax: <n>
413Description: Debugging information level, from 0 to 6:
414 0 = none (use carefully)
415 1 = critical errors
416 2 = significant information
417 3 = configuration or general messages
418 4 = warnings
419 5 = called functions
420 6 = function internals
421 Level 5 and 6 are useful for testing only, when only one
422 device is used.
423Default: 2
424-------------------------------------------------------------------------------
425Name: specific_debug
426Type: bool
427Syntax: <0|1>
428Description: Enable or disable specific debugging messages:
429 0 = print messages concerning every level <= 'debug' level.
430 1 = print messages concerning the level indicated by 'debug'.
431Default: 0
432-------------------------------------------------------------------------------
433
434
4359. Contact information
436======================
437I may be contacted by e-mail at <luca.risolia@studio.unibo.it>.
438
439I can accept GPG/PGP encrypted e-mail. My GPG key ID is 'FCE635A4'.
440My public 1024-bit key should be available at your keyserver; the fingerprint
441is: '88E8 F32F 7244 68BA 3958 5D40 99DA 5D2A FCE6 35A4'.
442
443
44410. Credits
445==========
446The development would not have proceed much further without having looked at
447the source code of other drivers and without the help of several persons; in
448particular:
449
450- the I2C interface to kernel and high-level image sensor control routines have
451 been taken from the OV511 driver by Mark McClelland;
452
453- memory management code has been copied from the bttv driver by Ralph Metzler,
454 Marcus Metzler and Gerd Knorr;
455
456- the low-level I2C read function has been written by Frederic Jouault;
457
458- the low-level I2C fast write function has been written by Piotr Czerczak.
diff --git a/Documentation/video4linux/zc0301.txt b/Documentation/video4linux/zc0301.txt
deleted file mode 100644
index b41c83cf09f4..000000000000
--- a/Documentation/video4linux/zc0301.txt
+++ /dev/null
@@ -1,270 +0,0 @@
1
2 ZC0301 and ZC0301P Image Processor and Control Chip
3 Driver for Linux
4 ===================================================
5
6 - Documentation -
7
8
9Index
10=====
111. Copyright
122. Disclaimer
133. License
144. Overview and features
155. Module dependencies
166. Module loading
177. Module parameters
188. Supported devices
199. Notes for V4L2 application developers
2010. Contact information
2111. Credits
22
23
241. Copyright
25============
26Copyright (C) 2006-2007 by Luca Risolia <luca.risolia@studio.unibo.it>
27
28
292. Disclaimer
30=============
31This software is not developed or sponsored by Z-Star Microelectronics Corp.
32Trademarks are property of their respective owner.
33
34
353. License
36==========
37This program is free software; you can redistribute it and/or modify
38it under the terms of the GNU General Public License as published by
39the Free Software Foundation; either version 2 of the License, or
40(at your option) any later version.
41
42This program is distributed in the hope that it will be useful,
43but WITHOUT ANY WARRANTY; without even the implied warranty of
44MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45GNU General Public License for more details.
46
47You should have received a copy of the GNU General Public License
48along with this program; if not, write to the Free Software
49Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
50
51
524. Overview and features
53========================
54This driver supports the video interface of the devices mounting the ZC0301 or
55ZC0301P Image Processors and Control Chips.
56
57The driver relies on the Video4Linux2 and USB core modules. It has been
58designed to run properly on SMP systems as well.
59
60The latest version of the ZC0301[P] driver can be found at the following URL:
61http://www.linux-projects.org/
62
63Some of the features of the driver are:
64
65- full compliance with the Video4Linux2 API (see also "Notes for V4L2
66 application developers" paragraph);
67- available mmap or read/poll methods for video streaming through isochronous
68 data transfers;
69- automatic detection of image sensor;
70- video format is standard JPEG;
71- dynamic driver control thanks to various module parameters (see "Module
72 parameters" paragraph);
73- up to 64 cameras can be handled at the same time; they can be connected and
74 disconnected from the host many times without turning off the computer, if
75 the system supports hotplugging;
76
77
785. Module dependencies
79======================
80For it to work properly, the driver needs kernel support for Video4Linux and
81USB.
82
83The following options of the kernel configuration file must be enabled and
84corresponding modules must be compiled:
85
86 # Multimedia devices
87 #
88 CONFIG_VIDEO_DEV=m
89
90 # USB support
91 #
92 CONFIG_USB=m
93
94In addition, depending on the hardware being used, the modules below are
95necessary:
96
97 # USB Host Controller Drivers
98 #
99 CONFIG_USB_EHCI_HCD=m
100 CONFIG_USB_UHCI_HCD=m
101 CONFIG_USB_OHCI_HCD=m
102
103The ZC0301 controller also provides a built-in microphone interface. It is
104supported by the USB Audio driver thanks to the ALSA API:
105
106 # Sound
107 #
108 CONFIG_SOUND=y
109
110 # Advanced Linux Sound Architecture
111 #
112 CONFIG_SND=m
113
114 # USB devices
115 #
116 CONFIG_SND_USB_AUDIO=m
117
118And finally:
119
120 # V4L USB devices
121 #
122 CONFIG_USB_ZC0301=m
123
124
1256. Module loading
126=================
127To use the driver, it is necessary to load the "zc0301" module into memory
128after every other module required: "videodev", "v4l2_common", "compat_ioctl32",
129"usbcore" and, depending on the USB host controller you have, "ehci-hcd",
130"uhci-hcd" or "ohci-hcd".
131
132Loading can be done as shown below:
133
134 [root@localhost home]# modprobe zc0301
135
136At this point the devices should be recognized. You can invoke "dmesg" to
137analyze kernel messages and verify that the loading process has gone well:
138
139 [user@localhost home]$ dmesg
140
141
1427. Module parameters
143====================
144Module parameters are listed below:
145-------------------------------------------------------------------------------
146Name: video_nr
147Type: short array (min = 0, max = 64)
148Syntax: <-1|n[,...]>
149Description: Specify V4L2 minor mode number:
150 -1 = use next available
151 n = use minor number n
152 You can specify up to 64 cameras this way.
153 For example:
154 video_nr=-1,2,-1 would assign minor number 2 to the second
155 registered camera and use auto for the first one and for every
156 other camera.
157Default: -1
158-------------------------------------------------------------------------------
159Name: force_munmap
160Type: bool array (min = 0, max = 64)
161Syntax: <0|1[,...]>
162Description: Force the application to unmap previously mapped buffer memory
163 before calling any VIDIOC_S_CROP or VIDIOC_S_FMT ioctl's. Not
164 all the applications support this feature. This parameter is
165 specific for each detected camera.
166 0 = do not force memory unmapping
167 1 = force memory unmapping (save memory)
168Default: 0
169-------------------------------------------------------------------------------
170Name: frame_timeout
171Type: uint array (min = 0, max = 64)
172Syntax: <n[,...]>
173Description: Timeout for a video frame in seconds. This parameter is
174 specific for each detected camera. This parameter can be
175 changed at runtime thanks to the /sys filesystem interface.
176Default: 2
177-------------------------------------------------------------------------------
178Name: debug
179Type: ushort
180Syntax: <n>
181Description: Debugging information level, from 0 to 3:
182 0 = none (use carefully)
183 1 = critical errors
184 2 = significant information
185 3 = more verbose messages
186 Level 3 is useful for testing only, when only one device
187 is used at the same time. It also shows some information
188 about the hardware being detected. This module parameter can be
189 changed at runtime thanks to the /sys filesystem interface.
190Default: 2
191-------------------------------------------------------------------------------
192
193
1948. Supported devices
195====================
196None of the names of the companies as well as their products will be mentioned
197here. They have never collaborated with the author, so no advertising.
198
199From the point of view of a driver, what unambiguously identify a device are
200its vendor and product USB identifiers. Below is a list of known identifiers of
201devices mounting the ZC0301 Image Processor and Control Chips:
202
203Vendor ID Product ID
204--------- ----------
2050x041e 0x4017
2060x041e 0x401c
2070x041e 0x401e
2080x041e 0x401f
2090x041e 0x4022
2100x041e 0x4034
2110x041e 0x4035
2120x041e 0x4036
2130x041e 0x403a
2140x0458 0x7007
2150x0458 0x700c
2160x0458 0x700f
2170x046d 0x08ae
2180x055f 0xd003
2190x055f 0xd004
2200x0ac8 0x0301
2210x0ac8 0x301b
2220x0ac8 0x303b
2230x10fd 0x0128
2240x10fd 0x8050
2250x10fd 0x804e
226
227The list above does not imply that all those devices work with this driver: up
228until now only the ones that mount the following image sensors are supported;
229kernel messages will always tell you whether this is the case:
230
231Model Manufacturer
232----- ------------
233PAS202BCB PixArt Imaging, Inc.
234PB-0330 Photobit Corporation
235
236
2379. Notes for V4L2 application developers
238========================================
239This driver follows the V4L2 API specifications. In particular, it enforces two
240rules:
241
242- exactly one I/O method, either "mmap" or "read", is associated with each
243file descriptor. Once it is selected, the application must close and reopen the
244device to switch to the other I/O method;
245
246- although it is not mandatory, previously mapped buffer memory should always
247be unmapped before calling any "VIDIOC_S_CROP" or "VIDIOC_S_FMT" ioctl's.
248The same number of buffers as before will be allocated again to match the size
249of the new video frames, so you have to map the buffers again before any I/O
250attempts on them.
251
252
25310. Contact information
254=======================
255The author may be contacted by e-mail at <luca.risolia@studio.unibo.it>.
256
257GPG/PGP encrypted e-mail's are accepted. The GPG key ID of the author is
258'FCE635A4'; the public 1024-bit key should be available at any keyserver;
259the fingerprint is: '88E8 F32F 7244 68BA 3958 5D40 99DA 5D2A FCE6 35A4'.
260
261
26211. Credits
263===========
264- Information about the chip internals needed to enable the I2C protocol have
265 been taken from the documentation of the ZC030x Video4Linux1 driver written
266 by Andrew Birkett <andy@nobugs.org>;
267- The initialization values of the ZC0301 controller connected to the PAS202BCB
268 and PB-0330 image sensors have been taken from the SPCA5XX driver maintained
269 by Michel Xhaard <mxhaard@magic.fr>;
270- Stanislav Lechev donated one camera.
diff --git a/MAINTAINERS b/MAINTAINERS
index a92f485f5456..870ba56207d7 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -465,6 +465,14 @@ S: Maintained
465F: drivers/scsi/aic7xxx/ 465F: drivers/scsi/aic7xxx/
466F: drivers/scsi/aic7xxx_old/ 466F: drivers/scsi/aic7xxx_old/
467 467
468AIMSLAB FM RADIO RECEIVER DRIVER
469M: Hans Verkuil <hverkuil@xs4all.nl>
470L: linux-media@vger.kernel.org
471T: git git://linuxtv.org/media_tree.git
472W: http://linuxtv.org
473S: Maintained
474F: drivers/media/radio/radio-aimslab*
475
468AIO 476AIO
469M: Benjamin LaHaise <bcrl@kvack.org> 477M: Benjamin LaHaise <bcrl@kvack.org>
470L: linux-aio@kvack.org 478L: linux-aio@kvack.org
@@ -559,6 +567,18 @@ L: linux-rdma@vger.kernel.org
559S: Maintained 567S: Maintained
560F: drivers/infiniband/hw/amso1100/ 568F: drivers/infiniband/hw/amso1100/
561 569
570ANALOG DEVICES INC AD9389B DRIVER
571M: Hans Verkuil <hans.verkuil@cisco.com>
572L: linux-media@vger.kernel.org
573S: Maintained
574F: drivers/media/i2c/ad9389b*
575
576ANALOG DEVICES INC ADV7604 DRIVER
577M: Hans Verkuil <hans.verkuil@cisco.com>
578L: linux-media@vger.kernel.org
579S: Maintained
580F: drivers/media/i2c/adv7604*
581
562ANALOG DEVICES INC ASOC CODEC DRIVERS 582ANALOG DEVICES INC ASOC CODEC DRIVERS
563M: Lars-Peter Clausen <lars@metafoo.de> 583M: Lars-Peter Clausen <lars@metafoo.de>
564L: device-drivers-devel@blackfin.uclinux.org 584L: device-drivers-devel@blackfin.uclinux.org
@@ -1126,6 +1146,14 @@ F: arch/arm/mach-s5pv210/mach-goni.c
1126F: arch/arm/mach-exynos/mach-universal_c210.c 1146F: arch/arm/mach-exynos/mach-universal_c210.c
1127F: arch/arm/mach-exynos/mach-nuri.c 1147F: arch/arm/mach-exynos/mach-nuri.c
1128 1148
1149ARM/SAMSUNG S5P SERIES 2D GRAPHICS ACCELERATION (G2D) SUPPORT
1150M: Kyungmin Park <kyungmin.park@samsung.com>
1151M: Kamil Debski <k.debski@samsung.com>
1152L: linux-arm-kernel@lists.infradead.org
1153L: linux-media@vger.kernel.org
1154S: Maintained
1155F: drivers/media/platform/s5p-g2d/
1156
1129ARM/SAMSUNG S5P SERIES FIMC SUPPORT 1157ARM/SAMSUNG S5P SERIES FIMC SUPPORT
1130M: Kyungmin Park <kyungmin.park@samsung.com> 1158M: Kyungmin Park <kyungmin.park@samsung.com>
1131M: Sylwester Nawrocki <s.nawrocki@samsung.com> 1159M: Sylwester Nawrocki <s.nawrocki@samsung.com>
@@ -1291,6 +1319,14 @@ S: Maintained
1291F: arch/arm64/ 1319F: arch/arm64/
1292F: Documentation/arm64/ 1320F: Documentation/arm64/
1293 1321
1322AS3645A LED FLASH CONTROLLER DRIVER
1323M: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
1324L: linux-media@vger.kernel.org
1325T: git git://linuxtv.org/media_tree.git
1326S: Maintained
1327F: drivers/media/i2c/as3645a.c
1328F: include/media/as3645a.h
1329
1294ASC7621 HARDWARE MONITOR DRIVER 1330ASC7621 HARDWARE MONITOR DRIVER
1295M: George Joseph <george.joseph@fairview5.com> 1331M: George Joseph <george.joseph@fairview5.com>
1296L: lm-sensors@lm-sensors.org 1332L: lm-sensors@lm-sensors.org
@@ -1538,6 +1574,14 @@ T: git git://linuxtv.org/media_tree.git
1538S: Maintained 1574S: Maintained
1539F: drivers/media/usb/dvb-usb-v2/az6007.c 1575F: drivers/media/usb/dvb-usb-v2/az6007.c
1540 1576
1577AZTECH FM RADIO RECEIVER DRIVER
1578M: Hans Verkuil <hverkuil@xs4all.nl>
1579L: linux-media@vger.kernel.org
1580T: git git://linuxtv.org/media_tree.git
1581W: http://linuxtv.org
1582S: Maintained
1583F: drivers/media/radio/radio-aztech*
1584
1541B43 WIRELESS DRIVER 1585B43 WIRELESS DRIVER
1542M: Stefano Brivio <stefano.brivio@polimi.it> 1586M: Stefano Brivio <stefano.brivio@polimi.it>
1543L: linux-wireless@vger.kernel.org 1587L: linux-wireless@vger.kernel.org
@@ -1637,6 +1681,15 @@ W: http://blackfin.uclinux.org/
1637S: Supported 1681S: Supported
1638F: drivers/i2c/busses/i2c-bfin-twi.c 1682F: drivers/i2c/busses/i2c-bfin-twi.c
1639 1683
1684BLACKFIN MEDIA DRIVER
1685M: Scott Jiang <scott.jiang.linux@gmail.com>
1686L: uclinux-dist-devel@blackfin.uclinux.org
1687W: http://blackfin.uclinux.org/
1688S: Supported
1689F: drivers/media/platform/blackfin/
1690F: drivers/media/i2c/adv7183*
1691F: drivers/media/i2c/vs6624*
1692
1640BLINKM RGB LED DRIVER 1693BLINKM RGB LED DRIVER
1641M: Jan-Simon Moeller <jansimon.moeller@gmx.de> 1694M: Jan-Simon Moeller <jansimon.moeller@gmx.de>
1642S: Maintained 1695S: Maintained
@@ -1820,6 +1873,14 @@ S: Supported
1820F: Documentation/filesystems/caching/cachefiles.txt 1873F: Documentation/filesystems/caching/cachefiles.txt
1821F: fs/cachefiles/ 1874F: fs/cachefiles/
1822 1875
1876CADET FM/AM RADIO RECEIVER DRIVER
1877M: Hans Verkuil <hverkuil@xs4all.nl>
1878L: linux-media@vger.kernel.org
1879T: git git://linuxtv.org/media_tree.git
1880W: http://linuxtv.org
1881S: Maintained
1882F: drivers/media/radio/radio-cadet*
1883
1823CAFE CMOS INTEGRATED CAMERA CONTROLLER DRIVER 1884CAFE CMOS INTEGRATED CAMERA CONTROLLER DRIVER
1824M: Jonathan Corbet <corbet@lwn.net> 1885M: Jonathan Corbet <corbet@lwn.net>
1825L: linux-media@vger.kernel.org 1886L: linux-media@vger.kernel.org
@@ -2221,6 +2282,15 @@ F: Documentation/video4linux/cx18.txt
2221F: drivers/media/pci/cx18/ 2282F: drivers/media/pci/cx18/
2222F: include/uapi/linux/ivtv* 2283F: include/uapi/linux/ivtv*
2223 2284
2285CX2341X MPEG ENCODER HELPER MODULE
2286M: Hans Verkuil <hverkuil@xs4all.nl>
2287L: linux-media@vger.kernel.org
2288T: git git://linuxtv.org/media_tree.git
2289W: http://linuxtv.org
2290S: Maintained
2291F: drivers/media/i2c/cx2341x*
2292F: include/media/cx2341x*
2293
2224CX88 VIDEO4LINUX DRIVER 2294CX88 VIDEO4LINUX DRIVER
2225M: Mauro Carvalho Chehab <mchehab@redhat.com> 2295M: Mauro Carvalho Chehab <mchehab@redhat.com>
2226L: linux-media@vger.kernel.org 2296L: linux-media@vger.kernel.org
@@ -2598,6 +2668,13 @@ S: Maintained
2598F: drivers/gpu/drm/tegra/ 2668F: drivers/gpu/drm/tegra/
2599F: Documentation/devicetree/bindings/gpu/nvidia,tegra20-host1x.txt 2669F: Documentation/devicetree/bindings/gpu/nvidia,tegra20-host1x.txt
2600 2670
2671DSBR100 USB FM RADIO DRIVER
2672M: Alexey Klimov <klimov.linux@gmail.com>
2673L: linux-media@vger.kernel.org
2674T: git git://linuxtv.org/media_tree.git
2675S: Maintained
2676F: drivers/media/radio/dsbr100.c
2677
2601DSCC4 DRIVER 2678DSCC4 DRIVER
2602M: Francois Romieu <romieu@fr.zoreil.com> 2679M: Francois Romieu <romieu@fr.zoreil.com>
2603L: netdev@vger.kernel.org 2680L: netdev@vger.kernel.org
@@ -3364,6 +3441,14 @@ W: http://www.icp-vortex.com/
3364S: Supported 3441S: Supported
3365F: drivers/scsi/gdt* 3442F: drivers/scsi/gdt*
3366 3443
3444GEMTEK FM RADIO RECEIVER DRIVER
3445M: Hans Verkuil <hverkuil@xs4all.nl>
3446L: linux-media@vger.kernel.org
3447T: git git://linuxtv.org/media_tree.git
3448W: http://linuxtv.org
3449S: Maintained
3450F: drivers/media/radio/radio-gemtek*
3451
3367GENERIC GPIO I2C DRIVER 3452GENERIC GPIO I2C DRIVER
3368M: Haavard Skinnemoen <hskinnemoen@gmail.com> 3453M: Haavard Skinnemoen <hskinnemoen@gmail.com>
3369S: Supported 3454S: Supported
@@ -4250,6 +4335,14 @@ F: Documentation/isapnp.txt
4250F: drivers/pnp/isapnp/ 4335F: drivers/pnp/isapnp/
4251F: include/linux/isapnp.h 4336F: include/linux/isapnp.h
4252 4337
4338ISA RADIO MODULE
4339M: Hans Verkuil <hverkuil@xs4all.nl>
4340L: linux-media@vger.kernel.org
4341T: git git://linuxtv.org/media_tree.git
4342W: http://linuxtv.org
4343S: Maintained
4344F: drivers/media/radio/radio-isa*
4345
4253iSCSI BOOT FIRMWARE TABLE (iBFT) DRIVER 4346iSCSI BOOT FIRMWARE TABLE (iBFT) DRIVER
4254M: Peter Jones <pjones@redhat.com> 4347M: Peter Jones <pjones@redhat.com>
4255M: Konrad Rzeszutek Wilk <konrad@kernel.org> 4348M: Konrad Rzeszutek Wilk <konrad@kernel.org>
@@ -4408,6 +4501,14 @@ W: http://lse.sourceforge.net/kdump/
4408S: Maintained 4501S: Maintained
4409F: Documentation/kdump/ 4502F: Documentation/kdump/
4410 4503
4504KEENE FM RADIO TRANSMITTER DRIVER
4505M: Hans Verkuil <hverkuil@xs4all.nl>
4506L: linux-media@vger.kernel.org
4507T: git git://linuxtv.org/media_tree.git
4508W: http://linuxtv.org
4509S: Maintained
4510F: drivers/media/radio/radio-keene*
4511
4411KERNEL AUTOMOUNTER v4 (AUTOFS4) 4512KERNEL AUTOMOUNTER v4 (AUTOFS4)
4412M: Ian Kent <raven@themaw.net> 4513M: Ian Kent <raven@themaw.net>
4413L: autofs@vger.kernel.org 4514L: autofs@vger.kernel.org
@@ -4895,6 +4996,13 @@ Q: http://patchwork.linuxtv.org/project/linux-media/list/
4895S: Maintained 4996S: Maintained
4896F: drivers/media/dvb-frontends/m88rs2000* 4997F: drivers/media/dvb-frontends/m88rs2000*
4897 4998
4999MA901 MASTERKIT USB FM RADIO DRIVER
5000M: Alexey Klimov <klimov.linux@gmail.com>
5001L: linux-media@vger.kernel.org
5002T: git git://linuxtv.org/media_tree.git
5003S: Maintained
5004F: drivers/media/radio/radio-ma901.c
5005
4898MAC80211 5006MAC80211
4899M: Johannes Berg <johannes@sipsolutions.net> 5007M: Johannes Berg <johannes@sipsolutions.net>
4900L: linux-wireless@vger.kernel.org 5008L: linux-wireless@vger.kernel.org
@@ -4992,6 +5100,14 @@ S: Maintained
4992F: Documentation/hwmon/max6650 5100F: Documentation/hwmon/max6650
4993F: drivers/hwmon/max6650.c 5101F: drivers/hwmon/max6650.c
4994 5102
5103MAXIRADIO FM RADIO RECEIVER DRIVER
5104M: Hans Verkuil <hverkuil@xs4all.nl>
5105L: linux-media@vger.kernel.org
5106T: git git://linuxtv.org/media_tree.git
5107W: http://linuxtv.org
5108S: Maintained
5109F: drivers/media/radio/radio-maxiradio*
5110
4995MEDIA INPUT INFRASTRUCTURE (V4L/DVB) 5111MEDIA INPUT INFRASTRUCTURE (V4L/DVB)
4996M: Mauro Carvalho Chehab <mchehab@redhat.com> 5112M: Mauro Carvalho Chehab <mchehab@redhat.com>
4997P: LinuxTV.org Project 5113P: LinuxTV.org Project
@@ -5014,6 +5130,14 @@ F: include/uapi/linux/meye.h
5014F: include/uapi/linux/ivtv* 5130F: include/uapi/linux/ivtv*
5015F: include/uapi/linux/uvcvideo.h 5131F: include/uapi/linux/uvcvideo.h
5016 5132
5133MEDIAVISION PRO MOVIE STUDIO DRIVER
5134M: Hans Verkuil <hverkuil@xs4all.nl>
5135L: linux-media@vger.kernel.org
5136T: git git://linuxtv.org/media_tree.git
5137W: http://linuxtv.org
5138S: Odd Fixes
5139F: drivers/media/parport/pms*
5140
5017MEGARAID SCSI DRIVERS 5141MEGARAID SCSI DRIVERS
5018M: Neela Syam Kolli <megaraidlinux@lsi.com> 5142M: Neela Syam Kolli <megaraidlinux@lsi.com>
5019L: linux-scsi@vger.kernel.org 5143L: linux-scsi@vger.kernel.org
@@ -5087,6 +5211,14 @@ S: Supported
5087F: Documentation/mips/ 5211F: Documentation/mips/
5088F: arch/mips/ 5212F: arch/mips/
5089 5213
5214MIROSOUND PCM20 FM RADIO RECEIVER DRIVER
5215M: Hans Verkuil <hverkuil@xs4all.nl>
5216L: linux-media@vger.kernel.org
5217T: git git://linuxtv.org/media_tree.git
5218W: http://linuxtv.org
5219S: Odd Fixes
5220F: drivers/media/radio/radio-miropcm20*
5221
5090MODULE SUPPORT 5222MODULE SUPPORT
5091M: Rusty Russell <rusty@rustcorp.com.au> 5223M: Rusty Russell <rusty@rustcorp.com.au>
5092S: Maintained 5224S: Maintained
@@ -5125,6 +5257,38 @@ L: platform-driver-x86@vger.kernel.org
5125S: Supported 5257S: Supported
5126F: drivers/platform/x86/msi-wmi.c 5258F: drivers/platform/x86/msi-wmi.c
5127 5259
5260MT9M032 SENSOR DRIVER
5261M: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
5262L: linux-media@vger.kernel.org
5263T: git git://linuxtv.org/media_tree.git
5264S: Maintained
5265F: drivers/media/i2c/mt9m032.c
5266F: include/media/mt9m032.h
5267
5268MT9P031 SENSOR DRIVER
5269M: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
5270L: linux-media@vger.kernel.org
5271T: git git://linuxtv.org/media_tree.git
5272S: Maintained
5273F: drivers/media/i2c/mt9p031.c
5274F: include/media/mt9p031.h
5275
5276MT9T001 SENSOR DRIVER
5277M: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
5278L: linux-media@vger.kernel.org
5279T: git git://linuxtv.org/media_tree.git
5280S: Maintained
5281F: drivers/media/i2c/mt9t001.c
5282F: include/media/mt9t001.h
5283
5284MT9V032 SENSOR DRIVER
5285M: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
5286L: linux-media@vger.kernel.org
5287T: git git://linuxtv.org/media_tree.git
5288S: Maintained
5289F: drivers/media/i2c/mt9v032.c
5290F: include/media/mt9v032.h
5291
5128MULTIFUNCTION DEVICES (MFD) 5292MULTIFUNCTION DEVICES (MFD)
5129M: Samuel Ortiz <sameo@linux.intel.com> 5293M: Samuel Ortiz <sameo@linux.intel.com>
5130T: git git://git.kernel.org/pub/scm/linux/kernel/git/sameo/mfd-2.6.git 5294T: git git://git.kernel.org/pub/scm/linux/kernel/git/sameo/mfd-2.6.git
@@ -6276,6 +6440,14 @@ L: linux-hexagon@vger.kernel.org
6276S: Supported 6440S: Supported
6277F: arch/hexagon/ 6441F: arch/hexagon/
6278 6442
6443QUICKCAM PARALLEL PORT WEBCAMS
6444M: Hans Verkuil <hverkuil@xs4all.nl>
6445L: linux-media@vger.kernel.org
6446T: git git://linuxtv.org/media_tree.git
6447W: http://linuxtv.org
6448S: Odd Fixes
6449F: drivers/media/parport/*-qcam*
6450
6279RADOS BLOCK DEVICE (RBD) 6451RADOS BLOCK DEVICE (RBD)
6280M: Yehuda Sadeh <yehuda@inktank.com> 6452M: Yehuda Sadeh <yehuda@inktank.com>
6281M: Sage Weil <sage@inktank.com> 6453M: Sage Weil <sage@inktank.com>
@@ -6550,6 +6722,14 @@ L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
6550S: Supported 6722S: Supported
6551F: drivers/mmc/host/s3cmci.* 6723F: drivers/mmc/host/s3cmci.*
6552 6724
6725SAA6588 RDS RECEIVER DRIVER
6726M: Hans Verkuil <hverkuil@xs4all.nl>
6727L: linux-media@vger.kernel.org
6728T: git git://linuxtv.org/media_tree.git
6729W: http://linuxtv.org
6730S: Odd Fixes
6731F: drivers/media/i2c/saa6588*
6732
6553SAA7134 VIDEO4LINUX DRIVER 6733SAA7134 VIDEO4LINUX DRIVER
6554M: Mauro Carvalho Chehab <mchehab@redhat.com> 6734M: Mauro Carvalho Chehab <mchehab@redhat.com>
6555L: linux-media@vger.kernel.org 6735L: linux-media@vger.kernel.org
@@ -6560,10 +6740,9 @@ F: Documentation/video4linux/saa7134/
6560F: drivers/media/pci/saa7134/ 6740F: drivers/media/pci/saa7134/
6561 6741
6562SAA7146 VIDEO4LINUX-2 DRIVER 6742SAA7146 VIDEO4LINUX-2 DRIVER
6563M: Michael Hunold <michael@mihu.de> 6743M: Hans Verkuil <hverkuil@xs4all.nl>
6564L: linux-media@vger.kernel.org 6744L: linux-media@vger.kernel.org
6565T: git git://linuxtv.org/media_tree.git 6745T: git git://linuxtv.org/media_tree.git
6566W: http://www.mihu.de/linux/saa7146
6567S: Maintained 6746S: Maintained
6568F: drivers/media/common/saa7146/ 6747F: drivers/media/common/saa7146/
6569F: drivers/media/pci/saa7146/ 6748F: drivers/media/pci/saa7146/
@@ -6605,6 +6784,13 @@ S: Maintained
6605F: drivers/media/platform/s3c-camif/ 6784F: drivers/media/platform/s3c-camif/
6606F: include/media/s3c_camif.h 6785F: include/media/s3c_camif.h
6607 6786
6787SAMSUNG S5C73M3 CAMERA DRIVER
6788M: Kyungmin Park <kyungmin.park@samsung.com>
6789M: Andrzej Hajda <a.hajda@samsung.com>
6790L: linux-media@vger.kernel.org
6791S: Supported
6792F: drivers/media/i2c/s5c73m3/*
6793
6608SERIAL DRIVERS 6794SERIAL DRIVERS
6609M: Greg Kroah-Hartman <gregkh@linuxfoundation.org> 6795M: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
6610L: linux-serial@vger.kernel.org 6796L: linux-serial@vger.kernel.org
@@ -6866,6 +7052,38 @@ M: Robin Holt <holt@sgi.com>
6866S: Maintained 7052S: Maintained
6867F: drivers/misc/sgi-xp/ 7053F: drivers/misc/sgi-xp/
6868 7054
7055SI470X FM RADIO RECEIVER I2C DRIVER
7056M: Hans Verkuil <hverkuil@xs4all.nl>
7057L: linux-media@vger.kernel.org
7058T: git git://linuxtv.org/media_tree.git
7059W: http://linuxtv.org
7060S: Odd Fixes
7061F: drivers/media/radio/si470x/radio-si470x-i2c.c
7062
7063SI470X FM RADIO RECEIVER USB DRIVER
7064M: Hans Verkuil <hverkuil@xs4all.nl>
7065L: linux-media@vger.kernel.org
7066T: git git://linuxtv.org/media_tree.git
7067W: http://linuxtv.org
7068S: Maintained
7069F: drivers/media/radio/si470x/radio-si470x-common.c
7070F: drivers/media/radio/si470x/radio-si470x.h
7071F: drivers/media/radio/si470x/radio-si470x-usb.c
7072
7073SH_VEU V4L2 MEM2MEM DRIVER
7074M: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
7075L: linux-media@vger.kernel.org
7076S: Maintained
7077F: drivers/media/platform/sh_veu.c
7078F: include/media/sh_veu.h
7079
7080SH_VOU V4L2 OUTPUT DRIVER
7081M: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
7082L: linux-media@vger.kernel.org
7083S: Maintained
7084F: drivers/media/platform/sh_vou.c
7085F: include/media/sh_vou.h
7086
6869SIMPLE FIRMWARE INTERFACE (SFI) 7087SIMPLE FIRMWARE INTERFACE (SFI)
6870M: Len Brown <lenb@kernel.org> 7088M: Len Brown <lenb@kernel.org>
6871L: sfi-devel@simplefirmware.org 7089L: sfi-devel@simplefirmware.org
@@ -7533,6 +7751,14 @@ T: git git://linuxtv.org/mkrufky/tuners.git
7533S: Maintained 7751S: Maintained
7534F: drivers/media/tuners/tda8290.* 7752F: drivers/media/tuners/tda8290.*
7535 7753
7754TDA9840 MEDIA DRIVER
7755M: Hans Verkuil <hverkuil@xs4all.nl>
7756L: linux-media@vger.kernel.org
7757T: git git://linuxtv.org/media_tree.git
7758W: http://linuxtv.org
7759S: Maintained
7760F: drivers/media/i2c/tda9840*
7761
7536TEA5761 TUNER DRIVER 7762TEA5761 TUNER DRIVER
7537M: Mauro Carvalho Chehab <mchehab@redhat.com> 7763M: Mauro Carvalho Chehab <mchehab@redhat.com>
7538L: linux-media@vger.kernel.org 7764L: linux-media@vger.kernel.org
@@ -7549,6 +7775,22 @@ T: git git://linuxtv.org/media_tree.git
7549S: Maintained 7775S: Maintained
7550F: drivers/media/tuners/tea5767.* 7776F: drivers/media/tuners/tea5767.*
7551 7777
7778TEA6415C MEDIA DRIVER
7779M: Hans Verkuil <hverkuil@xs4all.nl>
7780L: linux-media@vger.kernel.org
7781T: git git://linuxtv.org/media_tree.git
7782W: http://linuxtv.org
7783S: Maintained
7784F: drivers/media/i2c/tea6415c*
7785
7786TEA6420 MEDIA DRIVER
7787M: Hans Verkuil <hverkuil@xs4all.nl>
7788L: linux-media@vger.kernel.org
7789T: git git://linuxtv.org/media_tree.git
7790W: http://linuxtv.org
7791S: Maintained
7792F: drivers/media/i2c/tea6420*
7793
7552TEAM DRIVER 7794TEAM DRIVER
7553M: Jiri Pirko <jiri@resnulli.us> 7795M: Jiri Pirko <jiri@resnulli.us>
7554L: netdev@vger.kernel.org 7796L: netdev@vger.kernel.org
@@ -8198,6 +8440,14 @@ S: Maintained
8198F: drivers/media/usb/uvc/ 8440F: drivers/media/usb/uvc/
8199F: include/uapi/linux/uvcvideo.h 8441F: include/uapi/linux/uvcvideo.h
8200 8442
8443USB VISION DRIVER
8444M: Hans Verkuil <hverkuil@xs4all.nl>
8445L: linux-media@vger.kernel.org
8446T: git git://linuxtv.org/media_tree.git
8447W: http://linuxtv.org
8448S: Odd Fixes
8449F: drivers/media/usb/usbvision/
8450
8201USB WEBCAM GADGET 8451USB WEBCAM GADGET
8202M: Laurent Pinchart <laurent.pinchart@ideasonboard.com> 8452M: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
8203L: linux-usb@vger.kernel.org 8453L: linux-usb@vger.kernel.org
@@ -8347,6 +8597,14 @@ L: netdev@vger.kernel.org
8347S: Maintained 8597S: Maintained
8348F: drivers/net/ethernet/via/via-velocity.* 8598F: drivers/net/ethernet/via/via-velocity.*
8349 8599
8600VIVI VIRTUAL VIDEO DRIVER
8601M: Hans Verkuil <hverkuil@xs4all.nl>
8602L: linux-media@vger.kernel.org
8603T: git git://linuxtv.org/media_tree.git
8604W: http://linuxtv.org
8605S: Maintained
8606F: drivers/media/platform/vivi*
8607
8350VLAN (802.1Q) 8608VLAN (802.1Q)
8351M: Patrick McHardy <kaber@trash.net> 8609M: Patrick McHardy <kaber@trash.net>
8352L: netdev@vger.kernel.org 8610L: netdev@vger.kernel.org
diff --git a/arch/arm/mach-davinci/board-da850-evm.c b/arch/arm/mach-davinci/board-da850-evm.c
index 1f50a653eb8c..c2dfe06563df 100644
--- a/arch/arm/mach-davinci/board-da850-evm.c
+++ b/arch/arm/mach-davinci/board-da850-evm.c
@@ -1253,11 +1253,24 @@ static struct vpif_capture_config da850_vpif_capture_config = {
1253}; 1253};
1254 1254
1255/* VPIF display configuration */ 1255/* VPIF display configuration */
1256
1257static struct adv7343_platform_data adv7343_pdata = {
1258 .mode_config = {
1259 .dac_3 = 1,
1260 .dac_2 = 1,
1261 .dac_1 = 1,
1262 },
1263 .sd_config = {
1264 .sd_dac_out1 = 1,
1265 },
1266};
1267
1256static struct vpif_subdev_info da850_vpif_subdev[] = { 1268static struct vpif_subdev_info da850_vpif_subdev[] = {
1257 { 1269 {
1258 .name = "adv7343", 1270 .name = "adv7343",
1259 .board_info = { 1271 .board_info = {
1260 I2C_BOARD_INFO("adv7343", 0x2a), 1272 I2C_BOARD_INFO("adv7343", 0x2a),
1273 .platform_data = &adv7343_pdata,
1261 }, 1274 },
1262 }, 1275 },
1263}; 1276};
diff --git a/arch/arm/mach-davinci/board-dm644x-evm.c b/arch/arm/mach-davinci/board-dm644x-evm.c
index e4a16f98e6a2..71735e7797cc 100644
--- a/arch/arm/mach-davinci/board-dm644x-evm.c
+++ b/arch/arm/mach-davinci/board-dm644x-evm.c
@@ -690,7 +690,7 @@ static struct vpbe_output dm644xevm_vpbe_outputs[] = {
690 .std = VENC_STD_ALL, 690 .std = VENC_STD_ALL,
691 .capabilities = V4L2_OUT_CAP_STD, 691 .capabilities = V4L2_OUT_CAP_STD,
692 }, 692 },
693 .subdev_name = VPBE_VENC_SUBDEV_NAME, 693 .subdev_name = DM644X_VPBE_VENC_SUBDEV_NAME,
694 .default_mode = "ntsc", 694 .default_mode = "ntsc",
695 .num_modes = ARRAY_SIZE(dm644xevm_enc_std_timing), 695 .num_modes = ARRAY_SIZE(dm644xevm_enc_std_timing),
696 .modes = dm644xevm_enc_std_timing, 696 .modes = dm644xevm_enc_std_timing,
@@ -702,7 +702,7 @@ static struct vpbe_output dm644xevm_vpbe_outputs[] = {
702 .type = V4L2_OUTPUT_TYPE_ANALOG, 702 .type = V4L2_OUTPUT_TYPE_ANALOG,
703 .capabilities = V4L2_OUT_CAP_DV_TIMINGS, 703 .capabilities = V4L2_OUT_CAP_DV_TIMINGS,
704 }, 704 },
705 .subdev_name = VPBE_VENC_SUBDEV_NAME, 705 .subdev_name = DM644X_VPBE_VENC_SUBDEV_NAME,
706 .default_mode = "480p59_94", 706 .default_mode = "480p59_94",
707 .num_modes = ARRAY_SIZE(dm644xevm_enc_preset_timing), 707 .num_modes = ARRAY_SIZE(dm644xevm_enc_preset_timing),
708 .modes = dm644xevm_enc_preset_timing, 708 .modes = dm644xevm_enc_preset_timing,
@@ -713,10 +713,10 @@ static struct vpbe_config dm644xevm_display_cfg = {
713 .module_name = "dm644x-vpbe-display", 713 .module_name = "dm644x-vpbe-display",
714 .i2c_adapter_id = 1, 714 .i2c_adapter_id = 1,
715 .osd = { 715 .osd = {
716 .module_name = VPBE_OSD_SUBDEV_NAME, 716 .module_name = DM644X_VPBE_OSD_SUBDEV_NAME,
717 }, 717 },
718 .venc = { 718 .venc = {
719 .module_name = VPBE_VENC_SUBDEV_NAME, 719 .module_name = DM644X_VPBE_VENC_SUBDEV_NAME,
720 }, 720 },
721 .num_outputs = ARRAY_SIZE(dm644xevm_vpbe_outputs), 721 .num_outputs = ARRAY_SIZE(dm644xevm_vpbe_outputs),
722 .outputs = dm644xevm_vpbe_outputs, 722 .outputs = dm644xevm_vpbe_outputs,
diff --git a/arch/arm/mach-davinci/dm644x.c b/arch/arm/mach-davinci/dm644x.c
index 11c79a3362ef..db1dd92e00af 100644
--- a/arch/arm/mach-davinci/dm644x.c
+++ b/arch/arm/mach-davinci/dm644x.c
@@ -669,19 +669,14 @@ static struct resource dm644x_osd_resources[] = {
669 }, 669 },
670}; 670};
671 671
672static struct osd_platform_data dm644x_osd_data = {
673 .vpbe_type = VPBE_VERSION_1,
674};
675
676static struct platform_device dm644x_osd_dev = { 672static struct platform_device dm644x_osd_dev = {
677 .name = VPBE_OSD_SUBDEV_NAME, 673 .name = DM644X_VPBE_OSD_SUBDEV_NAME,
678 .id = -1, 674 .id = -1,
679 .num_resources = ARRAY_SIZE(dm644x_osd_resources), 675 .num_resources = ARRAY_SIZE(dm644x_osd_resources),
680 .resource = dm644x_osd_resources, 676 .resource = dm644x_osd_resources,
681 .dev = { 677 .dev = {
682 .dma_mask = &dm644x_video_dma_mask, 678 .dma_mask = &dm644x_video_dma_mask,
683 .coherent_dma_mask = DMA_BIT_MASK(32), 679 .coherent_dma_mask = DMA_BIT_MASK(32),
684 .platform_data = &dm644x_osd_data,
685 }, 680 },
686}; 681};
687 682
@@ -751,12 +746,11 @@ static struct platform_device dm644x_vpbe_display = {
751}; 746};
752 747
753static struct venc_platform_data dm644x_venc_pdata = { 748static struct venc_platform_data dm644x_venc_pdata = {
754 .venc_type = VPBE_VERSION_1,
755 .setup_clock = dm644x_venc_setup_clock, 749 .setup_clock = dm644x_venc_setup_clock,
756}; 750};
757 751
758static struct platform_device dm644x_venc_dev = { 752static struct platform_device dm644x_venc_dev = {
759 .name = VPBE_VENC_SUBDEV_NAME, 753 .name = DM644X_VPBE_VENC_SUBDEV_NAME,
760 .id = -1, 754 .id = -1,
761 .num_resources = ARRAY_SIZE(dm644x_venc_resources), 755 .num_resources = ARRAY_SIZE(dm644x_venc_resources),
762 .resource = dm644x_venc_resources, 756 .resource = dm644x_venc_resources,
diff --git a/arch/arm/mach-exynos/mach-nuri.c b/arch/arm/mach-exynos/mach-nuri.c
index b8b3fbf0bae7..1ea79730187f 100644
--- a/arch/arm/mach-exynos/mach-nuri.c
+++ b/arch/arm/mach-exynos/mach-nuri.c
@@ -1208,25 +1208,25 @@ static struct i2c_board_info m5mols_board_info = {
1208 .platform_data = &m5mols_platdata, 1208 .platform_data = &m5mols_platdata,
1209}; 1209};
1210 1210
1211static struct s5p_fimc_isp_info nuri_camera_sensors[] = { 1211static struct fimc_source_info nuri_camera_sensors[] = {
1212 { 1212 {
1213 .flags = V4L2_MBUS_PCLK_SAMPLE_RISING | 1213 .flags = V4L2_MBUS_PCLK_SAMPLE_RISING |
1214 V4L2_MBUS_VSYNC_ACTIVE_LOW, 1214 V4L2_MBUS_VSYNC_ACTIVE_LOW,
1215 .bus_type = FIMC_ITU_601, 1215 .fimc_bus_type = FIMC_BUS_TYPE_ITU_601,
1216 .board_info = &s5k6aa_board_info, 1216 .board_info = &s5k6aa_board_info,
1217 .clk_frequency = 24000000UL, 1217 .clk_frequency = 24000000UL,
1218 .i2c_bus_num = 6, 1218 .i2c_bus_num = 6,
1219 }, { 1219 }, {
1220 .flags = V4L2_MBUS_PCLK_SAMPLE_FALLING | 1220 .flags = V4L2_MBUS_PCLK_SAMPLE_FALLING |
1221 V4L2_MBUS_VSYNC_ACTIVE_LOW, 1221 V4L2_MBUS_VSYNC_ACTIVE_LOW,
1222 .bus_type = FIMC_MIPI_CSI2, 1222 .fimc_bus_type = FIMC_BUS_TYPE_MIPI_CSI2,
1223 .board_info = &m5mols_board_info, 1223 .board_info = &m5mols_board_info,
1224 .clk_frequency = 24000000UL, 1224 .clk_frequency = 24000000UL,
1225 }, 1225 },
1226}; 1226};
1227 1227
1228static struct s5p_platform_fimc fimc_md_platdata = { 1228static struct s5p_platform_fimc fimc_md_platdata = {
1229 .isp_info = nuri_camera_sensors, 1229 .source_info = nuri_camera_sensors,
1230 .num_clients = ARRAY_SIZE(nuri_camera_sensors), 1230 .num_clients = ARRAY_SIZE(nuri_camera_sensors),
1231}; 1231};
1232 1232
diff --git a/arch/arm/mach-exynos/mach-universal_c210.c b/arch/arm/mach-exynos/mach-universal_c210.c
index c9d33a43103e..497fcb793dc1 100644
--- a/arch/arm/mach-exynos/mach-universal_c210.c
+++ b/arch/arm/mach-exynos/mach-universal_c210.c
@@ -987,12 +987,12 @@ static struct i2c_board_info m5mols_board_info = {
987 .platform_data = &m5mols_platdata, 987 .platform_data = &m5mols_platdata,
988}; 988};
989 989
990static struct s5p_fimc_isp_info universal_camera_sensors[] = { 990static struct fimc_source_info universal_camera_sensors[] = {
991 { 991 {
992 .mux_id = 0, 992 .mux_id = 0,
993 .flags = V4L2_MBUS_PCLK_SAMPLE_FALLING | 993 .flags = V4L2_MBUS_PCLK_SAMPLE_FALLING |
994 V4L2_MBUS_VSYNC_ACTIVE_LOW, 994 V4L2_MBUS_VSYNC_ACTIVE_LOW,
995 .bus_type = FIMC_ITU_601, 995 .fimc_bus_type = FIMC_BUS_TYPE_ITU_601,
996 .board_info = &s5k6aa_board_info, 996 .board_info = &s5k6aa_board_info,
997 .i2c_bus_num = 0, 997 .i2c_bus_num = 0,
998 .clk_frequency = 24000000UL, 998 .clk_frequency = 24000000UL,
@@ -1000,7 +1000,7 @@ static struct s5p_fimc_isp_info universal_camera_sensors[] = {
1000 .mux_id = 0, 1000 .mux_id = 0,
1001 .flags = V4L2_MBUS_PCLK_SAMPLE_FALLING | 1001 .flags = V4L2_MBUS_PCLK_SAMPLE_FALLING |
1002 V4L2_MBUS_VSYNC_ACTIVE_LOW, 1002 V4L2_MBUS_VSYNC_ACTIVE_LOW,
1003 .bus_type = FIMC_MIPI_CSI2, 1003 .fimc_bus_type = FIMC_BUS_TYPE_MIPI_CSI2,
1004 .board_info = &m5mols_board_info, 1004 .board_info = &m5mols_board_info,
1005 .i2c_bus_num = 0, 1005 .i2c_bus_num = 0,
1006 .clk_frequency = 24000000UL, 1006 .clk_frequency = 24000000UL,
@@ -1008,7 +1008,7 @@ static struct s5p_fimc_isp_info universal_camera_sensors[] = {
1008}; 1008};
1009 1009
1010static struct s5p_platform_fimc fimc_md_platdata = { 1010static struct s5p_platform_fimc fimc_md_platdata = {
1011 .isp_info = universal_camera_sensors, 1011 .source_info = universal_camera_sensors,
1012 .num_clients = ARRAY_SIZE(universal_camera_sensors), 1012 .num_clients = ARRAY_SIZE(universal_camera_sensors),
1013}; 1013};
1014 1014
diff --git a/arch/arm/mach-s5pv210/mach-goni.c b/arch/arm/mach-s5pv210/mach-goni.c
index 570481591746..3a38f7b34b94 100644
--- a/arch/arm/mach-s5pv210/mach-goni.c
+++ b/arch/arm/mach-s5pv210/mach-goni.c
@@ -840,12 +840,12 @@ static struct i2c_board_info noon010pc30_board_info = {
840 .platform_data = &noon010pc30_pldata, 840 .platform_data = &noon010pc30_pldata,
841}; 841};
842 842
843static struct s5p_fimc_isp_info goni_camera_sensors[] = { 843static struct fimc_source_info goni_camera_sensors[] = {
844 { 844 {
845 .mux_id = 0, 845 .mux_id = 0,
846 .flags = V4L2_MBUS_PCLK_SAMPLE_FALLING | 846 .flags = V4L2_MBUS_PCLK_SAMPLE_FALLING |
847 V4L2_MBUS_VSYNC_ACTIVE_LOW, 847 V4L2_MBUS_VSYNC_ACTIVE_LOW,
848 .bus_type = FIMC_ITU_601, 848 .bus_type = FIMC_BUS_TYPE_ITU_601,
849 .board_info = &noon010pc30_board_info, 849 .board_info = &noon010pc30_board_info,
850 .i2c_bus_num = 0, 850 .i2c_bus_num = 0,
851 .clk_frequency = 16000000UL, 851 .clk_frequency = 16000000UL,
@@ -853,7 +853,7 @@ static struct s5p_fimc_isp_info goni_camera_sensors[] = {
853}; 853};
854 854
855static struct s5p_platform_fimc goni_fimc_md_platdata __initdata = { 855static struct s5p_platform_fimc goni_fimc_md_platdata __initdata = {
856 .isp_info = goni_camera_sensors, 856 .source_info = goni_camera_sensors,
857 .num_clients = ARRAY_SIZE(goni_camera_sensors), 857 .num_clients = ARRAY_SIZE(goni_camera_sensors),
858}; 858};
859 859
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index ff75cabf7393..512b01c04ea7 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -2077,6 +2077,7 @@ static const struct hid_device_id hid_ignore_list[] = {
2077 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HYBRID) }, 2077 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HYBRID) },
2078 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HEATCONTROL) }, 2078 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_HEATCONTROL) },
2079 { HID_USB_DEVICE(USB_VENDOR_ID_MADCATZ, USB_DEVICE_ID_MADCATZ_BEATPAD) }, 2079 { HID_USB_DEVICE(USB_VENDOR_ID_MADCATZ, USB_DEVICE_ID_MADCATZ_BEATPAD) },
2080 { HID_USB_DEVICE(USB_VENDOR_ID_MASTERKIT, USB_DEVICE_ID_MASTERKIT_MA901RADIO) },
2080 { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS) }, 2081 { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS) },
2081 { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS) }, 2082 { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS) },
2082 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT1) }, 2083 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT1) },
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 6e5c2ffa8d96..92e47e5c9564 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -557,6 +557,9 @@
557#define USB_VENDOR_ID_MADCATZ 0x0738 557#define USB_VENDOR_ID_MADCATZ 0x0738
558#define USB_DEVICE_ID_MADCATZ_BEATPAD 0x4540 558#define USB_DEVICE_ID_MADCATZ_BEATPAD 0x4540
559 559
560#define USB_VENDOR_ID_MASTERKIT 0x16c0
561#define USB_DEVICE_ID_MASTERKIT_MA901RADIO 0x05df
562
560#define USB_VENDOR_ID_MCC 0x09db 563#define USB_VENDOR_ID_MCC 0x09db
561#define USB_DEVICE_ID_MCC_PMD1024LS 0x0076 564#define USB_DEVICE_ID_MCC_PMD1024LS 0x0076
562#define USB_DEVICE_ID_MCC_PMD1208LS 0x007a 565#define USB_DEVICE_ID_MCC_PMD1208LS 0x007a
diff --git a/drivers/media/Kconfig b/drivers/media/Kconfig
index 8567a7a64104..7f5a7cac6dc7 100644
--- a/drivers/media/Kconfig
+++ b/drivers/media/Kconfig
@@ -134,6 +134,12 @@ config DVB_NET
134 You may want to disable the network support on embedded devices. If 134 You may want to disable the network support on embedded devices. If
135 unsure say Y. 135 unsure say Y.
136 136
137# This Kconfig option is used by both PCI and USB drivers
138config TTPCI_EEPROM
139 tristate
140 depends on I2C
141 default n
142
137source "drivers/media/dvb-core/Kconfig" 143source "drivers/media/dvb-core/Kconfig"
138 144
139comment "Media drivers" 145comment "Media drivers"
@@ -157,17 +163,20 @@ source "drivers/media/firewire/Kconfig"
157# Common driver options 163# Common driver options
158source "drivers/media/common/Kconfig" 164source "drivers/media/common/Kconfig"
159 165
166comment "Media ancillary drivers (tuners, sensors, i2c, frontends)"
167
160# 168#
161# Ancillary drivers (tuners, i2c, frontends) 169# Ancillary drivers (tuners, i2c, frontends)
162# 170#
163 171
164config MEDIA_SUBDRV_AUTOSELECT 172config MEDIA_SUBDRV_AUTOSELECT
165 bool "Autoselect tuners and i2c modules to build" 173 bool "Autoselect ancillary drivers (tuners, sensors, i2c, frontends)"
166 depends on MEDIA_ANALOG_TV_SUPPORT || MEDIA_DIGITAL_TV_SUPPORT || MEDIA_CAMERA_SUPPORT 174 depends on MEDIA_ANALOG_TV_SUPPORT || MEDIA_DIGITAL_TV_SUPPORT || MEDIA_CAMERA_SUPPORT
167 default y 175 default y
168 help 176 help
169 By default, a media driver auto-selects all possible i2c 177 By default, a media driver auto-selects all possible ancillary
170 devices that are used by any of the supported devices. 178 devices such as tuners, sensors, video encoders/decoders and
179 frontends, that are used by any of the supported devices.
171 180
172 This is generally the right thing to do, except when there 181 This is generally the right thing to do, except when there
173 are strict constraints with regards to the kernel size, 182 are strict constraints with regards to the kernel size,
@@ -176,12 +185,10 @@ config MEDIA_SUBDRV_AUTOSELECT
176 Use this option with care, as deselecting ancillary drivers which 185 Use this option with care, as deselecting ancillary drivers which
177 are, in fact, necessary will result in the lack of the needed 186 are, in fact, necessary will result in the lack of the needed
178 functionality for your device (it may not tune or may not have 187 functionality for your device (it may not tune or may not have
179 the need demodulers). 188 the needed demodulators).
180 189
181 If unsure say Y. 190 If unsure say Y.
182 191
183comment "Media ancillary drivers (tuners, sensors, i2c, frontends)"
184
185source "drivers/media/i2c/Kconfig" 192source "drivers/media/i2c/Kconfig"
186source "drivers/media/tuners/Kconfig" 193source "drivers/media/tuners/Kconfig"
187source "drivers/media/dvb-frontends/Kconfig" 194source "drivers/media/dvb-frontends/Kconfig"
diff --git a/drivers/media/common/Kconfig b/drivers/media/common/Kconfig
index d2a436ce77f8..56c25e6299e9 100644
--- a/drivers/media/common/Kconfig
+++ b/drivers/media/common/Kconfig
@@ -5,6 +5,17 @@ config MEDIA_COMMON_OPTIONS
5comment "common driver options" 5comment "common driver options"
6 depends on MEDIA_COMMON_OPTIONS 6 depends on MEDIA_COMMON_OPTIONS
7 7
8config VIDEO_CX2341X
9 tristate
10
11config VIDEO_BTCX
12 depends on PCI
13 tristate
14
15config VIDEO_TVEEPROM
16 tristate
17 depends on I2C
18
8source "drivers/media/common/b2c2/Kconfig" 19source "drivers/media/common/b2c2/Kconfig"
9source "drivers/media/common/saa7146/Kconfig" 20source "drivers/media/common/saa7146/Kconfig"
10source "drivers/media/common/siano/Kconfig" 21source "drivers/media/common/siano/Kconfig"
diff --git a/drivers/media/common/Makefile b/drivers/media/common/Makefile
index b8e2e3a33a31..8f8d18755d15 100644
--- a/drivers/media/common/Makefile
+++ b/drivers/media/common/Makefile
@@ -1 +1,4 @@
1obj-y += b2c2/ saa7146/ siano/ 1obj-y += b2c2/ saa7146/ siano/
2obj-$(CONFIG_VIDEO_CX2341X) += cx2341x.o
3obj-$(CONFIG_VIDEO_BTCX) += btcx-risc.o
4obj-$(CONFIG_VIDEO_TVEEPROM) += tveeprom.o
diff --git a/drivers/media/i2c/btcx-risc.c b/drivers/media/common/btcx-risc.c
index ac1b2687a20d..ac1b2687a20d 100644
--- a/drivers/media/i2c/btcx-risc.c
+++ b/drivers/media/common/btcx-risc.c
diff --git a/drivers/media/i2c/btcx-risc.h b/drivers/media/common/btcx-risc.h
index f8bc6e8e7b51..f8bc6e8e7b51 100644
--- a/drivers/media/i2c/btcx-risc.h
+++ b/drivers/media/common/btcx-risc.h
diff --git a/drivers/media/i2c/cx2341x.c b/drivers/media/common/cx2341x.c
index 103ef6bad2e2..103ef6bad2e2 100644
--- a/drivers/media/i2c/cx2341x.c
+++ b/drivers/media/common/cx2341x.c
diff --git a/drivers/media/common/saa7146/saa7146_fops.c b/drivers/media/common/saa7146/saa7146_fops.c
index b3890bd49df6..eda01bc68ab2 100644
--- a/drivers/media/common/saa7146/saa7146_fops.c
+++ b/drivers/media/common/saa7146/saa7146_fops.c
@@ -105,7 +105,7 @@ void saa7146_buffer_finish(struct saa7146_dev *dev,
105 } 105 }
106 106
107 q->curr->vb.state = state; 107 q->curr->vb.state = state;
108 do_gettimeofday(&q->curr->vb.ts); 108 v4l2_get_timestamp(&q->curr->vb.ts);
109 wake_up(&q->curr->vb.done); 109 wake_up(&q->curr->vb.done);
110 110
111 q->curr = NULL; 111 q->curr = NULL;
@@ -265,8 +265,7 @@ static int fops_release(struct file *file)
265 265
266 DEB_EE("file:%p\n", file); 266 DEB_EE("file:%p\n", file);
267 267
268 if (mutex_lock_interruptible(vdev->lock)) 268 mutex_lock(vdev->lock);
269 return -ERESTARTSYS;
270 269
271 if (vdev->vfl_type == VFL_TYPE_VBI) { 270 if (vdev->vfl_type == VFL_TYPE_VBI) {
272 if (dev->ext_vv_data->capabilities & V4L2_CAP_VBI_CAPTURE) 271 if (dev->ext_vv_data->capabilities & V4L2_CAP_VBI_CAPTURE)
diff --git a/drivers/media/i2c/tveeprom.c b/drivers/media/common/tveeprom.c
index 3b6cf034976a..cc1e172dfece 100644
--- a/drivers/media/i2c/tveeprom.c
+++ b/drivers/media/common/tveeprom.c
@@ -96,170 +96,170 @@ static struct HAUPPAUGE_TUNER
96hauppauge_tuner[] = 96hauppauge_tuner[] =
97{ 97{
98 /* 0-9 */ 98 /* 0-9 */
99 { TUNER_ABSENT, "None" }, 99 { TUNER_ABSENT, "None" },
100 { TUNER_ABSENT, "External" }, 100 { TUNER_ABSENT, "External" },
101 { TUNER_ABSENT, "Unspecified" }, 101 { TUNER_ABSENT, "Unspecified" },
102 { TUNER_PHILIPS_PAL, "Philips FI1216" }, 102 { TUNER_PHILIPS_PAL, "Philips FI1216" },
103 { TUNER_PHILIPS_SECAM, "Philips FI1216MF" }, 103 { TUNER_PHILIPS_SECAM, "Philips FI1216MF" },
104 { TUNER_PHILIPS_NTSC, "Philips FI1236" }, 104 { TUNER_PHILIPS_NTSC, "Philips FI1236" },
105 { TUNER_PHILIPS_PAL_I, "Philips FI1246" }, 105 { TUNER_PHILIPS_PAL_I, "Philips FI1246" },
106 { TUNER_PHILIPS_PAL_DK, "Philips FI1256" }, 106 { TUNER_PHILIPS_PAL_DK, "Philips FI1256" },
107 { TUNER_PHILIPS_PAL, "Philips FI1216 MK2" }, 107 { TUNER_PHILIPS_PAL, "Philips FI1216 MK2" },
108 { TUNER_PHILIPS_SECAM, "Philips FI1216MF MK2" }, 108 { TUNER_PHILIPS_SECAM, "Philips FI1216MF MK2" },
109 /* 10-19 */ 109 /* 10-19 */
110 { TUNER_PHILIPS_NTSC, "Philips FI1236 MK2" }, 110 { TUNER_PHILIPS_NTSC, "Philips FI1236 MK2" },
111 { TUNER_PHILIPS_PAL_I, "Philips FI1246 MK2" }, 111 { TUNER_PHILIPS_PAL_I, "Philips FI1246 MK2" },
112 { TUNER_PHILIPS_PAL_DK, "Philips FI1256 MK2" }, 112 { TUNER_PHILIPS_PAL_DK, "Philips FI1256 MK2" },
113 { TUNER_TEMIC_NTSC, "Temic 4032FY5" }, 113 { TUNER_TEMIC_NTSC, "Temic 4032FY5" },
114 { TUNER_TEMIC_PAL, "Temic 4002FH5" }, 114 { TUNER_TEMIC_PAL, "Temic 4002FH5" },
115 { TUNER_TEMIC_PAL_I, "Temic 4062FY5" }, 115 { TUNER_TEMIC_PAL_I, "Temic 4062FY5" },
116 { TUNER_PHILIPS_PAL, "Philips FR1216 MK2" }, 116 { TUNER_PHILIPS_PAL, "Philips FR1216 MK2" },
117 { TUNER_PHILIPS_SECAM, "Philips FR1216MF MK2" }, 117 { TUNER_PHILIPS_SECAM, "Philips FR1216MF MK2" },
118 { TUNER_PHILIPS_NTSC, "Philips FR1236 MK2" }, 118 { TUNER_PHILIPS_NTSC, "Philips FR1236 MK2" },
119 { TUNER_PHILIPS_PAL_I, "Philips FR1246 MK2" }, 119 { TUNER_PHILIPS_PAL_I, "Philips FR1246 MK2" },
120 /* 20-29 */ 120 /* 20-29 */
121 { TUNER_PHILIPS_PAL_DK, "Philips FR1256 MK2" }, 121 { TUNER_PHILIPS_PAL_DK, "Philips FR1256 MK2" },
122 { TUNER_PHILIPS_PAL, "Philips FM1216" }, 122 { TUNER_PHILIPS_PAL, "Philips FM1216" },
123 { TUNER_PHILIPS_SECAM, "Philips FM1216MF" }, 123 { TUNER_PHILIPS_SECAM, "Philips FM1216MF" },
124 { TUNER_PHILIPS_NTSC, "Philips FM1236" }, 124 { TUNER_PHILIPS_NTSC, "Philips FM1236" },
125 { TUNER_PHILIPS_PAL_I, "Philips FM1246" }, 125 { TUNER_PHILIPS_PAL_I, "Philips FM1246" },
126 { TUNER_PHILIPS_PAL_DK, "Philips FM1256" }, 126 { TUNER_PHILIPS_PAL_DK, "Philips FM1256" },
127 { TUNER_TEMIC_4036FY5_NTSC, "Temic 4036FY5" }, 127 { TUNER_TEMIC_4036FY5_NTSC, "Temic 4036FY5" },
128 { TUNER_ABSENT, "Samsung TCPN9082D" }, 128 { TUNER_ABSENT, "Samsung TCPN9082D" },
129 { TUNER_ABSENT, "Samsung TCPM9092P" }, 129 { TUNER_ABSENT, "Samsung TCPM9092P" },
130 { TUNER_TEMIC_4006FH5_PAL, "Temic 4006FH5" }, 130 { TUNER_TEMIC_4006FH5_PAL, "Temic 4006FH5" },
131 /* 30-39 */ 131 /* 30-39 */
132 { TUNER_ABSENT, "Samsung TCPN9085D" }, 132 { TUNER_ABSENT, "Samsung TCPN9085D" },
133 { TUNER_ABSENT, "Samsung TCPB9085P" }, 133 { TUNER_ABSENT, "Samsung TCPB9085P" },
134 { TUNER_ABSENT, "Samsung TCPL9091P" }, 134 { TUNER_ABSENT, "Samsung TCPL9091P" },
135 { TUNER_TEMIC_4039FR5_NTSC, "Temic 4039FR5" }, 135 { TUNER_TEMIC_4039FR5_NTSC, "Temic 4039FR5" },
136 { TUNER_PHILIPS_FQ1216ME, "Philips FQ1216 ME" }, 136 { TUNER_PHILIPS_FQ1216ME, "Philips FQ1216 ME" },
137 { TUNER_TEMIC_4066FY5_PAL_I, "Temic 4066FY5" }, 137 { TUNER_TEMIC_4066FY5_PAL_I, "Temic 4066FY5" },
138 { TUNER_PHILIPS_NTSC, "Philips TD1536" }, 138 { TUNER_PHILIPS_NTSC, "Philips TD1536" },
139 { TUNER_PHILIPS_NTSC, "Philips TD1536D" }, 139 { TUNER_PHILIPS_NTSC, "Philips TD1536D" },
140 { TUNER_PHILIPS_NTSC, "Philips FMR1236" }, /* mono radio */ 140 { TUNER_PHILIPS_NTSC, "Philips FMR1236" }, /* mono radio */
141 { TUNER_ABSENT, "Philips FI1256MP" }, 141 { TUNER_ABSENT, "Philips FI1256MP" },
142 /* 40-49 */ 142 /* 40-49 */
143 { TUNER_ABSENT, "Samsung TCPQ9091P" }, 143 { TUNER_ABSENT, "Samsung TCPQ9091P" },
144 { TUNER_TEMIC_4006FN5_MULTI_PAL, "Temic 4006FN5" }, 144 { TUNER_TEMIC_4006FN5_MULTI_PAL,"Temic 4006FN5" },
145 { TUNER_TEMIC_4009FR5_PAL, "Temic 4009FR5" }, 145 { TUNER_TEMIC_4009FR5_PAL, "Temic 4009FR5" },
146 { TUNER_TEMIC_4046FM5, "Temic 4046FM5" }, 146 { TUNER_TEMIC_4046FM5, "Temic 4046FM5" },
147 { TUNER_TEMIC_4009FN5_MULTI_PAL_FM, "Temic 4009FN5" }, 147 { TUNER_TEMIC_4009FN5_MULTI_PAL_FM, "Temic 4009FN5" },
148 { TUNER_ABSENT, "Philips TD1536D FH 44"}, 148 { TUNER_ABSENT, "Philips TD1536D FH 44"},
149 { TUNER_LG_NTSC_FM, "LG TP18NSR01F"}, 149 { TUNER_LG_NTSC_FM, "LG TP18NSR01F"},
150 { TUNER_LG_PAL_FM, "LG TP18PSB01D"}, 150 { TUNER_LG_PAL_FM, "LG TP18PSB01D"},
151 { TUNER_LG_PAL, "LG TP18PSB11D"}, 151 { TUNER_LG_PAL, "LG TP18PSB11D"},
152 { TUNER_LG_PAL_I_FM, "LG TAPC-I001D"}, 152 { TUNER_LG_PAL_I_FM, "LG TAPC-I001D"},
153 /* 50-59 */ 153 /* 50-59 */
154 { TUNER_LG_PAL_I, "LG TAPC-I701D"}, 154 { TUNER_LG_PAL_I, "LG TAPC-I701D"},
155 { TUNER_ABSENT, "Temic 4042FI5"}, 155 { TUNER_ABSENT, "Temic 4042FI5"},
156 { TUNER_MICROTUNE_4049FM5, "Microtune 4049 FM5"}, 156 { TUNER_MICROTUNE_4049FM5, "Microtune 4049 FM5"},
157 { TUNER_ABSENT, "LG TPI8NSR11F"}, 157 { TUNER_ABSENT, "LG TPI8NSR11F"},
158 { TUNER_ABSENT, "Microtune 4049 FM5 Alt I2C"}, 158 { TUNER_ABSENT, "Microtune 4049 FM5 Alt I2C"},
159 { TUNER_PHILIPS_FM1216ME_MK3, "Philips FQ1216ME MK3"}, 159 { TUNER_PHILIPS_FM1216ME_MK3, "Philips FQ1216ME MK3"},
160 { TUNER_ABSENT, "Philips FI1236 MK3"}, 160 { TUNER_ABSENT, "Philips FI1236 MK3"},
161 { TUNER_PHILIPS_FM1216ME_MK3, "Philips FM1216 ME MK3"}, 161 { TUNER_PHILIPS_FM1216ME_MK3, "Philips FM1216 ME MK3"},
162 { TUNER_PHILIPS_FM1236_MK3, "Philips FM1236 MK3"}, 162 { TUNER_PHILIPS_FM1236_MK3, "Philips FM1236 MK3"},
163 { TUNER_ABSENT, "Philips FM1216MP MK3"}, 163 { TUNER_ABSENT, "Philips FM1216MP MK3"},
164 /* 60-69 */ 164 /* 60-69 */
165 { TUNER_PHILIPS_FM1216ME_MK3, "LG S001D MK3"}, 165 { TUNER_PHILIPS_FM1216ME_MK3, "LG S001D MK3"},
166 { TUNER_ABSENT, "LG M001D MK3"}, 166 { TUNER_ABSENT, "LG M001D MK3"},
167 { TUNER_PHILIPS_FM1216ME_MK3, "LG S701D MK3"}, 167 { TUNER_PHILIPS_FM1216ME_MK3, "LG S701D MK3"},
168 { TUNER_ABSENT, "LG M701D MK3"}, 168 { TUNER_ABSENT, "LG M701D MK3"},
169 { TUNER_ABSENT, "Temic 4146FM5"}, 169 { TUNER_ABSENT, "Temic 4146FM5"},
170 { TUNER_ABSENT, "Temic 4136FY5"}, 170 { TUNER_ABSENT, "Temic 4136FY5"},
171 { TUNER_ABSENT, "Temic 4106FH5"}, 171 { TUNER_ABSENT, "Temic 4106FH5"},
172 { TUNER_ABSENT, "Philips FQ1216LMP MK3"}, 172 { TUNER_ABSENT, "Philips FQ1216LMP MK3"},
173 { TUNER_LG_NTSC_TAPE, "LG TAPE H001F MK3"}, 173 { TUNER_LG_NTSC_TAPE, "LG TAPE H001F MK3"},
174 { TUNER_LG_NTSC_TAPE, "LG TAPE H701F MK3"}, 174 { TUNER_LG_NTSC_TAPE, "LG TAPE H701F MK3"},
175 /* 70-79 */ 175 /* 70-79 */
176 { TUNER_ABSENT, "LG TALN H200T"}, 176 { TUNER_ABSENT, "LG TALN H200T"},
177 { TUNER_ABSENT, "LG TALN H250T"}, 177 { TUNER_ABSENT, "LG TALN H250T"},
178 { TUNER_ABSENT, "LG TALN M200T"}, 178 { TUNER_ABSENT, "LG TALN M200T"},
179 { TUNER_ABSENT, "LG TALN Z200T"}, 179 { TUNER_ABSENT, "LG TALN Z200T"},
180 { TUNER_ABSENT, "LG TALN S200T"}, 180 { TUNER_ABSENT, "LG TALN S200T"},
181 { TUNER_ABSENT, "Thompson DTT7595"}, 181 { TUNER_ABSENT, "Thompson DTT7595"},
182 { TUNER_ABSENT, "Thompson DTT7592"}, 182 { TUNER_ABSENT, "Thompson DTT7592"},
183 { TUNER_ABSENT, "Silicon TDA8275C1 8290"}, 183 { TUNER_ABSENT, "Silicon TDA8275C1 8290"},
184 { TUNER_ABSENT, "Silicon TDA8275C1 8290 FM"}, 184 { TUNER_ABSENT, "Silicon TDA8275C1 8290 FM"},
185 { TUNER_ABSENT, "Thompson DTT757"}, 185 { TUNER_ABSENT, "Thompson DTT757"},
186 /* 80-89 */ 186 /* 80-89 */
187 { TUNER_PHILIPS_FQ1216LME_MK3, "Philips FQ1216LME MK3"}, 187 { TUNER_PHILIPS_FQ1216LME_MK3, "Philips FQ1216LME MK3"},
188 { TUNER_LG_PAL_NEW_TAPC, "LG TAPC G701D"}, 188 { TUNER_LG_PAL_NEW_TAPC, "LG TAPC G701D"},
189 { TUNER_LG_NTSC_NEW_TAPC, "LG TAPC H791F"}, 189 { TUNER_LG_NTSC_NEW_TAPC, "LG TAPC H791F"},
190 { TUNER_LG_PAL_NEW_TAPC, "TCL 2002MB 3"}, 190 { TUNER_LG_PAL_NEW_TAPC, "TCL 2002MB 3"},
191 { TUNER_LG_PAL_NEW_TAPC, "TCL 2002MI 3"}, 191 { TUNER_LG_PAL_NEW_TAPC, "TCL 2002MI 3"},
192 { TUNER_TCL_2002N, "TCL 2002N 6A"}, 192 { TUNER_TCL_2002N, "TCL 2002N 6A"},
193 { TUNER_PHILIPS_FM1236_MK3, "Philips FQ1236 MK3"}, 193 { TUNER_PHILIPS_FM1236_MK3, "Philips FQ1236 MK3"},
194 { TUNER_SAMSUNG_TCPN_2121P30A, "Samsung TCPN 2121P30A"}, 194 { TUNER_SAMSUNG_TCPN_2121P30A, "Samsung TCPN 2121P30A"},
195 { TUNER_ABSENT, "Samsung TCPE 4121P30A"}, 195 { TUNER_ABSENT, "Samsung TCPE 4121P30A"},
196 { TUNER_PHILIPS_FM1216ME_MK3, "TCL MFPE05 2"}, 196 { TUNER_PHILIPS_FM1216ME_MK3, "TCL MFPE05 2"},
197 /* 90-99 */ 197 /* 90-99 */
198 { TUNER_ABSENT, "LG TALN H202T"}, 198 { TUNER_ABSENT, "LG TALN H202T"},
199 { TUNER_PHILIPS_FQ1216AME_MK4, "Philips FQ1216AME MK4"}, 199 { TUNER_PHILIPS_FQ1216AME_MK4, "Philips FQ1216AME MK4"},
200 { TUNER_PHILIPS_FQ1236A_MK4, "Philips FQ1236A MK4"}, 200 { TUNER_PHILIPS_FQ1236A_MK4, "Philips FQ1236A MK4"},
201 { TUNER_ABSENT, "Philips FQ1286A MK4"}, 201 { TUNER_ABSENT, "Philips FQ1286A MK4"},
202 { TUNER_ABSENT, "Philips FQ1216ME MK5"}, 202 { TUNER_ABSENT, "Philips FQ1216ME MK5"},
203 { TUNER_ABSENT, "Philips FQ1236 MK5"}, 203 { TUNER_ABSENT, "Philips FQ1236 MK5"},
204 { TUNER_SAMSUNG_TCPG_6121P30A, "Samsung TCPG 6121P30A"}, 204 { TUNER_SAMSUNG_TCPG_6121P30A, "Samsung TCPG 6121P30A"},
205 { TUNER_TCL_2002MB, "TCL 2002MB_3H"}, 205 { TUNER_TCL_2002MB, "TCL 2002MB_3H"},
206 { TUNER_ABSENT, "TCL 2002MI_3H"}, 206 { TUNER_ABSENT, "TCL 2002MI_3H"},
207 { TUNER_TCL_2002N, "TCL 2002N 5H"}, 207 { TUNER_TCL_2002N, "TCL 2002N 5H"},
208 /* 100-109 */ 208 /* 100-109 */
209 { TUNER_PHILIPS_FMD1216ME_MK3, "Philips FMD1216ME"}, 209 { TUNER_PHILIPS_FMD1216ME_MK3, "Philips FMD1216ME"},
210 { TUNER_TEA5767, "Philips TEA5768HL FM Radio"}, 210 { TUNER_TEA5767, "Philips TEA5768HL FM Radio"},
211 { TUNER_ABSENT, "Panasonic ENV57H12D5"}, 211 { TUNER_ABSENT, "Panasonic ENV57H12D5"},
212 { TUNER_PHILIPS_FM1236_MK3, "TCL MFNM05-4"}, 212 { TUNER_PHILIPS_FM1236_MK3, "TCL MFNM05-4"},
213 { TUNER_PHILIPS_FM1236_MK3, "TCL MNM05-4"}, 213 { TUNER_PHILIPS_FM1236_MK3, "TCL MNM05-4"},
214 { TUNER_PHILIPS_FM1216ME_MK3, "TCL MPE05-2"}, 214 { TUNER_PHILIPS_FM1216ME_MK3, "TCL MPE05-2"},
215 { TUNER_ABSENT, "TCL MQNM05-4"}, 215 { TUNER_ABSENT, "TCL MQNM05-4"},
216 { TUNER_ABSENT, "LG TAPC-W701D"}, 216 { TUNER_ABSENT, "LG TAPC-W701D"},
217 { TUNER_ABSENT, "TCL 9886P-WM"}, 217 { TUNER_ABSENT, "TCL 9886P-WM"},
218 { TUNER_ABSENT, "TCL 1676NM-WM"}, 218 { TUNER_ABSENT, "TCL 1676NM-WM"},
219 /* 110-119 */ 219 /* 110-119 */
220 { TUNER_ABSENT, "Thompson DTT75105"}, 220 { TUNER_ABSENT, "Thompson DTT75105"},
221 { TUNER_ABSENT, "Conexant_CX24109"}, 221 { TUNER_ABSENT, "Conexant_CX24109"},
222 { TUNER_TCL_2002N, "TCL M2523_5N_E"}, 222 { TUNER_TCL_2002N, "TCL M2523_5N_E"},
223 { TUNER_TCL_2002MB, "TCL M2523_3DB_E"}, 223 { TUNER_TCL_2002MB, "TCL M2523_3DB_E"},
224 { TUNER_ABSENT, "Philips 8275A"}, 224 { TUNER_ABSENT, "Philips 8275A"},
225 { TUNER_ABSENT, "Microtune MT2060"}, 225 { TUNER_ABSENT, "Microtune MT2060"},
226 { TUNER_PHILIPS_FM1236_MK3, "Philips FM1236 MK5"}, 226 { TUNER_PHILIPS_FM1236_MK3, "Philips FM1236 MK5"},
227 { TUNER_PHILIPS_FM1216ME_MK3, "Philips FM1216ME MK5"}, 227 { TUNER_PHILIPS_FM1216ME_MK3, "Philips FM1216ME MK5"},
228 { TUNER_ABSENT, "TCL M2523_3DI_E"}, 228 { TUNER_ABSENT, "TCL M2523_3DI_E"},
229 { TUNER_ABSENT, "Samsung THPD5222FG30A"}, 229 { TUNER_ABSENT, "Samsung THPD5222FG30A"},
230 /* 120-129 */ 230 /* 120-129 */
231 { TUNER_XC2028, "Xceive XC3028"}, 231 { TUNER_XC2028, "Xceive XC3028"},
232 { TUNER_PHILIPS_FQ1216LME_MK3, "Philips FQ1216LME MK5"}, 232 { TUNER_PHILIPS_FQ1216LME_MK3, "Philips FQ1216LME MK5"},
233 { TUNER_ABSENT, "Philips FQD1216LME"}, 233 { TUNER_ABSENT, "Philips FQD1216LME"},
234 { TUNER_ABSENT, "Conexant CX24118A"}, 234 { TUNER_ABSENT, "Conexant CX24118A"},
235 { TUNER_ABSENT, "TCL DMF11WIP"}, 235 { TUNER_ABSENT, "TCL DMF11WIP"},
236 { TUNER_ABSENT, "TCL MFNM05_4H_E"}, 236 { TUNER_ABSENT, "TCL MFNM05_4H_E"},
237 { TUNER_ABSENT, "TCL MNM05_4H_E"}, 237 { TUNER_ABSENT, "TCL MNM05_4H_E"},
238 { TUNER_ABSENT, "TCL MPE05_2H_E"}, 238 { TUNER_ABSENT, "TCL MPE05_2H_E"},
239 { TUNER_ABSENT, "TCL MQNM05_4_U"}, 239 { TUNER_ABSENT, "TCL MQNM05_4_U"},
240 { TUNER_ABSENT, "TCL M2523_5NH_E"}, 240 { TUNER_ABSENT, "TCL M2523_5NH_E"},
241 /* 130-139 */ 241 /* 130-139 */
242 { TUNER_ABSENT, "TCL M2523_3DBH_E"}, 242 { TUNER_ABSENT, "TCL M2523_3DBH_E"},
243 { TUNER_ABSENT, "TCL M2523_3DIH_E"}, 243 { TUNER_ABSENT, "TCL M2523_3DIH_E"},
244 { TUNER_ABSENT, "TCL MFPE05_2_U"}, 244 { TUNER_ABSENT, "TCL MFPE05_2_U"},
245 { TUNER_PHILIPS_FMD1216MEX_MK3, "Philips FMD1216MEX"}, 245 { TUNER_PHILIPS_FMD1216MEX_MK3, "Philips FMD1216MEX"},
246 { TUNER_ABSENT, "Philips FRH2036B"}, 246 { TUNER_ABSENT, "Philips FRH2036B"},
247 { TUNER_ABSENT, "Panasonic ENGF75_01GF"}, 247 { TUNER_ABSENT, "Panasonic ENGF75_01GF"},
248 { TUNER_ABSENT, "MaxLinear MXL5005"}, 248 { TUNER_ABSENT, "MaxLinear MXL5005"},
249 { TUNER_ABSENT, "MaxLinear MXL5003"}, 249 { TUNER_ABSENT, "MaxLinear MXL5003"},
250 { TUNER_ABSENT, "Xceive XC2028"}, 250 { TUNER_ABSENT, "Xceive XC2028"},
251 { TUNER_ABSENT, "Microtune MT2131"}, 251 { TUNER_ABSENT, "Microtune MT2131"},
252 /* 140-149 */ 252 /* 140-149 */
253 { TUNER_ABSENT, "Philips 8275A_8295"}, 253 { TUNER_ABSENT, "Philips 8275A_8295"},
254 { TUNER_ABSENT, "TCL MF02GIP_5N_E"}, 254 { TUNER_ABSENT, "TCL MF02GIP_5N_E"},
255 { TUNER_ABSENT, "TCL MF02GIP_3DB_E"}, 255 { TUNER_ABSENT, "TCL MF02GIP_3DB_E"},
256 { TUNER_ABSENT, "TCL MF02GIP_3DI_E"}, 256 { TUNER_ABSENT, "TCL MF02GIP_3DI_E"},
257 { TUNER_ABSENT, "Microtune MT2266"}, 257 { TUNER_ABSENT, "Microtune MT2266"},
258 { TUNER_ABSENT, "TCL MF10WPP_4N_E"}, 258 { TUNER_ABSENT, "TCL MF10WPP_4N_E"},
259 { TUNER_ABSENT, "LG TAPQ_H702F"}, 259 { TUNER_ABSENT, "LG TAPQ_H702F"},
260 { TUNER_ABSENT, "TCL M09WPP_4N_E"}, 260 { TUNER_ABSENT, "TCL M09WPP_4N_E"},
261 { TUNER_ABSENT, "MaxLinear MXL5005_v2"}, 261 { TUNER_ABSENT, "MaxLinear MXL5005_v2"},
262 { TUNER_PHILIPS_TDA8290, "Philips 18271_8295"}, 262 { TUNER_PHILIPS_TDA8290, "Philips 18271_8295"},
263 /* 150-159 */ 263 /* 150-159 */
264 { TUNER_XC5000, "Xceive XC5000"}, 264 { TUNER_XC5000, "Xceive XC5000"},
265 { TUNER_ABSENT, "Xceive XC3028L"}, 265 { TUNER_ABSENT, "Xceive XC3028L"},
@@ -784,9 +784,3 @@ int tveeprom_read(struct i2c_client *c, unsigned char *eedata, int len)
784 return 0; 784 return 0;
785} 785}
786EXPORT_SYMBOL(tveeprom_read); 786EXPORT_SYMBOL(tveeprom_read);
787
788/*
789 * Local variables:
790 * c-basic-offset: 8
791 * End:
792 */
diff --git a/drivers/media/dvb-core/dvb-usb-ids.h b/drivers/media/dvb-core/dvb-usb-ids.h
index 388c2eb4d747..399e1042d351 100644
--- a/drivers/media/dvb-core/dvb-usb-ids.h
+++ b/drivers/media/dvb-core/dvb-usb-ids.h
@@ -172,6 +172,7 @@
172#define USB_PID_TWINHAN_VP7045_WARM 0x3206 172#define USB_PID_TWINHAN_VP7045_WARM 0x3206
173#define USB_PID_TWINHAN_VP7021_COLD 0x3207 173#define USB_PID_TWINHAN_VP7021_COLD 0x3207
174#define USB_PID_TWINHAN_VP7021_WARM 0x3208 174#define USB_PID_TWINHAN_VP7021_WARM 0x3208
175#define USB_PID_TWINHAN_VP7049 0x3219
175#define USB_PID_TINYTWIN 0x3226 176#define USB_PID_TINYTWIN 0x3226
176#define USB_PID_TINYTWIN_2 0xe402 177#define USB_PID_TINYTWIN_2 0xe402
177#define USB_PID_TINYTWIN_3 0x9016 178#define USB_PID_TINYTWIN_3 0x9016
@@ -233,10 +234,15 @@
233#define USB_PID_AVERMEDIA_A815M 0x815a 234#define USB_PID_AVERMEDIA_A815M 0x815a
234#define USB_PID_AVERMEDIA_A835 0xa835 235#define USB_PID_AVERMEDIA_A835 0xa835
235#define USB_PID_AVERMEDIA_B835 0xb835 236#define USB_PID_AVERMEDIA_B835 0xb835
237#define USB_PID_AVERMEDIA_A835B_1835 0x1835
238#define USB_PID_AVERMEDIA_A835B_2835 0x2835
239#define USB_PID_AVERMEDIA_A835B_3835 0x3835
240#define USB_PID_AVERMEDIA_A835B_4835 0x4835
236#define USB_PID_AVERMEDIA_1867 0x1867 241#define USB_PID_AVERMEDIA_1867 0x1867
237#define USB_PID_AVERMEDIA_A867 0xa867 242#define USB_PID_AVERMEDIA_A867 0xa867
238#define USB_PID_AVERMEDIA_TWINSTAR 0x0825 243#define USB_PID_AVERMEDIA_TWINSTAR 0x0825
239#define USB_PID_TECHNOTREND_CONNECT_S2400 0x3006 244#define USB_PID_TECHNOTREND_CONNECT_S2400 0x3006
245#define USB_PID_TECHNOTREND_CONNECT_S2400_8KEEPROM 0x3009
240#define USB_PID_TECHNOTREND_CONNECT_CT3650 0x300d 246#define USB_PID_TECHNOTREND_CONNECT_CT3650 0x300d
241#define USB_PID_TERRATEC_CINERGY_DT_XS_DIVERSITY 0x005a 247#define USB_PID_TERRATEC_CINERGY_DT_XS_DIVERSITY 0x005a
242#define USB_PID_TERRATEC_CINERGY_DT_XS_DIVERSITY_2 0x0081 248#define USB_PID_TERRATEC_CINERGY_DT_XS_DIVERSITY_2 0x0081
diff --git a/drivers/media/dvb-core/dvb_ca_en50221.c b/drivers/media/dvb-core/dvb_ca_en50221.c
index 9be65a3b931f..0aac3096728e 100644
--- a/drivers/media/dvb-core/dvb_ca_en50221.c
+++ b/drivers/media/dvb-core/dvb_ca_en50221.c
@@ -156,6 +156,9 @@ struct dvb_ca_private {
156 156
157 /* Slot to start looking for data to read from in the next user-space read operation */ 157 /* Slot to start looking for data to read from in the next user-space read operation */
158 int next_read_slot; 158 int next_read_slot;
159
160 /* mutex serializing ioctls */
161 struct mutex ioctl_mutex;
159}; 162};
160 163
161static void dvb_ca_en50221_thread_wakeup(struct dvb_ca_private *ca); 164static void dvb_ca_en50221_thread_wakeup(struct dvb_ca_private *ca);
@@ -1191,6 +1194,9 @@ static int dvb_ca_en50221_io_do_ioctl(struct file *file,
1191 1194
1192 dprintk("%s\n", __func__); 1195 dprintk("%s\n", __func__);
1193 1196
1197 if (mutex_lock_interruptible(&ca->ioctl_mutex))
1198 return -ERESTARTSYS;
1199
1194 switch (cmd) { 1200 switch (cmd) {
1195 case CA_RESET: 1201 case CA_RESET:
1196 for (slot = 0; slot < ca->slot_count; slot++) { 1202 for (slot = 0; slot < ca->slot_count; slot++) {
@@ -1221,8 +1227,10 @@ static int dvb_ca_en50221_io_do_ioctl(struct file *file,
1221 case CA_GET_SLOT_INFO: { 1227 case CA_GET_SLOT_INFO: {
1222 struct ca_slot_info *info = parg; 1228 struct ca_slot_info *info = parg;
1223 1229
1224 if ((info->num > ca->slot_count) || (info->num < 0)) 1230 if ((info->num > ca->slot_count) || (info->num < 0)) {
1225 return -EINVAL; 1231 err = -EINVAL;
1232 goto out_unlock;
1233 }
1226 1234
1227 info->type = CA_CI_LINK; 1235 info->type = CA_CI_LINK;
1228 info->flags = 0; 1236 info->flags = 0;
@@ -1241,6 +1249,8 @@ static int dvb_ca_en50221_io_do_ioctl(struct file *file,
1241 break; 1249 break;
1242 } 1250 }
1243 1251
1252out_unlock:
1253 mutex_unlock(&ca->ioctl_mutex);
1244 return err; 1254 return err;
1245} 1255}
1246 1256
@@ -1695,6 +1705,8 @@ int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter,
1695 mutex_init(&ca->slot_info[i].slot_lock); 1705 mutex_init(&ca->slot_info[i].slot_lock);
1696 } 1706 }
1697 1707
1708 mutex_init(&ca->ioctl_mutex);
1709
1698 if (signal_pending(current)) { 1710 if (signal_pending(current)) {
1699 ret = -EINTR; 1711 ret = -EINTR;
1700 goto error; 1712 goto error;
diff --git a/drivers/media/dvb-core/dvb_frontend.c b/drivers/media/dvb-core/dvb_frontend.c
index 0223ad255cb4..6e50a7581568 100644
--- a/drivers/media/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb-core/dvb_frontend.c
@@ -603,6 +603,7 @@ static int dvb_frontend_thread(void *data)
603 enum dvbfe_algo algo; 603 enum dvbfe_algo algo;
604 604
605 bool re_tune = false; 605 bool re_tune = false;
606 bool semheld = false;
606 607
607 dev_dbg(fe->dvb->device, "%s:\n", __func__); 608 dev_dbg(fe->dvb->device, "%s:\n", __func__);
608 609
@@ -626,6 +627,8 @@ restart:
626 627
627 if (kthread_should_stop() || dvb_frontend_is_exiting(fe)) { 628 if (kthread_should_stop() || dvb_frontend_is_exiting(fe)) {
628 /* got signal or quitting */ 629 /* got signal or quitting */
630 if (!down_interruptible(&fepriv->sem))
631 semheld = true;
629 fepriv->exit = DVB_FE_NORMAL_EXIT; 632 fepriv->exit = DVB_FE_NORMAL_EXIT;
630 break; 633 break;
631 } 634 }
@@ -741,6 +744,8 @@ restart:
741 fepriv->exit = DVB_FE_NO_EXIT; 744 fepriv->exit = DVB_FE_NO_EXIT;
742 mb(); 745 mb();
743 746
747 if (semheld)
748 up(&fepriv->sem);
744 dvb_frontend_wakeup(fe); 749 dvb_frontend_wakeup(fe);
745 return 0; 750 return 0;
746} 751}
@@ -1048,6 +1053,16 @@ static struct dtv_cmds_h dtv_cmds[DTV_MAX_COMMAND + 1] = {
1048 _DTV_CMD(DTV_ATSCMH_SCCC_CODE_MODE_B, 0, 0), 1053 _DTV_CMD(DTV_ATSCMH_SCCC_CODE_MODE_B, 0, 0),
1049 _DTV_CMD(DTV_ATSCMH_SCCC_CODE_MODE_C, 0, 0), 1054 _DTV_CMD(DTV_ATSCMH_SCCC_CODE_MODE_C, 0, 0),
1050 _DTV_CMD(DTV_ATSCMH_SCCC_CODE_MODE_D, 0, 0), 1055 _DTV_CMD(DTV_ATSCMH_SCCC_CODE_MODE_D, 0, 0),
1056
1057 /* Statistics API */
1058 _DTV_CMD(DTV_STAT_SIGNAL_STRENGTH, 0, 0),
1059 _DTV_CMD(DTV_STAT_CNR, 0, 0),
1060 _DTV_CMD(DTV_STAT_PRE_ERROR_BIT_COUNT, 0, 0),
1061 _DTV_CMD(DTV_STAT_PRE_TOTAL_BIT_COUNT, 0, 0),
1062 _DTV_CMD(DTV_STAT_POST_ERROR_BIT_COUNT, 0, 0),
1063 _DTV_CMD(DTV_STAT_POST_TOTAL_BIT_COUNT, 0, 0),
1064 _DTV_CMD(DTV_STAT_ERROR_BLOCK_COUNT, 0, 0),
1065 _DTV_CMD(DTV_STAT_TOTAL_BLOCK_COUNT, 0, 0),
1051}; 1066};
1052 1067
1053static void dtv_property_dump(struct dvb_frontend *fe, struct dtv_property *tvp) 1068static void dtv_property_dump(struct dvb_frontend *fe, struct dtv_property *tvp)
@@ -1438,7 +1453,35 @@ static int dtv_property_process_get(struct dvb_frontend *fe,
1438 tvp->u.data = c->lna; 1453 tvp->u.data = c->lna;
1439 break; 1454 break;
1440 1455
1456 /* Fill quality measures */
1457 case DTV_STAT_SIGNAL_STRENGTH:
1458 tvp->u.st = c->strength;
1459 break;
1460 case DTV_STAT_CNR:
1461 tvp->u.st = c->cnr;
1462 break;
1463 case DTV_STAT_PRE_ERROR_BIT_COUNT:
1464 tvp->u.st = c->pre_bit_error;
1465 break;
1466 case DTV_STAT_PRE_TOTAL_BIT_COUNT:
1467 tvp->u.st = c->pre_bit_count;
1468 break;
1469 case DTV_STAT_POST_ERROR_BIT_COUNT:
1470 tvp->u.st = c->post_bit_error;
1471 break;
1472 case DTV_STAT_POST_TOTAL_BIT_COUNT:
1473 tvp->u.st = c->post_bit_count;
1474 break;
1475 case DTV_STAT_ERROR_BLOCK_COUNT:
1476 tvp->u.st = c->block_error;
1477 break;
1478 case DTV_STAT_TOTAL_BLOCK_COUNT:
1479 tvp->u.st = c->block_count;
1480 break;
1441 default: 1481 default:
1482 dev_dbg(fe->dvb->device,
1483 "%s: FE property %d doesn't exist\n",
1484 __func__, tvp->cmd);
1442 return -EINVAL; 1485 return -EINVAL;
1443 } 1486 }
1444 1487
@@ -1823,16 +1866,20 @@ static int dvb_frontend_ioctl(struct file *file,
1823 int err = -EOPNOTSUPP; 1866 int err = -EOPNOTSUPP;
1824 1867
1825 dev_dbg(fe->dvb->device, "%s: (%d)\n", __func__, _IOC_NR(cmd)); 1868 dev_dbg(fe->dvb->device, "%s: (%d)\n", __func__, _IOC_NR(cmd));
1826 if (fepriv->exit != DVB_FE_NO_EXIT) 1869 if (down_interruptible(&fepriv->sem))
1870 return -ERESTARTSYS;
1871
1872 if (fepriv->exit != DVB_FE_NO_EXIT) {
1873 up(&fepriv->sem);
1827 return -ENODEV; 1874 return -ENODEV;
1875 }
1828 1876
1829 if ((file->f_flags & O_ACCMODE) == O_RDONLY && 1877 if ((file->f_flags & O_ACCMODE) == O_RDONLY &&
1830 (_IOC_DIR(cmd) != _IOC_READ || cmd == FE_GET_EVENT || 1878 (_IOC_DIR(cmd) != _IOC_READ || cmd == FE_GET_EVENT ||
1831 cmd == FE_DISEQC_RECV_SLAVE_REPLY)) 1879 cmd == FE_DISEQC_RECV_SLAVE_REPLY)) {
1880 up(&fepriv->sem);
1832 return -EPERM; 1881 return -EPERM;
1833 1882 }
1834 if (down_interruptible (&fepriv->sem))
1835 return -ERESTARTSYS;
1836 1883
1837 if ((cmd == FE_SET_PROPERTY) || (cmd == FE_GET_PROPERTY)) 1884 if ((cmd == FE_SET_PROPERTY) || (cmd == FE_GET_PROPERTY))
1838 err = dvb_frontend_ioctl_properties(file, cmd, parg); 1885 err = dvb_frontend_ioctl_properties(file, cmd, parg);
@@ -2246,7 +2293,7 @@ static int dvb_frontend_ioctl_legacy(struct file *file,
2246 printk("%s switch command: 0x%04lx\n", __func__, swcmd); 2293 printk("%s switch command: 0x%04lx\n", __func__, swcmd);
2247 do_gettimeofday(&nexttime); 2294 do_gettimeofday(&nexttime);
2248 if (dvb_frontend_debug) 2295 if (dvb_frontend_debug)
2249 memcpy(&tv[0], &nexttime, sizeof(struct timeval)); 2296 tv[0] = nexttime;
2250 /* before sending a command, initialize by sending 2297 /* before sending a command, initialize by sending
2251 * a 32ms 18V to the switch 2298 * a 32ms 18V to the switch
2252 */ 2299 */
diff --git a/drivers/media/dvb-core/dvb_frontend.h b/drivers/media/dvb-core/dvb_frontend.h
index 97112cd88a17..b34922a08156 100644
--- a/drivers/media/dvb-core/dvb_frontend.h
+++ b/drivers/media/dvb-core/dvb_frontend.h
@@ -393,6 +393,16 @@ struct dtv_frontend_properties {
393 u8 atscmh_sccc_code_mode_d; 393 u8 atscmh_sccc_code_mode_d;
394 394
395 u32 lna; 395 u32 lna;
396
397 /* statistics data */
398 struct dtv_fe_stats strength;
399 struct dtv_fe_stats cnr;
400 struct dtv_fe_stats pre_bit_error;
401 struct dtv_fe_stats pre_bit_count;
402 struct dtv_fe_stats post_bit_error;
403 struct dtv_fe_stats post_bit_count;
404 struct dtv_fe_stats block_error;
405 struct dtv_fe_stats block_count;
396}; 406};
397 407
398struct dvb_frontend { 408struct dvb_frontend {
diff --git a/drivers/media/dvb-core/dvb_net.c b/drivers/media/dvb-core/dvb_net.c
index c2117688aa23..44225b186f6d 100644
--- a/drivers/media/dvb-core/dvb_net.c
+++ b/drivers/media/dvb-core/dvb_net.c
@@ -1345,26 +1345,35 @@ static int dvb_net_do_ioctl(struct file *file,
1345{ 1345{
1346 struct dvb_device *dvbdev = file->private_data; 1346 struct dvb_device *dvbdev = file->private_data;
1347 struct dvb_net *dvbnet = dvbdev->priv; 1347 struct dvb_net *dvbnet = dvbdev->priv;
1348 int ret = 0;
1348 1349
1349 if (((file->f_flags&O_ACCMODE)==O_RDONLY)) 1350 if (((file->f_flags&O_ACCMODE)==O_RDONLY))
1350 return -EPERM; 1351 return -EPERM;
1351 1352
1353 if (mutex_lock_interruptible(&dvbnet->ioctl_mutex))
1354 return -ERESTARTSYS;
1355
1352 switch (cmd) { 1356 switch (cmd) {
1353 case NET_ADD_IF: 1357 case NET_ADD_IF:
1354 { 1358 {
1355 struct dvb_net_if *dvbnetif = parg; 1359 struct dvb_net_if *dvbnetif = parg;
1356 int result; 1360 int result;
1357 1361
1358 if (!capable(CAP_SYS_ADMIN)) 1362 if (!capable(CAP_SYS_ADMIN)) {
1359 return -EPERM; 1363 ret = -EPERM;
1364 goto ioctl_error;
1365 }
1360 1366
1361 if (!try_module_get(dvbdev->adapter->module)) 1367 if (!try_module_get(dvbdev->adapter->module)) {
1362 return -EPERM; 1368 ret = -EPERM;
1369 goto ioctl_error;
1370 }
1363 1371
1364 result=dvb_net_add_if(dvbnet, dvbnetif->pid, dvbnetif->feedtype); 1372 result=dvb_net_add_if(dvbnet, dvbnetif->pid, dvbnetif->feedtype);
1365 if (result<0) { 1373 if (result<0) {
1366 module_put(dvbdev->adapter->module); 1374 module_put(dvbdev->adapter->module);
1367 return result; 1375 ret = result;
1376 goto ioctl_error;
1368 } 1377 }
1369 dvbnetif->if_num=result; 1378 dvbnetif->if_num=result;
1370 break; 1379 break;
@@ -1376,8 +1385,10 @@ static int dvb_net_do_ioctl(struct file *file,
1376 struct dvb_net_if *dvbnetif = parg; 1385 struct dvb_net_if *dvbnetif = parg;
1377 1386
1378 if (dvbnetif->if_num >= DVB_NET_DEVICES_MAX || 1387 if (dvbnetif->if_num >= DVB_NET_DEVICES_MAX ||
1379 !dvbnet->state[dvbnetif->if_num]) 1388 !dvbnet->state[dvbnetif->if_num]) {
1380 return -EINVAL; 1389 ret = -EINVAL;
1390 goto ioctl_error;
1391 }
1381 1392
1382 netdev = dvbnet->device[dvbnetif->if_num]; 1393 netdev = dvbnet->device[dvbnetif->if_num];
1383 1394
@@ -1388,16 +1399,18 @@ static int dvb_net_do_ioctl(struct file *file,
1388 } 1399 }
1389 case NET_REMOVE_IF: 1400 case NET_REMOVE_IF:
1390 { 1401 {
1391 int ret; 1402 if (!capable(CAP_SYS_ADMIN)) {
1392 1403 ret = -EPERM;
1393 if (!capable(CAP_SYS_ADMIN)) 1404 goto ioctl_error;
1394 return -EPERM; 1405 }
1395 if ((unsigned long) parg >= DVB_NET_DEVICES_MAX) 1406 if ((unsigned long) parg >= DVB_NET_DEVICES_MAX) {
1396 return -EINVAL; 1407 ret = -EINVAL;
1408 goto ioctl_error;
1409 }
1397 ret = dvb_net_remove_if(dvbnet, (unsigned long) parg); 1410 ret = dvb_net_remove_if(dvbnet, (unsigned long) parg);
1398 if (!ret) 1411 if (!ret)
1399 module_put(dvbdev->adapter->module); 1412 module_put(dvbdev->adapter->module);
1400 return ret; 1413 break;
1401 } 1414 }
1402 1415
1403 /* binary compatibility cruft */ 1416 /* binary compatibility cruft */
@@ -1406,16 +1419,21 @@ static int dvb_net_do_ioctl(struct file *file,
1406 struct __dvb_net_if_old *dvbnetif = parg; 1419 struct __dvb_net_if_old *dvbnetif = parg;
1407 int result; 1420 int result;
1408 1421
1409 if (!capable(CAP_SYS_ADMIN)) 1422 if (!capable(CAP_SYS_ADMIN)) {
1410 return -EPERM; 1423 ret = -EPERM;
1424 goto ioctl_error;
1425 }
1411 1426
1412 if (!try_module_get(dvbdev->adapter->module)) 1427 if (!try_module_get(dvbdev->adapter->module)) {
1413 return -EPERM; 1428 ret = -EPERM;
1429 goto ioctl_error;
1430 }
1414 1431
1415 result=dvb_net_add_if(dvbnet, dvbnetif->pid, DVB_NET_FEEDTYPE_MPE); 1432 result=dvb_net_add_if(dvbnet, dvbnetif->pid, DVB_NET_FEEDTYPE_MPE);
1416 if (result<0) { 1433 if (result<0) {
1417 module_put(dvbdev->adapter->module); 1434 module_put(dvbdev->adapter->module);
1418 return result; 1435 ret = result;
1436 goto ioctl_error;
1419 } 1437 }
1420 dvbnetif->if_num=result; 1438 dvbnetif->if_num=result;
1421 break; 1439 break;
@@ -1427,8 +1445,10 @@ static int dvb_net_do_ioctl(struct file *file,
1427 struct __dvb_net_if_old *dvbnetif = parg; 1445 struct __dvb_net_if_old *dvbnetif = parg;
1428 1446
1429 if (dvbnetif->if_num >= DVB_NET_DEVICES_MAX || 1447 if (dvbnetif->if_num >= DVB_NET_DEVICES_MAX ||
1430 !dvbnet->state[dvbnetif->if_num]) 1448 !dvbnet->state[dvbnetif->if_num]) {
1431 return -EINVAL; 1449 ret = -EINVAL;
1450 goto ioctl_error;
1451 }
1432 1452
1433 netdev = dvbnet->device[dvbnetif->if_num]; 1453 netdev = dvbnet->device[dvbnetif->if_num];
1434 1454
@@ -1437,9 +1457,13 @@ static int dvb_net_do_ioctl(struct file *file,
1437 break; 1457 break;
1438 } 1458 }
1439 default: 1459 default:
1440 return -ENOTTY; 1460 ret = -ENOTTY;
1461 break;
1441 } 1462 }
1442 return 0; 1463
1464ioctl_error:
1465 mutex_unlock(&dvbnet->ioctl_mutex);
1466 return ret;
1443} 1467}
1444 1468
1445static long dvb_net_ioctl(struct file *file, 1469static long dvb_net_ioctl(struct file *file,
@@ -1505,6 +1529,7 @@ int dvb_net_init (struct dvb_adapter *adap, struct dvb_net *dvbnet,
1505{ 1529{
1506 int i; 1530 int i;
1507 1531
1532 mutex_init(&dvbnet->ioctl_mutex);
1508 dvbnet->demux = dmx; 1533 dvbnet->demux = dmx;
1509 1534
1510 for (i=0; i<DVB_NET_DEVICES_MAX; i++) 1535 for (i=0; i<DVB_NET_DEVICES_MAX; i++)
diff --git a/drivers/media/dvb-core/dvb_net.h b/drivers/media/dvb-core/dvb_net.h
index 1e53acd50cf4..ede78e8c8aa8 100644
--- a/drivers/media/dvb-core/dvb_net.h
+++ b/drivers/media/dvb-core/dvb_net.h
@@ -40,6 +40,7 @@ struct dvb_net {
40 int state[DVB_NET_DEVICES_MAX]; 40 int state[DVB_NET_DEVICES_MAX];
41 unsigned int exit:1; 41 unsigned int exit:1;
42 struct dmx_demux *demux; 42 struct dmx_demux *demux;
43 struct mutex ioctl_mutex;
43}; 44};
44 45
45void dvb_net_release(struct dvb_net *); 46void dvb_net_release(struct dvb_net *);
diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
index d33101aaf0b5..401ef64f92c6 100644
--- a/drivers/media/dvb-core/dvbdev.c
+++ b/drivers/media/dvb-core/dvbdev.c
@@ -418,10 +418,8 @@ int dvb_usercopy(struct file *file,
418 } 418 }
419 419
420 /* call driver */ 420 /* call driver */
421 mutex_lock(&dvbdev_mutex);
422 if ((err = func(file, cmd, parg)) == -ENOIOCTLCMD) 421 if ((err = func(file, cmd, parg)) == -ENOIOCTLCMD)
423 err = -ENOTTY; 422 err = -ENOTTY;
424 mutex_unlock(&dvbdev_mutex);
425 423
426 if (err < 0) 424 if (err < 0)
427 goto out; 425 goto out;
diff --git a/drivers/media/dvb-frontends/Kconfig b/drivers/media/dvb-frontends/Kconfig
index 5efec73a32d2..6f809a70c78e 100644
--- a/drivers/media/dvb-frontends/Kconfig
+++ b/drivers/media/dvb-frontends/Kconfig
@@ -207,6 +207,13 @@ config DVB_SI21XX
207 help 207 help
208 A DVB-S tuner module. Say Y when you want to support this frontend. 208 A DVB-S tuner module. Say Y when you want to support this frontend.
209 209
210config DVB_TS2020
211 tristate "Montage Tehnology TS2020 based tuners"
212 depends on DVB_CORE && I2C
213 default m if DVB_FE_CUSTOMISE
214 help
215 A DVB-S/S2 silicon tuner. Say Y when you want to support this tuner.
216
210config DVB_DS3000 217config DVB_DS3000
211 tristate "Montage Tehnology DS3000 based" 218 tristate "Montage Tehnology DS3000 based"
212 depends on DVB_CORE && I2C 219 depends on DVB_CORE && I2C
diff --git a/drivers/media/dvb-frontends/Makefile b/drivers/media/dvb-frontends/Makefile
index 7eb73bbd2e26..cebc0faffab5 100644
--- a/drivers/media/dvb-frontends/Makefile
+++ b/drivers/media/dvb-frontends/Makefile
@@ -88,6 +88,7 @@ obj-$(CONFIG_DVB_ISL6423) += isl6423.o
88obj-$(CONFIG_DVB_EC100) += ec100.o 88obj-$(CONFIG_DVB_EC100) += ec100.o
89obj-$(CONFIG_DVB_HD29L2) += hd29l2.o 89obj-$(CONFIG_DVB_HD29L2) += hd29l2.o
90obj-$(CONFIG_DVB_DS3000) += ds3000.o 90obj-$(CONFIG_DVB_DS3000) += ds3000.o
91obj-$(CONFIG_DVB_TS2020) += ts2020.o
91obj-$(CONFIG_DVB_MB86A16) += mb86a16.o 92obj-$(CONFIG_DVB_MB86A16) += mb86a16.o
92obj-$(CONFIG_DVB_MB86A20S) += mb86a20s.o 93obj-$(CONFIG_DVB_MB86A20S) += mb86a20s.o
93obj-$(CONFIG_DVB_IX2505V) += ix2505v.o 94obj-$(CONFIG_DVB_IX2505V) += ix2505v.o
diff --git a/drivers/media/dvb-frontends/af9033.c b/drivers/media/dvb-frontends/af9033.c
index 464ad878490b..c9cad989b8b9 100644
--- a/drivers/media/dvb-frontends/af9033.c
+++ b/drivers/media/dvb-frontends/af9033.c
@@ -318,6 +318,10 @@ static int af9033_init(struct dvb_frontend *fe)
318 len = ARRAY_SIZE(tuner_init_fc2580); 318 len = ARRAY_SIZE(tuner_init_fc2580);
319 init = tuner_init_fc2580; 319 init = tuner_init_fc2580;
320 break; 320 break;
321 case AF9033_TUNER_FC0012:
322 len = ARRAY_SIZE(tuner_init_fc0012);
323 init = tuner_init_fc0012;
324 break;
321 default: 325 default:
322 dev_dbg(&state->i2c->dev, "%s: unsupported tuner ID=%d\n", 326 dev_dbg(&state->i2c->dev, "%s: unsupported tuner ID=%d\n",
323 __func__, state->cfg.tuner); 327 __func__, state->cfg.tuner);
@@ -331,6 +335,20 @@ static int af9033_init(struct dvb_frontend *fe)
331 goto err; 335 goto err;
332 } 336 }
333 337
338 if (state->cfg.ts_mode == AF9033_TS_MODE_SERIAL) {
339 ret = af9033_wr_reg_mask(state, 0x00d91c, 0x01, 0x01);
340 if (ret < 0)
341 goto err;
342
343 ret = af9033_wr_reg_mask(state, 0x00d917, 0x00, 0x01);
344 if (ret < 0)
345 goto err;
346
347 ret = af9033_wr_reg_mask(state, 0x00d916, 0x00, 0x01);
348 if (ret < 0)
349 goto err;
350 }
351
334 state->bandwidth_hz = 0; /* force to program all parameters */ 352 state->bandwidth_hz = 0; /* force to program all parameters */
335 353
336 return 0; 354 return 0;
diff --git a/drivers/media/dvb-frontends/af9033.h b/drivers/media/dvb-frontends/af9033.h
index bfa4313fde21..82bd8c1513b6 100644
--- a/drivers/media/dvb-frontends/af9033.h
+++ b/drivers/media/dvb-frontends/af9033.h
@@ -40,6 +40,7 @@ struct af9033_config {
40 */ 40 */
41#define AF9033_TUNER_TUA9001 0x27 /* Infineon TUA 9001 */ 41#define AF9033_TUNER_TUA9001 0x27 /* Infineon TUA 9001 */
42#define AF9033_TUNER_FC0011 0x28 /* Fitipower FC0011 */ 42#define AF9033_TUNER_FC0011 0x28 /* Fitipower FC0011 */
43#define AF9033_TUNER_FC0012 0x2e /* Fitipower FC0012 */
43#define AF9033_TUNER_MXL5007T 0xa0 /* MaxLinear MxL5007T */ 44#define AF9033_TUNER_MXL5007T 0xa0 /* MaxLinear MxL5007T */
44#define AF9033_TUNER_TDA18218 0xa1 /* NXP TDA 18218HN */ 45#define AF9033_TUNER_TDA18218 0xa1 /* NXP TDA 18218HN */
45#define AF9033_TUNER_FC2580 0x32 /* FCI FC2580 */ 46#define AF9033_TUNER_FC2580 0x32 /* FCI FC2580 */
diff --git a/drivers/media/dvb-frontends/af9033_priv.h b/drivers/media/dvb-frontends/af9033_priv.h
index 34dddcd77538..e9bd78265543 100644
--- a/drivers/media/dvb-frontends/af9033_priv.h
+++ b/drivers/media/dvb-frontends/af9033_priv.h
@@ -199,10 +199,9 @@ static const struct reg_val ofsm_init[] = {
199 { 0x8000a6, 0x01 }, 199 { 0x8000a6, 0x01 },
200 { 0x8000a9, 0x00 }, 200 { 0x8000a9, 0x00 },
201 { 0x8000aa, 0x01 }, 201 { 0x8000aa, 0x01 },
202 { 0x8000ab, 0x01 },
203 { 0x8000b0, 0x01 }, 202 { 0x8000b0, 0x01 },
204 { 0x8000c0, 0x05 }, 203 { 0x8000c4, 0x05 },
205 { 0x8000c4, 0x19 }, 204 { 0x8000c8, 0x19 },
206 { 0x80f000, 0x0f }, 205 { 0x80f000, 0x0f },
207 { 0x80f016, 0x10 }, 206 { 0x80f016, 0x10 },
208 { 0x80f017, 0x04 }, 207 { 0x80f017, 0x04 },
@@ -322,8 +321,9 @@ static const struct reg_val tuner_init_tua9001[] = {
322 { 0x80009b, 0x05 }, 321 { 0x80009b, 0x05 },
323 { 0x80009c, 0x80 }, 322 { 0x80009c, 0x80 },
324 { 0x8000b3, 0x00 }, 323 { 0x8000b3, 0x00 },
325 { 0x8000c1, 0x01 }, 324 { 0x8000c5, 0x01 },
326 { 0x8000c2, 0x00 }, 325 { 0x8000c6, 0x00 },
326 { 0x8000c9, 0x5d },
327 { 0x80f007, 0x00 }, 327 { 0x80f007, 0x00 },
328 { 0x80f01f, 0x82 }, 328 { 0x80f01f, 0x82 },
329 { 0x80f020, 0x00 }, 329 { 0x80f020, 0x00 },
@@ -339,14 +339,14 @@ static const struct reg_val tuner_init_tua9001[] = {
339/* Fitipower fc0011 tuner init 339/* Fitipower fc0011 tuner init
340 AF9033_TUNER_FC0011 = 0x28 */ 340 AF9033_TUNER_FC0011 = 0x28 */
341static const struct reg_val tuner_init_fc0011[] = { 341static const struct reg_val tuner_init_fc0011[] = {
342 { 0x800046, AF9033_TUNER_FC0011 }, 342 { 0x800046, 0x28 },
343 { 0x800057, 0x00 }, 343 { 0x800057, 0x00 },
344 { 0x800058, 0x01 }, 344 { 0x800058, 0x01 },
345 { 0x80005f, 0x00 }, 345 { 0x80005f, 0x00 },
346 { 0x800060, 0x00 }, 346 { 0x800060, 0x00 },
347 { 0x800068, 0xa5 }, 347 { 0x800068, 0xa5 },
348 { 0x80006e, 0x01 }, 348 { 0x80006e, 0x01 },
349 { 0x800071, 0x0A }, 349 { 0x800071, 0x0a },
350 { 0x800072, 0x02 }, 350 { 0x800072, 0x02 },
351 { 0x800074, 0x01 }, 351 { 0x800074, 0x01 },
352 { 0x800079, 0x01 }, 352 { 0x800079, 0x01 },
@@ -354,7 +354,7 @@ static const struct reg_val tuner_init_fc0011[] = {
354 { 0x800094, 0x00 }, 354 { 0x800094, 0x00 },
355 { 0x800095, 0x00 }, 355 { 0x800095, 0x00 },
356 { 0x800096, 0x00 }, 356 { 0x800096, 0x00 },
357 { 0x80009b, 0x2D }, 357 { 0x80009b, 0x2d },
358 { 0x80009c, 0x60 }, 358 { 0x80009c, 0x60 },
359 { 0x80009d, 0x23 }, 359 { 0x80009d, 0x23 },
360 { 0x8000a4, 0x50 }, 360 { 0x8000a4, 0x50 },
@@ -362,39 +362,82 @@ static const struct reg_val tuner_init_fc0011[] = {
362 { 0x8000b3, 0x01 }, 362 { 0x8000b3, 0x01 },
363 { 0x8000b7, 0x88 }, 363 { 0x8000b7, 0x88 },
364 { 0x8000b8, 0xa6 }, 364 { 0x8000b8, 0xa6 },
365 { 0x8000c3, 0x01 }, 365 { 0x8000c5, 0x01 },
366 { 0x8000c4, 0x01 }, 366 { 0x8000c6, 0x01 },
367 { 0x8000c7, 0x69 }, 367 { 0x8000c9, 0x69 },
368 { 0x80F007, 0x00 }, 368 { 0x80f007, 0x00 },
369 { 0x80F00A, 0x1B }, 369 { 0x80f00a, 0x1b },
370 { 0x80F00B, 0x1B }, 370 { 0x80f00b, 0x1b },
371 { 0x80F00C, 0x1B }, 371 { 0x80f00c, 0x1b },
372 { 0x80F00D, 0x1B }, 372 { 0x80f00d, 0x1b },
373 { 0x80F00E, 0xFF }, 373 { 0x80f00e, 0xff },
374 { 0x80F00F, 0x01 }, 374 { 0x80f00f, 0x01 },
375 { 0x80F010, 0x00 }, 375 { 0x80f010, 0x00 },
376 { 0x80F011, 0x02 }, 376 { 0x80f011, 0x02 },
377 { 0x80F012, 0xFF }, 377 { 0x80f012, 0xff },
378 { 0x80F013, 0x01 }, 378 { 0x80f013, 0x01 },
379 { 0x80F014, 0x00 }, 379 { 0x80f014, 0x00 },
380 { 0x80F015, 0x02 }, 380 { 0x80f015, 0x02 },
381 { 0x80F01B, 0xEF }, 381 { 0x80f01b, 0xef },
382 { 0x80F01C, 0x01 }, 382 { 0x80f01c, 0x01 },
383 { 0x80F01D, 0x0f }, 383 { 0x80f01d, 0x0f },
384 { 0x80F01E, 0x02 }, 384 { 0x80f01e, 0x02 },
385 { 0x80F01F, 0x6E }, 385 { 0x80f01f, 0x6e },
386 { 0x80F020, 0x00 }, 386 { 0x80f020, 0x00 },
387 { 0x80F025, 0xDE }, 387 { 0x80f025, 0xde },
388 { 0x80F026, 0x00 }, 388 { 0x80f026, 0x00 },
389 { 0x80F027, 0x0A }, 389 { 0x80f027, 0x0a },
390 { 0x80F028, 0x03 }, 390 { 0x80f028, 0x03 },
391 { 0x80F029, 0x6E }, 391 { 0x80f029, 0x6e },
392 { 0x80F02A, 0x00 }, 392 { 0x80f02a, 0x00 },
393 { 0x80F047, 0x00 }, 393 { 0x80f047, 0x00 },
394 { 0x80F054, 0x00 }, 394 { 0x80f054, 0x00 },
395 { 0x80F055, 0x00 }, 395 { 0x80f055, 0x00 },
396 { 0x80F077, 0x01 }, 396 { 0x80f077, 0x01 },
397 { 0x80F1E6, 0x00 }, 397 { 0x80f1e6, 0x00 },
398};
399
400/* Fitipower FC0012 tuner init
401 AF9033_TUNER_FC0012 = 0x2e */
402static const struct reg_val tuner_init_fc0012[] = {
403 { 0x800046, 0x2e },
404 { 0x800057, 0x00 },
405 { 0x800058, 0x01 },
406 { 0x800059, 0x01 },
407 { 0x80005f, 0x00 },
408 { 0x800060, 0x00 },
409 { 0x80006d, 0x00 },
410 { 0x800071, 0x05 },
411 { 0x800072, 0x02 },
412 { 0x800074, 0x01 },
413 { 0x800075, 0x03 },
414 { 0x800076, 0x02 },
415 { 0x800077, 0x01 },
416 { 0x800078, 0x00 },
417 { 0x800079, 0x00 },
418 { 0x80007a, 0x90 },
419 { 0x80007b, 0x90 },
420 { 0x800093, 0x00 },
421 { 0x800094, 0x01 },
422 { 0x800095, 0x02 },
423 { 0x800096, 0x01 },
424 { 0x800098, 0x0a },
425 { 0x80009b, 0x05 },
426 { 0x80009c, 0x80 },
427 { 0x8000b3, 0x00 },
428 { 0x8000c5, 0x01 },
429 { 0x8000c6, 0x00 },
430 { 0x8000c9, 0x5d },
431 { 0x80f007, 0x00 },
432 { 0x80f01f, 0xa0 },
433 { 0x80f020, 0x00 },
434 { 0x80f029, 0x82 },
435 { 0x80f02a, 0x00 },
436 { 0x80f047, 0x00 },
437 { 0x80f054, 0x00 },
438 { 0x80f055, 0x00 },
439 { 0x80f077, 0x01 },
440 { 0x80f1e6, 0x00 },
398}; 441};
399 442
400/* MaxLinear MxL5007T tuner init 443/* MaxLinear MxL5007T tuner init
@@ -482,11 +525,12 @@ static const struct reg_val tuner_init_fc2580[] = {
482 { 0x800095, 0x00 }, 525 { 0x800095, 0x00 },
483 { 0x800096, 0x05 }, 526 { 0x800096, 0x05 },
484 { 0x8000b3, 0x01 }, 527 { 0x8000b3, 0x01 },
485 { 0x8000c3, 0x01 }, 528 { 0x8000c5, 0x01 },
486 { 0x8000c4, 0x00 }, 529 { 0x8000c6, 0x00 },
530 { 0x8000d1, 0x01 },
487 { 0x80f007, 0x00 }, 531 { 0x80f007, 0x00 },
488 { 0x80f00c, 0x19 }, 532 { 0x80f00c, 0x19 },
489 { 0x80f00d, 0x1A }, 533 { 0x80f00d, 0x1a },
490 { 0x80f00e, 0x00 }, 534 { 0x80f00e, 0x00 },
491 { 0x80f00f, 0x02 }, 535 { 0x80f00f, 0x02 },
492 { 0x80f010, 0x00 }, 536 { 0x80f010, 0x00 },
diff --git a/drivers/media/dvb-frontends/bcm3510.h b/drivers/media/dvb-frontends/bcm3510.h
index f4575c0cc446..5bd56b1623bf 100644
--- a/drivers/media/dvb-frontends/bcm3510.h
+++ b/drivers/media/dvb-frontends/bcm3510.h
@@ -34,7 +34,7 @@ struct bcm3510_config
34 int (*request_firmware)(struct dvb_frontend* fe, const struct firmware **fw, char* name); 34 int (*request_firmware)(struct dvb_frontend* fe, const struct firmware **fw, char* name);
35}; 35};
36 36
37#if defined(CONFIG_DVB_BCM3510) || (defined(CONFIG_DVB_BCM3510_MODULE) && defined(MODULE)) 37#if IS_ENABLED(CONFIG_DVB_BCM3510)
38extern struct dvb_frontend* bcm3510_attach(const struct bcm3510_config* config, 38extern struct dvb_frontend* bcm3510_attach(const struct bcm3510_config* config,
39 struct i2c_adapter* i2c); 39 struct i2c_adapter* i2c);
40#else 40#else
diff --git a/drivers/media/dvb-frontends/cx22700.h b/drivers/media/dvb-frontends/cx22700.h
index 4757a930ca05..382a7b1f3618 100644
--- a/drivers/media/dvb-frontends/cx22700.h
+++ b/drivers/media/dvb-frontends/cx22700.h
@@ -31,7 +31,7 @@ struct cx22700_config
31 u8 demod_address; 31 u8 demod_address;
32}; 32};
33 33
34#if defined(CONFIG_DVB_CX22700) || (defined(CONFIG_DVB_CX22700_MODULE) && defined(MODULE)) 34#if IS_ENABLED(CONFIG_DVB_CX22700)
35extern struct dvb_frontend* cx22700_attach(const struct cx22700_config* config, 35extern struct dvb_frontend* cx22700_attach(const struct cx22700_config* config,
36 struct i2c_adapter* i2c); 36 struct i2c_adapter* i2c);
37#else 37#else
diff --git a/drivers/media/dvb-frontends/cx24110.h b/drivers/media/dvb-frontends/cx24110.h
index fdcceee91f3a..527aff1f2723 100644
--- a/drivers/media/dvb-frontends/cx24110.h
+++ b/drivers/media/dvb-frontends/cx24110.h
@@ -46,7 +46,7 @@ static inline int cx24110_pll_write(struct dvb_frontend *fe, u32 val)
46 return 0; 46 return 0;
47} 47}
48 48
49#if defined(CONFIG_DVB_CX24110) || (defined(CONFIG_DVB_CX24110_MODULE) && defined(MODULE)) 49#if IS_ENABLED(CONFIG_DVB_CX24110)
50extern struct dvb_frontend* cx24110_attach(const struct cx24110_config* config, 50extern struct dvb_frontend* cx24110_attach(const struct cx24110_config* config,
51 struct i2c_adapter* i2c); 51 struct i2c_adapter* i2c);
52#else 52#else
diff --git a/drivers/media/dvb-frontends/cx24116.c b/drivers/media/dvb-frontends/cx24116.c
index b48879186537..2916d7c74a1d 100644
--- a/drivers/media/dvb-frontends/cx24116.c
+++ b/drivers/media/dvb-frontends/cx24116.c
@@ -819,7 +819,7 @@ static int cx24116_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
819static void cx24116_clone_params(struct dvb_frontend *fe) 819static void cx24116_clone_params(struct dvb_frontend *fe)
820{ 820{
821 struct cx24116_state *state = fe->demodulator_priv; 821 struct cx24116_state *state = fe->demodulator_priv;
822 memcpy(&state->dcur, &state->dnxt, sizeof(state->dcur)); 822 state->dcur = state->dnxt;
823} 823}
824 824
825/* Wait for LNB */ 825/* Wait for LNB */
diff --git a/drivers/media/dvb-frontends/dib0070.h b/drivers/media/dvb-frontends/dib0070.h
index 45c31fae3967..0c6befcc9143 100644
--- a/drivers/media/dvb-frontends/dib0070.h
+++ b/drivers/media/dvb-frontends/dib0070.h
@@ -48,7 +48,7 @@ struct dib0070_config {
48 u8 vga_filter; 48 u8 vga_filter;
49}; 49};
50 50
51#if defined(CONFIG_DVB_TUNER_DIB0070) || (defined(CONFIG_DVB_TUNER_DIB0070_MODULE) && defined(MODULE)) 51#if IS_ENABLED(CONFIG_DVB_TUNER_DIB0070)
52extern struct dvb_frontend *dib0070_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, struct dib0070_config *cfg); 52extern struct dvb_frontend *dib0070_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, struct dib0070_config *cfg);
53extern u16 dib0070_wbd_offset(struct dvb_frontend *); 53extern u16 dib0070_wbd_offset(struct dvb_frontend *);
54extern void dib0070_ctrl_agc_filter(struct dvb_frontend *, u8 open); 54extern void dib0070_ctrl_agc_filter(struct dvb_frontend *, u8 open);
diff --git a/drivers/media/dvb-frontends/dib0090.h b/drivers/media/dvb-frontends/dib0090.h
index 781dc49de45b..6a090954fa10 100644
--- a/drivers/media/dvb-frontends/dib0090.h
+++ b/drivers/media/dvb-frontends/dib0090.h
@@ -75,7 +75,7 @@ struct dib0090_config {
75 u8 force_crystal_mode; 75 u8 force_crystal_mode;
76}; 76};
77 77
78#if defined(CONFIG_DVB_TUNER_DIB0090) || (defined(CONFIG_DVB_TUNER_DIB0090_MODULE) && defined(MODULE)) 78#if IS_ENABLED(CONFIG_DVB_TUNER_DIB0090)
79extern struct dvb_frontend *dib0090_register(struct dvb_frontend *fe, struct i2c_adapter *i2c, const struct dib0090_config *config); 79extern struct dvb_frontend *dib0090_register(struct dvb_frontend *fe, struct i2c_adapter *i2c, const struct dib0090_config *config);
80extern struct dvb_frontend *dib0090_fw_register(struct dvb_frontend *fe, struct i2c_adapter *i2c, const struct dib0090_config *config); 80extern struct dvb_frontend *dib0090_fw_register(struct dvb_frontend *fe, struct i2c_adapter *i2c, const struct dib0090_config *config);
81extern void dib0090_dcc_freq(struct dvb_frontend *fe, u8 fast); 81extern void dib0090_dcc_freq(struct dvb_frontend *fe, u8 fast);
diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
index 404f63a6f26b..9b6c3bbc983a 100644
--- a/drivers/media/dvb-frontends/dib3000.h
+++ b/drivers/media/dvb-frontends/dib3000.h
@@ -41,7 +41,7 @@ struct dib_fe_xfer_ops
41 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl); 41 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
42}; 42};
43 43
44#if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE)) 44#if IS_ENABLED(CONFIG_DVB_DIB3000MB)
45extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config, 45extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
46 struct i2c_adapter* i2c, struct dib_fe_xfer_ops *xfer_ops); 46 struct i2c_adapter* i2c, struct dib_fe_xfer_ops *xfer_ops);
47#else 47#else
diff --git a/drivers/media/dvb-frontends/dib8000.h b/drivers/media/dvb-frontends/dib8000.h
index 39591bb172c1..9e7a2b170d55 100644
--- a/drivers/media/dvb-frontends/dib8000.h
+++ b/drivers/media/dvb-frontends/dib8000.h
@@ -37,7 +37,7 @@ struct dib8000_config {
37 37
38#define DEFAULT_DIB8000_I2C_ADDRESS 18 38#define DEFAULT_DIB8000_I2C_ADDRESS 18
39 39
40#if defined(CONFIG_DVB_DIB8000) || (defined(CONFIG_DVB_DIB8000_MODULE) && defined(MODULE)) 40#if IS_ENABLED(CONFIG_DVB_DIB8000)
41extern struct dvb_frontend *dib8000_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib8000_config *cfg); 41extern struct dvb_frontend *dib8000_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib8000_config *cfg);
42extern struct i2c_adapter *dib8000_get_i2c_master(struct dvb_frontend *, enum dibx000_i2c_interface, int); 42extern struct i2c_adapter *dib8000_get_i2c_master(struct dvb_frontend *, enum dibx000_i2c_interface, int);
43 43
diff --git a/drivers/media/dvb-frontends/dib9000.h b/drivers/media/dvb-frontends/dib9000.h
index de1cc91fd833..f3639f045ff0 100644
--- a/drivers/media/dvb-frontends/dib9000.h
+++ b/drivers/media/dvb-frontends/dib9000.h
@@ -27,7 +27,7 @@ struct dib9000_config {
27 27
28#define DEFAULT_DIB9000_I2C_ADDRESS 18 28#define DEFAULT_DIB9000_I2C_ADDRESS 18
29 29
30#if defined(CONFIG_DVB_DIB9000) || (defined(CONFIG_DVB_DIB9000_MODULE) && defined(MODULE)) 30#if IS_ENABLED(CONFIG_DVB_DIB9000)
31extern struct dvb_frontend *dib9000_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr, const struct dib9000_config *cfg); 31extern struct dvb_frontend *dib9000_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr, const struct dib9000_config *cfg);
32extern int dib9000_i2c_enumeration(struct i2c_adapter *host, int no_of_demods, u8 default_addr, u8 first_addr); 32extern int dib9000_i2c_enumeration(struct i2c_adapter *host, int no_of_demods, u8 default_addr, u8 first_addr);
33extern struct i2c_adapter *dib9000_get_tuner_interface(struct dvb_frontend *fe); 33extern struct i2c_adapter *dib9000_get_tuner_interface(struct dvb_frontend *fe);
diff --git a/drivers/media/dvb-frontends/drxd_hard.c b/drivers/media/dvb-frontends/drxd_hard.c
index e71cc60851e7..9a2134792cfa 100644
--- a/drivers/media/dvb-frontends/drxd_hard.c
+++ b/drivers/media/dvb-frontends/drxd_hard.c
@@ -2965,7 +2965,7 @@ struct dvb_frontend *drxd_attach(const struct drxd_config *config,
2965 return NULL; 2965 return NULL;
2966 memset(state, 0, sizeof(*state)); 2966 memset(state, 0, sizeof(*state));
2967 2967
2968 memcpy(&state->ops, &drxd_ops, sizeof(struct dvb_frontend_ops)); 2968 state->ops = drxd_ops;
2969 state->dev = dev; 2969 state->dev = dev;
2970 state->config = *config; 2970 state->config = *config;
2971 state->i2c = i2c; 2971 state->i2c = i2c;
@@ -2976,10 +2976,13 @@ struct dvb_frontend *drxd_attach(const struct drxd_config *config,
2976 if (Read16(state, 0, 0, 0) < 0) 2976 if (Read16(state, 0, 0, 0) < 0)
2977 goto error; 2977 goto error;
2978 2978
2979 memcpy(&state->frontend.ops, &drxd_ops, 2979 state->frontend.ops = drxd_ops;
2980 sizeof(struct dvb_frontend_ops));
2981 state->frontend.demodulator_priv = state; 2980 state->frontend.demodulator_priv = state;
2982 ConfigureMPEGOutput(state, 0); 2981 ConfigureMPEGOutput(state, 0);
2982 /* add few initialization to allow gate control */
2983 CDRXD(state, state->config.IF ? state->config.IF : 36000000);
2984 InitHI(state);
2985
2983 return &state->frontend; 2986 return &state->frontend;
2984 2987
2985error: 2988error:
diff --git a/drivers/media/dvb-frontends/ds3000.c b/drivers/media/dvb-frontends/ds3000.c
index 60a529e3833f..1e344b033277 100644
--- a/drivers/media/dvb-frontends/ds3000.c
+++ b/drivers/media/dvb-frontends/ds3000.c
@@ -1,8 +1,8 @@
1/* 1/*
2 Montage Technology DS3000/TS2020 - DVBS/S2 Demodulator/Tuner driver 2 Montage Technology DS3000 - DVBS/S2 Demodulator driver
3 Copyright (C) 2009 Konstantin Dimitrov <kosio.dimitrov@gmail.com> 3 Copyright (C) 2009-2012 Konstantin Dimitrov <kosio.dimitrov@gmail.com>
4 4
5 Copyright (C) 2009 TurboSight.com 5 Copyright (C) 2009-2012 TurboSight.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 by 8 it under the terms of the GNU General Public License as published by
@@ -27,6 +27,7 @@
27#include <linux/firmware.h> 27#include <linux/firmware.h>
28 28
29#include "dvb_frontend.h" 29#include "dvb_frontend.h"
30#include "ts2020.h"
30#include "ds3000.h" 31#include "ds3000.h"
31 32
32static int debug; 33static int debug;
@@ -42,7 +43,6 @@ static int debug;
42#define DS3000_DEFAULT_FIRMWARE "dvb-fe-ds3000.fw" 43#define DS3000_DEFAULT_FIRMWARE "dvb-fe-ds3000.fw"
43 44
44#define DS3000_SAMPLE_RATE 96000 /* in kHz */ 45#define DS3000_SAMPLE_RATE 96000 /* in kHz */
45#define DS3000_XTAL_FREQ 27000 /* in kHz */
46 46
47/* Register values to initialise the demod in DVB-S mode */ 47/* Register values to initialise the demod in DVB-S mode */
48static u8 ds3000_dvbs_init_tab[] = { 48static u8 ds3000_dvbs_init_tab[] = {
@@ -256,22 +256,14 @@ static int ds3000_writereg(struct ds3000_state *state, int reg, int data)
256 return 0; 256 return 0;
257} 257}
258 258
259static int ds3000_tuner_writereg(struct ds3000_state *state, int reg, int data) 259static int ds3000_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
260{ 260{
261 u8 buf[] = { reg, data }; 261 struct ds3000_state *state = fe->demodulator_priv;
262 struct i2c_msg msg = { .addr = 0x60,
263 .flags = 0, .buf = buf, .len = 2 };
264 int err;
265
266 dprintk("%s: write reg 0x%02x, value 0x%02x\n", __func__, reg, data);
267 262
268 ds3000_writereg(state, 0x03, 0x11); 263 if (enable)
269 err = i2c_transfer(state->i2c, &msg, 1); 264 ds3000_writereg(state, 0x03, 0x12);
270 if (err != 1) { 265 else
271 printk("%s: writereg error(err == %i, reg == 0x%02x," 266 ds3000_writereg(state, 0x03, 0x02);
272 " value == 0x%02x)\n", __func__, err, reg, data);
273 return -EREMOTEIO;
274 }
275 267
276 return 0; 268 return 0;
277} 269}
@@ -280,15 +272,14 @@ static int ds3000_tuner_writereg(struct ds3000_state *state, int reg, int data)
280static int ds3000_writeFW(struct ds3000_state *state, int reg, 272static int ds3000_writeFW(struct ds3000_state *state, int reg,
281 const u8 *data, u16 len) 273 const u8 *data, u16 len)
282{ 274{
283 int i, ret = -EREMOTEIO; 275 int i, ret = 0;
284 struct i2c_msg msg; 276 struct i2c_msg msg;
285 u8 *buf; 277 u8 *buf;
286 278
287 buf = kmalloc(33, GFP_KERNEL); 279 buf = kmalloc(33, GFP_KERNEL);
288 if (buf == NULL) { 280 if (buf == NULL) {
289 printk(KERN_ERR "Unable to kmalloc\n"); 281 printk(KERN_ERR "Unable to kmalloc\n");
290 ret = -ENOMEM; 282 return -ENOMEM;
291 goto error;
292 } 283 }
293 284
294 *(buf) = reg; 285 *(buf) = reg;
@@ -308,8 +299,10 @@ static int ds3000_writeFW(struct ds3000_state *state, int reg,
308 printk(KERN_ERR "%s: write error(err == %i, " 299 printk(KERN_ERR "%s: write error(err == %i, "
309 "reg == 0x%02x\n", __func__, ret, reg); 300 "reg == 0x%02x\n", __func__, ret, reg);
310 ret = -EREMOTEIO; 301 ret = -EREMOTEIO;
302 goto error;
311 } 303 }
312 } 304 }
305 ret = 0;
313 306
314error: 307error:
315 kfree(buf); 308 kfree(buf);
@@ -348,38 +341,6 @@ static int ds3000_readreg(struct ds3000_state *state, u8 reg)
348 return b1[0]; 341 return b1[0];
349} 342}
350 343
351static int ds3000_tuner_readreg(struct ds3000_state *state, u8 reg)
352{
353 int ret;
354 u8 b0[] = { reg };
355 u8 b1[] = { 0 };
356 struct i2c_msg msg[] = {
357 {
358 .addr = 0x60,
359 .flags = 0,
360 .buf = b0,
361 .len = 1
362 }, {
363 .addr = 0x60,
364 .flags = I2C_M_RD,
365 .buf = b1,
366 .len = 1
367 }
368 };
369
370 ds3000_writereg(state, 0x03, 0x12);
371 ret = i2c_transfer(state->i2c, msg, 2);
372
373 if (ret != 2) {
374 printk(KERN_ERR "%s: reg=0x%x(error=%d)\n", __func__, reg, ret);
375 return ret;
376 }
377
378 dprintk("%s: read reg 0x%02x, value 0x%02x\n", __func__, reg, b1[0]);
379
380 return b1[0];
381}
382
383static int ds3000_load_firmware(struct dvb_frontend *fe, 344static int ds3000_load_firmware(struct dvb_frontend *fe,
384 const struct firmware *fw); 345 const struct firmware *fw);
385 346
@@ -424,6 +385,7 @@ static int ds3000_load_firmware(struct dvb_frontend *fe,
424 const struct firmware *fw) 385 const struct firmware *fw)
425{ 386{
426 struct ds3000_state *state = fe->demodulator_priv; 387 struct ds3000_state *state = fe->demodulator_priv;
388 int ret = 0;
427 389
428 dprintk("%s\n", __func__); 390 dprintk("%s\n", __func__);
429 dprintk("Firmware is %zu bytes (%02x %02x .. %02x %02x)\n", 391 dprintk("Firmware is %zu bytes (%02x %02x .. %02x %02x)\n",
@@ -436,10 +398,10 @@ static int ds3000_load_firmware(struct dvb_frontend *fe,
436 /* Begin the firmware load process */ 398 /* Begin the firmware load process */
437 ds3000_writereg(state, 0xb2, 0x01); 399 ds3000_writereg(state, 0xb2, 0x01);
438 /* write the entire firmware */ 400 /* write the entire firmware */
439 ds3000_writeFW(state, 0xb0, fw->data, fw->size); 401 ret = ds3000_writeFW(state, 0xb0, fw->data, fw->size);
440 ds3000_writereg(state, 0xb2, 0x00); 402 ds3000_writereg(state, 0xb2, 0x00);
441 403
442 return 0; 404 return ret;
443} 405}
444 406
445static int ds3000_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage) 407static int ds3000_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
@@ -498,6 +460,9 @@ static int ds3000_read_status(struct dvb_frontend *fe, fe_status_t* status)
498 return 1; 460 return 1;
499 } 461 }
500 462
463 if (state->config->set_lock_led)
464 state->config->set_lock_led(fe, *status == 0 ? 0 : 1);
465
501 dprintk("%s: status = 0x%02x\n", __func__, lock); 466 dprintk("%s: status = 0x%02x\n", __func__, lock);
502 467
503 return 0; 468 return 0;
@@ -568,33 +533,11 @@ static int ds3000_read_ber(struct dvb_frontend *fe, u32* ber)
568 return 0; 533 return 0;
569} 534}
570 535
571/* read TS2020 signal strength */
572static int ds3000_read_signal_strength(struct dvb_frontend *fe, 536static int ds3000_read_signal_strength(struct dvb_frontend *fe,
573 u16 *signal_strength) 537 u16 *signal_strength)
574{ 538{
575 struct ds3000_state *state = fe->demodulator_priv; 539 if (fe->ops.tuner_ops.get_rf_strength)
576 u16 sig_reading, sig_strength; 540 fe->ops.tuner_ops.get_rf_strength(fe, signal_strength);
577 u8 rfgain, bbgain;
578
579 dprintk("%s()\n", __func__);
580
581 rfgain = ds3000_tuner_readreg(state, 0x3d) & 0x1f;
582 bbgain = ds3000_tuner_readreg(state, 0x21) & 0x1f;
583
584 if (rfgain > 15)
585 rfgain = 15;
586 if (bbgain > 13)
587 bbgain = 13;
588
589 sig_reading = rfgain * 2 + bbgain * 3;
590
591 sig_strength = 40 + (64 - sig_reading) * 50 / 64 ;
592
593 /* cook the value to be suitable for szap-s2 human readable output */
594 *signal_strength = sig_strength * 1000;
595
596 dprintk("%s: raw / cooked = 0x%04x / 0x%04x\n", __func__,
597 sig_reading, *signal_strength);
598 541
599 return 0; 542 return 0;
600} 543}
@@ -878,6 +821,10 @@ static int ds3000_diseqc_send_burst(struct dvb_frontend *fe,
878static void ds3000_release(struct dvb_frontend *fe) 821static void ds3000_release(struct dvb_frontend *fe)
879{ 822{
880 struct ds3000_state *state = fe->demodulator_priv; 823 struct ds3000_state *state = fe->demodulator_priv;
824
825 if (state->config->set_lock_led)
826 state->config->set_lock_led(fe, 0);
827
881 dprintk("%s\n", __func__); 828 dprintk("%s\n", __func__);
882 kfree(state); 829 kfree(state);
883} 830}
@@ -952,133 +899,17 @@ static int ds3000_set_frontend(struct dvb_frontend *fe)
952 899
953 int i; 900 int i;
954 fe_status_t status; 901 fe_status_t status;
955 u8 mlpf, mlpf_new, mlpf_max, mlpf_min, nlpf, div4;
956 s32 offset_khz; 902 s32 offset_khz;
957 u16 value, ndiv; 903 u32 frequency;
958 u32 f3db; 904 u16 value;
959 905
960 dprintk("%s() ", __func__); 906 dprintk("%s() ", __func__);
961 907
962 if (state->config->set_ts_params) 908 if (state->config->set_ts_params)
963 state->config->set_ts_params(fe, 0); 909 state->config->set_ts_params(fe, 0);
964 /* Tune */ 910 /* Tune */
965 /* unknown */ 911 if (fe->ops.tuner_ops.set_params)
966 ds3000_tuner_writereg(state, 0x07, 0x02); 912 fe->ops.tuner_ops.set_params(fe);
967 ds3000_tuner_writereg(state, 0x10, 0x00);
968 ds3000_tuner_writereg(state, 0x60, 0x79);
969 ds3000_tuner_writereg(state, 0x08, 0x01);
970 ds3000_tuner_writereg(state, 0x00, 0x01);
971 div4 = 0;
972
973 /* calculate and set freq divider */
974 if (c->frequency < 1146000) {
975 ds3000_tuner_writereg(state, 0x10, 0x11);
976 div4 = 1;
977 ndiv = ((c->frequency * (6 + 8) * 4) +
978 (DS3000_XTAL_FREQ / 2)) /
979 DS3000_XTAL_FREQ - 1024;
980 } else {
981 ds3000_tuner_writereg(state, 0x10, 0x01);
982 ndiv = ((c->frequency * (6 + 8) * 2) +
983 (DS3000_XTAL_FREQ / 2)) /
984 DS3000_XTAL_FREQ - 1024;
985 }
986
987 ds3000_tuner_writereg(state, 0x01, (ndiv & 0x0f00) >> 8);
988 ds3000_tuner_writereg(state, 0x02, ndiv & 0x00ff);
989
990 /* set pll */
991 ds3000_tuner_writereg(state, 0x03, 0x06);
992 ds3000_tuner_writereg(state, 0x51, 0x0f);
993 ds3000_tuner_writereg(state, 0x51, 0x1f);
994 ds3000_tuner_writereg(state, 0x50, 0x10);
995 ds3000_tuner_writereg(state, 0x50, 0x00);
996 msleep(5);
997
998 /* unknown */
999 ds3000_tuner_writereg(state, 0x51, 0x17);
1000 ds3000_tuner_writereg(state, 0x51, 0x1f);
1001 ds3000_tuner_writereg(state, 0x50, 0x08);
1002 ds3000_tuner_writereg(state, 0x50, 0x00);
1003 msleep(5);
1004
1005 value = ds3000_tuner_readreg(state, 0x3d);
1006 value &= 0x0f;
1007 if ((value > 4) && (value < 15)) {
1008 value -= 3;
1009 if (value < 4)
1010 value = 4;
1011 value = ((value << 3) | 0x01) & 0x79;
1012 }
1013
1014 ds3000_tuner_writereg(state, 0x60, value);
1015 ds3000_tuner_writereg(state, 0x51, 0x17);
1016 ds3000_tuner_writereg(state, 0x51, 0x1f);
1017 ds3000_tuner_writereg(state, 0x50, 0x08);
1018 ds3000_tuner_writereg(state, 0x50, 0x00);
1019
1020 /* set low-pass filter period */
1021 ds3000_tuner_writereg(state, 0x04, 0x2e);
1022 ds3000_tuner_writereg(state, 0x51, 0x1b);
1023 ds3000_tuner_writereg(state, 0x51, 0x1f);
1024 ds3000_tuner_writereg(state, 0x50, 0x04);
1025 ds3000_tuner_writereg(state, 0x50, 0x00);
1026 msleep(5);
1027
1028 f3db = ((c->symbol_rate / 1000) << 2) / 5 + 2000;
1029 if ((c->symbol_rate / 1000) < 5000)
1030 f3db += 3000;
1031 if (f3db < 7000)
1032 f3db = 7000;
1033 if (f3db > 40000)
1034 f3db = 40000;
1035
1036 /* set low-pass filter baseband */
1037 value = ds3000_tuner_readreg(state, 0x26);
1038 mlpf = 0x2e * 207 / ((value << 1) + 151);
1039 mlpf_max = mlpf * 135 / 100;
1040 mlpf_min = mlpf * 78 / 100;
1041 if (mlpf_max > 63)
1042 mlpf_max = 63;
1043
1044 /* rounded to the closest integer */
1045 nlpf = ((mlpf * f3db * 1000) + (2766 * DS3000_XTAL_FREQ / 2))
1046 / (2766 * DS3000_XTAL_FREQ);
1047 if (nlpf > 23)
1048 nlpf = 23;
1049 if (nlpf < 1)
1050 nlpf = 1;
1051
1052 /* rounded to the closest integer */
1053 mlpf_new = ((DS3000_XTAL_FREQ * nlpf * 2766) +
1054 (1000 * f3db / 2)) / (1000 * f3db);
1055
1056 if (mlpf_new < mlpf_min) {
1057 nlpf++;
1058 mlpf_new = ((DS3000_XTAL_FREQ * nlpf * 2766) +
1059 (1000 * f3db / 2)) / (1000 * f3db);
1060 }
1061
1062 if (mlpf_new > mlpf_max)
1063 mlpf_new = mlpf_max;
1064
1065 ds3000_tuner_writereg(state, 0x04, mlpf_new);
1066 ds3000_tuner_writereg(state, 0x06, nlpf);
1067 ds3000_tuner_writereg(state, 0x51, 0x1b);
1068 ds3000_tuner_writereg(state, 0x51, 0x1f);
1069 ds3000_tuner_writereg(state, 0x50, 0x04);
1070 ds3000_tuner_writereg(state, 0x50, 0x00);
1071 msleep(5);
1072
1073 /* unknown */
1074 ds3000_tuner_writereg(state, 0x51, 0x1e);
1075 ds3000_tuner_writereg(state, 0x51, 0x1f);
1076 ds3000_tuner_writereg(state, 0x50, 0x01);
1077 ds3000_tuner_writereg(state, 0x50, 0x00);
1078 msleep(60);
1079
1080 offset_khz = (ndiv - ndiv % 2 + 1024) * DS3000_XTAL_FREQ
1081 / (6 + 8) / (div4 + 1) / 2 - c->frequency;
1082 913
1083 /* ds3000 global reset */ 914 /* ds3000 global reset */
1084 ds3000_writereg(state, 0x07, 0x80); 915 ds3000_writereg(state, 0x07, 0x80);
@@ -1186,7 +1017,11 @@ static int ds3000_set_frontend(struct dvb_frontend *fe)
1186 /* start ds3000 build-in uC */ 1017 /* start ds3000 build-in uC */
1187 ds3000_writereg(state, 0xb2, 0x00); 1018 ds3000_writereg(state, 0xb2, 0x00);
1188 1019
1189 ds3000_set_carrier_offset(fe, offset_khz); 1020 if (fe->ops.tuner_ops.get_frequency) {
1021 fe->ops.tuner_ops.get_frequency(fe, &frequency);
1022 offset_khz = frequency - c->frequency;
1023 ds3000_set_carrier_offset(fe, offset_khz);
1024 }
1190 1025
1191 for (i = 0; i < 30 ; i++) { 1026 for (i = 0; i < 30 ; i++) {
1192 ds3000_read_status(fe, &status); 1027 ds3000_read_status(fe, &status);
@@ -1218,6 +1053,11 @@ static int ds3000_tune(struct dvb_frontend *fe,
1218 1053
1219static enum dvbfe_algo ds3000_get_algo(struct dvb_frontend *fe) 1054static enum dvbfe_algo ds3000_get_algo(struct dvb_frontend *fe)
1220{ 1055{
1056 struct ds3000_state *state = fe->demodulator_priv;
1057
1058 if (state->config->set_lock_led)
1059 state->config->set_lock_led(fe, 0);
1060
1221 dprintk("%s()\n", __func__); 1061 dprintk("%s()\n", __func__);
1222 return DVBFE_ALGO_HW; 1062 return DVBFE_ALGO_HW;
1223} 1063}
@@ -1237,10 +1077,6 @@ static int ds3000_initfe(struct dvb_frontend *fe)
1237 ds3000_writereg(state, 0x08, 0x01 | ds3000_readreg(state, 0x08)); 1077 ds3000_writereg(state, 0x08, 0x01 | ds3000_readreg(state, 0x08));
1238 msleep(1); 1078 msleep(1);
1239 1079
1240 /* TS2020 init */
1241 ds3000_tuner_writereg(state, 0x42, 0x73);
1242 ds3000_tuner_writereg(state, 0x05, 0x01);
1243 ds3000_tuner_writereg(state, 0x62, 0xf5);
1244 /* Load the firmware if required */ 1080 /* Load the firmware if required */
1245 ret = ds3000_firmware_ondemand(fe); 1081 ret = ds3000_firmware_ondemand(fe);
1246 if (ret != 0) { 1082 if (ret != 0) {
@@ -1251,17 +1087,10 @@ static int ds3000_initfe(struct dvb_frontend *fe)
1251 return 0; 1087 return 0;
1252} 1088}
1253 1089
1254/* Put device to sleep */
1255static int ds3000_sleep(struct dvb_frontend *fe)
1256{
1257 dprintk("%s()\n", __func__);
1258 return 0;
1259}
1260
1261static struct dvb_frontend_ops ds3000_ops = { 1090static struct dvb_frontend_ops ds3000_ops = {
1262 .delsys = { SYS_DVBS, SYS_DVBS2}, 1091 .delsys = { SYS_DVBS, SYS_DVBS2 },
1263 .info = { 1092 .info = {
1264 .name = "Montage Technology DS3000/TS2020", 1093 .name = "Montage Technology DS3000",
1265 .frequency_min = 950000, 1094 .frequency_min = 950000,
1266 .frequency_max = 2150000, 1095 .frequency_max = 2150000,
1267 .frequency_stepsize = 1011, /* kHz for QPSK frontends */ 1096 .frequency_stepsize = 1011, /* kHz for QPSK frontends */
@@ -1279,7 +1108,7 @@ static struct dvb_frontend_ops ds3000_ops = {
1279 .release = ds3000_release, 1108 .release = ds3000_release,
1280 1109
1281 .init = ds3000_initfe, 1110 .init = ds3000_initfe,
1282 .sleep = ds3000_sleep, 1111 .i2c_gate_ctrl = ds3000_i2c_gate_ctrl,
1283 .read_status = ds3000_read_status, 1112 .read_status = ds3000_read_status,
1284 .read_ber = ds3000_read_ber, 1113 .read_ber = ds3000_read_ber,
1285 .read_signal_strength = ds3000_read_signal_strength, 1114 .read_signal_strength = ds3000_read_signal_strength,
@@ -1299,7 +1128,7 @@ module_param(debug, int, 0644);
1299MODULE_PARM_DESC(debug, "Activates frontend debugging (default:0)"); 1128MODULE_PARM_DESC(debug, "Activates frontend debugging (default:0)");
1300 1129
1301MODULE_DESCRIPTION("DVB Frontend module for Montage Technology " 1130MODULE_DESCRIPTION("DVB Frontend module for Montage Technology "
1302 "DS3000/TS2020 hardware"); 1131 "DS3000 hardware");
1303MODULE_AUTHOR("Konstantin Dimitrov"); 1132MODULE_AUTHOR("Konstantin Dimitrov <kosio.dimitrov@gmail.com>");
1304MODULE_LICENSE("GPL"); 1133MODULE_LICENSE("GPL");
1305MODULE_FIRMWARE(DS3000_DEFAULT_FIRMWARE); 1134MODULE_FIRMWARE(DS3000_DEFAULT_FIRMWARE);
diff --git a/drivers/media/dvb-frontends/ds3000.h b/drivers/media/dvb-frontends/ds3000.h
index 1b736888ea37..478ad66c63d7 100644
--- a/drivers/media/dvb-frontends/ds3000.h
+++ b/drivers/media/dvb-frontends/ds3000.h
@@ -1,8 +1,8 @@
1/* 1/*
2 Montage Technology DS3000/TS2020 - DVBS/S2 Satellite demod/tuner driver 2 Montage Technology DS3000 - DVBS/S2 Demodulator driver
3 Copyright (C) 2009 Konstantin Dimitrov <kosio.dimitrov@gmail.com> 3 Copyright (C) 2009-2012 Konstantin Dimitrov <kosio.dimitrov@gmail.com>
4 4
5 Copyright (C) 2009 TurboSight.com 5 Copyright (C) 2009-2012 TurboSight.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 by 8 it under the terms of the GNU General Public License as published by
@@ -17,7 +17,7 @@
17 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software 18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20*/ 20 */
21 21
22#ifndef DS3000_H 22#ifndef DS3000_H
23#define DS3000_H 23#define DS3000_H
@@ -30,6 +30,8 @@ struct ds3000_config {
30 u8 ci_mode; 30 u8 ci_mode;
31 /* Set device param to start dma */ 31 /* Set device param to start dma */
32 int (*set_ts_params)(struct dvb_frontend *fe, int is_punctured); 32 int (*set_ts_params)(struct dvb_frontend *fe, int is_punctured);
33 /* Hook for Lock LED */
34 void (*set_lock_led)(struct dvb_frontend *fe, int offon);
33}; 35};
34 36
35#if defined(CONFIG_DVB_DS3000) || \ 37#if defined(CONFIG_DVB_DS3000) || \
diff --git a/drivers/media/dvb-frontends/dvb-pll.h b/drivers/media/dvb-frontends/dvb-pll.h
index 4de754f76ce9..f4b5a0601c3a 100644
--- a/drivers/media/dvb-frontends/dvb-pll.h
+++ b/drivers/media/dvb-frontends/dvb-pll.h
@@ -38,7 +38,7 @@
38 * @param pll_desc_id dvb_pll_desc to use. 38 * @param pll_desc_id dvb_pll_desc to use.
39 * @return Frontend pointer on success, NULL on failure 39 * @return Frontend pointer on success, NULL on failure
40 */ 40 */
41#if defined(CONFIG_DVB_PLL) || (defined(CONFIG_DVB_PLL_MODULE) && defined(MODULE)) 41#if IS_ENABLED(CONFIG_DVB_PLL)
42extern struct dvb_frontend *dvb_pll_attach(struct dvb_frontend *fe, 42extern struct dvb_frontend *dvb_pll_attach(struct dvb_frontend *fe,
43 int pll_addr, 43 int pll_addr,
44 struct i2c_adapter *i2c, 44 struct i2c_adapter *i2c,
diff --git a/drivers/media/dvb-frontends/isl6405.h b/drivers/media/dvb-frontends/isl6405.h
index 1c793d37576b..8abb70c26fd9 100644
--- a/drivers/media/dvb-frontends/isl6405.h
+++ b/drivers/media/dvb-frontends/isl6405.h
@@ -55,7 +55,7 @@
55#define ISL6405_ENT2 0x20 55#define ISL6405_ENT2 0x20
56#define ISL6405_ISEL2 0x40 56#define ISL6405_ISEL2 0x40
57 57
58#if defined(CONFIG_DVB_ISL6405) || (defined(CONFIG_DVB_ISL6405_MODULE) && defined(MODULE)) 58#if IS_ENABLED(CONFIG_DVB_ISL6405)
59/* override_set and override_clear control which system register bits (above) 59/* override_set and override_clear control which system register bits (above)
60 * to always set & clear 60 * to always set & clear
61 */ 61 */
diff --git a/drivers/media/dvb-frontends/isl6421.h b/drivers/media/dvb-frontends/isl6421.h
index 47e4518a042d..e7ca7d12b50a 100644
--- a/drivers/media/dvb-frontends/isl6421.h
+++ b/drivers/media/dvb-frontends/isl6421.h
@@ -39,7 +39,7 @@
39#define ISL6421_ISEL1 0x20 39#define ISL6421_ISEL1 0x20
40#define ISL6421_DCL 0x40 40#define ISL6421_DCL 0x40
41 41
42#if defined(CONFIG_DVB_ISL6421) || (defined(CONFIG_DVB_ISL6421_MODULE) && defined(MODULE)) 42#if IS_ENABLED(CONFIG_DVB_ISL6421)
43/* override_set and override_clear control which system register bits (above) to always set & clear */ 43/* override_set and override_clear control which system register bits (above) to always set & clear */
44extern struct dvb_frontend *isl6421_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, u8 i2c_addr, 44extern struct dvb_frontend *isl6421_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, u8 i2c_addr,
45 u8 override_set, u8 override_clear); 45 u8 override_set, u8 override_clear);
diff --git a/drivers/media/dvb-frontends/isl6423.h b/drivers/media/dvb-frontends/isl6423.h
index e1a37fba01ca..80dfd9cc4f41 100644
--- a/drivers/media/dvb-frontends/isl6423.h
+++ b/drivers/media/dvb-frontends/isl6423.h
@@ -42,7 +42,7 @@ struct isl6423_config {
42 u8 mod_extern; 42 u8 mod_extern;
43}; 43};
44 44
45#if defined(CONFIG_DVB_ISL6423) || (defined(CONFIG_DVB_ISL6423_MODULE) && defined(MODULE)) 45#if IS_ENABLED(CONFIG_DVB_ISL6423)
46 46
47 47
48extern struct dvb_frontend *isl6423_attach(struct dvb_frontend *fe, 48extern struct dvb_frontend *isl6423_attach(struct dvb_frontend *fe,
diff --git a/drivers/media/dvb-frontends/itd1000.h b/drivers/media/dvb-frontends/itd1000.h
index 5e18df071b88..edae0902f4fd 100644
--- a/drivers/media/dvb-frontends/itd1000.h
+++ b/drivers/media/dvb-frontends/itd1000.h
@@ -29,7 +29,7 @@ struct itd1000_config {
29 u8 i2c_address; 29 u8 i2c_address;
30}; 30};
31 31
32#if defined(CONFIG_DVB_TUNER_ITD1000) || (defined(CONFIG_DVB_TUNER_ITD1000_MODULE) && defined(MODULE)) 32#if IS_ENABLED(CONFIG_DVB_TUNER_ITD1000)
33extern struct dvb_frontend *itd1000_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, struct itd1000_config *cfg); 33extern struct dvb_frontend *itd1000_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, struct itd1000_config *cfg);
34#else 34#else
35static inline struct dvb_frontend *itd1000_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, struct itd1000_config *cfg) 35static inline struct dvb_frontend *itd1000_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, struct itd1000_config *cfg)
diff --git a/drivers/media/dvb-frontends/ix2505v.c b/drivers/media/dvb-frontends/ix2505v.c
index bc5a82082aaa..0e3387e00952 100644
--- a/drivers/media/dvb-frontends/ix2505v.c
+++ b/drivers/media/dvb-frontends/ix2505v.c
@@ -212,7 +212,7 @@ static int ix2505v_set_params(struct dvb_frontend *fe)
212 lpf = 0xb; 212 lpf = 0xb;
213 213
214 deb_info("Osc=%x b_w=%x lpf=%x\n", local_osc, b_w, lpf); 214 deb_info("Osc=%x b_w=%x lpf=%x\n", local_osc, b_w, lpf);
215 deb_info("Data 0=[%x%x%x%x]\n", data[0], data[1], data[2], data[3]); 215 deb_info("Data 0=[%4phN]\n", data);
216 216
217 if (fe->ops.i2c_gate_ctrl) 217 if (fe->ops.i2c_gate_ctrl)
218 fe->ops.i2c_gate_ctrl(fe, 1); 218 fe->ops.i2c_gate_ctrl(fe, 1);
diff --git a/drivers/media/dvb-frontends/l64781.h b/drivers/media/dvb-frontends/l64781.h
index 1305a9e7fb0b..6813b08a774d 100644
--- a/drivers/media/dvb-frontends/l64781.h
+++ b/drivers/media/dvb-frontends/l64781.h
@@ -31,7 +31,7 @@ struct l64781_config
31 u8 demod_address; 31 u8 demod_address;
32}; 32};
33 33
34#if defined(CONFIG_DVB_L64781) || (defined(CONFIG_DVB_L64781_MODULE) && defined(MODULE)) 34#if IS_ENABLED(CONFIG_DVB_L64781)
35extern struct dvb_frontend* l64781_attach(const struct l64781_config* config, 35extern struct dvb_frontend* l64781_attach(const struct l64781_config* config,
36 struct i2c_adapter* i2c); 36 struct i2c_adapter* i2c);
37#else 37#else
diff --git a/drivers/media/dvb-frontends/lgdt330x.h b/drivers/media/dvb-frontends/lgdt330x.h
index 9012504f0f2d..ca0eab562e1e 100644
--- a/drivers/media/dvb-frontends/lgdt330x.h
+++ b/drivers/media/dvb-frontends/lgdt330x.h
@@ -52,7 +52,7 @@ struct lgdt330x_config
52 int clock_polarity_flip; 52 int clock_polarity_flip;
53}; 53};
54 54
55#if defined(CONFIG_DVB_LGDT330X) || (defined(CONFIG_DVB_LGDT330X_MODULE) && defined(MODULE)) 55#if IS_ENABLED(CONFIG_DVB_LGDT330X)
56extern struct dvb_frontend* lgdt330x_attach(const struct lgdt330x_config* config, 56extern struct dvb_frontend* lgdt330x_attach(const struct lgdt330x_config* config,
57 struct i2c_adapter* i2c); 57 struct i2c_adapter* i2c);
58#else 58#else
diff --git a/drivers/media/dvb-frontends/m88rs2000.c b/drivers/media/dvb-frontends/m88rs2000.c
index 633815ed90ca..4da5272075cb 100644
--- a/drivers/media/dvb-frontends/m88rs2000.c
+++ b/drivers/media/dvb-frontends/m88rs2000.c
@@ -60,15 +60,13 @@ MODULE_PARM_DESC(debug, "set debugging level (1=info (or-able)).");
60#define info(format, arg...) \ 60#define info(format, arg...) \
61 printk(KERN_INFO "m88rs2000-fe: " format "\n" , ## arg) 61 printk(KERN_INFO "m88rs2000-fe: " format "\n" , ## arg)
62 62
63static int m88rs2000_writereg(struct m88rs2000_state *state, u8 tuner, 63static int m88rs2000_writereg(struct m88rs2000_state *state,
64 u8 reg, u8 data) 64 u8 reg, u8 data)
65{ 65{
66 int ret; 66 int ret;
67 u8 addr = (tuner == 0) ? state->config->tuner_addr :
68 state->config->demod_addr;
69 u8 buf[] = { reg, data }; 67 u8 buf[] = { reg, data };
70 struct i2c_msg msg = { 68 struct i2c_msg msg = {
71 .addr = addr, 69 .addr = state->config->demod_addr,
72 .flags = 0, 70 .flags = 0,
73 .buf = buf, 71 .buf = buf,
74 .len = 2 72 .len = 2
@@ -83,44 +81,20 @@ static int m88rs2000_writereg(struct m88rs2000_state *state, u8 tuner,
83 return (ret != 1) ? -EREMOTEIO : 0; 81 return (ret != 1) ? -EREMOTEIO : 0;
84} 82}
85 83
86static int m88rs2000_demod_write(struct m88rs2000_state *state, u8 reg, u8 data) 84static u8 m88rs2000_readreg(struct m88rs2000_state *state, u8 reg)
87{
88 return m88rs2000_writereg(state, 1, reg, data);
89}
90
91static int m88rs2000_tuner_write(struct m88rs2000_state *state, u8 reg, u8 data)
92{
93 m88rs2000_demod_write(state, 0x81, 0x84);
94 udelay(10);
95 return m88rs2000_writereg(state, 0, reg, data);
96
97}
98
99static int m88rs2000_write(struct dvb_frontend *fe, const u8 buf[], int len)
100{
101 struct m88rs2000_state *state = fe->demodulator_priv;
102
103 if (len != 2)
104 return -EINVAL;
105
106 return m88rs2000_writereg(state, 1, buf[0], buf[1]);
107}
108
109static u8 m88rs2000_readreg(struct m88rs2000_state *state, u8 tuner, u8 reg)
110{ 85{
111 int ret; 86 int ret;
112 u8 b0[] = { reg }; 87 u8 b0[] = { reg };
113 u8 b1[] = { 0 }; 88 u8 b1[] = { 0 };
114 u8 addr = (tuner == 0) ? state->config->tuner_addr : 89
115 state->config->demod_addr;
116 struct i2c_msg msg[] = { 90 struct i2c_msg msg[] = {
117 { 91 {
118 .addr = addr, 92 .addr = state->config->demod_addr,
119 .flags = 0, 93 .flags = 0,
120 .buf = b0, 94 .buf = b0,
121 .len = 1 95 .len = 1
122 }, { 96 }, {
123 .addr = addr, 97 .addr = state->config->demod_addr,
124 .flags = I2C_M_RD, 98 .flags = I2C_M_RD,
125 .buf = b1, 99 .buf = b1,
126 .len = 1 100 .len = 1
@@ -136,18 +110,6 @@ static u8 m88rs2000_readreg(struct m88rs2000_state *state, u8 tuner, u8 reg)
136 return b1[0]; 110 return b1[0];
137} 111}
138 112
139static u8 m88rs2000_demod_read(struct m88rs2000_state *state, u8 reg)
140{
141 return m88rs2000_readreg(state, 1, reg);
142}
143
144static u8 m88rs2000_tuner_read(struct m88rs2000_state *state, u8 reg)
145{
146 m88rs2000_demod_write(state, 0x81, 0x85);
147 udelay(10);
148 return m88rs2000_readreg(state, 0, reg);
149}
150
151static int m88rs2000_set_symbolrate(struct dvb_frontend *fe, u32 srate) 113static int m88rs2000_set_symbolrate(struct dvb_frontend *fe, u32 srate)
152{ 114{
153 struct m88rs2000_state *state = fe->demodulator_priv; 115 struct m88rs2000_state *state = fe->demodulator_priv;
@@ -166,9 +128,9 @@ static int m88rs2000_set_symbolrate(struct dvb_frontend *fe, u32 srate)
166 b[0] = (u8) (temp >> 16) & 0xff; 128 b[0] = (u8) (temp >> 16) & 0xff;
167 b[1] = (u8) (temp >> 8) & 0xff; 129 b[1] = (u8) (temp >> 8) & 0xff;
168 b[2] = (u8) temp & 0xff; 130 b[2] = (u8) temp & 0xff;
169 ret = m88rs2000_demod_write(state, 0x93, b[2]); 131 ret = m88rs2000_writereg(state, 0x93, b[2]);
170 ret |= m88rs2000_demod_write(state, 0x94, b[1]); 132 ret |= m88rs2000_writereg(state, 0x94, b[1]);
171 ret |= m88rs2000_demod_write(state, 0x95, b[0]); 133 ret |= m88rs2000_writereg(state, 0x95, b[0]);
172 134
173 deb_info("m88rs2000: m88rs2000_set_symbolrate\n"); 135 deb_info("m88rs2000: m88rs2000_set_symbolrate\n");
174 return ret; 136 return ret;
@@ -182,37 +144,37 @@ static int m88rs2000_send_diseqc_msg(struct dvb_frontend *fe,
182 int i; 144 int i;
183 u8 reg; 145 u8 reg;
184 deb_info("%s\n", __func__); 146 deb_info("%s\n", __func__);
185 m88rs2000_demod_write(state, 0x9a, 0x30); 147 m88rs2000_writereg(state, 0x9a, 0x30);
186 reg = m88rs2000_demod_read(state, 0xb2); 148 reg = m88rs2000_readreg(state, 0xb2);
187 reg &= 0x3f; 149 reg &= 0x3f;
188 m88rs2000_demod_write(state, 0xb2, reg); 150 m88rs2000_writereg(state, 0xb2, reg);
189 for (i = 0; i < m->msg_len; i++) 151 for (i = 0; i < m->msg_len; i++)
190 m88rs2000_demod_write(state, 0xb3 + i, m->msg[i]); 152 m88rs2000_writereg(state, 0xb3 + i, m->msg[i]);
191 153
192 reg = m88rs2000_demod_read(state, 0xb1); 154 reg = m88rs2000_readreg(state, 0xb1);
193 reg &= 0x87; 155 reg &= 0x87;
194 reg |= ((m->msg_len - 1) << 3) | 0x07; 156 reg |= ((m->msg_len - 1) << 3) | 0x07;
195 reg &= 0x7f; 157 reg &= 0x7f;
196 m88rs2000_demod_write(state, 0xb1, reg); 158 m88rs2000_writereg(state, 0xb1, reg);
197 159
198 for (i = 0; i < 15; i++) { 160 for (i = 0; i < 15; i++) {
199 if ((m88rs2000_demod_read(state, 0xb1) & 0x40) == 0x0) 161 if ((m88rs2000_readreg(state, 0xb1) & 0x40) == 0x0)
200 break; 162 break;
201 msleep(20); 163 msleep(20);
202 } 164 }
203 165
204 reg = m88rs2000_demod_read(state, 0xb1); 166 reg = m88rs2000_readreg(state, 0xb1);
205 if ((reg & 0x40) > 0x0) { 167 if ((reg & 0x40) > 0x0) {
206 reg &= 0x7f; 168 reg &= 0x7f;
207 reg |= 0x40; 169 reg |= 0x40;
208 m88rs2000_demod_write(state, 0xb1, reg); 170 m88rs2000_writereg(state, 0xb1, reg);
209 } 171 }
210 172
211 reg = m88rs2000_demod_read(state, 0xb2); 173 reg = m88rs2000_readreg(state, 0xb2);
212 reg &= 0x3f; 174 reg &= 0x3f;
213 reg |= 0x80; 175 reg |= 0x80;
214 m88rs2000_demod_write(state, 0xb2, reg); 176 m88rs2000_writereg(state, 0xb2, reg);
215 m88rs2000_demod_write(state, 0x9a, 0xb0); 177 m88rs2000_writereg(state, 0x9a, 0xb0);
216 178
217 179
218 return 0; 180 return 0;
@@ -224,14 +186,14 @@ static int m88rs2000_send_diseqc_burst(struct dvb_frontend *fe,
224 struct m88rs2000_state *state = fe->demodulator_priv; 186 struct m88rs2000_state *state = fe->demodulator_priv;
225 u8 reg0, reg1; 187 u8 reg0, reg1;
226 deb_info("%s\n", __func__); 188 deb_info("%s\n", __func__);
227 m88rs2000_demod_write(state, 0x9a, 0x30); 189 m88rs2000_writereg(state, 0x9a, 0x30);
228 msleep(50); 190 msleep(50);
229 reg0 = m88rs2000_demod_read(state, 0xb1); 191 reg0 = m88rs2000_readreg(state, 0xb1);
230 reg1 = m88rs2000_demod_read(state, 0xb2); 192 reg1 = m88rs2000_readreg(state, 0xb2);
231 /* TODO complete this section */ 193 /* TODO complete this section */
232 m88rs2000_demod_write(state, 0xb2, reg1); 194 m88rs2000_writereg(state, 0xb2, reg1);
233 m88rs2000_demod_write(state, 0xb1, reg0); 195 m88rs2000_writereg(state, 0xb1, reg0);
234 m88rs2000_demod_write(state, 0x9a, 0xb0); 196 m88rs2000_writereg(state, 0x9a, 0xb0);
235 197
236 return 0; 198 return 0;
237} 199}
@@ -240,9 +202,9 @@ static int m88rs2000_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone)
240{ 202{
241 struct m88rs2000_state *state = fe->demodulator_priv; 203 struct m88rs2000_state *state = fe->demodulator_priv;
242 u8 reg0, reg1; 204 u8 reg0, reg1;
243 m88rs2000_demod_write(state, 0x9a, 0x30); 205 m88rs2000_writereg(state, 0x9a, 0x30);
244 reg0 = m88rs2000_demod_read(state, 0xb1); 206 reg0 = m88rs2000_readreg(state, 0xb1);
245 reg1 = m88rs2000_demod_read(state, 0xb2); 207 reg1 = m88rs2000_readreg(state, 0xb2);
246 208
247 reg1 &= 0x3f; 209 reg1 &= 0x3f;
248 210
@@ -257,9 +219,9 @@ static int m88rs2000_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone)
257 default: 219 default:
258 break; 220 break;
259 } 221 }
260 m88rs2000_demod_write(state, 0xb2, reg1); 222 m88rs2000_writereg(state, 0xb2, reg1);
261 m88rs2000_demod_write(state, 0xb1, reg0); 223 m88rs2000_writereg(state, 0xb1, reg0);
262 m88rs2000_demod_write(state, 0x9a, 0xb0); 224 m88rs2000_writereg(state, 0x9a, 0xb0);
263 return 0; 225 return 0;
264} 226}
265 227
@@ -276,14 +238,6 @@ struct inittab m88rs2000_setup[] = {
276 {DEMOD_WRITE, 0x00, 0x00}, 238 {DEMOD_WRITE, 0x00, 0x00},
277 {DEMOD_WRITE, 0x9a, 0xb0}, 239 {DEMOD_WRITE, 0x9a, 0xb0},
278 {DEMOD_WRITE, 0x81, 0xc1}, 240 {DEMOD_WRITE, 0x81, 0xc1},
279 {TUNER_WRITE, 0x42, 0x73},
280 {TUNER_WRITE, 0x05, 0x07},
281 {TUNER_WRITE, 0x20, 0x27},
282 {TUNER_WRITE, 0x07, 0x02},
283 {TUNER_WRITE, 0x11, 0xff},
284 {TUNER_WRITE, 0x60, 0xf9},
285 {TUNER_WRITE, 0x08, 0x01},
286 {TUNER_WRITE, 0x00, 0x41},
287 {DEMOD_WRITE, 0x81, 0x81}, 241 {DEMOD_WRITE, 0x81, 0x81},
288 {DEMOD_WRITE, 0x86, 0xc6}, 242 {DEMOD_WRITE, 0x86, 0xc6},
289 {DEMOD_WRITE, 0x9a, 0x30}, 243 {DEMOD_WRITE, 0x9a, 0x30},
@@ -301,23 +255,10 @@ struct inittab m88rs2000_shutdown[] = {
301 {DEMOD_WRITE, 0xf1, 0x89}, 255 {DEMOD_WRITE, 0xf1, 0x89},
302 {DEMOD_WRITE, 0x00, 0x01}, 256 {DEMOD_WRITE, 0x00, 0x01},
303 {DEMOD_WRITE, 0x9a, 0xb0}, 257 {DEMOD_WRITE, 0x9a, 0xb0},
304 {TUNER_WRITE, 0x00, 0x40},
305 {DEMOD_WRITE, 0x81, 0x81}, 258 {DEMOD_WRITE, 0x81, 0x81},
306 {0xff, 0xaa, 0xff} 259 {0xff, 0xaa, 0xff}
307}; 260};
308 261
309struct inittab tuner_reset[] = {
310 {TUNER_WRITE, 0x42, 0x73},
311 {TUNER_WRITE, 0x05, 0x07},
312 {TUNER_WRITE, 0x20, 0x27},
313 {TUNER_WRITE, 0x07, 0x02},
314 {TUNER_WRITE, 0x11, 0xff},
315 {TUNER_WRITE, 0x60, 0xf9},
316 {TUNER_WRITE, 0x08, 0x01},
317 {TUNER_WRITE, 0x00, 0x41},
318 {0xff, 0xaa, 0xff}
319};
320
321struct inittab fe_reset[] = { 262struct inittab fe_reset[] = {
322 {DEMOD_WRITE, 0x00, 0x01}, 263 {DEMOD_WRITE, 0x00, 0x01},
323 {DEMOD_WRITE, 0xf1, 0xbf}, 264 {DEMOD_WRITE, 0xf1, 0xbf},
@@ -389,11 +330,7 @@ static int m88rs2000_tab_set(struct m88rs2000_state *state,
389 for (i = 0; i < 255; i++) { 330 for (i = 0; i < 255; i++) {
390 switch (tab[i].cmd) { 331 switch (tab[i].cmd) {
391 case 0x01: 332 case 0x01:
392 ret = m88rs2000_demod_write(state, tab[i].reg, 333 ret = m88rs2000_writereg(state, tab[i].reg,
393 tab[i].val);
394 break;
395 case 0x02:
396 ret = m88rs2000_tuner_write(state, tab[i].reg,
397 tab[i].val); 334 tab[i].val);
398 break; 335 break;
399 case 0x10: 336 case 0x10:
@@ -419,7 +356,7 @@ static int m88rs2000_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t volt)
419 struct m88rs2000_state *state = fe->demodulator_priv; 356 struct m88rs2000_state *state = fe->demodulator_priv;
420 u8 data; 357 u8 data;
421 358
422 data = m88rs2000_demod_read(state, 0xb2); 359 data = m88rs2000_readreg(state, 0xb2);
423 data |= 0x03; /* bit0 V/H, bit1 off/on */ 360 data |= 0x03; /* bit0 V/H, bit1 off/on */
424 361
425 switch (volt) { 362 switch (volt) {
@@ -434,23 +371,11 @@ static int m88rs2000_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t volt)
434 break; 371 break;
435 } 372 }
436 373
437 m88rs2000_demod_write(state, 0xb2, data); 374 m88rs2000_writereg(state, 0xb2, data);
438 375
439 return 0; 376 return 0;
440} 377}
441 378
442static int m88rs2000_startup(struct m88rs2000_state *state)
443{
444 int ret = 0;
445 u8 reg;
446
447 reg = m88rs2000_tuner_read(state, 0x00);
448 if ((reg & 0x40) == 0)
449 ret = -ENODEV;
450
451 return ret;
452}
453
454static int m88rs2000_init(struct dvb_frontend *fe) 379static int m88rs2000_init(struct dvb_frontend *fe)
455{ 380{
456 struct m88rs2000_state *state = fe->demodulator_priv; 381 struct m88rs2000_state *state = fe->demodulator_priv;
@@ -458,7 +383,11 @@ static int m88rs2000_init(struct dvb_frontend *fe)
458 383
459 deb_info("m88rs2000: init chip\n"); 384 deb_info("m88rs2000: init chip\n");
460 /* Setup frontend from shutdown/cold */ 385 /* Setup frontend from shutdown/cold */
461 ret = m88rs2000_tab_set(state, m88rs2000_setup); 386 if (state->config->inittab)
387 ret = m88rs2000_tab_set(state,
388 (struct inittab *)state->config->inittab);
389 else
390 ret = m88rs2000_tab_set(state, m88rs2000_setup);
462 391
463 return ret; 392 return ret;
464} 393}
@@ -475,7 +404,7 @@ static int m88rs2000_sleep(struct dvb_frontend *fe)
475static int m88rs2000_read_status(struct dvb_frontend *fe, fe_status_t *status) 404static int m88rs2000_read_status(struct dvb_frontend *fe, fe_status_t *status)
476{ 405{
477 struct m88rs2000_state *state = fe->demodulator_priv; 406 struct m88rs2000_state *state = fe->demodulator_priv;
478 u8 reg = m88rs2000_demod_read(state, 0x8c); 407 u8 reg = m88rs2000_readreg(state, 0x8c);
479 408
480 *status = 0; 409 *status = 0;
481 410
@@ -488,183 +417,64 @@ static int m88rs2000_read_status(struct dvb_frontend *fe, fe_status_t *status)
488 return 0; 417 return 0;
489} 418}
490 419
491/* Extact code for these unknown but lmedm04 driver uses interupt callbacks */
492
493static int m88rs2000_read_ber(struct dvb_frontend *fe, u32 *ber) 420static int m88rs2000_read_ber(struct dvb_frontend *fe, u32 *ber)
494{ 421{
495 deb_info("m88rs2000_read_ber %d\n", *ber); 422 struct m88rs2000_state *state = fe->demodulator_priv;
496 *ber = 0; 423 u8 tmp0, tmp1;
424
425 m88rs2000_writereg(state, 0x9a, 0x30);
426 tmp0 = m88rs2000_readreg(state, 0xd8);
427 if ((tmp0 & 0x10) != 0) {
428 m88rs2000_writereg(state, 0x9a, 0xb0);
429 *ber = 0xffffffff;
430 return 0;
431 }
432
433 *ber = (m88rs2000_readreg(state, 0xd7) << 8) |
434 m88rs2000_readreg(state, 0xd6);
435
436 tmp1 = m88rs2000_readreg(state, 0xd9);
437 m88rs2000_writereg(state, 0xd9, (tmp1 & ~7) | 4);
438 /* needs twice */
439 m88rs2000_writereg(state, 0xd8, (tmp0 & ~8) | 0x30);
440 m88rs2000_writereg(state, 0xd8, (tmp0 & ~8) | 0x30);
441 m88rs2000_writereg(state, 0x9a, 0xb0);
442
497 return 0; 443 return 0;
498} 444}
499 445
500static int m88rs2000_read_signal_strength(struct dvb_frontend *fe, 446static int m88rs2000_read_signal_strength(struct dvb_frontend *fe,
501 u16 *strength) 447 u16 *strength)
502{ 448{
503 *strength = 0; 449 if (fe->ops.tuner_ops.get_rf_strength)
504 return 0; 450 fe->ops.tuner_ops.get_rf_strength(fe, strength);
505}
506 451
507static int m88rs2000_read_snr(struct dvb_frontend *fe, u16 *snr)
508{
509 deb_info("m88rs2000_read_snr %d\n", *snr);
510 *snr = 0;
511 return 0; 452 return 0;
512} 453}
513 454
514static int m88rs2000_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks) 455static int m88rs2000_read_snr(struct dvb_frontend *fe, u16 *snr)
515{
516 deb_info("m88rs2000_read_ber %d\n", *ucblocks);
517 *ucblocks = 0;
518 return 0;
519}
520
521static int m88rs2000_tuner_gate_ctrl(struct m88rs2000_state *state, u8 offset)
522{
523 int ret;
524 ret = m88rs2000_tuner_write(state, 0x51, 0x1f - offset);
525 ret |= m88rs2000_tuner_write(state, 0x51, 0x1f);
526 ret |= m88rs2000_tuner_write(state, 0x50, offset);
527 ret |= m88rs2000_tuner_write(state, 0x50, 0x00);
528 msleep(20);
529 return ret;
530}
531
532static int m88rs2000_set_tuner_rf(struct dvb_frontend *fe)
533{ 456{
534 struct m88rs2000_state *state = fe->demodulator_priv; 457 struct m88rs2000_state *state = fe->demodulator_priv;
535 int reg;
536 reg = m88rs2000_tuner_read(state, 0x3d);
537 reg &= 0x7f;
538 if (reg < 0x16)
539 reg = 0xa1;
540 else if (reg == 0x16)
541 reg = 0x99;
542 else
543 reg = 0xf9;
544 458
545 m88rs2000_tuner_write(state, 0x60, reg); 459 *snr = 512 * m88rs2000_readreg(state, 0x65);
546 reg = m88rs2000_tuner_gate_ctrl(state, 0x08);
547 460
548 if (fe->ops.i2c_gate_ctrl) 461 return 0;
549 fe->ops.i2c_gate_ctrl(fe, 0);
550 return reg;
551} 462}
552 463
553static int m88rs2000_set_tuner(struct dvb_frontend *fe, u16 *offset) 464static int m88rs2000_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
554{ 465{
555 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
556 struct m88rs2000_state *state = fe->demodulator_priv; 466 struct m88rs2000_state *state = fe->demodulator_priv;
557 int ret; 467 u8 tmp;
558 u32 frequency = c->frequency;
559 s32 offset_khz;
560 s32 tmp;
561 u32 symbol_rate = (c->symbol_rate / 1000);
562 u32 f3db, gdiv28;
563 u16 value, ndiv, lpf_coeff;
564 u8 lpf_mxdiv, mlpf_max, mlpf_min, nlpf;
565 u8 lo = 0x01, div4 = 0x0;
566
567 /* Reset Tuner */
568 ret = m88rs2000_tab_set(state, tuner_reset);
569
570 /* Calculate frequency divider */
571 if (frequency < 1060000) {
572 lo |= 0x10;
573 div4 = 0x1;
574 ndiv = (frequency * 14 * 4) / FE_CRYSTAL_KHZ;
575 } else
576 ndiv = (frequency * 14 * 2) / FE_CRYSTAL_KHZ;
577 ndiv = ndiv + ndiv % 2;
578 ndiv = ndiv - 1024;
579
580 ret = m88rs2000_tuner_write(state, 0x10, 0x80 | lo);
581
582 /* Set frequency divider */
583 ret |= m88rs2000_tuner_write(state, 0x01, (ndiv >> 8) & 0xf);
584 ret |= m88rs2000_tuner_write(state, 0x02, ndiv & 0xff);
585
586 ret |= m88rs2000_tuner_write(state, 0x03, 0x06);
587 ret |= m88rs2000_tuner_gate_ctrl(state, 0x10);
588 if (ret < 0)
589 return -ENODEV;
590
591 /* Tuner Frequency Range */
592 ret = m88rs2000_tuner_write(state, 0x10, lo);
593
594 ret |= m88rs2000_tuner_gate_ctrl(state, 0x08);
595
596 /* Tuner RF */
597 ret |= m88rs2000_set_tuner_rf(fe);
598
599 gdiv28 = (FE_CRYSTAL_KHZ / 1000 * 1694 + 500) / 1000;
600 ret |= m88rs2000_tuner_write(state, 0x04, gdiv28 & 0xff);
601 ret |= m88rs2000_tuner_gate_ctrl(state, 0x04);
602 if (ret < 0)
603 return -ENODEV;
604
605 value = m88rs2000_tuner_read(state, 0x26);
606
607 f3db = (symbol_rate * 135) / 200 + 2000;
608 f3db += FREQ_OFFSET_LOW_SYM_RATE;
609 if (f3db < 7000)
610 f3db = 7000;
611 if (f3db > 40000)
612 f3db = 40000;
613
614 gdiv28 = gdiv28 * 207 / (value * 2 + 151);
615 mlpf_max = gdiv28 * 135 / 100;
616 mlpf_min = gdiv28 * 78 / 100;
617 if (mlpf_max > 63)
618 mlpf_max = 63;
619
620 lpf_coeff = 2766;
621
622 nlpf = (f3db * gdiv28 * 2 / lpf_coeff /
623 (FE_CRYSTAL_KHZ / 1000) + 1) / 2;
624 if (nlpf > 23)
625 nlpf = 23;
626 if (nlpf < 1)
627 nlpf = 1;
628
629 lpf_mxdiv = (nlpf * (FE_CRYSTAL_KHZ / 1000)
630 * lpf_coeff * 2 / f3db + 1) / 2;
631
632 if (lpf_mxdiv < mlpf_min) {
633 nlpf++;
634 lpf_mxdiv = (nlpf * (FE_CRYSTAL_KHZ / 1000)
635 * lpf_coeff * 2 / f3db + 1) / 2;
636 }
637
638 if (lpf_mxdiv > mlpf_max)
639 lpf_mxdiv = mlpf_max;
640
641 ret = m88rs2000_tuner_write(state, 0x04, lpf_mxdiv);
642 ret |= m88rs2000_tuner_write(state, 0x06, nlpf);
643
644 ret |= m88rs2000_tuner_gate_ctrl(state, 0x04);
645
646 ret |= m88rs2000_tuner_gate_ctrl(state, 0x01);
647
648 msleep(80);
649 /* calculate offset assuming 96000kHz*/
650 offset_khz = (ndiv - ndiv % 2 + 1024) * FE_CRYSTAL_KHZ
651 / 14 / (div4 + 1) / 2;
652 468
653 offset_khz -= frequency; 469 *ucblocks = (m88rs2000_readreg(state, 0xd5) << 8) |
470 m88rs2000_readreg(state, 0xd4);
471 tmp = m88rs2000_readreg(state, 0xd8);
472 m88rs2000_writereg(state, 0xd8, tmp & ~0x20);
473 /* needs two times */
474 m88rs2000_writereg(state, 0xd8, tmp | 0x20);
475 m88rs2000_writereg(state, 0xd8, tmp | 0x20);
654 476
655 tmp = offset_khz; 477 return 0;
656 tmp *= 65536;
657
658 tmp = (2 * tmp + 96000) / (2 * 96000);
659 if (tmp < 0)
660 tmp += 65536;
661
662 *offset = tmp & 0xffff;
663
664 if (fe->ops.i2c_gate_ctrl)
665 fe->ops.i2c_gate_ctrl(fe, 0);
666
667 return (ret < 0) ? -EINVAL : 0;
668} 478}
669 479
670static int m88rs2000_set_fec(struct m88rs2000_state *state, 480static int m88rs2000_set_fec(struct m88rs2000_state *state,
@@ -692,7 +502,7 @@ static int m88rs2000_set_fec(struct m88rs2000_state *state,
692 default: 502 default:
693 fec_set = 0x08; 503 fec_set = 0x08;
694 } 504 }
695 m88rs2000_demod_write(state, 0x76, fec_set); 505 m88rs2000_writereg(state, 0x76, fec_set);
696 506
697 return 0; 507 return 0;
698} 508}
@@ -701,9 +511,9 @@ static int m88rs2000_set_fec(struct m88rs2000_state *state,
701static fe_code_rate_t m88rs2000_get_fec(struct m88rs2000_state *state) 511static fe_code_rate_t m88rs2000_get_fec(struct m88rs2000_state *state)
702{ 512{
703 u8 reg; 513 u8 reg;
704 m88rs2000_demod_write(state, 0x9a, 0x30); 514 m88rs2000_writereg(state, 0x9a, 0x30);
705 reg = m88rs2000_demod_read(state, 0x76); 515 reg = m88rs2000_readreg(state, 0x76);
706 m88rs2000_demod_write(state, 0x9a, 0xb0); 516 m88rs2000_writereg(state, 0x9a, 0xb0);
707 517
708 switch (reg) { 518 switch (reg) {
709 case 0x88: 519 case 0x88:
@@ -729,7 +539,9 @@ static int m88rs2000_set_frontend(struct dvb_frontend *fe)
729 struct m88rs2000_state *state = fe->demodulator_priv; 539 struct m88rs2000_state *state = fe->demodulator_priv;
730 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 540 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
731 fe_status_t status; 541 fe_status_t status;
732 int i, ret; 542 int i, ret = 0;
543 s32 tmp;
544 u32 tuner_freq;
733 u16 offset = 0; 545 u16 offset = 0;
734 u8 reg; 546 u8 reg;
735 547
@@ -743,17 +555,37 @@ static int m88rs2000_set_frontend(struct dvb_frontend *fe)
743 } 555 }
744 556
745 /* Set Tuner */ 557 /* Set Tuner */
746 ret = m88rs2000_set_tuner(fe, &offset); 558 if (fe->ops.tuner_ops.set_params)
559 ret = fe->ops.tuner_ops.set_params(fe);
560
561 if (ret < 0)
562 return -ENODEV;
563
564 if (fe->ops.tuner_ops.get_frequency)
565 ret = fe->ops.tuner_ops.get_frequency(fe, &tuner_freq);
566
747 if (ret < 0) 567 if (ret < 0)
748 return -ENODEV; 568 return -ENODEV;
749 569
750 ret = m88rs2000_demod_write(state, 0x9a, 0x30); 570 offset = tuner_freq - c->frequency;
571
572 /* calculate offset assuming 96000kHz*/
573 tmp = offset;
574 tmp *= 65536;
575
576 tmp = (2 * tmp + 96000) / (2 * 96000);
577 if (tmp < 0)
578 tmp += 65536;
579
580 offset = tmp & 0xffff;
581
582 ret = m88rs2000_writereg(state, 0x9a, 0x30);
751 /* Unknown usually 0xc6 sometimes 0xc1 */ 583 /* Unknown usually 0xc6 sometimes 0xc1 */
752 reg = m88rs2000_demod_read(state, 0x86); 584 reg = m88rs2000_readreg(state, 0x86);
753 ret |= m88rs2000_demod_write(state, 0x86, reg); 585 ret |= m88rs2000_writereg(state, 0x86, reg);
754 /* Offset lower nibble always 0 */ 586 /* Offset lower nibble always 0 */
755 ret |= m88rs2000_demod_write(state, 0x9c, (offset >> 8)); 587 ret |= m88rs2000_writereg(state, 0x9c, (offset >> 8));
756 ret |= m88rs2000_demod_write(state, 0x9d, offset & 0xf0); 588 ret |= m88rs2000_writereg(state, 0x9d, offset & 0xf0);
757 589
758 590
759 /* Reset Demod */ 591 /* Reset Demod */
@@ -762,16 +594,16 @@ static int m88rs2000_set_frontend(struct dvb_frontend *fe)
762 return -ENODEV; 594 return -ENODEV;
763 595
764 /* Unknown */ 596 /* Unknown */
765 reg = m88rs2000_demod_read(state, 0x70); 597 reg = m88rs2000_readreg(state, 0x70);
766 ret = m88rs2000_demod_write(state, 0x70, reg); 598 ret = m88rs2000_writereg(state, 0x70, reg);
767 599
768 /* Set FEC */ 600 /* Set FEC */
769 ret |= m88rs2000_set_fec(state, c->fec_inner); 601 ret |= m88rs2000_set_fec(state, c->fec_inner);
770 ret |= m88rs2000_demod_write(state, 0x85, 0x1); 602 ret |= m88rs2000_writereg(state, 0x85, 0x1);
771 ret |= m88rs2000_demod_write(state, 0x8a, 0xbf); 603 ret |= m88rs2000_writereg(state, 0x8a, 0xbf);
772 ret |= m88rs2000_demod_write(state, 0x8d, 0x1e); 604 ret |= m88rs2000_writereg(state, 0x8d, 0x1e);
773 ret |= m88rs2000_demod_write(state, 0x90, 0xf1); 605 ret |= m88rs2000_writereg(state, 0x90, 0xf1);
774 ret |= m88rs2000_demod_write(state, 0x91, 0x08); 606 ret |= m88rs2000_writereg(state, 0x91, 0x08);
775 607
776 if (ret < 0) 608 if (ret < 0)
777 return -ENODEV; 609 return -ENODEV;
@@ -787,27 +619,25 @@ static int m88rs2000_set_frontend(struct dvb_frontend *fe)
787 return -ENODEV; 619 return -ENODEV;
788 620
789 for (i = 0; i < 25; i++) { 621 for (i = 0; i < 25; i++) {
790 reg = m88rs2000_demod_read(state, 0x8c); 622 reg = m88rs2000_readreg(state, 0x8c);
791 if ((reg & 0x7) == 0x7) { 623 if ((reg & 0x7) == 0x7) {
792 status = FE_HAS_LOCK; 624 status = FE_HAS_LOCK;
793 break; 625 break;
794 } 626 }
795 state->no_lock_count++; 627 state->no_lock_count++;
796 if (state->no_lock_count == 15) { 628 if (state->no_lock_count == 15) {
797 reg = m88rs2000_demod_read(state, 0x70); 629 reg = m88rs2000_readreg(state, 0x70);
798 reg ^= 0x4; 630 reg ^= 0x4;
799 m88rs2000_demod_write(state, 0x70, reg); 631 m88rs2000_writereg(state, 0x70, reg);
800 state->no_lock_count = 0; 632 state->no_lock_count = 0;
801 } 633 }
802 if (state->no_lock_count == 20)
803 m88rs2000_set_tuner_rf(fe);
804 msleep(20); 634 msleep(20);
805 } 635 }
806 636
807 if (status & FE_HAS_LOCK) { 637 if (status & FE_HAS_LOCK) {
808 state->fec_inner = m88rs2000_get_fec(state); 638 state->fec_inner = m88rs2000_get_fec(state);
809 /* Uknown suspect SNR level */ 639 /* Uknown suspect SNR level */
810 reg = m88rs2000_demod_read(state, 0x65); 640 reg = m88rs2000_readreg(state, 0x65);
811 } 641 }
812 642
813 state->tuner_frequency = c->frequency; 643 state->tuner_frequency = c->frequency;
@@ -830,9 +660,9 @@ static int m88rs2000_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
830 struct m88rs2000_state *state = fe->demodulator_priv; 660 struct m88rs2000_state *state = fe->demodulator_priv;
831 661
832 if (enable) 662 if (enable)
833 m88rs2000_demod_write(state, 0x81, 0x84); 663 m88rs2000_writereg(state, 0x81, 0x84);
834 else 664 else
835 m88rs2000_demod_write(state, 0x81, 0x81); 665 m88rs2000_writereg(state, 0x81, 0x81);
836 udelay(10); 666 udelay(10);
837 return 0; 667 return 0;
838} 668}
@@ -863,7 +693,6 @@ static struct dvb_frontend_ops m88rs2000_ops = {
863 .release = m88rs2000_release, 693 .release = m88rs2000_release,
864 .init = m88rs2000_init, 694 .init = m88rs2000_init,
865 .sleep = m88rs2000_sleep, 695 .sleep = m88rs2000_sleep,
866 .write = m88rs2000_write,
867 .i2c_gate_ctrl = m88rs2000_i2c_gate_ctrl, 696 .i2c_gate_ctrl = m88rs2000_i2c_gate_ctrl,
868 .read_status = m88rs2000_read_status, 697 .read_status = m88rs2000_read_status,
869 .read_ber = m88rs2000_read_ber, 698 .read_ber = m88rs2000_read_ber,
@@ -896,9 +725,6 @@ struct dvb_frontend *m88rs2000_attach(const struct m88rs2000_config *config,
896 state->symbol_rate = 0; 725 state->symbol_rate = 0;
897 state->fec_inner = 0; 726 state->fec_inner = 0;
898 727
899 if (m88rs2000_startup(state) < 0)
900 goto error;
901
902 /* create dvb_frontend */ 728 /* create dvb_frontend */
903 memcpy(&state->frontend.ops, &m88rs2000_ops, 729 memcpy(&state->frontend.ops, &m88rs2000_ops,
904 sizeof(struct dvb_frontend_ops)); 730 sizeof(struct dvb_frontend_ops));
diff --git a/drivers/media/dvb-frontends/m88rs2000.h b/drivers/media/dvb-frontends/m88rs2000.h
index 59acdb696873..5a8023e5a4b8 100644
--- a/drivers/media/dvb-frontends/m88rs2000.h
+++ b/drivers/media/dvb-frontends/m88rs2000.h
@@ -26,8 +26,6 @@
26struct m88rs2000_config { 26struct m88rs2000_config {
27 /* Demodulator i2c address */ 27 /* Demodulator i2c address */
28 u8 demod_addr; 28 u8 demod_addr;
29 /* Tuner address */
30 u8 tuner_addr;
31 29
32 u8 *inittab; 30 u8 *inittab;
33 31
@@ -55,12 +53,8 @@ static inline struct dvb_frontend *m88rs2000_attach(
55} 53}
56#endif /* CONFIG_DVB_M88RS2000 */ 54#endif /* CONFIG_DVB_M88RS2000 */
57 55
58#define FE_CRYSTAL_KHZ 27000
59#define FREQ_OFFSET_LOW_SYM_RATE 3000
60
61enum { 56enum {
62 DEMOD_WRITE = 0x1, 57 DEMOD_WRITE = 0x1,
63 TUNER_WRITE,
64 WRITE_DELAY = 0x10, 58 WRITE_DELAY = 0x10,
65}; 59};
66#endif /* M88RS2000_H */ 60#endif /* M88RS2000_H */
diff --git a/drivers/media/dvb-frontends/mb86a16.h b/drivers/media/dvb-frontends/mb86a16.h
index 6ea8c376394f..277ce061acf9 100644
--- a/drivers/media/dvb-frontends/mb86a16.h
+++ b/drivers/media/dvb-frontends/mb86a16.h
@@ -33,7 +33,7 @@ struct mb86a16_config {
33 33
34 34
35 35
36#if defined(CONFIG_DVB_MB86A16) || (defined(CONFIG_DVB_MB86A16_MODULE) && defined(MODULE)) 36#if IS_ENABLED(CONFIG_DVB_MB86A16)
37 37
38extern struct dvb_frontend *mb86a16_attach(const struct mb86a16_config *config, 38extern struct dvb_frontend *mb86a16_attach(const struct mb86a16_config *config,
39 struct i2c_adapter *i2c_adap); 39 struct i2c_adapter *i2c_adap);
diff --git a/drivers/media/dvb-frontends/mb86a20s.c b/drivers/media/dvb-frontends/mb86a20s.c
index fade566927c3..f19cd7367040 100644
--- a/drivers/media/dvb-frontends/mb86a20s.c
+++ b/drivers/media/dvb-frontends/mb86a20s.c
@@ -1,11 +1,9 @@
1/* 1/*
2 * Fujitu mb86a20s ISDB-T/ISDB-Tsb Module driver 2 * Fujitu mb86a20s ISDB-T/ISDB-Tsb Module driver
3 * 3 *
4 * Copyright (C) 2010 Mauro Carvalho Chehab <mchehab@redhat.com> 4 * Copyright (C) 2010-2013 Mauro Carvalho Chehab <mchehab@redhat.com>
5 * Copyright (C) 2009-2010 Douglas Landgraf <dougsland@redhat.com> 5 * Copyright (C) 2009-2010 Douglas Landgraf <dougsland@redhat.com>
6 * 6 *
7 * FIXME: Need to port to DVB v5.2 API
8 *
9 * This program is free software; you can redistribute it and/or 7 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as 8 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation version 2. 9 * published by the Free Software Foundation version 2.
@@ -26,24 +24,15 @@ static int debug = 1;
26module_param(debug, int, 0644); 24module_param(debug, int, 0644);
27MODULE_PARM_DESC(debug, "Activates frontend debugging (default:0)"); 25MODULE_PARM_DESC(debug, "Activates frontend debugging (default:0)");
28 26
29#define rc(args...) do { \
30 printk(KERN_ERR "mb86a20s: " args); \
31} while (0)
32
33#define dprintk(args...) \
34 do { \
35 if (debug) { \
36 printk(KERN_DEBUG "mb86a20s: %s: ", __func__); \
37 printk(args); \
38 } \
39 } while (0)
40
41struct mb86a20s_state { 27struct mb86a20s_state {
42 struct i2c_adapter *i2c; 28 struct i2c_adapter *i2c;
43 const struct mb86a20s_config *config; 29 const struct mb86a20s_config *config;
30 u32 last_frequency;
44 31
45 struct dvb_frontend frontend; 32 struct dvb_frontend frontend;
46 33
34 u32 estimated_rate[3];
35
47 bool need_init; 36 bool need_init;
48}; 37};
49 38
@@ -52,6 +41,8 @@ struct regdata {
52 u8 data; 41 u8 data;
53}; 42};
54 43
44#define BER_SAMPLING_RATE 1 /* Seconds */
45
55/* 46/*
56 * Initialization sequence: Use whatevere default values that PV SBTVD 47 * Initialization sequence: Use whatevere default values that PV SBTVD
57 * does on its initialisation, obtained via USB snoop 48 * does on its initialisation, obtained via USB snoop
@@ -94,41 +85,68 @@ static struct regdata mb86a20s_init[] = {
94 { 0x04, 0x13 }, { 0x05, 0xff }, 85 { 0x04, 0x13 }, { 0x05, 0xff },
95 { 0x04, 0x15 }, { 0x05, 0x4e }, 86 { 0x04, 0x15 }, { 0x05, 0x4e },
96 { 0x04, 0x16 }, { 0x05, 0x20 }, 87 { 0x04, 0x16 }, { 0x05, 0x20 },
97 { 0x52, 0x01 }, 88
98 { 0x50, 0xa7 }, { 0x51, 0xff }, 89 /*
90 * On this demod, when the bit count reaches the count below,
91 * it collects the bit error count. The bit counters are initialized
92 * to 65535 here. This warrants that all of them will be quickly
93 * calculated when device gets locked. As TMCC is parsed, the values
94 * will be adjusted later in the driver's code.
95 */
96 { 0x52, 0x01 }, /* Turn on BER before Viterbi */
97 { 0x50, 0xa7 }, { 0x51, 0x00 },
99 { 0x50, 0xa8 }, { 0x51, 0xff }, 98 { 0x50, 0xa8 }, { 0x51, 0xff },
100 { 0x50, 0xa9 }, { 0x51, 0xff }, 99 { 0x50, 0xa9 }, { 0x51, 0xff },
101 { 0x50, 0xaa }, { 0x51, 0xff }, 100 { 0x50, 0xaa }, { 0x51, 0x00 },
102 { 0x50, 0xab }, { 0x51, 0xff }, 101 { 0x50, 0xab }, { 0x51, 0xff },
103 { 0x50, 0xac }, { 0x51, 0xff }, 102 { 0x50, 0xac }, { 0x51, 0xff },
104 { 0x50, 0xad }, { 0x51, 0xff }, 103 { 0x50, 0xad }, { 0x51, 0x00 },
105 { 0x50, 0xae }, { 0x51, 0xff }, 104 { 0x50, 0xae }, { 0x51, 0xff },
106 { 0x50, 0xaf }, { 0x51, 0xff }, 105 { 0x50, 0xaf }, { 0x51, 0xff },
107 { 0x5e, 0x07 }, 106
108 { 0x50, 0xdc }, { 0x51, 0x01 }, 107 /*
109 { 0x50, 0xdd }, { 0x51, 0xf4 }, 108 * On this demod, post BER counts blocks. When the count reaches the
110 { 0x50, 0xde }, { 0x51, 0x01 }, 109 * value below, it collects the block error count. The block counters
111 { 0x50, 0xdf }, { 0x51, 0xf4 }, 110 * are initialized to 127 here. This warrants that all of them will be
112 { 0x50, 0xe0 }, { 0x51, 0x01 }, 111 * quickly calculated when device gets locked. As TMCC is parsed, the
113 { 0x50, 0xe1 }, { 0x51, 0xf4 }, 112 * values will be adjusted later in the driver's code.
114 { 0x50, 0xb0 }, { 0x51, 0x07 }, 113 */
115 { 0x50, 0xb2 }, { 0x51, 0xff }, 114 { 0x5e, 0x07 }, /* Turn on BER after Viterbi */
116 { 0x50, 0xb3 }, { 0x51, 0xff }, 115 { 0x50, 0xdc }, { 0x51, 0x00 },
117 { 0x50, 0xb4 }, { 0x51, 0xff }, 116 { 0x50, 0xdd }, { 0x51, 0x7f },
118 { 0x50, 0xb5 }, { 0x51, 0xff }, 117 { 0x50, 0xde }, { 0x51, 0x00 },
119 { 0x50, 0xb6 }, { 0x51, 0xff }, 118 { 0x50, 0xdf }, { 0x51, 0x7f },
120 { 0x50, 0xb7 }, { 0x51, 0xff }, 119 { 0x50, 0xe0 }, { 0x51, 0x00 },
121 { 0x50, 0x50 }, { 0x51, 0x02 }, 120 { 0x50, 0xe1 }, { 0x51, 0x7f },
122 { 0x50, 0x51 }, { 0x51, 0x04 }, 121
123 { 0x45, 0x04 }, 122 /*
124 { 0x48, 0x04 }, 123 * On this demod, when the block count reaches the count below,
124 * it collects the block error count. The block counters are initialized
125 * to 127 here. This warrants that all of them will be quickly
126 * calculated when device gets locked. As TMCC is parsed, the values
127 * will be adjusted later in the driver's code.
128 */
129 { 0x50, 0xb0 }, { 0x51, 0x07 }, /* Enable PER */
130 { 0x50, 0xb2 }, { 0x51, 0x00 },
131 { 0x50, 0xb3 }, { 0x51, 0x7f },
132 { 0x50, 0xb4 }, { 0x51, 0x00 },
133 { 0x50, 0xb5 }, { 0x51, 0x7f },
134 { 0x50, 0xb6 }, { 0x51, 0x00 },
135 { 0x50, 0xb7 }, { 0x51, 0x7f },
136
137 { 0x50, 0x50 }, { 0x51, 0x02 }, /* MER manual mode */
138 { 0x50, 0x51 }, { 0x51, 0x04 }, /* MER symbol 4 */
139 { 0x45, 0x04 }, /* CN symbol 4 */
140 { 0x48, 0x04 }, /* CN manual mode */
141
125 { 0x50, 0xd5 }, { 0x51, 0x01 }, /* Serial */ 142 { 0x50, 0xd5 }, { 0x51, 0x01 }, /* Serial */
126 { 0x50, 0xd6 }, { 0x51, 0x1f }, 143 { 0x50, 0xd6 }, { 0x51, 0x1f },
127 { 0x50, 0xd2 }, { 0x51, 0x03 }, 144 { 0x50, 0xd2 }, { 0x51, 0x03 },
128 { 0x50, 0xd7 }, { 0x51, 0x3f }, 145 { 0x50, 0xd7 }, { 0x51, 0x3f },
129 { 0x28, 0x74 }, { 0x29, 0x00 }, { 0x28, 0x74 }, { 0x29, 0x40 }, 146 { 0x28, 0x74 }, { 0x29, 0x00 }, { 0x28, 0x74 }, { 0x29, 0x40 },
130 { 0x28, 0x46 }, { 0x29, 0x2c }, { 0x28, 0x46 }, { 0x29, 0x0c }, 147 { 0x28, 0x46 }, { 0x29, 0x2c }, { 0x28, 0x46 }, { 0x29, 0x0c },
131 { 0x04, 0x40 }, { 0x05, 0x01 }, 148
149 { 0x04, 0x40 }, { 0x05, 0x00 },
132 { 0x28, 0x00 }, { 0x29, 0x10 }, 150 { 0x28, 0x00 }, { 0x29, 0x10 },
133 { 0x28, 0x05 }, { 0x29, 0x02 }, 151 { 0x28, 0x05 }, { 0x29, 0x02 },
134 { 0x1c, 0x01 }, 152 { 0x1c, 0x01 },
@@ -176,8 +194,24 @@ static struct regdata mb86a20s_reset_reception[] = {
176 { 0x08, 0x00 }, 194 { 0x08, 0x00 },
177}; 195};
178 196
197static struct regdata mb86a20s_per_ber_reset[] = {
198 { 0x53, 0x00 }, /* pre BER Counter reset */
199 { 0x53, 0x07 },
200
201 { 0x5f, 0x00 }, /* post BER Counter reset */
202 { 0x5f, 0x07 },
203
204 { 0x50, 0xb1 }, /* PER Counter reset */
205 { 0x51, 0x07 },
206 { 0x51, 0x00 },
207};
208
209/*
210 * I2C read/write functions and macros
211 */
212
179static int mb86a20s_i2c_writereg(struct mb86a20s_state *state, 213static int mb86a20s_i2c_writereg(struct mb86a20s_state *state,
180 u8 i2c_addr, int reg, int data) 214 u8 i2c_addr, u8 reg, u8 data)
181{ 215{
182 u8 buf[] = { reg, data }; 216 u8 buf[] = { reg, data };
183 struct i2c_msg msg = { 217 struct i2c_msg msg = {
@@ -187,8 +221,9 @@ static int mb86a20s_i2c_writereg(struct mb86a20s_state *state,
187 221
188 rc = i2c_transfer(state->i2c, &msg, 1); 222 rc = i2c_transfer(state->i2c, &msg, 1);
189 if (rc != 1) { 223 if (rc != 1) {
190 printk("%s: writereg error (rc == %i, reg == 0x%02x," 224 dev_err(&state->i2c->dev,
191 " data == 0x%02x)\n", __func__, rc, reg, data); 225 "%s: writereg error (rc == %i, reg == 0x%02x, data == 0x%02x)\n",
226 __func__, rc, reg, data);
192 return rc; 227 return rc;
193 } 228 }
194 229
@@ -222,8 +257,9 @@ static int mb86a20s_i2c_readreg(struct mb86a20s_state *state,
222 rc = i2c_transfer(state->i2c, msg, 2); 257 rc = i2c_transfer(state->i2c, msg, 2);
223 258
224 if (rc != 2) { 259 if (rc != 2) {
225 rc("%s: reg=0x%x (error=%d)\n", __func__, reg, rc); 260 dev_err(&state->i2c->dev, "%s: reg=0x%x (error=%d)\n",
226 return rc; 261 __func__, reg, rc);
262 return (rc < 0) ? rc : -EIO;
227 } 263 }
228 264
229 return val; 265 return val;
@@ -237,100 +273,22 @@ static int mb86a20s_i2c_readreg(struct mb86a20s_state *state,
237 mb86a20s_i2c_writeregdata(state, state->config->demod_address, \ 273 mb86a20s_i2c_writeregdata(state, state->config->demod_address, \
238 regdata, ARRAY_SIZE(regdata)) 274 regdata, ARRAY_SIZE(regdata))
239 275
240static int mb86a20s_initfe(struct dvb_frontend *fe) 276/*
241{ 277 * Ancillary internal routines (likely compiled inlined)
242 struct mb86a20s_state *state = fe->demodulator_priv; 278 *
243 int rc; 279 * The functions below assume that gateway lock has already obtained
244 u8 regD5 = 1; 280 */
245
246 dprintk("\n");
247
248 if (fe->ops.i2c_gate_ctrl)
249 fe->ops.i2c_gate_ctrl(fe, 0);
250
251 /* Initialize the frontend */
252 rc = mb86a20s_writeregdata(state, mb86a20s_init);
253 if (rc < 0)
254 goto err;
255
256 if (!state->config->is_serial) {
257 regD5 &= ~1;
258
259 rc = mb86a20s_writereg(state, 0x50, 0xd5);
260 if (rc < 0)
261 goto err;
262 rc = mb86a20s_writereg(state, 0x51, regD5);
263 if (rc < 0)
264 goto err;
265 }
266
267 if (fe->ops.i2c_gate_ctrl)
268 fe->ops.i2c_gate_ctrl(fe, 1);
269
270err:
271 if (rc < 0) {
272 state->need_init = true;
273 printk(KERN_INFO "mb86a20s: Init failed. Will try again later\n");
274 } else {
275 state->need_init = false;
276 dprintk("Initialization succeeded.\n");
277 }
278 return rc;
279}
280
281static int mb86a20s_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
282{
283 struct mb86a20s_state *state = fe->demodulator_priv;
284 unsigned rf_max, rf_min, rf;
285 u8 val;
286
287 dprintk("\n");
288
289 if (fe->ops.i2c_gate_ctrl)
290 fe->ops.i2c_gate_ctrl(fe, 0);
291
292 /* Does a binary search to get RF strength */
293 rf_max = 0xfff;
294 rf_min = 0;
295 do {
296 rf = (rf_max + rf_min) / 2;
297 mb86a20s_writereg(state, 0x04, 0x1f);
298 mb86a20s_writereg(state, 0x05, rf >> 8);
299 mb86a20s_writereg(state, 0x04, 0x20);
300 mb86a20s_writereg(state, 0x04, rf);
301
302 val = mb86a20s_readreg(state, 0x02);
303 if (val & 0x08)
304 rf_min = (rf_max + rf_min) / 2;
305 else
306 rf_max = (rf_max + rf_min) / 2;
307 if (rf_max - rf_min < 4) {
308 *strength = (((rf_max + rf_min) / 2) * 65535) / 4095;
309 break;
310 }
311 } while (1);
312
313 dprintk("signal strength = %d\n", *strength);
314
315 if (fe->ops.i2c_gate_ctrl)
316 fe->ops.i2c_gate_ctrl(fe, 1);
317
318 return 0;
319}
320 281
321static int mb86a20s_read_status(struct dvb_frontend *fe, fe_status_t *status) 282static int mb86a20s_read_status(struct dvb_frontend *fe, fe_status_t *status)
322{ 283{
323 struct mb86a20s_state *state = fe->demodulator_priv; 284 struct mb86a20s_state *state = fe->demodulator_priv;
324 u8 val; 285 int val;
325 286
326 dprintk("\n");
327 *status = 0; 287 *status = 0;
328 288
329 if (fe->ops.i2c_gate_ctrl)
330 fe->ops.i2c_gate_ctrl(fe, 0);
331 val = mb86a20s_readreg(state, 0x0a) & 0xf; 289 val = mb86a20s_readreg(state, 0x0a) & 0xf;
332 if (fe->ops.i2c_gate_ctrl) 290 if (val < 0)
333 fe->ops.i2c_gate_ctrl(fe, 1); 291 return val;
334 292
335 if (val >= 2) 293 if (val >= 2)
336 *status |= FE_HAS_SIGNAL; 294 *status |= FE_HAS_SIGNAL;
@@ -347,49 +305,56 @@ static int mb86a20s_read_status(struct dvb_frontend *fe, fe_status_t *status)
347 if (val >= 8) /* Maybe 9? */ 305 if (val >= 8) /* Maybe 9? */
348 *status |= FE_HAS_LOCK; 306 *status |= FE_HAS_LOCK;
349 307
350 dprintk("val = %d, status = 0x%02x\n", val, *status); 308 dev_dbg(&state->i2c->dev, "%s: Status = 0x%02x (state = %d)\n",
309 __func__, *status, val);
351 310
352 return 0; 311 return 0;
353} 312}
354 313
355static int mb86a20s_set_frontend(struct dvb_frontend *fe) 314static int mb86a20s_read_signal_strength(struct dvb_frontend *fe)
356{ 315{
357 struct mb86a20s_state *state = fe->demodulator_priv; 316 struct mb86a20s_state *state = fe->demodulator_priv;
358 int rc; 317 int rc;
359#if 0 318 unsigned rf_max, rf_min, rf;
360 /*
361 * FIXME: Properly implement the set frontend properties
362 */
363 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
364#endif
365
366 dprintk("\n");
367
368 if (fe->ops.i2c_gate_ctrl)
369 fe->ops.i2c_gate_ctrl(fe, 1);
370 dprintk("Calling tuner set parameters\n");
371 fe->ops.tuner_ops.set_params(fe);
372 319
373 /* 320 /* Does a binary search to get RF strength */
374 * Make it more reliable: if, for some reason, the initial 321 rf_max = 0xfff;
375 * device initialization doesn't happen, initialize it when 322 rf_min = 0;
376 * a SBTVD parameters are adjusted. 323 do {
377 * 324 rf = (rf_max + rf_min) / 2;
378 * Unfortunately, due to a hard to track bug at tda829x/tda18271, 325 rc = mb86a20s_writereg(state, 0x04, 0x1f);
379 * the agc callback logic is not called during DVB attach time, 326 if (rc < 0)
380 * causing mb86a20s to not be initialized with Kworld SBTVD. 327 return rc;
381 * So, this hack is needed, in order to make Kworld SBTVD to work. 328 rc = mb86a20s_writereg(state, 0x05, rf >> 8);
382 */ 329 if (rc < 0)
383 if (state->need_init) 330 return rc;
384 mb86a20s_initfe(fe); 331 rc = mb86a20s_writereg(state, 0x04, 0x20);
332 if (rc < 0)
333 return rc;
334 rc = mb86a20s_writereg(state, 0x04, rf);
335 if (rc < 0)
336 return rc;
385 337
386 if (fe->ops.i2c_gate_ctrl) 338 rc = mb86a20s_readreg(state, 0x02);
387 fe->ops.i2c_gate_ctrl(fe, 0); 339 if (rc < 0)
388 rc = mb86a20s_writeregdata(state, mb86a20s_reset_reception); 340 return rc;
389 if (fe->ops.i2c_gate_ctrl) 341 if (rc & 0x08)
390 fe->ops.i2c_gate_ctrl(fe, 1); 342 rf_min = (rf_max + rf_min) / 2;
343 else
344 rf_max = (rf_max + rf_min) / 2;
345 if (rf_max - rf_min < 4) {
346 rf = (rf_max + rf_min) / 2;
347
348 /* Rescale it from 2^12 (4096) to 2^16 */
349 rf <<= (16 - 12);
350 dev_dbg(&state->i2c->dev,
351 "%s: signal strength = %d (%d < RF=%d < %d)\n",
352 __func__, rf, rf_min, rf >> 4, rf_max);
353 return rf;
354 }
355 } while (1);
391 356
392 return rc; 357 return 0;
393} 358}
394 359
395static int mb86a20s_get_modulation(struct mb86a20s_state *state, 360static int mb86a20s_get_modulation(struct mb86a20s_state *state,
@@ -410,7 +375,7 @@ static int mb86a20s_get_modulation(struct mb86a20s_state *state,
410 rc = mb86a20s_readreg(state, 0x6e); 375 rc = mb86a20s_readreg(state, 0x6e);
411 if (rc < 0) 376 if (rc < 0)
412 return rc; 377 return rc;
413 switch ((rc & 0x70) >> 4) { 378 switch ((rc >> 4) & 0x07) {
414 case 0: 379 case 0:
415 return DQPSK; 380 return DQPSK;
416 case 1: 381 case 1:
@@ -443,7 +408,7 @@ static int mb86a20s_get_fec(struct mb86a20s_state *state,
443 rc = mb86a20s_readreg(state, 0x6e); 408 rc = mb86a20s_readreg(state, 0x6e);
444 if (rc < 0) 409 if (rc < 0)
445 return rc; 410 return rc;
446 switch (rc) { 411 switch ((rc >> 4) & 0x07) {
447 case 0: 412 case 0:
448 return FEC_1_2; 413 return FEC_1_2;
449 case 1: 414 case 1:
@@ -478,24 +443,38 @@ static int mb86a20s_get_interleaving(struct mb86a20s_state *state,
478 rc = mb86a20s_readreg(state, 0x6e); 443 rc = mb86a20s_readreg(state, 0x6e);
479 if (rc < 0) 444 if (rc < 0)
480 return rc; 445 return rc;
481 if (rc > 3) 446
482 return -EINVAL; /* Not used */ 447 switch ((rc >> 4) & 0x07) {
483 return rc; 448 case 1:
449 return GUARD_INTERVAL_1_4;
450 case 2:
451 return GUARD_INTERVAL_1_8;
452 case 3:
453 return GUARD_INTERVAL_1_16;
454 case 4:
455 return GUARD_INTERVAL_1_32;
456
457 default:
458 case 0:
459 return GUARD_INTERVAL_AUTO;
460 }
484} 461}
485 462
486static int mb86a20s_get_segment_count(struct mb86a20s_state *state, 463static int mb86a20s_get_segment_count(struct mb86a20s_state *state,
487 unsigned layer) 464 unsigned layer)
488{ 465{
489 int rc, count; 466 int rc, count;
490
491 static unsigned char reg[] = { 467 static unsigned char reg[] = {
492 [0] = 0x89, /* Layer A */ 468 [0] = 0x89, /* Layer A */
493 [1] = 0x8d, /* Layer B */ 469 [1] = 0x8d, /* Layer B */
494 [2] = 0x91, /* Layer C */ 470 [2] = 0x91, /* Layer C */
495 }; 471 };
496 472
473 dev_dbg(&state->i2c->dev, "%s called.\n", __func__);
474
497 if (layer >= ARRAY_SIZE(reg)) 475 if (layer >= ARRAY_SIZE(reg))
498 return -EINVAL; 476 return -EINVAL;
477
499 rc = mb86a20s_writereg(state, 0x6d, reg[layer]); 478 rc = mb86a20s_writereg(state, 0x6d, reg[layer]);
500 if (rc < 0) 479 if (rc < 0)
501 return rc; 480 return rc;
@@ -504,113 +483,1451 @@ static int mb86a20s_get_segment_count(struct mb86a20s_state *state,
504 return rc; 483 return rc;
505 count = (rc >> 4) & 0x0f; 484 count = (rc >> 4) & 0x0f;
506 485
486 dev_dbg(&state->i2c->dev, "%s: segments: %d.\n", __func__, count);
487
507 return count; 488 return count;
508} 489}
509 490
491static void mb86a20s_reset_frontend_cache(struct dvb_frontend *fe)
492{
493 struct mb86a20s_state *state = fe->demodulator_priv;
494 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
495
496 dev_dbg(&state->i2c->dev, "%s called.\n", __func__);
497
498 /* Fixed parameters */
499 c->delivery_system = SYS_ISDBT;
500 c->bandwidth_hz = 6000000;
501
502 /* Initialize values that will be later autodetected */
503 c->isdbt_layer_enabled = 0;
504 c->transmission_mode = TRANSMISSION_MODE_AUTO;
505 c->guard_interval = GUARD_INTERVAL_AUTO;
506 c->isdbt_sb_mode = 0;
507 c->isdbt_sb_segment_count = 0;
508}
509
510/*
511 * Estimates the bit rate using the per-segment bit rate given by
512 * ABNT/NBR 15601 spec (table 4).
513 */
514static u32 isdbt_rate[3][5][4] = {
515 { /* DQPSK/QPSK */
516 { 280850, 312060, 330420, 340430 }, /* 1/2 */
517 { 374470, 416080, 440560, 453910 }, /* 2/3 */
518 { 421280, 468090, 495630, 510650 }, /* 3/4 */
519 { 468090, 520100, 550700, 567390 }, /* 5/6 */
520 { 491500, 546110, 578230, 595760 }, /* 7/8 */
521 }, { /* QAM16 */
522 { 561710, 624130, 660840, 680870 }, /* 1/2 */
523 { 748950, 832170, 881120, 907820 }, /* 2/3 */
524 { 842570, 936190, 991260, 1021300 }, /* 3/4 */
525 { 936190, 1040210, 1101400, 1134780 }, /* 5/6 */
526 { 983000, 1092220, 1156470, 1191520 }, /* 7/8 */
527 }, { /* QAM64 */
528 { 842570, 936190, 991260, 1021300 }, /* 1/2 */
529 { 1123430, 1248260, 1321680, 1361740 }, /* 2/3 */
530 { 1263860, 1404290, 1486900, 1531950 }, /* 3/4 */
531 { 1404290, 1560320, 1652110, 1702170 }, /* 5/6 */
532 { 1474500, 1638340, 1734710, 1787280 }, /* 7/8 */
533 }
534};
535
536static void mb86a20s_layer_bitrate(struct dvb_frontend *fe, u32 layer,
537 u32 modulation, u32 fec, u32 interleaving,
538 u32 segment)
539{
540 struct mb86a20s_state *state = fe->demodulator_priv;
541 u32 rate;
542 int m, f, i;
543
544 /*
545 * If modulation/fec/interleaving is not detected, the default is
546 * to consider the lowest bit rate, to avoid taking too long time
547 * to get BER.
548 */
549 switch (modulation) {
550 case DQPSK:
551 case QPSK:
552 default:
553 m = 0;
554 break;
555 case QAM_16:
556 m = 1;
557 break;
558 case QAM_64:
559 m = 2;
560 break;
561 }
562
563 switch (fec) {
564 default:
565 case FEC_1_2:
566 case FEC_AUTO:
567 f = 0;
568 break;
569 case FEC_2_3:
570 f = 1;
571 break;
572 case FEC_3_4:
573 f = 2;
574 break;
575 case FEC_5_6:
576 f = 3;
577 break;
578 case FEC_7_8:
579 f = 4;
580 break;
581 }
582
583 switch (interleaving) {
584 default:
585 case GUARD_INTERVAL_1_4:
586 i = 0;
587 break;
588 case GUARD_INTERVAL_1_8:
589 i = 1;
590 break;
591 case GUARD_INTERVAL_1_16:
592 i = 2;
593 break;
594 case GUARD_INTERVAL_1_32:
595 i = 3;
596 break;
597 }
598
599 /* Samples BER at BER_SAMPLING_RATE seconds */
600 rate = isdbt_rate[m][f][i] * segment * BER_SAMPLING_RATE;
601
602 /* Avoids sampling too quickly or to overflow the register */
603 if (rate < 256)
604 rate = 256;
605 else if (rate > (1 << 24) - 1)
606 rate = (1 << 24) - 1;
607
608 dev_dbg(&state->i2c->dev,
609 "%s: layer %c bitrate: %d kbps; counter = %d (0x%06x)\n",
610 __func__, 'A' + layer, segment * isdbt_rate[m][f][i]/1000,
611 rate, rate);
612
613 state->estimated_rate[i] = rate;
614}
615
616
510static int mb86a20s_get_frontend(struct dvb_frontend *fe) 617static int mb86a20s_get_frontend(struct dvb_frontend *fe)
511{ 618{
512 struct mb86a20s_state *state = fe->demodulator_priv; 619 struct mb86a20s_state *state = fe->demodulator_priv;
513 struct dtv_frontend_properties *p = &fe->dtv_property_cache; 620 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
514 int i, rc; 621 int i, rc;
515 622
516 /* Fixed parameters */ 623 dev_dbg(&state->i2c->dev, "%s called.\n", __func__);
517 p->delivery_system = SYS_ISDBT;
518 p->bandwidth_hz = 6000000;
519 624
520 if (fe->ops.i2c_gate_ctrl) 625 /* Reset frontend cache to default values */
521 fe->ops.i2c_gate_ctrl(fe, 0); 626 mb86a20s_reset_frontend_cache(fe);
522 627
523 /* Check for partial reception */ 628 /* Check for partial reception */
524 rc = mb86a20s_writereg(state, 0x6d, 0x85); 629 rc = mb86a20s_writereg(state, 0x6d, 0x85);
525 if (rc >= 0) 630 if (rc < 0)
526 rc = mb86a20s_readreg(state, 0x6e); 631 return rc;
527 if (rc >= 0) 632 rc = mb86a20s_readreg(state, 0x6e);
528 p->isdbt_partial_reception = (rc & 0x10) ? 1 : 0; 633 if (rc < 0)
634 return rc;
635 c->isdbt_partial_reception = (rc & 0x10) ? 1 : 0;
529 636
530 /* Get per-layer data */ 637 /* Get per-layer data */
531 p->isdbt_layer_enabled = 0; 638
532 for (i = 0; i < 3; i++) { 639 for (i = 0; i < 3; i++) {
640 dev_dbg(&state->i2c->dev, "%s: getting data for layer %c.\n",
641 __func__, 'A' + i);
642
533 rc = mb86a20s_get_segment_count(state, i); 643 rc = mb86a20s_get_segment_count(state, i);
534 if (rc >= 0 && rc < 14) 644 if (rc < 0)
535 p->layer[i].segment_count = rc; 645 goto noperlayer_error;
536 if (rc == 0x0f) 646 if (rc >= 0 && rc < 14) {
647 c->layer[i].segment_count = rc;
648 } else {
649 c->layer[i].segment_count = 0;
650 state->estimated_rate[i] = 0;
537 continue; 651 continue;
538 p->isdbt_layer_enabled |= 1 << i; 652 }
653 c->isdbt_layer_enabled |= 1 << i;
539 rc = mb86a20s_get_modulation(state, i); 654 rc = mb86a20s_get_modulation(state, i);
540 if (rc >= 0) 655 if (rc < 0)
541 p->layer[i].modulation = rc; 656 goto noperlayer_error;
657 dev_dbg(&state->i2c->dev, "%s: modulation %d.\n",
658 __func__, rc);
659 c->layer[i].modulation = rc;
542 rc = mb86a20s_get_fec(state, i); 660 rc = mb86a20s_get_fec(state, i);
543 if (rc >= 0) 661 if (rc < 0)
544 p->layer[i].fec = rc; 662 goto noperlayer_error;
663 dev_dbg(&state->i2c->dev, "%s: FEC %d.\n",
664 __func__, rc);
665 c->layer[i].fec = rc;
545 rc = mb86a20s_get_interleaving(state, i); 666 rc = mb86a20s_get_interleaving(state, i);
546 if (rc >= 0) 667 if (rc < 0)
547 p->layer[i].interleaving = rc; 668 goto noperlayer_error;
669 dev_dbg(&state->i2c->dev, "%s: interleaving %d.\n",
670 __func__, rc);
671 c->layer[i].interleaving = rc;
672 mb86a20s_layer_bitrate(fe, i, c->layer[i].modulation,
673 c->layer[i].fec,
674 c->layer[i].interleaving,
675 c->layer[i].segment_count);
548 } 676 }
549 677
550 p->isdbt_sb_mode = 0;
551 rc = mb86a20s_writereg(state, 0x6d, 0x84); 678 rc = mb86a20s_writereg(state, 0x6d, 0x84);
552 if ((rc >= 0) && ((rc & 0x60) == 0x20)) { 679 if (rc < 0)
553 p->isdbt_sb_mode = 1; 680 return rc;
681 if ((rc & 0x60) == 0x20) {
682 c->isdbt_sb_mode = 1;
554 /* At least, one segment should exist */ 683 /* At least, one segment should exist */
555 if (!p->isdbt_sb_segment_count) 684 if (!c->isdbt_sb_segment_count)
556 p->isdbt_sb_segment_count = 1; 685 c->isdbt_sb_segment_count = 1;
557 } else 686 }
558 p->isdbt_sb_segment_count = 0;
559 687
560 /* Get transmission mode and guard interval */ 688 /* Get transmission mode and guard interval */
561 p->transmission_mode = TRANSMISSION_MODE_AUTO;
562 p->guard_interval = GUARD_INTERVAL_AUTO;
563 rc = mb86a20s_readreg(state, 0x07); 689 rc = mb86a20s_readreg(state, 0x07);
564 if (rc >= 0) { 690 if (rc < 0)
565 if ((rc & 0x60) == 0x20) { 691 return rc;
566 switch (rc & 0x0c >> 2) { 692 if ((rc & 0x60) == 0x20) {
567 case 0: 693 switch (rc & 0x0c >> 2) {
568 p->transmission_mode = TRANSMISSION_MODE_2K; 694 case 0:
569 break; 695 c->transmission_mode = TRANSMISSION_MODE_2K;
570 case 1: 696 break;
571 p->transmission_mode = TRANSMISSION_MODE_4K; 697 case 1:
572 break; 698 c->transmission_mode = TRANSMISSION_MODE_4K;
573 case 2: 699 break;
574 p->transmission_mode = TRANSMISSION_MODE_8K; 700 case 2:
575 break; 701 c->transmission_mode = TRANSMISSION_MODE_8K;
576 } 702 break;
703 }
704 }
705 if (!(rc & 0x10)) {
706 switch (rc & 0x3) {
707 case 0:
708 c->guard_interval = GUARD_INTERVAL_1_4;
709 break;
710 case 1:
711 c->guard_interval = GUARD_INTERVAL_1_8;
712 break;
713 case 2:
714 c->guard_interval = GUARD_INTERVAL_1_16;
715 break;
716 }
717 }
718 return 0;
719
720noperlayer_error:
721
722 /* per-layer info is incomplete; discard all per-layer */
723 c->isdbt_layer_enabled = 0;
724
725 return rc;
726}
727
728static int mb86a20s_reset_counters(struct dvb_frontend *fe)
729{
730 struct mb86a20s_state *state = fe->demodulator_priv;
731 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
732 int rc, val;
733
734 dev_dbg(&state->i2c->dev, "%s called.\n", __func__);
735
736 /* Reset the counters, if the channel changed */
737 if (state->last_frequency != c->frequency) {
738 memset(&c->strength, 0, sizeof(c->strength));
739 memset(&c->cnr, 0, sizeof(c->cnr));
740 memset(&c->pre_bit_error, 0, sizeof(c->pre_bit_error));
741 memset(&c->pre_bit_count, 0, sizeof(c->pre_bit_count));
742 memset(&c->post_bit_error, 0, sizeof(c->post_bit_error));
743 memset(&c->post_bit_count, 0, sizeof(c->post_bit_count));
744 memset(&c->block_error, 0, sizeof(c->block_error));
745 memset(&c->block_count, 0, sizeof(c->block_count));
746
747 state->last_frequency = c->frequency;
748 }
749
750 /* Clear status for most stats */
751
752 /* BER/PER counter reset */
753 rc = mb86a20s_writeregdata(state, mb86a20s_per_ber_reset);
754 if (rc < 0)
755 goto err;
756
757 /* CNR counter reset */
758 rc = mb86a20s_readreg(state, 0x45);
759 if (rc < 0)
760 goto err;
761 val = rc;
762 rc = mb86a20s_writereg(state, 0x45, val | 0x10);
763 if (rc < 0)
764 goto err;
765 rc = mb86a20s_writereg(state, 0x45, val & 0x6f);
766 if (rc < 0)
767 goto err;
768
769 /* MER counter reset */
770 rc = mb86a20s_writereg(state, 0x50, 0x50);
771 if (rc < 0)
772 goto err;
773 rc = mb86a20s_readreg(state, 0x51);
774 if (rc < 0)
775 goto err;
776 val = rc;
777 rc = mb86a20s_writereg(state, 0x51, val | 0x01);
778 if (rc < 0)
779 goto err;
780 rc = mb86a20s_writereg(state, 0x51, val & 0x06);
781 if (rc < 0)
782 goto err;
783
784 goto ok;
785err:
786 dev_err(&state->i2c->dev,
787 "%s: Can't reset FE statistics (error %d).\n",
788 __func__, rc);
789ok:
790 return rc;
791}
792
793static int mb86a20s_get_pre_ber(struct dvb_frontend *fe,
794 unsigned layer,
795 u32 *error, u32 *count)
796{
797 struct mb86a20s_state *state = fe->demodulator_priv;
798 int rc, val;
799
800 dev_dbg(&state->i2c->dev, "%s called.\n", __func__);
801
802 if (layer >= 3)
803 return -EINVAL;
804
805 /* Check if the BER measures are already available */
806 rc = mb86a20s_readreg(state, 0x54);
807 if (rc < 0)
808 return rc;
809
810 /* Check if data is available for that layer */
811 if (!(rc & (1 << layer))) {
812 dev_dbg(&state->i2c->dev,
813 "%s: preBER for layer %c is not available yet.\n",
814 __func__, 'A' + layer);
815 return -EBUSY;
816 }
817
818 /* Read Bit Error Count */
819 rc = mb86a20s_readreg(state, 0x55 + layer * 3);
820 if (rc < 0)
821 return rc;
822 *error = rc << 16;
823 rc = mb86a20s_readreg(state, 0x56 + layer * 3);
824 if (rc < 0)
825 return rc;
826 *error |= rc << 8;
827 rc = mb86a20s_readreg(state, 0x57 + layer * 3);
828 if (rc < 0)
829 return rc;
830 *error |= rc;
831
832 dev_dbg(&state->i2c->dev,
833 "%s: bit error before Viterbi for layer %c: %d.\n",
834 __func__, 'A' + layer, *error);
835
836 /* Read Bit Count */
837 rc = mb86a20s_writereg(state, 0x50, 0xa7 + layer * 3);
838 if (rc < 0)
839 return rc;
840 rc = mb86a20s_readreg(state, 0x51);
841 if (rc < 0)
842 return rc;
843 *count = rc << 16;
844 rc = mb86a20s_writereg(state, 0x50, 0xa8 + layer * 3);
845 if (rc < 0)
846 return rc;
847 rc = mb86a20s_readreg(state, 0x51);
848 if (rc < 0)
849 return rc;
850 *count |= rc << 8;
851 rc = mb86a20s_writereg(state, 0x50, 0xa9 + layer * 3);
852 if (rc < 0)
853 return rc;
854 rc = mb86a20s_readreg(state, 0x51);
855 if (rc < 0)
856 return rc;
857 *count |= rc;
858
859 dev_dbg(&state->i2c->dev,
860 "%s: bit count before Viterbi for layer %c: %d.\n",
861 __func__, 'A' + layer, *count);
862
863
864 /*
865 * As we get TMCC data from the frontend, we can better estimate the
866 * BER bit counters, in order to do the BER measure during a longer
867 * time. Use those data, if available, to update the bit count
868 * measure.
869 */
870
871 if (state->estimated_rate[layer]
872 && state->estimated_rate[layer] != *count) {
873 dev_dbg(&state->i2c->dev,
874 "%s: updating layer %c preBER counter to %d.\n",
875 __func__, 'A' + layer, state->estimated_rate[layer]);
876
877 /* Turn off BER before Viterbi */
878 rc = mb86a20s_writereg(state, 0x52, 0x00);
879
880 /* Update counter for this layer */
881 rc = mb86a20s_writereg(state, 0x50, 0xa7 + layer * 3);
882 if (rc < 0)
883 return rc;
884 rc = mb86a20s_writereg(state, 0x51,
885 state->estimated_rate[layer] >> 16);
886 if (rc < 0)
887 return rc;
888 rc = mb86a20s_writereg(state, 0x50, 0xa8 + layer * 3);
889 if (rc < 0)
890 return rc;
891 rc = mb86a20s_writereg(state, 0x51,
892 state->estimated_rate[layer] >> 8);
893 if (rc < 0)
894 return rc;
895 rc = mb86a20s_writereg(state, 0x50, 0xa9 + layer * 3);
896 if (rc < 0)
897 return rc;
898 rc = mb86a20s_writereg(state, 0x51,
899 state->estimated_rate[layer]);
900 if (rc < 0)
901 return rc;
902
903 /* Turn on BER before Viterbi */
904 rc = mb86a20s_writereg(state, 0x52, 0x01);
905
906 /* Reset all preBER counters */
907 rc = mb86a20s_writereg(state, 0x53, 0x00);
908 if (rc < 0)
909 return rc;
910 rc = mb86a20s_writereg(state, 0x53, 0x07);
911 } else {
912 /* Reset counter to collect new data */
913 rc = mb86a20s_readreg(state, 0x53);
914 if (rc < 0)
915 return rc;
916 val = rc;
917 rc = mb86a20s_writereg(state, 0x53, val & ~(1 << layer));
918 if (rc < 0)
919 return rc;
920 rc = mb86a20s_writereg(state, 0x53, val | (1 << layer));
921 }
922
923 return rc;
924}
925
926static int mb86a20s_get_post_ber(struct dvb_frontend *fe,
927 unsigned layer,
928 u32 *error, u32 *count)
929{
930 struct mb86a20s_state *state = fe->demodulator_priv;
931 u32 counter, collect_rate;
932 int rc, val;
933
934 dev_dbg(&state->i2c->dev, "%s called.\n", __func__);
935
936 if (layer >= 3)
937 return -EINVAL;
938
939 /* Check if the BER measures are already available */
940 rc = mb86a20s_readreg(state, 0x60);
941 if (rc < 0)
942 return rc;
943
944 /* Check if data is available for that layer */
945 if (!(rc & (1 << layer))) {
946 dev_dbg(&state->i2c->dev,
947 "%s: post BER for layer %c is not available yet.\n",
948 __func__, 'A' + layer);
949 return -EBUSY;
950 }
951
952 /* Read Bit Error Count */
953 rc = mb86a20s_readreg(state, 0x64 + layer * 3);
954 if (rc < 0)
955 return rc;
956 *error = rc << 16;
957 rc = mb86a20s_readreg(state, 0x65 + layer * 3);
958 if (rc < 0)
959 return rc;
960 *error |= rc << 8;
961 rc = mb86a20s_readreg(state, 0x66 + layer * 3);
962 if (rc < 0)
963 return rc;
964 *error |= rc;
965
966 dev_dbg(&state->i2c->dev,
967 "%s: post bit error for layer %c: %d.\n",
968 __func__, 'A' + layer, *error);
969
970 /* Read Bit Count */
971 rc = mb86a20s_writereg(state, 0x50, 0xdc + layer * 2);
972 if (rc < 0)
973 return rc;
974 rc = mb86a20s_readreg(state, 0x51);
975 if (rc < 0)
976 return rc;
977 counter = rc << 8;
978 rc = mb86a20s_writereg(state, 0x50, 0xdd + layer * 2);
979 if (rc < 0)
980 return rc;
981 rc = mb86a20s_readreg(state, 0x51);
982 if (rc < 0)
983 return rc;
984 counter |= rc;
985 *count = counter * 204 * 8;
986
987 dev_dbg(&state->i2c->dev,
988 "%s: post bit count for layer %c: %d.\n",
989 __func__, 'A' + layer, *count);
990
991 /*
992 * As we get TMCC data from the frontend, we can better estimate the
993 * BER bit counters, in order to do the BER measure during a longer
994 * time. Use those data, if available, to update the bit count
995 * measure.
996 */
997
998 if (!state->estimated_rate[layer])
999 goto reset_measurement;
1000
1001 collect_rate = state->estimated_rate[layer] / 204 / 8;
1002 if (collect_rate < 32)
1003 collect_rate = 32;
1004 if (collect_rate > 65535)
1005 collect_rate = 65535;
1006 if (collect_rate != counter) {
1007 dev_dbg(&state->i2c->dev,
1008 "%s: updating postBER counter on layer %c to %d.\n",
1009 __func__, 'A' + layer, collect_rate);
1010
1011 /* Turn off BER after Viterbi */
1012 rc = mb86a20s_writereg(state, 0x5e, 0x00);
1013
1014 /* Update counter for this layer */
1015 rc = mb86a20s_writereg(state, 0x50, 0xdc + layer * 2);
1016 if (rc < 0)
1017 return rc;
1018 rc = mb86a20s_writereg(state, 0x51, collect_rate >> 8);
1019 if (rc < 0)
1020 return rc;
1021 rc = mb86a20s_writereg(state, 0x50, 0xdd + layer * 2);
1022 if (rc < 0)
1023 return rc;
1024 rc = mb86a20s_writereg(state, 0x51, collect_rate & 0xff);
1025 if (rc < 0)
1026 return rc;
1027
1028 /* Turn on BER after Viterbi */
1029 rc = mb86a20s_writereg(state, 0x5e, 0x07);
1030
1031 /* Reset all preBER counters */
1032 rc = mb86a20s_writereg(state, 0x5f, 0x00);
1033 if (rc < 0)
1034 return rc;
1035 rc = mb86a20s_writereg(state, 0x5f, 0x07);
1036
1037 return rc;
1038 }
1039
1040reset_measurement:
1041 /* Reset counter to collect new data */
1042 rc = mb86a20s_readreg(state, 0x5f);
1043 if (rc < 0)
1044 return rc;
1045 val = rc;
1046 rc = mb86a20s_writereg(state, 0x5f, val & ~(1 << layer));
1047 if (rc < 0)
1048 return rc;
1049 rc = mb86a20s_writereg(state, 0x5f, val | (1 << layer));
1050
1051 return rc;
1052}
1053
1054static int mb86a20s_get_blk_error(struct dvb_frontend *fe,
1055 unsigned layer,
1056 u32 *error, u32 *count)
1057{
1058 struct mb86a20s_state *state = fe->demodulator_priv;
1059 int rc, val;
1060 u32 collect_rate;
1061 dev_dbg(&state->i2c->dev, "%s called.\n", __func__);
1062
1063 if (layer >= 3)
1064 return -EINVAL;
1065
1066 /* Check if the PER measures are already available */
1067 rc = mb86a20s_writereg(state, 0x50, 0xb8);
1068 if (rc < 0)
1069 return rc;
1070 rc = mb86a20s_readreg(state, 0x51);
1071 if (rc < 0)
1072 return rc;
1073
1074 /* Check if data is available for that layer */
1075
1076 if (!(rc & (1 << layer))) {
1077 dev_dbg(&state->i2c->dev,
1078 "%s: block counts for layer %c aren't available yet.\n",
1079 __func__, 'A' + layer);
1080 return -EBUSY;
1081 }
1082
1083 /* Read Packet error Count */
1084 rc = mb86a20s_writereg(state, 0x50, 0xb9 + layer * 2);
1085 if (rc < 0)
1086 return rc;
1087 rc = mb86a20s_readreg(state, 0x51);
1088 if (rc < 0)
1089 return rc;
1090 *error = rc << 8;
1091 rc = mb86a20s_writereg(state, 0x50, 0xba + layer * 2);
1092 if (rc < 0)
1093 return rc;
1094 rc = mb86a20s_readreg(state, 0x51);
1095 if (rc < 0)
1096 return rc;
1097 *error |= rc;
1098 dev_err(&state->i2c->dev, "%s: block error for layer %c: %d.\n",
1099 __func__, 'A' + layer, *error);
1100
1101 /* Read Bit Count */
1102 rc = mb86a20s_writereg(state, 0x50, 0xb2 + layer * 2);
1103 if (rc < 0)
1104 return rc;
1105 rc = mb86a20s_readreg(state, 0x51);
1106 if (rc < 0)
1107 return rc;
1108 *count = rc << 8;
1109 rc = mb86a20s_writereg(state, 0x50, 0xb3 + layer * 2);
1110 if (rc < 0)
1111 return rc;
1112 rc = mb86a20s_readreg(state, 0x51);
1113 if (rc < 0)
1114 return rc;
1115 *count |= rc;
1116
1117 dev_dbg(&state->i2c->dev,
1118 "%s: block count for layer %c: %d.\n",
1119 __func__, 'A' + layer, *count);
1120
1121 /*
1122 * As we get TMCC data from the frontend, we can better estimate the
1123 * BER bit counters, in order to do the BER measure during a longer
1124 * time. Use those data, if available, to update the bit count
1125 * measure.
1126 */
1127
1128 if (!state->estimated_rate[layer])
1129 goto reset_measurement;
1130
1131 collect_rate = state->estimated_rate[layer] / 204 / 8;
1132 if (collect_rate < 32)
1133 collect_rate = 32;
1134 if (collect_rate > 65535)
1135 collect_rate = 65535;
1136
1137 if (collect_rate != *count) {
1138 dev_dbg(&state->i2c->dev,
1139 "%s: updating PER counter on layer %c to %d.\n",
1140 __func__, 'A' + layer, collect_rate);
1141
1142 /* Stop PER measurement */
1143 rc = mb86a20s_writereg(state, 0x50, 0xb0);
1144 if (rc < 0)
1145 return rc;
1146 rc = mb86a20s_writereg(state, 0x51, 0x00);
1147 if (rc < 0)
1148 return rc;
1149
1150 /* Update this layer's counter */
1151 rc = mb86a20s_writereg(state, 0x50, 0xb2 + layer * 2);
1152 if (rc < 0)
1153 return rc;
1154 rc = mb86a20s_writereg(state, 0x51, collect_rate >> 8);
1155 if (rc < 0)
1156 return rc;
1157 rc = mb86a20s_writereg(state, 0x50, 0xb3 + layer * 2);
1158 if (rc < 0)
1159 return rc;
1160 rc = mb86a20s_writereg(state, 0x51, collect_rate & 0xff);
1161 if (rc < 0)
1162 return rc;
1163
1164 /* start PER measurement */
1165 rc = mb86a20s_writereg(state, 0x50, 0xb0);
1166 if (rc < 0)
1167 return rc;
1168 rc = mb86a20s_writereg(state, 0x51, 0x07);
1169 if (rc < 0)
1170 return rc;
1171
1172 /* Reset all counters to collect new data */
1173 rc = mb86a20s_writereg(state, 0x50, 0xb1);
1174 if (rc < 0)
1175 return rc;
1176 rc = mb86a20s_writereg(state, 0x51, 0x07);
1177 if (rc < 0)
1178 return rc;
1179 rc = mb86a20s_writereg(state, 0x51, 0x00);
1180
1181 return rc;
1182 }
1183
1184reset_measurement:
1185 /* Reset counter to collect new data */
1186 rc = mb86a20s_writereg(state, 0x50, 0xb1);
1187 if (rc < 0)
1188 return rc;
1189 rc = mb86a20s_readreg(state, 0x51);
1190 if (rc < 0)
1191 return rc;
1192 val = rc;
1193 rc = mb86a20s_writereg(state, 0x51, val | (1 << layer));
1194 if (rc < 0)
1195 return rc;
1196 rc = mb86a20s_writereg(state, 0x51, val & ~(1 << layer));
1197
1198 return rc;
1199}
1200
1201struct linear_segments {
1202 unsigned x, y;
1203};
1204
1205/*
1206 * All tables below return a dB/1000 measurement
1207 */
1208
1209static struct linear_segments cnr_to_db_table[] = {
1210 { 19648, 0},
1211 { 18187, 1000},
1212 { 16534, 2000},
1213 { 14823, 3000},
1214 { 13161, 4000},
1215 { 11622, 5000},
1216 { 10279, 6000},
1217 { 9089, 7000},
1218 { 8042, 8000},
1219 { 7137, 9000},
1220 { 6342, 10000},
1221 { 5641, 11000},
1222 { 5030, 12000},
1223 { 4474, 13000},
1224 { 3988, 14000},
1225 { 3556, 15000},
1226 { 3180, 16000},
1227 { 2841, 17000},
1228 { 2541, 18000},
1229 { 2276, 19000},
1230 { 2038, 20000},
1231 { 1800, 21000},
1232 { 1625, 22000},
1233 { 1462, 23000},
1234 { 1324, 24000},
1235 { 1175, 25000},
1236 { 1063, 26000},
1237 { 980, 27000},
1238 { 907, 28000},
1239 { 840, 29000},
1240 { 788, 30000},
1241};
1242
1243static struct linear_segments cnr_64qam_table[] = {
1244 { 3922688, 0},
1245 { 3920384, 1000},
1246 { 3902720, 2000},
1247 { 3894784, 3000},
1248 { 3882496, 4000},
1249 { 3872768, 5000},
1250 { 3858944, 6000},
1251 { 3851520, 7000},
1252 { 3838976, 8000},
1253 { 3829248, 9000},
1254 { 3818240, 10000},
1255 { 3806976, 11000},
1256 { 3791872, 12000},
1257 { 3767040, 13000},
1258 { 3720960, 14000},
1259 { 3637504, 15000},
1260 { 3498496, 16000},
1261 { 3296000, 17000},
1262 { 3031040, 18000},
1263 { 2715392, 19000},
1264 { 2362624, 20000},
1265 { 1963264, 21000},
1266 { 1649664, 22000},
1267 { 1366784, 23000},
1268 { 1120768, 24000},
1269 { 890880, 25000},
1270 { 723456, 26000},
1271 { 612096, 27000},
1272 { 518912, 28000},
1273 { 448256, 29000},
1274 { 388864, 30000},
1275};
1276
1277static struct linear_segments cnr_16qam_table[] = {
1278 { 5314816, 0},
1279 { 5219072, 1000},
1280 { 5118720, 2000},
1281 { 4998912, 3000},
1282 { 4875520, 4000},
1283 { 4736000, 5000},
1284 { 4604160, 6000},
1285 { 4458752, 7000},
1286 { 4300288, 8000},
1287 { 4092928, 9000},
1288 { 3836160, 10000},
1289 { 3521024, 11000},
1290 { 3155968, 12000},
1291 { 2756864, 13000},
1292 { 2347008, 14000},
1293 { 1955072, 15000},
1294 { 1593600, 16000},
1295 { 1297920, 17000},
1296 { 1043968, 18000},
1297 { 839680, 19000},
1298 { 672256, 20000},
1299 { 523008, 21000},
1300 { 424704, 22000},
1301 { 345088, 23000},
1302 { 280064, 24000},
1303 { 221440, 25000},
1304 { 179712, 26000},
1305 { 151040, 27000},
1306 { 128512, 28000},
1307 { 110080, 29000},
1308 { 95744, 30000},
1309};
1310
1311struct linear_segments cnr_qpsk_table[] = {
1312 { 2834176, 0},
1313 { 2683648, 1000},
1314 { 2536960, 2000},
1315 { 2391808, 3000},
1316 { 2133248, 4000},
1317 { 1906176, 5000},
1318 { 1666560, 6000},
1319 { 1422080, 7000},
1320 { 1189632, 8000},
1321 { 976384, 9000},
1322 { 790272, 10000},
1323 { 633344, 11000},
1324 { 505600, 12000},
1325 { 402944, 13000},
1326 { 320768, 14000},
1327 { 255488, 15000},
1328 { 204032, 16000},
1329 { 163072, 17000},
1330 { 130304, 18000},
1331 { 105216, 19000},
1332 { 83456, 20000},
1333 { 65024, 21000},
1334 { 52480, 22000},
1335 { 42752, 23000},
1336 { 34560, 24000},
1337 { 27136, 25000},
1338 { 22016, 26000},
1339 { 18432, 27000},
1340 { 15616, 28000},
1341 { 13312, 29000},
1342 { 11520, 30000},
1343};
1344
1345static u32 interpolate_value(u32 value, struct linear_segments *segments,
1346 unsigned len)
1347{
1348 u64 tmp64;
1349 u32 dx, dy;
1350 int i, ret;
1351
1352 if (value >= segments[0].x)
1353 return segments[0].y;
1354 if (value < segments[len-1].x)
1355 return segments[len-1].y;
1356
1357 for (i = 1; i < len - 1; i++) {
1358 /* If value is identical, no need to interpolate */
1359 if (value == segments[i].x)
1360 return segments[i].y;
1361 if (value > segments[i].x)
1362 break;
1363 }
1364
1365 /* Linear interpolation between the two (x,y) points */
1366 dy = segments[i].y - segments[i - 1].y;
1367 dx = segments[i - 1].x - segments[i].x;
1368 tmp64 = value - segments[i].x;
1369 tmp64 *= dy;
1370 do_div(tmp64, dx);
1371 ret = segments[i].y - tmp64;
1372
1373 return ret;
1374}
1375
1376static int mb86a20s_get_main_CNR(struct dvb_frontend *fe)
1377{
1378 struct mb86a20s_state *state = fe->demodulator_priv;
1379 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1380 u32 cnr_linear, cnr;
1381 int rc, val;
1382
1383 /* Check if CNR is available */
1384 rc = mb86a20s_readreg(state, 0x45);
1385 if (rc < 0)
1386 return rc;
1387
1388 if (!(rc & 0x40)) {
1389 dev_info(&state->i2c->dev, "%s: CNR is not available yet.\n",
1390 __func__);
1391 return -EBUSY;
1392 }
1393 val = rc;
1394
1395 rc = mb86a20s_readreg(state, 0x46);
1396 if (rc < 0)
1397 return rc;
1398 cnr_linear = rc << 8;
1399
1400 rc = mb86a20s_readreg(state, 0x46);
1401 if (rc < 0)
1402 return rc;
1403 cnr_linear |= rc;
1404
1405 cnr = interpolate_value(cnr_linear,
1406 cnr_to_db_table, ARRAY_SIZE(cnr_to_db_table));
1407
1408 c->cnr.stat[0].scale = FE_SCALE_DECIBEL;
1409 c->cnr.stat[0].svalue = cnr;
1410
1411 dev_dbg(&state->i2c->dev, "%s: CNR is %d.%03d dB (%d)\n",
1412 __func__, cnr / 1000, cnr % 1000, cnr_linear);
1413
1414 /* CNR counter reset */
1415 rc = mb86a20s_writereg(state, 0x45, val | 0x10);
1416 if (rc < 0)
1417 return rc;
1418 rc = mb86a20s_writereg(state, 0x45, val & 0x6f);
1419
1420 return rc;
1421}
1422
1423static int mb86a20s_get_blk_error_layer_CNR(struct dvb_frontend *fe)
1424{
1425 struct mb86a20s_state *state = fe->demodulator_priv;
1426 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1427 u32 mer, cnr;
1428 int rc, val, i;
1429 struct linear_segments *segs;
1430 unsigned segs_len;
1431
1432 dev_dbg(&state->i2c->dev, "%s called.\n", __func__);
1433
1434 /* Check if the measures are already available */
1435 rc = mb86a20s_writereg(state, 0x50, 0x5b);
1436 if (rc < 0)
1437 return rc;
1438 rc = mb86a20s_readreg(state, 0x51);
1439 if (rc < 0)
1440 return rc;
1441
1442 /* Check if data is available */
1443 if (!(rc & 0x01)) {
1444 dev_info(&state->i2c->dev,
1445 "%s: MER measures aren't available yet.\n", __func__);
1446 return -EBUSY;
1447 }
1448
1449 /* Read all layers */
1450 for (i = 0; i < 3; i++) {
1451 if (!(c->isdbt_layer_enabled & (1 << i))) {
1452 c->cnr.stat[1 + i].scale = FE_SCALE_NOT_AVAILABLE;
1453 continue;
1454 }
1455
1456 rc = mb86a20s_writereg(state, 0x50, 0x52 + i * 3);
1457 if (rc < 0)
1458 return rc;
1459 rc = mb86a20s_readreg(state, 0x51);
1460 if (rc < 0)
1461 return rc;
1462 mer = rc << 16;
1463 rc = mb86a20s_writereg(state, 0x50, 0x53 + i * 3);
1464 if (rc < 0)
1465 return rc;
1466 rc = mb86a20s_readreg(state, 0x51);
1467 if (rc < 0)
1468 return rc;
1469 mer |= rc << 8;
1470 rc = mb86a20s_writereg(state, 0x50, 0x54 + i * 3);
1471 if (rc < 0)
1472 return rc;
1473 rc = mb86a20s_readreg(state, 0x51);
1474 if (rc < 0)
1475 return rc;
1476 mer |= rc;
1477
1478 switch (c->layer[i].modulation) {
1479 case DQPSK:
1480 case QPSK:
1481 segs = cnr_qpsk_table;
1482 segs_len = ARRAY_SIZE(cnr_qpsk_table);
1483 break;
1484 case QAM_16:
1485 segs = cnr_16qam_table;
1486 segs_len = ARRAY_SIZE(cnr_16qam_table);
1487 break;
1488 default:
1489 case QAM_64:
1490 segs = cnr_64qam_table;
1491 segs_len = ARRAY_SIZE(cnr_64qam_table);
1492 break;
577 } 1493 }
578 if (!(rc & 0x10)) { 1494 cnr = interpolate_value(mer, segs, segs_len);
579 switch (rc & 0x3) { 1495
580 case 0: 1496 c->cnr.stat[1 + i].scale = FE_SCALE_DECIBEL;
581 p->guard_interval = GUARD_INTERVAL_1_4; 1497 c->cnr.stat[1 + i].svalue = cnr;
582 break; 1498
583 case 1: 1499 dev_dbg(&state->i2c->dev,
584 p->guard_interval = GUARD_INTERVAL_1_8; 1500 "%s: CNR for layer %c is %d.%03d dB (MER = %d).\n",
585 break; 1501 __func__, 'A' + i, cnr / 1000, cnr % 1000, mer);
586 case 2: 1502
587 p->guard_interval = GUARD_INTERVAL_1_16; 1503 }
588 break; 1504
1505 /* Start a new MER measurement */
1506 /* MER counter reset */
1507 rc = mb86a20s_writereg(state, 0x50, 0x50);
1508 if (rc < 0)
1509 return rc;
1510 rc = mb86a20s_readreg(state, 0x51);
1511 if (rc < 0)
1512 return rc;
1513 val = rc;
1514
1515 rc = mb86a20s_writereg(state, 0x51, val | 0x01);
1516 if (rc < 0)
1517 return rc;
1518 rc = mb86a20s_writereg(state, 0x51, val & 0x06);
1519 if (rc < 0)
1520 return rc;
1521
1522 return 0;
1523}
1524
1525static void mb86a20s_stats_not_ready(struct dvb_frontend *fe)
1526{
1527 struct mb86a20s_state *state = fe->demodulator_priv;
1528 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1529 int i;
1530
1531 dev_dbg(&state->i2c->dev, "%s called.\n", __func__);
1532
1533 /* Fill the length of each status counter */
1534
1535 /* Only global stats */
1536 c->strength.len = 1;
1537
1538 /* Per-layer stats - 3 layers + global */
1539 c->cnr.len = 4;
1540 c->pre_bit_error.len = 4;
1541 c->pre_bit_count.len = 4;
1542 c->post_bit_error.len = 4;
1543 c->post_bit_count.len = 4;
1544 c->block_error.len = 4;
1545 c->block_count.len = 4;
1546
1547 /* Signal is always available */
1548 c->strength.stat[0].scale = FE_SCALE_RELATIVE;
1549 c->strength.stat[0].uvalue = 0;
1550
1551 /* Put all of them at FE_SCALE_NOT_AVAILABLE */
1552 for (i = 0; i < 4; i++) {
1553 c->cnr.stat[i].scale = FE_SCALE_NOT_AVAILABLE;
1554 c->pre_bit_error.stat[i].scale = FE_SCALE_NOT_AVAILABLE;
1555 c->pre_bit_count.stat[i].scale = FE_SCALE_NOT_AVAILABLE;
1556 c->post_bit_error.stat[i].scale = FE_SCALE_NOT_AVAILABLE;
1557 c->post_bit_count.stat[i].scale = FE_SCALE_NOT_AVAILABLE;
1558 c->block_error.stat[i].scale = FE_SCALE_NOT_AVAILABLE;
1559 c->block_count.stat[i].scale = FE_SCALE_NOT_AVAILABLE;
1560 }
1561}
1562
1563static int mb86a20s_get_stats(struct dvb_frontend *fe)
1564{
1565 struct mb86a20s_state *state = fe->demodulator_priv;
1566 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1567 int rc = 0, i;
1568 u32 bit_error = 0, bit_count = 0;
1569 u32 t_pre_bit_error = 0, t_pre_bit_count = 0;
1570 u32 t_post_bit_error = 0, t_post_bit_count = 0;
1571 u32 block_error = 0, block_count = 0;
1572 u32 t_block_error = 0, t_block_count = 0;
1573 int active_layers = 0, pre_ber_layers = 0, post_ber_layers = 0;
1574 int per_layers = 0;
1575
1576 dev_dbg(&state->i2c->dev, "%s called.\n", __func__);
1577
1578 mb86a20s_get_main_CNR(fe);
1579
1580 /* Get per-layer stats */
1581 mb86a20s_get_blk_error_layer_CNR(fe);
1582
1583 for (i = 0; i < 3; i++) {
1584 if (c->isdbt_layer_enabled & (1 << i)) {
1585 /* Layer is active and has rc segments */
1586 active_layers++;
1587
1588 /* Handle BER before vterbi */
1589 rc = mb86a20s_get_pre_ber(fe, i,
1590 &bit_error, &bit_count);
1591 if (rc >= 0) {
1592 c->pre_bit_error.stat[1 + i].scale = FE_SCALE_COUNTER;
1593 c->pre_bit_error.stat[1 + i].uvalue += bit_error;
1594 c->pre_bit_count.stat[1 + i].scale = FE_SCALE_COUNTER;
1595 c->pre_bit_count.stat[1 + i].uvalue += bit_count;
1596 } else if (rc != -EBUSY) {
1597 /*
1598 * If an I/O error happened,
1599 * measures are now unavailable
1600 */
1601 c->pre_bit_error.stat[1 + i].scale = FE_SCALE_NOT_AVAILABLE;
1602 c->pre_bit_count.stat[1 + i].scale = FE_SCALE_NOT_AVAILABLE;
1603 dev_err(&state->i2c->dev,
1604 "%s: Can't get BER for layer %c (error %d).\n",
1605 __func__, 'A' + i, rc);
589 } 1606 }
1607 if (c->block_error.stat[1 + i].scale != FE_SCALE_NOT_AVAILABLE)
1608 pre_ber_layers++;
1609
1610 /* Handle BER post vterbi */
1611 rc = mb86a20s_get_post_ber(fe, i,
1612 &bit_error, &bit_count);
1613 if (rc >= 0) {
1614 c->post_bit_error.stat[1 + i].scale = FE_SCALE_COUNTER;
1615 c->post_bit_error.stat[1 + i].uvalue += bit_error;
1616 c->post_bit_count.stat[1 + i].scale = FE_SCALE_COUNTER;
1617 c->post_bit_count.stat[1 + i].uvalue += bit_count;
1618 } else if (rc != -EBUSY) {
1619 /*
1620 * If an I/O error happened,
1621 * measures are now unavailable
1622 */
1623 c->post_bit_error.stat[1 + i].scale = FE_SCALE_NOT_AVAILABLE;
1624 c->post_bit_count.stat[1 + i].scale = FE_SCALE_NOT_AVAILABLE;
1625 dev_err(&state->i2c->dev,
1626 "%s: Can't get BER for layer %c (error %d).\n",
1627 __func__, 'A' + i, rc);
1628 }
1629 if (c->block_error.stat[1 + i].scale != FE_SCALE_NOT_AVAILABLE)
1630 post_ber_layers++;
1631
1632 /* Handle Block errors for PER/UCB reports */
1633 rc = mb86a20s_get_blk_error(fe, i,
1634 &block_error,
1635 &block_count);
1636 if (rc >= 0) {
1637 c->block_error.stat[1 + i].scale = FE_SCALE_COUNTER;
1638 c->block_error.stat[1 + i].uvalue += block_error;
1639 c->block_count.stat[1 + i].scale = FE_SCALE_COUNTER;
1640 c->block_count.stat[1 + i].uvalue += block_count;
1641 } else if (rc != -EBUSY) {
1642 /*
1643 * If an I/O error happened,
1644 * measures are now unavailable
1645 */
1646 c->block_error.stat[1 + i].scale = FE_SCALE_NOT_AVAILABLE;
1647 c->block_count.stat[1 + i].scale = FE_SCALE_NOT_AVAILABLE;
1648 dev_err(&state->i2c->dev,
1649 "%s: Can't get PER for layer %c (error %d).\n",
1650 __func__, 'A' + i, rc);
1651
1652 }
1653 if (c->block_error.stat[1 + i].scale != FE_SCALE_NOT_AVAILABLE)
1654 per_layers++;
1655
1656 /* Update total preBER */
1657 t_pre_bit_error += c->pre_bit_error.stat[1 + i].uvalue;
1658 t_pre_bit_count += c->pre_bit_count.stat[1 + i].uvalue;
1659
1660 /* Update total postBER */
1661 t_post_bit_error += c->post_bit_error.stat[1 + i].uvalue;
1662 t_post_bit_count += c->post_bit_count.stat[1 + i].uvalue;
1663
1664 /* Update total PER */
1665 t_block_error += c->block_error.stat[1 + i].uvalue;
1666 t_block_count += c->block_count.stat[1 + i].uvalue;
590 } 1667 }
591 } 1668 }
592 1669
1670 /*
1671 * Start showing global count if at least one error count is
1672 * available.
1673 */
1674 if (pre_ber_layers) {
1675 /*
1676 * At least one per-layer BER measure was read. We can now
1677 * calculate the total BER
1678 *
1679 * Total Bit Error/Count is calculated as the sum of the
1680 * bit errors on all active layers.
1681 */
1682 c->pre_bit_error.stat[0].scale = FE_SCALE_COUNTER;
1683 c->pre_bit_error.stat[0].uvalue = t_pre_bit_error;
1684 c->pre_bit_count.stat[0].scale = FE_SCALE_COUNTER;
1685 c->pre_bit_count.stat[0].uvalue = t_pre_bit_count;
1686 } else {
1687 c->pre_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
1688 c->pre_bit_count.stat[0].scale = FE_SCALE_COUNTER;
1689 }
1690
1691 /*
1692 * Start showing global count if at least one error count is
1693 * available.
1694 */
1695 if (post_ber_layers) {
1696 /*
1697 * At least one per-layer BER measure was read. We can now
1698 * calculate the total BER
1699 *
1700 * Total Bit Error/Count is calculated as the sum of the
1701 * bit errors on all active layers.
1702 */
1703 c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER;
1704 c->post_bit_error.stat[0].uvalue = t_post_bit_error;
1705 c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER;
1706 c->post_bit_count.stat[0].uvalue = t_post_bit_count;
1707 } else {
1708 c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
1709 c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER;
1710 }
1711
1712 if (per_layers) {
1713 /*
1714 * At least one per-layer UCB measure was read. We can now
1715 * calculate the total UCB
1716 *
1717 * Total block Error/Count is calculated as the sum of the
1718 * block errors on all active layers.
1719 */
1720 c->block_error.stat[0].scale = FE_SCALE_COUNTER;
1721 c->block_error.stat[0].uvalue = t_block_error;
1722 c->block_count.stat[0].scale = FE_SCALE_COUNTER;
1723 c->block_count.stat[0].uvalue = t_block_count;
1724 } else {
1725 c->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
1726 c->block_count.stat[0].scale = FE_SCALE_COUNTER;
1727 }
1728
1729 return rc;
1730}
1731
1732/*
1733 * The functions below are called via DVB callbacks, so they need to
1734 * properly use the I2C gate control
1735 */
1736
1737static int mb86a20s_initfe(struct dvb_frontend *fe)
1738{
1739 struct mb86a20s_state *state = fe->demodulator_priv;
1740 int rc;
1741 u8 regD5 = 1;
1742
1743 dev_dbg(&state->i2c->dev, "%s called.\n", __func__);
1744
1745 if (fe->ops.i2c_gate_ctrl)
1746 fe->ops.i2c_gate_ctrl(fe, 0);
1747
1748 /* Initialize the frontend */
1749 rc = mb86a20s_writeregdata(state, mb86a20s_init);
1750 if (rc < 0)
1751 goto err;
1752
1753 if (!state->config->is_serial) {
1754 regD5 &= ~1;
1755
1756 rc = mb86a20s_writereg(state, 0x50, 0xd5);
1757 if (rc < 0)
1758 goto err;
1759 rc = mb86a20s_writereg(state, 0x51, regD5);
1760 if (rc < 0)
1761 goto err;
1762 }
1763
1764err:
593 if (fe->ops.i2c_gate_ctrl) 1765 if (fe->ops.i2c_gate_ctrl)
594 fe->ops.i2c_gate_ctrl(fe, 1); 1766 fe->ops.i2c_gate_ctrl(fe, 1);
595 1767
1768 if (rc < 0) {
1769 state->need_init = true;
1770 dev_info(&state->i2c->dev,
1771 "mb86a20s: Init failed. Will try again later\n");
1772 } else {
1773 state->need_init = false;
1774 dev_dbg(&state->i2c->dev, "Initialization succeeded.\n");
1775 }
1776 return rc;
1777}
1778
1779static int mb86a20s_set_frontend(struct dvb_frontend *fe)
1780{
1781 struct mb86a20s_state *state = fe->demodulator_priv;
1782 int rc;
1783#if 0
1784 /*
1785 * FIXME: Properly implement the set frontend properties
1786 */
1787 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1788#endif
1789 dev_dbg(&state->i2c->dev, "%s called.\n", __func__);
1790
1791 /*
1792 * Gate should already be opened, but it doesn't hurt to
1793 * double-check
1794 */
1795 if (fe->ops.i2c_gate_ctrl)
1796 fe->ops.i2c_gate_ctrl(fe, 1);
1797 fe->ops.tuner_ops.set_params(fe);
1798
1799 /*
1800 * Make it more reliable: if, for some reason, the initial
1801 * device initialization doesn't happen, initialize it when
1802 * a SBTVD parameters are adjusted.
1803 *
1804 * Unfortunately, due to a hard to track bug at tda829x/tda18271,
1805 * the agc callback logic is not called during DVB attach time,
1806 * causing mb86a20s to not be initialized with Kworld SBTVD.
1807 * So, this hack is needed, in order to make Kworld SBTVD to work.
1808 */
1809 if (state->need_init)
1810 mb86a20s_initfe(fe);
1811
1812 if (fe->ops.i2c_gate_ctrl)
1813 fe->ops.i2c_gate_ctrl(fe, 0);
1814
1815 rc = mb86a20s_writeregdata(state, mb86a20s_reset_reception);
1816 mb86a20s_reset_counters(fe);
1817
1818 if (fe->ops.i2c_gate_ctrl)
1819 fe->ops.i2c_gate_ctrl(fe, 1);
1820
1821 return rc;
1822}
1823
1824static int mb86a20s_read_status_and_stats(struct dvb_frontend *fe,
1825 fe_status_t *status)
1826{
1827 struct mb86a20s_state *state = fe->demodulator_priv;
1828 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1829 int rc;
1830
1831 dev_dbg(&state->i2c->dev, "%s called.\n", __func__);
1832
1833 if (fe->ops.i2c_gate_ctrl)
1834 fe->ops.i2c_gate_ctrl(fe, 0);
1835
1836 /* Get lock */
1837 rc = mb86a20s_read_status(fe, status);
1838 if (!(*status & FE_HAS_LOCK)) {
1839 mb86a20s_stats_not_ready(fe);
1840 mb86a20s_reset_frontend_cache(fe);
1841 }
1842 if (rc < 0) {
1843 dev_err(&state->i2c->dev,
1844 "%s: Can't read frontend lock status\n", __func__);
1845 goto error;
1846 }
1847
1848 /* Get signal strength */
1849 rc = mb86a20s_read_signal_strength(fe);
1850 if (rc < 0) {
1851 dev_err(&state->i2c->dev,
1852 "%s: Can't reset VBER registers.\n", __func__);
1853 mb86a20s_stats_not_ready(fe);
1854 mb86a20s_reset_frontend_cache(fe);
1855
1856 rc = 0; /* Status is OK */
1857 goto error;
1858 }
1859 /* Fill signal strength */
1860 c->strength.stat[0].uvalue = rc;
1861
1862 if (*status & FE_HAS_LOCK) {
1863 /* Get TMCC info*/
1864 rc = mb86a20s_get_frontend(fe);
1865 if (rc < 0) {
1866 dev_err(&state->i2c->dev,
1867 "%s: Can't get FE TMCC data.\n", __func__);
1868 rc = 0; /* Status is OK */
1869 goto error;
1870 }
1871
1872 /* Get statistics */
1873 rc = mb86a20s_get_stats(fe);
1874 if (rc < 0 && rc != -EBUSY) {
1875 dev_err(&state->i2c->dev,
1876 "%s: Can't get FE statistics.\n", __func__);
1877 rc = 0;
1878 goto error;
1879 }
1880 rc = 0; /* Don't return EBUSY to userspace */
1881 }
1882 goto ok;
1883
1884error:
1885 mb86a20s_stats_not_ready(fe);
1886
1887ok:
1888 if (fe->ops.i2c_gate_ctrl)
1889 fe->ops.i2c_gate_ctrl(fe, 1);
1890
1891 return rc;
1892}
1893
1894static int mb86a20s_read_signal_strength_from_cache(struct dvb_frontend *fe,
1895 u16 *strength)
1896{
1897 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1898
1899
1900 *strength = c->strength.stat[0].uvalue;
1901
596 return 0; 1902 return 0;
597} 1903}
598 1904
1905static int mb86a20s_get_frontend_dummy(struct dvb_frontend *fe)
1906{
1907 /*
1908 * get_frontend is now handled together with other stats
1909 * retrival, when read_status() is called, as some statistics
1910 * will depend on the layers detection.
1911 */
1912 return 0;
1913};
1914
599static int mb86a20s_tune(struct dvb_frontend *fe, 1915static int mb86a20s_tune(struct dvb_frontend *fe,
600 bool re_tune, 1916 bool re_tune,
601 unsigned int mode_flags, 1917 unsigned int mode_flags,
602 unsigned int *delay, 1918 unsigned int *delay,
603 fe_status_t *status) 1919 fe_status_t *status)
604{ 1920{
1921 struct mb86a20s_state *state = fe->demodulator_priv;
605 int rc = 0; 1922 int rc = 0;
606 1923
607 dprintk("\n"); 1924 dev_dbg(&state->i2c->dev, "%s called.\n", __func__);
608 1925
609 if (re_tune) 1926 if (re_tune)
610 rc = mb86a20s_set_frontend(fe); 1927 rc = mb86a20s_set_frontend(fe);
611 1928
612 if (!(mode_flags & FE_TUNE_MODE_ONESHOT)) 1929 if (!(mode_flags & FE_TUNE_MODE_ONESHOT))
613 mb86a20s_read_status(fe, status); 1930 mb86a20s_read_status_and_stats(fe, status);
614 1931
615 return rc; 1932 return rc;
616} 1933}
@@ -619,7 +1936,7 @@ static void mb86a20s_release(struct dvb_frontend *fe)
619{ 1936{
620 struct mb86a20s_state *state = fe->demodulator_priv; 1937 struct mb86a20s_state *state = fe->demodulator_priv;
621 1938
622 dprintk("\n"); 1939 dev_dbg(&state->i2c->dev, "%s called.\n", __func__);
623 1940
624 kfree(state); 1941 kfree(state);
625} 1942}
@@ -629,15 +1946,16 @@ static struct dvb_frontend_ops mb86a20s_ops;
629struct dvb_frontend *mb86a20s_attach(const struct mb86a20s_config *config, 1946struct dvb_frontend *mb86a20s_attach(const struct mb86a20s_config *config,
630 struct i2c_adapter *i2c) 1947 struct i2c_adapter *i2c)
631{ 1948{
1949 struct mb86a20s_state *state;
632 u8 rev; 1950 u8 rev;
633 1951
634 /* allocate memory for the internal state */ 1952 dev_dbg(&i2c->dev, "%s called.\n", __func__);
635 struct mb86a20s_state *state =
636 kzalloc(sizeof(struct mb86a20s_state), GFP_KERNEL);
637 1953
638 dprintk("\n"); 1954 /* allocate memory for the internal state */
1955 state = kzalloc(sizeof(struct mb86a20s_state), GFP_KERNEL);
639 if (state == NULL) { 1956 if (state == NULL) {
640 rc("Unable to kzalloc\n"); 1957 dev_err(&i2c->dev,
1958 "%s: unable to allocate memory for state\n", __func__);
641 goto error; 1959 goto error;
642 } 1960 }
643 1961
@@ -654,9 +1972,11 @@ struct dvb_frontend *mb86a20s_attach(const struct mb86a20s_config *config,
654 rev = mb86a20s_readreg(state, 0); 1972 rev = mb86a20s_readreg(state, 0);
655 1973
656 if (rev == 0x13) { 1974 if (rev == 0x13) {
657 printk(KERN_INFO "Detected a Fujitsu mb86a20s frontend\n"); 1975 dev_info(&i2c->dev,
1976 "Detected a Fujitsu mb86a20s frontend\n");
658 } else { 1977 } else {
659 printk(KERN_ERR "Frontend revision %d is unknown - aborting.\n", 1978 dev_dbg(&i2c->dev,
1979 "Frontend revision %d is unknown - aborting.\n",
660 rev); 1980 rev);
661 goto error; 1981 goto error;
662 } 1982 }
@@ -690,9 +2010,9 @@ static struct dvb_frontend_ops mb86a20s_ops = {
690 2010
691 .init = mb86a20s_initfe, 2011 .init = mb86a20s_initfe,
692 .set_frontend = mb86a20s_set_frontend, 2012 .set_frontend = mb86a20s_set_frontend,
693 .get_frontend = mb86a20s_get_frontend, 2013 .get_frontend = mb86a20s_get_frontend_dummy,
694 .read_status = mb86a20s_read_status, 2014 .read_status = mb86a20s_read_status_and_stats,
695 .read_signal_strength = mb86a20s_read_signal_strength, 2015 .read_signal_strength = mb86a20s_read_signal_strength_from_cache,
696 .tune = mb86a20s_tune, 2016 .tune = mb86a20s_tune,
697}; 2017};
698 2018
diff --git a/drivers/media/dvb-frontends/mt312.h b/drivers/media/dvb-frontends/mt312.h
index 29e3bb5496b8..5706621ad79d 100644
--- a/drivers/media/dvb-frontends/mt312.h
+++ b/drivers/media/dvb-frontends/mt312.h
@@ -36,7 +36,7 @@ struct mt312_config {
36 unsigned int voltage_inverted:1; 36 unsigned int voltage_inverted:1;
37}; 37};
38 38
39#if defined(CONFIG_DVB_MT312) || (defined(CONFIG_DVB_MT312_MODULE) && defined(MODULE)) 39#if IS_ENABLED(CONFIG_DVB_MT312)
40struct dvb_frontend *mt312_attach(const struct mt312_config *config, 40struct dvb_frontend *mt312_attach(const struct mt312_config *config,
41 struct i2c_adapter *i2c); 41 struct i2c_adapter *i2c);
42#else 42#else
diff --git a/drivers/media/dvb-frontends/mt352.h b/drivers/media/dvb-frontends/mt352.h
index ca2562d6f289..451d904e1500 100644
--- a/drivers/media/dvb-frontends/mt352.h
+++ b/drivers/media/dvb-frontends/mt352.h
@@ -51,7 +51,7 @@ struct mt352_config
51 int (*demod_init)(struct dvb_frontend* fe); 51 int (*demod_init)(struct dvb_frontend* fe);
52}; 52};
53 53
54#if defined(CONFIG_DVB_MT352) || (defined(CONFIG_DVB_MT352_MODULE) && defined(MODULE)) 54#if IS_ENABLED(CONFIG_DVB_MT352)
55extern struct dvb_frontend* mt352_attach(const struct mt352_config* config, 55extern struct dvb_frontend* mt352_attach(const struct mt352_config* config,
56 struct i2c_adapter* i2c); 56 struct i2c_adapter* i2c);
57#else 57#else
diff --git a/drivers/media/dvb-frontends/nxt200x.h b/drivers/media/dvb-frontends/nxt200x.h
index f3c84583770f..b518d545609e 100644
--- a/drivers/media/dvb-frontends/nxt200x.h
+++ b/drivers/media/dvb-frontends/nxt200x.h
@@ -42,7 +42,7 @@ struct nxt200x_config
42 int (*set_ts_params)(struct dvb_frontend* fe, int is_punctured); 42 int (*set_ts_params)(struct dvb_frontend* fe, int is_punctured);
43}; 43};
44 44
45#if defined(CONFIG_DVB_NXT200X) || (defined(CONFIG_DVB_NXT200X_MODULE) && defined(MODULE)) 45#if IS_ENABLED(CONFIG_DVB_NXT200X)
46extern struct dvb_frontend* nxt200x_attach(const struct nxt200x_config* config, 46extern struct dvb_frontend* nxt200x_attach(const struct nxt200x_config* config,
47 struct i2c_adapter* i2c); 47 struct i2c_adapter* i2c);
48#else 48#else
diff --git a/drivers/media/dvb-frontends/nxt6000.h b/drivers/media/dvb-frontends/nxt6000.h
index 878eb38a075e..b5867c2ae681 100644
--- a/drivers/media/dvb-frontends/nxt6000.h
+++ b/drivers/media/dvb-frontends/nxt6000.h
@@ -33,7 +33,7 @@ struct nxt6000_config
33 u8 clock_inversion:1; 33 u8 clock_inversion:1;
34}; 34};
35 35
36#if defined(CONFIG_DVB_NXT6000) || (defined(CONFIG_DVB_NXT6000_MODULE) && defined(MODULE)) 36#if IS_ENABLED(CONFIG_DVB_NXT6000)
37extern struct dvb_frontend* nxt6000_attach(const struct nxt6000_config* config, 37extern struct dvb_frontend* nxt6000_attach(const struct nxt6000_config* config,
38 struct i2c_adapter* i2c); 38 struct i2c_adapter* i2c);
39#else 39#else
diff --git a/drivers/media/dvb-frontends/or51132.h b/drivers/media/dvb-frontends/or51132.h
index 1b8e04d973c8..938958386cb1 100644
--- a/drivers/media/dvb-frontends/or51132.h
+++ b/drivers/media/dvb-frontends/or51132.h
@@ -34,7 +34,7 @@ struct or51132_config
34 int (*set_ts_params)(struct dvb_frontend* fe, int is_punctured); 34 int (*set_ts_params)(struct dvb_frontend* fe, int is_punctured);
35}; 35};
36 36
37#if defined(CONFIG_DVB_OR51132) || (defined(CONFIG_DVB_OR51132_MODULE) && defined(MODULE)) 37#if IS_ENABLED(CONFIG_DVB_OR51132)
38extern struct dvb_frontend* or51132_attach(const struct or51132_config* config, 38extern struct dvb_frontend* or51132_attach(const struct or51132_config* config,
39 struct i2c_adapter* i2c); 39 struct i2c_adapter* i2c);
40#else 40#else
diff --git a/drivers/media/dvb-frontends/or51211.c b/drivers/media/dvb-frontends/or51211.c
index c625b57b4333..10cfc0579168 100644
--- a/drivers/media/dvb-frontends/or51211.c
+++ b/drivers/media/dvb-frontends/or51211.c
@@ -22,6 +22,8 @@
22 * 22 *
23*/ 23*/
24 24
25#define pr_fmt(fmt) KBUILD_MODNAME ": %s: " fmt, __func__
26
25/* 27/*
26 * This driver needs external firmware. Please use the command 28 * This driver needs external firmware. Please use the command
27 * "<kerneldir>/Documentation/dvb/get_dvb_firmware or51211" to 29 * "<kerneldir>/Documentation/dvb/get_dvb_firmware or51211" to
@@ -44,9 +46,7 @@
44 46
45static int debug; 47static int debug;
46#define dprintk(args...) \ 48#define dprintk(args...) \
47 do { \ 49 do { if (debug) pr_debug(args); } while (0)
48 if (debug) printk(KERN_DEBUG "or51211: " args); \
49 } while (0)
50 50
51static u8 run_buf[] = {0x7f,0x01}; 51static u8 run_buf[] = {0x7f,0x01};
52static u8 cmd_buf[] = {0x04,0x01,0x50,0x80,0x06}; // ATSC 52static u8 cmd_buf[] = {0x04,0x01,0x50,0x80,0x06}; // ATSC
@@ -80,8 +80,7 @@ static int i2c_writebytes (struct or51211_state* state, u8 reg, const u8 *buf,
80 msg.buf = (u8 *)buf; 80 msg.buf = (u8 *)buf;
81 81
82 if ((err = i2c_transfer (state->i2c, &msg, 1)) != 1) { 82 if ((err = i2c_transfer (state->i2c, &msg, 1)) != 1) {
83 printk(KERN_WARNING "or51211: i2c_writebytes error " 83 pr_warn("error (addr %02x, err == %i)\n", reg, err);
84 "(addr %02x, err == %i)\n", reg, err);
85 return -EREMOTEIO; 84 return -EREMOTEIO;
86 } 85 }
87 86
@@ -98,8 +97,7 @@ static int i2c_readbytes(struct or51211_state *state, u8 reg, u8 *buf, int len)
98 msg.buf = buf; 97 msg.buf = buf;
99 98
100 if ((err = i2c_transfer (state->i2c, &msg, 1)) != 1) { 99 if ((err = i2c_transfer (state->i2c, &msg, 1)) != 1) {
101 printk(KERN_WARNING "or51211: i2c_readbytes error " 100 pr_warn("error (addr %02x, err == %i)\n", reg, err);
102 "(addr %02x, err == %i)\n", reg, err);
103 return -EREMOTEIO; 101 return -EREMOTEIO;
104 } 102 }
105 103
@@ -118,11 +116,11 @@ static int or51211_load_firmware (struct dvb_frontend* fe,
118 /* Get eprom data */ 116 /* Get eprom data */
119 tudata[0] = 17; 117 tudata[0] = 17;
120 if (i2c_writebytes(state,0x50,tudata,1)) { 118 if (i2c_writebytes(state,0x50,tudata,1)) {
121 printk(KERN_WARNING "or51211:load_firmware error eprom addr\n"); 119 pr_warn("error eprom addr\n");
122 return -1; 120 return -1;
123 } 121 }
124 if (i2c_readbytes(state,0x50,&tudata[145],192)) { 122 if (i2c_readbytes(state,0x50,&tudata[145],192)) {
125 printk(KERN_WARNING "or51211: load_firmware error eprom\n"); 123 pr_warn("error eprom\n");
126 return -1; 124 return -1;
127 } 125 }
128 126
@@ -136,32 +134,32 @@ static int or51211_load_firmware (struct dvb_frontend* fe,
136 state->config->reset(fe); 134 state->config->reset(fe);
137 135
138 if (i2c_writebytes(state,state->config->demod_address,tudata,585)) { 136 if (i2c_writebytes(state,state->config->demod_address,tudata,585)) {
139 printk(KERN_WARNING "or51211: load_firmware error 1\n"); 137 pr_warn("error 1\n");
140 return -1; 138 return -1;
141 } 139 }
142 msleep(1); 140 msleep(1);
143 141
144 if (i2c_writebytes(state,state->config->demod_address, 142 if (i2c_writebytes(state,state->config->demod_address,
145 &fw->data[393],8125)) { 143 &fw->data[393],8125)) {
146 printk(KERN_WARNING "or51211: load_firmware error 2\n"); 144 pr_warn("error 2\n");
147 return -1; 145 return -1;
148 } 146 }
149 msleep(1); 147 msleep(1);
150 148
151 if (i2c_writebytes(state,state->config->demod_address,run_buf,2)) { 149 if (i2c_writebytes(state,state->config->demod_address,run_buf,2)) {
152 printk(KERN_WARNING "or51211: load_firmware error 3\n"); 150 pr_warn("error 3\n");
153 return -1; 151 return -1;
154 } 152 }
155 153
156 /* Wait at least 5 msec */ 154 /* Wait at least 5 msec */
157 msleep(10); 155 msleep(10);
158 if (i2c_writebytes(state,state->config->demod_address,run_buf,2)) { 156 if (i2c_writebytes(state,state->config->demod_address,run_buf,2)) {
159 printk(KERN_WARNING "or51211: load_firmware error 4\n"); 157 pr_warn("error 4\n");
160 return -1; 158 return -1;
161 } 159 }
162 msleep(10); 160 msleep(10);
163 161
164 printk("or51211: Done.\n"); 162 pr_info("Done.\n");
165 return 0; 163 return 0;
166}; 164};
167 165
@@ -173,14 +171,14 @@ static int or51211_setmode(struct dvb_frontend* fe, int mode)
173 state->config->setmode(fe, mode); 171 state->config->setmode(fe, mode);
174 172
175 if (i2c_writebytes(state,state->config->demod_address,run_buf,2)) { 173 if (i2c_writebytes(state,state->config->demod_address,run_buf,2)) {
176 printk(KERN_WARNING "or51211: setmode error 1\n"); 174 pr_warn("error 1\n");
177 return -1; 175 return -1;
178 } 176 }
179 177
180 /* Wait at least 5 msec */ 178 /* Wait at least 5 msec */
181 msleep(10); 179 msleep(10);
182 if (i2c_writebytes(state,state->config->demod_address,run_buf,2)) { 180 if (i2c_writebytes(state,state->config->demod_address,run_buf,2)) {
183 printk(KERN_WARNING "or51211: setmode error 2\n"); 181 pr_warn("error 2\n");
184 return -1; 182 return -1;
185 } 183 }
186 184
@@ -196,7 +194,7 @@ static int or51211_setmode(struct dvb_frontend* fe, int mode)
196 * normal +/-150kHz Carrier acquisition range 194 * normal +/-150kHz Carrier acquisition range
197 */ 195 */
198 if (i2c_writebytes(state,state->config->demod_address,cmd_buf,3)) { 196 if (i2c_writebytes(state,state->config->demod_address,cmd_buf,3)) {
199 printk(KERN_WARNING "or51211: setmode error 3\n"); 197 pr_warn("error 3\n");
200 return -1; 198 return -1;
201 } 199 }
202 200
@@ -206,14 +204,14 @@ static int or51211_setmode(struct dvb_frontend* fe, int mode)
206 rec_buf[3] = 0x00; 204 rec_buf[3] = 0x00;
207 msleep(20); 205 msleep(20);
208 if (i2c_writebytes(state,state->config->demod_address,rec_buf,3)) { 206 if (i2c_writebytes(state,state->config->demod_address,rec_buf,3)) {
209 printk(KERN_WARNING "or51211: setmode error 5\n"); 207 pr_warn("error 5\n");
210 } 208 }
211 msleep(3); 209 msleep(3);
212 if (i2c_readbytes(state,state->config->demod_address,&rec_buf[10],2)) { 210 if (i2c_readbytes(state,state->config->demod_address,&rec_buf[10],2)) {
213 printk(KERN_WARNING "or51211: setmode error 6"); 211 pr_warn("error 6\n");
214 return -1; 212 return -1;
215 } 213 }
216 dprintk("setmode rec status %02x %02x\n",rec_buf[10],rec_buf[11]); 214 dprintk("rec status %02x %02x\n", rec_buf[10], rec_buf[11]);
217 215
218 return 0; 216 return 0;
219} 217}
@@ -248,15 +246,15 @@ static int or51211_read_status(struct dvb_frontend* fe, fe_status_t* status)
248 246
249 /* Receiver Status */ 247 /* Receiver Status */
250 if (i2c_writebytes(state,state->config->demod_address,snd_buf,3)) { 248 if (i2c_writebytes(state,state->config->demod_address,snd_buf,3)) {
251 printk(KERN_WARNING "or51132: read_status write error\n"); 249 pr_warn("write error\n");
252 return -1; 250 return -1;
253 } 251 }
254 msleep(3); 252 msleep(3);
255 if (i2c_readbytes(state,state->config->demod_address,rec_buf,2)) { 253 if (i2c_readbytes(state,state->config->demod_address,rec_buf,2)) {
256 printk(KERN_WARNING "or51132: read_status read error\n"); 254 pr_warn("read error\n");
257 return -1; 255 return -1;
258 } 256 }
259 dprintk("read_status %x %x\n",rec_buf[0],rec_buf[1]); 257 dprintk("%x %x\n", rec_buf[0], rec_buf[1]);
260 258
261 if (rec_buf[0] & 0x01) { /* Receiver Lock */ 259 if (rec_buf[0] & 0x01) { /* Receiver Lock */
262 *status |= FE_HAS_SIGNAL; 260 *status |= FE_HAS_SIGNAL;
@@ -306,20 +304,18 @@ static int or51211_read_snr(struct dvb_frontend* fe, u16* snr)
306 snd_buf[2] = 0x04; 304 snd_buf[2] = 0x04;
307 305
308 if (i2c_writebytes(state,state->config->demod_address,snd_buf,3)) { 306 if (i2c_writebytes(state,state->config->demod_address,snd_buf,3)) {
309 printk(KERN_WARNING "%s: error writing snr reg\n", 307 pr_warn("error writing snr reg\n");
310 __func__);
311 return -1; 308 return -1;
312 } 309 }
313 if (i2c_readbytes(state,state->config->demod_address,rec_buf,2)) { 310 if (i2c_readbytes(state,state->config->demod_address,rec_buf,2)) {
314 printk(KERN_WARNING "%s: read_status read error\n", 311 pr_warn("read_status read error\n");
315 __func__);
316 return -1; 312 return -1;
317 } 313 }
318 314
319 state->snr = calculate_snr(rec_buf[0], 89599047); 315 state->snr = calculate_snr(rec_buf[0], 89599047);
320 *snr = (state->snr) >> 16; 316 *snr = (state->snr) >> 16;
321 317
322 dprintk("%s: noise = 0x%02x, snr = %d.%02d dB\n", __func__, rec_buf[0], 318 dprintk("noise = 0x%02x, snr = %d.%02d dB\n", rec_buf[0],
323 state->snr >> 24, (((state->snr>>8) & 0xffff) * 100) >> 16); 319 state->snr >> 24, (((state->snr>>8) & 0xffff) * 100) >> 16);
324 320
325 return 0; 321 return 0;
@@ -375,25 +371,24 @@ static int or51211_init(struct dvb_frontend* fe)
375 371
376 if (!state->initialized) { 372 if (!state->initialized) {
377 /* Request the firmware, this will block until it uploads */ 373 /* Request the firmware, this will block until it uploads */
378 printk(KERN_INFO "or51211: Waiting for firmware upload " 374 pr_info("Waiting for firmware upload (%s)...\n",
379 "(%s)...\n", OR51211_DEFAULT_FIRMWARE); 375 OR51211_DEFAULT_FIRMWARE);
380 ret = config->request_firmware(fe, &fw, 376 ret = config->request_firmware(fe, &fw,
381 OR51211_DEFAULT_FIRMWARE); 377 OR51211_DEFAULT_FIRMWARE);
382 printk(KERN_INFO "or51211:Got Hotplug firmware\n"); 378 pr_info("Got Hotplug firmware\n");
383 if (ret) { 379 if (ret) {
384 printk(KERN_WARNING "or51211: No firmware uploaded " 380 pr_warn("No firmware uploaded "
385 "(timeout or file not found?)\n"); 381 "(timeout or file not found?)\n");
386 return ret; 382 return ret;
387 } 383 }
388 384
389 ret = or51211_load_firmware(fe, fw); 385 ret = or51211_load_firmware(fe, fw);
390 release_firmware(fw); 386 release_firmware(fw);
391 if (ret) { 387 if (ret) {
392 printk(KERN_WARNING "or51211: Writing firmware to " 388 pr_warn("Writing firmware to device failed!\n");
393 "device failed!\n");
394 return ret; 389 return ret;
395 } 390 }
396 printk(KERN_INFO "or51211: Firmware upload complete.\n"); 391 pr_info("Firmware upload complete.\n");
397 392
398 /* Set operation mode in Receiver 1 register; 393 /* Set operation mode in Receiver 1 register;
399 * type 1: 394 * type 1:
@@ -406,7 +401,7 @@ static int or51211_init(struct dvb_frontend* fe)
406 */ 401 */
407 if (i2c_writebytes(state,state->config->demod_address, 402 if (i2c_writebytes(state,state->config->demod_address,
408 cmd_buf,3)) { 403 cmd_buf,3)) {
409 printk(KERN_WARNING "or51211: Load DVR Error 5\n"); 404 pr_warn("Load DVR Error 5\n");
410 return -1; 405 return -1;
411 } 406 }
412 407
@@ -419,13 +414,13 @@ static int or51211_init(struct dvb_frontend* fe)
419 msleep(30); 414 msleep(30);
420 if (i2c_writebytes(state,state->config->demod_address, 415 if (i2c_writebytes(state,state->config->demod_address,
421 rec_buf,3)) { 416 rec_buf,3)) {
422 printk(KERN_WARNING "or51211: Load DVR Error A\n"); 417 pr_warn("Load DVR Error A\n");
423 return -1; 418 return -1;
424 } 419 }
425 msleep(3); 420 msleep(3);
426 if (i2c_readbytes(state,state->config->demod_address, 421 if (i2c_readbytes(state,state->config->demod_address,
427 &rec_buf[10],2)) { 422 &rec_buf[10],2)) {
428 printk(KERN_WARNING "or51211: Load DVR Error B\n"); 423 pr_warn("Load DVR Error B\n");
429 return -1; 424 return -1;
430 } 425 }
431 426
@@ -436,13 +431,13 @@ static int or51211_init(struct dvb_frontend* fe)
436 msleep(20); 431 msleep(20);
437 if (i2c_writebytes(state,state->config->demod_address, 432 if (i2c_writebytes(state,state->config->demod_address,
438 rec_buf,3)) { 433 rec_buf,3)) {
439 printk(KERN_WARNING "or51211: Load DVR Error C\n"); 434 pr_warn("Load DVR Error C\n");
440 return -1; 435 return -1;
441 } 436 }
442 msleep(3); 437 msleep(3);
443 if (i2c_readbytes(state,state->config->demod_address, 438 if (i2c_readbytes(state,state->config->demod_address,
444 &rec_buf[12],2)) { 439 &rec_buf[12],2)) {
445 printk(KERN_WARNING "or51211: Load DVR Error D\n"); 440 pr_warn("Load DVR Error D\n");
446 return -1; 441 return -1;
447 } 442 }
448 443
@@ -454,16 +449,14 @@ static int or51211_init(struct dvb_frontend* fe)
454 get_ver_buf[4] = i+1; 449 get_ver_buf[4] = i+1;
455 if (i2c_writebytes(state,state->config->demod_address, 450 if (i2c_writebytes(state,state->config->demod_address,
456 get_ver_buf,5)) { 451 get_ver_buf,5)) {
457 printk(KERN_WARNING "or51211:Load DVR Error 6" 452 pr_warn("Load DVR Error 6 - %d\n", i);
458 " - %d\n",i);
459 return -1; 453 return -1;
460 } 454 }
461 msleep(3); 455 msleep(3);
462 456
463 if (i2c_readbytes(state,state->config->demod_address, 457 if (i2c_readbytes(state,state->config->demod_address,
464 &rec_buf[i*2],2)) { 458 &rec_buf[i*2],2)) {
465 printk(KERN_WARNING "or51211:Load DVR Error 7" 459 pr_warn("Load DVR Error 7 - %d\n", i);
466 " - %d\n",i);
467 return -1; 460 return -1;
468 } 461 }
469 /* If we didn't receive the right index, try again */ 462 /* If we didn't receive the right index, try again */
@@ -471,15 +464,11 @@ static int or51211_init(struct dvb_frontend* fe)
471 i--; 464 i--;
472 } 465 }
473 } 466 }
474 dprintk("read_fwbits %x %x %x %x %x %x %x %x %x %x\n", 467 dprintk("read_fwbits %10ph\n", rec_buf);
475 rec_buf[0], rec_buf[1], rec_buf[2], rec_buf[3],
476 rec_buf[4], rec_buf[5], rec_buf[6], rec_buf[7],
477 rec_buf[8], rec_buf[9]);
478 468
479 printk(KERN_INFO "or51211: ver TU%02x%02x%02x VSB mode %02x" 469 pr_info("ver TU%02x%02x%02x VSB mode %02x Status %02x\n",
480 " Status %02x\n", 470 rec_buf[2], rec_buf[4], rec_buf[6], rec_buf[12],
481 rec_buf[2], rec_buf[4],rec_buf[6], 471 rec_buf[10]);
482 rec_buf[12],rec_buf[10]);
483 472
484 rec_buf[0] = 0x04; 473 rec_buf[0] = 0x04;
485 rec_buf[1] = 0x00; 474 rec_buf[1] = 0x00;
@@ -488,13 +477,13 @@ static int or51211_init(struct dvb_frontend* fe)
488 msleep(20); 477 msleep(20);
489 if (i2c_writebytes(state,state->config->demod_address, 478 if (i2c_writebytes(state,state->config->demod_address,
490 rec_buf,3)) { 479 rec_buf,3)) {
491 printk(KERN_WARNING "or51211: Load DVR Error 8\n"); 480 pr_warn("Load DVR Error 8\n");
492 return -1; 481 return -1;
493 } 482 }
494 msleep(20); 483 msleep(20);
495 if (i2c_readbytes(state,state->config->demod_address, 484 if (i2c_readbytes(state,state->config->demod_address,
496 &rec_buf[8],2)) { 485 &rec_buf[8],2)) {
497 printk(KERN_WARNING "or51211: Load DVR Error 9\n"); 486 pr_warn("Load DVR Error 9\n");
498 return -1; 487 return -1;
499 } 488 }
500 state->initialized = 1; 489 state->initialized = 1;
diff --git a/drivers/media/dvb-frontends/or51211.h b/drivers/media/dvb-frontends/or51211.h
index 3ce0508b898e..9a8ae936b62d 100644
--- a/drivers/media/dvb-frontends/or51211.h
+++ b/drivers/media/dvb-frontends/or51211.h
@@ -37,7 +37,7 @@ struct or51211_config
37 void (*sleep)(struct dvb_frontend * fe); 37 void (*sleep)(struct dvb_frontend * fe);
38}; 38};
39 39
40#if defined(CONFIG_DVB_OR51211) || (defined(CONFIG_DVB_OR51211_MODULE) && defined(MODULE)) 40#if IS_ENABLED(CONFIG_DVB_OR51211)
41extern struct dvb_frontend* or51211_attach(const struct or51211_config* config, 41extern struct dvb_frontend* or51211_attach(const struct or51211_config* config,
42 struct i2c_adapter* i2c); 42 struct i2c_adapter* i2c);
43#else 43#else
diff --git a/drivers/media/dvb-frontends/s5h1420.h b/drivers/media/dvb-frontends/s5h1420.h
index ff308136d865..210049b5cf30 100644
--- a/drivers/media/dvb-frontends/s5h1420.h
+++ b/drivers/media/dvb-frontends/s5h1420.h
@@ -40,7 +40,7 @@ struct s5h1420_config
40 u8 serial_mpeg:1; 40 u8 serial_mpeg:1;
41}; 41};
42 42
43#if defined(CONFIG_DVB_S5H1420) || (defined(CONFIG_DVB_S5H1420_MODULE) && defined(MODULE)) 43#if IS_ENABLED(CONFIG_DVB_S5H1420)
44extern struct dvb_frontend *s5h1420_attach(const struct s5h1420_config *config, 44extern struct dvb_frontend *s5h1420_attach(const struct s5h1420_config *config,
45 struct i2c_adapter *i2c); 45 struct i2c_adapter *i2c);
46extern struct i2c_adapter *s5h1420_get_tuner_i2c_adapter(struct dvb_frontend *fe); 46extern struct i2c_adapter *s5h1420_get_tuner_i2c_adapter(struct dvb_frontend *fe);
diff --git a/drivers/media/dvb-frontends/sp8870.h b/drivers/media/dvb-frontends/sp8870.h
index a764a793c7d8..065ec67d4e30 100644
--- a/drivers/media/dvb-frontends/sp8870.h
+++ b/drivers/media/dvb-frontends/sp8870.h
@@ -35,7 +35,7 @@ struct sp8870_config
35 int (*request_firmware)(struct dvb_frontend* fe, const struct firmware **fw, char* name); 35 int (*request_firmware)(struct dvb_frontend* fe, const struct firmware **fw, char* name);
36}; 36};
37 37
38#if defined(CONFIG_DVB_SP8870) || (defined(CONFIG_DVB_SP8870_MODULE) && defined(MODULE)) 38#if IS_ENABLED(CONFIG_DVB_SP8870)
39extern struct dvb_frontend* sp8870_attach(const struct sp8870_config* config, 39extern struct dvb_frontend* sp8870_attach(const struct sp8870_config* config,
40 struct i2c_adapter* i2c); 40 struct i2c_adapter* i2c);
41#else 41#else
diff --git a/drivers/media/dvb-frontends/sp887x.h b/drivers/media/dvb-frontends/sp887x.h
index 04eff6e0eef3..2cdc4e8bc9cd 100644
--- a/drivers/media/dvb-frontends/sp887x.h
+++ b/drivers/media/dvb-frontends/sp887x.h
@@ -17,7 +17,7 @@ struct sp887x_config
17 int (*request_firmware)(struct dvb_frontend* fe, const struct firmware **fw, char* name); 17 int (*request_firmware)(struct dvb_frontend* fe, const struct firmware **fw, char* name);
18}; 18};
19 19
20#if defined(CONFIG_DVB_SP887X) || (defined(CONFIG_DVB_SP887X_MODULE) && defined(MODULE)) 20#if IS_ENABLED(CONFIG_DVB_SP887X)
21extern struct dvb_frontend* sp887x_attach(const struct sp887x_config* config, 21extern struct dvb_frontend* sp887x_attach(const struct sp887x_config* config,
22 struct i2c_adapter* i2c); 22 struct i2c_adapter* i2c);
23#else 23#else
diff --git a/drivers/media/dvb-frontends/stb0899_drv.h b/drivers/media/dvb-frontends/stb0899_drv.h
index 98b200ce0c34..8d26ff6eb1db 100644
--- a/drivers/media/dvb-frontends/stb0899_drv.h
+++ b/drivers/media/dvb-frontends/stb0899_drv.h
@@ -142,7 +142,7 @@ struct stb0899_config {
142 int (*tuner_set_rfsiggain)(struct dvb_frontend *fe, u32 rf_gain); 142 int (*tuner_set_rfsiggain)(struct dvb_frontend *fe, u32 rf_gain);
143}; 143};
144 144
145#if defined(CONFIG_DVB_STB0899) || (defined(CONFIG_DVB_STB0899_MODULE) && defined(MODULE)) 145#if IS_ENABLED(CONFIG_DVB_STB0899)
146 146
147extern struct dvb_frontend *stb0899_attach(struct stb0899_config *config, 147extern struct dvb_frontend *stb0899_attach(struct stb0899_config *config,
148 struct i2c_adapter *i2c); 148 struct i2c_adapter *i2c);
diff --git a/drivers/media/dvb-frontends/stb6100.h b/drivers/media/dvb-frontends/stb6100.h
index 2ab096614b3f..3a1e40f3b8be 100644
--- a/drivers/media/dvb-frontends/stb6100.h
+++ b/drivers/media/dvb-frontends/stb6100.h
@@ -94,7 +94,7 @@ struct stb6100_state {
94 u32 reference; 94 u32 reference;
95}; 95};
96 96
97#if defined(CONFIG_DVB_STB6100) || (defined(CONFIG_DVB_STB6100_MODULE) && defined(MODULE)) 97#if IS_ENABLED(CONFIG_DVB_STB6100)
98 98
99extern struct dvb_frontend *stb6100_attach(struct dvb_frontend *fe, 99extern struct dvb_frontend *stb6100_attach(struct dvb_frontend *fe,
100 const struct stb6100_config *config, 100 const struct stb6100_config *config,
diff --git a/drivers/media/dvb-frontends/stv0297.h b/drivers/media/dvb-frontends/stv0297.h
index 3f8f9468f387..c8ff3639ce00 100644
--- a/drivers/media/dvb-frontends/stv0297.h
+++ b/drivers/media/dvb-frontends/stv0297.h
@@ -42,7 +42,7 @@ struct stv0297_config
42 u8 stop_during_read:1; 42 u8 stop_during_read:1;
43}; 43};
44 44
45#if defined(CONFIG_DVB_STV0297) || (defined(CONFIG_DVB_STV0297_MODULE) && defined(MODULE)) 45#if IS_ENABLED(CONFIG_DVB_STV0297)
46extern struct dvb_frontend* stv0297_attach(const struct stv0297_config* config, 46extern struct dvb_frontend* stv0297_attach(const struct stv0297_config* config,
47 struct i2c_adapter* i2c); 47 struct i2c_adapter* i2c);
48#else 48#else
diff --git a/drivers/media/dvb-frontends/stv0299.c b/drivers/media/dvb-frontends/stv0299.c
index 92a6075cd82f..b57ecf42e75a 100644
--- a/drivers/media/dvb-frontends/stv0299.c
+++ b/drivers/media/dvb-frontends/stv0299.c
@@ -420,7 +420,7 @@ static int stv0299_send_legacy_dish_cmd (struct dvb_frontend* fe, unsigned long
420 420
421 do_gettimeofday (&nexttime); 421 do_gettimeofday (&nexttime);
422 if (debug_legacy_dish_switch) 422 if (debug_legacy_dish_switch)
423 memcpy (&tv[0], &nexttime, sizeof (struct timeval)); 423 tv[0] = nexttime;
424 stv0299_writeregI (state, 0x0c, reg0x0c | 0x50); /* set LNB to 18V */ 424 stv0299_writeregI (state, 0x0c, reg0x0c | 0x50); /* set LNB to 18V */
425 425
426 dvb_frontend_sleep_until(&nexttime, 32000); 426 dvb_frontend_sleep_until(&nexttime, 32000);
diff --git a/drivers/media/dvb-frontends/stv0299.h b/drivers/media/dvb-frontends/stv0299.h
index ba219b767a69..06f70fc8327b 100644
--- a/drivers/media/dvb-frontends/stv0299.h
+++ b/drivers/media/dvb-frontends/stv0299.h
@@ -95,7 +95,7 @@ struct stv0299_config
95 int (*set_ts_params)(struct dvb_frontend *fe, int is_punctured); 95 int (*set_ts_params)(struct dvb_frontend *fe, int is_punctured);
96}; 96};
97 97
98#if defined(CONFIG_DVB_STV0299) || (defined(CONFIG_DVB_STV0299_MODULE) && defined(MODULE)) 98#if IS_ENABLED(CONFIG_DVB_STV0299)
99extern struct dvb_frontend *stv0299_attach(const struct stv0299_config *config, 99extern struct dvb_frontend *stv0299_attach(const struct stv0299_config *config,
100 struct i2c_adapter *i2c); 100 struct i2c_adapter *i2c);
101#else 101#else
diff --git a/drivers/media/dvb-frontends/stv0900_core.c b/drivers/media/dvb-frontends/stv0900_core.c
index b551ca350e00..e5a87b57d855 100644
--- a/drivers/media/dvb-frontends/stv0900_core.c
+++ b/drivers/media/dvb-frontends/stv0900_core.c
@@ -524,11 +524,8 @@ void stv0900_set_tuner(struct dvb_frontend *fe, u32 frequency,
524 struct dvb_frontend_ops *frontend_ops = NULL; 524 struct dvb_frontend_ops *frontend_ops = NULL;
525 struct dvb_tuner_ops *tuner_ops = NULL; 525 struct dvb_tuner_ops *tuner_ops = NULL;
526 526
527 if (&fe->ops) 527 frontend_ops = &fe->ops;
528 frontend_ops = &fe->ops; 528 tuner_ops = &frontend_ops->tuner_ops;
529
530 if (&frontend_ops->tuner_ops)
531 tuner_ops = &frontend_ops->tuner_ops;
532 529
533 if (tuner_ops->set_frequency) { 530 if (tuner_ops->set_frequency) {
534 if ((tuner_ops->set_frequency(fe, frequency)) < 0) 531 if ((tuner_ops->set_frequency(fe, frequency)) < 0)
@@ -552,11 +549,8 @@ void stv0900_set_bandwidth(struct dvb_frontend *fe, u32 bandwidth)
552 struct dvb_frontend_ops *frontend_ops = NULL; 549 struct dvb_frontend_ops *frontend_ops = NULL;
553 struct dvb_tuner_ops *tuner_ops = NULL; 550 struct dvb_tuner_ops *tuner_ops = NULL;
554 551
555 if (&fe->ops) 552 frontend_ops = &fe->ops;
556 frontend_ops = &fe->ops; 553 tuner_ops = &frontend_ops->tuner_ops;
557
558 if (&frontend_ops->tuner_ops)
559 tuner_ops = &frontend_ops->tuner_ops;
560 554
561 if (tuner_ops->set_bandwidth) { 555 if (tuner_ops->set_bandwidth) {
562 if ((tuner_ops->set_bandwidth(fe, bandwidth)) < 0) 556 if ((tuner_ops->set_bandwidth(fe, bandwidth)) < 0)
@@ -1558,6 +1552,27 @@ static int stv0900_status(struct stv0900_internal *intp,
1558 return locked; 1552 return locked;
1559} 1553}
1560 1554
1555static int stv0900_set_mis(struct stv0900_internal *intp,
1556 enum fe_stv0900_demod_num demod, int mis)
1557{
1558 enum fe_stv0900_error error = STV0900_NO_ERROR;
1559
1560 dprintk("%s\n", __func__);
1561
1562 if (mis < 0 || mis > 255) {
1563 dprintk("Disable MIS filtering\n");
1564 stv0900_write_bits(intp, FILTER_EN, 0);
1565 } else {
1566 dprintk("Enable MIS filtering - %d\n", mis);
1567 stv0900_write_bits(intp, FILTER_EN, 1);
1568 stv0900_write_reg(intp, ISIENTRY, mis);
1569 stv0900_write_reg(intp, ISIBITENA, 0xff);
1570 }
1571
1572 return error;
1573}
1574
1575
1561static enum dvbfe_search stv0900_search(struct dvb_frontend *fe) 1576static enum dvbfe_search stv0900_search(struct dvb_frontend *fe)
1562{ 1577{
1563 struct stv0900_state *state = fe->demodulator_priv; 1578 struct stv0900_state *state = fe->demodulator_priv;
@@ -1578,6 +1593,8 @@ static enum dvbfe_search stv0900_search(struct dvb_frontend *fe)
1578 if (state->config->set_ts_params) 1593 if (state->config->set_ts_params)
1579 state->config->set_ts_params(fe, 0); 1594 state->config->set_ts_params(fe, 0);
1580 1595
1596 stv0900_set_mis(intp, demod, c->stream_id);
1597
1581 p_result.locked = FALSE; 1598 p_result.locked = FALSE;
1582 p_search.path = demod; 1599 p_search.path = demod;
1583 p_search.frequency = c->frequency; 1600 p_search.frequency = c->frequency;
@@ -1935,6 +1952,9 @@ struct dvb_frontend *stv0900_attach(const struct stv0900_config *config,
1935 if (err_stv0900) 1952 if (err_stv0900)
1936 goto error; 1953 goto error;
1937 1954
1955 if (state->internal->chip_id >= 0x30)
1956 state->frontend.ops.info.caps |= FE_CAN_MULTISTREAM;
1957
1938 break; 1958 break;
1939 default: 1959 default:
1940 goto error; 1960 goto error;
diff --git a/drivers/media/dvb-frontends/stv0900_reg.h b/drivers/media/dvb-frontends/stv0900_reg.h
index 731afe93a823..511ed2a2d987 100644
--- a/drivers/media/dvb-frontends/stv0900_reg.h
+++ b/drivers/media/dvb-frontends/stv0900_reg.h
@@ -3446,8 +3446,11 @@ extern s32 shiftx(s32 x, int demod, s32 shift);
3446#define R0900_P1_PDELCTRL1 0xf550 3446#define R0900_P1_PDELCTRL1 0xf550
3447#define PDELCTRL1 REGx(R0900_P1_PDELCTRL1) 3447#define PDELCTRL1 REGx(R0900_P1_PDELCTRL1)
3448#define F0900_P1_INV_MISMASK 0xf5500080 3448#define F0900_P1_INV_MISMASK 0xf5500080
3449#define INV_MISMASK FLDx(F0900_P1_INV_MISMASK)
3449#define F0900_P1_FILTER_EN 0xf5500020 3450#define F0900_P1_FILTER_EN 0xf5500020
3451#define FILTER_EN FLDx(F0900_P1_FILTER_EN)
3450#define F0900_P1_EN_MIS00 0xf5500002 3452#define F0900_P1_EN_MIS00 0xf5500002
3453#define EN_MIS00 FLDx(F0900_P1_EN_MIS00)
3451#define F0900_P1_ALGOSWRST 0xf5500001 3454#define F0900_P1_ALGOSWRST 0xf5500001
3452#define ALGOSWRST FLDx(F0900_P1_ALGOSWRST) 3455#define ALGOSWRST FLDx(F0900_P1_ALGOSWRST)
3453 3456
diff --git a/drivers/media/dvb-frontends/stv0900_sw.c b/drivers/media/dvb-frontends/stv0900_sw.c
index 4af20780fb9c..0a40edfad739 100644
--- a/drivers/media/dvb-frontends/stv0900_sw.c
+++ b/drivers/media/dvb-frontends/stv0900_sw.c
@@ -1167,11 +1167,8 @@ static u32 stv0900_get_tuner_freq(struct dvb_frontend *fe)
1167 struct dvb_tuner_ops *tuner_ops = NULL; 1167 struct dvb_tuner_ops *tuner_ops = NULL;
1168 u32 freq = 0; 1168 u32 freq = 0;
1169 1169
1170 if (&fe->ops) 1170 frontend_ops = &fe->ops;
1171 frontend_ops = &fe->ops; 1171 tuner_ops = &frontend_ops->tuner_ops;
1172
1173 if (&frontend_ops->tuner_ops)
1174 tuner_ops = &frontend_ops->tuner_ops;
1175 1172
1176 if (tuner_ops->get_frequency) { 1173 if (tuner_ops->get_frequency) {
1177 if ((tuner_ops->get_frequency(fe, &freq)) < 0) 1174 if ((tuner_ops->get_frequency(fe, &freq)) < 0)
diff --git a/drivers/media/dvb-frontends/stv090x.c b/drivers/media/dvb-frontends/stv090x.c
index 13caec013902..f36eeefb76a6 100644
--- a/drivers/media/dvb-frontends/stv090x.c
+++ b/drivers/media/dvb-frontends/stv090x.c
@@ -4267,7 +4267,7 @@ err:
4267 return -1; 4267 return -1;
4268} 4268}
4269 4269
4270static int stv090x_set_tspath(struct stv090x_state *state) 4270static int stv0900_set_tspath(struct stv090x_state *state)
4271{ 4271{
4272 u32 reg; 4272 u32 reg;
4273 4273
@@ -4538,6 +4538,121 @@ err:
4538 return -1; 4538 return -1;
4539} 4539}
4540 4540
4541static int stv0903_set_tspath(struct stv090x_state *state)
4542{
4543 u32 reg;
4544
4545 if (state->internal->dev_ver >= 0x20) {
4546 switch (state->config->ts1_mode) {
4547 case STV090x_TSMODE_PARALLEL_PUNCTURED:
4548 case STV090x_TSMODE_DVBCI:
4549 stv090x_write_reg(state, STV090x_TSGENERAL, 0x00);
4550 break;
4551
4552 case STV090x_TSMODE_SERIAL_PUNCTURED:
4553 case STV090x_TSMODE_SERIAL_CONTINUOUS:
4554 default:
4555 stv090x_write_reg(state, STV090x_TSGENERAL, 0x0c);
4556 break;
4557 }
4558 } else {
4559 switch (state->config->ts1_mode) {
4560 case STV090x_TSMODE_PARALLEL_PUNCTURED:
4561 case STV090x_TSMODE_DVBCI:
4562 stv090x_write_reg(state, STV090x_TSGENERAL1X, 0x10);
4563 break;
4564
4565 case STV090x_TSMODE_SERIAL_PUNCTURED:
4566 case STV090x_TSMODE_SERIAL_CONTINUOUS:
4567 default:
4568 stv090x_write_reg(state, STV090x_TSGENERAL1X, 0x14);
4569 break;
4570 }
4571 }
4572
4573 switch (state->config->ts1_mode) {
4574 case STV090x_TSMODE_PARALLEL_PUNCTURED:
4575 reg = stv090x_read_reg(state, STV090x_P1_TSCFGH);
4576 STV090x_SETFIELD_Px(reg, TSFIFO_SERIAL_FIELD, 0x00);
4577 STV090x_SETFIELD_Px(reg, TSFIFO_DVBCI_FIELD, 0x00);
4578 if (stv090x_write_reg(state, STV090x_P1_TSCFGH, reg) < 0)
4579 goto err;
4580 break;
4581
4582 case STV090x_TSMODE_DVBCI:
4583 reg = stv090x_read_reg(state, STV090x_P1_TSCFGH);
4584 STV090x_SETFIELD_Px(reg, TSFIFO_SERIAL_FIELD, 0x00);
4585 STV090x_SETFIELD_Px(reg, TSFIFO_DVBCI_FIELD, 0x01);
4586 if (stv090x_write_reg(state, STV090x_P1_TSCFGH, reg) < 0)
4587 goto err;
4588 break;
4589
4590 case STV090x_TSMODE_SERIAL_PUNCTURED:
4591 reg = stv090x_read_reg(state, STV090x_P1_TSCFGH);
4592 STV090x_SETFIELD_Px(reg, TSFIFO_SERIAL_FIELD, 0x01);
4593 STV090x_SETFIELD_Px(reg, TSFIFO_DVBCI_FIELD, 0x00);
4594 if (stv090x_write_reg(state, STV090x_P1_TSCFGH, reg) < 0)
4595 goto err;
4596 break;
4597
4598 case STV090x_TSMODE_SERIAL_CONTINUOUS:
4599 reg = stv090x_read_reg(state, STV090x_P1_TSCFGH);
4600 STV090x_SETFIELD_Px(reg, TSFIFO_SERIAL_FIELD, 0x01);
4601 STV090x_SETFIELD_Px(reg, TSFIFO_DVBCI_FIELD, 0x01);
4602 if (stv090x_write_reg(state, STV090x_P1_TSCFGH, reg) < 0)
4603 goto err;
4604 break;
4605
4606 default:
4607 break;
4608 }
4609
4610 if (state->config->ts1_clk > 0) {
4611 u32 speed;
4612
4613 switch (state->config->ts1_mode) {
4614 case STV090x_TSMODE_PARALLEL_PUNCTURED:
4615 case STV090x_TSMODE_DVBCI:
4616 default:
4617 speed = state->internal->mclk /
4618 (state->config->ts1_clk / 4);
4619 if (speed < 0x08)
4620 speed = 0x08;
4621 if (speed > 0xFF)
4622 speed = 0xFF;
4623 break;
4624 case STV090x_TSMODE_SERIAL_PUNCTURED:
4625 case STV090x_TSMODE_SERIAL_CONTINUOUS:
4626 speed = state->internal->mclk /
4627 (state->config->ts1_clk / 32);
4628 if (speed < 0x20)
4629 speed = 0x20;
4630 if (speed > 0xFF)
4631 speed = 0xFF;
4632 break;
4633 }
4634 reg = stv090x_read_reg(state, STV090x_P1_TSCFGM);
4635 STV090x_SETFIELD_Px(reg, TSFIFO_MANSPEED_FIELD, 3);
4636 if (stv090x_write_reg(state, STV090x_P1_TSCFGM, reg) < 0)
4637 goto err;
4638 if (stv090x_write_reg(state, STV090x_P1_TSSPEED, speed) < 0)
4639 goto err;
4640 }
4641
4642 reg = stv090x_read_reg(state, STV090x_P1_TSCFGH);
4643 STV090x_SETFIELD_Px(reg, RST_HWARE_FIELD, 0x01);
4644 if (stv090x_write_reg(state, STV090x_P1_TSCFGH, reg) < 0)
4645 goto err;
4646 STV090x_SETFIELD_Px(reg, RST_HWARE_FIELD, 0x00);
4647 if (stv090x_write_reg(state, STV090x_P1_TSCFGH, reg) < 0)
4648 goto err;
4649
4650 return 0;
4651err:
4652 dprintk(FE_ERROR, 1, "I/O error");
4653 return -1;
4654}
4655
4541static int stv090x_init(struct dvb_frontend *fe) 4656static int stv090x_init(struct dvb_frontend *fe)
4542{ 4657{
4543 struct stv090x_state *state = fe->demodulator_priv; 4658 struct stv090x_state *state = fe->demodulator_priv;
@@ -4600,8 +4715,13 @@ static int stv090x_init(struct dvb_frontend *fe)
4600 if (stv090x_i2c_gate_ctrl(state, 0) < 0) 4715 if (stv090x_i2c_gate_ctrl(state, 0) < 0)
4601 goto err; 4716 goto err;
4602 4717
4603 if (stv090x_set_tspath(state) < 0) 4718 if (state->device == STV0900) {
4604 goto err; 4719 if (stv0900_set_tspath(state) < 0)
4720 goto err;
4721 } else {
4722 if (stv0903_set_tspath(state) < 0)
4723 goto err;
4724 }
4605 4725
4606 return 0; 4726 return 0;
4607 4727
@@ -4642,23 +4762,26 @@ static int stv090x_setup(struct dvb_frontend *fe)
4642 /* Stop Demod */ 4762 /* Stop Demod */
4643 if (stv090x_write_reg(state, STV090x_P1_DMDISTATE, 0x5c) < 0) 4763 if (stv090x_write_reg(state, STV090x_P1_DMDISTATE, 0x5c) < 0)
4644 goto err; 4764 goto err;
4645 if (stv090x_write_reg(state, STV090x_P2_DMDISTATE, 0x5c) < 0) 4765 if (state->device == STV0900)
4646 goto err; 4766 if (stv090x_write_reg(state, STV090x_P2_DMDISTATE, 0x5c) < 0)
4767 goto err;
4647 4768
4648 msleep(5); 4769 msleep(5);
4649 4770
4650 /* Set No Tuner Mode */ 4771 /* Set No Tuner Mode */
4651 if (stv090x_write_reg(state, STV090x_P1_TNRCFG, 0x6c) < 0) 4772 if (stv090x_write_reg(state, STV090x_P1_TNRCFG, 0x6c) < 0)
4652 goto err; 4773 goto err;
4653 if (stv090x_write_reg(state, STV090x_P2_TNRCFG, 0x6c) < 0) 4774 if (state->device == STV0900)
4654 goto err; 4775 if (stv090x_write_reg(state, STV090x_P2_TNRCFG, 0x6c) < 0)
4776 goto err;
4655 4777
4656 /* I2C repeater OFF */ 4778 /* I2C repeater OFF */
4657 STV090x_SETFIELD_Px(reg, ENARPT_LEVEL_FIELD, config->repeater_level); 4779 STV090x_SETFIELD_Px(reg, ENARPT_LEVEL_FIELD, config->repeater_level);
4658 if (stv090x_write_reg(state, STV090x_P1_I2CRPT, reg) < 0) 4780 if (stv090x_write_reg(state, STV090x_P1_I2CRPT, reg) < 0)
4659 goto err; 4781 goto err;
4660 if (stv090x_write_reg(state, STV090x_P2_I2CRPT, reg) < 0) 4782 if (state->device == STV0900)
4661 goto err; 4783 if (stv090x_write_reg(state, STV090x_P2_I2CRPT, reg) < 0)
4784 goto err;
4662 4785
4663 if (stv090x_write_reg(state, STV090x_NCOARSE, 0x13) < 0) /* set PLL divider */ 4786 if (stv090x_write_reg(state, STV090x_NCOARSE, 0x13) < 0) /* set PLL divider */
4664 goto err; 4787 goto err;
diff --git a/drivers/media/dvb-frontends/stv090x.h b/drivers/media/dvb-frontends/stv090x.h
index 29cdc2b71314..0bd6adcfee8a 100644
--- a/drivers/media/dvb-frontends/stv090x.h
+++ b/drivers/media/dvb-frontends/stv090x.h
@@ -103,7 +103,7 @@ struct stv090x_config {
103 void (*tuner_i2c_lock) (struct dvb_frontend *fe, int lock); 103 void (*tuner_i2c_lock) (struct dvb_frontend *fe, int lock);
104}; 104};
105 105
106#if defined(CONFIG_DVB_STV090x) || (defined(CONFIG_DVB_STV090x_MODULE) && defined(MODULE)) 106#if IS_ENABLED(CONFIG_DVB_STV090x)
107 107
108extern struct dvb_frontend *stv090x_attach(const struct stv090x_config *config, 108extern struct dvb_frontend *stv090x_attach(const struct stv090x_config *config,
109 struct i2c_adapter *i2c, 109 struct i2c_adapter *i2c,
diff --git a/drivers/media/dvb-frontends/stv6110x.h b/drivers/media/dvb-frontends/stv6110x.h
index 47516753929a..bc4766db29c5 100644
--- a/drivers/media/dvb-frontends/stv6110x.h
+++ b/drivers/media/dvb-frontends/stv6110x.h
@@ -53,7 +53,7 @@ struct stv6110x_devctl {
53}; 53};
54 54
55 55
56#if defined(CONFIG_DVB_STV6110x) || (defined(CONFIG_DVB_STV6110x_MODULE) && defined(MODULE)) 56#if IS_ENABLED(CONFIG_DVB_STV6110x)
57 57
58extern struct stv6110x_devctl *stv6110x_attach(struct dvb_frontend *fe, 58extern struct stv6110x_devctl *stv6110x_attach(struct dvb_frontend *fe,
59 const struct stv6110x_config *config, 59 const struct stv6110x_config *config,
diff --git a/drivers/media/dvb-frontends/tda1002x.h b/drivers/media/dvb-frontends/tda1002x.h
index 04d19418bf20..e404b6e44802 100644
--- a/drivers/media/dvb-frontends/tda1002x.h
+++ b/drivers/media/dvb-frontends/tda1002x.h
@@ -57,7 +57,7 @@ struct tda10023_config {
57 u16 deltaf; 57 u16 deltaf;
58}; 58};
59 59
60#if defined(CONFIG_DVB_TDA10021) || (defined(CONFIG_DVB_TDA10021_MODULE) && defined(MODULE)) 60#if IS_ENABLED(CONFIG_DVB_TDA10021)
61extern struct dvb_frontend* tda10021_attach(const struct tda1002x_config* config, 61extern struct dvb_frontend* tda10021_attach(const struct tda1002x_config* config,
62 struct i2c_adapter* i2c, u8 pwm); 62 struct i2c_adapter* i2c, u8 pwm);
63#else 63#else
@@ -69,8 +69,7 @@ static inline struct dvb_frontend* tda10021_attach(const struct tda1002x_config*
69} 69}
70#endif // CONFIG_DVB_TDA10021 70#endif // CONFIG_DVB_TDA10021
71 71
72#if defined(CONFIG_DVB_TDA10023) || \ 72#if IS_ENABLED(CONFIG_DVB_TDA10023)
73 (defined(CONFIG_DVB_TDA10023_MODULE) && defined(MODULE))
74extern struct dvb_frontend *tda10023_attach( 73extern struct dvb_frontend *tda10023_attach(
75 const struct tda10023_config *config, 74 const struct tda10023_config *config,
76 struct i2c_adapter *i2c, u8 pwm); 75 struct i2c_adapter *i2c, u8 pwm);
diff --git a/drivers/media/dvb-frontends/tda1004x.h b/drivers/media/dvb-frontends/tda1004x.h
index 4e27ffb0f14e..dd283fbb61c0 100644
--- a/drivers/media/dvb-frontends/tda1004x.h
+++ b/drivers/media/dvb-frontends/tda1004x.h
@@ -117,7 +117,7 @@ struct tda1004x_state {
117 enum tda1004x_demod demod_type; 117 enum tda1004x_demod demod_type;
118}; 118};
119 119
120#if defined(CONFIG_DVB_TDA1004X) || (defined(CONFIG_DVB_TDA1004X_MODULE) && defined(MODULE)) 120#if IS_ENABLED(CONFIG_DVB_TDA1004X)
121extern struct dvb_frontend* tda10045_attach(const struct tda1004x_config* config, 121extern struct dvb_frontend* tda10045_attach(const struct tda1004x_config* config,
122 struct i2c_adapter* i2c); 122 struct i2c_adapter* i2c);
123 123
diff --git a/drivers/media/dvb-frontends/tda10071.c b/drivers/media/dvb-frontends/tda10071.c
index 16a4bc54dbe7..2521f7e23018 100644
--- a/drivers/media/dvb-frontends/tda10071.c
+++ b/drivers/media/dvb-frontends/tda10071.c
@@ -30,7 +30,7 @@ static int tda10071_wr_regs(struct tda10071_priv *priv, u8 reg, u8 *val,
30 u8 buf[len+1]; 30 u8 buf[len+1];
31 struct i2c_msg msg[1] = { 31 struct i2c_msg msg[1] = {
32 { 32 {
33 .addr = priv->cfg.i2c_address, 33 .addr = priv->cfg.demod_i2c_addr,
34 .flags = 0, 34 .flags = 0,
35 .len = sizeof(buf), 35 .len = sizeof(buf),
36 .buf = buf, 36 .buf = buf,
@@ -59,12 +59,12 @@ static int tda10071_rd_regs(struct tda10071_priv *priv, u8 reg, u8 *val,
59 u8 buf[len]; 59 u8 buf[len];
60 struct i2c_msg msg[2] = { 60 struct i2c_msg msg[2] = {
61 { 61 {
62 .addr = priv->cfg.i2c_address, 62 .addr = priv->cfg.demod_i2c_addr,
63 .flags = 0, 63 .flags = 0,
64 .len = 1, 64 .len = 1,
65 .buf = &reg, 65 .buf = &reg,
66 }, { 66 }, {
67 .addr = priv->cfg.i2c_address, 67 .addr = priv->cfg.demod_i2c_addr,
68 .flags = I2C_M_RD, 68 .flags = I2C_M_RD,
69 .len = sizeof(buf), 69 .len = sizeof(buf),
70 .buf = buf, 70 .buf = buf,
@@ -1064,7 +1064,7 @@ static int tda10071_init(struct dvb_frontend *fe)
1064 cmd.args[2] = 0x00; 1064 cmd.args[2] = 0x00;
1065 cmd.args[3] = 0x00; 1065 cmd.args[3] = 0x00;
1066 cmd.args[4] = 0x00; 1066 cmd.args[4] = 0x00;
1067 cmd.args[5] = 0x14; 1067 cmd.args[5] = (priv->cfg.tuner_i2c_addr) ? priv->cfg.tuner_i2c_addr : 0x14;
1068 cmd.args[6] = 0x00; 1068 cmd.args[6] = 0x00;
1069 cmd.args[7] = 0x03; 1069 cmd.args[7] = 0x03;
1070 cmd.args[8] = 0x02; 1070 cmd.args[8] = 0x02;
@@ -1202,6 +1202,20 @@ struct dvb_frontend *tda10071_attach(const struct tda10071_config *config,
1202 goto error; 1202 goto error;
1203 } 1203 }
1204 1204
1205 /* make sure demod i2c address is specified */
1206 if (!config->demod_i2c_addr) {
1207 dev_dbg(&i2c->dev, "%s: invalid demod i2c address!\n", __func__);
1208 ret = -EINVAL;
1209 goto error;
1210 }
1211
1212 /* make sure tuner i2c address is specified */
1213 if (!config->tuner_i2c_addr) {
1214 dev_dbg(&i2c->dev, "%s: invalid tuner i2c address!\n", __func__);
1215 ret = -EINVAL;
1216 goto error;
1217 }
1218
1205 /* setup the priv */ 1219 /* setup the priv */
1206 priv->i2c = i2c; 1220 priv->i2c = i2c;
1207 memcpy(&priv->cfg, config, sizeof(struct tda10071_config)); 1221 memcpy(&priv->cfg, config, sizeof(struct tda10071_config));
diff --git a/drivers/media/dvb-frontends/tda10071.h b/drivers/media/dvb-frontends/tda10071.h
index 21163c4b555c..bff1c38df802 100644
--- a/drivers/media/dvb-frontends/tda10071.h
+++ b/drivers/media/dvb-frontends/tda10071.h
@@ -28,7 +28,13 @@ struct tda10071_config {
28 * Default: none, must set 28 * Default: none, must set
29 * Values: 0x55, 29 * Values: 0x55,
30 */ 30 */
31 u8 i2c_address; 31 u8 demod_i2c_addr;
32
33 /* Tuner I2C address.
34 * Default: none, must set
35 * Values: 0x14, 0x54, ...
36 */
37 u8 tuner_i2c_addr;
32 38
33 /* Max bytes I2C provider can write at once. 39 /* Max bytes I2C provider can write at once.
34 * Note: Buffer is taken from the stack currently! 40 * Note: Buffer is taken from the stack currently!
diff --git a/drivers/media/dvb-frontends/tda10086.h b/drivers/media/dvb-frontends/tda10086.h
index 61148c558d8d..458fe91c1b88 100644
--- a/drivers/media/dvb-frontends/tda10086.h
+++ b/drivers/media/dvb-frontends/tda10086.h
@@ -46,7 +46,7 @@ struct tda10086_config
46 enum tda10086_xtal xtal_freq; 46 enum tda10086_xtal xtal_freq;
47}; 47};
48 48
49#if defined(CONFIG_DVB_TDA10086) || (defined(CONFIG_DVB_TDA10086_MODULE) && defined(MODULE)) 49#if IS_ENABLED(CONFIG_DVB_TDA10086)
50extern struct dvb_frontend* tda10086_attach(const struct tda10086_config* config, 50extern struct dvb_frontend* tda10086_attach(const struct tda10086_config* config,
51 struct i2c_adapter* i2c); 51 struct i2c_adapter* i2c);
52#else 52#else
diff --git a/drivers/media/dvb-frontends/tda665x.h b/drivers/media/dvb-frontends/tda665x.h
index ec7927aa75ae..03a0da6d5cf2 100644
--- a/drivers/media/dvb-frontends/tda665x.h
+++ b/drivers/media/dvb-frontends/tda665x.h
@@ -31,7 +31,7 @@ struct tda665x_config {
31 u32 ref_divider; 31 u32 ref_divider;
32}; 32};
33 33
34#if defined(CONFIG_DVB_TDA665x) || (defined(CONFIG_DVB_TDA665x_MODULE) && defined(MODULE)) 34#if IS_ENABLED(CONFIG_DVB_TDA665x)
35 35
36extern struct dvb_frontend *tda665x_attach(struct dvb_frontend *fe, 36extern struct dvb_frontend *tda665x_attach(struct dvb_frontend *fe,
37 const struct tda665x_config *config, 37 const struct tda665x_config *config,
diff --git a/drivers/media/dvb-frontends/tda8083.h b/drivers/media/dvb-frontends/tda8083.h
index 5a03c14a10e8..de6b1860dfdd 100644
--- a/drivers/media/dvb-frontends/tda8083.h
+++ b/drivers/media/dvb-frontends/tda8083.h
@@ -35,7 +35,7 @@ struct tda8083_config
35 u8 demod_address; 35 u8 demod_address;
36}; 36};
37 37
38#if defined(CONFIG_DVB_TDA8083) || (defined(CONFIG_DVB_TDA8083_MODULE) && defined(MODULE)) 38#if IS_ENABLED(CONFIG_DVB_TDA8083)
39extern struct dvb_frontend* tda8083_attach(const struct tda8083_config* config, 39extern struct dvb_frontend* tda8083_attach(const struct tda8083_config* config,
40 struct i2c_adapter* i2c); 40 struct i2c_adapter* i2c);
41#else 41#else
diff --git a/drivers/media/dvb-frontends/tda8261.h b/drivers/media/dvb-frontends/tda8261.h
index 006e45351b94..55cf4ffcbfdf 100644
--- a/drivers/media/dvb-frontends/tda8261.h
+++ b/drivers/media/dvb-frontends/tda8261.h
@@ -34,7 +34,7 @@ struct tda8261_config {
34 enum tda8261_step step_size; 34 enum tda8261_step step_size;
35}; 35};
36 36
37#if defined(CONFIG_DVB_TDA8261) || (defined(CONFIG_DVB_TDA8261_MODULE) && defined(MODULE)) 37#if IS_ENABLED(CONFIG_DVB_TDA8261)
38 38
39extern struct dvb_frontend *tda8261_attach(struct dvb_frontend *fe, 39extern struct dvb_frontend *tda8261_attach(struct dvb_frontend *fe,
40 const struct tda8261_config *config, 40 const struct tda8261_config *config,
diff --git a/drivers/media/dvb-frontends/tda8261_cfg.h b/drivers/media/dvb-frontends/tda8261_cfg.h
index 1af1ee49b542..46710744173b 100644
--- a/drivers/media/dvb-frontends/tda8261_cfg.h
+++ b/drivers/media/dvb-frontends/tda8261_cfg.h
@@ -78,7 +78,7 @@ static int tda8261_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
78 return err; 78 return err;
79 } 79 }
80 *bandwidth = t_state.bandwidth; 80 *bandwidth = t_state.bandwidth;
81 printk("%s: Bandwidth=%d\n", __func__, t_state.bandwidth);
81 } 82 }
82 printk("%s: Bandwidth=%d\n", __func__, t_state.bandwidth);
83 return 0; 83 return 0;
84} 84}
diff --git a/drivers/media/dvb-frontends/tda826x.h b/drivers/media/dvb-frontends/tda826x.h
index 89e97926ab23..5f0f20e7e4f8 100644
--- a/drivers/media/dvb-frontends/tda826x.h
+++ b/drivers/media/dvb-frontends/tda826x.h
@@ -35,7 +35,7 @@
35 * @param has_loopthrough Set to 1 if the card has a loopthrough RF connector. 35 * @param has_loopthrough Set to 1 if the card has a loopthrough RF connector.
36 * @return FE pointer on success, NULL on failure. 36 * @return FE pointer on success, NULL on failure.
37 */ 37 */
38#if defined(CONFIG_DVB_TDA826X) || (defined(CONFIG_DVB_TDA826X_MODULE) && defined(MODULE)) 38#if IS_ENABLED(CONFIG_DVB_TDA826X)
39extern struct dvb_frontend* tda826x_attach(struct dvb_frontend *fe, int addr, 39extern struct dvb_frontend* tda826x_attach(struct dvb_frontend *fe, int addr,
40 struct i2c_adapter *i2c, 40 struct i2c_adapter *i2c,
41 int has_loopthrough); 41 int has_loopthrough);
diff --git a/drivers/media/dvb-frontends/ts2020.c b/drivers/media/dvb-frontends/ts2020.c
new file mode 100644
index 000000000000..ad7ad857ab2a
--- /dev/null
+++ b/drivers/media/dvb-frontends/ts2020.c
@@ -0,0 +1,373 @@
1/*
2 Montage Technology TS2020 - Silicon Tuner driver
3 Copyright (C) 2009-2012 Konstantin Dimitrov <kosio.dimitrov@gmail.com>
4
5 Copyright (C) 2009-2012 TurboSight.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 as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22#include "dvb_frontend.h"
23#include "ts2020.h"
24
25#define TS2020_XTAL_FREQ 27000 /* in kHz */
26#define FREQ_OFFSET_LOW_SYM_RATE 3000
27
28struct ts2020_priv {
29 /* i2c details */
30 int i2c_address;
31 struct i2c_adapter *i2c;
32 u8 clk_out_div;
33 u32 frequency;
34};
35
36static int ts2020_release(struct dvb_frontend *fe)
37{
38 kfree(fe->tuner_priv);
39 fe->tuner_priv = NULL;
40 return 0;
41}
42
43static int ts2020_writereg(struct dvb_frontend *fe, int reg, int data)
44{
45 struct ts2020_priv *priv = fe->tuner_priv;
46 u8 buf[] = { reg, data };
47 struct i2c_msg msg[] = {
48 {
49 .addr = priv->i2c_address,
50 .flags = 0,
51 .buf = buf,
52 .len = 2
53 }
54 };
55 int err;
56
57 if (fe->ops.i2c_gate_ctrl)
58 fe->ops.i2c_gate_ctrl(fe, 1);
59
60 err = i2c_transfer(priv->i2c, msg, 1);
61 if (err != 1) {
62 printk(KERN_ERR
63 "%s: writereg error(err == %i, reg == 0x%02x, value == 0x%02x)\n",
64 __func__, err, reg, data);
65 return -EREMOTEIO;
66 }
67
68 if (fe->ops.i2c_gate_ctrl)
69 fe->ops.i2c_gate_ctrl(fe, 0);
70
71 return 0;
72}
73
74static int ts2020_readreg(struct dvb_frontend *fe, u8 reg)
75{
76 struct ts2020_priv *priv = fe->tuner_priv;
77 int ret;
78 u8 b0[] = { reg };
79 u8 b1[] = { 0 };
80 struct i2c_msg msg[] = {
81 {
82 .addr = priv->i2c_address,
83 .flags = 0,
84 .buf = b0,
85 .len = 1
86 }, {
87 .addr = priv->i2c_address,
88 .flags = I2C_M_RD,
89 .buf = b1,
90 .len = 1
91 }
92 };
93
94 if (fe->ops.i2c_gate_ctrl)
95 fe->ops.i2c_gate_ctrl(fe, 1);
96
97 ret = i2c_transfer(priv->i2c, msg, 2);
98
99 if (ret != 2) {
100 printk(KERN_ERR "%s: reg=0x%x(error=%d)\n",
101 __func__, reg, ret);
102 return ret;
103 }
104
105 if (fe->ops.i2c_gate_ctrl)
106 fe->ops.i2c_gate_ctrl(fe, 0);
107
108 return b1[0];
109}
110
111static int ts2020_sleep(struct dvb_frontend *fe)
112{
113 struct ts2020_priv *priv = fe->tuner_priv;
114 int ret;
115 u8 buf[] = { 10, 0 };
116 struct i2c_msg msg = {
117 .addr = priv->i2c_address,
118 .flags = 0,
119 .buf = buf,
120 .len = 2
121 };
122
123 if (fe->ops.i2c_gate_ctrl)
124 fe->ops.i2c_gate_ctrl(fe, 1);
125
126 ret = i2c_transfer(priv->i2c, &msg, 1);
127 if (ret != 1)
128 printk(KERN_ERR "%s: i2c error\n", __func__);
129
130 if (fe->ops.i2c_gate_ctrl)
131 fe->ops.i2c_gate_ctrl(fe, 0);
132
133 return (ret == 1) ? 0 : ret;
134}
135
136static int ts2020_init(struct dvb_frontend *fe)
137{
138 struct ts2020_priv *priv = fe->tuner_priv;
139
140 ts2020_writereg(fe, 0x42, 0x73);
141 ts2020_writereg(fe, 0x05, priv->clk_out_div);
142 ts2020_writereg(fe, 0x20, 0x27);
143 ts2020_writereg(fe, 0x07, 0x02);
144 ts2020_writereg(fe, 0x11, 0xff);
145 ts2020_writereg(fe, 0x60, 0xf9);
146 ts2020_writereg(fe, 0x08, 0x01);
147 ts2020_writereg(fe, 0x00, 0x41);
148
149 return 0;
150}
151
152static int ts2020_tuner_gate_ctrl(struct dvb_frontend *fe, u8 offset)
153{
154 int ret;
155 ret = ts2020_writereg(fe, 0x51, 0x1f - offset);
156 ret |= ts2020_writereg(fe, 0x51, 0x1f);
157 ret |= ts2020_writereg(fe, 0x50, offset);
158 ret |= ts2020_writereg(fe, 0x50, 0x00);
159 msleep(20);
160 return ret;
161}
162
163static int ts2020_set_tuner_rf(struct dvb_frontend *fe)
164{
165 int reg;
166
167 reg = ts2020_readreg(fe, 0x3d);
168 reg &= 0x7f;
169 if (reg < 0x16)
170 reg = 0xa1;
171 else if (reg == 0x16)
172 reg = 0x99;
173 else
174 reg = 0xf9;
175
176 ts2020_writereg(fe, 0x60, reg);
177 reg = ts2020_tuner_gate_ctrl(fe, 0x08);
178
179 return reg;
180}
181
182static int ts2020_set_params(struct dvb_frontend *fe)
183{
184 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
185 struct ts2020_priv *priv = fe->tuner_priv;
186 int ret;
187 u32 frequency = c->frequency;
188 s32 offset_khz;
189 u32 symbol_rate = (c->symbol_rate / 1000);
190 u32 f3db, gdiv28;
191 u16 value, ndiv, lpf_coeff;
192 u8 lpf_mxdiv, mlpf_max, mlpf_min, nlpf;
193 u8 lo = 0x01, div4 = 0x0;
194
195 /* Calculate frequency divider */
196 if (frequency < 1060000) {
197 lo |= 0x10;
198 div4 = 0x1;
199 ndiv = (frequency * 14 * 4) / TS2020_XTAL_FREQ;
200 } else
201 ndiv = (frequency * 14 * 2) / TS2020_XTAL_FREQ;
202 ndiv = ndiv + ndiv % 2;
203 ndiv = ndiv - 1024;
204
205 ret = ts2020_writereg(fe, 0x10, 0x80 | lo);
206
207 /* Set frequency divider */
208 ret |= ts2020_writereg(fe, 0x01, (ndiv >> 8) & 0xf);
209 ret |= ts2020_writereg(fe, 0x02, ndiv & 0xff);
210
211 ret |= ts2020_writereg(fe, 0x03, 0x06);
212 ret |= ts2020_tuner_gate_ctrl(fe, 0x10);
213 if (ret < 0)
214 return -ENODEV;
215
216 /* Tuner Frequency Range */
217 ret = ts2020_writereg(fe, 0x10, lo);
218
219 ret |= ts2020_tuner_gate_ctrl(fe, 0x08);
220
221 /* Tuner RF */
222 ret |= ts2020_set_tuner_rf(fe);
223
224 gdiv28 = (TS2020_XTAL_FREQ / 1000 * 1694 + 500) / 1000;
225 ret |= ts2020_writereg(fe, 0x04, gdiv28 & 0xff);
226 ret |= ts2020_tuner_gate_ctrl(fe, 0x04);
227 if (ret < 0)
228 return -ENODEV;
229
230 value = ts2020_readreg(fe, 0x26);
231
232 f3db = (symbol_rate * 135) / 200 + 2000;
233 f3db += FREQ_OFFSET_LOW_SYM_RATE;
234 if (f3db < 7000)
235 f3db = 7000;
236 if (f3db > 40000)
237 f3db = 40000;
238
239 gdiv28 = gdiv28 * 207 / (value * 2 + 151);
240 mlpf_max = gdiv28 * 135 / 100;
241 mlpf_min = gdiv28 * 78 / 100;
242 if (mlpf_max > 63)
243 mlpf_max = 63;
244
245 lpf_coeff = 2766;
246
247 nlpf = (f3db * gdiv28 * 2 / lpf_coeff /
248 (TS2020_XTAL_FREQ / 1000) + 1) / 2;
249 if (nlpf > 23)
250 nlpf = 23;
251 if (nlpf < 1)
252 nlpf = 1;
253
254 lpf_mxdiv = (nlpf * (TS2020_XTAL_FREQ / 1000)
255 * lpf_coeff * 2 / f3db + 1) / 2;
256
257 if (lpf_mxdiv < mlpf_min) {
258 nlpf++;
259 lpf_mxdiv = (nlpf * (TS2020_XTAL_FREQ / 1000)
260 * lpf_coeff * 2 / f3db + 1) / 2;
261 }
262
263 if (lpf_mxdiv > mlpf_max)
264 lpf_mxdiv = mlpf_max;
265
266 ret = ts2020_writereg(fe, 0x04, lpf_mxdiv);
267 ret |= ts2020_writereg(fe, 0x06, nlpf);
268
269 ret |= ts2020_tuner_gate_ctrl(fe, 0x04);
270
271 ret |= ts2020_tuner_gate_ctrl(fe, 0x01);
272
273 msleep(80);
274 /* calculate offset assuming 96000kHz*/
275 offset_khz = (ndiv - ndiv % 2 + 1024) * TS2020_XTAL_FREQ
276 / (6 + 8) / (div4 + 1) / 2;
277
278 priv->frequency = offset_khz;
279
280 return (ret < 0) ? -EINVAL : 0;
281}
282
283static int ts2020_get_frequency(struct dvb_frontend *fe, u32 *frequency)
284{
285 struct ts2020_priv *priv = fe->tuner_priv;
286 *frequency = priv->frequency;
287 return 0;
288}
289
290/* read TS2020 signal strength */
291static int ts2020_read_signal_strength(struct dvb_frontend *fe,
292 u16 *signal_strength)
293{
294 u16 sig_reading, sig_strength;
295 u8 rfgain, bbgain;
296
297 rfgain = ts2020_readreg(fe, 0x3d) & 0x1f;
298 bbgain = ts2020_readreg(fe, 0x21) & 0x1f;
299
300 if (rfgain > 15)
301 rfgain = 15;
302 if (bbgain > 13)
303 bbgain = 13;
304
305 sig_reading = rfgain * 2 + bbgain * 3;
306
307 sig_strength = 40 + (64 - sig_reading) * 50 / 64 ;
308
309 /* cook the value to be suitable for szap-s2 human readable output */
310 *signal_strength = sig_strength * 1000;
311
312 return 0;
313}
314
315static struct dvb_tuner_ops ts2020_tuner_ops = {
316 .info = {
317 .name = "TS2020",
318 .frequency_min = 950000,
319 .frequency_max = 2150000
320 },
321 .init = ts2020_init,
322 .release = ts2020_release,
323 .sleep = ts2020_sleep,
324 .set_params = ts2020_set_params,
325 .get_frequency = ts2020_get_frequency,
326 .get_rf_strength = ts2020_read_signal_strength,
327};
328
329struct dvb_frontend *ts2020_attach(struct dvb_frontend *fe,
330 const struct ts2020_config *config,
331 struct i2c_adapter *i2c)
332{
333 struct ts2020_priv *priv = NULL;
334 u8 buf;
335
336 priv = kzalloc(sizeof(struct ts2020_priv), GFP_KERNEL);
337 if (priv == NULL)
338 return NULL;
339
340 priv->i2c_address = config->tuner_address;
341 priv->i2c = i2c;
342 priv->clk_out_div = config->clk_out_div;
343 fe->tuner_priv = priv;
344
345 /* Wake Up the tuner */
346 if ((0x03 & ts2020_readreg(fe, 0x00)) == 0x00) {
347 ts2020_writereg(fe, 0x00, 0x01);
348 msleep(2);
349 }
350
351 ts2020_writereg(fe, 0x00, 0x03);
352 msleep(2);
353
354 /* Check the tuner version */
355 buf = ts2020_readreg(fe, 0x00);
356 if ((buf == 0x01) || (buf == 0x41) || (buf == 0x81))
357 printk(KERN_INFO "%s: Find tuner TS2020!\n", __func__);
358 else {
359 printk(KERN_ERR "%s: Read tuner reg[0] = %d\n", __func__, buf);
360 kfree(priv);
361 return NULL;
362 }
363
364 memcpy(&fe->ops.tuner_ops, &ts2020_tuner_ops,
365 sizeof(struct dvb_tuner_ops));
366
367 return fe;
368}
369EXPORT_SYMBOL(ts2020_attach);
370
371MODULE_AUTHOR("Konstantin Dimitrov <kosio.dimitrov@gmail.com>");
372MODULE_DESCRIPTION("Montage Technology TS2020 - Silicon tuner driver module");
373MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb-frontends/ts2020.h b/drivers/media/dvb-frontends/ts2020.h
new file mode 100644
index 000000000000..c7e64afa614a
--- /dev/null
+++ b/drivers/media/dvb-frontends/ts2020.h
@@ -0,0 +1,50 @@
1/*
2 Montage Technology TS2020 - Silicon Tuner driver
3 Copyright (C) 2009-2012 Konstantin Dimitrov <kosio.dimitrov@gmail.com>
4
5 Copyright (C) 2009-2012 TurboSight.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 as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22#ifndef TS2020_H
23#define TS2020_H
24
25#include <linux/dvb/frontend.h>
26
27struct ts2020_config {
28 u8 tuner_address;
29 u8 clk_out_div;
30};
31
32#if defined(CONFIG_DVB_TS2020) || \
33 (defined(CONFIG_DVB_TS2020_MODULE) && defined(MODULE))
34
35extern struct dvb_frontend *ts2020_attach(
36 struct dvb_frontend *fe,
37 const struct ts2020_config *config,
38 struct i2c_adapter *i2c);
39#else
40static inline struct dvb_frontend *ts2020_attach(
41 struct dvb_frontend *fe,
42 const struct ts2020_config *config,
43 struct i2c_adapter *i2c)
44{
45 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
46 return NULL;
47}
48#endif
49
50#endif /* TS2020_H */
diff --git a/drivers/media/dvb-frontends/tua6100.h b/drivers/media/dvb-frontends/tua6100.h
index f83dbd5e42ae..83a9c30e67ca 100644
--- a/drivers/media/dvb-frontends/tua6100.h
+++ b/drivers/media/dvb-frontends/tua6100.h
@@ -34,7 +34,7 @@
34#include <linux/i2c.h> 34#include <linux/i2c.h>
35#include "dvb_frontend.h" 35#include "dvb_frontend.h"
36 36
37#if defined(CONFIG_DVB_TUA6100) || (defined(CONFIG_DVB_TUA6100_MODULE) && defined(MODULE)) 37#if IS_ENABLED(CONFIG_DVB_TUA6100)
38extern struct dvb_frontend *tua6100_attach(struct dvb_frontend *fe, int addr, struct i2c_adapter *i2c); 38extern struct dvb_frontend *tua6100_attach(struct dvb_frontend *fe, int addr, struct i2c_adapter *i2c);
39#else 39#else
40static inline struct dvb_frontend* tua6100_attach(struct dvb_frontend *fe, int addr, struct i2c_adapter *i2c) 40static inline struct dvb_frontend* tua6100_attach(struct dvb_frontend *fe, int addr, struct i2c_adapter *i2c)
diff --git a/drivers/media/dvb-frontends/ves1820.h b/drivers/media/dvb-frontends/ves1820.h
index e902ed634ec3..c073f353ac38 100644
--- a/drivers/media/dvb-frontends/ves1820.h
+++ b/drivers/media/dvb-frontends/ves1820.h
@@ -41,7 +41,7 @@ struct ves1820_config
41 u8 selagc:1; 41 u8 selagc:1;
42}; 42};
43 43
44#if defined(CONFIG_DVB_VES1820) || (defined(CONFIG_DVB_VES1820_MODULE) && defined(MODULE)) 44#if IS_ENABLED(CONFIG_DVB_VES1820)
45extern struct dvb_frontend* ves1820_attach(const struct ves1820_config* config, 45extern struct dvb_frontend* ves1820_attach(const struct ves1820_config* config,
46 struct i2c_adapter* i2c, u8 pwm); 46 struct i2c_adapter* i2c, u8 pwm);
47#else 47#else
diff --git a/drivers/media/dvb-frontends/ves1x93.h b/drivers/media/dvb-frontends/ves1x93.h
index 8a5a49e808f6..2307caea6aec 100644
--- a/drivers/media/dvb-frontends/ves1x93.h
+++ b/drivers/media/dvb-frontends/ves1x93.h
@@ -40,7 +40,7 @@ struct ves1x93_config
40 u8 invert_pwm:1; 40 u8 invert_pwm:1;
41}; 41};
42 42
43#if defined(CONFIG_DVB_VES1X93) || (defined(CONFIG_DVB_VES1X93_MODULE) && defined(MODULE)) 43#if IS_ENABLED(CONFIG_DVB_VES1X93)
44extern struct dvb_frontend* ves1x93_attach(const struct ves1x93_config* config, 44extern struct dvb_frontend* ves1x93_attach(const struct ves1x93_config* config,
45 struct i2c_adapter* i2c); 45 struct i2c_adapter* i2c);
46#else 46#else
diff --git a/drivers/media/dvb-frontends/zl10353.h b/drivers/media/dvb-frontends/zl10353.h
index 6e3ca9eed048..50c1004aef36 100644
--- a/drivers/media/dvb-frontends/zl10353.h
+++ b/drivers/media/dvb-frontends/zl10353.h
@@ -47,7 +47,7 @@ struct zl10353_config
47 u8 pll_0; /* default: 0x15 */ 47 u8 pll_0; /* default: 0x15 */
48}; 48};
49 49
50#if defined(CONFIG_DVB_ZL10353) || (defined(CONFIG_DVB_ZL10353_MODULE) && defined(MODULE)) 50#if IS_ENABLED(CONFIG_DVB_ZL10353)
51extern struct dvb_frontend* zl10353_attach(const struct zl10353_config *config, 51extern struct dvb_frontend* zl10353_attach(const struct zl10353_config *config,
52 struct i2c_adapter *i2c); 52 struct i2c_adapter *i2c);
53#else 53#else
diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 24d78e28e493..7b771baa2212 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -1,16 +1,4 @@
1# 1#
2# Generic video config states
3#
4
5config VIDEO_BTCX
6 depends on PCI
7 tristate
8
9config VIDEO_TVEEPROM
10 tristate
11 depends on I2C
12
13#
14# Multimedia Video device configuration 2# Multimedia Video device configuration
15# 3#
16 4
@@ -317,20 +305,6 @@ config VIDEO_SAA717X
317 305
318source "drivers/media/i2c/cx25840/Kconfig" 306source "drivers/media/i2c/cx25840/Kconfig"
319 307
320comment "MPEG video encoders"
321
322config VIDEO_CX2341X
323 tristate "Conexant CX2341x MPEG encoders"
324 depends on VIDEO_V4L2
325 ---help---
326 Support for the Conexant CX23416 MPEG encoders
327 and CX23415 MPEG encoder/decoders.
328
329 This module currently supports the encoding functions only.
330
331 To compile this driver as a module, choose M here: the
332 module will be called cx2341x.
333
334comment "Video encoders" 308comment "Video encoders"
335 309
336config VIDEO_SAA7127 310config VIDEO_SAA7127
@@ -421,6 +395,13 @@ config VIDEO_OV7670
421 OV7670 VGA camera. It currently only works with the M88ALP01 395 OV7670 VGA camera. It currently only works with the M88ALP01
422 controller. 396 controller.
423 397
398config VIDEO_OV9650
399 tristate "OmniVision OV9650/OV9652 sensor support"
400 depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
401 ---help---
402 This is a V4L2 sensor-level driver for the Omnivision
403 OV9650 and OV9652 camera sensors.
404
424config VIDEO_VS6624 405config VIDEO_VS6624
425 tristate "ST VS6624 sensor support" 406 tristate "ST VS6624 sensor support"
426 depends on VIDEO_V4L2 && I2C 407 depends on VIDEO_V4L2 && I2C
@@ -477,7 +458,7 @@ config VIDEO_MT9V032
477 458
478config VIDEO_TCM825X 459config VIDEO_TCM825X
479 tristate "TCM825x camera sensor support" 460 tristate "TCM825x camera sensor support"
480 depends on I2C && VIDEO_V4L2 461 depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_INT_DEVICE
481 depends on MEDIA_CAMERA_SUPPORT 462 depends on MEDIA_CAMERA_SUPPORT
482 ---help--- 463 ---help---
483 This is a driver for the Toshiba TCM825x VGA camera sensor. 464 This is a driver for the Toshiba TCM825x VGA camera sensor.
@@ -516,6 +497,13 @@ config VIDEO_S5K4ECGX
516 497
517source "drivers/media/i2c/smiapp/Kconfig" 498source "drivers/media/i2c/smiapp/Kconfig"
518 499
500config VIDEO_S5C73M3
501 tristate "Samsung S5C73M3 sensor support"
502 depends on I2C && SPI && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
503 ---help---
504 This is a V4L2 sensor-level driver for Samsung S5C73M3
505 8 Mpixel camera.
506
519comment "Flash devices" 507comment "Flash devices"
520 508
521config VIDEO_ADP1653 509config VIDEO_ADP1653
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index b1d62dfd49b8..cfefd30cc1bc 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -47,8 +47,8 @@ obj-$(CONFIG_VIDEO_VP27SMPX) += vp27smpx.o
47obj-$(CONFIG_VIDEO_UPD64031A) += upd64031a.o 47obj-$(CONFIG_VIDEO_UPD64031A) += upd64031a.o
48obj-$(CONFIG_VIDEO_UPD64083) += upd64083.o 48obj-$(CONFIG_VIDEO_UPD64083) += upd64083.o
49obj-$(CONFIG_VIDEO_OV7670) += ov7670.o 49obj-$(CONFIG_VIDEO_OV7670) += ov7670.o
50obj-$(CONFIG_VIDEO_OV9650) += ov9650.o
50obj-$(CONFIG_VIDEO_TCM825X) += tcm825x.o 51obj-$(CONFIG_VIDEO_TCM825X) += tcm825x.o
51obj-$(CONFIG_VIDEO_TVEEPROM) += tveeprom.o
52obj-$(CONFIG_VIDEO_MT9M032) += mt9m032.o 52obj-$(CONFIG_VIDEO_MT9M032) += mt9m032.o
53obj-$(CONFIG_VIDEO_MT9P031) += mt9p031.o 53obj-$(CONFIG_VIDEO_MT9P031) += mt9p031.o
54obj-$(CONFIG_VIDEO_MT9T001) += mt9t001.o 54obj-$(CONFIG_VIDEO_MT9T001) += mt9t001.o
@@ -58,10 +58,9 @@ obj-$(CONFIG_VIDEO_SR030PC30) += sr030pc30.o
58obj-$(CONFIG_VIDEO_NOON010PC30) += noon010pc30.o 58obj-$(CONFIG_VIDEO_NOON010PC30) += noon010pc30.o
59obj-$(CONFIG_VIDEO_S5K6AA) += s5k6aa.o 59obj-$(CONFIG_VIDEO_S5K6AA) += s5k6aa.o
60obj-$(CONFIG_VIDEO_S5K4ECGX) += s5k4ecgx.o 60obj-$(CONFIG_VIDEO_S5K4ECGX) += s5k4ecgx.o
61obj-$(CONFIG_VIDEO_S5C73M3) += s5c73m3/
61obj-$(CONFIG_VIDEO_ADP1653) += adp1653.o 62obj-$(CONFIG_VIDEO_ADP1653) += adp1653.o
62obj-$(CONFIG_VIDEO_AS3645A) += as3645a.o 63obj-$(CONFIG_VIDEO_AS3645A) += as3645a.o
63obj-$(CONFIG_VIDEO_SMIAPP_PLL) += smiapp-pll.o 64obj-$(CONFIG_VIDEO_SMIAPP_PLL) += smiapp-pll.o
64obj-$(CONFIG_VIDEO_BTCX) += btcx-risc.o
65obj-$(CONFIG_VIDEO_CX2341X) += cx2341x.o
66obj-$(CONFIG_VIDEO_AK881X) += ak881x.o 65obj-$(CONFIG_VIDEO_AK881X) += ak881x.o
67obj-$(CONFIG_VIDEO_IR_I2C) += ir-kbd-i2c.o 66obj-$(CONFIG_VIDEO_IR_I2C) += ir-kbd-i2c.o
diff --git a/drivers/media/i2c/adv7180.c b/drivers/media/i2c/adv7180.c
index 64d71fb87a96..34f39d3b3e3e 100644
--- a/drivers/media/i2c/adv7180.c
+++ b/drivers/media/i2c/adv7180.c
@@ -402,9 +402,6 @@ static const struct v4l2_subdev_video_ops adv7180_video_ops = {
402static const struct v4l2_subdev_core_ops adv7180_core_ops = { 402static const struct v4l2_subdev_core_ops adv7180_core_ops = {
403 .g_chip_ident = adv7180_g_chip_ident, 403 .g_chip_ident = adv7180_g_chip_ident,
404 .s_std = adv7180_s_std, 404 .s_std = adv7180_s_std,
405 .queryctrl = v4l2_subdev_queryctrl,
406 .g_ctrl = v4l2_subdev_g_ctrl,
407 .s_ctrl = v4l2_subdev_s_ctrl,
408}; 405};
409 406
410static const struct v4l2_subdev_ops adv7180_ops = { 407static const struct v4l2_subdev_ops adv7180_ops = {
diff --git a/drivers/media/i2c/adv7343.c b/drivers/media/i2c/adv7343.c
index 2b5aa676a84e..9fc2b985df0e 100644
--- a/drivers/media/i2c/adv7343.c
+++ b/drivers/media/i2c/adv7343.c
@@ -43,6 +43,7 @@ MODULE_PARM_DESC(debug, "Debug level 0-1");
43struct adv7343_state { 43struct adv7343_state {
44 struct v4l2_subdev sd; 44 struct v4l2_subdev sd;
45 struct v4l2_ctrl_handler hdl; 45 struct v4l2_ctrl_handler hdl;
46 const struct adv7343_platform_data *pdata;
46 u8 reg00; 47 u8 reg00;
47 u8 reg01; 48 u8 reg01;
48 u8 reg02; 49 u8 reg02;
@@ -215,12 +216,23 @@ static int adv7343_setoutput(struct v4l2_subdev *sd, u32 output_type)
215 /* Enable Appropriate DAC */ 216 /* Enable Appropriate DAC */
216 val = state->reg00 & 0x03; 217 val = state->reg00 & 0x03;
217 218
218 if (output_type == ADV7343_COMPOSITE_ID) 219 /* configure default configuration */
219 val |= ADV7343_COMPOSITE_POWER_VALUE; 220 if (!state->pdata)
220 else if (output_type == ADV7343_COMPONENT_ID) 221 if (output_type == ADV7343_COMPOSITE_ID)
221 val |= ADV7343_COMPONENT_POWER_VALUE; 222 val |= ADV7343_COMPOSITE_POWER_VALUE;
223 else if (output_type == ADV7343_COMPONENT_ID)
224 val |= ADV7343_COMPONENT_POWER_VALUE;
225 else
226 val |= ADV7343_SVIDEO_POWER_VALUE;
222 else 227 else
223 val |= ADV7343_SVIDEO_POWER_VALUE; 228 val = state->pdata->mode_config.sleep_mode << 0 |
229 state->pdata->mode_config.pll_control << 1 |
230 state->pdata->mode_config.dac_3 << 2 |
231 state->pdata->mode_config.dac_2 << 3 |
232 state->pdata->mode_config.dac_1 << 4 |
233 state->pdata->mode_config.dac_6 << 5 |
234 state->pdata->mode_config.dac_5 << 6 |
235 state->pdata->mode_config.dac_4 << 7;
224 236
225 err = adv7343_write(sd, ADV7343_POWER_MODE_REG, val); 237 err = adv7343_write(sd, ADV7343_POWER_MODE_REG, val);
226 if (err < 0) 238 if (err < 0)
@@ -238,6 +250,17 @@ static int adv7343_setoutput(struct v4l2_subdev *sd, u32 output_type)
238 250
239 /* configure SD DAC Output 2 and SD DAC Output 1 bit to zero */ 251 /* configure SD DAC Output 2 and SD DAC Output 1 bit to zero */
240 val = state->reg82 & (SD_DAC_1_DI & SD_DAC_2_DI); 252 val = state->reg82 & (SD_DAC_1_DI & SD_DAC_2_DI);
253
254 if (state->pdata && state->pdata->sd_config.sd_dac_out1)
255 val = val | (state->pdata->sd_config.sd_dac_out1 << 1);
256 else if (state->pdata && !state->pdata->sd_config.sd_dac_out1)
257 val = val & ~(state->pdata->sd_config.sd_dac_out1 << 1);
258
259 if (state->pdata && state->pdata->sd_config.sd_dac_out2)
260 val = val | (state->pdata->sd_config.sd_dac_out2 << 2);
261 else if (state->pdata && !state->pdata->sd_config.sd_dac_out2)
262 val = val & ~(state->pdata->sd_config.sd_dac_out2 << 2);
263
241 err = adv7343_write(sd, ADV7343_SD_MODE_REG2, val); 264 err = adv7343_write(sd, ADV7343_SD_MODE_REG2, val);
242 if (err < 0) 265 if (err < 0)
243 goto setoutput_exit; 266 goto setoutput_exit;
@@ -397,10 +420,14 @@ static int adv7343_probe(struct i2c_client *client,
397 v4l_info(client, "chip found @ 0x%x (%s)\n", 420 v4l_info(client, "chip found @ 0x%x (%s)\n",
398 client->addr << 1, client->adapter->name); 421 client->addr << 1, client->adapter->name);
399 422
400 state = kzalloc(sizeof(struct adv7343_state), GFP_KERNEL); 423 state = devm_kzalloc(&client->dev, sizeof(struct adv7343_state),
424 GFP_KERNEL);
401 if (state == NULL) 425 if (state == NULL)
402 return -ENOMEM; 426 return -ENOMEM;
403 427
428 /* Copy board specific information here */
429 state->pdata = client->dev.platform_data;
430
404 state->reg00 = 0x80; 431 state->reg00 = 0x80;
405 state->reg01 = 0x00; 432 state->reg01 = 0x00;
406 state->reg02 = 0x20; 433 state->reg02 = 0x20;
@@ -431,16 +458,13 @@ static int adv7343_probe(struct i2c_client *client,
431 int err = state->hdl.error; 458 int err = state->hdl.error;
432 459
433 v4l2_ctrl_handler_free(&state->hdl); 460 v4l2_ctrl_handler_free(&state->hdl);
434 kfree(state);
435 return err; 461 return err;
436 } 462 }
437 v4l2_ctrl_handler_setup(&state->hdl); 463 v4l2_ctrl_handler_setup(&state->hdl);
438 464
439 err = adv7343_initialize(&state->sd); 465 err = adv7343_initialize(&state->sd);
440 if (err) { 466 if (err)
441 v4l2_ctrl_handler_free(&state->hdl); 467 v4l2_ctrl_handler_free(&state->hdl);
442 kfree(state);
443 }
444 return err; 468 return err;
445} 469}
446 470
@@ -451,7 +475,6 @@ static int adv7343_remove(struct i2c_client *client)
451 475
452 v4l2_device_unregister_subdev(sd); 476 v4l2_device_unregister_subdev(sd);
453 v4l2_ctrl_handler_free(&state->hdl); 477 v4l2_ctrl_handler_free(&state->hdl);
454 kfree(state);
455 478
456 return 0; 479 return 0;
457} 480}
diff --git a/drivers/media/i2c/cx25840/cx25840-ir.c b/drivers/media/i2c/cx25840/cx25840-ir.c
index 38ce76ed1924..9ae977b5983a 100644
--- a/drivers/media/i2c/cx25840/cx25840-ir.c
+++ b/drivers/media/i2c/cx25840/cx25840-ir.c
@@ -1251,13 +1251,11 @@ int cx25840_ir_probe(struct v4l2_subdev *sd)
1251 cx25840_write4(ir_state->c, CX25840_IR_IRQEN_REG, 0); 1251 cx25840_write4(ir_state->c, CX25840_IR_IRQEN_REG, 0);
1252 1252
1253 mutex_init(&ir_state->rx_params_lock); 1253 mutex_init(&ir_state->rx_params_lock);
1254 memcpy(&default_params, &default_rx_params, 1254 default_params = default_rx_params;
1255 sizeof(struct v4l2_subdev_ir_parameters));
1256 v4l2_subdev_call(sd, ir, rx_s_parameters, &default_params); 1255 v4l2_subdev_call(sd, ir, rx_s_parameters, &default_params);
1257 1256
1258 mutex_init(&ir_state->tx_params_lock); 1257 mutex_init(&ir_state->tx_params_lock);
1259 memcpy(&default_params, &default_tx_params, 1258 default_params = default_tx_params;
1260 sizeof(struct v4l2_subdev_ir_parameters));
1261 v4l2_subdev_call(sd, ir, tx_s_parameters, &default_params); 1259 v4l2_subdev_call(sd, ir, tx_s_parameters, &default_params);
1262 1260
1263 return 0; 1261 return 0;
diff --git a/drivers/media/i2c/mt9v011.c b/drivers/media/i2c/mt9v011.c
index 6bf01ad62765..73b7688cbebd 100644
--- a/drivers/media/i2c/mt9v011.c
+++ b/drivers/media/i2c/mt9v011.c
@@ -13,6 +13,7 @@
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> 15#include <media/v4l2-chip-ident.h>
16#include <media/v4l2-ctrls.h>
16#include <media/mt9v011.h> 17#include <media/mt9v011.h>
17 18
18MODULE_DESCRIPTION("Micron mt9v011 sensor driver"); 19MODULE_DESCRIPTION("Micron mt9v011 sensor driver");
@@ -48,68 +49,9 @@ MODULE_PARM_DESC(debug, "Debug level (0-2)");
48#define MT9V011_VERSION 0x8232 49#define MT9V011_VERSION 0x8232
49#define MT9V011_REV_B_VERSION 0x8243 50#define MT9V011_REV_B_VERSION 0x8243
50 51
51/* supported controls */
52static struct v4l2_queryctrl mt9v011_qctrl[] = {
53 {
54 .id = V4L2_CID_GAIN,
55 .type = V4L2_CTRL_TYPE_INTEGER,
56 .name = "Gain",
57 .minimum = 0,
58 .maximum = (1 << 12) - 1 - 0x0020,
59 .step = 1,
60 .default_value = 0x0020,
61 .flags = 0,
62 }, {
63 .id = V4L2_CID_EXPOSURE,
64 .type = V4L2_CTRL_TYPE_INTEGER,
65 .name = "Exposure",
66 .minimum = 0,
67 .maximum = 2047,
68 .step = 1,
69 .default_value = 0x01fc,
70 .flags = 0,
71 }, {
72 .id = V4L2_CID_RED_BALANCE,
73 .type = V4L2_CTRL_TYPE_INTEGER,
74 .name = "Red Balance",
75 .minimum = -1 << 9,
76 .maximum = (1 << 9) - 1,
77 .step = 1,
78 .default_value = 0,
79 .flags = 0,
80 }, {
81 .id = V4L2_CID_BLUE_BALANCE,
82 .type = V4L2_CTRL_TYPE_INTEGER,
83 .name = "Blue Balance",
84 .minimum = -1 << 9,
85 .maximum = (1 << 9) - 1,
86 .step = 1,
87 .default_value = 0,
88 .flags = 0,
89 }, {
90 .id = V4L2_CID_HFLIP,
91 .type = V4L2_CTRL_TYPE_BOOLEAN,
92 .name = "Mirror",
93 .minimum = 0,
94 .maximum = 1,
95 .step = 1,
96 .default_value = 0,
97 .flags = 0,
98 }, {
99 .id = V4L2_CID_VFLIP,
100 .type = V4L2_CTRL_TYPE_BOOLEAN,
101 .name = "Vflip",
102 .minimum = 0,
103 .maximum = 1,
104 .step = 1,
105 .default_value = 0,
106 .flags = 0,
107 }, {
108 }
109};
110
111struct mt9v011 { 52struct mt9v011 {
112 struct v4l2_subdev sd; 53 struct v4l2_subdev sd;
54 struct v4l2_ctrl_handler ctrls;
113 unsigned width, height; 55 unsigned width, height;
114 unsigned xtal; 56 unsigned xtal;
115 unsigned hflip:1; 57 unsigned hflip:1;
@@ -381,99 +323,6 @@ static int mt9v011_reset(struct v4l2_subdev *sd, u32 val)
381 set_read_mode(sd); 323 set_read_mode(sd);
382 324
383 return 0; 325 return 0;
384};
385
386static int mt9v011_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
387{
388 struct mt9v011 *core = to_mt9v011(sd);
389
390 v4l2_dbg(1, debug, sd, "g_ctrl called\n");
391
392 switch (ctrl->id) {
393 case V4L2_CID_GAIN:
394 ctrl->value = core->global_gain;
395 return 0;
396 case V4L2_CID_EXPOSURE:
397 ctrl->value = core->exposure;
398 return 0;
399 case V4L2_CID_RED_BALANCE:
400 ctrl->value = core->red_bal;
401 return 0;
402 case V4L2_CID_BLUE_BALANCE:
403 ctrl->value = core->blue_bal;
404 return 0;
405 case V4L2_CID_HFLIP:
406 ctrl->value = core->hflip ? 1 : 0;
407 return 0;
408 case V4L2_CID_VFLIP:
409 ctrl->value = core->vflip ? 1 : 0;
410 return 0;
411 }
412 return -EINVAL;
413}
414
415static int mt9v011_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc)
416{
417 int i;
418
419 v4l2_dbg(1, debug, sd, "queryctrl called\n");
420
421 for (i = 0; i < ARRAY_SIZE(mt9v011_qctrl); i++)
422 if (qc->id && qc->id == mt9v011_qctrl[i].id) {
423 memcpy(qc, &(mt9v011_qctrl[i]),
424 sizeof(*qc));
425 return 0;
426 }
427
428 return -EINVAL;
429}
430
431
432static int mt9v011_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
433{
434 struct mt9v011 *core = to_mt9v011(sd);
435 u8 i, n;
436 n = ARRAY_SIZE(mt9v011_qctrl);
437
438 for (i = 0; i < n; i++) {
439 if (ctrl->id != mt9v011_qctrl[i].id)
440 continue;
441 if (ctrl->value < mt9v011_qctrl[i].minimum ||
442 ctrl->value > mt9v011_qctrl[i].maximum)
443 return -ERANGE;
444 v4l2_dbg(1, debug, sd, "s_ctrl: id=%d, value=%d\n",
445 ctrl->id, ctrl->value);
446 break;
447 }
448
449 switch (ctrl->id) {
450 case V4L2_CID_GAIN:
451 core->global_gain = ctrl->value;
452 break;
453 case V4L2_CID_EXPOSURE:
454 core->exposure = ctrl->value;
455 break;
456 case V4L2_CID_RED_BALANCE:
457 core->red_bal = ctrl->value;
458 break;
459 case V4L2_CID_BLUE_BALANCE:
460 core->blue_bal = ctrl->value;
461 break;
462 case V4L2_CID_HFLIP:
463 core->hflip = ctrl->value;
464 set_read_mode(sd);
465 return 0;
466 case V4L2_CID_VFLIP:
467 core->vflip = ctrl->value;
468 set_read_mode(sd);
469 return 0;
470 default:
471 return -EINVAL;
472 }
473
474 set_balance(sd);
475
476 return 0;
477} 326}
478 327
479static int mt9v011_enum_mbus_fmt(struct v4l2_subdev *sd, unsigned index, 328static int mt9v011_enum_mbus_fmt(struct v4l2_subdev *sd, unsigned index,
@@ -599,10 +448,46 @@ static int mt9v011_g_chip_ident(struct v4l2_subdev *sd,
599 version); 448 version);
600} 449}
601 450
602static const struct v4l2_subdev_core_ops mt9v011_core_ops = { 451static int mt9v011_s_ctrl(struct v4l2_ctrl *ctrl)
603 .queryctrl = mt9v011_queryctrl, 452{
604 .g_ctrl = mt9v011_g_ctrl, 453 struct mt9v011 *core =
454 container_of(ctrl->handler, struct mt9v011, ctrls);
455 struct v4l2_subdev *sd = &core->sd;
456
457 switch (ctrl->id) {
458 case V4L2_CID_GAIN:
459 core->global_gain = ctrl->val;
460 break;
461 case V4L2_CID_EXPOSURE:
462 core->exposure = ctrl->val;
463 break;
464 case V4L2_CID_RED_BALANCE:
465 core->red_bal = ctrl->val;
466 break;
467 case V4L2_CID_BLUE_BALANCE:
468 core->blue_bal = ctrl->val;
469 break;
470 case V4L2_CID_HFLIP:
471 core->hflip = ctrl->val;
472 set_read_mode(sd);
473 return 0;
474 case V4L2_CID_VFLIP:
475 core->vflip = ctrl->val;
476 set_read_mode(sd);
477 return 0;
478 default:
479 return -EINVAL;
480 }
481
482 set_balance(sd);
483 return 0;
484}
485
486static struct v4l2_ctrl_ops mt9v011_ctrl_ops = {
605 .s_ctrl = mt9v011_s_ctrl, 487 .s_ctrl = mt9v011_s_ctrl,
488};
489
490static const struct v4l2_subdev_core_ops mt9v011_core_ops = {
606 .reset = mt9v011_reset, 491 .reset = mt9v011_reset,
607 .g_chip_ident = mt9v011_g_chip_ident, 492 .g_chip_ident = mt9v011_g_chip_ident,
608#ifdef CONFIG_VIDEO_ADV_DEBUG 493#ifdef CONFIG_VIDEO_ADV_DEBUG
@@ -658,6 +543,30 @@ static int mt9v011_probe(struct i2c_client *c,
658 return -EINVAL; 543 return -EINVAL;
659 } 544 }
660 545
546 v4l2_ctrl_handler_init(&core->ctrls, 5);
547 v4l2_ctrl_new_std(&core->ctrls, &mt9v011_ctrl_ops,
548 V4L2_CID_GAIN, 0, (1 << 12) - 1 - 0x20, 1, 0x20);
549 v4l2_ctrl_new_std(&core->ctrls, &mt9v011_ctrl_ops,
550 V4L2_CID_EXPOSURE, 0, 2047, 1, 0x01fc);
551 v4l2_ctrl_new_std(&core->ctrls, &mt9v011_ctrl_ops,
552 V4L2_CID_RED_BALANCE, -(1 << 9), (1 << 9) - 1, 1, 0);
553 v4l2_ctrl_new_std(&core->ctrls, &mt9v011_ctrl_ops,
554 V4L2_CID_BLUE_BALANCE, -(1 << 9), (1 << 9) - 1, 1, 0);
555 v4l2_ctrl_new_std(&core->ctrls, &mt9v011_ctrl_ops,
556 V4L2_CID_HFLIP, 0, 1, 1, 0);
557 v4l2_ctrl_new_std(&core->ctrls, &mt9v011_ctrl_ops,
558 V4L2_CID_VFLIP, 0, 1, 1, 0);
559
560 if (core->ctrls.error) {
561 int ret = core->ctrls.error;
562
563 v4l2_err(sd, "control initialization error %d\n", ret);
564 v4l2_ctrl_handler_free(&core->ctrls);
565 kfree(core);
566 return ret;
567 }
568 core->sd.ctrl_handler = &core->ctrls;
569
661 core->global_gain = 0x0024; 570 core->global_gain = 0x0024;
662 core->exposure = 0x01fc; 571 core->exposure = 0x01fc;
663 core->width = 640; 572 core->width = 640;
@@ -681,12 +590,14 @@ static int mt9v011_probe(struct i2c_client *c,
681static int mt9v011_remove(struct i2c_client *c) 590static int mt9v011_remove(struct i2c_client *c)
682{ 591{
683 struct v4l2_subdev *sd = i2c_get_clientdata(c); 592 struct v4l2_subdev *sd = i2c_get_clientdata(c);
593 struct mt9v011 *core = to_mt9v011(sd);
684 594
685 v4l2_dbg(1, debug, sd, 595 v4l2_dbg(1, debug, sd,
686 "mt9v011.c: removing mt9v011 adapter on address 0x%x\n", 596 "mt9v011.c: removing mt9v011 adapter on address 0x%x\n",
687 c->addr << 1); 597 c->addr << 1);
688 598
689 v4l2_device_unregister_subdev(sd); 599 v4l2_device_unregister_subdev(sd);
600 v4l2_ctrl_handler_free(&core->ctrls);
690 kfree(to_mt9v011(sd)); 601 kfree(to_mt9v011(sd));
691 return 0; 602 return 0;
692} 603}
diff --git a/drivers/media/i2c/noon010pc30.c b/drivers/media/i2c/noon010pc30.c
index 440c12962bae..8554b47f993a 100644
--- a/drivers/media/i2c/noon010pc30.c
+++ b/drivers/media/i2c/noon010pc30.c
@@ -660,13 +660,6 @@ static const struct v4l2_ctrl_ops noon010_ctrl_ops = {
660 660
661static const struct v4l2_subdev_core_ops noon010_core_ops = { 661static const struct v4l2_subdev_core_ops noon010_core_ops = {
662 .s_power = noon010_s_power, 662 .s_power = noon010_s_power,
663 .g_ctrl = v4l2_subdev_g_ctrl,
664 .s_ctrl = v4l2_subdev_s_ctrl,
665 .queryctrl = v4l2_subdev_queryctrl,
666 .querymenu = v4l2_subdev_querymenu,
667 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls,
668 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls,
669 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls,
670 .log_status = noon010_log_status, 663 .log_status = noon010_log_status,
671}; 664};
672 665
diff --git a/drivers/media/i2c/ov7670.c b/drivers/media/i2c/ov7670.c
index e7c82b297514..05ed5b8e7f88 100644
--- a/drivers/media/i2c/ov7670.c
+++ b/drivers/media/i2c/ov7670.c
@@ -18,6 +18,7 @@
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> 20#include <media/v4l2-chip-ident.h>
21#include <media/v4l2-ctrls.h>
21#include <media/v4l2-mediabus.h> 22#include <media/v4l2-mediabus.h>
22#include <media/ov7670.h> 23#include <media/ov7670.h>
23 24
@@ -47,6 +48,8 @@ MODULE_PARM_DESC(debug, "Debug level (0-1)");
47 */ 48 */
48#define OV7670_I2C_ADDR 0x42 49#define OV7670_I2C_ADDR 0x42
49 50
51#define PLL_FACTOR 4
52
50/* Registers */ 53/* Registers */
51#define REG_GAIN 0x00 /* Gain lower 8 bits (rest in vref) */ 54#define REG_GAIN 0x00 /* Gain lower 8 bits (rest in vref) */
52#define REG_BLUE 0x01 /* blue gain */ 55#define REG_BLUE 0x01 /* blue gain */
@@ -164,6 +167,12 @@ MODULE_PARM_DESC(debug, "Debug level (0-1)");
164 167
165#define REG_GFIX 0x69 /* Fix gain control */ 168#define REG_GFIX 0x69 /* Fix gain control */
166 169
170#define REG_DBLV 0x6b /* PLL control an debugging */
171#define DBLV_BYPASS 0x00 /* Bypass PLL */
172#define DBLV_X4 0x01 /* clock x4 */
173#define DBLV_X6 0x10 /* clock x6 */
174#define DBLV_X8 0x11 /* clock x8 */
175
167#define REG_REG76 0x76 /* OV's name */ 176#define REG_REG76 0x76 /* OV's name */
168#define R76_BLKPCOR 0x80 /* Black pixel correction enable */ 177#define R76_BLKPCOR 0x80 /* Black pixel correction enable */
169#define R76_WHTPCOR 0x40 /* White pixel correction enable */ 178#define R76_WHTPCOR 0x40 /* White pixel correction enable */
@@ -183,6 +192,30 @@ MODULE_PARM_DESC(debug, "Debug level (0-1)");
183#define REG_HAECC7 0xaa /* Hist AEC/AGC control 7 */ 192#define REG_HAECC7 0xaa /* Hist AEC/AGC control 7 */
184#define REG_BD60MAX 0xab /* 60hz banding step limit */ 193#define REG_BD60MAX 0xab /* 60hz banding step limit */
185 194
195enum ov7670_model {
196 MODEL_OV7670 = 0,
197 MODEL_OV7675,
198};
199
200struct ov7670_win_size {
201 int width;
202 int height;
203 unsigned char com7_bit;
204 int hstart; /* Start/stop values for the camera. Note */
205 int hstop; /* that they do not always make complete */
206 int vstart; /* sense to humans, but evidently the sensor */
207 int vstop; /* will do the right thing... */
208 struct regval_list *regs; /* Regs to tweak */
209};
210
211struct ov7670_devtype {
212 /* formats supported for each model */
213 struct ov7670_win_size *win_sizes;
214 unsigned int n_win_sizes;
215 /* callbacks for frame rate control */
216 int (*set_framerate)(struct v4l2_subdev *, struct v4l2_fract *);
217 void (*get_framerate)(struct v4l2_subdev *, struct v4l2_fract *);
218};
186 219
187/* 220/*
188 * Information we maintain about a known sensor. 221 * Information we maintain about a known sensor.
@@ -190,14 +223,31 @@ MODULE_PARM_DESC(debug, "Debug level (0-1)");
190struct ov7670_format_struct; /* coming later */ 223struct ov7670_format_struct; /* coming later */
191struct ov7670_info { 224struct ov7670_info {
192 struct v4l2_subdev sd; 225 struct v4l2_subdev sd;
226 struct v4l2_ctrl_handler hdl;
227 struct {
228 /* gain cluster */
229 struct v4l2_ctrl *auto_gain;
230 struct v4l2_ctrl *gain;
231 };
232 struct {
233 /* exposure cluster */
234 struct v4l2_ctrl *auto_exposure;
235 struct v4l2_ctrl *exposure;
236 };
237 struct {
238 /* saturation/hue cluster */
239 struct v4l2_ctrl *saturation;
240 struct v4l2_ctrl *hue;
241 };
193 struct ov7670_format_struct *fmt; /* Current format */ 242 struct ov7670_format_struct *fmt; /* Current format */
194 unsigned char sat; /* Saturation value */
195 int hue; /* Hue value */
196 int min_width; /* Filter out smaller sizes */ 243 int min_width; /* Filter out smaller sizes */
197 int min_height; /* Filter out smaller sizes */ 244 int min_height; /* Filter out smaller sizes */
198 int clock_speed; /* External clock speed (MHz) */ 245 int clock_speed; /* External clock speed (MHz) */
199 u8 clkrc; /* Clock divider value */ 246 u8 clkrc; /* Clock divider value */
200 bool use_smbus; /* Use smbus I/O instead of I2C */ 247 bool use_smbus; /* Use smbus I/O instead of I2C */
248 bool pll_bypass;
249 bool pclk_hb_disable;
250 const struct ov7670_devtype *devtype; /* Device specifics */
201}; 251};
202 252
203static inline struct ov7670_info *to_state(struct v4l2_subdev *sd) 253static inline struct ov7670_info *to_state(struct v4l2_subdev *sd)
@@ -205,6 +255,11 @@ static inline struct ov7670_info *to_state(struct v4l2_subdev *sd)
205 return container_of(sd, struct ov7670_info, sd); 255 return container_of(sd, struct ov7670_info, sd);
206} 256}
207 257
258static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl)
259{
260 return &container_of(ctrl->handler, struct ov7670_info, hdl)->sd;
261}
262
208 263
209 264
210/* 265/*
@@ -353,7 +408,7 @@ static struct regval_list ov7670_fmt_yuv422[] = {
353 { REG_RGB444, 0 }, /* No RGB444 please */ 408 { REG_RGB444, 0 }, /* No RGB444 please */
354 { REG_COM1, 0 }, /* CCIR601 */ 409 { REG_COM1, 0 }, /* CCIR601 */
355 { REG_COM15, COM15_R00FF }, 410 { REG_COM15, COM15_R00FF },
356 { REG_COM9, 0x18 }, /* 4x gain ceiling; 0x8 is reserved bit */ 411 { REG_COM9, 0x48 }, /* 32x gain ceiling; 0x8 is reserved bit */
357 { 0x4f, 0x80 }, /* "matrix coefficient 1" */ 412 { 0x4f, 0x80 }, /* "matrix coefficient 1" */
358 { 0x50, 0x80 }, /* "matrix coefficient 2" */ 413 { 0x50, 0x80 }, /* "matrix coefficient 2" */
359 { 0x51, 0 }, /* vb */ 414 { 0x51, 0 }, /* vb */
@@ -652,65 +707,178 @@ static struct regval_list ov7670_qcif_regs[] = {
652 { 0xff, 0xff }, 707 { 0xff, 0xff },
653}; 708};
654 709
655static struct ov7670_win_size { 710static struct ov7670_win_size ov7670_win_sizes[] = {
656 int width;
657 int height;
658 unsigned char com7_bit;
659 int hstart; /* Start/stop values for the camera. Note */
660 int hstop; /* that they do not always make complete */
661 int vstart; /* sense to humans, but evidently the sensor */
662 int vstop; /* will do the right thing... */
663 struct regval_list *regs; /* Regs to tweak */
664/* h/vref stuff */
665} ov7670_win_sizes[] = {
666 /* VGA */ 711 /* VGA */
667 { 712 {
668 .width = VGA_WIDTH, 713 .width = VGA_WIDTH,
669 .height = VGA_HEIGHT, 714 .height = VGA_HEIGHT,
670 .com7_bit = COM7_FMT_VGA, 715 .com7_bit = COM7_FMT_VGA,
671 .hstart = 158, /* These values from */ 716 .hstart = 158, /* These values from */
672 .hstop = 14, /* Omnivision */ 717 .hstop = 14, /* Omnivision */
673 .vstart = 10, 718 .vstart = 10,
674 .vstop = 490, 719 .vstop = 490,
675 .regs = NULL, 720 .regs = NULL,
676 }, 721 },
677 /* CIF */ 722 /* CIF */
678 { 723 {
679 .width = CIF_WIDTH, 724 .width = CIF_WIDTH,
680 .height = CIF_HEIGHT, 725 .height = CIF_HEIGHT,
681 .com7_bit = COM7_FMT_CIF, 726 .com7_bit = COM7_FMT_CIF,
682 .hstart = 170, /* Empirically determined */ 727 .hstart = 170, /* Empirically determined */
683 .hstop = 90, 728 .hstop = 90,
684 .vstart = 14, 729 .vstart = 14,
685 .vstop = 494, 730 .vstop = 494,
686 .regs = NULL, 731 .regs = NULL,
687 }, 732 },
688 /* QVGA */ 733 /* QVGA */
689 { 734 {
690 .width = QVGA_WIDTH, 735 .width = QVGA_WIDTH,
691 .height = QVGA_HEIGHT, 736 .height = QVGA_HEIGHT,
692 .com7_bit = COM7_FMT_QVGA, 737 .com7_bit = COM7_FMT_QVGA,
693 .hstart = 168, /* Empirically determined */ 738 .hstart = 168, /* Empirically determined */
694 .hstop = 24, 739 .hstop = 24,
695 .vstart = 12, 740 .vstart = 12,
696 .vstop = 492, 741 .vstop = 492,
697 .regs = NULL, 742 .regs = NULL,
698 }, 743 },
699 /* QCIF */ 744 /* QCIF */
700 { 745 {
701 .width = QCIF_WIDTH, 746 .width = QCIF_WIDTH,
702 .height = QCIF_HEIGHT, 747 .height = QCIF_HEIGHT,
703 .com7_bit = COM7_FMT_VGA, /* see comment above */ 748 .com7_bit = COM7_FMT_VGA, /* see comment above */
704 .hstart = 456, /* Empirically determined */ 749 .hstart = 456, /* Empirically determined */
705 .hstop = 24, 750 .hstop = 24,
706 .vstart = 14, 751 .vstart = 14,
707 .vstop = 494, 752 .vstop = 494,
708 .regs = ov7670_qcif_regs, 753 .regs = ov7670_qcif_regs,
709 }, 754 }
755};
756
757static struct ov7670_win_size ov7675_win_sizes[] = {
758 /*
759 * Currently, only VGA is supported. Theoretically it could be possible
760 * to support CIF, QVGA and QCIF too. Taking values for ov7670 as a
761 * base and tweak them empirically could be required.
762 */
763 {
764 .width = VGA_WIDTH,
765 .height = VGA_HEIGHT,
766 .com7_bit = COM7_FMT_VGA,
767 .hstart = 158, /* These values from */
768 .hstop = 14, /* Omnivision */
769 .vstart = 14, /* Empirically determined */
770 .vstop = 494,
771 .regs = NULL,
772 }
710}; 773};
711 774
712#define N_WIN_SIZES (ARRAY_SIZE(ov7670_win_sizes)) 775static void ov7675_get_framerate(struct v4l2_subdev *sd,
776 struct v4l2_fract *tpf)
777{
778 struct ov7670_info *info = to_state(sd);
779 u32 clkrc = info->clkrc;
780 int pll_factor;
781
782 if (info->pll_bypass)
783 pll_factor = 1;
784 else
785 pll_factor = PLL_FACTOR;
786
787 clkrc++;
788 if (info->fmt->mbus_code == V4L2_MBUS_FMT_SBGGR8_1X8)
789 clkrc = (clkrc >> 1);
790
791 tpf->numerator = 1;
792 tpf->denominator = (5 * pll_factor * info->clock_speed) /
793 (4 * clkrc);
794}
795
796static int ov7675_set_framerate(struct v4l2_subdev *sd,
797 struct v4l2_fract *tpf)
798{
799 struct ov7670_info *info = to_state(sd);
800 u32 clkrc;
801 int pll_factor;
802 int ret;
803
804 /*
805 * The formula is fps = 5/4*pixclk for YUV/RGB and
806 * fps = 5/2*pixclk for RAW.
807 *
808 * pixclk = clock_speed / (clkrc + 1) * PLLfactor
809 *
810 */
811 if (info->pll_bypass) {
812 pll_factor = 1;
813 ret = ov7670_write(sd, REG_DBLV, DBLV_BYPASS);
814 } else {
815 pll_factor = PLL_FACTOR;
816 ret = ov7670_write(sd, REG_DBLV, DBLV_X4);
817 }
818 if (ret < 0)
819 return ret;
820
821 if (tpf->numerator == 0 || tpf->denominator == 0) {
822 clkrc = 0;
823 } else {
824 clkrc = (5 * pll_factor * info->clock_speed * tpf->numerator) /
825 (4 * tpf->denominator);
826 if (info->fmt->mbus_code == V4L2_MBUS_FMT_SBGGR8_1X8)
827 clkrc = (clkrc << 1);
828 clkrc--;
829 }
830
831 /*
832 * The datasheet claims that clkrc = 0 will divide the input clock by 1
833 * but we've checked with an oscilloscope that it divides by 2 instead.
834 * So, if clkrc = 0 just bypass the divider.
835 */
836 if (clkrc <= 0)
837 clkrc = CLK_EXT;
838 else if (clkrc > CLK_SCALE)
839 clkrc = CLK_SCALE;
840 info->clkrc = clkrc;
841
842 /* Recalculate frame rate */
843 ov7675_get_framerate(sd, tpf);
844
845 ret = ov7670_write(sd, REG_CLKRC, info->clkrc);
846 if (ret < 0)
847 return ret;
848
849 return ov7670_write(sd, REG_DBLV, DBLV_X4);
850}
851
852static void ov7670_get_framerate_legacy(struct v4l2_subdev *sd,
853 struct v4l2_fract *tpf)
854{
855 struct ov7670_info *info = to_state(sd);
856
857 tpf->numerator = 1;
858 tpf->denominator = info->clock_speed;
859 if ((info->clkrc & CLK_EXT) == 0 && (info->clkrc & CLK_SCALE) > 1)
860 tpf->denominator /= (info->clkrc & CLK_SCALE);
861}
862
863static int ov7670_set_framerate_legacy(struct v4l2_subdev *sd,
864 struct v4l2_fract *tpf)
865{
866 struct ov7670_info *info = to_state(sd);
867 int div;
713 868
869 if (tpf->numerator == 0 || tpf->denominator == 0)
870 div = 1; /* Reset to full rate */
871 else
872 div = (tpf->numerator * info->clock_speed) / tpf->denominator;
873 if (div == 0)
874 div = 1;
875 else if (div > CLK_SCALE)
876 div = CLK_SCALE;
877 info->clkrc = (info->clkrc & 0x80) | div;
878 tpf->numerator = 1;
879 tpf->denominator = info->clock_speed / div;
880 return ov7670_write(sd, REG_CLKRC, info->clkrc);
881}
714 882
715/* 883/*
716 * Store a set of start/stop values into the camera. 884 * Store a set of start/stop values into the camera.
@@ -759,8 +927,11 @@ static int ov7670_try_fmt_internal(struct v4l2_subdev *sd,
759 struct ov7670_format_struct **ret_fmt, 927 struct ov7670_format_struct **ret_fmt,
760 struct ov7670_win_size **ret_wsize) 928 struct ov7670_win_size **ret_wsize)
761{ 929{
762 int index; 930 int index, i;
763 struct ov7670_win_size *wsize; 931 struct ov7670_win_size *wsize;
932 struct ov7670_info *info = to_state(sd);
933 unsigned int n_win_sizes = info->devtype->n_win_sizes;
934 unsigned int win_sizes_limit = n_win_sizes;
764 935
765 for (index = 0; index < N_OV7670_FMTS; index++) 936 for (index = 0; index < N_OV7670_FMTS; index++)
766 if (ov7670_formats[index].mbus_code == fmt->code) 937 if (ov7670_formats[index].mbus_code == fmt->code)
@@ -776,15 +947,30 @@ static int ov7670_try_fmt_internal(struct v4l2_subdev *sd,
776 * Fields: the OV devices claim to be progressive. 947 * Fields: the OV devices claim to be progressive.
777 */ 948 */
778 fmt->field = V4L2_FIELD_NONE; 949 fmt->field = V4L2_FIELD_NONE;
950
951 /*
952 * Don't consider values that don't match min_height and min_width
953 * constraints.
954 */
955 if (info->min_width || info->min_height)
956 for (i = 0; i < n_win_sizes; i++) {
957 wsize = info->devtype->win_sizes + i;
958
959 if (wsize->width < info->min_width ||
960 wsize->height < info->min_height) {
961 win_sizes_limit = i;
962 break;
963 }
964 }
779 /* 965 /*
780 * Round requested image size down to the nearest 966 * Round requested image size down to the nearest
781 * we support, but not below the smallest. 967 * we support, but not below the smallest.
782 */ 968 */
783 for (wsize = ov7670_win_sizes; wsize < ov7670_win_sizes + N_WIN_SIZES; 969 for (wsize = info->devtype->win_sizes;
784 wsize++) 970 wsize < info->devtype->win_sizes + win_sizes_limit; wsize++)
785 if (fmt->width >= wsize->width && fmt->height >= wsize->height) 971 if (fmt->width >= wsize->width && fmt->height >= wsize->height)
786 break; 972 break;
787 if (wsize >= ov7670_win_sizes + N_WIN_SIZES) 973 if (wsize >= info->devtype->win_sizes + win_sizes_limit)
788 wsize--; /* Take the smallest one */ 974 wsize--; /* Take the smallest one */
789 if (ret_wsize != NULL) 975 if (ret_wsize != NULL)
790 *ret_wsize = wsize; 976 *ret_wsize = wsize;
@@ -868,10 +1054,8 @@ static int ov7670_g_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *parms)
868 1054
869 memset(cp, 0, sizeof(struct v4l2_captureparm)); 1055 memset(cp, 0, sizeof(struct v4l2_captureparm));
870 cp->capability = V4L2_CAP_TIMEPERFRAME; 1056 cp->capability = V4L2_CAP_TIMEPERFRAME;
871 cp->timeperframe.numerator = 1; 1057 info->devtype->get_framerate(sd, &cp->timeperframe);
872 cp->timeperframe.denominator = info->clock_speed; 1058
873 if ((info->clkrc & CLK_EXT) == 0 && (info->clkrc & CLK_SCALE) > 1)
874 cp->timeperframe.denominator /= (info->clkrc & CLK_SCALE);
875 return 0; 1059 return 0;
876} 1060}
877 1061
@@ -880,25 +1064,13 @@ static int ov7670_s_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *parms)
880 struct v4l2_captureparm *cp = &parms->parm.capture; 1064 struct v4l2_captureparm *cp = &parms->parm.capture;
881 struct v4l2_fract *tpf = &cp->timeperframe; 1065 struct v4l2_fract *tpf = &cp->timeperframe;
882 struct ov7670_info *info = to_state(sd); 1066 struct ov7670_info *info = to_state(sd);
883 int div;
884 1067
885 if (parms->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 1068 if (parms->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
886 return -EINVAL; 1069 return -EINVAL;
887 if (cp->extendedmode != 0) 1070 if (cp->extendedmode != 0)
888 return -EINVAL; 1071 return -EINVAL;
889 1072
890 if (tpf->numerator == 0 || tpf->denominator == 0) 1073 return info->devtype->set_framerate(sd, tpf);
891 div = 1; /* Reset to full rate */
892 else
893 div = (tpf->numerator * info->clock_speed) / tpf->denominator;
894 if (div == 0)
895 div = 1;
896 else if (div > CLK_SCALE)
897 div = CLK_SCALE;
898 info->clkrc = (info->clkrc & 0x80) | div;
899 tpf->numerator = 1;
900 tpf->denominator = info->clock_speed / div;
901 return ov7670_write(sd, REG_CLKRC, info->clkrc);
902} 1074}
903 1075
904 1076
@@ -931,13 +1103,14 @@ static int ov7670_enum_framesizes(struct v4l2_subdev *sd,
931 int i; 1103 int i;
932 int num_valid = -1; 1104 int num_valid = -1;
933 __u32 index = fsize->index; 1105 __u32 index = fsize->index;
1106 unsigned int n_win_sizes = info->devtype->n_win_sizes;
934 1107
935 /* 1108 /*
936 * If a minimum width/height was requested, filter out the capture 1109 * If a minimum width/height was requested, filter out the capture
937 * windows that fall outside that. 1110 * windows that fall outside that.
938 */ 1111 */
939 for (i = 0; i < N_WIN_SIZES; i++) { 1112 for (i = 0; i < n_win_sizes; i++) {
940 struct ov7670_win_size *win = &ov7670_win_sizes[index]; 1113 struct ov7670_win_size *win = &info->devtype->win_sizes[index];
941 if (info->min_width && win->width < info->min_width) 1114 if (info->min_width && win->width < info->min_width)
942 continue; 1115 continue;
943 if (info->min_height && win->height < info->min_height) 1116 if (info->min_height && win->height < info->min_height)
@@ -1042,23 +1215,23 @@ static int ov7670_cosine(int theta)
1042 1215
1043 1216
1044static void ov7670_calc_cmatrix(struct ov7670_info *info, 1217static void ov7670_calc_cmatrix(struct ov7670_info *info,
1045 int matrix[CMATRIX_LEN]) 1218 int matrix[CMATRIX_LEN], int sat, int hue)
1046{ 1219{
1047 int i; 1220 int i;
1048 /* 1221 /*
1049 * Apply the current saturation setting first. 1222 * Apply the current saturation setting first.
1050 */ 1223 */
1051 for (i = 0; i < CMATRIX_LEN; i++) 1224 for (i = 0; i < CMATRIX_LEN; i++)
1052 matrix[i] = (info->fmt->cmatrix[i]*info->sat) >> 7; 1225 matrix[i] = (info->fmt->cmatrix[i] * sat) >> 7;
1053 /* 1226 /*
1054 * Then, if need be, rotate the hue value. 1227 * Then, if need be, rotate the hue value.
1055 */ 1228 */
1056 if (info->hue != 0) { 1229 if (hue != 0) {
1057 int sinth, costh, tmpmatrix[CMATRIX_LEN]; 1230 int sinth, costh, tmpmatrix[CMATRIX_LEN];
1058 1231
1059 memcpy(tmpmatrix, matrix, CMATRIX_LEN*sizeof(int)); 1232 memcpy(tmpmatrix, matrix, CMATRIX_LEN*sizeof(int));
1060 sinth = ov7670_sine(info->hue); 1233 sinth = ov7670_sine(hue);
1061 costh = ov7670_cosine(info->hue); 1234 costh = ov7670_cosine(hue);
1062 1235
1063 matrix[0] = (matrix[3]*sinth + matrix[0]*costh)/1000; 1236 matrix[0] = (matrix[3]*sinth + matrix[0]*costh)/1000;
1064 matrix[1] = (matrix[4]*sinth + matrix[1]*costh)/1000; 1237 matrix[1] = (matrix[4]*sinth + matrix[1]*costh)/1000;
@@ -1071,60 +1244,21 @@ static void ov7670_calc_cmatrix(struct ov7670_info *info,
1071 1244
1072 1245
1073 1246
1074static int ov7670_s_sat(struct v4l2_subdev *sd, int value) 1247static int ov7670_s_sat_hue(struct v4l2_subdev *sd, int sat, int hue)
1075{
1076 struct ov7670_info *info = to_state(sd);
1077 int matrix[CMATRIX_LEN];
1078 int ret;
1079
1080 info->sat = value;
1081 ov7670_calc_cmatrix(info, matrix);
1082 ret = ov7670_store_cmatrix(sd, matrix);
1083 return ret;
1084}
1085
1086static int ov7670_g_sat(struct v4l2_subdev *sd, __s32 *value)
1087{
1088 struct ov7670_info *info = to_state(sd);
1089
1090 *value = info->sat;
1091 return 0;
1092}
1093
1094static int ov7670_s_hue(struct v4l2_subdev *sd, int value)
1095{ 1248{
1096 struct ov7670_info *info = to_state(sd); 1249 struct ov7670_info *info = to_state(sd);
1097 int matrix[CMATRIX_LEN]; 1250 int matrix[CMATRIX_LEN];
1098 int ret; 1251 int ret;
1099 1252
1100 if (value < -180 || value > 180) 1253 ov7670_calc_cmatrix(info, matrix, sat, hue);
1101 return -EINVAL;
1102 info->hue = value;
1103 ov7670_calc_cmatrix(info, matrix);
1104 ret = ov7670_store_cmatrix(sd, matrix); 1254 ret = ov7670_store_cmatrix(sd, matrix);
1105 return ret; 1255 return ret;
1106} 1256}
1107 1257
1108 1258
1109static int ov7670_g_hue(struct v4l2_subdev *sd, __s32 *value)
1110{
1111 struct ov7670_info *info = to_state(sd);
1112
1113 *value = info->hue;
1114 return 0;
1115}
1116
1117
1118/* 1259/*
1119 * Some weird registers seem to store values in a sign/magnitude format! 1260 * Some weird registers seem to store values in a sign/magnitude format!
1120 */ 1261 */
1121static unsigned char ov7670_sm_to_abs(unsigned char v)
1122{
1123 if ((v & 0x80) == 0)
1124 return v + 128;
1125 return 128 - (v & 0x7f);
1126}
1127
1128 1262
1129static unsigned char ov7670_abs_to_sm(unsigned char v) 1263static unsigned char ov7670_abs_to_sm(unsigned char v)
1130{ 1264{
@@ -1146,40 +1280,11 @@ static int ov7670_s_brightness(struct v4l2_subdev *sd, int value)
1146 return ret; 1280 return ret;
1147} 1281}
1148 1282
1149static int ov7670_g_brightness(struct v4l2_subdev *sd, __s32 *value)
1150{
1151 unsigned char v = 0;
1152 int ret = ov7670_read(sd, REG_BRIGHT, &v);
1153
1154 *value = ov7670_sm_to_abs(v);
1155 return ret;
1156}
1157
1158static int ov7670_s_contrast(struct v4l2_subdev *sd, int value) 1283static int ov7670_s_contrast(struct v4l2_subdev *sd, int value)
1159{ 1284{
1160 return ov7670_write(sd, REG_CONTRAS, (unsigned char) value); 1285 return ov7670_write(sd, REG_CONTRAS, (unsigned char) value);
1161} 1286}
1162 1287
1163static int ov7670_g_contrast(struct v4l2_subdev *sd, __s32 *value)
1164{
1165 unsigned char v = 0;
1166 int ret = ov7670_read(sd, REG_CONTRAS, &v);
1167
1168 *value = v;
1169 return ret;
1170}
1171
1172static int ov7670_g_hflip(struct v4l2_subdev *sd, __s32 *value)
1173{
1174 int ret;
1175 unsigned char v = 0;
1176
1177 ret = ov7670_read(sd, REG_MVFP, &v);
1178 *value = (v & MVFP_MIRROR) == MVFP_MIRROR;
1179 return ret;
1180}
1181
1182
1183static int ov7670_s_hflip(struct v4l2_subdev *sd, int value) 1288static int ov7670_s_hflip(struct v4l2_subdev *sd, int value)
1184{ 1289{
1185 unsigned char v = 0; 1290 unsigned char v = 0;
@@ -1195,19 +1300,6 @@ static int ov7670_s_hflip(struct v4l2_subdev *sd, int value)
1195 return ret; 1300 return ret;
1196} 1301}
1197 1302
1198
1199
1200static int ov7670_g_vflip(struct v4l2_subdev *sd, __s32 *value)
1201{
1202 int ret;
1203 unsigned char v = 0;
1204
1205 ret = ov7670_read(sd, REG_MVFP, &v);
1206 *value = (v & MVFP_FLIP) == MVFP_FLIP;
1207 return ret;
1208}
1209
1210
1211static int ov7670_s_vflip(struct v4l2_subdev *sd, int value) 1303static int ov7670_s_vflip(struct v4l2_subdev *sd, int value)
1212{ 1304{
1213 unsigned char v = 0; 1305 unsigned char v = 0;
@@ -1256,16 +1348,6 @@ static int ov7670_s_gain(struct v4l2_subdev *sd, int value)
1256/* 1348/*
1257 * Tweak autogain. 1349 * Tweak autogain.
1258 */ 1350 */
1259static int ov7670_g_autogain(struct v4l2_subdev *sd, __s32 *value)
1260{
1261 int ret;
1262 unsigned char com8;
1263
1264 ret = ov7670_read(sd, REG_COM8, &com8);
1265 *value = (com8 & COM8_AGC) != 0;
1266 return ret;
1267}
1268
1269static int ov7670_s_autogain(struct v4l2_subdev *sd, int value) 1351static int ov7670_s_autogain(struct v4l2_subdev *sd, int value)
1270{ 1352{
1271 int ret; 1353 int ret;
@@ -1282,22 +1364,6 @@ static int ov7670_s_autogain(struct v4l2_subdev *sd, int value)
1282 return ret; 1364 return ret;
1283} 1365}
1284 1366
1285/*
1286 * Exposure is spread all over the place: top 6 bits in AECHH, middle
1287 * 8 in AECH, and two stashed in COM1 just for the hell of it.
1288 */
1289static int ov7670_g_exp(struct v4l2_subdev *sd, __s32 *value)
1290{
1291 int ret;
1292 unsigned char com1, aech, aechh;
1293
1294 ret = ov7670_read(sd, REG_COM1, &com1) +
1295 ov7670_read(sd, REG_AECH, &aech) +
1296 ov7670_read(sd, REG_AECHH, &aechh);
1297 *value = ((aechh & 0x3f) << 10) | (aech << 2) | (com1 & 0x03);
1298 return ret;
1299}
1300
1301static int ov7670_s_exp(struct v4l2_subdev *sd, int value) 1367static int ov7670_s_exp(struct v4l2_subdev *sd, int value)
1302{ 1368{
1303 int ret; 1369 int ret;
@@ -1324,20 +1390,6 @@ static int ov7670_s_exp(struct v4l2_subdev *sd, int value)
1324/* 1390/*
1325 * Tweak autoexposure. 1391 * Tweak autoexposure.
1326 */ 1392 */
1327static int ov7670_g_autoexp(struct v4l2_subdev *sd, __s32 *value)
1328{
1329 int ret;
1330 unsigned char com8;
1331 enum v4l2_exposure_auto_type *atype = (enum v4l2_exposure_auto_type *) value;
1332
1333 ret = ov7670_read(sd, REG_COM8, &com8);
1334 if (com8 & COM8_AEC)
1335 *atype = V4L2_EXPOSURE_AUTO;
1336 else
1337 *atype = V4L2_EXPOSURE_MANUAL;
1338 return ret;
1339}
1340
1341static int ov7670_s_autoexp(struct v4l2_subdev *sd, 1393static int ov7670_s_autoexp(struct v4l2_subdev *sd,
1342 enum v4l2_exposure_auto_type value) 1394 enum v4l2_exposure_auto_type value)
1343{ 1395{
@@ -1356,90 +1408,60 @@ static int ov7670_s_autoexp(struct v4l2_subdev *sd,
1356} 1408}
1357 1409
1358 1410
1359 1411static int ov7670_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
1360static int ov7670_queryctrl(struct v4l2_subdev *sd,
1361 struct v4l2_queryctrl *qc)
1362{ 1412{
1363 /* Fill in min, max, step and default value for these controls. */ 1413 struct v4l2_subdev *sd = to_sd(ctrl);
1364 switch (qc->id) { 1414 struct ov7670_info *info = to_state(sd);
1365 case V4L2_CID_BRIGHTNESS:
1366 return v4l2_ctrl_query_fill(qc, 0, 255, 1, 128);
1367 case V4L2_CID_CONTRAST:
1368 return v4l2_ctrl_query_fill(qc, 0, 127, 1, 64);
1369 case V4L2_CID_VFLIP:
1370 case V4L2_CID_HFLIP:
1371 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 0);
1372 case V4L2_CID_SATURATION:
1373 return v4l2_ctrl_query_fill(qc, 0, 256, 1, 128);
1374 case V4L2_CID_HUE:
1375 return v4l2_ctrl_query_fill(qc, -180, 180, 5, 0);
1376 case V4L2_CID_GAIN:
1377 return v4l2_ctrl_query_fill(qc, 0, 255, 1, 128);
1378 case V4L2_CID_AUTOGAIN:
1379 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
1380 case V4L2_CID_EXPOSURE:
1381 return v4l2_ctrl_query_fill(qc, 0, 65535, 1, 500);
1382 case V4L2_CID_EXPOSURE_AUTO:
1383 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 0);
1384 }
1385 return -EINVAL;
1386}
1387 1415
1388static int ov7670_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
1389{
1390 switch (ctrl->id) { 1416 switch (ctrl->id) {
1391 case V4L2_CID_BRIGHTNESS:
1392 return ov7670_g_brightness(sd, &ctrl->value);
1393 case V4L2_CID_CONTRAST:
1394 return ov7670_g_contrast(sd, &ctrl->value);
1395 case V4L2_CID_SATURATION:
1396 return ov7670_g_sat(sd, &ctrl->value);
1397 case V4L2_CID_HUE:
1398 return ov7670_g_hue(sd, &ctrl->value);
1399 case V4L2_CID_VFLIP:
1400 return ov7670_g_vflip(sd, &ctrl->value);
1401 case V4L2_CID_HFLIP:
1402 return ov7670_g_hflip(sd, &ctrl->value);
1403 case V4L2_CID_GAIN:
1404 return ov7670_g_gain(sd, &ctrl->value);
1405 case V4L2_CID_AUTOGAIN: 1417 case V4L2_CID_AUTOGAIN:
1406 return ov7670_g_autogain(sd, &ctrl->value); 1418 return ov7670_g_gain(sd, &info->gain->val);
1407 case V4L2_CID_EXPOSURE:
1408 return ov7670_g_exp(sd, &ctrl->value);
1409 case V4L2_CID_EXPOSURE_AUTO:
1410 return ov7670_g_autoexp(sd, &ctrl->value);
1411 } 1419 }
1412 return -EINVAL; 1420 return -EINVAL;
1413} 1421}
1414 1422
1415static int ov7670_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 1423static int ov7670_s_ctrl(struct v4l2_ctrl *ctrl)
1416{ 1424{
1425 struct v4l2_subdev *sd = to_sd(ctrl);
1426 struct ov7670_info *info = to_state(sd);
1427
1417 switch (ctrl->id) { 1428 switch (ctrl->id) {
1418 case V4L2_CID_BRIGHTNESS: 1429 case V4L2_CID_BRIGHTNESS:
1419 return ov7670_s_brightness(sd, ctrl->value); 1430 return ov7670_s_brightness(sd, ctrl->val);
1420 case V4L2_CID_CONTRAST: 1431 case V4L2_CID_CONTRAST:
1421 return ov7670_s_contrast(sd, ctrl->value); 1432 return ov7670_s_contrast(sd, ctrl->val);
1422 case V4L2_CID_SATURATION: 1433 case V4L2_CID_SATURATION:
1423 return ov7670_s_sat(sd, ctrl->value); 1434 return ov7670_s_sat_hue(sd,
1424 case V4L2_CID_HUE: 1435 info->saturation->val, info->hue->val);
1425 return ov7670_s_hue(sd, ctrl->value);
1426 case V4L2_CID_VFLIP: 1436 case V4L2_CID_VFLIP:
1427 return ov7670_s_vflip(sd, ctrl->value); 1437 return ov7670_s_vflip(sd, ctrl->val);
1428 case V4L2_CID_HFLIP: 1438 case V4L2_CID_HFLIP:
1429 return ov7670_s_hflip(sd, ctrl->value); 1439 return ov7670_s_hflip(sd, ctrl->val);
1430 case V4L2_CID_GAIN:
1431 return ov7670_s_gain(sd, ctrl->value);
1432 case V4L2_CID_AUTOGAIN: 1440 case V4L2_CID_AUTOGAIN:
1433 return ov7670_s_autogain(sd, ctrl->value); 1441 /* Only set manual gain if auto gain is not explicitly
1434 case V4L2_CID_EXPOSURE: 1442 turned on. */
1435 return ov7670_s_exp(sd, ctrl->value); 1443 if (!ctrl->val) {
1444 /* ov7670_s_gain turns off auto gain */
1445 return ov7670_s_gain(sd, info->gain->val);
1446 }
1447 return ov7670_s_autogain(sd, ctrl->val);
1436 case V4L2_CID_EXPOSURE_AUTO: 1448 case V4L2_CID_EXPOSURE_AUTO:
1437 return ov7670_s_autoexp(sd, 1449 /* Only set manual exposure if auto exposure is not explicitly
1438 (enum v4l2_exposure_auto_type) ctrl->value); 1450 turned on. */
1451 if (ctrl->val == V4L2_EXPOSURE_MANUAL) {
1452 /* ov7670_s_exp turns off auto exposure */
1453 return ov7670_s_exp(sd, info->exposure->val);
1454 }
1455 return ov7670_s_autoexp(sd, ctrl->val);
1439 } 1456 }
1440 return -EINVAL; 1457 return -EINVAL;
1441} 1458}
1442 1459
1460static const struct v4l2_ctrl_ops ov7670_ctrl_ops = {
1461 .s_ctrl = ov7670_s_ctrl,
1462 .g_volatile_ctrl = ov7670_g_volatile_ctrl,
1463};
1464
1443static int ov7670_g_chip_ident(struct v4l2_subdev *sd, 1465static int ov7670_g_chip_ident(struct v4l2_subdev *sd,
1444 struct v4l2_dbg_chip_ident *chip) 1466 struct v4l2_dbg_chip_ident *chip)
1445{ 1467{
@@ -1482,9 +1504,6 @@ static int ov7670_s_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *r
1482 1504
1483static const struct v4l2_subdev_core_ops ov7670_core_ops = { 1505static const struct v4l2_subdev_core_ops ov7670_core_ops = {
1484 .g_chip_ident = ov7670_g_chip_ident, 1506 .g_chip_ident = ov7670_g_chip_ident,
1485 .g_ctrl = ov7670_g_ctrl,
1486 .s_ctrl = ov7670_s_ctrl,
1487 .queryctrl = ov7670_queryctrl,
1488 .reset = ov7670_reset, 1507 .reset = ov7670_reset,
1489 .init = ov7670_init, 1508 .init = ov7670_init,
1490#ifdef CONFIG_VIDEO_ADV_DEBUG 1509#ifdef CONFIG_VIDEO_ADV_DEBUG
@@ -1510,9 +1529,25 @@ static const struct v4l2_subdev_ops ov7670_ops = {
1510 1529
1511/* ----------------------------------------------------------------------- */ 1530/* ----------------------------------------------------------------------- */
1512 1531
1532static const struct ov7670_devtype ov7670_devdata[] = {
1533 [MODEL_OV7670] = {
1534 .win_sizes = ov7670_win_sizes,
1535 .n_win_sizes = ARRAY_SIZE(ov7670_win_sizes),
1536 .set_framerate = ov7670_set_framerate_legacy,
1537 .get_framerate = ov7670_get_framerate_legacy,
1538 },
1539 [MODEL_OV7675] = {
1540 .win_sizes = ov7675_win_sizes,
1541 .n_win_sizes = ARRAY_SIZE(ov7675_win_sizes),
1542 .set_framerate = ov7675_set_framerate,
1543 .get_framerate = ov7675_get_framerate,
1544 },
1545};
1546
1513static int ov7670_probe(struct i2c_client *client, 1547static int ov7670_probe(struct i2c_client *client,
1514 const struct i2c_device_id *id) 1548 const struct i2c_device_id *id)
1515{ 1549{
1550 struct v4l2_fract tpf;
1516 struct v4l2_subdev *sd; 1551 struct v4l2_subdev *sd;
1517 struct ov7670_info *info; 1552 struct ov7670_info *info;
1518 int ret; 1553 int ret;
@@ -1537,6 +1572,16 @@ static int ov7670_probe(struct i2c_client *client,
1537 1572
1538 if (config->clock_speed) 1573 if (config->clock_speed)
1539 info->clock_speed = config->clock_speed; 1574 info->clock_speed = config->clock_speed;
1575
1576 /*
1577 * It should be allowed for ov7670 too when it is migrated to
1578 * the new frame rate formula.
1579 */
1580 if (config->pll_bypass && id->driver_data != MODEL_OV7670)
1581 info->pll_bypass = true;
1582
1583 if (config->pclk_hb_disable)
1584 info->pclk_hb_disable = true;
1540 } 1585 }
1541 1586
1542 /* Make sure it's an ov7670 */ 1587 /* Make sure it's an ov7670 */
@@ -1551,9 +1596,58 @@ static int ov7670_probe(struct i2c_client *client,
1551 v4l_info(client, "chip found @ 0x%02x (%s)\n", 1596 v4l_info(client, "chip found @ 0x%02x (%s)\n",
1552 client->addr << 1, client->adapter->name); 1597 client->addr << 1, client->adapter->name);
1553 1598
1599 info->devtype = &ov7670_devdata[id->driver_data];
1554 info->fmt = &ov7670_formats[0]; 1600 info->fmt = &ov7670_formats[0];
1555 info->sat = 128; /* Review this */ 1601 info->clkrc = 0;
1556 info->clkrc = info->clock_speed / 30; 1602
1603 /* Set default frame rate to 30 fps */
1604 tpf.numerator = 1;
1605 tpf.denominator = 30;
1606 info->devtype->set_framerate(sd, &tpf);
1607
1608 if (info->pclk_hb_disable)
1609 ov7670_write(sd, REG_COM10, COM10_PCLK_HB);
1610
1611 v4l2_ctrl_handler_init(&info->hdl, 10);
1612 v4l2_ctrl_new_std(&info->hdl, &ov7670_ctrl_ops,
1613 V4L2_CID_BRIGHTNESS, 0, 255, 1, 128);
1614 v4l2_ctrl_new_std(&info->hdl, &ov7670_ctrl_ops,
1615 V4L2_CID_CONTRAST, 0, 127, 1, 64);
1616 v4l2_ctrl_new_std(&info->hdl, &ov7670_ctrl_ops,
1617 V4L2_CID_VFLIP, 0, 1, 1, 0);
1618 v4l2_ctrl_new_std(&info->hdl, &ov7670_ctrl_ops,
1619 V4L2_CID_HFLIP, 0, 1, 1, 0);
1620 info->saturation = v4l2_ctrl_new_std(&info->hdl, &ov7670_ctrl_ops,
1621 V4L2_CID_SATURATION, 0, 256, 1, 128);
1622 info->hue = v4l2_ctrl_new_std(&info->hdl, &ov7670_ctrl_ops,
1623 V4L2_CID_HUE, -180, 180, 5, 0);
1624 info->gain = v4l2_ctrl_new_std(&info->hdl, &ov7670_ctrl_ops,
1625 V4L2_CID_GAIN, 0, 255, 1, 128);
1626 info->auto_gain = v4l2_ctrl_new_std(&info->hdl, &ov7670_ctrl_ops,
1627 V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
1628 info->exposure = v4l2_ctrl_new_std(&info->hdl, &ov7670_ctrl_ops,
1629 V4L2_CID_EXPOSURE, 0, 65535, 1, 500);
1630 info->auto_exposure = v4l2_ctrl_new_std_menu(&info->hdl, &ov7670_ctrl_ops,
1631 V4L2_CID_EXPOSURE_AUTO, V4L2_EXPOSURE_MANUAL, 0,
1632 V4L2_EXPOSURE_AUTO);
1633 sd->ctrl_handler = &info->hdl;
1634 if (info->hdl.error) {
1635 int err = info->hdl.error;
1636
1637 v4l2_ctrl_handler_free(&info->hdl);
1638 kfree(info);
1639 return err;
1640 }
1641 /*
1642 * We have checked empirically that hw allows to read back the gain
1643 * value chosen by auto gain but that's not the case for auto exposure.
1644 */
1645 v4l2_ctrl_auto_cluster(2, &info->auto_gain, 0, true);
1646 v4l2_ctrl_auto_cluster(2, &info->auto_exposure,
1647 V4L2_EXPOSURE_MANUAL, false);
1648 v4l2_ctrl_cluster(2, &info->saturation);
1649 v4l2_ctrl_handler_setup(&info->hdl);
1650
1557 return 0; 1651 return 0;
1558} 1652}
1559 1653
@@ -1561,14 +1655,17 @@ static int ov7670_probe(struct i2c_client *client,
1561static int ov7670_remove(struct i2c_client *client) 1655static int ov7670_remove(struct i2c_client *client)
1562{ 1656{
1563 struct v4l2_subdev *sd = i2c_get_clientdata(client); 1657 struct v4l2_subdev *sd = i2c_get_clientdata(client);
1658 struct ov7670_info *info = to_state(sd);
1564 1659
1565 v4l2_device_unregister_subdev(sd); 1660 v4l2_device_unregister_subdev(sd);
1566 kfree(to_state(sd)); 1661 v4l2_ctrl_handler_free(&info->hdl);
1662 kfree(info);
1567 return 0; 1663 return 0;
1568} 1664}
1569 1665
1570static const struct i2c_device_id ov7670_id[] = { 1666static const struct i2c_device_id ov7670_id[] = {
1571 { "ov7670", 0 }, 1667 { "ov7670", MODEL_OV7670 },
1668 { "ov7675", MODEL_OV7675 },
1572 { } 1669 { }
1573}; 1670};
1574MODULE_DEVICE_TABLE(i2c, ov7670_id); 1671MODULE_DEVICE_TABLE(i2c, ov7670_id);
diff --git a/drivers/media/i2c/ov9650.c b/drivers/media/i2c/ov9650.c
new file mode 100644
index 000000000000..1dbb8118a285
--- /dev/null
+++ b/drivers/media/i2c/ov9650.c
@@ -0,0 +1,1562 @@
1/*
2 * Omnivision OV9650/OV9652 CMOS Image Sensor driver
3 *
4 * Copyright (C) 2013, Sylwester Nawrocki <sylvester.nawrocki@gmail.com>
5 *
6 * Register definitions and initial settings based on a driver written
7 * by Vladimir Fonov.
8 * Copyright (c) 2010, Vladimir Fonov
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14#include <linux/delay.h>
15#include <linux/gpio.h>
16#include <linux/i2c.h>
17#include <linux/kernel.h>
18#include <linux/media.h>
19#include <linux/module.h>
20#include <linux/ratelimit.h>
21#include <linux/slab.h>
22#include <linux/string.h>
23#include <linux/videodev2.h>
24
25#include <media/media-entity.h>
26#include <media/v4l2-ctrls.h>
27#include <media/v4l2-device.h>
28#include <media/v4l2-event.h>
29#include <media/v4l2-image-sizes.h>
30#include <media/v4l2-subdev.h>
31#include <media/v4l2-mediabus.h>
32#include <media/ov9650.h>
33
34static int debug;
35module_param(debug, int, 0644);
36MODULE_PARM_DESC(debug, "Debug level (0-2)");
37
38#define DRIVER_NAME "OV9650"
39
40/*
41 * OV9650/OV9652 register definitions
42 */
43#define REG_GAIN 0x00 /* Gain control, AGC[7:0] */
44#define REG_BLUE 0x01 /* AWB - Blue chanel gain */
45#define REG_RED 0x02 /* AWB - Red chanel gain */
46#define REG_VREF 0x03 /* [7:6] - AGC[9:8], [5:3]/[2:0] */
47#define VREF_GAIN_MASK 0xc0 /* - VREF end/start low 3 bits */
48#define REG_COM1 0x04
49#define COM1_CCIR656 0x40
50#define REG_B_AVE 0x05
51#define REG_GB_AVE 0x06
52#define REG_GR_AVE 0x07
53#define REG_R_AVE 0x08
54#define REG_COM2 0x09
55#define REG_PID 0x0a /* Product ID MSB */
56#define REG_VER 0x0b /* Product ID LSB */
57#define REG_COM3 0x0c
58#define COM3_SWAP 0x40
59#define COM3_VARIOPIXEL1 0x04
60#define REG_COM4 0x0d /* Vario Pixels */
61#define COM4_VARIOPIXEL2 0x80
62#define REG_COM5 0x0e /* System clock options */
63#define COM5_SLAVE_MODE 0x10
64#define COM5_SYSTEMCLOCK48MHZ 0x80
65#define REG_COM6 0x0f /* HREF & ADBLC options */
66#define REG_AECH 0x10 /* Exposure value, AEC[9:2] */
67#define REG_CLKRC 0x11 /* Clock control */
68#define CLK_EXT 0x40 /* Use external clock directly */
69#define CLK_SCALE 0x3f /* Mask for internal clock scale */
70#define REG_COM7 0x12 /* SCCB reset, output format */
71#define COM7_RESET 0x80
72#define COM7_FMT_MASK 0x38
73#define COM7_FMT_VGA 0x40
74#define COM7_FMT_CIF 0x20
75#define COM7_FMT_QVGA 0x10
76#define COM7_FMT_QCIF 0x08
77#define COM7_RGB 0x04
78#define COM7_YUV 0x00
79#define COM7_BAYER 0x01
80#define COM7_PBAYER 0x05
81#define REG_COM8 0x13 /* AGC/AEC options */
82#define COM8_FASTAEC 0x80 /* Enable fast AGC/AEC */
83#define COM8_AECSTEP 0x40 /* Unlimited AEC step size */
84#define COM8_BFILT 0x20 /* Band filter enable */
85#define COM8_AGC 0x04 /* Auto gain enable */
86#define COM8_AWB 0x02 /* White balance enable */
87#define COM8_AEC 0x01 /* Auto exposure enable */
88#define REG_COM9 0x14 /* Gain ceiling */
89#define COM9_GAIN_CEIL_MASK 0x70 /* */
90#define REG_COM10 0x15 /* PCLK, HREF, HSYNC signals polarity */
91#define COM10_HSYNC 0x40 /* HSYNC instead of HREF */
92#define COM10_PCLK_HB 0x20 /* Suppress PCLK on horiz blank */
93#define COM10_HREF_REV 0x08 /* Reverse HREF */
94#define COM10_VS_LEAD 0x04 /* VSYNC on clock leading edge */
95#define COM10_VS_NEG 0x02 /* VSYNC negative */
96#define COM10_HS_NEG 0x01 /* HSYNC negative */
97#define REG_HSTART 0x17 /* Horiz start high bits */
98#define REG_HSTOP 0x18 /* Horiz stop high bits */
99#define REG_VSTART 0x19 /* Vert start high bits */
100#define REG_VSTOP 0x1a /* Vert stop high bits */
101#define REG_PSHFT 0x1b /* Pixel delay after HREF */
102#define REG_MIDH 0x1c /* Manufacturer ID MSB */
103#define REG_MIDL 0x1d /* Manufufacturer ID LSB */
104#define REG_MVFP 0x1e /* Image mirror/flip */
105#define MVFP_MIRROR 0x20 /* Mirror image */
106#define MVFP_FLIP 0x10 /* Vertical flip */
107#define REG_BOS 0x20 /* B channel Offset */
108#define REG_GBOS 0x21 /* Gb channel Offset */
109#define REG_GROS 0x22 /* Gr channel Offset */
110#define REG_ROS 0x23 /* R channel Offset */
111#define REG_AEW 0x24 /* AGC upper limit */
112#define REG_AEB 0x25 /* AGC lower limit */
113#define REG_VPT 0x26 /* AGC/AEC fast mode op region */
114#define REG_BBIAS 0x27 /* B channel output bias */
115#define REG_GBBIAS 0x28 /* Gb channel output bias */
116#define REG_GRCOM 0x29 /* Analog BLC & regulator */
117#define REG_EXHCH 0x2a /* Dummy pixel insert MSB */
118#define REG_EXHCL 0x2b /* Dummy pixel insert LSB */
119#define REG_RBIAS 0x2c /* R channel output bias */
120#define REG_ADVFL 0x2d /* LSB of dummy line insert */
121#define REG_ADVFH 0x2e /* MSB of dummy line insert */
122#define REG_YAVE 0x2f /* Y/G channel average value */
123#define REG_HSYST 0x30 /* HSYNC rising edge delay LSB*/
124#define REG_HSYEN 0x31 /* HSYNC falling edge delay LSB*/
125#define REG_HREF 0x32 /* HREF pieces */
126#define REG_CHLF 0x33 /* reserved */
127#define REG_ADC 0x37 /* reserved */
128#define REG_ACOM 0x38 /* reserved */
129#define REG_OFON 0x39 /* Power down register */
130#define OFON_PWRDN 0x08 /* Power down bit */
131#define REG_TSLB 0x3a /* YUVU format */
132#define TSLB_YUYV_MASK 0x0c /* UYVY or VYUY - see com13 */
133#define REG_COM11 0x3b /* Night mode, banding filter enable */
134#define COM11_NIGHT 0x80 /* Night mode enable */
135#define COM11_NMFR 0x60 /* Two bit NM frame rate */
136#define COM11_BANDING 0x01 /* Banding filter */
137#define COM11_AEC_REF_MASK 0x18 /* AEC reference area selection */
138#define REG_COM12 0x3c /* HREF option, UV average */
139#define COM12_HREF 0x80 /* HREF always */
140#define REG_COM13 0x3d /* Gamma selection, Color matrix en. */
141#define COM13_GAMMA 0x80 /* Gamma enable */
142#define COM13_UVSAT 0x40 /* UV saturation auto adjustment */
143#define COM13_UVSWAP 0x01 /* V before U - w/TSLB */
144#define REG_COM14 0x3e /* Edge enhancement options */
145#define COM14_EDGE_EN 0x02
146#define COM14_EEF_X2 0x01
147#define REG_EDGE 0x3f /* Edge enhancement factor */
148#define EDGE_FACTOR_MASK 0x0f
149#define REG_COM15 0x40 /* Output range, RGB 555/565 */
150#define COM15_R10F0 0x00 /* Data range 10 to F0 */
151#define COM15_R01FE 0x80 /* 01 to FE */
152#define COM15_R00FF 0xc0 /* 00 to FF */
153#define COM15_RGB565 0x10 /* RGB565 output */
154#define COM15_RGB555 0x30 /* RGB555 output */
155#define COM15_SWAPRB 0x04 /* Swap R&B */
156#define REG_COM16 0x41 /* Color matrix coeff options */
157#define REG_COM17 0x42 /* Single frame out, banding filter */
158/* n = 1...9, 0x4f..0x57 */
159#define REG_MTX(__n) (0x4f + (__n) - 1)
160#define REG_MTXS 0x58
161/* Lens Correction Option 1...5, __n = 0...5 */
162#define REG_LCC(__n) (0x62 + (__n) - 1)
163#define LCC5_LCC_ENABLE 0x01 /* LCC5, enable lens correction */
164#define LCC5_LCC_COLOR 0x04
165#define REG_MANU 0x67 /* Manual U value */
166#define REG_MANV 0x68 /* Manual V value */
167#define REG_HV 0x69 /* Manual banding filter MSB */
168#define REG_MBD 0x6a /* Manual banding filter value */
169#define REG_DBLV 0x6b /* reserved */
170#define REG_GSP 0x6c /* Gamma curve */
171#define GSP_LEN 15
172#define REG_GST 0x7c /* Gamma curve */
173#define GST_LEN 15
174#define REG_COM21 0x8b
175#define REG_COM22 0x8c /* Edge enhancement, denoising */
176#define COM22_WHTPCOR 0x02 /* White pixel correction enable */
177#define COM22_WHTPCOROPT 0x01 /* White pixel correction option */
178#define COM22_DENOISE 0x10 /* White pixel correction option */
179#define REG_COM23 0x8d /* Color bar test, color gain */
180#define COM23_TEST_MODE 0x10
181#define REG_DBLC1 0x8f /* Digital BLC */
182#define REG_DBLC_B 0x90 /* Digital BLC B channel offset */
183#define REG_DBLC_R 0x91 /* Digital BLC R channel offset */
184#define REG_DM_LNL 0x92 /* Dummy line low 8 bits */
185#define REG_DM_LNH 0x93 /* Dummy line high 8 bits */
186#define REG_LCCFB 0x9d /* Lens Correction B channel */
187#define REG_LCCFR 0x9e /* Lens Correction R channel */
188#define REG_DBLC_GB 0x9f /* Digital BLC GB chan offset */
189#define REG_DBLC_GR 0xa0 /* Digital BLC GR chan offset */
190#define REG_AECHM 0xa1 /* Exposure value - bits AEC[15:10] */
191#define REG_BD50ST 0xa2 /* Banding filter value for 50Hz */
192#define REG_BD60ST 0xa3 /* Banding filter value for 60Hz */
193#define REG_NULL 0xff /* Array end token */
194
195#define DEF_CLKRC 0x80
196
197#define OV965X_ID(_msb, _lsb) ((_msb) << 8 | (_lsb))
198#define OV9650_ID 0x9650
199#define OV9652_ID 0x9652
200
201struct ov965x_ctrls {
202 struct v4l2_ctrl_handler handler;
203 struct {
204 struct v4l2_ctrl *auto_exp;
205 struct v4l2_ctrl *exposure;
206 };
207 struct {
208 struct v4l2_ctrl *auto_wb;
209 struct v4l2_ctrl *blue_balance;
210 struct v4l2_ctrl *red_balance;
211 };
212 struct {
213 struct v4l2_ctrl *hflip;
214 struct v4l2_ctrl *vflip;
215 };
216 struct {
217 struct v4l2_ctrl *auto_gain;
218 struct v4l2_ctrl *gain;
219 };
220 struct v4l2_ctrl *brightness;
221 struct v4l2_ctrl *saturation;
222 struct v4l2_ctrl *sharpness;
223 struct v4l2_ctrl *light_freq;
224 u8 update;
225};
226
227struct ov965x_framesize {
228 u16 width;
229 u16 height;
230 u16 max_exp_lines;
231 const u8 *regs;
232};
233
234struct ov965x_interval {
235 struct v4l2_fract interval;
236 /* Maximum resolution for this interval */
237 struct v4l2_frmsize_discrete size;
238 u8 clkrc_div;
239};
240
241enum gpio_id {
242 GPIO_PWDN,
243 GPIO_RST,
244 NUM_GPIOS,
245};
246
247struct ov965x {
248 struct v4l2_subdev sd;
249 struct media_pad pad;
250 enum v4l2_mbus_type bus_type;
251 int gpios[NUM_GPIOS];
252 /* External master clock frequency */
253 unsigned long mclk_frequency;
254
255 /* Protects the struct fields below */
256 struct mutex lock;
257
258 struct i2c_client *client;
259
260 /* Exposure row interval in us */
261 unsigned int exp_row_interval;
262
263 unsigned short id;
264 const struct ov965x_framesize *frame_size;
265 /* YUYV sequence (pixel format) control register */
266 u8 tslb_reg;
267 struct v4l2_mbus_framefmt format;
268
269 struct ov965x_ctrls ctrls;
270 /* Pointer to frame rate control data structure */
271 const struct ov965x_interval *fiv;
272
273 int streaming;
274 int power;
275
276 u8 apply_frame_fmt;
277};
278
279struct i2c_rv {
280 u8 addr;
281 u8 value;
282};
283
284static const struct i2c_rv ov965x_init_regs[] = {
285 { REG_COM2, 0x10 }, /* Set soft sleep mode */
286 { REG_COM5, 0x00 }, /* System clock options */
287 { REG_COM2, 0x01 }, /* Output drive, soft sleep mode */
288 { REG_COM10, 0x00 }, /* Slave mode, HREF vs HSYNC, signals negate */
289 { REG_EDGE, 0xa6 }, /* Edge enhancement treshhold and factor */
290 { REG_COM16, 0x02 }, /* Color matrix coeff double option */
291 { REG_COM17, 0x08 }, /* Single frame out, banding filter */
292 { 0x16, 0x06 },
293 { REG_CHLF, 0xc0 }, /* Reserved */
294 { 0x34, 0xbf },
295 { 0xa8, 0x80 },
296 { 0x96, 0x04 },
297 { 0x8e, 0x00 },
298 { REG_COM12, 0x77 }, /* HREF option, UV average */
299 { 0x8b, 0x06 },
300 { 0x35, 0x91 },
301 { 0x94, 0x88 },
302 { 0x95, 0x88 },
303 { REG_COM15, 0xc1 }, /* Output range, RGB 555/565 */
304 { REG_GRCOM, 0x2f }, /* Analog BLC & regulator */
305 { REG_COM6, 0x43 }, /* HREF & ADBLC options */
306 { REG_COM8, 0xe5 }, /* AGC/AEC options */
307 { REG_COM13, 0x90 }, /* Gamma selection, colour matrix, UV delay */
308 { REG_HV, 0x80 }, /* Manual banding filter MSB */
309 { 0x5c, 0x96 }, /* Reserved up to 0xa5 */
310 { 0x5d, 0x96 },
311 { 0x5e, 0x10 },
312 { 0x59, 0xeb },
313 { 0x5a, 0x9c },
314 { 0x5b, 0x55 },
315 { 0x43, 0xf0 },
316 { 0x44, 0x10 },
317 { 0x45, 0x55 },
318 { 0x46, 0x86 },
319 { 0x47, 0x64 },
320 { 0x48, 0x86 },
321 { 0x5f, 0xe0 },
322 { 0x60, 0x8c },
323 { 0x61, 0x20 },
324 { 0xa5, 0xd9 },
325 { 0xa4, 0x74 }, /* reserved */
326 { REG_COM23, 0x02 }, /* Color gain analog/_digital_ */
327 { REG_COM8, 0xe7 }, /* Enable AEC, AWB, AEC */
328 { REG_COM22, 0x23 }, /* Edge enhancement, denoising */
329 { 0xa9, 0xb8 },
330 { 0xaa, 0x92 },
331 { 0xab, 0x0a },
332 { REG_DBLC1, 0xdf }, /* Digital BLC */
333 { REG_DBLC_B, 0x00 }, /* Digital BLC B chan offset */
334 { REG_DBLC_R, 0x00 }, /* Digital BLC R chan offset */
335 { REG_DBLC_GB, 0x00 }, /* Digital BLC GB chan offset */
336 { REG_DBLC_GR, 0x00 },
337 { REG_COM9, 0x3a }, /* Gain ceiling 16x */
338 { REG_NULL, 0 }
339};
340
341#define NUM_FMT_REGS 14
342/*
343 * COM7, COM3, COM4, HSTART, HSTOP, HREF, VSTART, VSTOP, VREF,
344 * EXHCH, EXHCL, ADC, OCOM, OFON
345 */
346static const u8 frame_size_reg_addr[NUM_FMT_REGS] = {
347 0x12, 0x0c, 0x0d, 0x17, 0x18, 0x32, 0x19, 0x1a, 0x03,
348 0x2a, 0x2b, 0x37, 0x38, 0x39,
349};
350
351static const u8 ov965x_sxga_regs[NUM_FMT_REGS] = {
352 0x00, 0x00, 0x00, 0x1e, 0xbe, 0xbf, 0x01, 0x81, 0x12,
353 0x10, 0x34, 0x81, 0x93, 0x51,
354};
355
356static const u8 ov965x_vga_regs[NUM_FMT_REGS] = {
357 0x40, 0x04, 0x80, 0x26, 0xc6, 0xed, 0x01, 0x3d, 0x00,
358 0x10, 0x40, 0x91, 0x12, 0x43,
359};
360
361/* Determined empirically. */
362static const u8 ov965x_qvga_regs[NUM_FMT_REGS] = {
363 0x10, 0x04, 0x80, 0x25, 0xc5, 0xbf, 0x00, 0x80, 0x12,
364 0x10, 0x40, 0x91, 0x12, 0x43,
365};
366
367static const struct ov965x_framesize ov965x_framesizes[] = {
368 {
369 .width = SXGA_WIDTH,
370 .height = SXGA_HEIGHT,
371 .regs = ov965x_sxga_regs,
372 .max_exp_lines = 1048,
373 }, {
374 .width = VGA_WIDTH,
375 .height = VGA_HEIGHT,
376 .regs = ov965x_vga_regs,
377 .max_exp_lines = 498,
378 }, {
379 .width = QVGA_WIDTH,
380 .height = QVGA_HEIGHT,
381 .regs = ov965x_qvga_regs,
382 .max_exp_lines = 248,
383 },
384};
385
386struct ov965x_pixfmt {
387 enum v4l2_mbus_pixelcode code;
388 u32 colorspace;
389 /* REG_TSLB value, only bits [3:2] may be set. */
390 u8 tslb_reg;
391};
392
393static const struct ov965x_pixfmt ov965x_formats[] = {
394 { V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG, 0x00},
395 { V4L2_MBUS_FMT_YVYU8_2X8, V4L2_COLORSPACE_JPEG, 0x04},
396 { V4L2_MBUS_FMT_UYVY8_2X8, V4L2_COLORSPACE_JPEG, 0x0c},
397 { V4L2_MBUS_FMT_VYUY8_2X8, V4L2_COLORSPACE_JPEG, 0x08},
398};
399
400/*
401 * This table specifies possible frame resolution and interval
402 * combinations. Default CLKRC[5:0] divider values are valid
403 * only for 24 MHz external clock frequency.
404 */
405static struct ov965x_interval ov965x_intervals[] = {
406 {{ 100, 625 }, { SXGA_WIDTH, SXGA_HEIGHT }, 0 }, /* 6.25 fps */
407 {{ 10, 125 }, { VGA_WIDTH, VGA_HEIGHT }, 1 }, /* 12.5 fps */
408 {{ 10, 125 }, { QVGA_WIDTH, QVGA_HEIGHT }, 3 }, /* 12.5 fps */
409 {{ 1, 25 }, { VGA_WIDTH, VGA_HEIGHT }, 0 }, /* 25 fps */
410 {{ 1, 25 }, { QVGA_WIDTH, QVGA_HEIGHT }, 1 }, /* 25 fps */
411};
412
413static inline struct v4l2_subdev *ctrl_to_sd(struct v4l2_ctrl *ctrl)
414{
415 return &container_of(ctrl->handler, struct ov965x, ctrls.handler)->sd;
416}
417
418static inline struct ov965x *to_ov965x(struct v4l2_subdev *sd)
419{
420 return container_of(sd, struct ov965x, sd);
421}
422
423static int ov965x_read(struct i2c_client *client, u8 addr, u8 *val)
424{
425 u8 buf = addr;
426 struct i2c_msg msg = {
427 .addr = client->addr,
428 .flags = 0,
429 .len = 1,
430 .buf = &buf
431 };
432 int ret;
433
434 ret = i2c_transfer(client->adapter, &msg, 1);
435 if (ret == 1) {
436 msg.flags = I2C_M_RD;
437 ret = i2c_transfer(client->adapter, &msg, 1);
438
439 if (ret == 1)
440 *val = buf;
441 }
442
443 v4l2_dbg(2, debug, client, "%s: 0x%02x @ 0x%02x. (%d)\n",
444 __func__, *val, addr, ret);
445
446 return ret == 1 ? 0 : ret;
447}
448
449static int ov965x_write(struct i2c_client *client, u8 addr, u8 val)
450{
451 u8 buf[2] = { addr, val };
452
453 int ret = i2c_master_send(client, buf, 2);
454
455 v4l2_dbg(2, debug, client, "%s: 0x%02x @ 0x%02X (%d)\n",
456 __func__, val, addr, ret);
457
458 return ret == 2 ? 0 : ret;
459}
460
461static int ov965x_write_array(struct i2c_client *client,
462 const struct i2c_rv *regs)
463{
464 int i, ret = 0;
465
466 for (i = 0; ret == 0 && regs[i].addr != REG_NULL; i++)
467 ret = ov965x_write(client, regs[i].addr, regs[i].value);
468
469 return ret;
470}
471
472static int ov965x_set_default_gamma_curve(struct ov965x *ov965x)
473{
474 static const u8 gamma_curve[] = {
475 /* Values taken from OV application note. */
476 0x40, 0x30, 0x4b, 0x60, 0x70, 0x70, 0x70, 0x70,
477 0x60, 0x60, 0x50, 0x48, 0x3a, 0x2e, 0x28, 0x22,
478 0x04, 0x07, 0x10, 0x28, 0x36, 0x44, 0x52, 0x60,
479 0x6c, 0x78, 0x8c, 0x9e, 0xbb, 0xd2, 0xe6
480 };
481 u8 addr = REG_GSP;
482 unsigned int i;
483
484 for (i = 0; i < ARRAY_SIZE(gamma_curve); i++) {
485 int ret = ov965x_write(ov965x->client, addr, gamma_curve[i]);
486 if (ret < 0)
487 return ret;
488 addr++;
489 }
490
491 return 0;
492};
493
494static int ov965x_set_color_matrix(struct ov965x *ov965x)
495{
496 static const u8 mtx[] = {
497 /* MTX1..MTX9, MTXS */
498 0x3a, 0x3d, 0x03, 0x12, 0x26, 0x38, 0x40, 0x40, 0x40, 0x0d
499 };
500 u8 addr = REG_MTX(1);
501 unsigned int i;
502
503 for (i = 0; i < ARRAY_SIZE(mtx); i++) {
504 int ret = ov965x_write(ov965x->client, addr, mtx[i]);
505 if (ret < 0)
506 return ret;
507 addr++;
508 }
509
510 return 0;
511}
512
513static void ov965x_gpio_set(int gpio, int val)
514{
515 if (gpio_is_valid(gpio))
516 gpio_set_value(gpio, val);
517}
518
519static void __ov965x_set_power(struct ov965x *ov965x, int on)
520{
521 if (on) {
522 ov965x_gpio_set(ov965x->gpios[GPIO_PWDN], 0);
523 ov965x_gpio_set(ov965x->gpios[GPIO_RST], 0);
524 usleep_range(25000, 26000);
525 } else {
526 ov965x_gpio_set(ov965x->gpios[GPIO_RST], 1);
527 ov965x_gpio_set(ov965x->gpios[GPIO_PWDN], 1);
528 }
529
530 ov965x->streaming = 0;
531}
532
533static int ov965x_s_power(struct v4l2_subdev *sd, int on)
534{
535 struct ov965x *ov965x = to_ov965x(sd);
536 struct i2c_client *client = ov965x->client;
537 int ret = 0;
538
539 v4l2_dbg(1, debug, client, "%s: on: %d\n", __func__, on);
540
541 mutex_lock(&ov965x->lock);
542 if (ov965x->power == !on) {
543 __ov965x_set_power(ov965x, on);
544 if (on) {
545 ret = ov965x_write_array(client,
546 ov965x_init_regs);
547 ov965x->apply_frame_fmt = 1;
548 ov965x->ctrls.update = 1;
549 }
550 }
551 if (!ret)
552 ov965x->power += on ? 1 : -1;
553
554 WARN_ON(ov965x->power < 0);
555 mutex_unlock(&ov965x->lock);
556 return ret;
557}
558
559/*
560 * V4L2 controls
561 */
562
563static void ov965x_update_exposure_ctrl(struct ov965x *ov965x)
564{
565 struct v4l2_ctrl *ctrl = ov965x->ctrls.exposure;
566 unsigned long fint, trow;
567 int min, max, def;
568 u8 clkrc;
569
570 mutex_lock(&ov965x->lock);
571 if (WARN_ON(!ctrl || !ov965x->frame_size)) {
572 mutex_unlock(&ov965x->lock);
573 return;
574 }
575 clkrc = DEF_CLKRC + ov965x->fiv->clkrc_div;
576 /* Calculate internal clock frequency */
577 fint = ov965x->mclk_frequency * ((clkrc >> 7) + 1) /
578 ((2 * ((clkrc & 0x3f) + 1)));
579 /* and the row interval (in us). */
580 trow = (2 * 1520 * 1000000UL) / fint;
581 max = ov965x->frame_size->max_exp_lines * trow;
582 ov965x->exp_row_interval = trow;
583 mutex_unlock(&ov965x->lock);
584
585 v4l2_dbg(1, debug, &ov965x->sd, "clkrc: %#x, fi: %lu, tr: %lu, %d\n",
586 clkrc, fint, trow, max);
587
588 /* Update exposure time range to match current frame format. */
589 min = (trow + 100) / 100;
590 max = (max - 100) / 100;
591 def = min + (max - min) / 2;
592
593 if (v4l2_ctrl_modify_range(ctrl, min, max, 1, def))
594 v4l2_err(&ov965x->sd, "Exposure ctrl range update failed\n");
595}
596
597static int ov965x_set_banding_filter(struct ov965x *ov965x, int value)
598{
599 unsigned long mbd, light_freq;
600 int ret;
601 u8 reg;
602
603 ret = ov965x_read(ov965x->client, REG_COM8, &reg);
604 if (!ret) {
605 if (value == V4L2_CID_POWER_LINE_FREQUENCY_DISABLED)
606 reg &= ~COM8_BFILT;
607 else
608 reg |= COM8_BFILT;
609 ret = ov965x_write(ov965x->client, REG_COM8, reg);
610 }
611 if (value == V4L2_CID_POWER_LINE_FREQUENCY_DISABLED)
612 return 0;
613 if (WARN_ON(ov965x->fiv == NULL))
614 return -EINVAL;
615 /* Set minimal exposure time for 50/60 HZ lighting */
616 if (value == V4L2_CID_POWER_LINE_FREQUENCY_50HZ)
617 light_freq = 50;
618 else
619 light_freq = 60;
620 mbd = (1000UL * ov965x->fiv->interval.denominator *
621 ov965x->frame_size->max_exp_lines) /
622 ov965x->fiv->interval.numerator;
623 mbd = ((mbd / (light_freq * 2)) + 500) / 1000UL;
624
625 return ov965x_write(ov965x->client, REG_MBD, mbd);
626}
627
628static int ov965x_set_white_balance(struct ov965x *ov965x, int awb)
629{
630 int ret;
631 u8 reg;
632
633 ret = ov965x_read(ov965x->client, REG_COM8, &reg);
634 if (!ret) {
635 reg = awb ? reg | REG_COM8 : reg & ~REG_COM8;
636 ret = ov965x_write(ov965x->client, REG_COM8, reg);
637 }
638 if (!ret && !awb) {
639 ret = ov965x_write(ov965x->client, REG_BLUE,
640 ov965x->ctrls.blue_balance->val);
641 if (ret < 0)
642 return ret;
643 ret = ov965x_write(ov965x->client, REG_RED,
644 ov965x->ctrls.red_balance->val);
645 }
646 return ret;
647}
648
649#define NUM_BR_LEVELS 7
650#define NUM_BR_REGS 3
651
652static int ov965x_set_brightness(struct ov965x *ov965x, int val)
653{
654 static const u8 regs[NUM_BR_LEVELS + 1][NUM_BR_REGS] = {
655 { REG_AEW, REG_AEB, REG_VPT },
656 { 0x1c, 0x12, 0x50 }, /* -3 */
657 { 0x3d, 0x30, 0x71 }, /* -2 */
658 { 0x50, 0x44, 0x92 }, /* -1 */
659 { 0x70, 0x64, 0xc3 }, /* 0 */
660 { 0x90, 0x84, 0xd4 }, /* +1 */
661 { 0xc4, 0xbf, 0xf9 }, /* +2 */
662 { 0xd8, 0xd0, 0xfa }, /* +3 */
663 };
664 int i, ret = 0;
665
666 val += (NUM_BR_LEVELS / 2 + 1);
667 if (val > NUM_BR_LEVELS)
668 return -EINVAL;
669
670 for (i = 0; i < NUM_BR_REGS && !ret; i++)
671 ret = ov965x_write(ov965x->client, regs[0][i],
672 regs[val][i]);
673 return ret;
674}
675
676static int ov965x_set_gain(struct ov965x *ov965x, int auto_gain)
677{
678 struct i2c_client *client = ov965x->client;
679 struct ov965x_ctrls *ctrls = &ov965x->ctrls;
680 int ret = 0;
681 u8 reg;
682 /*
683 * For manual mode we need to disable AGC first, so
684 * gain value in REG_VREF, REG_GAIN is not overwritten.
685 */
686 if (ctrls->auto_gain->is_new) {
687 ret = ov965x_read(client, REG_COM8, &reg);
688 if (ret < 0)
689 return ret;
690 if (ctrls->auto_gain->val)
691 reg |= COM8_AGC;
692 else
693 reg &= ~COM8_AGC;
694 ret = ov965x_write(client, REG_COM8, reg);
695 if (ret < 0)
696 return ret;
697 }
698
699 if (ctrls->gain->is_new && !auto_gain) {
700 unsigned int gain = ctrls->gain->val;
701 unsigned int rgain;
702 int m;
703 /*
704 * Convert gain control value to the sensor's gain
705 * registers (VREF[7:6], GAIN[7:0]) format.
706 */
707 for (m = 6; m >= 0; m--)
708 if (gain >= (1 << m) * 16)
709 break;
710 rgain = (gain - ((1 << m) * 16)) / (1 << m);
711 rgain |= (((1 << m) - 1) << 4);
712
713 ret = ov965x_write(client, REG_GAIN, rgain & 0xff);
714 if (ret < 0)
715 return ret;
716 ret = ov965x_read(client, REG_VREF, &reg);
717 if (ret < 0)
718 return ret;
719 reg &= ~VREF_GAIN_MASK;
720 reg |= (((rgain >> 8) & 0x3) << 6);
721 ret = ov965x_write(client, REG_VREF, reg);
722 if (ret < 0)
723 return ret;
724 /* Return updated control's value to userspace */
725 ctrls->gain->val = (1 << m) * (16 + (rgain & 0xf));
726 }
727
728 return ret;
729}
730
731static int ov965x_set_sharpness(struct ov965x *ov965x, unsigned int value)
732{
733 u8 com14, edge;
734 int ret;
735
736 ret = ov965x_read(ov965x->client, REG_COM14, &com14);
737 if (ret < 0)
738 return ret;
739 ret = ov965x_read(ov965x->client, REG_EDGE, &edge);
740 if (ret < 0)
741 return ret;
742 com14 = value ? com14 | COM14_EDGE_EN : com14 & ~COM14_EDGE_EN;
743 value--;
744 if (value > 0x0f) {
745 com14 |= COM14_EEF_X2;
746 value >>= 1;
747 } else {
748 com14 &= ~COM14_EEF_X2;
749 }
750 ret = ov965x_write(ov965x->client, REG_COM14, com14);
751 if (ret < 0)
752 return ret;
753
754 edge &= ~EDGE_FACTOR_MASK;
755 edge |= ((u8)value & 0x0f);
756
757 return ov965x_write(ov965x->client, REG_EDGE, edge);
758}
759
760static int ov965x_set_exposure(struct ov965x *ov965x, int exp)
761{
762 struct i2c_client *client = ov965x->client;
763 struct ov965x_ctrls *ctrls = &ov965x->ctrls;
764 bool auto_exposure = (exp == V4L2_EXPOSURE_AUTO);
765 int ret;
766 u8 reg;
767
768 if (ctrls->auto_exp->is_new) {
769 ret = ov965x_read(client, REG_COM8, &reg);
770 if (ret < 0)
771 return ret;
772 if (auto_exposure)
773 reg |= (COM8_AEC | COM8_AGC);
774 else
775 reg &= ~(COM8_AEC | COM8_AGC);
776 ret = ov965x_write(client, REG_COM8, reg);
777 if (ret < 0)
778 return ret;
779 }
780
781 if (!auto_exposure && ctrls->exposure->is_new) {
782 unsigned int exposure = (ctrls->exposure->val * 100)
783 / ov965x->exp_row_interval;
784 /*
785 * Manual exposure value
786 * [b15:b0] - AECHM (b15:b10), AECH (b9:b2), COM1 (b1:b0)
787 */
788 ret = ov965x_write(client, REG_COM1, exposure & 0x3);
789 if (!ret)
790 ret = ov965x_write(client, REG_AECH,
791 (exposure >> 2) & 0xff);
792 if (!ret)
793 ret = ov965x_write(client, REG_AECHM,
794 (exposure >> 10) & 0x3f);
795 /* Update the value to minimize rounding errors */
796 ctrls->exposure->val = ((exposure * ov965x->exp_row_interval)
797 + 50) / 100;
798 if (ret < 0)
799 return ret;
800 }
801
802 v4l2_ctrl_activate(ov965x->ctrls.brightness, !exp);
803 return 0;
804}
805
806static int ov965x_set_flip(struct ov965x *ov965x)
807{
808 u8 mvfp = 0;
809
810 if (ov965x->ctrls.hflip->val)
811 mvfp |= MVFP_MIRROR;
812
813 if (ov965x->ctrls.vflip->val)
814 mvfp |= MVFP_FLIP;
815
816 return ov965x_write(ov965x->client, REG_MVFP, mvfp);
817}
818
819#define NUM_SAT_LEVELS 5
820#define NUM_SAT_REGS 6
821
822static int ov965x_set_saturation(struct ov965x *ov965x, int val)
823{
824 static const u8 regs[NUM_SAT_LEVELS][NUM_SAT_REGS] = {
825 /* MTX(1)...MTX(6) */
826 { 0x1d, 0x1f, 0x02, 0x09, 0x13, 0x1c }, /* -2 */
827 { 0x2e, 0x31, 0x02, 0x0e, 0x1e, 0x2d }, /* -1 */
828 { 0x3a, 0x3d, 0x03, 0x12, 0x26, 0x38 }, /* 0 */
829 { 0x46, 0x49, 0x04, 0x16, 0x2e, 0x43 }, /* +1 */
830 { 0x57, 0x5c, 0x05, 0x1b, 0x39, 0x54 }, /* +2 */
831 };
832 u8 addr = REG_MTX(1);
833 int i, ret = 0;
834
835 val += (NUM_SAT_LEVELS / 2);
836 if (val >= NUM_SAT_LEVELS)
837 return -EINVAL;
838
839 for (i = 0; i < NUM_SAT_REGS && !ret; i++)
840 ret = ov965x_write(ov965x->client, addr + i, regs[val][i]);
841
842 return ret;
843}
844
845static int ov965x_set_test_pattern(struct ov965x *ov965x, int value)
846{
847 int ret;
848 u8 reg;
849
850 ret = ov965x_read(ov965x->client, REG_COM23, &reg);
851 if (ret < 0)
852 return ret;
853 reg = value ? reg | COM23_TEST_MODE : reg & ~COM23_TEST_MODE;
854 return ov965x_write(ov965x->client, REG_COM23, reg);
855}
856
857static int __g_volatile_ctrl(struct ov965x *ov965x, struct v4l2_ctrl *ctrl)
858{
859 struct i2c_client *client = ov965x->client;
860 unsigned int exposure, gain, m;
861 u8 reg0, reg1, reg2;
862 int ret;
863
864 if (!ov965x->power)
865 return 0;
866
867 switch (ctrl->id) {
868 case V4L2_CID_AUTOGAIN:
869 if (!ctrl->val)
870 return 0;
871 ret = ov965x_read(client, REG_GAIN, &reg0);
872 if (ret < 0)
873 return ret;
874 ret = ov965x_read(client, REG_VREF, &reg1);
875 if (ret < 0)
876 return ret;
877 gain = ((reg1 >> 6) << 8) | reg0;
878 m = 0x01 << fls(gain >> 4);
879 ov965x->ctrls.gain->val = m * (16 + (gain & 0xf));
880 break;
881
882 case V4L2_CID_EXPOSURE_AUTO:
883 if (ctrl->val == V4L2_EXPOSURE_MANUAL)
884 return 0;
885 ret = ov965x_read(client, REG_COM1, &reg0);
886 if (!ret)
887 ret = ov965x_read(client, REG_AECH, &reg1);
888 if (!ret)
889 ret = ov965x_read(client, REG_AECHM, &reg2);
890 if (ret < 0)
891 return ret;
892 exposure = ((reg2 & 0x3f) << 10) | (reg1 << 2) |
893 (reg0 & 0x3);
894 ov965x->ctrls.exposure->val = ((exposure *
895 ov965x->exp_row_interval) + 50) / 100;
896 break;
897 }
898
899 return 0;
900}
901
902static int ov965x_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
903{
904 struct v4l2_subdev *sd = ctrl_to_sd(ctrl);
905 struct ov965x *ov965x = to_ov965x(sd);
906 int ret;
907
908 v4l2_dbg(1, debug, sd, "g_ctrl: %s\n", ctrl->name);
909
910 mutex_lock(&ov965x->lock);
911 ret = __g_volatile_ctrl(ov965x, ctrl);
912 mutex_unlock(&ov965x->lock);
913 return ret;
914}
915
916static int ov965x_s_ctrl(struct v4l2_ctrl *ctrl)
917{
918 struct v4l2_subdev *sd = ctrl_to_sd(ctrl);
919 struct ov965x *ov965x = to_ov965x(sd);
920 int ret = -EINVAL;
921
922 v4l2_dbg(1, debug, sd, "s_ctrl: %s, value: %d. power: %d\n",
923 ctrl->name, ctrl->val, ov965x->power);
924
925 mutex_lock(&ov965x->lock);
926 /*
927 * If the device is not powered up now postpone applying control's
928 * value to the hardware, until it is ready to accept commands.
929 */
930 if (ov965x->power == 0) {
931 mutex_unlock(&ov965x->lock);
932 return 0;
933 }
934
935 switch (ctrl->id) {
936 case V4L2_CID_AUTO_WHITE_BALANCE:
937 ret = ov965x_set_white_balance(ov965x, ctrl->val);
938 break;
939
940 case V4L2_CID_BRIGHTNESS:
941 ret = ov965x_set_brightness(ov965x, ctrl->val);
942 break;
943
944 case V4L2_CID_EXPOSURE_AUTO:
945 ret = ov965x_set_exposure(ov965x, ctrl->val);
946 break;
947
948 case V4L2_CID_AUTOGAIN:
949 ret = ov965x_set_gain(ov965x, ctrl->val);
950 break;
951
952 case V4L2_CID_HFLIP:
953 ret = ov965x_set_flip(ov965x);
954 break;
955
956 case V4L2_CID_POWER_LINE_FREQUENCY:
957 ret = ov965x_set_banding_filter(ov965x, ctrl->val);
958 break;
959
960 case V4L2_CID_SATURATION:
961 ret = ov965x_set_saturation(ov965x, ctrl->val);
962 break;
963
964 case V4L2_CID_SHARPNESS:
965 ret = ov965x_set_sharpness(ov965x, ctrl->val);
966 break;
967
968 case V4L2_CID_TEST_PATTERN:
969 ret = ov965x_set_test_pattern(ov965x, ctrl->val);
970 break;
971 }
972
973 mutex_unlock(&ov965x->lock);
974 return ret;
975}
976
977static const struct v4l2_ctrl_ops ov965x_ctrl_ops = {
978 .g_volatile_ctrl = ov965x_g_volatile_ctrl,
979 .s_ctrl = ov965x_s_ctrl,
980};
981
982static const char * const test_pattern_menu[] = {
983 "Disabled",
984 "Color bars",
985 NULL
986};
987
988static int ov965x_initialize_controls(struct ov965x *ov965x)
989{
990 const struct v4l2_ctrl_ops *ops = &ov965x_ctrl_ops;
991 struct ov965x_ctrls *ctrls = &ov965x->ctrls;
992 struct v4l2_ctrl_handler *hdl = &ctrls->handler;
993 int ret;
994
995 ret = v4l2_ctrl_handler_init(hdl, 16);
996 if (ret < 0)
997 return ret;
998
999 /* Auto/manual white balance */
1000 ctrls->auto_wb = v4l2_ctrl_new_std(hdl, ops,
1001 V4L2_CID_AUTO_WHITE_BALANCE,
1002 0, 1, 1, 1);
1003 ctrls->blue_balance = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_BLUE_BALANCE,
1004 0, 0xff, 1, 0x80);
1005 ctrls->red_balance = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_RED_BALANCE,
1006 0, 0xff, 1, 0x80);
1007 /* Auto/manual exposure */
1008 ctrls->auto_exp = v4l2_ctrl_new_std_menu(hdl, ops,
1009 V4L2_CID_EXPOSURE_AUTO,
1010 V4L2_EXPOSURE_MANUAL, 0, V4L2_EXPOSURE_AUTO);
1011 /* Exposure time, in 100 us units. min/max is updated dynamically. */
1012 ctrls->exposure = v4l2_ctrl_new_std(hdl, ops,
1013 V4L2_CID_EXPOSURE_ABSOLUTE,
1014 2, 1500, 1, 500);
1015 /* Auto/manual gain */
1016 ctrls->auto_gain = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_AUTOGAIN,
1017 0, 1, 1, 1);
1018 ctrls->gain = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_GAIN,
1019 16, 64 * (16 + 15), 1, 64 * 16);
1020
1021 ctrls->saturation = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_SATURATION,
1022 -2, 2, 1, 0);
1023 ctrls->brightness = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_BRIGHTNESS,
1024 -3, 3, 1, 0);
1025 ctrls->sharpness = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_SHARPNESS,
1026 0, 32, 1, 6);
1027
1028 ctrls->hflip = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_HFLIP, 0, 1, 1, 0);
1029 ctrls->vflip = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_VFLIP, 0, 1, 1, 0);
1030
1031 ctrls->light_freq = v4l2_ctrl_new_std_menu(hdl, ops,
1032 V4L2_CID_POWER_LINE_FREQUENCY,
1033 V4L2_CID_POWER_LINE_FREQUENCY_60HZ, ~0x7,
1034 V4L2_CID_POWER_LINE_FREQUENCY_50HZ);
1035
1036 v4l2_ctrl_new_std_menu_items(hdl, ops, V4L2_CID_TEST_PATTERN,
1037 ARRAY_SIZE(test_pattern_menu) - 1, 0, 0,
1038 test_pattern_menu);
1039 if (hdl->error) {
1040 ret = hdl->error;
1041 v4l2_ctrl_handler_free(hdl);
1042 return ret;
1043 }
1044
1045 ctrls->gain->flags |= V4L2_CTRL_FLAG_VOLATILE;
1046 ctrls->exposure->flags |= V4L2_CTRL_FLAG_VOLATILE;
1047
1048 v4l2_ctrl_auto_cluster(3, &ctrls->auto_wb, 0, false);
1049 v4l2_ctrl_auto_cluster(3, &ctrls->auto_gain, 0, true);
1050 v4l2_ctrl_auto_cluster(3, &ctrls->auto_exp, 1, true);
1051 v4l2_ctrl_cluster(2, &ctrls->hflip);
1052
1053 ov965x->sd.ctrl_handler = hdl;
1054 return 0;
1055}
1056
1057/*
1058 * V4L2 subdev video and pad level operations
1059 */
1060static void ov965x_get_default_format(struct v4l2_mbus_framefmt *mf)
1061{
1062 mf->width = ov965x_framesizes[0].width;
1063 mf->height = ov965x_framesizes[0].height;
1064 mf->colorspace = ov965x_formats[0].colorspace;
1065 mf->code = ov965x_formats[0].code;
1066 mf->field = V4L2_FIELD_NONE;
1067}
1068
1069static int ov965x_enum_mbus_code(struct v4l2_subdev *sd,
1070 struct v4l2_subdev_fh *fh,
1071 struct v4l2_subdev_mbus_code_enum *code)
1072{
1073 if (code->index >= ARRAY_SIZE(ov965x_formats))
1074 return -EINVAL;
1075
1076 code->code = ov965x_formats[code->index].code;
1077 return 0;
1078}
1079
1080static int ov965x_enum_frame_sizes(struct v4l2_subdev *sd,
1081 struct v4l2_subdev_fh *fh,
1082 struct v4l2_subdev_frame_size_enum *fse)
1083{
1084 int i = ARRAY_SIZE(ov965x_formats);
1085
1086 if (fse->index > ARRAY_SIZE(ov965x_framesizes))
1087 return -EINVAL;
1088
1089 while (--i)
1090 if (fse->code == ov965x_formats[i].code)
1091 break;
1092
1093 fse->code = ov965x_formats[i].code;
1094
1095 fse->min_width = ov965x_framesizes[fse->index].width;
1096 fse->max_width = fse->min_width;
1097 fse->max_height = ov965x_framesizes[fse->index].height;
1098 fse->min_height = fse->max_height;
1099
1100 return 0;
1101}
1102
1103static int ov965x_g_frame_interval(struct v4l2_subdev *sd,
1104 struct v4l2_subdev_frame_interval *fi)
1105{
1106 struct ov965x *ov965x = to_ov965x(sd);
1107
1108 mutex_lock(&ov965x->lock);
1109 fi->interval = ov965x->fiv->interval;
1110 mutex_unlock(&ov965x->lock);
1111
1112 return 0;
1113}
1114
1115static int __ov965x_set_frame_interval(struct ov965x *ov965x,
1116 struct v4l2_subdev_frame_interval *fi)
1117{
1118 struct v4l2_mbus_framefmt *mbus_fmt = &ov965x->format;
1119 const struct ov965x_interval *fiv = &ov965x_intervals[0];
1120 u64 req_int, err, min_err = ~0ULL;
1121 unsigned int i;
1122
1123
1124 if (fi->interval.denominator == 0)
1125 return -EINVAL;
1126
1127 req_int = (u64)(fi->interval.numerator * 10000) /
1128 fi->interval.denominator;
1129
1130 for (i = 0; i < ARRAY_SIZE(ov965x_intervals); i++) {
1131 const struct ov965x_interval *iv = &ov965x_intervals[i];
1132
1133 if (mbus_fmt->width != iv->size.width ||
1134 mbus_fmt->height != iv->size.height)
1135 continue;
1136 err = abs64((u64)(iv->interval.numerator * 10000) /
1137 iv->interval.denominator - req_int);
1138 if (err < min_err) {
1139 fiv = iv;
1140 min_err = err;
1141 }
1142 }
1143 ov965x->fiv = fiv;
1144
1145 v4l2_dbg(1, debug, &ov965x->sd, "Changed frame interval to %u us\n",
1146 fiv->interval.numerator * 1000000 / fiv->interval.denominator);
1147
1148 return 0;
1149}
1150
1151static int ov965x_s_frame_interval(struct v4l2_subdev *sd,
1152 struct v4l2_subdev_frame_interval *fi)
1153{
1154 struct ov965x *ov965x = to_ov965x(sd);
1155 int ret;
1156
1157 v4l2_dbg(1, debug, sd, "Setting %d/%d frame interval\n",
1158 fi->interval.numerator, fi->interval.denominator);
1159
1160 mutex_lock(&ov965x->lock);
1161 ret = __ov965x_set_frame_interval(ov965x, fi);
1162 ov965x->apply_frame_fmt = 1;
1163 mutex_unlock(&ov965x->lock);
1164 return ret;
1165}
1166
1167static int ov965x_get_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1168 struct v4l2_subdev_format *fmt)
1169{
1170 struct ov965x *ov965x = to_ov965x(sd);
1171 struct v4l2_mbus_framefmt *mf;
1172
1173 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
1174 mf = v4l2_subdev_get_try_format(fh, 0);
1175 fmt->format = *mf;
1176 return 0;
1177 }
1178
1179 mutex_lock(&ov965x->lock);
1180 fmt->format = ov965x->format;
1181 mutex_unlock(&ov965x->lock);
1182
1183 return 0;
1184}
1185
1186static void __ov965x_try_frame_size(struct v4l2_mbus_framefmt *mf,
1187 const struct ov965x_framesize **size)
1188{
1189 const struct ov965x_framesize *fsize = &ov965x_framesizes[0],
1190 *match = NULL;
1191 int i = ARRAY_SIZE(ov965x_framesizes);
1192 unsigned int min_err = UINT_MAX;
1193
1194 while (i--) {
1195 int err = abs(fsize->width - mf->width)
1196 + abs(fsize->height - mf->height);
1197 if (err < min_err) {
1198 min_err = err;
1199 match = fsize;
1200 }
1201 fsize++;
1202 }
1203 if (!match)
1204 match = &ov965x_framesizes[0];
1205 mf->width = match->width;
1206 mf->height = match->height;
1207 if (size)
1208 *size = match;
1209}
1210
1211static int ov965x_set_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1212 struct v4l2_subdev_format *fmt)
1213{
1214 unsigned int index = ARRAY_SIZE(ov965x_formats);
1215 struct v4l2_mbus_framefmt *mf = &fmt->format;
1216 struct ov965x *ov965x = to_ov965x(sd);
1217 const struct ov965x_framesize *size = NULL;
1218 int ret = 0;
1219
1220 __ov965x_try_frame_size(mf, &size);
1221
1222 while (--index)
1223 if (ov965x_formats[index].code == mf->code)
1224 break;
1225
1226 mf->colorspace = V4L2_COLORSPACE_JPEG;
1227 mf->code = ov965x_formats[index].code;
1228 mf->field = V4L2_FIELD_NONE;
1229
1230 mutex_lock(&ov965x->lock);
1231
1232 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
1233 if (fh != NULL) {
1234 mf = v4l2_subdev_get_try_format(fh, fmt->pad);
1235 *mf = fmt->format;
1236 }
1237 } else {
1238 if (ov965x->streaming) {
1239 ret = -EBUSY;
1240 } else {
1241 ov965x->frame_size = size;
1242 ov965x->format = fmt->format;
1243 ov965x->tslb_reg = ov965x_formats[index].tslb_reg;
1244 ov965x->apply_frame_fmt = 1;
1245 }
1246 }
1247
1248 if (!ret && fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
1249 struct v4l2_subdev_frame_interval fiv = {
1250 .interval = { 0, 1 }
1251 };
1252 /* Reset to minimum possible frame interval */
1253 __ov965x_set_frame_interval(ov965x, &fiv);
1254 }
1255 mutex_unlock(&ov965x->lock);
1256
1257 if (!ret)
1258 ov965x_update_exposure_ctrl(ov965x);
1259
1260 return ret;
1261}
1262
1263static int ov965x_set_frame_size(struct ov965x *ov965x)
1264{
1265 int i, ret = 0;
1266
1267 for (i = 0; ret == 0 && i < NUM_FMT_REGS; i++)
1268 ret = ov965x_write(ov965x->client, frame_size_reg_addr[i],
1269 ov965x->frame_size->regs[i]);
1270 return ret;
1271}
1272
1273static int __ov965x_set_params(struct ov965x *ov965x)
1274{
1275 struct i2c_client *client = ov965x->client;
1276 struct ov965x_ctrls *ctrls = &ov965x->ctrls;
1277 int ret = 0;
1278 u8 reg;
1279
1280 if (ov965x->apply_frame_fmt) {
1281 reg = DEF_CLKRC + ov965x->fiv->clkrc_div;
1282 ret = ov965x_write(client, REG_CLKRC, reg);
1283 if (ret < 0)
1284 return ret;
1285 ret = ov965x_set_frame_size(ov965x);
1286 if (ret < 0)
1287 return ret;
1288 ret = ov965x_read(client, REG_TSLB, &reg);
1289 if (ret < 0)
1290 return ret;
1291 reg &= ~TSLB_YUYV_MASK;
1292 reg |= ov965x->tslb_reg;
1293 ret = ov965x_write(client, REG_TSLB, reg);
1294 if (ret < 0)
1295 return ret;
1296 }
1297 ret = ov965x_set_default_gamma_curve(ov965x);
1298 if (ret < 0)
1299 return ret;
1300 ret = ov965x_set_color_matrix(ov965x);
1301 if (ret < 0)
1302 return ret;
1303 /*
1304 * Select manual banding filter, the filter will
1305 * be enabled further if required.
1306 */
1307 ret = ov965x_read(client, REG_COM11, &reg);
1308 if (!ret)
1309 reg |= COM11_BANDING;
1310 ret = ov965x_write(client, REG_COM11, reg);
1311 if (ret < 0)
1312 return ret;
1313 /*
1314 * Banding filter (REG_MBD value) needs to match selected
1315 * resolution and frame rate, so it's always updated here.
1316 */
1317 return ov965x_set_banding_filter(ov965x, ctrls->light_freq->val);
1318}
1319
1320static int ov965x_s_stream(struct v4l2_subdev *sd, int on)
1321{
1322 struct i2c_client *client = v4l2_get_subdevdata(sd);
1323 struct ov965x *ov965x = to_ov965x(sd);
1324 struct ov965x_ctrls *ctrls = &ov965x->ctrls;
1325 int ret = 0;
1326
1327 v4l2_dbg(1, debug, client, "%s: on: %d\n", __func__, on);
1328
1329 mutex_lock(&ov965x->lock);
1330 if (ov965x->streaming == !on) {
1331 if (on)
1332 ret = __ov965x_set_params(ov965x);
1333
1334 if (!ret && ctrls->update) {
1335 /*
1336 * ov965x_s_ctrl callback takes the mutex
1337 * so it needs to be released here.
1338 */
1339 mutex_unlock(&ov965x->lock);
1340 ret = v4l2_ctrl_handler_setup(&ctrls->handler);
1341
1342 mutex_lock(&ov965x->lock);
1343 if (!ret)
1344 ctrls->update = 0;
1345 }
1346 if (!ret)
1347 ret = ov965x_write(client, REG_COM2,
1348 on ? 0x01 : 0x11);
1349 }
1350 if (!ret)
1351 ov965x->streaming += on ? 1 : -1;
1352
1353 WARN_ON(ov965x->streaming < 0);
1354 mutex_unlock(&ov965x->lock);
1355
1356 return ret;
1357}
1358
1359/*
1360 * V4L2 subdev internal operations
1361 */
1362static int ov965x_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
1363{
1364 struct v4l2_mbus_framefmt *mf = v4l2_subdev_get_try_format(fh, 0);
1365
1366 ov965x_get_default_format(mf);
1367 return 0;
1368}
1369
1370static const struct v4l2_subdev_pad_ops ov965x_pad_ops = {
1371 .enum_mbus_code = ov965x_enum_mbus_code,
1372 .enum_frame_size = ov965x_enum_frame_sizes,
1373 .get_fmt = ov965x_get_fmt,
1374 .set_fmt = ov965x_set_fmt,
1375};
1376
1377static const struct v4l2_subdev_video_ops ov965x_video_ops = {
1378 .s_stream = ov965x_s_stream,
1379 .g_frame_interval = ov965x_g_frame_interval,
1380 .s_frame_interval = ov965x_s_frame_interval,
1381
1382};
1383
1384static const struct v4l2_subdev_internal_ops ov965x_sd_internal_ops = {
1385 .open = ov965x_open,
1386};
1387
1388static const struct v4l2_subdev_core_ops ov965x_core_ops = {
1389 .s_power = ov965x_s_power,
1390 .log_status = v4l2_ctrl_subdev_log_status,
1391 .subscribe_event = v4l2_ctrl_subdev_subscribe_event,
1392 .unsubscribe_event = v4l2_event_subdev_unsubscribe,
1393};
1394
1395static const struct v4l2_subdev_ops ov965x_subdev_ops = {
1396 .core = &ov965x_core_ops,
1397 .pad = &ov965x_pad_ops,
1398 .video = &ov965x_video_ops,
1399};
1400
1401/*
1402 * Reset and power down GPIOs configuration
1403 */
1404static int ov965x_configure_gpios(struct ov965x *ov965x,
1405 const struct ov9650_platform_data *pdata)
1406{
1407 int ret, i;
1408
1409 ov965x->gpios[GPIO_PWDN] = pdata->gpio_pwdn;
1410 ov965x->gpios[GPIO_RST] = pdata->gpio_reset;
1411
1412 for (i = 0; i < ARRAY_SIZE(ov965x->gpios); i++) {
1413 int gpio = ov965x->gpios[i];
1414
1415 if (!gpio_is_valid(gpio))
1416 continue;
1417 ret = devm_gpio_request_one(&ov965x->client->dev, gpio,
1418 GPIOF_OUT_INIT_HIGH, "OV965X");
1419 if (ret < 0)
1420 return ret;
1421 v4l2_dbg(1, debug, &ov965x->sd, "set gpio %d to 1\n", gpio);
1422
1423 gpio_set_value(gpio, 1);
1424 gpio_export(gpio, 0);
1425 ov965x->gpios[i] = gpio;
1426 }
1427
1428 return 0;
1429}
1430
1431static int ov965x_detect_sensor(struct v4l2_subdev *sd)
1432{
1433 struct i2c_client *client = v4l2_get_subdevdata(sd);
1434 struct ov965x *ov965x = to_ov965x(sd);
1435 u8 pid, ver;
1436 int ret;
1437
1438 mutex_lock(&ov965x->lock);
1439 __ov965x_set_power(ov965x, 1);
1440 usleep_range(25000, 26000);
1441
1442 /* Check sensor revision */
1443 ret = ov965x_read(client, REG_PID, &pid);
1444 if (!ret)
1445 ret = ov965x_read(client, REG_VER, &ver);
1446
1447 __ov965x_set_power(ov965x, 0);
1448
1449 if (!ret) {
1450 ov965x->id = OV965X_ID(pid, ver);
1451 if (ov965x->id == OV9650_ID || ov965x->id == OV9652_ID) {
1452 v4l2_info(sd, "Found OV%04X sensor\n", ov965x->id);
1453 } else {
1454 v4l2_err(sd, "Sensor detection failed (%04X, %d)\n",
1455 ov965x->id, ret);
1456 ret = -ENODEV;
1457 }
1458 }
1459 mutex_unlock(&ov965x->lock);
1460
1461 return ret;
1462}
1463
1464static int ov965x_probe(struct i2c_client *client,
1465 const struct i2c_device_id *id)
1466{
1467 const struct ov9650_platform_data *pdata = client->dev.platform_data;
1468 struct v4l2_subdev *sd;
1469 struct ov965x *ov965x;
1470 int ret;
1471
1472 if (pdata == NULL) {
1473 dev_err(&client->dev, "platform data not specified\n");
1474 return -EINVAL;
1475 }
1476
1477 if (pdata->mclk_frequency == 0) {
1478 dev_err(&client->dev, "MCLK frequency not specified\n");
1479 return -EINVAL;
1480 }
1481
1482 ov965x = devm_kzalloc(&client->dev, sizeof(*ov965x), GFP_KERNEL);
1483 if (!ov965x)
1484 return -ENOMEM;
1485
1486 mutex_init(&ov965x->lock);
1487 ov965x->client = client;
1488 ov965x->mclk_frequency = pdata->mclk_frequency;
1489
1490 sd = &ov965x->sd;
1491 v4l2_i2c_subdev_init(sd, client, &ov965x_subdev_ops);
1492 strlcpy(sd->name, DRIVER_NAME, sizeof(sd->name));
1493
1494 sd->internal_ops = &ov965x_sd_internal_ops;
1495 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE |
1496 V4L2_SUBDEV_FL_HAS_EVENTS;
1497
1498 ret = ov965x_configure_gpios(ov965x, pdata);
1499 if (ret < 0)
1500 return ret;
1501
1502 ov965x->pad.flags = MEDIA_PAD_FL_SOURCE;
1503 sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV_SENSOR;
1504 ret = media_entity_init(&sd->entity, 1, &ov965x->pad, 0);
1505 if (ret < 0)
1506 return ret;
1507
1508 ret = ov965x_initialize_controls(ov965x);
1509 if (ret < 0)
1510 goto err_me;
1511
1512 ov965x_get_default_format(&ov965x->format);
1513 ov965x->frame_size = &ov965x_framesizes[0];
1514 ov965x->fiv = &ov965x_intervals[0];
1515
1516 ret = ov965x_detect_sensor(sd);
1517 if (ret < 0)
1518 goto err_ctrls;
1519
1520 /* Update exposure time min/max to match frame format */
1521 ov965x_update_exposure_ctrl(ov965x);
1522
1523 return 0;
1524err_ctrls:
1525 v4l2_ctrl_handler_free(sd->ctrl_handler);
1526err_me:
1527 media_entity_cleanup(&sd->entity);
1528 return ret;
1529}
1530
1531static int ov965x_remove(struct i2c_client *client)
1532{
1533 struct v4l2_subdev *sd = i2c_get_clientdata(client);
1534
1535 v4l2_device_unregister_subdev(sd);
1536 v4l2_ctrl_handler_free(sd->ctrl_handler);
1537 media_entity_cleanup(&sd->entity);
1538
1539 return 0;
1540}
1541
1542static const struct i2c_device_id ov965x_id[] = {
1543 { "OV9650", 0 },
1544 { "OV9652", 0 },
1545 { /* sentinel */ }
1546};
1547MODULE_DEVICE_TABLE(i2c, ov965x_id);
1548
1549static struct i2c_driver ov965x_i2c_driver = {
1550 .driver = {
1551 .name = DRIVER_NAME,
1552 },
1553 .probe = ov965x_probe,
1554 .remove = ov965x_remove,
1555 .id_table = ov965x_id,
1556};
1557
1558module_i2c_driver(ov965x_i2c_driver);
1559
1560MODULE_AUTHOR("Sylwester Nawrocki <sylvester.nawrocki@gmail.com>");
1561MODULE_DESCRIPTION("OV9650/OV9652 CMOS Image Sensor driver");
1562MODULE_LICENSE("GPL");
diff --git a/drivers/media/i2c/s5c73m3/Makefile b/drivers/media/i2c/s5c73m3/Makefile
new file mode 100644
index 000000000000..fa4df342d1f1
--- /dev/null
+++ b/drivers/media/i2c/s5c73m3/Makefile
@@ -0,0 +1,2 @@
1s5c73m3-objs := s5c73m3-core.o s5c73m3-spi.o s5c73m3-ctrls.o
2obj-$(CONFIG_VIDEO_S5C73M3) += s5c73m3.o
diff --git a/drivers/media/i2c/s5c73m3/s5c73m3-core.c b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
new file mode 100644
index 000000000000..5dbb65e1f6b7
--- /dev/null
+++ b/drivers/media/i2c/s5c73m3/s5c73m3-core.c
@@ -0,0 +1,1704 @@
1/*
2 * Samsung LSI S5C73M3 8M pixel camera driver
3 *
4 * Copyright (C) 2012, Samsung Electronics, Co., Ltd.
5 * Sylwester Nawrocki <s.nawrocki@samsung.com>
6 * Andrzej Hajda <a.hajda@samsung.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17
18#include <linux/sizes.h>
19#include <linux/delay.h>
20#include <linux/firmware.h>
21#include <linux/gpio.h>
22#include <linux/i2c.h>
23#include <linux/init.h>
24#include <linux/media.h>
25#include <linux/module.h>
26#include <linux/regulator/consumer.h>
27#include <linux/slab.h>
28#include <linux/spi/spi.h>
29#include <linux/videodev2.h>
30#include <media/media-entity.h>
31#include <media/v4l2-ctrls.h>
32#include <media/v4l2-device.h>
33#include <media/v4l2-subdev.h>
34#include <media/v4l2-mediabus.h>
35#include <media/s5c73m3.h>
36
37#include "s5c73m3.h"
38
39int s5c73m3_dbg;
40module_param_named(debug, s5c73m3_dbg, int, 0644);
41
42static int boot_from_rom = 1;
43module_param(boot_from_rom, int, 0644);
44
45static int update_fw;
46module_param(update_fw, int, 0644);
47
48#define S5C73M3_EMBEDDED_DATA_MAXLEN SZ_4K
49
50static const char * const s5c73m3_supply_names[S5C73M3_MAX_SUPPLIES] = {
51 "vdd-int", /* Digital Core supply (1.2V), CAM_ISP_CORE_1.2V */
52 "vdda", /* Analog Core supply (1.2V), CAM_SENSOR_CORE_1.2V */
53 "vdd-reg", /* Regulator input supply (2.8V), CAM_SENSOR_A2.8V */
54 "vddio-host", /* Digital Host I/O power supply (1.8V...2.8V),
55 CAM_ISP_SENSOR_1.8V */
56 "vddio-cis", /* Digital CIS I/O power (1.2V...1.8V),
57 CAM_ISP_MIPI_1.2V */
58 "vdd-af", /* Lens, CAM_AF_2.8V */
59};
60
61static const struct s5c73m3_frame_size s5c73m3_isp_resolutions[] = {
62 { 320, 240, COMM_CHG_MODE_YUV_320_240 },
63 { 352, 288, COMM_CHG_MODE_YUV_352_288 },
64 { 640, 480, COMM_CHG_MODE_YUV_640_480 },
65 { 880, 720, COMM_CHG_MODE_YUV_880_720 },
66 { 960, 720, COMM_CHG_MODE_YUV_960_720 },
67 { 1008, 672, COMM_CHG_MODE_YUV_1008_672 },
68 { 1184, 666, COMM_CHG_MODE_YUV_1184_666 },
69 { 1280, 720, COMM_CHG_MODE_YUV_1280_720 },
70 { 1536, 864, COMM_CHG_MODE_YUV_1536_864 },
71 { 1600, 1200, COMM_CHG_MODE_YUV_1600_1200 },
72 { 1632, 1224, COMM_CHG_MODE_YUV_1632_1224 },
73 { 1920, 1080, COMM_CHG_MODE_YUV_1920_1080 },
74 { 1920, 1440, COMM_CHG_MODE_YUV_1920_1440 },
75 { 2304, 1296, COMM_CHG_MODE_YUV_2304_1296 },
76 { 3264, 2448, COMM_CHG_MODE_YUV_3264_2448 },
77};
78
79static const struct s5c73m3_frame_size s5c73m3_jpeg_resolutions[] = {
80 { 640, 480, COMM_CHG_MODE_JPEG_640_480 },
81 { 800, 450, COMM_CHG_MODE_JPEG_800_450 },
82 { 800, 600, COMM_CHG_MODE_JPEG_800_600 },
83 { 1024, 768, COMM_CHG_MODE_JPEG_1024_768 },
84 { 1280, 720, COMM_CHG_MODE_JPEG_1280_720 },
85 { 1280, 960, COMM_CHG_MODE_JPEG_1280_960 },
86 { 1600, 900, COMM_CHG_MODE_JPEG_1600_900 },
87 { 1600, 1200, COMM_CHG_MODE_JPEG_1600_1200 },
88 { 2048, 1152, COMM_CHG_MODE_JPEG_2048_1152 },
89 { 2048, 1536, COMM_CHG_MODE_JPEG_2048_1536 },
90 { 2560, 1440, COMM_CHG_MODE_JPEG_2560_1440 },
91 { 2560, 1920, COMM_CHG_MODE_JPEG_2560_1920 },
92 { 3264, 1836, COMM_CHG_MODE_JPEG_3264_1836 },
93 { 3264, 2176, COMM_CHG_MODE_JPEG_3264_2176 },
94 { 3264, 2448, COMM_CHG_MODE_JPEG_3264_2448 },
95};
96
97static const struct s5c73m3_frame_size * const s5c73m3_resolutions[] = {
98 [RES_ISP] = s5c73m3_isp_resolutions,
99 [RES_JPEG] = s5c73m3_jpeg_resolutions
100};
101
102static const int s5c73m3_resolutions_len[] = {
103 [RES_ISP] = ARRAY_SIZE(s5c73m3_isp_resolutions),
104 [RES_JPEG] = ARRAY_SIZE(s5c73m3_jpeg_resolutions)
105};
106
107static const struct s5c73m3_interval s5c73m3_intervals[] = {
108 { COMM_FRAME_RATE_FIXED_7FPS, {142857, 1000000}, {3264, 2448} },
109 { COMM_FRAME_RATE_FIXED_15FPS, {66667, 1000000}, {3264, 2448} },
110 { COMM_FRAME_RATE_FIXED_20FPS, {50000, 1000000}, {2304, 1296} },
111 { COMM_FRAME_RATE_FIXED_30FPS, {33333, 1000000}, {2304, 1296} },
112};
113
114#define S5C73M3_DEFAULT_FRAME_INTERVAL 3 /* 30 fps */
115
116static void s5c73m3_fill_mbus_fmt(struct v4l2_mbus_framefmt *mf,
117 const struct s5c73m3_frame_size *fs,
118 u32 code)
119{
120 mf->width = fs->width;
121 mf->height = fs->height;
122 mf->code = code;
123 mf->colorspace = V4L2_COLORSPACE_JPEG;
124 mf->field = V4L2_FIELD_NONE;
125}
126
127static int s5c73m3_i2c_write(struct i2c_client *client, u16 addr, u16 data)
128{
129 u8 buf[4] = { addr >> 8, addr & 0xff, data >> 8, data & 0xff };
130
131 int ret = i2c_master_send(client, buf, sizeof(buf));
132
133 v4l_dbg(4, s5c73m3_dbg, client, "%s: addr 0x%04x, data 0x%04x\n",
134 __func__, addr, data);
135
136 if (ret == 4)
137 return 0;
138
139 return ret < 0 ? ret : -EREMOTEIO;
140}
141
142static int s5c73m3_i2c_read(struct i2c_client *client, u16 addr, u16 *data)
143{
144 int ret;
145 u8 rbuf[2], wbuf[2] = { addr >> 8, addr & 0xff };
146 struct i2c_msg msg[2] = {
147 {
148 .addr = client->addr,
149 .flags = 0,
150 .len = sizeof(wbuf),
151 .buf = wbuf
152 }, {
153 .addr = client->addr,
154 .flags = I2C_M_RD,
155 .len = sizeof(rbuf),
156 .buf = rbuf
157 }
158 };
159 /*
160 * Issue repeated START after writing 2 address bytes and
161 * just one STOP only after reading the data bytes.
162 */
163 ret = i2c_transfer(client->adapter, msg, 2);
164 if (ret == 2) {
165 *data = be16_to_cpup((u16 *)rbuf);
166 v4l2_dbg(4, s5c73m3_dbg, client,
167 "%s: addr: 0x%04x, data: 0x%04x\n",
168 __func__, addr, *data);
169 return 0;
170 }
171
172 v4l2_err(client, "I2C read failed: addr: %04x, (%d)\n", addr, ret);
173
174 return ret >= 0 ? -EREMOTEIO : ret;
175}
176
177int s5c73m3_write(struct s5c73m3 *state, u32 addr, u16 data)
178{
179 struct i2c_client *client = state->i2c_client;
180 int ret;
181
182 if ((addr ^ state->i2c_write_address) & 0xffff0000) {
183 ret = s5c73m3_i2c_write(client, REG_CMDWR_ADDRH, addr >> 16);
184 if (ret < 0) {
185 state->i2c_write_address = 0;
186 return ret;
187 }
188 }
189
190 if ((addr ^ state->i2c_write_address) & 0xffff) {
191 ret = s5c73m3_i2c_write(client, REG_CMDWR_ADDRL, addr & 0xffff);
192 if (ret < 0) {
193 state->i2c_write_address = 0;
194 return ret;
195 }
196 }
197
198 state->i2c_write_address = addr;
199
200 ret = s5c73m3_i2c_write(client, REG_CMDBUF_ADDR, data);
201 if (ret < 0)
202 return ret;
203
204 state->i2c_write_address += 2;
205
206 return ret;
207}
208
209int s5c73m3_read(struct s5c73m3 *state, u32 addr, u16 *data)
210{
211 struct i2c_client *client = state->i2c_client;
212 int ret;
213
214 if ((addr ^ state->i2c_read_address) & 0xffff0000) {
215 ret = s5c73m3_i2c_write(client, REG_CMDRD_ADDRH, addr >> 16);
216 if (ret < 0) {
217 state->i2c_read_address = 0;
218 return ret;
219 }
220 }
221
222 if ((addr ^ state->i2c_read_address) & 0xffff) {
223 ret = s5c73m3_i2c_write(client, REG_CMDRD_ADDRL, addr & 0xffff);
224 if (ret < 0) {
225 state->i2c_read_address = 0;
226 return ret;
227 }
228 }
229
230 state->i2c_read_address = addr;
231
232 ret = s5c73m3_i2c_read(client, REG_CMDBUF_ADDR, data);
233 if (ret < 0)
234 return ret;
235
236 state->i2c_read_address += 2;
237
238 return ret;
239}
240
241static int s5c73m3_check_status(struct s5c73m3 *state, unsigned int value)
242{
243 unsigned long start = jiffies;
244 unsigned long end = start + msecs_to_jiffies(2000);
245 int ret = 0;
246 u16 status;
247 int count = 0;
248
249 while (time_is_after_jiffies(end)) {
250 ret = s5c73m3_read(state, REG_STATUS, &status);
251 if (ret < 0 || status == value)
252 break;
253 usleep_range(500, 1000);
254 ++count;
255 }
256
257 if (count > 0)
258 v4l2_dbg(1, s5c73m3_dbg, &state->sensor_sd,
259 "status check took %dms\n",
260 jiffies_to_msecs(jiffies - start));
261
262 if (ret == 0 && status != value) {
263 u16 i2c_status = 0;
264 u16 i2c_seq_status = 0;
265
266 s5c73m3_read(state, REG_I2C_STATUS, &i2c_status);
267 s5c73m3_read(state, REG_I2C_SEQ_STATUS, &i2c_seq_status);
268
269 v4l2_err(&state->sensor_sd,
270 "wrong status %#x, expected: %#x, i2c_status: %#x/%#x\n",
271 status, value, i2c_status, i2c_seq_status);
272
273 return -ETIMEDOUT;
274 }
275
276 return ret;
277}
278
279int s5c73m3_isp_command(struct s5c73m3 *state, u16 command, u16 data)
280{
281 int ret;
282
283 ret = s5c73m3_check_status(state, REG_STATUS_ISP_COMMAND_COMPLETED);
284 if (ret < 0)
285 return ret;
286
287 ret = s5c73m3_write(state, 0x00095000, command);
288 if (ret < 0)
289 return ret;
290
291 ret = s5c73m3_write(state, 0x00095002, data);
292 if (ret < 0)
293 return ret;
294
295 return s5c73m3_write(state, REG_STATUS, 0x0001);
296}
297
298static int s5c73m3_isp_comm_result(struct s5c73m3 *state, u16 command,
299 u16 *data)
300{
301 return s5c73m3_read(state, COMM_RESULT_OFFSET + command, data);
302}
303
304static int s5c73m3_set_af_softlanding(struct s5c73m3 *state)
305{
306 unsigned long start = jiffies;
307 u16 af_softlanding;
308 int count = 0;
309 int ret;
310 const char *msg;
311
312 ret = s5c73m3_isp_command(state, COMM_AF_SOFTLANDING,
313 COMM_AF_SOFTLANDING_ON);
314 if (ret < 0) {
315 v4l2_info(&state->sensor_sd, "AF soft-landing failed\n");
316 return ret;
317 }
318
319 for (;;) {
320 ret = s5c73m3_isp_comm_result(state, COMM_AF_SOFTLANDING,
321 &af_softlanding);
322 if (ret < 0) {
323 msg = "failed";
324 break;
325 }
326 if (af_softlanding == COMM_AF_SOFTLANDING_RES_COMPLETE) {
327 msg = "succeeded";
328 break;
329 }
330 if (++count > 100) {
331 ret = -ETIME;
332 msg = "timed out";
333 break;
334 }
335 msleep(25);
336 }
337
338 v4l2_info(&state->sensor_sd, "AF soft-landing %s after %dms\n",
339 msg, jiffies_to_msecs(jiffies - start));
340
341 return ret;
342}
343
344static int s5c73m3_load_fw(struct v4l2_subdev *sd)
345{
346 struct s5c73m3 *state = sensor_sd_to_s5c73m3(sd);
347 struct i2c_client *client = state->i2c_client;
348 const struct firmware *fw;
349 int ret;
350 char fw_name[20];
351
352 snprintf(fw_name, sizeof(fw_name), "SlimISP_%.2s.bin",
353 state->fw_file_version);
354 ret = request_firmware(&fw, fw_name, &client->dev);
355 if (ret < 0) {
356 v4l2_err(sd, "Firmware request failed (%s)\n", fw_name);
357 return -EINVAL;
358 }
359
360 v4l2_info(sd, "Loading firmware (%s, %d B)\n", fw_name, fw->size);
361
362 ret = s5c73m3_spi_write(state, fw->data, fw->size, 64);
363
364 if (ret >= 0)
365 state->isp_ready = 1;
366 else
367 v4l2_err(sd, "SPI write failed\n");
368
369 release_firmware(fw);
370
371 return ret;
372}
373
374static int s5c73m3_set_frame_size(struct s5c73m3 *state)
375{
376 const struct s5c73m3_frame_size *prev_size =
377 state->sensor_pix_size[RES_ISP];
378 const struct s5c73m3_frame_size *cap_size =
379 state->sensor_pix_size[RES_JPEG];
380 unsigned int chg_mode;
381
382 v4l2_dbg(1, s5c73m3_dbg, &state->sensor_sd,
383 "Preview size: %dx%d, reg_val: 0x%x\n",
384 prev_size->width, prev_size->height, prev_size->reg_val);
385
386 chg_mode = prev_size->reg_val | COMM_CHG_MODE_NEW;
387
388 if (state->mbus_code == S5C73M3_JPEG_FMT) {
389 v4l2_dbg(1, s5c73m3_dbg, &state->sensor_sd,
390 "Capture size: %dx%d, reg_val: 0x%x\n",
391 cap_size->width, cap_size->height, cap_size->reg_val);
392 chg_mode |= cap_size->reg_val;
393 }
394
395 return s5c73m3_isp_command(state, COMM_CHG_MODE, chg_mode);
396}
397
398static int s5c73m3_set_frame_rate(struct s5c73m3 *state)
399{
400 int ret;
401
402 if (state->ctrls.stabilization->val)
403 return 0;
404
405 if (WARN_ON(state->fiv == NULL))
406 return -EINVAL;
407
408 ret = s5c73m3_isp_command(state, COMM_FRAME_RATE, state->fiv->fps_reg);
409 if (!ret)
410 state->apply_fiv = 0;
411
412 return ret;
413}
414
415static int __s5c73m3_s_stream(struct s5c73m3 *state, struct v4l2_subdev *sd,
416 int on)
417{
418 u16 mode;
419 int ret;
420
421 if (on && state->apply_fmt) {
422 if (state->mbus_code == S5C73M3_JPEG_FMT)
423 mode = COMM_IMG_OUTPUT_INTERLEAVED;
424 else
425 mode = COMM_IMG_OUTPUT_YUV;
426
427 ret = s5c73m3_isp_command(state, COMM_IMG_OUTPUT, mode);
428 if (!ret)
429 ret = s5c73m3_set_frame_size(state);
430 if (ret)
431 return ret;
432 state->apply_fmt = 0;
433 }
434
435 ret = s5c73m3_isp_command(state, COMM_SENSOR_STREAMING, !!on);
436 if (ret)
437 return ret;
438
439 state->streaming = !!on;
440
441 if (!on)
442 return ret;
443
444 if (state->apply_fiv) {
445 ret = s5c73m3_set_frame_rate(state);
446 if (ret < 0)
447 v4l2_err(sd, "Error setting frame rate(%d)\n", ret);
448 }
449
450 return s5c73m3_check_status(state, REG_STATUS_ISP_COMMAND_COMPLETED);
451}
452
453static int s5c73m3_oif_s_stream(struct v4l2_subdev *sd, int on)
454{
455 struct s5c73m3 *state = oif_sd_to_s5c73m3(sd);
456 int ret;
457
458 mutex_lock(&state->lock);
459 ret = __s5c73m3_s_stream(state, sd, on);
460 mutex_unlock(&state->lock);
461
462 return ret;
463}
464
465static int s5c73m3_system_status_wait(struct s5c73m3 *state, u32 value,
466 unsigned int delay, unsigned int steps)
467{
468 u16 reg = 0;
469
470 while (steps-- > 0) {
471 int ret = s5c73m3_read(state, 0x30100010, &reg);
472 if (ret < 0)
473 return ret;
474 if (reg == value)
475 return 0;
476 usleep_range(delay, delay + 25);
477 }
478 return -ETIMEDOUT;
479}
480
481static int s5c73m3_read_fw_version(struct s5c73m3 *state)
482{
483 struct v4l2_subdev *sd = &state->sensor_sd;
484 int i, ret;
485 u16 data[2];
486 int offset;
487
488 offset = state->isp_ready ? 0x60 : 0;
489
490 for (i = 0; i < S5C73M3_SENSOR_FW_LEN / 2; i++) {
491 ret = s5c73m3_read(state, offset + i * 2, data);
492 if (ret < 0)
493 return ret;
494 state->sensor_fw[i * 2] = (char)(*data & 0xff);
495 state->sensor_fw[i * 2 + 1] = (char)(*data >> 8);
496 }
497 state->sensor_fw[S5C73M3_SENSOR_FW_LEN] = '\0';
498
499
500 for (i = 0; i < S5C73M3_SENSOR_TYPE_LEN / 2; i++) {
501 ret = s5c73m3_read(state, offset + 6 + i * 2, data);
502 if (ret < 0)
503 return ret;
504 state->sensor_type[i * 2] = (char)(*data & 0xff);
505 state->sensor_type[i * 2 + 1] = (char)(*data >> 8);
506 }
507 state->sensor_type[S5C73M3_SENSOR_TYPE_LEN] = '\0';
508
509 ret = s5c73m3_read(state, offset + 0x14, data);
510 if (ret >= 0) {
511 ret = s5c73m3_read(state, offset + 0x16, data + 1);
512 if (ret >= 0)
513 state->fw_size = data[0] + (data[1] << 16);
514 }
515
516 v4l2_info(sd, "Sensor type: %s, FW version: %s\n",
517 state->sensor_type, state->sensor_fw);
518 return ret;
519}
520
521static int s5c73m3_fw_update_from(struct s5c73m3 *state)
522{
523 struct v4l2_subdev *sd = &state->sensor_sd;
524 u16 status = COMM_FW_UPDATE_NOT_READY;
525 int ret;
526 int count = 0;
527
528 v4l2_warn(sd, "Updating F-ROM firmware.\n");
529 do {
530 if (status == COMM_FW_UPDATE_NOT_READY) {
531 ret = s5c73m3_isp_command(state, COMM_FW_UPDATE, 0);
532 if (ret < 0)
533 return ret;
534 }
535
536 ret = s5c73m3_read(state, 0x00095906, &status);
537 if (ret < 0)
538 return ret;
539 switch (status) {
540 case COMM_FW_UPDATE_FAIL:
541 v4l2_warn(sd, "Updating F-ROM firmware failed.\n");
542 return -EIO;
543 case COMM_FW_UPDATE_SUCCESS:
544 v4l2_warn(sd, "Updating F-ROM firmware finished.\n");
545 return 0;
546 }
547 ++count;
548 msleep(20);
549 } while (count < 500);
550
551 v4l2_warn(sd, "Updating F-ROM firmware timed-out.\n");
552 return -ETIMEDOUT;
553}
554
555static int s5c73m3_spi_boot(struct s5c73m3 *state, bool load_fw)
556{
557 struct v4l2_subdev *sd = &state->sensor_sd;
558 int ret;
559
560 /* Run ARM MCU */
561 ret = s5c73m3_write(state, 0x30000004, 0xffff);
562 if (ret < 0)
563 return ret;
564
565 usleep_range(400, 500);
566
567 /* Check booting status */
568 ret = s5c73m3_system_status_wait(state, 0x0c, 100, 3);
569 if (ret < 0) {
570 v4l2_err(sd, "booting failed: %d\n", ret);
571 return ret;
572 }
573
574 /* P,M,S and Boot Mode */
575 ret = s5c73m3_write(state, 0x30100014, 0x2146);
576 if (ret < 0)
577 return ret;
578
579 ret = s5c73m3_write(state, 0x30100010, 0x210c);
580 if (ret < 0)
581 return ret;
582
583 usleep_range(200, 250);
584
585 /* Check SPI status */
586 ret = s5c73m3_system_status_wait(state, 0x210d, 100, 300);
587 if (ret < 0)
588 v4l2_err(sd, "SPI not ready: %d\n", ret);
589
590 /* Firmware download over SPI */
591 if (load_fw)
592 s5c73m3_load_fw(sd);
593
594 /* MCU reset */
595 ret = s5c73m3_write(state, 0x30000004, 0xfffd);
596 if (ret < 0)
597 return ret;
598
599 /* Remap */
600 ret = s5c73m3_write(state, 0x301000a4, 0x0183);
601 if (ret < 0)
602 return ret;
603
604 /* MCU restart */
605 ret = s5c73m3_write(state, 0x30000004, 0xffff);
606 if (ret < 0 || !load_fw)
607 return ret;
608
609 ret = s5c73m3_read_fw_version(state);
610 if (ret < 0)
611 return ret;
612
613 if (load_fw && update_fw) {
614 ret = s5c73m3_fw_update_from(state);
615 update_fw = 0;
616 }
617
618 return ret;
619}
620
621static int s5c73m3_set_timing_register_for_vdd(struct s5c73m3 *state)
622{
623 static const u32 regs[][2] = {
624 { 0x30100018, 0x0618 },
625 { 0x3010001c, 0x10c1 },
626 { 0x30100020, 0x249e }
627 };
628 int ret;
629 int i;
630
631 for (i = 0; i < ARRAY_SIZE(regs); i++) {
632 ret = s5c73m3_write(state, regs[i][0], regs[i][1]);
633 if (ret < 0)
634 return ret;
635 }
636
637 return 0;
638}
639
640static void s5c73m3_set_fw_file_version(struct s5c73m3 *state)
641{
642 switch (state->sensor_fw[0]) {
643 case 'G':
644 case 'O':
645 state->fw_file_version[0] = 'G';
646 break;
647 case 'S':
648 case 'Z':
649 state->fw_file_version[0] = 'Z';
650 break;
651 }
652
653 switch (state->sensor_fw[1]) {
654 case 'C'...'F':
655 state->fw_file_version[1] = state->sensor_fw[1];
656 break;
657 }
658}
659
660static int s5c73m3_get_fw_version(struct s5c73m3 *state)
661{
662 struct v4l2_subdev *sd = &state->sensor_sd;
663 int ret;
664
665 /* Run ARM MCU */
666 ret = s5c73m3_write(state, 0x30000004, 0xffff);
667 if (ret < 0)
668 return ret;
669 usleep_range(400, 500);
670
671 /* Check booting status */
672 ret = s5c73m3_system_status_wait(state, 0x0c, 100, 3);
673 if (ret < 0) {
674
675 v4l2_err(sd, "%s: booting failed: %d\n", __func__, ret);
676 return ret;
677 }
678
679 /* Change I/O Driver Current in order to read from F-ROM */
680 ret = s5c73m3_write(state, 0x30100120, 0x0820);
681 ret = s5c73m3_write(state, 0x30100124, 0x0820);
682
683 /* Offset Setting */
684 ret = s5c73m3_write(state, 0x00010418, 0x0008);
685
686 /* P,M,S and Boot Mode */
687 ret = s5c73m3_write(state, 0x30100014, 0x2146);
688 if (ret < 0)
689 return ret;
690 ret = s5c73m3_write(state, 0x30100010, 0x230c);
691 if (ret < 0)
692 return ret;
693
694 usleep_range(200, 250);
695
696 /* Check SPI status */
697 ret = s5c73m3_system_status_wait(state, 0x230e, 100, 300);
698 if (ret < 0)
699 v4l2_err(sd, "SPI not ready: %d\n", ret);
700
701 /* ARM reset */
702 ret = s5c73m3_write(state, 0x30000004, 0xfffd);
703 if (ret < 0)
704 return ret;
705
706 /* Remap */
707 ret = s5c73m3_write(state, 0x301000a4, 0x0183);
708 if (ret < 0)
709 return ret;
710
711 s5c73m3_set_timing_register_for_vdd(state);
712
713 ret = s5c73m3_read_fw_version(state);
714
715 s5c73m3_set_fw_file_version(state);
716
717 return ret;
718}
719
720static int s5c73m3_rom_boot(struct s5c73m3 *state, bool load_fw)
721{
722 static const u32 boot_regs[][2] = {
723 { 0x3100010c, 0x0044 },
724 { 0x31000108, 0x000d },
725 { 0x31000304, 0x0001 },
726 { 0x00010000, 0x5800 },
727 { 0x00010002, 0x0002 },
728 { 0x31000000, 0x0001 },
729 { 0x30100014, 0x1b85 },
730 { 0x30100010, 0x230c }
731 };
732 struct v4l2_subdev *sd = &state->sensor_sd;
733 int i, ret;
734
735 /* Run ARM MCU */
736 ret = s5c73m3_write(state, 0x30000004, 0xffff);
737 if (ret < 0)
738 return ret;
739 usleep_range(400, 450);
740
741 /* Check booting status */
742 ret = s5c73m3_system_status_wait(state, 0x0c, 100, 4);
743 if (ret < 0) {
744 v4l2_err(sd, "Booting failed: %d\n", ret);
745 return ret;
746 }
747
748 for (i = 0; i < ARRAY_SIZE(boot_regs); i++) {
749 ret = s5c73m3_write(state, boot_regs[i][0], boot_regs[i][1]);
750 if (ret < 0)
751 return ret;
752 }
753 msleep(200);
754
755 /* Check the binary read status */
756 ret = s5c73m3_system_status_wait(state, 0x230e, 1000, 150);
757 if (ret < 0) {
758 v4l2_err(sd, "Binary read failed: %d\n", ret);
759 return ret;
760 }
761
762 /* ARM reset */
763 ret = s5c73m3_write(state, 0x30000004, 0xfffd);
764 if (ret < 0)
765 return ret;
766 /* Remap */
767 ret = s5c73m3_write(state, 0x301000a4, 0x0183);
768 if (ret < 0)
769 return ret;
770 /* MCU re-start */
771 ret = s5c73m3_write(state, 0x30000004, 0xffff);
772 if (ret < 0)
773 return ret;
774
775 state->isp_ready = 1;
776
777 return s5c73m3_read_fw_version(state);
778}
779
780static int s5c73m3_isp_init(struct s5c73m3 *state)
781{
782 int ret;
783
784 state->i2c_read_address = 0;
785 state->i2c_write_address = 0;
786
787 ret = s5c73m3_i2c_write(state->i2c_client, AHB_MSB_ADDR_PTR, 0x3310);
788 if (ret < 0)
789 return ret;
790
791 if (boot_from_rom)
792 return s5c73m3_rom_boot(state, true);
793 else
794 return s5c73m3_spi_boot(state, true);
795}
796
797static const struct s5c73m3_frame_size *s5c73m3_find_frame_size(
798 struct v4l2_mbus_framefmt *fmt,
799 enum s5c73m3_resolution_types idx)
800{
801 const struct s5c73m3_frame_size *fs;
802 const struct s5c73m3_frame_size *best_fs;
803 int best_dist = INT_MAX;
804 int i;
805
806 fs = s5c73m3_resolutions[idx];
807 best_fs = NULL;
808 for (i = 0; i < s5c73m3_resolutions_len[idx]; ++i) {
809 int dist = abs(fs->width - fmt->width) +
810 abs(fs->height - fmt->height);
811 if (dist < best_dist) {
812 best_dist = dist;
813 best_fs = fs;
814 }
815 ++fs;
816 }
817
818 return best_fs;
819}
820
821static void s5c73m3_oif_try_format(struct s5c73m3 *state,
822 struct v4l2_subdev_fh *fh,
823 struct v4l2_subdev_format *fmt,
824 const struct s5c73m3_frame_size **fs)
825{
826 u32 code;
827
828 switch (fmt->pad) {
829 case OIF_ISP_PAD:
830 *fs = s5c73m3_find_frame_size(&fmt->format, RES_ISP);
831 code = S5C73M3_ISP_FMT;
832 break;
833 case OIF_JPEG_PAD:
834 *fs = s5c73m3_find_frame_size(&fmt->format, RES_JPEG);
835 code = S5C73M3_JPEG_FMT;
836 break;
837 case OIF_SOURCE_PAD:
838 default:
839 if (fmt->format.code == S5C73M3_JPEG_FMT)
840 code = S5C73M3_JPEG_FMT;
841 else
842 code = S5C73M3_ISP_FMT;
843
844 if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE)
845 *fs = state->oif_pix_size[RES_ISP];
846 else
847 *fs = s5c73m3_find_frame_size(
848 v4l2_subdev_get_try_format(fh,
849 OIF_ISP_PAD),
850 RES_ISP);
851 break;
852 }
853
854 s5c73m3_fill_mbus_fmt(&fmt->format, *fs, code);
855}
856
857static void s5c73m3_try_format(struct s5c73m3 *state,
858 struct v4l2_subdev_fh *fh,
859 struct v4l2_subdev_format *fmt,
860 const struct s5c73m3_frame_size **fs)
861{
862 u32 code;
863
864 if (fmt->pad == S5C73M3_ISP_PAD) {
865 *fs = s5c73m3_find_frame_size(&fmt->format, RES_ISP);
866 code = S5C73M3_ISP_FMT;
867 } else {
868 *fs = s5c73m3_find_frame_size(&fmt->format, RES_JPEG);
869 code = S5C73M3_JPEG_FMT;
870 }
871
872 s5c73m3_fill_mbus_fmt(&fmt->format, *fs, code);
873}
874
875static int s5c73m3_oif_g_frame_interval(struct v4l2_subdev *sd,
876 struct v4l2_subdev_frame_interval *fi)
877{
878 struct s5c73m3 *state = oif_sd_to_s5c73m3(sd);
879
880 if (fi->pad != OIF_SOURCE_PAD)
881 return -EINVAL;
882
883 mutex_lock(&state->lock);
884 fi->interval = state->fiv->interval;
885 mutex_unlock(&state->lock);
886
887 return 0;
888}
889
890static int __s5c73m3_set_frame_interval(struct s5c73m3 *state,
891 struct v4l2_subdev_frame_interval *fi)
892{
893 const struct s5c73m3_frame_size *prev_size =
894 state->sensor_pix_size[RES_ISP];
895 const struct s5c73m3_interval *fiv = &s5c73m3_intervals[0];
896 unsigned int ret, min_err = UINT_MAX;
897 unsigned int i, fr_time;
898
899 if (fi->interval.denominator == 0)
900 return -EINVAL;
901
902 fr_time = fi->interval.numerator * 1000 / fi->interval.denominator;
903
904 for (i = 0; i < ARRAY_SIZE(s5c73m3_intervals); i++) {
905 const struct s5c73m3_interval *iv = &s5c73m3_intervals[i];
906
907 if (prev_size->width > iv->size.width ||
908 prev_size->height > iv->size.height)
909 continue;
910
911 ret = abs(iv->interval.numerator / 1000 - fr_time);
912 if (ret < min_err) {
913 fiv = iv;
914 min_err = ret;
915 }
916 }
917 state->fiv = fiv;
918
919 v4l2_dbg(1, s5c73m3_dbg, &state->sensor_sd,
920 "Changed frame interval to %u us\n", fiv->interval.numerator);
921 return 0;
922}
923
924static int s5c73m3_oif_s_frame_interval(struct v4l2_subdev *sd,
925 struct v4l2_subdev_frame_interval *fi)
926{
927 struct s5c73m3 *state = oif_sd_to_s5c73m3(sd);
928 int ret;
929
930 if (fi->pad != OIF_SOURCE_PAD)
931 return -EINVAL;
932
933 v4l2_dbg(1, s5c73m3_dbg, sd, "Setting %d/%d frame interval\n",
934 fi->interval.numerator, fi->interval.denominator);
935
936 mutex_lock(&state->lock);
937
938 ret = __s5c73m3_set_frame_interval(state, fi);
939 if (!ret) {
940 if (state->streaming)
941 ret = s5c73m3_set_frame_rate(state);
942 else
943 state->apply_fiv = 1;
944 }
945 mutex_unlock(&state->lock);
946 return ret;
947}
948
949static int s5c73m3_oif_enum_frame_interval(struct v4l2_subdev *sd,
950 struct v4l2_subdev_fh *fh,
951 struct v4l2_subdev_frame_interval_enum *fie)
952{
953 struct s5c73m3 *state = oif_sd_to_s5c73m3(sd);
954 const struct s5c73m3_interval *fi;
955 int ret = 0;
956
957 if (fie->pad != OIF_SOURCE_PAD)
958 return -EINVAL;
959 if (fie->index > ARRAY_SIZE(s5c73m3_intervals))
960 return -EINVAL;
961
962 mutex_lock(&state->lock);
963 fi = &s5c73m3_intervals[fie->index];
964 if (fie->width > fi->size.width || fie->height > fi->size.height)
965 ret = -EINVAL;
966 else
967 fie->interval = fi->interval;
968 mutex_unlock(&state->lock);
969
970 return ret;
971}
972
973static int s5c73m3_oif_get_pad_code(int pad, int index)
974{
975 if (pad == OIF_SOURCE_PAD) {
976 if (index > 1)
977 return -EINVAL;
978 return (index == 0) ? S5C73M3_ISP_FMT : S5C73M3_JPEG_FMT;
979 }
980
981 if (index > 0)
982 return -EINVAL;
983
984 return (pad == OIF_ISP_PAD) ? S5C73M3_ISP_FMT : S5C73M3_JPEG_FMT;
985}
986
987static int s5c73m3_get_fmt(struct v4l2_subdev *sd,
988 struct v4l2_subdev_fh *fh,
989 struct v4l2_subdev_format *fmt)
990{
991 struct s5c73m3 *state = sensor_sd_to_s5c73m3(sd);
992 const struct s5c73m3_frame_size *fs;
993 u32 code;
994
995 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
996 fmt->format = *v4l2_subdev_get_try_format(fh, fmt->pad);
997 return 0;
998 }
999
1000 mutex_lock(&state->lock);
1001
1002 switch (fmt->pad) {
1003 case S5C73M3_ISP_PAD:
1004 code = S5C73M3_ISP_FMT;
1005 fs = state->sensor_pix_size[RES_ISP];
1006 break;
1007 case S5C73M3_JPEG_PAD:
1008 code = S5C73M3_JPEG_FMT;
1009 fs = state->sensor_pix_size[RES_JPEG];
1010 break;
1011 default:
1012 mutex_unlock(&state->lock);
1013 return -EINVAL;
1014 }
1015 s5c73m3_fill_mbus_fmt(&fmt->format, fs, code);
1016
1017 mutex_unlock(&state->lock);
1018 return 0;
1019}
1020
1021static int s5c73m3_oif_get_fmt(struct v4l2_subdev *sd,
1022 struct v4l2_subdev_fh *fh,
1023 struct v4l2_subdev_format *fmt)
1024{
1025 struct s5c73m3 *state = oif_sd_to_s5c73m3(sd);
1026 const struct s5c73m3_frame_size *fs;
1027 u32 code;
1028
1029 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
1030 fmt->format = *v4l2_subdev_get_try_format(fh, fmt->pad);
1031 return 0;
1032 }
1033
1034 mutex_lock(&state->lock);
1035
1036 switch (fmt->pad) {
1037 case OIF_ISP_PAD:
1038 code = S5C73M3_ISP_FMT;
1039 fs = state->oif_pix_size[RES_ISP];
1040 break;
1041 case OIF_JPEG_PAD:
1042 code = S5C73M3_JPEG_FMT;
1043 fs = state->oif_pix_size[RES_JPEG];
1044 break;
1045 case OIF_SOURCE_PAD:
1046 code = state->mbus_code;
1047 fs = state->oif_pix_size[RES_ISP];
1048 break;
1049 default:
1050 mutex_unlock(&state->lock);
1051 return -EINVAL;
1052 }
1053 s5c73m3_fill_mbus_fmt(&fmt->format, fs, code);
1054
1055 mutex_unlock(&state->lock);
1056 return 0;
1057}
1058
1059static int s5c73m3_set_fmt(struct v4l2_subdev *sd,
1060 struct v4l2_subdev_fh *fh,
1061 struct v4l2_subdev_format *fmt)
1062{
1063 const struct s5c73m3_frame_size *frame_size = NULL;
1064 struct s5c73m3 *state = sensor_sd_to_s5c73m3(sd);
1065 struct v4l2_mbus_framefmt *mf;
1066 int ret = 0;
1067
1068 mutex_lock(&state->lock);
1069
1070 s5c73m3_try_format(state, fh, fmt, &frame_size);
1071
1072 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
1073 mf = v4l2_subdev_get_try_format(fh, fmt->pad);
1074 *mf = fmt->format;
1075 } else {
1076 switch (fmt->pad) {
1077 case S5C73M3_ISP_PAD:
1078 state->sensor_pix_size[RES_ISP] = frame_size;
1079 break;
1080 case S5C73M3_JPEG_PAD:
1081 state->sensor_pix_size[RES_JPEG] = frame_size;
1082 break;
1083 default:
1084 ret = -EBUSY;
1085 }
1086
1087 if (state->streaming)
1088 ret = -EBUSY;
1089 else
1090 state->apply_fmt = 1;
1091 }
1092
1093 mutex_unlock(&state->lock);
1094
1095 return ret;
1096}
1097
1098static int s5c73m3_oif_set_fmt(struct v4l2_subdev *sd,
1099 struct v4l2_subdev_fh *fh,
1100 struct v4l2_subdev_format *fmt)
1101{
1102 const struct s5c73m3_frame_size *frame_size = NULL;
1103 struct s5c73m3 *state = oif_sd_to_s5c73m3(sd);
1104 struct v4l2_mbus_framefmt *mf;
1105 int ret = 0;
1106
1107 mutex_lock(&state->lock);
1108
1109 s5c73m3_oif_try_format(state, fh, fmt, &frame_size);
1110
1111 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
1112 mf = v4l2_subdev_get_try_format(fh, fmt->pad);
1113 *mf = fmt->format;
1114 } else {
1115 switch (fmt->pad) {
1116 case OIF_ISP_PAD:
1117 state->oif_pix_size[RES_ISP] = frame_size;
1118 break;
1119 case OIF_JPEG_PAD:
1120 state->oif_pix_size[RES_JPEG] = frame_size;
1121 break;
1122 case OIF_SOURCE_PAD:
1123 state->mbus_code = fmt->format.code;
1124 break;
1125 default:
1126 ret = -EBUSY;
1127 }
1128
1129 if (state->streaming)
1130 ret = -EBUSY;
1131 else
1132 state->apply_fmt = 1;
1133 }
1134
1135 mutex_unlock(&state->lock);
1136
1137 return ret;
1138}
1139
1140static int s5c73m3_oif_get_frame_desc(struct v4l2_subdev *sd, unsigned int pad,
1141 struct v4l2_mbus_frame_desc *fd)
1142{
1143 struct s5c73m3 *state = oif_sd_to_s5c73m3(sd);
1144 int i;
1145
1146 if (pad != OIF_SOURCE_PAD || fd == NULL)
1147 return -EINVAL;
1148
1149 mutex_lock(&state->lock);
1150 fd->num_entries = 2;
1151 for (i = 0; i < fd->num_entries; i++)
1152 fd->entry[i] = state->frame_desc.entry[i];
1153 mutex_unlock(&state->lock);
1154
1155 return 0;
1156}
1157
1158static int s5c73m3_oif_set_frame_desc(struct v4l2_subdev *sd, unsigned int pad,
1159 struct v4l2_mbus_frame_desc *fd)
1160{
1161 struct s5c73m3 *state = oif_sd_to_s5c73m3(sd);
1162 struct v4l2_mbus_frame_desc *frame_desc = &state->frame_desc;
1163 int i;
1164
1165 if (pad != OIF_SOURCE_PAD || fd == NULL)
1166 return -EINVAL;
1167
1168 fd->entry[0].length = 10 * SZ_1M;
1169 fd->entry[1].length = max_t(u32, fd->entry[1].length,
1170 S5C73M3_EMBEDDED_DATA_MAXLEN);
1171 fd->num_entries = 2;
1172
1173 mutex_lock(&state->lock);
1174 for (i = 0; i < fd->num_entries; i++)
1175 frame_desc->entry[i] = fd->entry[i];
1176 mutex_unlock(&state->lock);
1177
1178 return 0;
1179}
1180
1181static int s5c73m3_enum_mbus_code(struct v4l2_subdev *sd,
1182 struct v4l2_subdev_fh *fh,
1183 struct v4l2_subdev_mbus_code_enum *code)
1184{
1185 static const int codes[] = {
1186 [S5C73M3_ISP_PAD] = S5C73M3_ISP_FMT,
1187 [S5C73M3_JPEG_PAD] = S5C73M3_JPEG_FMT};
1188
1189 if (code->index > 0 || code->pad >= S5C73M3_NUM_PADS)
1190 return -EINVAL;
1191
1192 code->code = codes[code->pad];
1193
1194 return 0;
1195}
1196
1197static int s5c73m3_oif_enum_mbus_code(struct v4l2_subdev *sd,
1198 struct v4l2_subdev_fh *fh,
1199 struct v4l2_subdev_mbus_code_enum *code)
1200{
1201 int ret;
1202
1203 ret = s5c73m3_oif_get_pad_code(code->pad, code->index);
1204 if (ret < 0)
1205 return ret;
1206
1207 code->code = ret;
1208
1209 return 0;
1210}
1211
1212static int s5c73m3_enum_frame_size(struct v4l2_subdev *sd,
1213 struct v4l2_subdev_fh *fh,
1214 struct v4l2_subdev_frame_size_enum *fse)
1215{
1216 int idx;
1217
1218 if (fse->pad == S5C73M3_ISP_PAD) {
1219 if (fse->code != S5C73M3_ISP_FMT)
1220 return -EINVAL;
1221 idx = RES_ISP;
1222 } else{
1223 if (fse->code != S5C73M3_JPEG_FMT)
1224 return -EINVAL;
1225 idx = RES_JPEG;
1226 }
1227
1228 if (fse->index >= s5c73m3_resolutions_len[idx])
1229 return -EINVAL;
1230
1231 fse->min_width = s5c73m3_resolutions[idx][fse->index].width;
1232 fse->max_width = fse->min_width;
1233 fse->max_height = s5c73m3_resolutions[idx][fse->index].height;
1234 fse->min_height = fse->max_height;
1235
1236 return 0;
1237}
1238
1239static int s5c73m3_oif_enum_frame_size(struct v4l2_subdev *sd,
1240 struct v4l2_subdev_fh *fh,
1241 struct v4l2_subdev_frame_size_enum *fse)
1242{
1243 int idx;
1244
1245 if (fse->pad == OIF_SOURCE_PAD) {
1246 if (fse->index > 0)
1247 return -EINVAL;
1248
1249 switch (fse->code) {
1250 case S5C73M3_JPEG_FMT:
1251 case S5C73M3_ISP_FMT: {
1252 struct v4l2_mbus_framefmt *mf =
1253 v4l2_subdev_get_try_format(fh, OIF_ISP_PAD);
1254
1255 fse->max_width = fse->min_width = mf->width;
1256 fse->max_height = fse->min_height = mf->height;
1257 return 0;
1258 }
1259 default:
1260 return -EINVAL;
1261 }
1262 }
1263
1264 if (fse->code != s5c73m3_oif_get_pad_code(fse->pad, 0))
1265 return -EINVAL;
1266
1267 if (fse->pad == OIF_JPEG_PAD)
1268 idx = RES_JPEG;
1269 else
1270 idx = RES_ISP;
1271
1272 if (fse->index >= s5c73m3_resolutions_len[idx])
1273 return -EINVAL;
1274
1275 fse->min_width = s5c73m3_resolutions[idx][fse->index].width;
1276 fse->max_width = fse->min_width;
1277 fse->max_height = s5c73m3_resolutions[idx][fse->index].height;
1278 fse->min_height = fse->max_height;
1279
1280 return 0;
1281}
1282
1283static int s5c73m3_oif_log_status(struct v4l2_subdev *sd)
1284{
1285 struct s5c73m3 *state = oif_sd_to_s5c73m3(sd);
1286
1287 v4l2_ctrl_handler_log_status(sd->ctrl_handler, sd->name);
1288
1289 v4l2_info(sd, "power: %d, apply_fmt: %d\n", state->power,
1290 state->apply_fmt);
1291
1292 return 0;
1293}
1294
1295static int s5c73m3_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
1296{
1297 struct v4l2_mbus_framefmt *mf;
1298
1299 mf = v4l2_subdev_get_try_format(fh, S5C73M3_ISP_PAD);
1300 s5c73m3_fill_mbus_fmt(mf, &s5c73m3_isp_resolutions[1],
1301 S5C73M3_ISP_FMT);
1302
1303 mf = v4l2_subdev_get_try_format(fh, S5C73M3_JPEG_PAD);
1304 s5c73m3_fill_mbus_fmt(mf, &s5c73m3_jpeg_resolutions[1],
1305 S5C73M3_JPEG_FMT);
1306
1307 return 0;
1308}
1309
1310static int s5c73m3_oif_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
1311{
1312 struct v4l2_mbus_framefmt *mf;
1313
1314 mf = v4l2_subdev_get_try_format(fh, OIF_ISP_PAD);
1315 s5c73m3_fill_mbus_fmt(mf, &s5c73m3_isp_resolutions[1],
1316 S5C73M3_ISP_FMT);
1317
1318 mf = v4l2_subdev_get_try_format(fh, OIF_JPEG_PAD);
1319 s5c73m3_fill_mbus_fmt(mf, &s5c73m3_jpeg_resolutions[1],
1320 S5C73M3_JPEG_FMT);
1321
1322 mf = v4l2_subdev_get_try_format(fh, OIF_SOURCE_PAD);
1323 s5c73m3_fill_mbus_fmt(mf, &s5c73m3_isp_resolutions[1],
1324 S5C73M3_ISP_FMT);
1325 return 0;
1326}
1327
1328static int s5c73m3_gpio_set_value(struct s5c73m3 *priv, int id, u32 val)
1329{
1330 if (!gpio_is_valid(priv->gpio[id].gpio))
1331 return 0;
1332 gpio_set_value(priv->gpio[id].gpio, !!val);
1333 return 1;
1334}
1335
1336static int s5c73m3_gpio_assert(struct s5c73m3 *priv, int id)
1337{
1338 return s5c73m3_gpio_set_value(priv, id, priv->gpio[id].level);
1339}
1340
1341static int s5c73m3_gpio_deassert(struct s5c73m3 *priv, int id)
1342{
1343 return s5c73m3_gpio_set_value(priv, id, !priv->gpio[id].level);
1344}
1345
1346static int __s5c73m3_power_on(struct s5c73m3 *state)
1347{
1348 int i, ret;
1349
1350 for (i = 0; i < S5C73M3_MAX_SUPPLIES; i++) {
1351 ret = regulator_enable(state->supplies[i].consumer);
1352 if (ret)
1353 goto err;
1354 }
1355
1356 s5c73m3_gpio_deassert(state, STBY);
1357 usleep_range(100, 200);
1358
1359 s5c73m3_gpio_deassert(state, RST);
1360 usleep_range(50, 100);
1361
1362 return 0;
1363err:
1364 for (--i; i >= 0; i--)
1365 regulator_disable(state->supplies[i].consumer);
1366 return ret;
1367}
1368
1369static int __s5c73m3_power_off(struct s5c73m3 *state)
1370{
1371 int i, ret;
1372
1373 if (s5c73m3_gpio_assert(state, RST))
1374 usleep_range(10, 50);
1375
1376 if (s5c73m3_gpio_assert(state, STBY))
1377 usleep_range(100, 200);
1378 state->streaming = 0;
1379 state->isp_ready = 0;
1380
1381 for (i = S5C73M3_MAX_SUPPLIES - 1; i >= 0; i--) {
1382 ret = regulator_disable(state->supplies[i].consumer);
1383 if (ret)
1384 goto err;
1385 }
1386 return 0;
1387err:
1388 for (++i; i < S5C73M3_MAX_SUPPLIES; i++)
1389 regulator_enable(state->supplies[i].consumer);
1390
1391 return ret;
1392}
1393
1394static int s5c73m3_oif_set_power(struct v4l2_subdev *sd, int on)
1395{
1396 struct s5c73m3 *state = oif_sd_to_s5c73m3(sd);
1397 int ret = 0;
1398
1399 mutex_lock(&state->lock);
1400
1401 if (on && !state->power) {
1402 ret = __s5c73m3_power_on(state);
1403 if (!ret)
1404 ret = s5c73m3_isp_init(state);
1405 if (!ret) {
1406 state->apply_fiv = 1;
1407 state->apply_fmt = 1;
1408 }
1409 } else if (!on == state->power) {
1410 ret = s5c73m3_set_af_softlanding(state);
1411 if (!ret)
1412 ret = __s5c73m3_power_off(state);
1413 else
1414 v4l2_err(sd, "Soft landing lens failed\n");
1415 }
1416 if (!ret)
1417 state->power += on ? 1 : -1;
1418
1419 v4l2_dbg(1, s5c73m3_dbg, sd, "%s: power: %d\n",
1420 __func__, state->power);
1421
1422 mutex_unlock(&state->lock);
1423 return ret;
1424}
1425
1426static int s5c73m3_oif_registered(struct v4l2_subdev *sd)
1427{
1428 struct s5c73m3 *state = oif_sd_to_s5c73m3(sd);
1429 int ret;
1430
1431 ret = v4l2_device_register_subdev(sd->v4l2_dev, &state->sensor_sd);
1432 if (ret) {
1433 v4l2_err(sd->v4l2_dev, "Failed to register %s\n",
1434 state->oif_sd.name);
1435 return ret;
1436 }
1437
1438 ret = media_entity_create_link(&state->sensor_sd.entity,
1439 S5C73M3_ISP_PAD, &state->oif_sd.entity, OIF_ISP_PAD,
1440 MEDIA_LNK_FL_IMMUTABLE | MEDIA_LNK_FL_ENABLED);
1441
1442 ret = media_entity_create_link(&state->sensor_sd.entity,
1443 S5C73M3_JPEG_PAD, &state->oif_sd.entity, OIF_JPEG_PAD,
1444 MEDIA_LNK_FL_IMMUTABLE | MEDIA_LNK_FL_ENABLED);
1445
1446 mutex_lock(&state->lock);
1447 ret = __s5c73m3_power_on(state);
1448 if (ret == 0)
1449 s5c73m3_get_fw_version(state);
1450
1451 __s5c73m3_power_off(state);
1452 mutex_unlock(&state->lock);
1453
1454 v4l2_dbg(1, s5c73m3_dbg, sd, "%s: Booting %s (%d)\n",
1455 __func__, ret ? "failed" : "succeded", ret);
1456
1457 return ret;
1458}
1459
1460static const struct v4l2_subdev_internal_ops s5c73m3_internal_ops = {
1461 .open = s5c73m3_open,
1462};
1463
1464static const struct v4l2_subdev_pad_ops s5c73m3_pad_ops = {
1465 .enum_mbus_code = s5c73m3_enum_mbus_code,
1466 .enum_frame_size = s5c73m3_enum_frame_size,
1467 .get_fmt = s5c73m3_get_fmt,
1468 .set_fmt = s5c73m3_set_fmt,
1469};
1470
1471static const struct v4l2_subdev_ops s5c73m3_subdev_ops = {
1472 .pad = &s5c73m3_pad_ops,
1473};
1474
1475static const struct v4l2_subdev_internal_ops oif_internal_ops = {
1476 .registered = s5c73m3_oif_registered,
1477 .open = s5c73m3_oif_open,
1478};
1479
1480static const struct v4l2_subdev_pad_ops s5c73m3_oif_pad_ops = {
1481 .enum_mbus_code = s5c73m3_oif_enum_mbus_code,
1482 .enum_frame_size = s5c73m3_oif_enum_frame_size,
1483 .enum_frame_interval = s5c73m3_oif_enum_frame_interval,
1484 .get_fmt = s5c73m3_oif_get_fmt,
1485 .set_fmt = s5c73m3_oif_set_fmt,
1486 .get_frame_desc = s5c73m3_oif_get_frame_desc,
1487 .set_frame_desc = s5c73m3_oif_set_frame_desc,
1488};
1489
1490static const struct v4l2_subdev_core_ops s5c73m3_oif_core_ops = {
1491 .s_power = s5c73m3_oif_set_power,
1492 .log_status = s5c73m3_oif_log_status,
1493};
1494
1495static const struct v4l2_subdev_video_ops s5c73m3_oif_video_ops = {
1496 .s_stream = s5c73m3_oif_s_stream,
1497 .g_frame_interval = s5c73m3_oif_g_frame_interval,
1498 .s_frame_interval = s5c73m3_oif_s_frame_interval,
1499};
1500
1501static const struct v4l2_subdev_ops oif_subdev_ops = {
1502 .core = &s5c73m3_oif_core_ops,
1503 .pad = &s5c73m3_oif_pad_ops,
1504 .video = &s5c73m3_oif_video_ops,
1505};
1506
1507static int s5c73m3_configure_gpio(int nr, int val, const char *name)
1508{
1509 unsigned long flags = val ? GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW;
1510 int ret;
1511
1512 if (!gpio_is_valid(nr))
1513 return 0;
1514 ret = gpio_request_one(nr, flags, name);
1515 if (!ret)
1516 gpio_export(nr, 0);
1517 return ret;
1518}
1519
1520static int s5c73m3_free_gpios(struct s5c73m3 *state)
1521{
1522 int i;
1523
1524 for (i = 0; i < ARRAY_SIZE(state->gpio); i++) {
1525 if (!gpio_is_valid(state->gpio[i].gpio))
1526 continue;
1527 gpio_free(state->gpio[i].gpio);
1528 state->gpio[i].gpio = -EINVAL;
1529 }
1530 return 0;
1531}
1532
1533static int s5c73m3_configure_gpios(struct s5c73m3 *state,
1534 const struct s5c73m3_platform_data *pdata)
1535{
1536 const struct s5c73m3_gpio *gpio = &pdata->gpio_stby;
1537 int ret;
1538
1539 state->gpio[STBY].gpio = -EINVAL;
1540 state->gpio[RST].gpio = -EINVAL;
1541
1542 ret = s5c73m3_configure_gpio(gpio->gpio, gpio->level, "S5C73M3_STBY");
1543 if (ret) {
1544 s5c73m3_free_gpios(state);
1545 return ret;
1546 }
1547 state->gpio[STBY] = *gpio;
1548 if (gpio_is_valid(gpio->gpio))
1549 gpio_set_value(gpio->gpio, 0);
1550
1551 gpio = &pdata->gpio_reset;
1552 ret = s5c73m3_configure_gpio(gpio->gpio, gpio->level, "S5C73M3_RST");
1553 if (ret) {
1554 s5c73m3_free_gpios(state);
1555 return ret;
1556 }
1557 state->gpio[RST] = *gpio;
1558 if (gpio_is_valid(gpio->gpio))
1559 gpio_set_value(gpio->gpio, 0);
1560
1561 return 0;
1562}
1563
1564static int s5c73m3_probe(struct i2c_client *client,
1565 const struct i2c_device_id *id)
1566{
1567 struct device *dev = &client->dev;
1568 const struct s5c73m3_platform_data *pdata = client->dev.platform_data;
1569 struct v4l2_subdev *sd;
1570 struct v4l2_subdev *oif_sd;
1571 struct s5c73m3 *state;
1572 int ret, i;
1573
1574 if (pdata == NULL) {
1575 dev_err(&client->dev, "Platform data not specified\n");
1576 return -EINVAL;
1577 }
1578
1579 state = devm_kzalloc(dev, sizeof(*state), GFP_KERNEL);
1580 if (!state)
1581 return -ENOMEM;
1582
1583 mutex_init(&state->lock);
1584 sd = &state->sensor_sd;
1585 oif_sd = &state->oif_sd;
1586
1587 v4l2_subdev_init(sd, &s5c73m3_subdev_ops);
1588 sd->owner = client->driver->driver.owner;
1589 v4l2_set_subdevdata(sd, state);
1590 strlcpy(sd->name, "S5C73M3", sizeof(sd->name));
1591
1592 sd->internal_ops = &s5c73m3_internal_ops;
1593 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
1594
1595 state->sensor_pads[S5C73M3_JPEG_PAD].flags = MEDIA_PAD_FL_SOURCE;
1596 state->sensor_pads[S5C73M3_ISP_PAD].flags = MEDIA_PAD_FL_SOURCE;
1597 sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV;
1598
1599 ret = media_entity_init(&sd->entity, S5C73M3_NUM_PADS,
1600 state->sensor_pads, 0);
1601 if (ret < 0)
1602 return ret;
1603
1604 v4l2_i2c_subdev_init(oif_sd, client, &oif_subdev_ops);
1605 strcpy(oif_sd->name, "S5C73M3-OIF");
1606
1607 oif_sd->internal_ops = &oif_internal_ops;
1608 oif_sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
1609
1610 state->oif_pads[OIF_ISP_PAD].flags = MEDIA_PAD_FL_SINK;
1611 state->oif_pads[OIF_JPEG_PAD].flags = MEDIA_PAD_FL_SINK;
1612 state->oif_pads[OIF_SOURCE_PAD].flags = MEDIA_PAD_FL_SOURCE;
1613 oif_sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV;
1614
1615 ret = media_entity_init(&oif_sd->entity, OIF_NUM_PADS,
1616 state->oif_pads, 0);
1617 if (ret < 0)
1618 return ret;
1619
1620 state->mclk_frequency = pdata->mclk_frequency;
1621 state->bus_type = pdata->bus_type;
1622
1623 ret = s5c73m3_configure_gpios(state, pdata);
1624 if (ret)
1625 goto out_err1;
1626
1627 for (i = 0; i < S5C73M3_MAX_SUPPLIES; i++)
1628 state->supplies[i].supply = s5c73m3_supply_names[i];
1629
1630 ret = devm_regulator_bulk_get(dev, S5C73M3_MAX_SUPPLIES,
1631 state->supplies);
1632 if (ret) {
1633 dev_err(dev, "failed to get regulators\n");
1634 goto out_err2;
1635 }
1636
1637 ret = s5c73m3_init_controls(state);
1638 if (ret)
1639 goto out_err2;
1640
1641 state->sensor_pix_size[RES_ISP] = &s5c73m3_isp_resolutions[1];
1642 state->sensor_pix_size[RES_JPEG] = &s5c73m3_jpeg_resolutions[1];
1643 state->oif_pix_size[RES_ISP] = state->sensor_pix_size[RES_ISP];
1644 state->oif_pix_size[RES_JPEG] = state->sensor_pix_size[RES_JPEG];
1645
1646 state->mbus_code = S5C73M3_ISP_FMT;
1647
1648 state->fiv = &s5c73m3_intervals[S5C73M3_DEFAULT_FRAME_INTERVAL];
1649
1650 state->fw_file_version[0] = 'G';
1651 state->fw_file_version[1] = 'C';
1652
1653 ret = s5c73m3_register_spi_driver(state);
1654 if (ret < 0)
1655 goto out_err2;
1656
1657 state->i2c_client = client;
1658
1659 v4l2_info(sd, "%s: completed succesfully\n", __func__);
1660 return 0;
1661
1662out_err2:
1663 s5c73m3_free_gpios(state);
1664out_err1:
1665 media_entity_cleanup(&sd->entity);
1666 return ret;
1667}
1668
1669static int s5c73m3_remove(struct i2c_client *client)
1670{
1671 struct v4l2_subdev *sd = i2c_get_clientdata(client);
1672 struct s5c73m3 *state = sensor_sd_to_s5c73m3(sd);
1673
1674 v4l2_device_unregister_subdev(sd);
1675
1676 v4l2_ctrl_handler_free(sd->ctrl_handler);
1677 media_entity_cleanup(&sd->entity);
1678
1679 s5c73m3_unregister_spi_driver(state);
1680 s5c73m3_free_gpios(state);
1681
1682 return 0;
1683}
1684
1685static const struct i2c_device_id s5c73m3_id[] = {
1686 { DRIVER_NAME, 0 },
1687 { }
1688};
1689MODULE_DEVICE_TABLE(i2c, s5c73m3_id);
1690
1691static struct i2c_driver s5c73m3_i2c_driver = {
1692 .driver = {
1693 .name = DRIVER_NAME,
1694 },
1695 .probe = s5c73m3_probe,
1696 .remove = s5c73m3_remove,
1697 .id_table = s5c73m3_id,
1698};
1699
1700module_i2c_driver(s5c73m3_i2c_driver);
1701
1702MODULE_DESCRIPTION("Samsung S5C73M3 camera driver");
1703MODULE_AUTHOR("Sylwester Nawrocki <s.nawrocki@samsung.com>");
1704MODULE_LICENSE("GPL");
diff --git a/drivers/media/i2c/s5c73m3/s5c73m3-ctrls.c b/drivers/media/i2c/s5c73m3/s5c73m3-ctrls.c
new file mode 100644
index 000000000000..8001cde1db1e
--- /dev/null
+++ b/drivers/media/i2c/s5c73m3/s5c73m3-ctrls.c
@@ -0,0 +1,563 @@
1/*
2 * Samsung LSI S5C73M3 8M pixel camera driver
3 *
4 * Copyright (C) 2012, Samsung Electronics, Co., Ltd.
5 * Sylwester Nawrocki <s.nawrocki@samsung.com>
6 * Andrzej Hajda <a.hajda@samsung.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17
18#include <linux/sizes.h>
19#include <linux/delay.h>
20#include <linux/firmware.h>
21#include <linux/gpio.h>
22#include <linux/i2c.h>
23#include <linux/init.h>
24#include <linux/media.h>
25#include <linux/module.h>
26#include <linux/regulator/consumer.h>
27#include <linux/slab.h>
28#include <linux/spi/spi.h>
29#include <linux/videodev2.h>
30#include <media/media-entity.h>
31#include <media/v4l2-ctrls.h>
32#include <media/v4l2-device.h>
33#include <media/v4l2-subdev.h>
34#include <media/v4l2-mediabus.h>
35#include <media/s5c73m3.h>
36
37#include "s5c73m3.h"
38
39static int s5c73m3_get_af_status(struct s5c73m3 *state, struct v4l2_ctrl *ctrl)
40{
41 u16 reg = REG_AF_STATUS_UNFOCUSED;
42
43 int ret = s5c73m3_read(state, REG_AF_STATUS, &reg);
44
45 switch (reg) {
46 case REG_CAF_STATUS_FIND_SEARCH_DIR:
47 case REG_AF_STATUS_FOCUSING:
48 case REG_CAF_STATUS_FOCUSING:
49 ctrl->val = V4L2_AUTO_FOCUS_STATUS_BUSY;
50 break;
51 case REG_CAF_STATUS_FOCUSED:
52 case REG_AF_STATUS_FOCUSED:
53 ctrl->val = V4L2_AUTO_FOCUS_STATUS_REACHED;
54 break;
55 default:
56 v4l2_info(&state->sensor_sd, "Unknown AF status %#x\n", reg);
57 /* Fall through */
58 case REG_CAF_STATUS_UNFOCUSED:
59 case REG_AF_STATUS_UNFOCUSED:
60 case REG_AF_STATUS_INVALID:
61 ctrl->val = V4L2_AUTO_FOCUS_STATUS_FAILED;
62 break;
63 }
64
65 return ret;
66}
67
68static int s5c73m3_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
69{
70 struct v4l2_subdev *sd = ctrl_to_sensor_sd(ctrl);
71 struct s5c73m3 *state = sensor_sd_to_s5c73m3(sd);
72 int ret;
73
74 if (state->power == 0)
75 return -EBUSY;
76
77 switch (ctrl->id) {
78 case V4L2_CID_FOCUS_AUTO:
79 ret = s5c73m3_get_af_status(state, state->ctrls.af_status);
80 if (ret)
81 return ret;
82 break;
83 }
84
85 return 0;
86}
87
88static int s5c73m3_set_colorfx(struct s5c73m3 *state, int val)
89{
90 static const unsigned short colorfx[][2] = {
91 { V4L2_COLORFX_NONE, COMM_IMAGE_EFFECT_NONE },
92 { V4L2_COLORFX_BW, COMM_IMAGE_EFFECT_MONO },
93 { V4L2_COLORFX_SEPIA, COMM_IMAGE_EFFECT_SEPIA },
94 { V4L2_COLORFX_NEGATIVE, COMM_IMAGE_EFFECT_NEGATIVE },
95 { V4L2_COLORFX_AQUA, COMM_IMAGE_EFFECT_AQUA },
96 };
97 int i;
98
99 for (i = 0; i < ARRAY_SIZE(colorfx); i++) {
100 if (colorfx[i][0] != val)
101 continue;
102
103 v4l2_dbg(1, s5c73m3_dbg, &state->sensor_sd,
104 "Setting %s color effect\n",
105 v4l2_ctrl_get_menu(state->ctrls.colorfx->id)[i]);
106
107 return s5c73m3_isp_command(state, COMM_IMAGE_EFFECT,
108 colorfx[i][1]);
109 }
110 return -EINVAL;
111}
112
113/* Set exposure metering/exposure bias */
114static int s5c73m3_set_exposure(struct s5c73m3 *state, int auto_exp)
115{
116 struct v4l2_subdev *sd = &state->sensor_sd;
117 struct s5c73m3_ctrls *ctrls = &state->ctrls;
118 int ret = 0;
119
120 if (ctrls->exposure_metering->is_new) {
121 u16 metering;
122
123 switch (ctrls->exposure_metering->val) {
124 case V4L2_EXPOSURE_METERING_CENTER_WEIGHTED:
125 metering = COMM_METERING_CENTER;
126 break;
127 case V4L2_EXPOSURE_METERING_SPOT:
128 metering = COMM_METERING_SPOT;
129 break;
130 default:
131 metering = COMM_METERING_AVERAGE;
132 break;
133 }
134
135 ret = s5c73m3_isp_command(state, COMM_METERING, metering);
136 }
137
138 if (!ret && ctrls->exposure_bias->is_new) {
139 u16 exp_bias = ctrls->exposure_bias->val;
140 ret = s5c73m3_isp_command(state, COMM_EV, exp_bias);
141 }
142
143 v4l2_dbg(1, s5c73m3_dbg, sd,
144 "%s: exposure bias: %#x, metering: %#x (%d)\n", __func__,
145 ctrls->exposure_bias->val, ctrls->exposure_metering->val, ret);
146
147 return ret;
148}
149
150static int s5c73m3_set_white_balance(struct s5c73m3 *state, int val)
151{
152 static const unsigned short wb[][2] = {
153 { V4L2_WHITE_BALANCE_INCANDESCENT, COMM_AWB_MODE_INCANDESCENT},
154 { V4L2_WHITE_BALANCE_FLUORESCENT, COMM_AWB_MODE_FLUORESCENT1},
155 { V4L2_WHITE_BALANCE_FLUORESCENT_H, COMM_AWB_MODE_FLUORESCENT2},
156 { V4L2_WHITE_BALANCE_CLOUDY, COMM_AWB_MODE_CLOUDY},
157 { V4L2_WHITE_BALANCE_DAYLIGHT, COMM_AWB_MODE_DAYLIGHT},
158 { V4L2_WHITE_BALANCE_AUTO, COMM_AWB_MODE_AUTO},
159 };
160 int i;
161
162 for (i = 0; i < ARRAY_SIZE(wb); i++) {
163 if (wb[i][0] != val)
164 continue;
165
166 v4l2_dbg(1, s5c73m3_dbg, &state->sensor_sd,
167 "Setting white balance to: %s\n",
168 v4l2_ctrl_get_menu(state->ctrls.auto_wb->id)[i]);
169
170 return s5c73m3_isp_command(state, COMM_AWB_MODE, wb[i][1]);
171 }
172
173 return -EINVAL;
174}
175
176static int s5c73m3_af_run(struct s5c73m3 *state, bool on)
177{
178 struct s5c73m3_ctrls *c = &state->ctrls;
179
180 if (!on)
181 return s5c73m3_isp_command(state, COMM_AF_CON,
182 COMM_AF_CON_STOP);
183
184 if (c->focus_auto->val)
185 return s5c73m3_isp_command(state, COMM_AF_MODE,
186 COMM_AF_MODE_PREVIEW_CAF_START);
187
188 return s5c73m3_isp_command(state, COMM_AF_CON, COMM_AF_CON_START);
189}
190
191static int s5c73m3_3a_lock(struct s5c73m3 *state, struct v4l2_ctrl *ctrl)
192{
193 bool awb_lock = ctrl->val & V4L2_LOCK_WHITE_BALANCE;
194 bool ae_lock = ctrl->val & V4L2_LOCK_EXPOSURE;
195 bool af_lock = ctrl->val & V4L2_LOCK_FOCUS;
196 int ret = 0;
197
198 if ((ctrl->val ^ ctrl->cur.val) & V4L2_LOCK_EXPOSURE) {
199 ret = s5c73m3_isp_command(state, COMM_AE_CON,
200 ae_lock ? COMM_AE_STOP : COMM_AE_START);
201 if (ret)
202 return ret;
203 }
204
205 if (((ctrl->val ^ ctrl->cur.val) & V4L2_LOCK_WHITE_BALANCE)
206 && state->ctrls.auto_wb->val) {
207 ret = s5c73m3_isp_command(state, COMM_AWB_CON,
208 awb_lock ? COMM_AWB_STOP : COMM_AWB_START);
209 if (ret)
210 return ret;
211 }
212
213 if ((ctrl->val ^ ctrl->cur.val) & V4L2_LOCK_FOCUS)
214 ret = s5c73m3_af_run(state, ~af_lock);
215
216 return ret;
217}
218
219static int s5c73m3_set_auto_focus(struct s5c73m3 *state, int caf)
220{
221 struct s5c73m3_ctrls *c = &state->ctrls;
222 int ret = 1;
223
224 if (c->af_distance->is_new) {
225 u16 mode = (c->af_distance->val == V4L2_AUTO_FOCUS_RANGE_MACRO)
226 ? COMM_AF_MODE_MACRO : COMM_AF_MODE_NORMAL;
227 ret = s5c73m3_isp_command(state, COMM_AF_MODE, mode);
228 if (ret != 0)
229 return ret;
230 }
231
232 if (!ret || (c->focus_auto->is_new && c->focus_auto->val) ||
233 c->af_start->is_new)
234 ret = s5c73m3_af_run(state, 1);
235 else if ((c->focus_auto->is_new && !c->focus_auto->val) ||
236 c->af_stop->is_new)
237 ret = s5c73m3_af_run(state, 0);
238 else
239 ret = 0;
240
241 return ret;
242}
243
244static int s5c73m3_set_contrast(struct s5c73m3 *state, int val)
245{
246 u16 reg = (val < 0) ? -val + 2 : val;
247 return s5c73m3_isp_command(state, COMM_CONTRAST, reg);
248}
249
250static int s5c73m3_set_saturation(struct s5c73m3 *state, int val)
251{
252 u16 reg = (val < 0) ? -val + 2 : val;
253 return s5c73m3_isp_command(state, COMM_SATURATION, reg);
254}
255
256static int s5c73m3_set_sharpness(struct s5c73m3 *state, int val)
257{
258 u16 reg = (val < 0) ? -val + 2 : val;
259 return s5c73m3_isp_command(state, COMM_SHARPNESS, reg);
260}
261
262static int s5c73m3_set_iso(struct s5c73m3 *state, int val)
263{
264 u32 iso;
265
266 if (val == V4L2_ISO_SENSITIVITY_MANUAL)
267 iso = state->ctrls.iso->val + 1;
268 else
269 iso = 0;
270
271 return s5c73m3_isp_command(state, COMM_ISO, iso);
272}
273
274static int s5c73m3_set_stabilization(struct s5c73m3 *state, int val)
275{
276 struct v4l2_subdev *sd = &state->sensor_sd;
277
278 v4l2_dbg(1, s5c73m3_dbg, sd, "Image stabilization: %d\n", val);
279
280 return s5c73m3_isp_command(state, COMM_FRAME_RATE, val ?
281 COMM_FRAME_RATE_ANTI_SHAKE : COMM_FRAME_RATE_AUTO_SET);
282}
283
284static int s5c73m3_set_jpeg_quality(struct s5c73m3 *state, int quality)
285{
286 int reg;
287
288 if (quality <= 65)
289 reg = COMM_IMAGE_QUALITY_NORMAL;
290 else if (quality <= 75)
291 reg = COMM_IMAGE_QUALITY_FINE;
292 else
293 reg = COMM_IMAGE_QUALITY_SUPERFINE;
294
295 return s5c73m3_isp_command(state, COMM_IMAGE_QUALITY, reg);
296}
297
298static int s5c73m3_set_scene_program(struct s5c73m3 *state, int val)
299{
300 static const unsigned short scene_lookup[] = {
301 COMM_SCENE_MODE_NONE, /* V4L2_SCENE_MODE_NONE */
302 COMM_SCENE_MODE_AGAINST_LIGHT,/* V4L2_SCENE_MODE_BACKLIGHT */
303 COMM_SCENE_MODE_BEACH, /* V4L2_SCENE_MODE_BEACH_SNOW */
304 COMM_SCENE_MODE_CANDLE, /* V4L2_SCENE_MODE_CANDLE_LIGHT */
305 COMM_SCENE_MODE_DAWN, /* V4L2_SCENE_MODE_DAWN_DUSK */
306 COMM_SCENE_MODE_FALL, /* V4L2_SCENE_MODE_FALL_COLORS */
307 COMM_SCENE_MODE_FIRE, /* V4L2_SCENE_MODE_FIREWORKS */
308 COMM_SCENE_MODE_LANDSCAPE, /* V4L2_SCENE_MODE_LANDSCAPE */
309 COMM_SCENE_MODE_NIGHT, /* V4L2_SCENE_MODE_NIGHT */
310 COMM_SCENE_MODE_INDOOR, /* V4L2_SCENE_MODE_PARTY_INDOOR */
311 COMM_SCENE_MODE_PORTRAIT, /* V4L2_SCENE_MODE_PORTRAIT */
312 COMM_SCENE_MODE_SPORTS, /* V4L2_SCENE_MODE_SPORTS */
313 COMM_SCENE_MODE_SUNSET, /* V4L2_SCENE_MODE_SUNSET */
314 COMM_SCENE_MODE_TEXT, /* V4L2_SCENE_MODE_TEXT */
315 };
316
317 v4l2_dbg(1, s5c73m3_dbg, &state->sensor_sd, "Setting %s scene mode\n",
318 v4l2_ctrl_get_menu(state->ctrls.scene_mode->id)[val]);
319
320 return s5c73m3_isp_command(state, COMM_SCENE_MODE, scene_lookup[val]);
321}
322
323static int s5c73m3_set_power_line_freq(struct s5c73m3 *state, int val)
324{
325 unsigned int pwr_line_freq = COMM_FLICKER_NONE;
326
327 switch (val) {
328 case V4L2_CID_POWER_LINE_FREQUENCY_DISABLED:
329 pwr_line_freq = COMM_FLICKER_NONE;
330 break;
331 case V4L2_CID_POWER_LINE_FREQUENCY_50HZ:
332 pwr_line_freq = COMM_FLICKER_AUTO_50HZ;
333 break;
334 case V4L2_CID_POWER_LINE_FREQUENCY_60HZ:
335 pwr_line_freq = COMM_FLICKER_AUTO_60HZ;
336 break;
337 default:
338 case V4L2_CID_POWER_LINE_FREQUENCY_AUTO:
339 pwr_line_freq = COMM_FLICKER_NONE;
340 }
341
342 return s5c73m3_isp_command(state, COMM_FLICKER_MODE, pwr_line_freq);
343}
344
345static int s5c73m3_s_ctrl(struct v4l2_ctrl *ctrl)
346{
347 struct v4l2_subdev *sd = ctrl_to_sensor_sd(ctrl);
348 struct s5c73m3 *state = sensor_sd_to_s5c73m3(sd);
349 int ret = 0;
350
351 v4l2_dbg(1, s5c73m3_dbg, sd, "set_ctrl: %s, value: %d\n",
352 ctrl->name, ctrl->val);
353
354 mutex_lock(&state->lock);
355 /*
356 * If the device is not powered up by the host driver do
357 * not apply any controls to H/W at this time. Instead
358 * the controls will be restored right after power-up.
359 */
360 if (state->power == 0)
361 goto unlock;
362
363 if (ctrl->flags & V4L2_CTRL_FLAG_INACTIVE) {
364 ret = -EINVAL;
365 goto unlock;
366 }
367
368 switch (ctrl->id) {
369 case V4L2_CID_3A_LOCK:
370 ret = s5c73m3_3a_lock(state, ctrl);
371 break;
372
373 case V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE:
374 ret = s5c73m3_set_white_balance(state, ctrl->val);
375 break;
376
377 case V4L2_CID_CONTRAST:
378 ret = s5c73m3_set_contrast(state, ctrl->val);
379 break;
380
381 case V4L2_CID_COLORFX:
382 ret = s5c73m3_set_colorfx(state, ctrl->val);
383 break;
384
385 case V4L2_CID_EXPOSURE_AUTO:
386 ret = s5c73m3_set_exposure(state, ctrl->val);
387 break;
388
389 case V4L2_CID_FOCUS_AUTO:
390 ret = s5c73m3_set_auto_focus(state, ctrl->val);
391 break;
392
393 case V4L2_CID_IMAGE_STABILIZATION:
394 ret = s5c73m3_set_stabilization(state, ctrl->val);
395 break;
396
397 case V4L2_CID_ISO_SENSITIVITY:
398 ret = s5c73m3_set_iso(state, ctrl->val);
399 break;
400
401 case V4L2_CID_JPEG_COMPRESSION_QUALITY:
402 ret = s5c73m3_set_jpeg_quality(state, ctrl->val);
403 break;
404
405 case V4L2_CID_POWER_LINE_FREQUENCY:
406 ret = s5c73m3_set_power_line_freq(state, ctrl->val);
407 break;
408
409 case V4L2_CID_SATURATION:
410 ret = s5c73m3_set_saturation(state, ctrl->val);
411 break;
412
413 case V4L2_CID_SCENE_MODE:
414 ret = s5c73m3_set_scene_program(state, ctrl->val);
415 break;
416
417 case V4L2_CID_SHARPNESS:
418 ret = s5c73m3_set_sharpness(state, ctrl->val);
419 break;
420
421 case V4L2_CID_WIDE_DYNAMIC_RANGE:
422 ret = s5c73m3_isp_command(state, COMM_WDR, !!ctrl->val);
423 break;
424
425 case V4L2_CID_ZOOM_ABSOLUTE:
426 ret = s5c73m3_isp_command(state, COMM_ZOOM_STEP, ctrl->val);
427 break;
428 }
429unlock:
430 mutex_unlock(&state->lock);
431 return ret;
432}
433
434static const struct v4l2_ctrl_ops s5c73m3_ctrl_ops = {
435 .g_volatile_ctrl = s5c73m3_g_volatile_ctrl,
436 .s_ctrl = s5c73m3_s_ctrl,
437};
438
439/* Supported manual ISO values */
440static const s64 iso_qmenu[] = {
441 /* COMM_ISO: 0x0001...0x0004 */
442 100, 200, 400, 800,
443};
444
445/* Supported exposure bias values (-2.0EV...+2.0EV) */
446static const s64 ev_bias_qmenu[] = {
447 /* COMM_EV: 0x0000...0x0008 */
448 -2000, -1500, -1000, -500, 0, 500, 1000, 1500, 2000
449};
450
451int s5c73m3_init_controls(struct s5c73m3 *state)
452{
453 const struct v4l2_ctrl_ops *ops = &s5c73m3_ctrl_ops;
454 struct s5c73m3_ctrls *ctrls = &state->ctrls;
455 struct v4l2_ctrl_handler *hdl = &ctrls->handler;
456
457 int ret = v4l2_ctrl_handler_init(hdl, 22);
458 if (ret)
459 return ret;
460
461 /* White balance */
462 ctrls->auto_wb = v4l2_ctrl_new_std_menu(hdl, ops,
463 V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE,
464 9, ~0x15e, V4L2_WHITE_BALANCE_AUTO);
465
466 /* Exposure (only automatic exposure) */
467 ctrls->auto_exposure = v4l2_ctrl_new_std_menu(hdl, ops,
468 V4L2_CID_EXPOSURE_AUTO, 0, ~0x01, V4L2_EXPOSURE_AUTO);
469
470 ctrls->exposure_bias = v4l2_ctrl_new_int_menu(hdl, ops,
471 V4L2_CID_AUTO_EXPOSURE_BIAS,
472 ARRAY_SIZE(ev_bias_qmenu) - 1,
473 ARRAY_SIZE(ev_bias_qmenu)/2 - 1,
474 ev_bias_qmenu);
475
476 ctrls->exposure_metering = v4l2_ctrl_new_std_menu(hdl, ops,
477 V4L2_CID_EXPOSURE_METERING,
478 2, ~0x7, V4L2_EXPOSURE_METERING_AVERAGE);
479
480 /* Auto focus */
481 ctrls->focus_auto = v4l2_ctrl_new_std(hdl, ops,
482 V4L2_CID_FOCUS_AUTO, 0, 1, 1, 0);
483
484 ctrls->af_start = v4l2_ctrl_new_std(hdl, ops,
485 V4L2_CID_AUTO_FOCUS_START, 0, 1, 1, 0);
486
487 ctrls->af_stop = v4l2_ctrl_new_std(hdl, ops,
488 V4L2_CID_AUTO_FOCUS_STOP, 0, 1, 1, 0);
489
490 ctrls->af_status = v4l2_ctrl_new_std(hdl, ops,
491 V4L2_CID_AUTO_FOCUS_STATUS, 0,
492 (V4L2_AUTO_FOCUS_STATUS_BUSY |
493 V4L2_AUTO_FOCUS_STATUS_REACHED |
494 V4L2_AUTO_FOCUS_STATUS_FAILED),
495 0, V4L2_AUTO_FOCUS_STATUS_IDLE);
496
497 ctrls->af_distance = v4l2_ctrl_new_std_menu(hdl, ops,
498 V4L2_CID_AUTO_FOCUS_RANGE,
499 V4L2_AUTO_FOCUS_RANGE_MACRO,
500 ~(1 << V4L2_AUTO_FOCUS_RANGE_NORMAL |
501 1 << V4L2_AUTO_FOCUS_RANGE_MACRO),
502 V4L2_AUTO_FOCUS_RANGE_NORMAL);
503 /* ISO sensitivity */
504 ctrls->auto_iso = v4l2_ctrl_new_std_menu(hdl, ops,
505 V4L2_CID_ISO_SENSITIVITY_AUTO, 1, 0,
506 V4L2_ISO_SENSITIVITY_AUTO);
507
508 ctrls->iso = v4l2_ctrl_new_int_menu(hdl, ops,
509 V4L2_CID_ISO_SENSITIVITY, ARRAY_SIZE(iso_qmenu) - 1,
510 ARRAY_SIZE(iso_qmenu)/2 - 1, iso_qmenu);
511
512 ctrls->contrast = v4l2_ctrl_new_std(hdl, ops,
513 V4L2_CID_CONTRAST, -2, 2, 1, 0);
514
515 ctrls->saturation = v4l2_ctrl_new_std(hdl, ops,
516 V4L2_CID_SATURATION, -2, 2, 1, 0);
517
518 ctrls->sharpness = v4l2_ctrl_new_std(hdl, ops,
519 V4L2_CID_SHARPNESS, -2, 2, 1, 0);
520
521 ctrls->zoom = v4l2_ctrl_new_std(hdl, ops,
522 V4L2_CID_ZOOM_ABSOLUTE, 0, 30, 1, 0);
523
524 ctrls->colorfx = v4l2_ctrl_new_std_menu(hdl, ops, V4L2_CID_COLORFX,
525 V4L2_COLORFX_AQUA, ~0x40f, V4L2_COLORFX_NONE);
526
527 ctrls->wdr = v4l2_ctrl_new_std(hdl, ops,
528 V4L2_CID_WIDE_DYNAMIC_RANGE, 0, 1, 1, 0);
529
530 ctrls->stabilization = v4l2_ctrl_new_std(hdl, ops,
531 V4L2_CID_IMAGE_STABILIZATION, 0, 1, 1, 0);
532
533 v4l2_ctrl_new_std_menu(hdl, ops, V4L2_CID_POWER_LINE_FREQUENCY,
534 V4L2_CID_POWER_LINE_FREQUENCY_AUTO, 0,
535 V4L2_CID_POWER_LINE_FREQUENCY_AUTO);
536
537 ctrls->jpeg_quality = v4l2_ctrl_new_std(hdl, ops,
538 V4L2_CID_JPEG_COMPRESSION_QUALITY, 1, 100, 1, 80);
539
540 ctrls->scene_mode = v4l2_ctrl_new_std_menu(hdl, ops,
541 V4L2_CID_SCENE_MODE, V4L2_SCENE_MODE_TEXT, ~0x3fff,
542 V4L2_SCENE_MODE_NONE);
543
544 ctrls->aaa_lock = v4l2_ctrl_new_std(hdl, ops,
545 V4L2_CID_3A_LOCK, 0, 0x7, 0, 0);
546
547 if (hdl->error) {
548 ret = hdl->error;
549 v4l2_ctrl_handler_free(hdl);
550 return ret;
551 }
552
553 v4l2_ctrl_auto_cluster(3, &ctrls->auto_exposure, 0, false);
554 ctrls->auto_iso->flags |= V4L2_CTRL_FLAG_VOLATILE |
555 V4L2_CTRL_FLAG_UPDATE;
556 v4l2_ctrl_auto_cluster(2, &ctrls->auto_iso, 0, false);
557 ctrls->af_status->flags |= V4L2_CTRL_FLAG_VOLATILE;
558 v4l2_ctrl_cluster(6, &ctrls->focus_auto);
559
560 state->sensor_sd.ctrl_handler = hdl;
561
562 return 0;
563}
diff --git a/drivers/media/i2c/s5c73m3/s5c73m3-spi.c b/drivers/media/i2c/s5c73m3/s5c73m3-spi.c
new file mode 100644
index 000000000000..6f3a9c00fe65
--- /dev/null
+++ b/drivers/media/i2c/s5c73m3/s5c73m3-spi.c
@@ -0,0 +1,156 @@
1/*
2 * Samsung LSI S5C73M3 8M pixel camera driver
3 *
4 * Copyright (C) 2012, Samsung Electronics, Co., Ltd.
5 * Sylwester Nawrocki <s.nawrocki@samsung.com>
6 * Andrzej Hajda <a.hajda@samsung.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17
18#include <linux/sizes.h>
19#include <linux/delay.h>
20#include <linux/init.h>
21#include <linux/media.h>
22#include <linux/module.h>
23#include <linux/slab.h>
24#include <linux/spi/spi.h>
25
26#include "s5c73m3.h"
27
28#define S5C73M3_SPI_DRV_NAME "S5C73M3-SPI"
29
30enum spi_direction {
31 SPI_DIR_RX,
32 SPI_DIR_TX
33};
34
35static int spi_xmit(struct spi_device *spi_dev, void *addr, const int len,
36 enum spi_direction dir)
37{
38 struct spi_message msg;
39 int r;
40 struct spi_transfer xfer = {
41 .len = len,
42 };
43
44 if (dir == SPI_DIR_TX)
45 xfer.tx_buf = addr;
46 else
47 xfer.rx_buf = addr;
48
49 if (spi_dev == NULL) {
50 dev_err(&spi_dev->dev, "SPI device is uninitialized\n");
51 return -ENODEV;
52 }
53
54 spi_message_init(&msg);
55 spi_message_add_tail(&xfer, &msg);
56
57 r = spi_sync(spi_dev, &msg);
58 if (r < 0)
59 dev_err(&spi_dev->dev, "%s spi_sync failed %d\n", __func__, r);
60
61 return r;
62}
63
64int s5c73m3_spi_write(struct s5c73m3 *state, const void *addr,
65 const unsigned int len, const unsigned int tx_size)
66{
67 struct spi_device *spi_dev = state->spi_dev;
68 u32 count = len / tx_size;
69 u32 extra = len % tx_size;
70 unsigned int i, j = 0;
71 u8 padding[32];
72 int r = 0;
73
74 memset(padding, 0, sizeof(padding));
75
76 for (i = 0; i < count ; i++) {
77 r = spi_xmit(spi_dev, (void *)addr + j, tx_size, SPI_DIR_TX);
78 if (r < 0)
79 return r;
80 j += tx_size;
81 }
82
83 if (extra > 0) {
84 r = spi_xmit(spi_dev, (void *)addr + j, extra, SPI_DIR_TX);
85 if (r < 0)
86 return r;
87 }
88
89 return spi_xmit(spi_dev, padding, sizeof(padding), SPI_DIR_TX);
90}
91
92int s5c73m3_spi_read(struct s5c73m3 *state, void *addr,
93 const unsigned int len, const unsigned int tx_size)
94{
95 struct spi_device *spi_dev = state->spi_dev;
96 u32 count = len / tx_size;
97 u32 extra = len % tx_size;
98 unsigned int i, j = 0;
99 int r = 0;
100
101 for (i = 0; i < count ; i++) {
102 r = spi_xmit(spi_dev, addr + j, tx_size, SPI_DIR_RX);
103 if (r < 0)
104 return r;
105 j += tx_size;
106 }
107
108 if (extra > 0)
109 return spi_xmit(spi_dev, addr + j, extra, SPI_DIR_RX);
110
111 return 0;
112}
113
114static int s5c73m3_spi_probe(struct spi_device *spi)
115{
116 int r;
117 struct s5c73m3 *state = container_of(spi->dev.driver, struct s5c73m3,
118 spidrv.driver);
119 spi->bits_per_word = 32;
120
121 r = spi_setup(spi);
122 if (r < 0) {
123 dev_err(&spi->dev, "spi_setup() failed\n");
124 return r;
125 }
126
127 mutex_lock(&state->lock);
128 state->spi_dev = spi;
129 mutex_unlock(&state->lock);
130
131 v4l2_info(&state->sensor_sd, "S5C73M3 SPI probed successfully\n");
132 return 0;
133}
134
135static int s5c73m3_spi_remove(struct spi_device *spi)
136{
137 return 0;
138}
139
140int s5c73m3_register_spi_driver(struct s5c73m3 *state)
141{
142 struct spi_driver *spidrv = &state->spidrv;
143
144 spidrv->remove = s5c73m3_spi_remove;
145 spidrv->probe = s5c73m3_spi_probe;
146 spidrv->driver.name = S5C73M3_SPI_DRV_NAME;
147 spidrv->driver.bus = &spi_bus_type;
148 spidrv->driver.owner = THIS_MODULE;
149
150 return spi_register_driver(spidrv);
151}
152
153void s5c73m3_unregister_spi_driver(struct s5c73m3 *state)
154{
155 spi_unregister_driver(&state->spidrv);
156}
diff --git a/drivers/media/i2c/s5c73m3/s5c73m3.h b/drivers/media/i2c/s5c73m3/s5c73m3.h
new file mode 100644
index 000000000000..9d2c08652246
--- /dev/null
+++ b/drivers/media/i2c/s5c73m3/s5c73m3.h
@@ -0,0 +1,459 @@
1/*
2 * Samsung LSI S5C73M3 8M pixel camera driver
3 *
4 * Copyright (C) 2012, Samsung Electronics, Co., Ltd.
5 * Sylwester Nawrocki <s.nawrocki@samsung.com>
6 * Andrzej Hajda <a.hajda@samsung.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17#ifndef S5C73M3_H_
18#define S5C73M3_H_
19
20#include <linux/kernel.h>
21#include <linux/regulator/consumer.h>
22#include <media/v4l2-common.h>
23#include <media/v4l2-ctrls.h>
24#include <media/v4l2-subdev.h>
25#include <media/s5c73m3.h>
26
27#define DRIVER_NAME "S5C73M3"
28
29#define S5C73M3_ISP_FMT V4L2_MBUS_FMT_VYUY8_2X8
30#define S5C73M3_JPEG_FMT V4L2_MBUS_FMT_S5C_UYVY_JPEG_1X8
31
32/* Subdevs pad index definitions */
33enum s5c73m3_pads {
34 S5C73M3_ISP_PAD,
35 S5C73M3_JPEG_PAD,
36 S5C73M3_NUM_PADS
37};
38
39enum s5c73m3_oif_pads {
40 OIF_ISP_PAD,
41 OIF_JPEG_PAD,
42 OIF_SOURCE_PAD,
43 OIF_NUM_PADS
44};
45
46#define S5C73M3_SENSOR_FW_LEN 6
47#define S5C73M3_SENSOR_TYPE_LEN 12
48
49#define S5C73M3_REG(_addrh, _addrl) (((_addrh) << 16) | _addrl)
50
51#define AHB_MSB_ADDR_PTR 0xfcfc
52#define REG_CMDWR_ADDRH 0x0050
53#define REG_CMDWR_ADDRL 0x0054
54#define REG_CMDRD_ADDRH 0x0058
55#define REG_CMDRD_ADDRL 0x005c
56#define REG_CMDBUF_ADDR 0x0f14
57
58#define REG_I2C_SEQ_STATUS S5C73M3_REG(0x0009, 0x59A6)
59#define SEQ_END_PLL (1<<0x0)
60#define SEQ_END_SENSOR (1<<0x1)
61#define SEQ_END_GPIO (1<<0x2)
62#define SEQ_END_FROM (1<<0x3)
63#define SEQ_END_STABLE_AE_AWB (1<<0x4)
64#define SEQ_END_READY_I2C_CMD (1<<0x5)
65
66#define REG_I2C_STATUS S5C73M3_REG(0x0009, 0x599E)
67#define I2C_STATUS_CIS_I2C (1<<0x0)
68#define I2C_STATUS_AF_INIT (1<<0x1)
69#define I2C_STATUS_CAL_DATA (1<<0x2)
70#define I2C_STATUS_FRAME_COUNT (1<<0x3)
71#define I2C_STATUS_FROM_INIT (1<<0x4)
72#define I2C_STATUS_I2C_CIS_STREAM_OFF (1<<0x5)
73#define I2C_STATUS_I2C_N_CMD_OVER (1<<0x6)
74#define I2C_STATUS_I2C_N_CMD_MISMATCH (1<<0x7)
75#define I2C_STATUS_CHECK_BIN_CRC (1<<0x8)
76#define I2C_STATUS_EXCEPTION (1<<0x9)
77#define I2C_STATUS_INIF_INIT_STATE (0x8)
78
79#define REG_STATUS S5C73M3_REG(0x0009, 0x5080)
80#define REG_STATUS_BOOT_SUB_MAIN_ENTER 0xff01
81#define REG_STATUS_BOOT_SRAM_TIMING_OK 0xff02
82#define REG_STATUS_BOOT_INTERRUPTS_EN 0xff03
83#define REG_STATUS_BOOT_R_PLL_DONE 0xff04
84#define REG_STATUS_BOOT_R_PLL_LOCKTIME_DONE 0xff05
85#define REG_STATUS_BOOT_DELAY_COUNT_DONE 0xff06
86#define REG_STATUS_BOOT_I_PLL_DONE 0xff07
87#define REG_STATUS_BOOT_I_PLL_LOCKTIME_DONE 0xff08
88#define REG_STATUS_BOOT_PLL_INIT_OK 0xff09
89#define REG_STATUS_BOOT_SENSOR_INIT_OK 0xff0a
90#define REG_STATUS_BOOT_GPIO_SETTING_OK 0xff0b
91#define REG_STATUS_BOOT_READ_CAL_DATA_OK 0xff0c
92#define REG_STATUS_BOOT_STABLE_AE_AWB_OK 0xff0d
93#define REG_STATUS_ISP_COMMAND_COMPLETED 0xffff
94#define REG_STATUS_EXCEPTION_OCCURED 0xdead
95
96#define COMM_RESULT_OFFSET S5C73M3_REG(0x0009, 0x5000)
97
98#define COMM_IMG_OUTPUT 0x0902
99#define COMM_IMG_OUTPUT_HDR 0x0008
100#define COMM_IMG_OUTPUT_YUV 0x0009
101#define COMM_IMG_OUTPUT_INTERLEAVED 0x000d
102
103#define COMM_STILL_PRE_FLASH 0x0a00
104#define COMM_STILL_PRE_FLASH_FIRE 0x0000
105#define COMM_STILL_PRE_FLASH_NON_FIRED 0x0000
106#define COMM_STILL_PRE_FLASH_FIRED 0x0001
107
108#define COMM_STILL_MAIN_FLASH 0x0a02
109#define COMM_STILL_MAIN_FLASH_CANCEL 0x0001
110#define COMM_STILL_MAIN_FLASH_FIRE 0x0002
111
112#define COMM_ZOOM_STEP 0x0b00
113
114#define COMM_IMAGE_EFFECT 0x0b0a
115#define COMM_IMAGE_EFFECT_NONE 0x0001
116#define COMM_IMAGE_EFFECT_NEGATIVE 0x0002
117#define COMM_IMAGE_EFFECT_AQUA 0x0003
118#define COMM_IMAGE_EFFECT_SEPIA 0x0004
119#define COMM_IMAGE_EFFECT_MONO 0x0005
120
121#define COMM_IMAGE_QUALITY 0x0b0c
122#define COMM_IMAGE_QUALITY_SUPERFINE 0x0000
123#define COMM_IMAGE_QUALITY_FINE 0x0001
124#define COMM_IMAGE_QUALITY_NORMAL 0x0002
125
126#define COMM_FLASH_MODE 0x0b0e
127#define COMM_FLASH_MODE_OFF 0x0000
128#define COMM_FLASH_MODE_ON 0x0001
129#define COMM_FLASH_MODE_AUTO 0x0002
130
131#define COMM_FLASH_STATUS 0x0b80
132#define COMM_FLASH_STATUS_OFF 0x0001
133#define COMM_FLASH_STATUS_ON 0x0002
134#define COMM_FLASH_STATUS_AUTO 0x0003
135
136#define COMM_FLASH_TORCH 0x0b12
137#define COMM_FLASH_TORCH_OFF 0x0000
138#define COMM_FLASH_TORCH_ON 0x0001
139
140#define COMM_AE_NEEDS_FLASH 0x0cba
141#define COMM_AE_NEEDS_FLASH_OFF 0x0000
142#define COMM_AE_NEEDS_FLASH_ON 0x0001
143
144#define COMM_CHG_MODE 0x0b10
145#define COMM_CHG_MODE_NEW 0x8000
146#define COMM_CHG_MODE_SUBSAMPLING_HALF 0x2000
147#define COMM_CHG_MODE_SUBSAMPLING_QUARTER 0x4000
148
149#define COMM_CHG_MODE_YUV_320_240 0x0001
150#define COMM_CHG_MODE_YUV_640_480 0x0002
151#define COMM_CHG_MODE_YUV_880_720 0x0003
152#define COMM_CHG_MODE_YUV_960_720 0x0004
153#define COMM_CHG_MODE_YUV_1184_666 0x0005
154#define COMM_CHG_MODE_YUV_1280_720 0x0006
155#define COMM_CHG_MODE_YUV_1536_864 0x0007
156#define COMM_CHG_MODE_YUV_1600_1200 0x0008
157#define COMM_CHG_MODE_YUV_1632_1224 0x0009
158#define COMM_CHG_MODE_YUV_1920_1080 0x000a
159#define COMM_CHG_MODE_YUV_1920_1440 0x000b
160#define COMM_CHG_MODE_YUV_2304_1296 0x000c
161#define COMM_CHG_MODE_YUV_3264_2448 0x000d
162#define COMM_CHG_MODE_YUV_352_288 0x000e
163#define COMM_CHG_MODE_YUV_1008_672 0x000f
164
165#define COMM_CHG_MODE_JPEG_640_480 0x0010
166#define COMM_CHG_MODE_JPEG_800_450 0x0020
167#define COMM_CHG_MODE_JPEG_800_600 0x0030
168#define COMM_CHG_MODE_JPEG_1280_720 0x0040
169#define COMM_CHG_MODE_JPEG_1280_960 0x0050
170#define COMM_CHG_MODE_JPEG_1600_900 0x0060
171#define COMM_CHG_MODE_JPEG_1600_1200 0x0070
172#define COMM_CHG_MODE_JPEG_2048_1152 0x0080
173#define COMM_CHG_MODE_JPEG_2048_1536 0x0090
174#define COMM_CHG_MODE_JPEG_2560_1440 0x00a0
175#define COMM_CHG_MODE_JPEG_2560_1920 0x00b0
176#define COMM_CHG_MODE_JPEG_3264_2176 0x00c0
177#define COMM_CHG_MODE_JPEG_1024_768 0x00d0
178#define COMM_CHG_MODE_JPEG_3264_1836 0x00e0
179#define COMM_CHG_MODE_JPEG_3264_2448 0x00f0
180
181#define COMM_AF_CON 0x0e00
182#define COMM_AF_CON_STOP 0x0000
183#define COMM_AF_CON_SCAN 0x0001 /* Full Search */
184#define COMM_AF_CON_START 0x0002 /* Fast Search */
185
186#define COMM_AF_CAL 0x0e06
187#define COMM_AF_TOUCH_AF 0x0e0a
188
189#define REG_AF_STATUS S5C73M3_REG(0x0009, 0x5e80)
190#define REG_CAF_STATUS_FIND_SEARCH_DIR 0x0001
191#define REG_CAF_STATUS_FOCUSING 0x0002
192#define REG_CAF_STATUS_FOCUSED 0x0003
193#define REG_CAF_STATUS_UNFOCUSED 0x0004
194#define REG_AF_STATUS_INVALID 0x0010
195#define REG_AF_STATUS_FOCUSING 0x0020
196#define REG_AF_STATUS_FOCUSED 0x0030
197#define REG_AF_STATUS_UNFOCUSED 0x0040
198
199#define REG_AF_TOUCH_POSITION S5C73M3_REG(0x0009, 0x5e8e)
200#define COMM_AF_FACE_ZOOM 0x0e10
201
202#define COMM_AF_MODE 0x0e02
203#define COMM_AF_MODE_NORMAL 0x0000
204#define COMM_AF_MODE_MACRO 0x0001
205#define COMM_AF_MODE_MOVIE_CAF_START 0x0002
206#define COMM_AF_MODE_MOVIE_CAF_STOP 0x0003
207#define COMM_AF_MODE_PREVIEW_CAF_START 0x0004
208#define COMM_AF_MODE_PREVIEW_CAF_STOP 0x0005
209
210#define COMM_AF_SOFTLANDING 0x0e16
211#define COMM_AF_SOFTLANDING_ON 0x0000
212#define COMM_AF_SOFTLANDING_RES_COMPLETE 0x0001
213
214#define COMM_FACE_DET 0x0e0c
215#define COMM_FACE_DET_OFF 0x0000
216#define COMM_FACE_DET_ON 0x0001
217
218#define COMM_FACE_DET_OSD 0x0e0e
219#define COMM_FACE_DET_OSD_OFF 0x0000
220#define COMM_FACE_DET_OSD_ON 0x0001
221
222#define COMM_AE_CON 0x0c00
223#define COMM_AE_STOP 0x0000 /* lock */
224#define COMM_AE_START 0x0001 /* unlock */
225
226#define COMM_ISO 0x0c02
227#define COMM_ISO_AUTO 0x0000
228#define COMM_ISO_100 0x0001
229#define COMM_ISO_200 0x0002
230#define COMM_ISO_400 0x0003
231#define COMM_ISO_800 0x0004
232#define COMM_ISO_SPORTS 0x0005
233#define COMM_ISO_NIGHT 0x0006
234#define COMM_ISO_INDOOR 0x0007
235
236/* 0x00000 (-2.0 EV)...0x0008 (2.0 EV), 0.5EV step */
237#define COMM_EV 0x0c04
238
239#define COMM_METERING 0x0c06
240#define COMM_METERING_CENTER 0x0000
241#define COMM_METERING_SPOT 0x0001
242#define COMM_METERING_AVERAGE 0x0002
243#define COMM_METERING_SMART 0x0003
244
245#define COMM_WDR 0x0c08
246#define COMM_WDR_OFF 0x0000
247#define COMM_WDR_ON 0x0001
248
249#define COMM_FLICKER_MODE 0x0c12
250#define COMM_FLICKER_NONE 0x0000
251#define COMM_FLICKER_MANUAL_50HZ 0x0001
252#define COMM_FLICKER_MANUAL_60HZ 0x0002
253#define COMM_FLICKER_AUTO 0x0003
254#define COMM_FLICKER_AUTO_50HZ 0x0004
255#define COMM_FLICKER_AUTO_60HZ 0x0005
256
257#define COMM_FRAME_RATE 0x0c1e
258#define COMM_FRAME_RATE_AUTO_SET 0x0000
259#define COMM_FRAME_RATE_FIXED_30FPS 0x0002
260#define COMM_FRAME_RATE_FIXED_20FPS 0x0003
261#define COMM_FRAME_RATE_FIXED_15FPS 0x0004
262#define COMM_FRAME_RATE_FIXED_60FPS 0x0007
263#define COMM_FRAME_RATE_FIXED_120FPS 0x0008
264#define COMM_FRAME_RATE_FIXED_7FPS 0x0009
265#define COMM_FRAME_RATE_FIXED_10FPS 0x000a
266#define COMM_FRAME_RATE_FIXED_90FPS 0x000b
267#define COMM_FRAME_RATE_ANTI_SHAKE 0x0013
268
269/* 0x0000...0x0004 -> sharpness: 0, 1, 2, -1, -2 */
270#define COMM_SHARPNESS 0x0c14
271
272/* 0x0000...0x0004 -> saturation: 0, 1, 2, -1, -2 */
273#define COMM_SATURATION 0x0c16
274
275/* 0x0000...0x0004 -> contrast: 0, 1, 2, -1, -2 */
276#define COMM_CONTRAST 0x0c18
277
278#define COMM_SCENE_MODE 0x0c1a
279#define COMM_SCENE_MODE_NONE 0x0000
280#define COMM_SCENE_MODE_PORTRAIT 0x0001
281#define COMM_SCENE_MODE_LANDSCAPE 0x0002
282#define COMM_SCENE_MODE_SPORTS 0x0003
283#define COMM_SCENE_MODE_INDOOR 0x0004
284#define COMM_SCENE_MODE_BEACH 0x0005
285#define COMM_SCENE_MODE_SUNSET 0x0006
286#define COMM_SCENE_MODE_DAWN 0x0007
287#define COMM_SCENE_MODE_FALL 0x0008
288#define COMM_SCENE_MODE_NIGHT 0x0009
289#define COMM_SCENE_MODE_AGAINST_LIGHT 0x000a
290#define COMM_SCENE_MODE_FIRE 0x000b
291#define COMM_SCENE_MODE_TEXT 0x000c
292#define COMM_SCENE_MODE_CANDLE 0x000d
293
294#define COMM_AE_AUTO_BRACKET 0x0b14
295#define COMM_AE_AUTO_BRAKET_EV05 0x0080
296#define COMM_AE_AUTO_BRAKET_EV10 0x0100
297#define COMM_AE_AUTO_BRAKET_EV15 0x0180
298#define COMM_AE_AUTO_BRAKET_EV20 0x0200
299
300#define COMM_SENSOR_STREAMING 0x090a
301#define COMM_SENSOR_STREAMING_OFF 0x0000
302#define COMM_SENSOR_STREAMING_ON 0x0001
303
304#define COMM_AWB_MODE 0x0d02
305#define COMM_AWB_MODE_INCANDESCENT 0x0000
306#define COMM_AWB_MODE_FLUORESCENT1 0x0001
307#define COMM_AWB_MODE_FLUORESCENT2 0x0002
308#define COMM_AWB_MODE_DAYLIGHT 0x0003
309#define COMM_AWB_MODE_CLOUDY 0x0004
310#define COMM_AWB_MODE_AUTO 0x0005
311
312#define COMM_AWB_CON 0x0d00
313#define COMM_AWB_STOP 0x0000 /* lock */
314#define COMM_AWB_START 0x0001 /* unlock */
315
316#define COMM_FW_UPDATE 0x0906
317#define COMM_FW_UPDATE_NOT_READY 0x0000
318#define COMM_FW_UPDATE_SUCCESS 0x0005
319#define COMM_FW_UPDATE_FAIL 0x0007
320#define COMM_FW_UPDATE_BUSY 0xffff
321
322
323#define S5C73M3_MAX_SUPPLIES 6
324
325struct s5c73m3_ctrls {
326 struct v4l2_ctrl_handler handler;
327 struct {
328 /* exposure/exposure bias cluster */
329 struct v4l2_ctrl *auto_exposure;
330 struct v4l2_ctrl *exposure_bias;
331 struct v4l2_ctrl *exposure_metering;
332 };
333 struct {
334 /* iso/auto iso cluster */
335 struct v4l2_ctrl *auto_iso;
336 struct v4l2_ctrl *iso;
337 };
338 struct v4l2_ctrl *auto_wb;
339 struct {
340 /* continuous auto focus/auto focus cluster */
341 struct v4l2_ctrl *focus_auto;
342 struct v4l2_ctrl *af_start;
343 struct v4l2_ctrl *af_stop;
344 struct v4l2_ctrl *af_status;
345 struct v4l2_ctrl *af_distance;
346 };
347
348 struct v4l2_ctrl *aaa_lock;
349 struct v4l2_ctrl *colorfx;
350 struct v4l2_ctrl *contrast;
351 struct v4l2_ctrl *saturation;
352 struct v4l2_ctrl *sharpness;
353 struct v4l2_ctrl *zoom;
354 struct v4l2_ctrl *wdr;
355 struct v4l2_ctrl *stabilization;
356 struct v4l2_ctrl *jpeg_quality;
357 struct v4l2_ctrl *scene_mode;
358};
359
360enum s5c73m3_gpio_id {
361 STBY,
362 RST,
363 GPIO_NUM,
364};
365
366enum s5c73m3_resolution_types {
367 RES_ISP,
368 RES_JPEG,
369};
370
371struct s5c73m3_interval {
372 u16 fps_reg;
373 struct v4l2_fract interval;
374 /* Maximum rectangle for the interval */
375 struct v4l2_frmsize_discrete size;
376};
377
378struct s5c73m3 {
379 struct v4l2_subdev sensor_sd;
380 struct media_pad sensor_pads[S5C73M3_NUM_PADS];
381
382 struct v4l2_subdev oif_sd;
383 struct media_pad oif_pads[OIF_NUM_PADS];
384
385 struct spi_driver spidrv;
386 struct spi_device *spi_dev;
387 struct i2c_client *i2c_client;
388 u32 i2c_write_address;
389 u32 i2c_read_address;
390
391 struct regulator_bulk_data supplies[S5C73M3_MAX_SUPPLIES];
392 struct s5c73m3_gpio gpio[GPIO_NUM];
393
394 /* External master clock frequency */
395 u32 mclk_frequency;
396 /* Video bus type - MIPI-CSI2/paralell */
397 enum v4l2_mbus_type bus_type;
398
399 const struct s5c73m3_frame_size *sensor_pix_size[2];
400 const struct s5c73m3_frame_size *oif_pix_size[2];
401 enum v4l2_mbus_pixelcode mbus_code;
402
403 const struct s5c73m3_interval *fiv;
404
405 struct v4l2_mbus_frame_desc frame_desc;
406 /* protects the struct members below */
407 struct mutex lock;
408
409 struct s5c73m3_ctrls ctrls;
410
411 u8 streaming:1;
412 u8 apply_fmt:1;
413 u8 apply_fiv:1;
414 u8 isp_ready:1;
415
416 short power;
417
418 char sensor_fw[S5C73M3_SENSOR_FW_LEN + 2];
419 char sensor_type[S5C73M3_SENSOR_TYPE_LEN + 2];
420 char fw_file_version[2];
421 unsigned int fw_size;
422};
423
424struct s5c73m3_frame_size {
425 u32 width;
426 u32 height;
427 u8 reg_val;
428};
429
430extern int s5c73m3_dbg;
431
432int s5c73m3_register_spi_driver(struct s5c73m3 *state);
433void s5c73m3_unregister_spi_driver(struct s5c73m3 *state);
434int s5c73m3_spi_write(struct s5c73m3 *state, const void *addr,
435 const unsigned int len, const unsigned int tx_size);
436int s5c73m3_spi_read(struct s5c73m3 *state, void *addr,
437 const unsigned int len, const unsigned int tx_size);
438
439int s5c73m3_read(struct s5c73m3 *state, u32 addr, u16 *data);
440int s5c73m3_write(struct s5c73m3 *state, u32 addr, u16 data);
441int s5c73m3_isp_command(struct s5c73m3 *state, u16 command, u16 data);
442int s5c73m3_init_controls(struct s5c73m3 *state);
443
444static inline struct v4l2_subdev *ctrl_to_sensor_sd(struct v4l2_ctrl *ctrl)
445{
446 return &container_of(ctrl->handler, struct s5c73m3,
447 ctrls.handler)->sensor_sd;
448}
449
450static inline struct s5c73m3 *sensor_sd_to_s5c73m3(struct v4l2_subdev *sd)
451{
452 return container_of(sd, struct s5c73m3, sensor_sd);
453}
454
455static inline struct s5c73m3 *oif_sd_to_s5c73m3(struct v4l2_subdev *sd)
456{
457 return container_of(sd, struct s5c73m3, oif_sd);
458}
459#endif /* S5C73M3_H_ */
diff --git a/drivers/media/i2c/s5k6aa.c b/drivers/media/i2c/s5k6aa.c
index 57cd4fa0193d..bdf5e3db31d1 100644
--- a/drivers/media/i2c/s5k6aa.c
+++ b/drivers/media/i2c/s5k6aa.c
@@ -1598,7 +1598,7 @@ static int s5k6aa_probe(struct i2c_client *client,
1598 for (i = 0; i < S5K6AA_NUM_SUPPLIES; i++) 1598 for (i = 0; i < S5K6AA_NUM_SUPPLIES; i++)
1599 s5k6aa->supplies[i].supply = s5k6aa_supply_names[i]; 1599 s5k6aa->supplies[i].supply = s5k6aa_supply_names[i];
1600 1600
1601 ret = regulator_bulk_get(&client->dev, S5K6AA_NUM_SUPPLIES, 1601 ret = devm_regulator_bulk_get(&client->dev, S5K6AA_NUM_SUPPLIES,
1602 s5k6aa->supplies); 1602 s5k6aa->supplies);
1603 if (ret) { 1603 if (ret) {
1604 dev_err(&client->dev, "Failed to get regulators\n"); 1604 dev_err(&client->dev, "Failed to get regulators\n");
@@ -1607,7 +1607,7 @@ static int s5k6aa_probe(struct i2c_client *client,
1607 1607
1608 ret = s5k6aa_initialize_ctrls(s5k6aa); 1608 ret = s5k6aa_initialize_ctrls(s5k6aa);
1609 if (ret) 1609 if (ret)
1610 goto out_err4; 1610 goto out_err3;
1611 1611
1612 s5k6aa_presets_data_init(s5k6aa); 1612 s5k6aa_presets_data_init(s5k6aa);
1613 1613
@@ -1618,8 +1618,6 @@ static int s5k6aa_probe(struct i2c_client *client,
1618 1618
1619 return 0; 1619 return 0;
1620 1620
1621out_err4:
1622 regulator_bulk_free(S5K6AA_NUM_SUPPLIES, s5k6aa->supplies);
1623out_err3: 1621out_err3:
1624 s5k6aa_free_gpios(s5k6aa); 1622 s5k6aa_free_gpios(s5k6aa);
1625out_err2: 1623out_err2:
@@ -1635,7 +1633,6 @@ static int s5k6aa_remove(struct i2c_client *client)
1635 v4l2_device_unregister_subdev(sd); 1633 v4l2_device_unregister_subdev(sd);
1636 v4l2_ctrl_handler_free(sd->ctrl_handler); 1634 v4l2_ctrl_handler_free(sd->ctrl_handler);
1637 media_entity_cleanup(&sd->entity); 1635 media_entity_cleanup(&sd->entity);
1638 regulator_bulk_free(S5K6AA_NUM_SUPPLIES, s5k6aa->supplies);
1639 s5k6aa_free_gpios(s5k6aa); 1636 s5k6aa_free_gpios(s5k6aa);
1640 1637
1641 return 0; 1638 return 0;
diff --git a/drivers/media/i2c/soc_camera/imx074.c b/drivers/media/i2c/soc_camera/imx074.c
index f8534eec9de9..a2a5cbbdbe28 100644
--- a/drivers/media/i2c/soc_camera/imx074.c
+++ b/drivers/media/i2c/soc_camera/imx074.c
@@ -271,9 +271,9 @@ static int imx074_g_chip_ident(struct v4l2_subdev *sd,
271static int imx074_s_power(struct v4l2_subdev *sd, int on) 271static int imx074_s_power(struct v4l2_subdev *sd, int on)
272{ 272{
273 struct i2c_client *client = v4l2_get_subdevdata(sd); 273 struct i2c_client *client = v4l2_get_subdevdata(sd);
274 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 274 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
275 275
276 return soc_camera_set_power(&client->dev, icl, on); 276 return soc_camera_set_power(&client->dev, ssdd, on);
277} 277}
278 278
279static int imx074_g_mbus_config(struct v4l2_subdev *sd, 279static int imx074_g_mbus_config(struct v4l2_subdev *sd,
@@ -430,10 +430,9 @@ static int imx074_probe(struct i2c_client *client,
430{ 430{
431 struct imx074 *priv; 431 struct imx074 *priv;
432 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 432 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
433 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 433 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
434 int ret;
435 434
436 if (!icl) { 435 if (!ssdd) {
437 dev_err(&client->dev, "IMX074: missing platform data!\n"); 436 dev_err(&client->dev, "IMX074: missing platform data!\n");
438 return -EINVAL; 437 return -EINVAL;
439 } 438 }
@@ -444,7 +443,7 @@ static int imx074_probe(struct i2c_client *client,
444 return -EIO; 443 return -EIO;
445 } 444 }
446 445
447 priv = kzalloc(sizeof(struct imx074), GFP_KERNEL); 446 priv = devm_kzalloc(&client->dev, sizeof(struct imx074), GFP_KERNEL);
448 if (!priv) 447 if (!priv)
449 return -ENOMEM; 448 return -ENOMEM;
450 449
@@ -452,23 +451,15 @@ static int imx074_probe(struct i2c_client *client,
452 451
453 priv->fmt = &imx074_colour_fmts[0]; 452 priv->fmt = &imx074_colour_fmts[0];
454 453
455 ret = imx074_video_probe(client); 454 return imx074_video_probe(client);
456 if (ret < 0) {
457 kfree(priv);
458 return ret;
459 }
460
461 return ret;
462} 455}
463 456
464static int imx074_remove(struct i2c_client *client) 457static int imx074_remove(struct i2c_client *client)
465{ 458{
466 struct imx074 *priv = to_imx074(client); 459 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
467 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
468 460
469 if (icl->free_bus) 461 if (ssdd->free_bus)
470 icl->free_bus(icl); 462 ssdd->free_bus(ssdd);
471 kfree(priv);
472 463
473 return 0; 464 return 0;
474} 465}
diff --git a/drivers/media/i2c/soc_camera/mt9m001.c b/drivers/media/i2c/soc_camera/mt9m001.c
index 19f8a07764f9..bcdc86175549 100644
--- a/drivers/media/i2c/soc_camera/mt9m001.c
+++ b/drivers/media/i2c/soc_camera/mt9m001.c
@@ -23,7 +23,7 @@
23/* 23/*
24 * mt9m001 i2c address 0x5d 24 * mt9m001 i2c address 0x5d
25 * The platform has to define struct i2c_board_info objects and link to them 25 * The platform has to define struct i2c_board_info objects and link to them
26 * from struct soc_camera_link 26 * from struct soc_camera_host_desc
27 */ 27 */
28 28
29/* mt9m001 selected register addresses */ 29/* mt9m001 selected register addresses */
@@ -380,9 +380,9 @@ static int mt9m001_s_register(struct v4l2_subdev *sd,
380static int mt9m001_s_power(struct v4l2_subdev *sd, int on) 380static int mt9m001_s_power(struct v4l2_subdev *sd, int on)
381{ 381{
382 struct i2c_client *client = v4l2_get_subdevdata(sd); 382 struct i2c_client *client = v4l2_get_subdevdata(sd);
383 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 383 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
384 384
385 return soc_camera_set_power(&client->dev, icl, on); 385 return soc_camera_set_power(&client->dev, ssdd, on);
386} 386}
387 387
388static int mt9m001_g_volatile_ctrl(struct v4l2_ctrl *ctrl) 388static int mt9m001_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
@@ -482,7 +482,7 @@ static int mt9m001_s_ctrl(struct v4l2_ctrl *ctrl)
482 * Interface active, can use i2c. If it fails, it can indeed mean, that 482 * Interface active, can use i2c. If it fails, it can indeed mean, that
483 * this wasn't our capture interface, so, we wait for the right one 483 * this wasn't our capture interface, so, we wait for the right one
484 */ 484 */
485static int mt9m001_video_probe(struct soc_camera_link *icl, 485static int mt9m001_video_probe(struct soc_camera_subdev_desc *ssdd,
486 struct i2c_client *client) 486 struct i2c_client *client)
487{ 487{
488 struct mt9m001 *mt9m001 = to_mt9m001(client); 488 struct mt9m001 *mt9m001 = to_mt9m001(client);
@@ -526,8 +526,8 @@ static int mt9m001_video_probe(struct soc_camera_link *icl,
526 * The platform may support different bus widths due to 526 * The platform may support different bus widths due to
527 * different routing of the data lines. 527 * different routing of the data lines.
528 */ 528 */
529 if (icl->query_bus_param) 529 if (ssdd->query_bus_param)
530 flags = icl->query_bus_param(icl); 530 flags = ssdd->query_bus_param(ssdd);
531 else 531 else
532 flags = SOCAM_DATAWIDTH_10; 532 flags = SOCAM_DATAWIDTH_10;
533 533
@@ -558,10 +558,10 @@ done:
558 return ret; 558 return ret;
559} 559}
560 560
561static void mt9m001_video_remove(struct soc_camera_link *icl) 561static void mt9m001_video_remove(struct soc_camera_subdev_desc *ssdd)
562{ 562{
563 if (icl->free_bus) 563 if (ssdd->free_bus)
564 icl->free_bus(icl); 564 ssdd->free_bus(ssdd);
565} 565}
566 566
567static int mt9m001_g_skip_top_lines(struct v4l2_subdev *sd, u32 *lines) 567static int mt9m001_g_skip_top_lines(struct v4l2_subdev *sd, u32 *lines)
@@ -605,14 +605,14 @@ static int mt9m001_g_mbus_config(struct v4l2_subdev *sd,
605 struct v4l2_mbus_config *cfg) 605 struct v4l2_mbus_config *cfg)
606{ 606{
607 struct i2c_client *client = v4l2_get_subdevdata(sd); 607 struct i2c_client *client = v4l2_get_subdevdata(sd);
608 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 608 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
609 609
610 /* MT9M001 has all capture_format parameters fixed */ 610 /* MT9M001 has all capture_format parameters fixed */
611 cfg->flags = V4L2_MBUS_PCLK_SAMPLE_FALLING | 611 cfg->flags = V4L2_MBUS_PCLK_SAMPLE_FALLING |
612 V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_HIGH | 612 V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_HIGH |
613 V4L2_MBUS_DATA_ACTIVE_HIGH | V4L2_MBUS_MASTER; 613 V4L2_MBUS_DATA_ACTIVE_HIGH | V4L2_MBUS_MASTER;
614 cfg->type = V4L2_MBUS_PARALLEL; 614 cfg->type = V4L2_MBUS_PARALLEL;
615 cfg->flags = soc_camera_apply_board_flags(icl, cfg); 615 cfg->flags = soc_camera_apply_board_flags(ssdd, cfg);
616 616
617 return 0; 617 return 0;
618} 618}
@@ -621,12 +621,12 @@ static int mt9m001_s_mbus_config(struct v4l2_subdev *sd,
621 const struct v4l2_mbus_config *cfg) 621 const struct v4l2_mbus_config *cfg)
622{ 622{
623 const struct i2c_client *client = v4l2_get_subdevdata(sd); 623 const struct i2c_client *client = v4l2_get_subdevdata(sd);
624 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 624 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
625 struct mt9m001 *mt9m001 = to_mt9m001(client); 625 struct mt9m001 *mt9m001 = to_mt9m001(client);
626 unsigned int bps = soc_mbus_get_fmtdesc(mt9m001->fmt->code)->bits_per_sample; 626 unsigned int bps = soc_mbus_get_fmtdesc(mt9m001->fmt->code)->bits_per_sample;
627 627
628 if (icl->set_bus_param) 628 if (ssdd->set_bus_param)
629 return icl->set_bus_param(icl, 1 << (bps - 1)); 629 return ssdd->set_bus_param(ssdd, 1 << (bps - 1));
630 630
631 /* 631 /*
632 * Without board specific bus width settings we only support the 632 * Without board specific bus width settings we only support the
@@ -663,10 +663,10 @@ static int mt9m001_probe(struct i2c_client *client,
663{ 663{
664 struct mt9m001 *mt9m001; 664 struct mt9m001 *mt9m001;
665 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 665 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
666 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 666 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
667 int ret; 667 int ret;
668 668
669 if (!icl) { 669 if (!ssdd) {
670 dev_err(&client->dev, "MT9M001 driver needs platform data\n"); 670 dev_err(&client->dev, "MT9M001 driver needs platform data\n");
671 return -EINVAL; 671 return -EINVAL;
672 } 672 }
@@ -677,7 +677,7 @@ static int mt9m001_probe(struct i2c_client *client,
677 return -EIO; 677 return -EIO;
678 } 678 }
679 679
680 mt9m001 = kzalloc(sizeof(struct mt9m001), GFP_KERNEL); 680 mt9m001 = devm_kzalloc(&client->dev, sizeof(struct mt9m001), GFP_KERNEL);
681 if (!mt9m001) 681 if (!mt9m001)
682 return -ENOMEM; 682 return -ENOMEM;
683 683
@@ -697,12 +697,9 @@ static int mt9m001_probe(struct i2c_client *client,
697 &mt9m001_ctrl_ops, V4L2_CID_EXPOSURE_AUTO, 1, 0, 697 &mt9m001_ctrl_ops, V4L2_CID_EXPOSURE_AUTO, 1, 0,
698 V4L2_EXPOSURE_AUTO); 698 V4L2_EXPOSURE_AUTO);
699 mt9m001->subdev.ctrl_handler = &mt9m001->hdl; 699 mt9m001->subdev.ctrl_handler = &mt9m001->hdl;
700 if (mt9m001->hdl.error) { 700 if (mt9m001->hdl.error)
701 int err = mt9m001->hdl.error; 701 return mt9m001->hdl.error;
702 702
703 kfree(mt9m001);
704 return err;
705 }
706 v4l2_ctrl_auto_cluster(2, &mt9m001->autoexposure, 703 v4l2_ctrl_auto_cluster(2, &mt9m001->autoexposure,
707 V4L2_EXPOSURE_MANUAL, true); 704 V4L2_EXPOSURE_MANUAL, true);
708 705
@@ -713,11 +710,9 @@ static int mt9m001_probe(struct i2c_client *client,
713 mt9m001->rect.width = MT9M001_MAX_WIDTH; 710 mt9m001->rect.width = MT9M001_MAX_WIDTH;
714 mt9m001->rect.height = MT9M001_MAX_HEIGHT; 711 mt9m001->rect.height = MT9M001_MAX_HEIGHT;
715 712
716 ret = mt9m001_video_probe(icl, client); 713 ret = mt9m001_video_probe(ssdd, client);
717 if (ret) { 714 if (ret)
718 v4l2_ctrl_handler_free(&mt9m001->hdl); 715 v4l2_ctrl_handler_free(&mt9m001->hdl);
719 kfree(mt9m001);
720 }
721 716
722 return ret; 717 return ret;
723} 718}
@@ -725,12 +720,11 @@ static int mt9m001_probe(struct i2c_client *client,
725static int mt9m001_remove(struct i2c_client *client) 720static int mt9m001_remove(struct i2c_client *client)
726{ 721{
727 struct mt9m001 *mt9m001 = to_mt9m001(client); 722 struct mt9m001 *mt9m001 = to_mt9m001(client);
728 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 723 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
729 724
730 v4l2_device_unregister_subdev(&mt9m001->subdev); 725 v4l2_device_unregister_subdev(&mt9m001->subdev);
731 v4l2_ctrl_handler_free(&mt9m001->hdl); 726 v4l2_ctrl_handler_free(&mt9m001->hdl);
732 mt9m001_video_remove(icl); 727 mt9m001_video_remove(ssdd);
733 kfree(mt9m001);
734 728
735 return 0; 729 return 0;
736} 730}
diff --git a/drivers/media/i2c/soc_camera/mt9m111.c b/drivers/media/i2c/soc_camera/mt9m111.c
index 62fd94af599b..bbc4ff99603c 100644
--- a/drivers/media/i2c/soc_camera/mt9m111.c
+++ b/drivers/media/i2c/soc_camera/mt9m111.c
@@ -24,7 +24,8 @@
24/* 24/*
25 * MT9M111, MT9M112 and MT9M131: 25 * MT9M111, MT9M112 and MT9M131:
26 * i2c address is 0x48 or 0x5d (depending on SADDR pin) 26 * i2c address is 0x48 or 0x5d (depending on SADDR pin)
27 * The platform has to define i2c_board_info and call i2c_register_board_info() 27 * The platform has to define struct i2c_board_info objects and link to them
28 * from struct soc_camera_host_desc
28 */ 29 */
29 30
30/* 31/*
@@ -799,17 +800,17 @@ static int mt9m111_init(struct mt9m111 *mt9m111)
799static int mt9m111_power_on(struct mt9m111 *mt9m111) 800static int mt9m111_power_on(struct mt9m111 *mt9m111)
800{ 801{
801 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); 802 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
802 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 803 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
803 int ret; 804 int ret;
804 805
805 ret = soc_camera_power_on(&client->dev, icl); 806 ret = soc_camera_power_on(&client->dev, ssdd);
806 if (ret < 0) 807 if (ret < 0)
807 return ret; 808 return ret;
808 809
809 ret = mt9m111_resume(mt9m111); 810 ret = mt9m111_resume(mt9m111);
810 if (ret < 0) { 811 if (ret < 0) {
811 dev_err(&client->dev, "Failed to resume the sensor: %d\n", ret); 812 dev_err(&client->dev, "Failed to resume the sensor: %d\n", ret);
812 soc_camera_power_off(&client->dev, icl); 813 soc_camera_power_off(&client->dev, ssdd);
813 } 814 }
814 815
815 return ret; 816 return ret;
@@ -818,10 +819,10 @@ static int mt9m111_power_on(struct mt9m111 *mt9m111)
818static void mt9m111_power_off(struct mt9m111 *mt9m111) 819static void mt9m111_power_off(struct mt9m111 *mt9m111)
819{ 820{
820 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); 821 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
821 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 822 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
822 823
823 mt9m111_suspend(mt9m111); 824 mt9m111_suspend(mt9m111);
824 soc_camera_power_off(&client->dev, icl); 825 soc_camera_power_off(&client->dev, ssdd);
825} 826}
826 827
827static int mt9m111_s_power(struct v4l2_subdev *sd, int on) 828static int mt9m111_s_power(struct v4l2_subdev *sd, int on)
@@ -879,13 +880,13 @@ static int mt9m111_g_mbus_config(struct v4l2_subdev *sd,
879 struct v4l2_mbus_config *cfg) 880 struct v4l2_mbus_config *cfg)
880{ 881{
881 struct i2c_client *client = v4l2_get_subdevdata(sd); 882 struct i2c_client *client = v4l2_get_subdevdata(sd);
882 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 883 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
883 884
884 cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_PCLK_SAMPLE_RISING | 885 cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_PCLK_SAMPLE_RISING |
885 V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_HIGH | 886 V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_HIGH |
886 V4L2_MBUS_DATA_ACTIVE_HIGH; 887 V4L2_MBUS_DATA_ACTIVE_HIGH;
887 cfg->type = V4L2_MBUS_PARALLEL; 888 cfg->type = V4L2_MBUS_PARALLEL;
888 cfg->flags = soc_camera_apply_board_flags(icl, cfg); 889 cfg->flags = soc_camera_apply_board_flags(ssdd, cfg);
889 890
890 return 0; 891 return 0;
891} 892}
@@ -956,10 +957,10 @@ static int mt9m111_probe(struct i2c_client *client,
956{ 957{
957 struct mt9m111 *mt9m111; 958 struct mt9m111 *mt9m111;
958 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 959 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
959 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 960 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
960 int ret; 961 int ret;
961 962
962 if (!icl) { 963 if (!ssdd) {
963 dev_err(&client->dev, "mt9m111: driver needs platform data\n"); 964 dev_err(&client->dev, "mt9m111: driver needs platform data\n");
964 return -EINVAL; 965 return -EINVAL;
965 } 966 }
@@ -970,7 +971,7 @@ static int mt9m111_probe(struct i2c_client *client,
970 return -EIO; 971 return -EIO;
971 } 972 }
972 973
973 mt9m111 = kzalloc(sizeof(struct mt9m111), GFP_KERNEL); 974 mt9m111 = devm_kzalloc(&client->dev, sizeof(struct mt9m111), GFP_KERNEL);
974 if (!mt9m111) 975 if (!mt9m111)
975 return -ENOMEM; 976 return -ENOMEM;
976 977
@@ -988,12 +989,8 @@ static int mt9m111_probe(struct i2c_client *client,
988 &mt9m111_ctrl_ops, V4L2_CID_EXPOSURE_AUTO, 1, 0, 989 &mt9m111_ctrl_ops, V4L2_CID_EXPOSURE_AUTO, 1, 0,
989 V4L2_EXPOSURE_AUTO); 990 V4L2_EXPOSURE_AUTO);
990 mt9m111->subdev.ctrl_handler = &mt9m111->hdl; 991 mt9m111->subdev.ctrl_handler = &mt9m111->hdl;
991 if (mt9m111->hdl.error) { 992 if (mt9m111->hdl.error)
992 int err = mt9m111->hdl.error; 993 return mt9m111->hdl.error;
993
994 kfree(mt9m111);
995 return err;
996 }
997 994
998 /* Second stage probe - when a capture adapter is there */ 995 /* Second stage probe - when a capture adapter is there */
999 mt9m111->rect.left = MT9M111_MIN_DARK_COLS; 996 mt9m111->rect.left = MT9M111_MIN_DARK_COLS;
@@ -1005,10 +1002,8 @@ static int mt9m111_probe(struct i2c_client *client,
1005 mutex_init(&mt9m111->power_lock); 1002 mutex_init(&mt9m111->power_lock);
1006 1003
1007 ret = mt9m111_video_probe(client); 1004 ret = mt9m111_video_probe(client);
1008 if (ret) { 1005 if (ret)
1009 v4l2_ctrl_handler_free(&mt9m111->hdl); 1006 v4l2_ctrl_handler_free(&mt9m111->hdl);
1010 kfree(mt9m111);
1011 }
1012 1007
1013 return ret; 1008 return ret;
1014} 1009}
@@ -1019,7 +1014,6 @@ static int mt9m111_remove(struct i2c_client *client)
1019 1014
1020 v4l2_device_unregister_subdev(&mt9m111->subdev); 1015 v4l2_device_unregister_subdev(&mt9m111->subdev);
1021 v4l2_ctrl_handler_free(&mt9m111->hdl); 1016 v4l2_ctrl_handler_free(&mt9m111->hdl);
1022 kfree(mt9m111);
1023 1017
1024 return 0; 1018 return 0;
1025} 1019}
diff --git a/drivers/media/i2c/soc_camera/mt9t031.c b/drivers/media/i2c/soc_camera/mt9t031.c
index 40800b10a080..d80d044ebf15 100644
--- a/drivers/media/i2c/soc_camera/mt9t031.c
+++ b/drivers/media/i2c/soc_camera/mt9t031.c
@@ -31,8 +31,8 @@
31 31
32/* 32/*
33 * mt9t031 i2c address 0x5d 33 * mt9t031 i2c address 0x5d
34 * The platform has to define i2c_board_info and link to it from 34 * The platform has to define struct i2c_board_info objects and link to them
35 * struct soc_camera_link 35 * from struct soc_camera_host_desc
36 */ 36 */
37 37
38/* mt9t031 selected register addresses */ 38/* mt9t031 selected register addresses */
@@ -608,18 +608,18 @@ static struct device_type mt9t031_dev_type = {
608static int mt9t031_s_power(struct v4l2_subdev *sd, int on) 608static int mt9t031_s_power(struct v4l2_subdev *sd, int on)
609{ 609{
610 struct i2c_client *client = v4l2_get_subdevdata(sd); 610 struct i2c_client *client = v4l2_get_subdevdata(sd);
611 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 611 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
612 struct video_device *vdev = soc_camera_i2c_to_vdev(client); 612 struct video_device *vdev = soc_camera_i2c_to_vdev(client);
613 int ret; 613 int ret;
614 614
615 if (on) { 615 if (on) {
616 ret = soc_camera_power_on(&client->dev, icl); 616 ret = soc_camera_power_on(&client->dev, ssdd);
617 if (ret < 0) 617 if (ret < 0)
618 return ret; 618 return ret;
619 vdev->dev.type = &mt9t031_dev_type; 619 vdev->dev.type = &mt9t031_dev_type;
620 } else { 620 } else {
621 vdev->dev.type = NULL; 621 vdev->dev.type = NULL;
622 soc_camera_power_off(&client->dev, icl); 622 soc_camera_power_off(&client->dev, ssdd);
623 } 623 }
624 624
625 return 0; 625 return 0;
@@ -707,13 +707,13 @@ static int mt9t031_g_mbus_config(struct v4l2_subdev *sd,
707 struct v4l2_mbus_config *cfg) 707 struct v4l2_mbus_config *cfg)
708{ 708{
709 struct i2c_client *client = v4l2_get_subdevdata(sd); 709 struct i2c_client *client = v4l2_get_subdevdata(sd);
710 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 710 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
711 711
712 cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_PCLK_SAMPLE_RISING | 712 cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_PCLK_SAMPLE_RISING |
713 V4L2_MBUS_PCLK_SAMPLE_FALLING | V4L2_MBUS_HSYNC_ACTIVE_HIGH | 713 V4L2_MBUS_PCLK_SAMPLE_FALLING | V4L2_MBUS_HSYNC_ACTIVE_HIGH |
714 V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_DATA_ACTIVE_HIGH; 714 V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_DATA_ACTIVE_HIGH;
715 cfg->type = V4L2_MBUS_PARALLEL; 715 cfg->type = V4L2_MBUS_PARALLEL;
716 cfg->flags = soc_camera_apply_board_flags(icl, cfg); 716 cfg->flags = soc_camera_apply_board_flags(ssdd, cfg);
717 717
718 return 0; 718 return 0;
719} 719}
@@ -722,9 +722,9 @@ static int mt9t031_s_mbus_config(struct v4l2_subdev *sd,
722 const struct v4l2_mbus_config *cfg) 722 const struct v4l2_mbus_config *cfg)
723{ 723{
724 struct i2c_client *client = v4l2_get_subdevdata(sd); 724 struct i2c_client *client = v4l2_get_subdevdata(sd);
725 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 725 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
726 726
727 if (soc_camera_apply_board_flags(icl, cfg) & 727 if (soc_camera_apply_board_flags(ssdd, cfg) &
728 V4L2_MBUS_PCLK_SAMPLE_FALLING) 728 V4L2_MBUS_PCLK_SAMPLE_FALLING)
729 return reg_clear(client, MT9T031_PIXEL_CLOCK_CONTROL, 0x8000); 729 return reg_clear(client, MT9T031_PIXEL_CLOCK_CONTROL, 0x8000);
730 else 730 else
@@ -758,11 +758,11 @@ static int mt9t031_probe(struct i2c_client *client,
758 const struct i2c_device_id *did) 758 const struct i2c_device_id *did)
759{ 759{
760 struct mt9t031 *mt9t031; 760 struct mt9t031 *mt9t031;
761 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 761 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
762 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 762 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
763 int ret; 763 int ret;
764 764
765 if (!icl) { 765 if (!ssdd) {
766 dev_err(&client->dev, "MT9T031 driver needs platform data\n"); 766 dev_err(&client->dev, "MT9T031 driver needs platform data\n");
767 return -EINVAL; 767 return -EINVAL;
768 } 768 }
@@ -773,7 +773,7 @@ static int mt9t031_probe(struct i2c_client *client,
773 return -EIO; 773 return -EIO;
774 } 774 }
775 775
776 mt9t031 = kzalloc(sizeof(struct mt9t031), GFP_KERNEL); 776 mt9t031 = devm_kzalloc(&client->dev, sizeof(struct mt9t031), GFP_KERNEL);
777 if (!mt9t031) 777 if (!mt9t031)
778 return -ENOMEM; 778 return -ENOMEM;
779 779
@@ -797,12 +797,9 @@ static int mt9t031_probe(struct i2c_client *client,
797 V4L2_CID_EXPOSURE, 1, 255, 1, 255); 797 V4L2_CID_EXPOSURE, 1, 255, 1, 255);
798 798
799 mt9t031->subdev.ctrl_handler = &mt9t031->hdl; 799 mt9t031->subdev.ctrl_handler = &mt9t031->hdl;
800 if (mt9t031->hdl.error) { 800 if (mt9t031->hdl.error)
801 int err = mt9t031->hdl.error; 801 return mt9t031->hdl.error;
802 802
803 kfree(mt9t031);
804 return err;
805 }
806 v4l2_ctrl_auto_cluster(2, &mt9t031->autoexposure, 803 v4l2_ctrl_auto_cluster(2, &mt9t031->autoexposure,
807 V4L2_EXPOSURE_MANUAL, true); 804 V4L2_EXPOSURE_MANUAL, true);
808 805
@@ -816,10 +813,8 @@ static int mt9t031_probe(struct i2c_client *client,
816 mt9t031->yskip = 1; 813 mt9t031->yskip = 1;
817 814
818 ret = mt9t031_video_probe(client); 815 ret = mt9t031_video_probe(client);
819 if (ret) { 816 if (ret)
820 v4l2_ctrl_handler_free(&mt9t031->hdl); 817 v4l2_ctrl_handler_free(&mt9t031->hdl);
821 kfree(mt9t031);
822 }
823 818
824 return ret; 819 return ret;
825} 820}
@@ -830,7 +825,6 @@ static int mt9t031_remove(struct i2c_client *client)
830 825
831 v4l2_device_unregister_subdev(&mt9t031->subdev); 826 v4l2_device_unregister_subdev(&mt9t031->subdev);
832 v4l2_ctrl_handler_free(&mt9t031->hdl); 827 v4l2_ctrl_handler_free(&mt9t031->hdl);
833 kfree(mt9t031);
834 828
835 return 0; 829 return 0;
836} 830}
diff --git a/drivers/media/i2c/soc_camera/mt9t112.c b/drivers/media/i2c/soc_camera/mt9t112.c
index de7cd836b0a2..188e29b03273 100644
--- a/drivers/media/i2c/soc_camera/mt9t112.c
+++ b/drivers/media/i2c/soc_camera/mt9t112.c
@@ -92,6 +92,7 @@ struct mt9t112_priv {
92 struct v4l2_rect frame; 92 struct v4l2_rect frame;
93 const struct mt9t112_format *format; 93 const struct mt9t112_format *format;
94 int model; 94 int model;
95 int num_formats;
95 u32 flags; 96 u32 flags;
96/* for flags */ 97/* for flags */
97#define INIT_DONE (1 << 0) 98#define INIT_DONE (1 << 0)
@@ -779,9 +780,9 @@ static int mt9t112_s_register(struct v4l2_subdev *sd,
779static int mt9t112_s_power(struct v4l2_subdev *sd, int on) 780static int mt9t112_s_power(struct v4l2_subdev *sd, int on)
780{ 781{
781 struct i2c_client *client = v4l2_get_subdevdata(sd); 782 struct i2c_client *client = v4l2_get_subdevdata(sd);
782 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 783 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
783 784
784 return soc_camera_set_power(&client->dev, icl, on); 785 return soc_camera_set_power(&client->dev, ssdd, on);
785} 786}
786 787
787static struct v4l2_subdev_core_ops mt9t112_subdev_core_ops = { 788static struct v4l2_subdev_core_ops mt9t112_subdev_core_ops = {
@@ -859,11 +860,11 @@ static int mt9t112_set_params(struct mt9t112_priv *priv,
859 /* 860 /*
860 * get color format 861 * get color format
861 */ 862 */
862 for (i = 0; i < ARRAY_SIZE(mt9t112_cfmts); i++) 863 for (i = 0; i < priv->num_formats; i++)
863 if (mt9t112_cfmts[i].code == code) 864 if (mt9t112_cfmts[i].code == code)
864 break; 865 break;
865 866
866 if (i == ARRAY_SIZE(mt9t112_cfmts)) 867 if (i == priv->num_formats)
867 return -EINVAL; 868 return -EINVAL;
868 869
869 priv->frame = *rect; 870 priv->frame = *rect;
@@ -955,14 +956,16 @@ static int mt9t112_s_fmt(struct v4l2_subdev *sd,
955static int mt9t112_try_fmt(struct v4l2_subdev *sd, 956static int mt9t112_try_fmt(struct v4l2_subdev *sd,
956 struct v4l2_mbus_framefmt *mf) 957 struct v4l2_mbus_framefmt *mf)
957{ 958{
959 struct i2c_client *client = v4l2_get_subdevdata(sd);
960 struct mt9t112_priv *priv = to_mt9t112(client);
958 unsigned int top, left; 961 unsigned int top, left;
959 int i; 962 int i;
960 963
961 for (i = 0; i < ARRAY_SIZE(mt9t112_cfmts); i++) 964 for (i = 0; i < priv->num_formats; i++)
962 if (mt9t112_cfmts[i].code == mf->code) 965 if (mt9t112_cfmts[i].code == mf->code)
963 break; 966 break;
964 967
965 if (i == ARRAY_SIZE(mt9t112_cfmts)) { 968 if (i == priv->num_formats) {
966 mf->code = V4L2_MBUS_FMT_UYVY8_2X8; 969 mf->code = V4L2_MBUS_FMT_UYVY8_2X8;
967 mf->colorspace = V4L2_COLORSPACE_JPEG; 970 mf->colorspace = V4L2_COLORSPACE_JPEG;
968 } else { 971 } else {
@@ -979,7 +982,10 @@ static int mt9t112_try_fmt(struct v4l2_subdev *sd,
979static int mt9t112_enum_fmt(struct v4l2_subdev *sd, unsigned int index, 982static int mt9t112_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
980 enum v4l2_mbus_pixelcode *code) 983 enum v4l2_mbus_pixelcode *code)
981{ 984{
982 if (index >= ARRAY_SIZE(mt9t112_cfmts)) 985 struct i2c_client *client = v4l2_get_subdevdata(sd);
986 struct mt9t112_priv *priv = to_mt9t112(client);
987
988 if (index >= priv->num_formats)
983 return -EINVAL; 989 return -EINVAL;
984 990
985 *code = mt9t112_cfmts[index].code; 991 *code = mt9t112_cfmts[index].code;
@@ -991,13 +997,13 @@ static int mt9t112_g_mbus_config(struct v4l2_subdev *sd,
991 struct v4l2_mbus_config *cfg) 997 struct v4l2_mbus_config *cfg)
992{ 998{
993 struct i2c_client *client = v4l2_get_subdevdata(sd); 999 struct i2c_client *client = v4l2_get_subdevdata(sd);
994 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 1000 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
995 1001
996 cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_VSYNC_ACTIVE_HIGH | 1002 cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_VSYNC_ACTIVE_HIGH |
997 V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_DATA_ACTIVE_HIGH | 1003 V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_DATA_ACTIVE_HIGH |
998 V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING; 1004 V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING;
999 cfg->type = V4L2_MBUS_PARALLEL; 1005 cfg->type = V4L2_MBUS_PARALLEL;
1000 cfg->flags = soc_camera_apply_board_flags(icl, cfg); 1006 cfg->flags = soc_camera_apply_board_flags(ssdd, cfg);
1001 1007
1002 return 0; 1008 return 0;
1003} 1009}
@@ -1006,10 +1012,10 @@ static int mt9t112_s_mbus_config(struct v4l2_subdev *sd,
1006 const struct v4l2_mbus_config *cfg) 1012 const struct v4l2_mbus_config *cfg)
1007{ 1013{
1008 struct i2c_client *client = v4l2_get_subdevdata(sd); 1014 struct i2c_client *client = v4l2_get_subdevdata(sd);
1009 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 1015 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
1010 struct mt9t112_priv *priv = to_mt9t112(client); 1016 struct mt9t112_priv *priv = to_mt9t112(client);
1011 1017
1012 if (soc_camera_apply_board_flags(icl, cfg) & V4L2_MBUS_PCLK_SAMPLE_RISING) 1018 if (soc_camera_apply_board_flags(ssdd, cfg) & V4L2_MBUS_PCLK_SAMPLE_RISING)
1013 priv->flags |= PCLK_RISING; 1019 priv->flags |= PCLK_RISING;
1014 1020
1015 return 0; 1021 return 0;
@@ -1056,10 +1062,12 @@ static int mt9t112_camera_probe(struct i2c_client *client)
1056 case 0x2680: 1062 case 0x2680:
1057 devname = "mt9t111"; 1063 devname = "mt9t111";
1058 priv->model = V4L2_IDENT_MT9T111; 1064 priv->model = V4L2_IDENT_MT9T111;
1065 priv->num_formats = 1;
1059 break; 1066 break;
1060 case 0x2682: 1067 case 0x2682:
1061 devname = "mt9t112"; 1068 devname = "mt9t112";
1062 priv->model = V4L2_IDENT_MT9T112; 1069 priv->model = V4L2_IDENT_MT9T112;
1070 priv->num_formats = ARRAY_SIZE(mt9t112_cfmts);
1063 break; 1071 break;
1064 default: 1072 default:
1065 dev_err(&client->dev, "Product ID error %04x\n", chipid); 1073 dev_err(&client->dev, "Product ID error %04x\n", chipid);
@@ -1078,7 +1086,7 @@ static int mt9t112_probe(struct i2c_client *client,
1078 const struct i2c_device_id *did) 1086 const struct i2c_device_id *did)
1079{ 1087{
1080 struct mt9t112_priv *priv; 1088 struct mt9t112_priv *priv;
1081 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 1089 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
1082 struct v4l2_rect rect = { 1090 struct v4l2_rect rect = {
1083 .width = VGA_WIDTH, 1091 .width = VGA_WIDTH,
1084 .height = VGA_HEIGHT, 1092 .height = VGA_HEIGHT,
@@ -1087,24 +1095,22 @@ static int mt9t112_probe(struct i2c_client *client,
1087 }; 1095 };
1088 int ret; 1096 int ret;
1089 1097
1090 if (!icl || !icl->priv) { 1098 if (!ssdd || !ssdd->drv_priv) {
1091 dev_err(&client->dev, "mt9t112: missing platform data!\n"); 1099 dev_err(&client->dev, "mt9t112: missing platform data!\n");
1092 return -EINVAL; 1100 return -EINVAL;
1093 } 1101 }
1094 1102
1095 priv = kzalloc(sizeof(*priv), GFP_KERNEL); 1103 priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL);
1096 if (!priv) 1104 if (!priv)
1097 return -ENOMEM; 1105 return -ENOMEM;
1098 1106
1099 priv->info = icl->priv; 1107 priv->info = ssdd->drv_priv;
1100 1108
1101 v4l2_i2c_subdev_init(&priv->subdev, client, &mt9t112_subdev_ops); 1109 v4l2_i2c_subdev_init(&priv->subdev, client, &mt9t112_subdev_ops);
1102 1110
1103 ret = mt9t112_camera_probe(client); 1111 ret = mt9t112_camera_probe(client);
1104 if (ret) { 1112 if (ret)
1105 kfree(priv);
1106 return ret; 1113 return ret;
1107 }
1108 1114
1109 /* Cannot fail: using the default supported pixel code */ 1115 /* Cannot fail: using the default supported pixel code */
1110 mt9t112_set_params(priv, &rect, V4L2_MBUS_FMT_UYVY8_2X8); 1116 mt9t112_set_params(priv, &rect, V4L2_MBUS_FMT_UYVY8_2X8);
@@ -1114,9 +1120,6 @@ static int mt9t112_probe(struct i2c_client *client,
1114 1120
1115static int mt9t112_remove(struct i2c_client *client) 1121static int mt9t112_remove(struct i2c_client *client)
1116{ 1122{
1117 struct mt9t112_priv *priv = to_mt9t112(client);
1118
1119 kfree(priv);
1120 return 0; 1123 return 0;
1121} 1124}
1122 1125
diff --git a/drivers/media/i2c/soc_camera/mt9v022.c b/drivers/media/i2c/soc_camera/mt9v022.c
index d40a8858be01..a5e65d6a0781 100644
--- a/drivers/media/i2c/soc_camera/mt9v022.c
+++ b/drivers/media/i2c/soc_camera/mt9v022.c
@@ -25,7 +25,7 @@
25/* 25/*
26 * mt9v022 i2c address 0x48, 0x4c, 0x58, 0x5c 26 * mt9v022 i2c address 0x48, 0x4c, 0x58, 0x5c
27 * The platform has to define struct i2c_board_info objects and link to them 27 * The platform has to define struct i2c_board_info objects and link to them
28 * from struct soc_camera_link 28 * from struct soc_camera_host_desc
29 */ 29 */
30 30
31static char *sensor_type; 31static char *sensor_type;
@@ -508,9 +508,9 @@ static int mt9v022_s_register(struct v4l2_subdev *sd,
508static int mt9v022_s_power(struct v4l2_subdev *sd, int on) 508static int mt9v022_s_power(struct v4l2_subdev *sd, int on)
509{ 509{
510 struct i2c_client *client = v4l2_get_subdevdata(sd); 510 struct i2c_client *client = v4l2_get_subdevdata(sd);
511 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 511 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
512 512
513 return soc_camera_set_power(&client->dev, icl, on); 513 return soc_camera_set_power(&client->dev, ssdd, on);
514} 514}
515 515
516static int mt9v022_g_volatile_ctrl(struct v4l2_ctrl *ctrl) 516static int mt9v022_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
@@ -655,7 +655,7 @@ static int mt9v022_s_ctrl(struct v4l2_ctrl *ctrl)
655static int mt9v022_video_probe(struct i2c_client *client) 655static int mt9v022_video_probe(struct i2c_client *client)
656{ 656{
657 struct mt9v022 *mt9v022 = to_mt9v022(client); 657 struct mt9v022 *mt9v022 = to_mt9v022(client);
658 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 658 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
659 s32 data; 659 s32 data;
660 int ret; 660 int ret;
661 unsigned long flags; 661 unsigned long flags;
@@ -715,8 +715,8 @@ static int mt9v022_video_probe(struct i2c_client *client)
715 * The platform may support different bus widths due to 715 * The platform may support different bus widths due to
716 * different routing of the data lines. 716 * different routing of the data lines.
717 */ 717 */
718 if (icl->query_bus_param) 718 if (ssdd->query_bus_param)
719 flags = icl->query_bus_param(icl); 719 flags = ssdd->query_bus_param(ssdd);
720 else 720 else
721 flags = SOCAM_DATAWIDTH_10; 721 flags = SOCAM_DATAWIDTH_10;
722 722
@@ -784,7 +784,7 @@ static int mt9v022_g_mbus_config(struct v4l2_subdev *sd,
784 struct v4l2_mbus_config *cfg) 784 struct v4l2_mbus_config *cfg)
785{ 785{
786 struct i2c_client *client = v4l2_get_subdevdata(sd); 786 struct i2c_client *client = v4l2_get_subdevdata(sd);
787 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 787 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
788 788
789 cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_SLAVE | 789 cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_SLAVE |
790 V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING | 790 V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING |
@@ -792,7 +792,7 @@ static int mt9v022_g_mbus_config(struct v4l2_subdev *sd,
792 V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_LOW | 792 V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_LOW |
793 V4L2_MBUS_DATA_ACTIVE_HIGH; 793 V4L2_MBUS_DATA_ACTIVE_HIGH;
794 cfg->type = V4L2_MBUS_PARALLEL; 794 cfg->type = V4L2_MBUS_PARALLEL;
795 cfg->flags = soc_camera_apply_board_flags(icl, cfg); 795 cfg->flags = soc_camera_apply_board_flags(ssdd, cfg);
796 796
797 return 0; 797 return 0;
798} 798}
@@ -801,15 +801,15 @@ static int mt9v022_s_mbus_config(struct v4l2_subdev *sd,
801 const struct v4l2_mbus_config *cfg) 801 const struct v4l2_mbus_config *cfg)
802{ 802{
803 struct i2c_client *client = v4l2_get_subdevdata(sd); 803 struct i2c_client *client = v4l2_get_subdevdata(sd);
804 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 804 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
805 struct mt9v022 *mt9v022 = to_mt9v022(client); 805 struct mt9v022 *mt9v022 = to_mt9v022(client);
806 unsigned long flags = soc_camera_apply_board_flags(icl, cfg); 806 unsigned long flags = soc_camera_apply_board_flags(ssdd, cfg);
807 unsigned int bps = soc_mbus_get_fmtdesc(mt9v022->fmt->code)->bits_per_sample; 807 unsigned int bps = soc_mbus_get_fmtdesc(mt9v022->fmt->code)->bits_per_sample;
808 int ret; 808 int ret;
809 u16 pixclk = 0; 809 u16 pixclk = 0;
810 810
811 if (icl->set_bus_param) { 811 if (ssdd->set_bus_param) {
812 ret = icl->set_bus_param(icl, 1 << (bps - 1)); 812 ret = ssdd->set_bus_param(ssdd, 1 << (bps - 1));
813 if (ret) 813 if (ret)
814 return ret; 814 return ret;
815 } else if (bps != 10) { 815 } else if (bps != 10) {
@@ -873,12 +873,12 @@ static int mt9v022_probe(struct i2c_client *client,
873 const struct i2c_device_id *did) 873 const struct i2c_device_id *did)
874{ 874{
875 struct mt9v022 *mt9v022; 875 struct mt9v022 *mt9v022;
876 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 876 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
877 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 877 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
878 struct mt9v022_platform_data *pdata = icl->priv; 878 struct mt9v022_platform_data *pdata;
879 int ret; 879 int ret;
880 880
881 if (!icl) { 881 if (!ssdd) {
882 dev_err(&client->dev, "MT9V022 driver needs platform data\n"); 882 dev_err(&client->dev, "MT9V022 driver needs platform data\n");
883 return -EINVAL; 883 return -EINVAL;
884 } 884 }
@@ -889,10 +889,11 @@ static int mt9v022_probe(struct i2c_client *client,
889 return -EIO; 889 return -EIO;
890 } 890 }
891 891
892 mt9v022 = kzalloc(sizeof(struct mt9v022), GFP_KERNEL); 892 mt9v022 = devm_kzalloc(&client->dev, sizeof(struct mt9v022), GFP_KERNEL);
893 if (!mt9v022) 893 if (!mt9v022)
894 return -ENOMEM; 894 return -ENOMEM;
895 895
896 pdata = ssdd->drv_priv;
896 v4l2_i2c_subdev_init(&mt9v022->subdev, client, &mt9v022_subdev_ops); 897 v4l2_i2c_subdev_init(&mt9v022->subdev, client, &mt9v022_subdev_ops);
897 v4l2_ctrl_handler_init(&mt9v022->hdl, 6); 898 v4l2_ctrl_handler_init(&mt9v022->hdl, 6);
898 v4l2_ctrl_new_std(&mt9v022->hdl, &mt9v022_ctrl_ops, 899 v4l2_ctrl_new_std(&mt9v022->hdl, &mt9v022_ctrl_ops,
@@ -929,7 +930,6 @@ static int mt9v022_probe(struct i2c_client *client,
929 int err = mt9v022->hdl.error; 930 int err = mt9v022->hdl.error;
930 931
931 dev_err(&client->dev, "control initialisation err %d\n", err); 932 dev_err(&client->dev, "control initialisation err %d\n", err);
932 kfree(mt9v022);
933 return err; 933 return err;
934 } 934 }
935 v4l2_ctrl_auto_cluster(2, &mt9v022->autoexposure, 935 v4l2_ctrl_auto_cluster(2, &mt9v022->autoexposure,
@@ -949,10 +949,8 @@ static int mt9v022_probe(struct i2c_client *client,
949 mt9v022->rect.height = MT9V022_MAX_HEIGHT; 949 mt9v022->rect.height = MT9V022_MAX_HEIGHT;
950 950
951 ret = mt9v022_video_probe(client); 951 ret = mt9v022_video_probe(client);
952 if (ret) { 952 if (ret)
953 v4l2_ctrl_handler_free(&mt9v022->hdl); 953 v4l2_ctrl_handler_free(&mt9v022->hdl);
954 kfree(mt9v022);
955 }
956 954
957 return ret; 955 return ret;
958} 956}
@@ -960,13 +958,12 @@ static int mt9v022_probe(struct i2c_client *client,
960static int mt9v022_remove(struct i2c_client *client) 958static int mt9v022_remove(struct i2c_client *client)
961{ 959{
962 struct mt9v022 *mt9v022 = to_mt9v022(client); 960 struct mt9v022 *mt9v022 = to_mt9v022(client);
963 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 961 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
964 962
965 v4l2_device_unregister_subdev(&mt9v022->subdev); 963 v4l2_device_unregister_subdev(&mt9v022->subdev);
966 if (icl->free_bus) 964 if (ssdd->free_bus)
967 icl->free_bus(icl); 965 ssdd->free_bus(ssdd);
968 v4l2_ctrl_handler_free(&mt9v022->hdl); 966 v4l2_ctrl_handler_free(&mt9v022->hdl);
969 kfree(mt9v022);
970 967
971 return 0; 968 return 0;
972} 969}
diff --git a/drivers/media/i2c/soc_camera/ov2640.c b/drivers/media/i2c/soc_camera/ov2640.c
index 66698a83bda2..0f520f693b6e 100644
--- a/drivers/media/i2c/soc_camera/ov2640.c
+++ b/drivers/media/i2c/soc_camera/ov2640.c
@@ -771,9 +771,9 @@ static int ov2640_s_register(struct v4l2_subdev *sd,
771static int ov2640_s_power(struct v4l2_subdev *sd, int on) 771static int ov2640_s_power(struct v4l2_subdev *sd, int on)
772{ 772{
773 struct i2c_client *client = v4l2_get_subdevdata(sd); 773 struct i2c_client *client = v4l2_get_subdevdata(sd);
774 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 774 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
775 775
776 return soc_camera_set_power(&client->dev, icl, on); 776 return soc_camera_set_power(&client->dev, ssdd, on);
777} 777}
778 778
779/* Select the nearest higher resolution for capture */ 779/* Select the nearest higher resolution for capture */
@@ -1046,13 +1046,13 @@ static int ov2640_g_mbus_config(struct v4l2_subdev *sd,
1046 struct v4l2_mbus_config *cfg) 1046 struct v4l2_mbus_config *cfg)
1047{ 1047{
1048 struct i2c_client *client = v4l2_get_subdevdata(sd); 1048 struct i2c_client *client = v4l2_get_subdevdata(sd);
1049 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 1049 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
1050 1050
1051 cfg->flags = V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_MASTER | 1051 cfg->flags = V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_MASTER |
1052 V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_HIGH | 1052 V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_HIGH |
1053 V4L2_MBUS_DATA_ACTIVE_HIGH; 1053 V4L2_MBUS_DATA_ACTIVE_HIGH;
1054 cfg->type = V4L2_MBUS_PARALLEL; 1054 cfg->type = V4L2_MBUS_PARALLEL;
1055 cfg->flags = soc_camera_apply_board_flags(icl, cfg); 1055 cfg->flags = soc_camera_apply_board_flags(ssdd, cfg);
1056 1056
1057 return 0; 1057 return 0;
1058} 1058}
@@ -1080,11 +1080,11 @@ static int ov2640_probe(struct i2c_client *client,
1080 const struct i2c_device_id *did) 1080 const struct i2c_device_id *did)
1081{ 1081{
1082 struct ov2640_priv *priv; 1082 struct ov2640_priv *priv;
1083 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 1083 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
1084 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 1084 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
1085 int ret; 1085 int ret;
1086 1086
1087 if (!icl) { 1087 if (!ssdd) {
1088 dev_err(&adapter->dev, 1088 dev_err(&adapter->dev,
1089 "OV2640: Missing platform_data for driver\n"); 1089 "OV2640: Missing platform_data for driver\n");
1090 return -EINVAL; 1090 return -EINVAL;
@@ -1096,7 +1096,7 @@ static int ov2640_probe(struct i2c_client *client,
1096 return -EIO; 1096 return -EIO;
1097 } 1097 }
1098 1098
1099 priv = kzalloc(sizeof(struct ov2640_priv), GFP_KERNEL); 1099 priv = devm_kzalloc(&client->dev, sizeof(struct ov2640_priv), GFP_KERNEL);
1100 if (!priv) { 1100 if (!priv) {
1101 dev_err(&adapter->dev, 1101 dev_err(&adapter->dev,
1102 "Failed to allocate memory for private data!\n"); 1102 "Failed to allocate memory for private data!\n");
@@ -1110,20 +1110,14 @@ static int ov2640_probe(struct i2c_client *client,
1110 v4l2_ctrl_new_std(&priv->hdl, &ov2640_ctrl_ops, 1110 v4l2_ctrl_new_std(&priv->hdl, &ov2640_ctrl_ops,
1111 V4L2_CID_HFLIP, 0, 1, 1, 0); 1111 V4L2_CID_HFLIP, 0, 1, 1, 0);
1112 priv->subdev.ctrl_handler = &priv->hdl; 1112 priv->subdev.ctrl_handler = &priv->hdl;
1113 if (priv->hdl.error) { 1113 if (priv->hdl.error)
1114 int err = priv->hdl.error; 1114 return priv->hdl.error;
1115
1116 kfree(priv);
1117 return err;
1118 }
1119 1115
1120 ret = ov2640_video_probe(client); 1116 ret = ov2640_video_probe(client);
1121 if (ret) { 1117 if (ret)
1122 v4l2_ctrl_handler_free(&priv->hdl); 1118 v4l2_ctrl_handler_free(&priv->hdl);
1123 kfree(priv); 1119 else
1124 } else {
1125 dev_info(&adapter->dev, "OV2640 Probed\n"); 1120 dev_info(&adapter->dev, "OV2640 Probed\n");
1126 }
1127 1121
1128 return ret; 1122 return ret;
1129} 1123}
@@ -1134,7 +1128,6 @@ static int ov2640_remove(struct i2c_client *client)
1134 1128
1135 v4l2_device_unregister_subdev(&priv->subdev); 1129 v4l2_device_unregister_subdev(&priv->subdev);
1136 v4l2_ctrl_handler_free(&priv->hdl); 1130 v4l2_ctrl_handler_free(&priv->hdl);
1137 kfree(priv);
1138 return 0; 1131 return 0;
1139} 1132}
1140 1133
diff --git a/drivers/media/i2c/soc_camera/ov5642.c b/drivers/media/i2c/soc_camera/ov5642.c
index 8577e0cfb7fe..9d53309619d2 100644
--- a/drivers/media/i2c/soc_camera/ov5642.c
+++ b/drivers/media/i2c/soc_camera/ov5642.c
@@ -934,13 +934,13 @@ static int ov5642_g_mbus_config(struct v4l2_subdev *sd,
934static int ov5642_s_power(struct v4l2_subdev *sd, int on) 934static int ov5642_s_power(struct v4l2_subdev *sd, int on)
935{ 935{
936 struct i2c_client *client = v4l2_get_subdevdata(sd); 936 struct i2c_client *client = v4l2_get_subdevdata(sd);
937 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 937 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
938 int ret; 938 int ret;
939 939
940 if (!on) 940 if (!on)
941 return soc_camera_power_off(&client->dev, icl); 941 return soc_camera_power_off(&client->dev, ssdd);
942 942
943 ret = soc_camera_power_on(&client->dev, icl); 943 ret = soc_camera_power_on(&client->dev, ssdd);
944 if (ret < 0) 944 if (ret < 0)
945 return ret; 945 return ret;
946 946
@@ -1020,15 +1020,14 @@ static int ov5642_probe(struct i2c_client *client,
1020 const struct i2c_device_id *did) 1020 const struct i2c_device_id *did)
1021{ 1021{
1022 struct ov5642 *priv; 1022 struct ov5642 *priv;
1023 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 1023 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
1024 int ret;
1025 1024
1026 if (!icl) { 1025 if (!ssdd) {
1027 dev_err(&client->dev, "OV5642: missing platform data!\n"); 1026 dev_err(&client->dev, "OV5642: missing platform data!\n");
1028 return -EINVAL; 1027 return -EINVAL;
1029 } 1028 }
1030 1029
1031 priv = kzalloc(sizeof(struct ov5642), GFP_KERNEL); 1030 priv = devm_kzalloc(&client->dev, sizeof(struct ov5642), GFP_KERNEL);
1032 if (!priv) 1031 if (!priv)
1033 return -ENOMEM; 1032 return -ENOMEM;
1034 1033
@@ -1043,25 +1042,15 @@ static int ov5642_probe(struct i2c_client *client,
1043 priv->total_width = OV5642_DEFAULT_WIDTH + BLANKING_EXTRA_WIDTH; 1042 priv->total_width = OV5642_DEFAULT_WIDTH + BLANKING_EXTRA_WIDTH;
1044 priv->total_height = BLANKING_MIN_HEIGHT; 1043 priv->total_height = BLANKING_MIN_HEIGHT;
1045 1044
1046 ret = ov5642_video_probe(client); 1045 return ov5642_video_probe(client);
1047 if (ret < 0)
1048 goto error;
1049
1050 return 0;
1051
1052error:
1053 kfree(priv);
1054 return ret;
1055} 1046}
1056 1047
1057static int ov5642_remove(struct i2c_client *client) 1048static int ov5642_remove(struct i2c_client *client)
1058{ 1049{
1059 struct ov5642 *priv = to_ov5642(client); 1050 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
1060 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
1061 1051
1062 if (icl->free_bus) 1052 if (ssdd->free_bus)
1063 icl->free_bus(icl); 1053 ssdd->free_bus(ssdd);
1064 kfree(priv);
1065 1054
1066 return 0; 1055 return 0;
1067} 1056}
diff --git a/drivers/media/i2c/soc_camera/ov6650.c b/drivers/media/i2c/soc_camera/ov6650.c
index e87feb0881e3..dbe4f564e6b2 100644
--- a/drivers/media/i2c/soc_camera/ov6650.c
+++ b/drivers/media/i2c/soc_camera/ov6650.c
@@ -435,9 +435,9 @@ static int ov6650_set_register(struct v4l2_subdev *sd,
435static int ov6650_s_power(struct v4l2_subdev *sd, int on) 435static int ov6650_s_power(struct v4l2_subdev *sd, int on)
436{ 436{
437 struct i2c_client *client = v4l2_get_subdevdata(sd); 437 struct i2c_client *client = v4l2_get_subdevdata(sd);
438 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 438 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
439 439
440 return soc_camera_set_power(&client->dev, icl, on); 440 return soc_camera_set_power(&client->dev, ssdd, on);
441} 441}
442 442
443static int ov6650_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a) 443static int ov6650_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
@@ -892,7 +892,7 @@ static int ov6650_g_mbus_config(struct v4l2_subdev *sd,
892 struct v4l2_mbus_config *cfg) 892 struct v4l2_mbus_config *cfg)
893{ 893{
894 struct i2c_client *client = v4l2_get_subdevdata(sd); 894 struct i2c_client *client = v4l2_get_subdevdata(sd);
895 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 895 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
896 896
897 cfg->flags = V4L2_MBUS_MASTER | 897 cfg->flags = V4L2_MBUS_MASTER |
898 V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING | 898 V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING |
@@ -900,7 +900,7 @@ static int ov6650_g_mbus_config(struct v4l2_subdev *sd,
900 V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_LOW | 900 V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_LOW |
901 V4L2_MBUS_DATA_ACTIVE_HIGH; 901 V4L2_MBUS_DATA_ACTIVE_HIGH;
902 cfg->type = V4L2_MBUS_PARALLEL; 902 cfg->type = V4L2_MBUS_PARALLEL;
903 cfg->flags = soc_camera_apply_board_flags(icl, cfg); 903 cfg->flags = soc_camera_apply_board_flags(ssdd, cfg);
904 904
905 return 0; 905 return 0;
906} 906}
@@ -910,8 +910,8 @@ static int ov6650_s_mbus_config(struct v4l2_subdev *sd,
910 const struct v4l2_mbus_config *cfg) 910 const struct v4l2_mbus_config *cfg)
911{ 911{
912 struct i2c_client *client = v4l2_get_subdevdata(sd); 912 struct i2c_client *client = v4l2_get_subdevdata(sd);
913 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 913 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
914 unsigned long flags = soc_camera_apply_board_flags(icl, cfg); 914 unsigned long flags = soc_camera_apply_board_flags(ssdd, cfg);
915 int ret; 915 int ret;
916 916
917 if (flags & V4L2_MBUS_PCLK_SAMPLE_RISING) 917 if (flags & V4L2_MBUS_PCLK_SAMPLE_RISING)
@@ -963,15 +963,15 @@ static int ov6650_probe(struct i2c_client *client,
963 const struct i2c_device_id *did) 963 const struct i2c_device_id *did)
964{ 964{
965 struct ov6650 *priv; 965 struct ov6650 *priv;
966 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 966 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
967 int ret; 967 int ret;
968 968
969 if (!icl) { 969 if (!ssdd) {
970 dev_err(&client->dev, "Missing platform_data for driver\n"); 970 dev_err(&client->dev, "Missing platform_data for driver\n");
971 return -EINVAL; 971 return -EINVAL;
972 } 972 }
973 973
974 priv = kzalloc(sizeof(*priv), GFP_KERNEL); 974 priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL);
975 if (!priv) { 975 if (!priv) {
976 dev_err(&client->dev, 976 dev_err(&client->dev,
977 "Failed to allocate memory for private data!\n"); 977 "Failed to allocate memory for private data!\n");
@@ -1009,12 +1009,9 @@ static int ov6650_probe(struct i2c_client *client,
1009 V4L2_CID_GAMMA, 0, 0xff, 1, 0x12); 1009 V4L2_CID_GAMMA, 0, 0xff, 1, 0x12);
1010 1010
1011 priv->subdev.ctrl_handler = &priv->hdl; 1011 priv->subdev.ctrl_handler = &priv->hdl;
1012 if (priv->hdl.error) { 1012 if (priv->hdl.error)
1013 int err = priv->hdl.error; 1013 return priv->hdl.error;
1014 1014
1015 kfree(priv);
1016 return err;
1017 }
1018 v4l2_ctrl_auto_cluster(2, &priv->autogain, 0, true); 1015 v4l2_ctrl_auto_cluster(2, &priv->autogain, 0, true);
1019 v4l2_ctrl_auto_cluster(3, &priv->autowb, 0, true); 1016 v4l2_ctrl_auto_cluster(3, &priv->autowb, 0, true);
1020 v4l2_ctrl_auto_cluster(2, &priv->autoexposure, 1017 v4l2_ctrl_auto_cluster(2, &priv->autoexposure,
@@ -1029,10 +1026,8 @@ static int ov6650_probe(struct i2c_client *client,
1029 priv->colorspace = V4L2_COLORSPACE_JPEG; 1026 priv->colorspace = V4L2_COLORSPACE_JPEG;
1030 1027
1031 ret = ov6650_video_probe(client); 1028 ret = ov6650_video_probe(client);
1032 if (ret) { 1029 if (ret)
1033 v4l2_ctrl_handler_free(&priv->hdl); 1030 v4l2_ctrl_handler_free(&priv->hdl);
1034 kfree(priv);
1035 }
1036 1031
1037 return ret; 1032 return ret;
1038} 1033}
@@ -1043,7 +1038,6 @@ static int ov6650_remove(struct i2c_client *client)
1043 1038
1044 v4l2_device_unregister_subdev(&priv->subdev); 1039 v4l2_device_unregister_subdev(&priv->subdev);
1045 v4l2_ctrl_handler_free(&priv->hdl); 1040 v4l2_ctrl_handler_free(&priv->hdl);
1046 kfree(priv);
1047 return 0; 1041 return 0;
1048} 1042}
1049 1043
diff --git a/drivers/media/i2c/soc_camera/ov772x.c b/drivers/media/i2c/soc_camera/ov772x.c
index e4a10751894d..fbeb5b2f3ae5 100644
--- a/drivers/media/i2c/soc_camera/ov772x.c
+++ b/drivers/media/i2c/soc_camera/ov772x.c
@@ -667,9 +667,9 @@ static int ov772x_s_register(struct v4l2_subdev *sd,
667static int ov772x_s_power(struct v4l2_subdev *sd, int on) 667static int ov772x_s_power(struct v4l2_subdev *sd, int on)
668{ 668{
669 struct i2c_client *client = v4l2_get_subdevdata(sd); 669 struct i2c_client *client = v4l2_get_subdevdata(sd);
670 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 670 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
671 671
672 return soc_camera_set_power(&client->dev, icl, on); 672 return soc_camera_set_power(&client->dev, ssdd, on);
673} 673}
674 674
675static const struct ov772x_win_size *ov772x_select_win(u32 width, u32 height) 675static const struct ov772x_win_size *ov772x_select_win(u32 width, u32 height)
@@ -1019,13 +1019,13 @@ static int ov772x_g_mbus_config(struct v4l2_subdev *sd,
1019 struct v4l2_mbus_config *cfg) 1019 struct v4l2_mbus_config *cfg)
1020{ 1020{
1021 struct i2c_client *client = v4l2_get_subdevdata(sd); 1021 struct i2c_client *client = v4l2_get_subdevdata(sd);
1022 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 1022 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
1023 1023
1024 cfg->flags = V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_MASTER | 1024 cfg->flags = V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_MASTER |
1025 V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_HIGH | 1025 V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_HIGH |
1026 V4L2_MBUS_DATA_ACTIVE_HIGH; 1026 V4L2_MBUS_DATA_ACTIVE_HIGH;
1027 cfg->type = V4L2_MBUS_PARALLEL; 1027 cfg->type = V4L2_MBUS_PARALLEL;
1028 cfg->flags = soc_camera_apply_board_flags(icl, cfg); 1028 cfg->flags = soc_camera_apply_board_flags(ssdd, cfg);
1029 1029
1030 return 0; 1030 return 0;
1031} 1031}
@@ -1054,11 +1054,11 @@ static int ov772x_probe(struct i2c_client *client,
1054 const struct i2c_device_id *did) 1054 const struct i2c_device_id *did)
1055{ 1055{
1056 struct ov772x_priv *priv; 1056 struct ov772x_priv *priv;
1057 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 1057 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
1058 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 1058 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
1059 int ret; 1059 int ret;
1060 1060
1061 if (!icl || !icl->priv) { 1061 if (!ssdd || !ssdd->drv_priv) {
1062 dev_err(&client->dev, "OV772X: missing platform data!\n"); 1062 dev_err(&client->dev, "OV772X: missing platform data!\n");
1063 return -EINVAL; 1063 return -EINVAL;
1064 } 1064 }
@@ -1070,11 +1070,11 @@ static int ov772x_probe(struct i2c_client *client,
1070 return -EIO; 1070 return -EIO;
1071 } 1071 }
1072 1072
1073 priv = kzalloc(sizeof(*priv), GFP_KERNEL); 1073 priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL);
1074 if (!priv) 1074 if (!priv)
1075 return -ENOMEM; 1075 return -ENOMEM;
1076 1076
1077 priv->info = icl->priv; 1077 priv->info = ssdd->drv_priv;
1078 1078
1079 v4l2_i2c_subdev_init(&priv->subdev, client, &ov772x_subdev_ops); 1079 v4l2_i2c_subdev_init(&priv->subdev, client, &ov772x_subdev_ops);
1080 v4l2_ctrl_handler_init(&priv->hdl, 3); 1080 v4l2_ctrl_handler_init(&priv->hdl, 3);
@@ -1085,22 +1085,15 @@ static int ov772x_probe(struct i2c_client *client,
1085 v4l2_ctrl_new_std(&priv->hdl, &ov772x_ctrl_ops, 1085 v4l2_ctrl_new_std(&priv->hdl, &ov772x_ctrl_ops,
1086 V4L2_CID_BAND_STOP_FILTER, 0, 256, 1, 0); 1086 V4L2_CID_BAND_STOP_FILTER, 0, 256, 1, 0);
1087 priv->subdev.ctrl_handler = &priv->hdl; 1087 priv->subdev.ctrl_handler = &priv->hdl;
1088 if (priv->hdl.error) { 1088 if (priv->hdl.error)
1089 ret = priv->hdl.error; 1089 return priv->hdl.error;
1090 goto done;
1091 }
1092 1090
1093 ret = ov772x_video_probe(priv); 1091 ret = ov772x_video_probe(priv);
1094 if (ret < 0) 1092 if (ret < 0) {
1095 goto done;
1096
1097 priv->cfmt = &ov772x_cfmts[0];
1098 priv->win = &ov772x_win_sizes[0];
1099
1100done:
1101 if (ret) {
1102 v4l2_ctrl_handler_free(&priv->hdl); 1093 v4l2_ctrl_handler_free(&priv->hdl);
1103 kfree(priv); 1094 } else {
1095 priv->cfmt = &ov772x_cfmts[0];
1096 priv->win = &ov772x_win_sizes[0];
1104 } 1097 }
1105 return ret; 1098 return ret;
1106} 1099}
@@ -1111,7 +1104,6 @@ static int ov772x_remove(struct i2c_client *client)
1111 1104
1112 v4l2_device_unregister_subdev(&priv->subdev); 1105 v4l2_device_unregister_subdev(&priv->subdev);
1113 v4l2_ctrl_handler_free(&priv->hdl); 1106 v4l2_ctrl_handler_free(&priv->hdl);
1114 kfree(priv);
1115 return 0; 1107 return 0;
1116} 1108}
1117 1109
diff --git a/drivers/media/i2c/soc_camera/ov9640.c b/drivers/media/i2c/soc_camera/ov9640.c
index b323684eaf77..05993041be31 100644
--- a/drivers/media/i2c/soc_camera/ov9640.c
+++ b/drivers/media/i2c/soc_camera/ov9640.c
@@ -336,9 +336,9 @@ static int ov9640_set_register(struct v4l2_subdev *sd,
336static int ov9640_s_power(struct v4l2_subdev *sd, int on) 336static int ov9640_s_power(struct v4l2_subdev *sd, int on)
337{ 337{
338 struct i2c_client *client = v4l2_get_subdevdata(sd); 338 struct i2c_client *client = v4l2_get_subdevdata(sd);
339 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 339 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
340 340
341 return soc_camera_set_power(&client->dev, icl, on); 341 return soc_camera_set_power(&client->dev, ssdd, on);
342} 342}
343 343
344/* select nearest higher resolution for capture */ 344/* select nearest higher resolution for capture */
@@ -657,13 +657,13 @@ static int ov9640_g_mbus_config(struct v4l2_subdev *sd,
657 struct v4l2_mbus_config *cfg) 657 struct v4l2_mbus_config *cfg)
658{ 658{
659 struct i2c_client *client = v4l2_get_subdevdata(sd); 659 struct i2c_client *client = v4l2_get_subdevdata(sd);
660 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 660 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
661 661
662 cfg->flags = V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_MASTER | 662 cfg->flags = V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_MASTER |
663 V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_HIGH | 663 V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_HIGH |
664 V4L2_MBUS_DATA_ACTIVE_HIGH; 664 V4L2_MBUS_DATA_ACTIVE_HIGH;
665 cfg->type = V4L2_MBUS_PARALLEL; 665 cfg->type = V4L2_MBUS_PARALLEL;
666 cfg->flags = soc_camera_apply_board_flags(icl, cfg); 666 cfg->flags = soc_camera_apply_board_flags(ssdd, cfg);
667 667
668 return 0; 668 return 0;
669} 669}
@@ -690,15 +690,15 @@ static int ov9640_probe(struct i2c_client *client,
690 const struct i2c_device_id *did) 690 const struct i2c_device_id *did)
691{ 691{
692 struct ov9640_priv *priv; 692 struct ov9640_priv *priv;
693 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 693 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
694 int ret; 694 int ret;
695 695
696 if (!icl) { 696 if (!ssdd) {
697 dev_err(&client->dev, "Missing platform_data for driver\n"); 697 dev_err(&client->dev, "Missing platform_data for driver\n");
698 return -EINVAL; 698 return -EINVAL;
699 } 699 }
700 700
701 priv = kzalloc(sizeof(struct ov9640_priv), GFP_KERNEL); 701 priv = devm_kzalloc(&client->dev, sizeof(struct ov9640_priv), GFP_KERNEL);
702 if (!priv) { 702 if (!priv) {
703 dev_err(&client->dev, 703 dev_err(&client->dev,
704 "Failed to allocate memory for private data!\n"); 704 "Failed to allocate memory for private data!\n");
@@ -713,19 +713,13 @@ static int ov9640_probe(struct i2c_client *client,
713 v4l2_ctrl_new_std(&priv->hdl, &ov9640_ctrl_ops, 713 v4l2_ctrl_new_std(&priv->hdl, &ov9640_ctrl_ops,
714 V4L2_CID_HFLIP, 0, 1, 1, 0); 714 V4L2_CID_HFLIP, 0, 1, 1, 0);
715 priv->subdev.ctrl_handler = &priv->hdl; 715 priv->subdev.ctrl_handler = &priv->hdl;
716 if (priv->hdl.error) { 716 if (priv->hdl.error)
717 int err = priv->hdl.error; 717 return priv->hdl.error;
718
719 kfree(priv);
720 return err;
721 }
722 718
723 ret = ov9640_video_probe(client); 719 ret = ov9640_video_probe(client);
724 720
725 if (ret) { 721 if (ret)
726 v4l2_ctrl_handler_free(&priv->hdl); 722 v4l2_ctrl_handler_free(&priv->hdl);
727 kfree(priv);
728 }
729 723
730 return ret; 724 return ret;
731} 725}
@@ -737,7 +731,6 @@ static int ov9640_remove(struct i2c_client *client)
737 731
738 v4l2_device_unregister_subdev(&priv->subdev); 732 v4l2_device_unregister_subdev(&priv->subdev);
739 v4l2_ctrl_handler_free(&priv->hdl); 733 v4l2_ctrl_handler_free(&priv->hdl);
740 kfree(priv);
741 return 0; 734 return 0;
742} 735}
743 736
diff --git a/drivers/media/i2c/soc_camera/ov9740.c b/drivers/media/i2c/soc_camera/ov9740.c
index 7a55889e397b..2f236da80165 100644
--- a/drivers/media/i2c/soc_camera/ov9740.c
+++ b/drivers/media/i2c/soc_camera/ov9740.c
@@ -787,12 +787,12 @@ static int ov9740_g_chip_ident(struct v4l2_subdev *sd,
787static int ov9740_s_power(struct v4l2_subdev *sd, int on) 787static int ov9740_s_power(struct v4l2_subdev *sd, int on)
788{ 788{
789 struct i2c_client *client = v4l2_get_subdevdata(sd); 789 struct i2c_client *client = v4l2_get_subdevdata(sd);
790 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 790 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
791 struct ov9740_priv *priv = to_ov9740(sd); 791 struct ov9740_priv *priv = to_ov9740(sd);
792 int ret; 792 int ret;
793 793
794 if (on) { 794 if (on) {
795 ret = soc_camera_power_on(&client->dev, icl); 795 ret = soc_camera_power_on(&client->dev, ssdd);
796 if (ret < 0) 796 if (ret < 0)
797 return ret; 797 return ret;
798 798
@@ -806,7 +806,7 @@ static int ov9740_s_power(struct v4l2_subdev *sd, int on)
806 priv->current_enable = true; 806 priv->current_enable = true;
807 } 807 }
808 808
809 soc_camera_power_off(&client->dev, icl); 809 soc_camera_power_off(&client->dev, ssdd);
810 } 810 }
811 811
812 return 0; 812 return 0;
@@ -905,13 +905,13 @@ static int ov9740_g_mbus_config(struct v4l2_subdev *sd,
905 struct v4l2_mbus_config *cfg) 905 struct v4l2_mbus_config *cfg)
906{ 906{
907 struct i2c_client *client = v4l2_get_subdevdata(sd); 907 struct i2c_client *client = v4l2_get_subdevdata(sd);
908 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 908 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
909 909
910 cfg->flags = V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_MASTER | 910 cfg->flags = V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_MASTER |
911 V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_HIGH | 911 V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_HIGH |
912 V4L2_MBUS_DATA_ACTIVE_HIGH; 912 V4L2_MBUS_DATA_ACTIVE_HIGH;
913 cfg->type = V4L2_MBUS_PARALLEL; 913 cfg->type = V4L2_MBUS_PARALLEL;
914 cfg->flags = soc_camera_apply_board_flags(icl, cfg); 914 cfg->flags = soc_camera_apply_board_flags(ssdd, cfg);
915 915
916 return 0; 916 return 0;
917} 917}
@@ -951,15 +951,15 @@ static int ov9740_probe(struct i2c_client *client,
951 const struct i2c_device_id *did) 951 const struct i2c_device_id *did)
952{ 952{
953 struct ov9740_priv *priv; 953 struct ov9740_priv *priv;
954 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 954 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
955 int ret; 955 int ret;
956 956
957 if (!icl) { 957 if (!ssdd) {
958 dev_err(&client->dev, "Missing platform_data for driver\n"); 958 dev_err(&client->dev, "Missing platform_data for driver\n");
959 return -EINVAL; 959 return -EINVAL;
960 } 960 }
961 961
962 priv = kzalloc(sizeof(struct ov9740_priv), GFP_KERNEL); 962 priv = devm_kzalloc(&client->dev, sizeof(struct ov9740_priv), GFP_KERNEL);
963 if (!priv) { 963 if (!priv) {
964 dev_err(&client->dev, "Failed to allocate private data!\n"); 964 dev_err(&client->dev, "Failed to allocate private data!\n");
965 return -ENOMEM; 965 return -ENOMEM;
@@ -972,18 +972,12 @@ static int ov9740_probe(struct i2c_client *client,
972 v4l2_ctrl_new_std(&priv->hdl, &ov9740_ctrl_ops, 972 v4l2_ctrl_new_std(&priv->hdl, &ov9740_ctrl_ops,
973 V4L2_CID_HFLIP, 0, 1, 1, 0); 973 V4L2_CID_HFLIP, 0, 1, 1, 0);
974 priv->subdev.ctrl_handler = &priv->hdl; 974 priv->subdev.ctrl_handler = &priv->hdl;
975 if (priv->hdl.error) { 975 if (priv->hdl.error)
976 int err = priv->hdl.error; 976 return priv->hdl.error;
977
978 kfree(priv);
979 return err;
980 }
981 977
982 ret = ov9740_video_probe(client); 978 ret = ov9740_video_probe(client);
983 if (ret < 0) { 979 if (ret < 0)
984 v4l2_ctrl_handler_free(&priv->hdl); 980 v4l2_ctrl_handler_free(&priv->hdl);
985 kfree(priv);
986 }
987 981
988 return ret; 982 return ret;
989} 983}
@@ -994,7 +988,6 @@ static int ov9740_remove(struct i2c_client *client)
994 988
995 v4l2_device_unregister_subdev(&priv->subdev); 989 v4l2_device_unregister_subdev(&priv->subdev);
996 v4l2_ctrl_handler_free(&priv->hdl); 990 v4l2_ctrl_handler_free(&priv->hdl);
997 kfree(priv);
998 return 0; 991 return 0;
999} 992}
1000 993
diff --git a/drivers/media/i2c/soc_camera/rj54n1cb0c.c b/drivers/media/i2c/soc_camera/rj54n1cb0c.c
index 02f0400051d9..5c92679bfefb 100644
--- a/drivers/media/i2c/soc_camera/rj54n1cb0c.c
+++ b/drivers/media/i2c/soc_camera/rj54n1cb0c.c
@@ -1183,9 +1183,9 @@ static int rj54n1_s_register(struct v4l2_subdev *sd,
1183static int rj54n1_s_power(struct v4l2_subdev *sd, int on) 1183static int rj54n1_s_power(struct v4l2_subdev *sd, int on)
1184{ 1184{
1185 struct i2c_client *client = v4l2_get_subdevdata(sd); 1185 struct i2c_client *client = v4l2_get_subdevdata(sd);
1186 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 1186 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
1187 1187
1188 return soc_camera_set_power(&client->dev, icl, on); 1188 return soc_camera_set_power(&client->dev, ssdd, on);
1189} 1189}
1190 1190
1191static int rj54n1_s_ctrl(struct v4l2_ctrl *ctrl) 1191static int rj54n1_s_ctrl(struct v4l2_ctrl *ctrl)
@@ -1245,14 +1245,14 @@ static int rj54n1_g_mbus_config(struct v4l2_subdev *sd,
1245 struct v4l2_mbus_config *cfg) 1245 struct v4l2_mbus_config *cfg)
1246{ 1246{
1247 struct i2c_client *client = v4l2_get_subdevdata(sd); 1247 struct i2c_client *client = v4l2_get_subdevdata(sd);
1248 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 1248 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
1249 1249
1250 cfg->flags = 1250 cfg->flags =
1251 V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING | 1251 V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING |
1252 V4L2_MBUS_MASTER | V4L2_MBUS_DATA_ACTIVE_HIGH | 1252 V4L2_MBUS_MASTER | V4L2_MBUS_DATA_ACTIVE_HIGH |
1253 V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_HIGH; 1253 V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_HIGH;
1254 cfg->type = V4L2_MBUS_PARALLEL; 1254 cfg->type = V4L2_MBUS_PARALLEL;
1255 cfg->flags = soc_camera_apply_board_flags(icl, cfg); 1255 cfg->flags = soc_camera_apply_board_flags(ssdd, cfg);
1256 1256
1257 return 0; 1257 return 0;
1258} 1258}
@@ -1261,10 +1261,10 @@ static int rj54n1_s_mbus_config(struct v4l2_subdev *sd,
1261 const struct v4l2_mbus_config *cfg) 1261 const struct v4l2_mbus_config *cfg)
1262{ 1262{
1263 struct i2c_client *client = v4l2_get_subdevdata(sd); 1263 struct i2c_client *client = v4l2_get_subdevdata(sd);
1264 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 1264 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
1265 1265
1266 /* Figures 2.5-1 to 2.5-3 - default falling pixclk edge */ 1266 /* Figures 2.5-1 to 2.5-3 - default falling pixclk edge */
1267 if (soc_camera_apply_board_flags(icl, cfg) & 1267 if (soc_camera_apply_board_flags(ssdd, cfg) &
1268 V4L2_MBUS_PCLK_SAMPLE_RISING) 1268 V4L2_MBUS_PCLK_SAMPLE_RISING)
1269 return reg_write(client, RJ54N1_OUT_SIGPO, 1 << 4); 1269 return reg_write(client, RJ54N1_OUT_SIGPO, 1 << 4);
1270 else 1270 else
@@ -1334,17 +1334,17 @@ static int rj54n1_probe(struct i2c_client *client,
1334 const struct i2c_device_id *did) 1334 const struct i2c_device_id *did)
1335{ 1335{
1336 struct rj54n1 *rj54n1; 1336 struct rj54n1 *rj54n1;
1337 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 1337 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
1338 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 1338 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
1339 struct rj54n1_pdata *rj54n1_priv; 1339 struct rj54n1_pdata *rj54n1_priv;
1340 int ret; 1340 int ret;
1341 1341
1342 if (!icl || !icl->priv) { 1342 if (!ssdd || !ssdd->drv_priv) {
1343 dev_err(&client->dev, "RJ54N1CB0C: missing platform data!\n"); 1343 dev_err(&client->dev, "RJ54N1CB0C: missing platform data!\n");
1344 return -EINVAL; 1344 return -EINVAL;
1345 } 1345 }
1346 1346
1347 rj54n1_priv = icl->priv; 1347 rj54n1_priv = ssdd->drv_priv;
1348 1348
1349 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { 1349 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
1350 dev_warn(&adapter->dev, 1350 dev_warn(&adapter->dev,
@@ -1352,7 +1352,7 @@ static int rj54n1_probe(struct i2c_client *client,
1352 return -EIO; 1352 return -EIO;
1353 } 1353 }
1354 1354
1355 rj54n1 = kzalloc(sizeof(struct rj54n1), GFP_KERNEL); 1355 rj54n1 = devm_kzalloc(&client->dev, sizeof(struct rj54n1), GFP_KERNEL);
1356 if (!rj54n1) 1356 if (!rj54n1)
1357 return -ENOMEM; 1357 return -ENOMEM;
1358 1358
@@ -1367,12 +1367,8 @@ static int rj54n1_probe(struct i2c_client *client,
1367 v4l2_ctrl_new_std(&rj54n1->hdl, &rj54n1_ctrl_ops, 1367 v4l2_ctrl_new_std(&rj54n1->hdl, &rj54n1_ctrl_ops,
1368 V4L2_CID_AUTO_WHITE_BALANCE, 0, 1, 1, 1); 1368 V4L2_CID_AUTO_WHITE_BALANCE, 0, 1, 1, 1);
1369 rj54n1->subdev.ctrl_handler = &rj54n1->hdl; 1369 rj54n1->subdev.ctrl_handler = &rj54n1->hdl;
1370 if (rj54n1->hdl.error) { 1370 if (rj54n1->hdl.error)
1371 int err = rj54n1->hdl.error; 1371 return rj54n1->hdl.error;
1372
1373 kfree(rj54n1);
1374 return err;
1375 }
1376 1372
1377 rj54n1->clk_div = clk_div; 1373 rj54n1->clk_div = clk_div;
1378 rj54n1->rect.left = RJ54N1_COLUMN_SKIP; 1374 rj54n1->rect.left = RJ54N1_COLUMN_SKIP;
@@ -1387,10 +1383,8 @@ static int rj54n1_probe(struct i2c_client *client,
1387 (clk_div.ratio_tg + 1) / (clk_div.ratio_t + 1); 1383 (clk_div.ratio_tg + 1) / (clk_div.ratio_t + 1);
1388 1384
1389 ret = rj54n1_video_probe(client, rj54n1_priv); 1385 ret = rj54n1_video_probe(client, rj54n1_priv);
1390 if (ret < 0) { 1386 if (ret < 0)
1391 v4l2_ctrl_handler_free(&rj54n1->hdl); 1387 v4l2_ctrl_handler_free(&rj54n1->hdl);
1392 kfree(rj54n1);
1393 }
1394 1388
1395 return ret; 1389 return ret;
1396} 1390}
@@ -1398,13 +1392,12 @@ static int rj54n1_probe(struct i2c_client *client,
1398static int rj54n1_remove(struct i2c_client *client) 1392static int rj54n1_remove(struct i2c_client *client)
1399{ 1393{
1400 struct rj54n1 *rj54n1 = to_rj54n1(client); 1394 struct rj54n1 *rj54n1 = to_rj54n1(client);
1401 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 1395 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
1402 1396
1403 v4l2_device_unregister_subdev(&rj54n1->subdev); 1397 v4l2_device_unregister_subdev(&rj54n1->subdev);
1404 if (icl->free_bus) 1398 if (ssdd->free_bus)
1405 icl->free_bus(icl); 1399 ssdd->free_bus(ssdd);
1406 v4l2_ctrl_handler_free(&rj54n1->hdl); 1400 v4l2_ctrl_handler_free(&rj54n1->hdl);
1407 kfree(rj54n1);
1408 1401
1409 return 0; 1402 return 0;
1410} 1403}
diff --git a/drivers/media/i2c/soc_camera/tw9910.c b/drivers/media/i2c/soc_camera/tw9910.c
index 140716e71a15..7d2074601881 100644
--- a/drivers/media/i2c/soc_camera/tw9910.c
+++ b/drivers/media/i2c/soc_camera/tw9910.c
@@ -569,9 +569,9 @@ static int tw9910_s_register(struct v4l2_subdev *sd,
569static int tw9910_s_power(struct v4l2_subdev *sd, int on) 569static int tw9910_s_power(struct v4l2_subdev *sd, int on)
570{ 570{
571 struct i2c_client *client = v4l2_get_subdevdata(sd); 571 struct i2c_client *client = v4l2_get_subdevdata(sd);
572 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 572 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
573 573
574 return soc_camera_set_power(&client->dev, icl, on); 574 return soc_camera_set_power(&client->dev, ssdd, on);
575} 575}
576 576
577static int tw9910_set_frame(struct v4l2_subdev *sd, u32 *width, u32 *height) 577static int tw9910_set_frame(struct v4l2_subdev *sd, u32 *width, u32 *height)
@@ -847,14 +847,14 @@ static int tw9910_g_mbus_config(struct v4l2_subdev *sd,
847 struct v4l2_mbus_config *cfg) 847 struct v4l2_mbus_config *cfg)
848{ 848{
849 struct i2c_client *client = v4l2_get_subdevdata(sd); 849 struct i2c_client *client = v4l2_get_subdevdata(sd);
850 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 850 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
851 851
852 cfg->flags = V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_MASTER | 852 cfg->flags = V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_MASTER |
853 V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_LOW | 853 V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_LOW |
854 V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_LOW | 854 V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_LOW |
855 V4L2_MBUS_DATA_ACTIVE_HIGH; 855 V4L2_MBUS_DATA_ACTIVE_HIGH;
856 cfg->type = V4L2_MBUS_PARALLEL; 856 cfg->type = V4L2_MBUS_PARALLEL;
857 cfg->flags = soc_camera_apply_board_flags(icl, cfg); 857 cfg->flags = soc_camera_apply_board_flags(ssdd, cfg);
858 858
859 return 0; 859 return 0;
860} 860}
@@ -863,9 +863,9 @@ static int tw9910_s_mbus_config(struct v4l2_subdev *sd,
863 const struct v4l2_mbus_config *cfg) 863 const struct v4l2_mbus_config *cfg)
864{ 864{
865 struct i2c_client *client = v4l2_get_subdevdata(sd); 865 struct i2c_client *client = v4l2_get_subdevdata(sd);
866 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 866 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
867 u8 val = VSSL_VVALID | HSSL_DVALID; 867 u8 val = VSSL_VVALID | HSSL_DVALID;
868 unsigned long flags = soc_camera_apply_board_flags(icl, cfg); 868 unsigned long flags = soc_camera_apply_board_flags(ssdd, cfg);
869 869
870 /* 870 /*
871 * set OUTCTR1 871 * set OUTCTR1
@@ -911,15 +911,14 @@ static int tw9910_probe(struct i2c_client *client,
911 struct tw9910_video_info *info; 911 struct tw9910_video_info *info;
912 struct i2c_adapter *adapter = 912 struct i2c_adapter *adapter =
913 to_i2c_adapter(client->dev.parent); 913 to_i2c_adapter(client->dev.parent);
914 struct soc_camera_link *icl = soc_camera_i2c_to_link(client); 914 struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);
915 int ret;
916 915
917 if (!icl || !icl->priv) { 916 if (!ssdd || !ssdd->drv_priv) {
918 dev_err(&client->dev, "TW9910: missing platform data!\n"); 917 dev_err(&client->dev, "TW9910: missing platform data!\n");
919 return -EINVAL; 918 return -EINVAL;
920 } 919 }
921 920
922 info = icl->priv; 921 info = ssdd->drv_priv;
923 922
924 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { 923 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
925 dev_err(&client->dev, 924 dev_err(&client->dev,
@@ -928,7 +927,7 @@ static int tw9910_probe(struct i2c_client *client,
928 return -EIO; 927 return -EIO;
929 } 928 }
930 929
931 priv = kzalloc(sizeof(*priv), GFP_KERNEL); 930 priv = devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL);
932 if (!priv) 931 if (!priv)
933 return -ENOMEM; 932 return -ENOMEM;
934 933
@@ -936,18 +935,11 @@ static int tw9910_probe(struct i2c_client *client,
936 935
937 v4l2_i2c_subdev_init(&priv->subdev, client, &tw9910_subdev_ops); 936 v4l2_i2c_subdev_init(&priv->subdev, client, &tw9910_subdev_ops);
938 937
939 ret = tw9910_video_probe(client); 938 return tw9910_video_probe(client);
940 if (ret)
941 kfree(priv);
942
943 return ret;
944} 939}
945 940
946static int tw9910_remove(struct i2c_client *client) 941static int tw9910_remove(struct i2c_client *client)
947{ 942{
948 struct tw9910_priv *priv = to_tw9910(client);
949
950 kfree(priv);
951 return 0; 943 return 0;
952} 944}
953 945
diff --git a/drivers/media/i2c/ths7303.c b/drivers/media/i2c/ths7303.c
index c31cc04fffd2..e747524ba6ed 100644
--- a/drivers/media/i2c/ths7303.c
+++ b/drivers/media/i2c/ths7303.c
@@ -175,7 +175,7 @@ static int ths7303_probe(struct i2c_client *client,
175 v4l_info(client, "chip found @ 0x%x (%s)\n", 175 v4l_info(client, "chip found @ 0x%x (%s)\n",
176 client->addr << 1, client->adapter->name); 176 client->addr << 1, client->adapter->name);
177 177
178 sd = kzalloc(sizeof(struct v4l2_subdev), GFP_KERNEL); 178 sd = devm_kzalloc(&client->dev, sizeof(struct v4l2_subdev), GFP_KERNEL);
179 if (sd == NULL) 179 if (sd == NULL)
180 return -ENOMEM; 180 return -ENOMEM;
181 181
@@ -189,7 +189,6 @@ static int ths7303_remove(struct i2c_client *client)
189 struct v4l2_subdev *sd = i2c_get_clientdata(client); 189 struct v4l2_subdev *sd = i2c_get_clientdata(client);
190 190
191 v4l2_device_unregister_subdev(sd); 191 v4l2_device_unregister_subdev(sd);
192 kfree(sd);
193 192
194 return 0; 193 return 0;
195} 194}
diff --git a/drivers/media/i2c/tvaudio.c b/drivers/media/i2c/tvaudio.c
index 3b24d3fc1866..e3b33b78dd21 100644
--- a/drivers/media/i2c/tvaudio.c
+++ b/drivers/media/i2c/tvaudio.c
@@ -39,6 +39,7 @@
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> 41#include <media/v4l2-chip-ident.h>
42#include <media/v4l2-ctrls.h>
42 43
43#include <media/i2c-addr.h> 44#include <media/i2c-addr.h>
44 45
@@ -91,13 +92,13 @@ struct CHIPDESC {
91 audiocmd init; 92 audiocmd init;
92 93
93 /* which register has which value */ 94 /* which register has which value */
94 int leftreg,rightreg,treblereg,bassreg; 95 int leftreg, rightreg, treblereg, bassreg;
95 96
96 /* initialize with (defaults to 65535/65535/32768/32768 */ 97 /* initialize with (defaults to 65535/32768/32768 */
97 int leftinit,rightinit,trebleinit,bassinit; 98 int volinit, trebleinit, bassinit;
98 99
99 /* functions to convert the values (v4l -> chip) */ 100 /* functions to convert the values (v4l -> chip) */
100 getvalue volfunc,treblefunc,bassfunc; 101 getvalue volfunc, treblefunc, bassfunc;
101 102
102 /* get/set mode */ 103 /* get/set mode */
103 getrxsubchans getrxsubchans; 104 getrxsubchans getrxsubchans;
@@ -113,6 +114,12 @@ struct CHIPDESC {
113/* current state of the chip */ 114/* current state of the chip */
114struct CHIPSTATE { 115struct CHIPSTATE {
115 struct v4l2_subdev sd; 116 struct v4l2_subdev sd;
117 struct v4l2_ctrl_handler hdl;
118 struct {
119 /* volume/balance cluster */
120 struct v4l2_ctrl *volume;
121 struct v4l2_ctrl *balance;
122 };
116 123
117 /* chip-specific description - should point to 124 /* chip-specific description - should point to
118 an entry at CHIPDESC table */ 125 an entry at CHIPDESC table */
@@ -122,7 +129,7 @@ struct CHIPSTATE {
122 audiocmd shadow; 129 audiocmd shadow;
123 130
124 /* current settings */ 131 /* current settings */
125 __u16 left, right, treble, bass, muted; 132 u16 muted;
126 int prevmode; 133 int prevmode;
127 int radio; 134 int radio;
128 int input; 135 int input;
@@ -138,6 +145,11 @@ static inline struct CHIPSTATE *to_state(struct v4l2_subdev *sd)
138 return container_of(sd, struct CHIPSTATE, sd); 145 return container_of(sd, struct CHIPSTATE, sd);
139} 146}
140 147
148static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl)
149{
150 return &container_of(ctrl->handler, struct CHIPSTATE, hdl)->sd;
151}
152
141 153
142/* ---------------------------------------------------------------------- */ 154/* ---------------------------------------------------------------------- */
143/* i2c I/O functions */ 155/* i2c I/O functions */
@@ -1523,8 +1535,7 @@ static struct CHIPDESC chiplist[] = {
1523 .rightreg = TDA9875_MVR, 1535 .rightreg = TDA9875_MVR,
1524 .bassreg = TDA9875_MBA, 1536 .bassreg = TDA9875_MBA,
1525 .treblereg = TDA9875_MTR, 1537 .treblereg = TDA9875_MTR,
1526 .leftinit = 58880, 1538 .volinit = 58880,
1527 .rightinit = 58880,
1528 }, 1539 },
1529 { 1540 {
1530 .name = "tda9850", 1541 .name = "tda9850",
@@ -1618,7 +1629,8 @@ static struct CHIPDESC chiplist[] = {
1618 1629
1619 .inputreg = -1, 1630 .inputreg = -1,
1620 .inputmap = { TEA6420_S_SA, TEA6420_S_SB, TEA6420_S_SC }, 1631 .inputmap = { TEA6420_S_SA, TEA6420_S_SB, TEA6420_S_SC },
1621 .inputmute = TEA6300_S_GMU, 1632 .inputmute = TEA6420_S_GMU,
1633 .inputmask = 0x07,
1622 }, 1634 },
1623 { 1635 {
1624 .name = "tda8425", 1636 .name = "tda8425",
@@ -1679,121 +1691,39 @@ static struct CHIPDESC chiplist[] = {
1679 1691
1680/* ---------------------------------------------------------------------- */ 1692/* ---------------------------------------------------------------------- */
1681 1693
1682static int tvaudio_g_ctrl(struct v4l2_subdev *sd, 1694static int tvaudio_s_ctrl(struct v4l2_ctrl *ctrl)
1683 struct v4l2_control *ctrl)
1684{ 1695{
1696 struct v4l2_subdev *sd = to_sd(ctrl);
1685 struct CHIPSTATE *chip = to_state(sd); 1697 struct CHIPSTATE *chip = to_state(sd);
1686 struct CHIPDESC *desc = chip->desc; 1698 struct CHIPDESC *desc = chip->desc;
1687 1699
1688 switch (ctrl->id) { 1700 switch (ctrl->id) {
1689 case V4L2_CID_AUDIO_MUTE: 1701 case V4L2_CID_AUDIO_MUTE:
1690 if (!(desc->flags & CHIP_HAS_INPUTSEL)) 1702 chip->muted = ctrl->val;
1691 break;
1692 ctrl->value=chip->muted;
1693 return 0;
1694 case V4L2_CID_AUDIO_VOLUME:
1695 if (!(desc->flags & CHIP_HAS_VOLUME))
1696 break;
1697 ctrl->value = max(chip->left,chip->right);
1698 return 0;
1699 case V4L2_CID_AUDIO_BALANCE:
1700 {
1701 int volume;
1702 if (!(desc->flags & CHIP_HAS_VOLUME))
1703 break;
1704 volume = max(chip->left,chip->right);
1705 if (volume)
1706 ctrl->value=(32768*min(chip->left,chip->right))/volume;
1707 else
1708 ctrl->value=32768;
1709 return 0;
1710 }
1711 case V4L2_CID_AUDIO_BASS:
1712 if (!(desc->flags & CHIP_HAS_BASSTREBLE))
1713 break;
1714 ctrl->value = chip->bass;
1715 return 0;
1716 case V4L2_CID_AUDIO_TREBLE:
1717 if (!(desc->flags & CHIP_HAS_BASSTREBLE))
1718 break;
1719 ctrl->value = chip->treble;
1720 return 0;
1721 }
1722 return -EINVAL;
1723}
1724
1725static int tvaudio_s_ctrl(struct v4l2_subdev *sd,
1726 struct v4l2_control *ctrl)
1727{
1728 struct CHIPSTATE *chip = to_state(sd);
1729 struct CHIPDESC *desc = chip->desc;
1730
1731 switch (ctrl->id) {
1732 case V4L2_CID_AUDIO_MUTE:
1733 if (!(desc->flags & CHIP_HAS_INPUTSEL))
1734 break;
1735
1736 if (ctrl->value < 0 || ctrl->value >= 2)
1737 return -ERANGE;
1738 chip->muted = ctrl->value;
1739 if (chip->muted) 1703 if (chip->muted)
1740 chip_write_masked(chip,desc->inputreg,desc->inputmute,desc->inputmask); 1704 chip_write_masked(chip,desc->inputreg,desc->inputmute,desc->inputmask);
1741 else 1705 else
1742 chip_write_masked(chip,desc->inputreg, 1706 chip_write_masked(chip,desc->inputreg,
1743 desc->inputmap[chip->input],desc->inputmask); 1707 desc->inputmap[chip->input],desc->inputmask);
1744 return 0; 1708 return 0;
1745 case V4L2_CID_AUDIO_VOLUME: 1709 case V4L2_CID_AUDIO_VOLUME: {
1746 { 1710 u32 volume, balance;
1747 int volume,balance; 1711 u32 left, right;
1748
1749 if (!(desc->flags & CHIP_HAS_VOLUME))
1750 break;
1751
1752 volume = max(chip->left,chip->right);
1753 if (volume)
1754 balance=(32768*min(chip->left,chip->right))/volume;
1755 else
1756 balance=32768;
1757
1758 volume=ctrl->value;
1759 chip->left = (min(65536 - balance,32768) * volume) / 32768;
1760 chip->right = (min(balance,volume *(__u16)32768)) / 32768;
1761
1762 chip_write(chip,desc->leftreg,desc->volfunc(chip->left));
1763 chip_write(chip,desc->rightreg,desc->volfunc(chip->right));
1764
1765 return 0;
1766 }
1767 case V4L2_CID_AUDIO_BALANCE:
1768 {
1769 int volume, balance;
1770
1771 if (!(desc->flags & CHIP_HAS_VOLUME))
1772 break;
1773
1774 volume = max(chip->left, chip->right);
1775 balance = ctrl->value;
1776 chip->left = (min(65536 - balance, 32768) * volume) / 32768;
1777 chip->right = (min(balance, volume * (__u16)32768)) / 32768;
1778 1712
1779 chip_write(chip, desc->leftreg, desc->volfunc(chip->left)); 1713 volume = chip->volume->val;
1780 chip_write(chip, desc->rightreg, desc->volfunc(chip->right)); 1714 balance = chip->balance->val;
1715 left = (min(65536U - balance, 32768U) * volume) / 32768U;
1716 right = (min(balance, 32768U) * volume) / 32768U;
1781 1717
1718 chip_write(chip, desc->leftreg, desc->volfunc(left));
1719 chip_write(chip, desc->rightreg, desc->volfunc(right));
1782 return 0; 1720 return 0;
1783 } 1721 }
1784 case V4L2_CID_AUDIO_BASS: 1722 case V4L2_CID_AUDIO_BASS:
1785 if (!(desc->flags & CHIP_HAS_BASSTREBLE)) 1723 chip_write(chip, desc->bassreg, desc->bassfunc(ctrl->val));
1786 break;
1787 chip->bass = ctrl->value;
1788 chip_write(chip,desc->bassreg,desc->bassfunc(chip->bass));
1789
1790 return 0; 1724 return 0;
1791 case V4L2_CID_AUDIO_TREBLE: 1725 case V4L2_CID_AUDIO_TREBLE:
1792 if (!(desc->flags & CHIP_HAS_BASSTREBLE)) 1726 chip_write(chip, desc->treblereg, desc->treblefunc(ctrl->val));
1793 break;
1794 chip->treble = ctrl->value;
1795 chip_write(chip,desc->treblereg,desc->treblefunc(chip->treble));
1796
1797 return 0; 1727 return 0;
1798 } 1728 }
1799 return -EINVAL; 1729 return -EINVAL;
@@ -1812,35 +1742,6 @@ static int tvaudio_s_radio(struct v4l2_subdev *sd)
1812 return 0; 1742 return 0;
1813} 1743}
1814 1744
1815static int tvaudio_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc)
1816{
1817 struct CHIPSTATE *chip = to_state(sd);
1818 struct CHIPDESC *desc = chip->desc;
1819
1820 switch (qc->id) {
1821 case V4L2_CID_AUDIO_MUTE:
1822 if (desc->flags & CHIP_HAS_INPUTSEL)
1823 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 0);
1824 break;
1825 case V4L2_CID_AUDIO_VOLUME:
1826 if (desc->flags & CHIP_HAS_VOLUME)
1827 return v4l2_ctrl_query_fill(qc, 0, 65535, 65535 / 100, 58880);
1828 break;
1829 case V4L2_CID_AUDIO_BALANCE:
1830 if (desc->flags & CHIP_HAS_VOLUME)
1831 return v4l2_ctrl_query_fill(qc, 0, 65535, 65535 / 100, 32768);
1832 break;
1833 case V4L2_CID_AUDIO_BASS:
1834 case V4L2_CID_AUDIO_TREBLE:
1835 if (desc->flags & CHIP_HAS_BASSTREBLE)
1836 return v4l2_ctrl_query_fill(qc, 0, 65535, 65535 / 100, 32768);
1837 break;
1838 default:
1839 break;
1840 }
1841 return -EINVAL;
1842}
1843
1844static int tvaudio_s_routing(struct v4l2_subdev *sd, 1745static int tvaudio_s_routing(struct v4l2_subdev *sd,
1845 u32 input, u32 output, u32 config) 1746 u32 input, u32 output, u32 config)
1846{ 1747{
@@ -1944,13 +1845,32 @@ static int tvaudio_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ide
1944 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_TVAUDIO, 0); 1845 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_TVAUDIO, 0);
1945} 1846}
1946 1847
1848static int tvaudio_log_status(struct v4l2_subdev *sd)
1849{
1850 struct CHIPSTATE *chip = to_state(sd);
1851 struct CHIPDESC *desc = chip->desc;
1852
1853 v4l2_info(sd, "Chip: %s\n", desc->name);
1854 v4l2_ctrl_handler_log_status(&chip->hdl, sd->name);
1855 return 0;
1856}
1857
1947/* ----------------------------------------------------------------------- */ 1858/* ----------------------------------------------------------------------- */
1948 1859
1860static const struct v4l2_ctrl_ops tvaudio_ctrl_ops = {
1861 .s_ctrl = tvaudio_s_ctrl,
1862};
1863
1949static const struct v4l2_subdev_core_ops tvaudio_core_ops = { 1864static const struct v4l2_subdev_core_ops tvaudio_core_ops = {
1865 .log_status = tvaudio_log_status,
1950 .g_chip_ident = tvaudio_g_chip_ident, 1866 .g_chip_ident = tvaudio_g_chip_ident,
1951 .queryctrl = tvaudio_queryctrl, 1867 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls,
1952 .g_ctrl = tvaudio_g_ctrl, 1868 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls,
1953 .s_ctrl = tvaudio_s_ctrl, 1869 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls,
1870 .g_ctrl = v4l2_subdev_g_ctrl,
1871 .s_ctrl = v4l2_subdev_s_ctrl,
1872 .queryctrl = v4l2_subdev_queryctrl,
1873 .querymenu = v4l2_subdev_querymenu,
1954 .s_std = tvaudio_s_std, 1874 .s_std = tvaudio_s_std,
1955}; 1875};
1956 1876
@@ -2035,6 +1955,10 @@ static int tvaudio_probe(struct i2c_client *client, const struct i2c_device_id *
2035 else 1955 else
2036 chip_cmd(chip, "init", &desc->init); 1956 chip_cmd(chip, "init", &desc->init);
2037 1957
1958 v4l2_ctrl_handler_init(&chip->hdl, 5);
1959 if (desc->flags & CHIP_HAS_INPUTSEL)
1960 v4l2_ctrl_new_std(&chip->hdl, &tvaudio_ctrl_ops,
1961 V4L2_CID_AUDIO_MUTE, 0, 1, 1, 0);
2038 if (desc->flags & CHIP_HAS_VOLUME) { 1962 if (desc->flags & CHIP_HAS_VOLUME) {
2039 if (!desc->volfunc) { 1963 if (!desc->volfunc) {
2040 /* This shouldn't be happen. Warn user, but keep working 1964 /* This shouldn't be happen. Warn user, but keep working
@@ -2043,12 +1967,14 @@ static int tvaudio_probe(struct i2c_client *client, const struct i2c_device_id *
2043 v4l2_info(sd, "volume callback undefined!\n"); 1967 v4l2_info(sd, "volume callback undefined!\n");
2044 desc->flags &= ~CHIP_HAS_VOLUME; 1968 desc->flags &= ~CHIP_HAS_VOLUME;
2045 } else { 1969 } else {
2046 chip->left = desc->leftinit ? desc->leftinit : 65535; 1970 chip->volume = v4l2_ctrl_new_std(&chip->hdl,
2047 chip->right = desc->rightinit ? desc->rightinit : 65535; 1971 &tvaudio_ctrl_ops, V4L2_CID_AUDIO_VOLUME,
2048 chip_write(chip, desc->leftreg, 1972 0, 65535, 65535 / 100,
2049 desc->volfunc(chip->left)); 1973 desc->volinit ? desc->volinit : 65535);
2050 chip_write(chip, desc->rightreg, 1974 chip->balance = v4l2_ctrl_new_std(&chip->hdl,
2051 desc->volfunc(chip->right)); 1975 &tvaudio_ctrl_ops, V4L2_CID_AUDIO_BALANCE,
1976 0, 65535, 65535 / 100, 32768);
1977 v4l2_ctrl_cluster(2, &chip->volume);
2052 } 1978 }
2053 } 1979 }
2054 if (desc->flags & CHIP_HAS_BASSTREBLE) { 1980 if (desc->flags & CHIP_HAS_BASSTREBLE) {
@@ -2059,17 +1985,28 @@ static int tvaudio_probe(struct i2c_client *client, const struct i2c_device_id *
2059 v4l2_info(sd, "bass/treble callbacks undefined!\n"); 1985 v4l2_info(sd, "bass/treble callbacks undefined!\n");
2060 desc->flags &= ~CHIP_HAS_BASSTREBLE; 1986 desc->flags &= ~CHIP_HAS_BASSTREBLE;
2061 } else { 1987 } else {
2062 chip->treble = desc->trebleinit ? 1988 v4l2_ctrl_new_std(&chip->hdl,
2063 desc->trebleinit : 32768; 1989 &tvaudio_ctrl_ops, V4L2_CID_AUDIO_BASS,
2064 chip->bass = desc->bassinit ? 1990 0, 65535, 65535 / 100,
2065 desc->bassinit : 32768; 1991 desc->bassinit ? desc->bassinit : 32768);
2066 chip_write(chip, desc->bassreg, 1992 v4l2_ctrl_new_std(&chip->hdl,
2067 desc->bassfunc(chip->bass)); 1993 &tvaudio_ctrl_ops, V4L2_CID_AUDIO_TREBLE,
2068 chip_write(chip, desc->treblereg, 1994 0, 65535, 65535 / 100,
2069 desc->treblefunc(chip->treble)); 1995 desc->trebleinit ? desc->trebleinit : 32768);
2070 } 1996 }
2071 } 1997 }
2072 1998
1999 sd->ctrl_handler = &chip->hdl;
2000 if (chip->hdl.error) {
2001 int err = chip->hdl.error;
2002
2003 v4l2_ctrl_handler_free(&chip->hdl);
2004 kfree(chip);
2005 return err;
2006 }
2007 /* set controls to the default values */
2008 v4l2_ctrl_handler_setup(&chip->hdl);
2009
2073 chip->thread = NULL; 2010 chip->thread = NULL;
2074 init_timer(&chip->wt); 2011 init_timer(&chip->wt);
2075 if (desc->flags & CHIP_NEED_CHECKMODE) { 2012 if (desc->flags & CHIP_NEED_CHECKMODE) {
@@ -2105,6 +2042,7 @@ static int tvaudio_remove(struct i2c_client *client)
2105 } 2042 }
2106 2043
2107 v4l2_device_unregister_subdev(sd); 2044 v4l2_device_unregister_subdev(sd);
2045 v4l2_ctrl_handler_free(&chip->hdl);
2108 kfree(chip); 2046 kfree(chip);
2109 return 0; 2047 return 0;
2110} 2048}
diff --git a/drivers/media/i2c/tvp514x.c b/drivers/media/i2c/tvp514x.c
index d5e10215a28f..aa94ebc2d755 100644
--- a/drivers/media/i2c/tvp514x.c
+++ b/drivers/media/i2c/tvp514x.c
@@ -951,7 +951,7 @@ tvp514x_probe(struct i2c_client *client, const struct i2c_device_id *id)
951 return -ENODEV; 951 return -ENODEV;
952 } 952 }
953 953
954 decoder = kzalloc(sizeof(*decoder), GFP_KERNEL); 954 decoder = devm_kzalloc(&client->dev, sizeof(*decoder), GFP_KERNEL);
955 if (!decoder) 955 if (!decoder)
956 return -ENOMEM; 956 return -ENOMEM;
957 957
@@ -998,7 +998,6 @@ tvp514x_probe(struct i2c_client *client, const struct i2c_device_id *id)
998 int err = decoder->hdl.error; 998 int err = decoder->hdl.error;
999 999
1000 v4l2_ctrl_handler_free(&decoder->hdl); 1000 v4l2_ctrl_handler_free(&decoder->hdl);
1001 kfree(decoder);
1002 return err; 1001 return err;
1003 } 1002 }
1004 v4l2_ctrl_handler_setup(&decoder->hdl); 1003 v4l2_ctrl_handler_setup(&decoder->hdl);
@@ -1023,7 +1022,6 @@ static int tvp514x_remove(struct i2c_client *client)
1023 1022
1024 v4l2_device_unregister_subdev(sd); 1023 v4l2_device_unregister_subdev(sd);
1025 v4l2_ctrl_handler_free(&decoder->hdl); 1024 v4l2_ctrl_handler_free(&decoder->hdl);
1026 kfree(decoder);
1027 return 0; 1025 return 0;
1028} 1026}
1029/* TVP5146 Init/Power on Sequence */ 1027/* TVP5146 Init/Power on Sequence */
diff --git a/drivers/media/i2c/tvp5150.c b/drivers/media/i2c/tvp5150.c
index 31104a960652..5967e1a0c809 100644
--- a/drivers/media/i2c/tvp5150.c
+++ b/drivers/media/i2c/tvp5150.c
@@ -1096,13 +1096,6 @@ static const struct v4l2_ctrl_ops tvp5150_ctrl_ops = {
1096 1096
1097static const struct v4l2_subdev_core_ops tvp5150_core_ops = { 1097static const struct v4l2_subdev_core_ops tvp5150_core_ops = {
1098 .log_status = tvp5150_log_status, 1098 .log_status = tvp5150_log_status,
1099 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls,
1100 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls,
1101 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls,
1102 .g_ctrl = v4l2_subdev_g_ctrl,
1103 .s_ctrl = v4l2_subdev_s_ctrl,
1104 .queryctrl = v4l2_subdev_queryctrl,
1105 .querymenu = v4l2_subdev_querymenu,
1106 .s_std = tvp5150_s_std, 1099 .s_std = tvp5150_s_std,
1107 .reset = tvp5150_reset, 1100 .reset = tvp5150_reset,
1108 .g_chip_ident = tvp5150_g_chip_ident, 1101 .g_chip_ident = tvp5150_g_chip_ident,
diff --git a/drivers/media/i2c/tvp7002.c b/drivers/media/i2c/tvp7002.c
index fb6a5b57eb83..537f6b4d4918 100644
--- a/drivers/media/i2c/tvp7002.c
+++ b/drivers/media/i2c/tvp7002.c
@@ -1036,7 +1036,7 @@ static int tvp7002_probe(struct i2c_client *c, const struct i2c_device_id *id)
1036 return -ENODEV; 1036 return -ENODEV;
1037 } 1037 }
1038 1038
1039 device = kzalloc(sizeof(struct tvp7002), GFP_KERNEL); 1039 device = devm_kzalloc(&c->dev, sizeof(struct tvp7002), GFP_KERNEL);
1040 1040
1041 if (!device) 1041 if (!device)
1042 return -ENOMEM; 1042 return -ENOMEM;
@@ -1052,7 +1052,7 @@ static int tvp7002_probe(struct i2c_client *c, const struct i2c_device_id *id)
1052 1052
1053 error = tvp7002_read(sd, TVP7002_CHIP_REV, &revision); 1053 error = tvp7002_read(sd, TVP7002_CHIP_REV, &revision);
1054 if (error < 0) 1054 if (error < 0)
1055 goto found_error; 1055 return error;
1056 1056
1057 /* Get revision number */ 1057 /* Get revision number */
1058 v4l2_info(sd, "Rev. %02x detected.\n", revision); 1058 v4l2_info(sd, "Rev. %02x detected.\n", revision);
@@ -1063,21 +1063,21 @@ static int tvp7002_probe(struct i2c_client *c, const struct i2c_device_id *id)
1063 error = tvp7002_write_inittab(sd, tvp7002_init_default); 1063 error = tvp7002_write_inittab(sd, tvp7002_init_default);
1064 1064
1065 if (error < 0) 1065 if (error < 0)
1066 goto found_error; 1066 return error;
1067 1067
1068 /* Set polarity information after registers have been set */ 1068 /* Set polarity information after registers have been set */
1069 polarity_a = 0x20 | device->pdata->hs_polarity << 5 1069 polarity_a = 0x20 | device->pdata->hs_polarity << 5
1070 | device->pdata->vs_polarity << 2; 1070 | device->pdata->vs_polarity << 2;
1071 error = tvp7002_write(sd, TVP7002_SYNC_CTL_1, polarity_a); 1071 error = tvp7002_write(sd, TVP7002_SYNC_CTL_1, polarity_a);
1072 if (error < 0) 1072 if (error < 0)
1073 goto found_error; 1073 return error;
1074 1074
1075 polarity_b = 0x01 | device->pdata->fid_polarity << 2 1075 polarity_b = 0x01 | device->pdata->fid_polarity << 2
1076 | device->pdata->sog_polarity << 1 1076 | device->pdata->sog_polarity << 1
1077 | device->pdata->clk_polarity; 1077 | device->pdata->clk_polarity;
1078 error = tvp7002_write(sd, TVP7002_MISC_CTL_3, polarity_b); 1078 error = tvp7002_write(sd, TVP7002_MISC_CTL_3, polarity_b);
1079 if (error < 0) 1079 if (error < 0)
1080 goto found_error; 1080 return error;
1081 1081
1082 /* Set registers according to default video mode */ 1082 /* Set registers according to default video mode */
1083 preset.preset = device->current_preset->preset; 1083 preset.preset = device->current_preset->preset;
@@ -1091,16 +1091,11 @@ static int tvp7002_probe(struct i2c_client *c, const struct i2c_device_id *id)
1091 int err = device->hdl.error; 1091 int err = device->hdl.error;
1092 1092
1093 v4l2_ctrl_handler_free(&device->hdl); 1093 v4l2_ctrl_handler_free(&device->hdl);
1094 kfree(device);
1095 return err; 1094 return err;
1096 } 1095 }
1097 v4l2_ctrl_handler_setup(&device->hdl); 1096 v4l2_ctrl_handler_setup(&device->hdl);
1098 1097
1099found_error: 1098 return 0;
1100 if (error < 0)
1101 kfree(device);
1102
1103 return error;
1104} 1099}
1105 1100
1106/* 1101/*
@@ -1120,7 +1115,6 @@ static int tvp7002_remove(struct i2c_client *c)
1120 1115
1121 v4l2_device_unregister_subdev(sd); 1116 v4l2_device_unregister_subdev(sd);
1122 v4l2_ctrl_handler_free(&device->hdl); 1117 v4l2_ctrl_handler_free(&device->hdl);
1123 kfree(device);
1124 return 0; 1118 return 0;
1125} 1119}
1126 1120
diff --git a/drivers/media/parport/Kconfig b/drivers/media/parport/Kconfig
index ece13dcff07d..948c981d9f05 100644
--- a/drivers/media/parport/Kconfig
+++ b/drivers/media/parport/Kconfig
@@ -9,6 +9,7 @@ if MEDIA_PARPORT_SUPPORT
9config VIDEO_BWQCAM 9config VIDEO_BWQCAM
10 tristate "Quickcam BW Video For Linux" 10 tristate "Quickcam BW Video For Linux"
11 depends on PARPORT && VIDEO_V4L2 11 depends on PARPORT && VIDEO_V4L2
12 select VIDEOBUF2_VMALLOC
12 help 13 help
13 Say Y have if you the black and white version of the QuickCam 14 Say Y have if you the black and white version of the QuickCam
14 camera. See the next option for the color version. 15 camera. See the next option for the color version.
diff --git a/drivers/media/parport/bw-qcam.c b/drivers/media/parport/bw-qcam.c
index 5b75a64b199b..06231b85e1a9 100644
--- a/drivers/media/parport/bw-qcam.c
+++ b/drivers/media/parport/bw-qcam.c
@@ -80,6 +80,7 @@ OTHER DEALINGS IN THE SOFTWARE.
80#include <media/v4l2-fh.h> 80#include <media/v4l2-fh.h>
81#include <media/v4l2-ctrls.h> 81#include <media/v4l2-ctrls.h>
82#include <media/v4l2-event.h> 82#include <media/v4l2-event.h>
83#include <media/videobuf2-vmalloc.h>
83 84
84/* One from column A... */ 85/* One from column A... */
85#define QC_NOTSET 0 86#define QC_NOTSET 0
@@ -107,9 +108,11 @@ struct qcam {
107 struct v4l2_device v4l2_dev; 108 struct v4l2_device v4l2_dev;
108 struct video_device vdev; 109 struct video_device vdev;
109 struct v4l2_ctrl_handler hdl; 110 struct v4l2_ctrl_handler hdl;
111 struct vb2_queue vb_vidq;
110 struct pardevice *pdev; 112 struct pardevice *pdev;
111 struct parport *pport; 113 struct parport *pport;
112 struct mutex lock; 114 struct mutex lock;
115 struct mutex queue_lock;
113 int width, height; 116 int width, height;
114 int bpp; 117 int bpp;
115 int mode; 118 int mode;
@@ -418,8 +421,6 @@ static void qc_set(struct qcam *q)
418 int val; 421 int val;
419 int val2; 422 int val2;
420 423
421 qc_reset(q);
422
423 /* Set the brightness. Yes, this is repetitive, but it works. 424 /* Set the brightness. Yes, this is repetitive, but it works.
424 * Shorter versions seem to fail subtly. Feel free to try :-). */ 425 * Shorter versions seem to fail subtly. Feel free to try :-). */
425 /* I think the problem was in qc_command, not here -- bls */ 426 /* I think the problem was in qc_command, not here -- bls */
@@ -558,7 +559,7 @@ static inline int qc_readbytes(struct qcam *q, char buffer[])
558 * n=2^(bit depth)-1. Ask me for more details if you don't understand 559 * n=2^(bit depth)-1. Ask me for more details if you don't understand
559 * this. */ 560 * this. */
560 561
561static long qc_capture(struct qcam *q, char __user *buf, unsigned long len) 562static long qc_capture(struct qcam *q, u8 *buf, unsigned long len)
562{ 563{
563 int i, j, k, yield; 564 int i, j, k, yield;
564 int bytes; 565 int bytes;
@@ -609,7 +610,7 @@ static long qc_capture(struct qcam *q, char __user *buf, unsigned long len)
609 if (o < len) { 610 if (o < len) {
610 u8 ch = invert - buffer[k]; 611 u8 ch = invert - buffer[k];
611 got++; 612 got++;
612 put_user(ch << shift, buf + o); 613 buf[o] = ch << shift;
613 } 614 }
614 } 615 }
615 pixels_read += bytes; 616 pixels_read += bytes;
@@ -639,6 +640,67 @@ static long qc_capture(struct qcam *q, char __user *buf, unsigned long len)
639 return len; 640 return len;
640} 641}
641 642
643/* ------------------------------------------------------------------
644 Videobuf operations
645 ------------------------------------------------------------------*/
646static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
647 unsigned int *nbuffers, unsigned int *nplanes,
648 unsigned int sizes[], void *alloc_ctxs[])
649{
650 struct qcam *dev = vb2_get_drv_priv(vq);
651
652 if (0 == *nbuffers)
653 *nbuffers = 3;
654 *nplanes = 1;
655 mutex_lock(&dev->lock);
656 if (fmt)
657 sizes[0] = fmt->fmt.pix.width * fmt->fmt.pix.height;
658 else
659 sizes[0] = (dev->width / dev->transfer_scale) *
660 (dev->height / dev->transfer_scale);
661 mutex_unlock(&dev->lock);
662 return 0;
663}
664
665static void buffer_queue(struct vb2_buffer *vb)
666{
667 vb2_buffer_done(vb, VB2_BUF_STATE_DONE);
668}
669
670static int buffer_finish(struct vb2_buffer *vb)
671{
672 struct qcam *qcam = vb2_get_drv_priv(vb->vb2_queue);
673 void *vbuf = vb2_plane_vaddr(vb, 0);
674 int size = vb->vb2_queue->plane_sizes[0];
675 int len;
676
677 mutex_lock(&qcam->lock);
678 parport_claim_or_block(qcam->pdev);
679
680 qc_reset(qcam);
681
682 /* Update the camera parameters if we need to */
683 if (qcam->status & QC_PARAM_CHANGE)
684 qc_set(qcam);
685
686 len = qc_capture(qcam, vbuf, size);
687
688 parport_release(qcam->pdev);
689 mutex_unlock(&qcam->lock);
690 if (len != size)
691 vb->state = VB2_BUF_STATE_ERROR;
692 vb2_set_plane_payload(vb, 0, len);
693 return 0;
694}
695
696static struct vb2_ops qcam_video_qops = {
697 .queue_setup = queue_setup,
698 .buf_queue = buffer_queue,
699 .buf_finish = buffer_finish,
700 .wait_prepare = vb2_ops_wait_prepare,
701 .wait_finish = vb2_ops_wait_finish,
702};
703
642/* 704/*
643 * Video4linux interfacing 705 * Video4linux interfacing
644 */ 706 */
@@ -651,7 +713,8 @@ static int qcam_querycap(struct file *file, void *priv,
651 strlcpy(vcap->driver, qcam->v4l2_dev.name, sizeof(vcap->driver)); 713 strlcpy(vcap->driver, qcam->v4l2_dev.name, sizeof(vcap->driver));
652 strlcpy(vcap->card, "Connectix B&W Quickcam", sizeof(vcap->card)); 714 strlcpy(vcap->card, "Connectix B&W Quickcam", sizeof(vcap->card));
653 strlcpy(vcap->bus_info, qcam->pport->name, sizeof(vcap->bus_info)); 715 strlcpy(vcap->bus_info, qcam->pport->name, sizeof(vcap->bus_info));
654 vcap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE; 716 vcap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE |
717 V4L2_CAP_STREAMING;
655 vcap->capabilities = vcap->device_caps | V4L2_CAP_DEVICE_CAPS; 718 vcap->capabilities = vcap->device_caps | V4L2_CAP_DEVICE_CAPS;
656 return 0; 719 return 0;
657} 720}
@@ -693,6 +756,7 @@ static int qcam_g_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *f
693 pix->sizeimage = pix->width * pix->height; 756 pix->sizeimage = pix->width * pix->height;
694 /* Just a guess */ 757 /* Just a guess */
695 pix->colorspace = V4L2_COLORSPACE_SRGB; 758 pix->colorspace = V4L2_COLORSPACE_SRGB;
759 pix->priv = 0;
696 return 0; 760 return 0;
697} 761}
698 762
@@ -718,6 +782,7 @@ static int qcam_try_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format
718 pix->sizeimage = pix->width * pix->height; 782 pix->sizeimage = pix->width * pix->height;
719 /* Just a guess */ 783 /* Just a guess */
720 pix->colorspace = V4L2_COLORSPACE_SRGB; 784 pix->colorspace = V4L2_COLORSPACE_SRGB;
785 pix->priv = 0;
721 return 0; 786 return 0;
722} 787}
723 788
@@ -729,6 +794,8 @@ static int qcam_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *f
729 794
730 if (ret) 795 if (ret)
731 return ret; 796 return ret;
797 if (vb2_is_busy(&qcam->vb_vidq))
798 return -EBUSY;
732 qcam->width = 320; 799 qcam->width = 320;
733 qcam->height = 240; 800 qcam->height = 240;
734 if (pix->height == 60) 801 if (pix->height == 60)
@@ -742,12 +809,10 @@ static int qcam_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *f
742 else 809 else
743 qcam->bpp = 4; 810 qcam->bpp = 4;
744 811
745 mutex_lock(&qcam->lock);
746 qc_setscanmode(qcam); 812 qc_setscanmode(qcam);
747 /* We must update the camera before we grab. We could 813 /* We must update the camera before we grab. We could
748 just have changed the grab size */ 814 just have changed the grab size */
749 qcam->status |= QC_PARAM_CHANGE; 815 qcam->status |= QC_PARAM_CHANGE;
750 mutex_unlock(&qcam->lock);
751 return 0; 816 return 0;
752} 817}
753 818
@@ -792,41 +857,12 @@ static int qcam_enum_framesizes(struct file *file, void *fh,
792 return 0; 857 return 0;
793} 858}
794 859
795static ssize_t qcam_read(struct file *file, char __user *buf,
796 size_t count, loff_t *ppos)
797{
798 struct qcam *qcam = video_drvdata(file);
799 int len;
800 parport_claim_or_block(qcam->pdev);
801
802 mutex_lock(&qcam->lock);
803
804 qc_reset(qcam);
805
806 /* Update the camera parameters if we need to */
807 if (qcam->status & QC_PARAM_CHANGE)
808 qc_set(qcam);
809
810 len = qc_capture(qcam, buf, count);
811
812 mutex_unlock(&qcam->lock);
813
814 parport_release(qcam->pdev);
815 return len;
816}
817
818static unsigned int qcam_poll(struct file *filp, poll_table *wait)
819{
820 return v4l2_ctrl_poll(filp, wait) | POLLIN | POLLRDNORM;
821}
822
823static int qcam_s_ctrl(struct v4l2_ctrl *ctrl) 860static int qcam_s_ctrl(struct v4l2_ctrl *ctrl)
824{ 861{
825 struct qcam *qcam = 862 struct qcam *qcam =
826 container_of(ctrl->handler, struct qcam, hdl); 863 container_of(ctrl->handler, struct qcam, hdl);
827 int ret = 0; 864 int ret = 0;
828 865
829 mutex_lock(&qcam->lock);
830 switch (ctrl->id) { 866 switch (ctrl->id) {
831 case V4L2_CID_BRIGHTNESS: 867 case V4L2_CID_BRIGHTNESS:
832 qcam->brightness = ctrl->val; 868 qcam->brightness = ctrl->val;
@@ -841,21 +877,19 @@ static int qcam_s_ctrl(struct v4l2_ctrl *ctrl)
841 ret = -EINVAL; 877 ret = -EINVAL;
842 break; 878 break;
843 } 879 }
844 if (ret == 0) { 880 if (ret == 0)
845 qc_setscanmode(qcam);
846 qcam->status |= QC_PARAM_CHANGE; 881 qcam->status |= QC_PARAM_CHANGE;
847 }
848 mutex_unlock(&qcam->lock);
849 return ret; 882 return ret;
850} 883}
851 884
852static const struct v4l2_file_operations qcam_fops = { 885static const struct v4l2_file_operations qcam_fops = {
853 .owner = THIS_MODULE, 886 .owner = THIS_MODULE,
854 .open = v4l2_fh_open, 887 .open = v4l2_fh_open,
855 .release = v4l2_fh_release, 888 .release = vb2_fop_release,
856 .poll = qcam_poll, 889 .poll = vb2_fop_poll,
857 .unlocked_ioctl = video_ioctl2, 890 .unlocked_ioctl = video_ioctl2,
858 .read = qcam_read, 891 .read = vb2_fop_read,
892 .mmap = vb2_fop_mmap,
859}; 893};
860 894
861static const struct v4l2_ioctl_ops qcam_ioctl_ops = { 895static const struct v4l2_ioctl_ops qcam_ioctl_ops = {
@@ -868,6 +902,14 @@ static const struct v4l2_ioctl_ops qcam_ioctl_ops = {
868 .vidioc_g_fmt_vid_cap = qcam_g_fmt_vid_cap, 902 .vidioc_g_fmt_vid_cap = qcam_g_fmt_vid_cap,
869 .vidioc_s_fmt_vid_cap = qcam_s_fmt_vid_cap, 903 .vidioc_s_fmt_vid_cap = qcam_s_fmt_vid_cap,
870 .vidioc_try_fmt_vid_cap = qcam_try_fmt_vid_cap, 904 .vidioc_try_fmt_vid_cap = qcam_try_fmt_vid_cap,
905 .vidioc_reqbufs = vb2_ioctl_reqbufs,
906 .vidioc_create_bufs = vb2_ioctl_create_bufs,
907 .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
908 .vidioc_querybuf = vb2_ioctl_querybuf,
909 .vidioc_qbuf = vb2_ioctl_qbuf,
910 .vidioc_dqbuf = vb2_ioctl_dqbuf,
911 .vidioc_streamon = vb2_ioctl_streamon,
912 .vidioc_streamoff = vb2_ioctl_streamoff,
871 .vidioc_log_status = v4l2_ctrl_log_status, 913 .vidioc_log_status = v4l2_ctrl_log_status,
872 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, 914 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
873 .vidioc_unsubscribe_event = v4l2_event_unsubscribe, 915 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
@@ -884,6 +926,8 @@ static struct qcam *qcam_init(struct parport *port)
884{ 926{
885 struct qcam *qcam; 927 struct qcam *qcam;
886 struct v4l2_device *v4l2_dev; 928 struct v4l2_device *v4l2_dev;
929 struct vb2_queue *q;
930 int err;
887 931
888 qcam = kzalloc(sizeof(struct qcam), GFP_KERNEL); 932 qcam = kzalloc(sizeof(struct qcam), GFP_KERNEL);
889 if (qcam == NULL) 933 if (qcam == NULL)
@@ -907,31 +951,45 @@ static struct qcam *qcam_init(struct parport *port)
907 V4L2_CID_GAMMA, 0, 255, 1, 105); 951 V4L2_CID_GAMMA, 0, 255, 1, 105);
908 if (qcam->hdl.error) { 952 if (qcam->hdl.error) {
909 v4l2_err(v4l2_dev, "couldn't register controls\n"); 953 v4l2_err(v4l2_dev, "couldn't register controls\n");
910 v4l2_ctrl_handler_free(&qcam->hdl); 954 goto exit;
911 kfree(qcam); 955 }
912 return NULL; 956
957 mutex_init(&qcam->lock);
958 mutex_init(&qcam->queue_lock);
959
960 /* initialize queue */
961 q = &qcam->vb_vidq;
962 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
963 q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ;
964 q->drv_priv = qcam;
965 q->ops = &qcam_video_qops;
966 q->mem_ops = &vb2_vmalloc_memops;
967 err = vb2_queue_init(q);
968 if (err < 0) {
969 v4l2_err(v4l2_dev, "couldn't init vb2_queue for %s.\n", port->name);
970 goto exit;
913 } 971 }
972 qcam->vdev.queue = q;
973 qcam->vdev.queue->lock = &qcam->queue_lock;
974
914 qcam->pport = port; 975 qcam->pport = port;
915 qcam->pdev = parport_register_device(port, v4l2_dev->name, NULL, NULL, 976 qcam->pdev = parport_register_device(port, v4l2_dev->name, NULL, NULL,
916 NULL, 0, NULL); 977 NULL, 0, NULL);
917 if (qcam->pdev == NULL) { 978 if (qcam->pdev == NULL) {
918 v4l2_err(v4l2_dev, "couldn't register for %s.\n", port->name); 979 v4l2_err(v4l2_dev, "couldn't register for %s.\n", port->name);
919 v4l2_ctrl_handler_free(&qcam->hdl); 980 goto exit;
920 kfree(qcam);
921 return NULL;
922 } 981 }
923 982
924 strlcpy(qcam->vdev.name, "Connectix QuickCam", sizeof(qcam->vdev.name)); 983 strlcpy(qcam->vdev.name, "Connectix QuickCam", sizeof(qcam->vdev.name));
925 qcam->vdev.v4l2_dev = v4l2_dev; 984 qcam->vdev.v4l2_dev = v4l2_dev;
926 qcam->vdev.ctrl_handler = &qcam->hdl; 985 qcam->vdev.ctrl_handler = &qcam->hdl;
927 qcam->vdev.fops = &qcam_fops; 986 qcam->vdev.fops = &qcam_fops;
987 qcam->vdev.lock = &qcam->lock;
928 qcam->vdev.ioctl_ops = &qcam_ioctl_ops; 988 qcam->vdev.ioctl_ops = &qcam_ioctl_ops;
929 set_bit(V4L2_FL_USE_FH_PRIO, &qcam->vdev.flags); 989 set_bit(V4L2_FL_USE_FH_PRIO, &qcam->vdev.flags);
930 qcam->vdev.release = video_device_release_empty; 990 qcam->vdev.release = video_device_release_empty;
931 video_set_drvdata(&qcam->vdev, qcam); 991 video_set_drvdata(&qcam->vdev, qcam);
932 992
933 mutex_init(&qcam->lock);
934
935 qcam->port_mode = (QC_ANY | QC_NOTSET); 993 qcam->port_mode = (QC_ANY | QC_NOTSET);
936 qcam->width = 320; 994 qcam->width = 320;
937 qcam->height = 240; 995 qcam->height = 240;
@@ -945,6 +1003,11 @@ static struct qcam *qcam_init(struct parport *port)
945 qcam->mode = -1; 1003 qcam->mode = -1;
946 qcam->status = QC_PARAM_CHANGE; 1004 qcam->status = QC_PARAM_CHANGE;
947 return qcam; 1005 return qcam;
1006
1007exit:
1008 v4l2_ctrl_handler_free(&qcam->hdl);
1009 kfree(qcam);
1010 return NULL;
948} 1011}
949 1012
950static int qc_calibrate(struct qcam *q) 1013static int qc_calibrate(struct qcam *q)
diff --git a/drivers/media/pci/bt8xx/Makefile b/drivers/media/pci/bt8xx/Makefile
index 5f06597c6a6e..f9fe7c4e7d53 100644
--- a/drivers/media/pci/bt8xx/Makefile
+++ b/drivers/media/pci/bt8xx/Makefile
@@ -8,4 +8,5 @@ obj-$(CONFIG_DVB_BT8XX) += bt878.o dvb-bt8xx.o dst.o dst_ca.o
8ccflags-y += -Idrivers/media/dvb-core 8ccflags-y += -Idrivers/media/dvb-core
9ccflags-y += -Idrivers/media/dvb-frontends 9ccflags-y += -Idrivers/media/dvb-frontends
10ccflags-y += -Idrivers/media/i2c 10ccflags-y += -Idrivers/media/i2c
11ccflags-y += -Idrivers/media/common
11ccflags-y += -Idrivers/media/tuners 12ccflags-y += -Idrivers/media/tuners
diff --git a/drivers/media/pci/bt8xx/bttv-driver.c b/drivers/media/pci/bt8xx/bttv-driver.c
index 45e5d0661b60..ccd18e4ee789 100644
--- a/drivers/media/pci/bt8xx/bttv-driver.c
+++ b/drivers/media/pci/bt8xx/bttv-driver.c
@@ -3835,7 +3835,7 @@ bttv_irq_wakeup_video(struct bttv *btv, struct bttv_buffer_set *wakeup,
3835{ 3835{
3836 struct timeval ts; 3836 struct timeval ts;
3837 3837
3838 do_gettimeofday(&ts); 3838 v4l2_get_timestamp(&ts);
3839 3839
3840 if (wakeup->top == wakeup->bottom) { 3840 if (wakeup->top == wakeup->bottom) {
3841 if (NULL != wakeup->top && curr->top != wakeup->top) { 3841 if (NULL != wakeup->top && curr->top != wakeup->top) {
@@ -3878,7 +3878,7 @@ bttv_irq_wakeup_vbi(struct bttv *btv, struct bttv_buffer *wakeup,
3878 if (NULL == wakeup) 3878 if (NULL == wakeup)
3879 return; 3879 return;
3880 3880
3881 do_gettimeofday(&ts); 3881 v4l2_get_timestamp(&ts);
3882 wakeup->vb.ts = ts; 3882 wakeup->vb.ts = ts;
3883 wakeup->vb.field_count = btv->field_count; 3883 wakeup->vb.field_count = btv->field_count;
3884 wakeup->vb.state = state; 3884 wakeup->vb.state = state;
@@ -3949,7 +3949,7 @@ bttv_irq_wakeup_top(struct bttv *btv)
3949 btv->curr.top = NULL; 3949 btv->curr.top = NULL;
3950 bttv_risc_hook(btv, RISC_SLOT_O_FIELD, NULL, 0); 3950 bttv_risc_hook(btv, RISC_SLOT_O_FIELD, NULL, 0);
3951 3951
3952 do_gettimeofday(&wakeup->vb.ts); 3952 v4l2_get_timestamp(&wakeup->vb.ts);
3953 wakeup->vb.field_count = btv->field_count; 3953 wakeup->vb.field_count = btv->field_count;
3954 wakeup->vb.state = VIDEOBUF_DONE; 3954 wakeup->vb.state = VIDEOBUF_DONE;
3955 wake_up(&wakeup->vb.done); 3955 wake_up(&wakeup->vb.done);
diff --git a/drivers/media/pci/bt8xx/bttv-i2c.c b/drivers/media/pci/bt8xx/bttv-i2c.c
index 5039b8826e0a..c63c643ed1f8 100644
--- a/drivers/media/pci/bt8xx/bttv-i2c.c
+++ b/drivers/media/pci/bt8xx/bttv-i2c.c
@@ -173,7 +173,7 @@ bttv_i2c_sendbytes(struct bttv *btv, const struct i2c_msg *msg, int last)
173 if (i2c_debug) 173 if (i2c_debug)
174 pr_cont(" %02x", msg->buf[cnt]); 174 pr_cont(" %02x", msg->buf[cnt]);
175 } 175 }
176 if (!(xmit & BT878_I2C_NOSTOP)) 176 if (i2c_debug && !(xmit & BT878_I2C_NOSTOP))
177 pr_cont(">\n"); 177 pr_cont(">\n");
178 return msg->len; 178 return msg->len;
179 179
@@ -366,8 +366,7 @@ int init_bttv_i2c(struct bttv *btv)
366 366
367 strlcpy(btv->c.i2c_adap.name, "bttv", 367 strlcpy(btv->c.i2c_adap.name, "bttv",
368 sizeof(btv->c.i2c_adap.name)); 368 sizeof(btv->c.i2c_adap.name));
369 memcpy(&btv->i2c_algo, &bttv_i2c_algo_bit_template, 369 btv->i2c_algo = bttv_i2c_algo_bit_template;
370 sizeof(bttv_i2c_algo_bit_template));
371 btv->i2c_algo.udelay = i2c_udelay; 370 btv->i2c_algo.udelay = i2c_udelay;
372 btv->i2c_algo.data = btv; 371 btv->i2c_algo.data = btv;
373 btv->c.i2c_adap.algo_data = &btv->i2c_algo; 372 btv->c.i2c_adap.algo_data = &btv->i2c_algo;
diff --git a/drivers/media/pci/bt8xx/dst_ca.c b/drivers/media/pci/bt8xx/dst_ca.c
index 7d96fab7d246..0e788fca992c 100644
--- a/drivers/media/pci/bt8xx/dst_ca.c
+++ b/drivers/media/pci/bt8xx/dst_ca.c
@@ -180,11 +180,11 @@ static int ca_get_app_info(struct dst_state *state)
180 put_command_and_length(&state->messages[0], CA_APP_INFO, length); 180 put_command_and_length(&state->messages[0], CA_APP_INFO, length);
181 181
182 // Copy application_type, application_manufacturer and manufacturer_code 182 // Copy application_type, application_manufacturer and manufacturer_code
183 memcpy(&state->messages[4], &state->messages[7], 5); 183 memmove(&state->messages[4], &state->messages[7], 5);
184 184
185 // Set string length and copy string 185 // Set string length and copy string
186 state->messages[9] = str_length; 186 state->messages[9] = str_length;
187 memcpy(&state->messages[10], &state->messages[12], str_length); 187 memmove(&state->messages[10], &state->messages[12], str_length);
188 188
189 return 0; 189 return 0;
190} 190}
diff --git a/drivers/media/pci/cx18/cx18-alsa-main.c b/drivers/media/pci/cx18/cx18-alsa-main.c
index 8e971ff60588..b2c8c3439fea 100644
--- a/drivers/media/pci/cx18/cx18-alsa-main.c
+++ b/drivers/media/pci/cx18/cx18-alsa-main.c
@@ -197,7 +197,7 @@ err_exit:
197 return ret; 197 return ret;
198} 198}
199 199
200static int __init cx18_alsa_load(struct cx18 *cx) 200static int cx18_alsa_load(struct cx18 *cx)
201{ 201{
202 struct v4l2_device *v4l2_dev = &cx->v4l2_dev; 202 struct v4l2_device *v4l2_dev = &cx->v4l2_dev;
203 struct cx18_stream *s; 203 struct cx18_stream *s;
diff --git a/drivers/media/pci/cx18/cx18-alsa-pcm.h b/drivers/media/pci/cx18/cx18-alsa-pcm.h
index d26e51f94577..e2b2c5b01215 100644
--- a/drivers/media/pci/cx18/cx18-alsa-pcm.h
+++ b/drivers/media/pci/cx18/cx18-alsa-pcm.h
@@ -20,7 +20,7 @@
20 * 02111-1307 USA 20 * 02111-1307 USA
21 */ 21 */
22 22
23int __init snd_cx18_pcm_create(struct snd_cx18_card *cxsc); 23int snd_cx18_pcm_create(struct snd_cx18_card *cxsc);
24 24
25/* Used by cx18-mailbox to announce the PCM data to the module */ 25/* Used by cx18-mailbox to announce the PCM data to the module */
26void cx18_alsa_announce_pcm_data(struct snd_cx18_card *card, u8 *pcm_data, 26void cx18_alsa_announce_pcm_data(struct snd_cx18_card *card, u8 *pcm_data,
diff --git a/drivers/media/pci/cx18/cx18-i2c.c b/drivers/media/pci/cx18/cx18-i2c.c
index 4908eb7bcf6c..4af8cd6df95d 100644
--- a/drivers/media/pci/cx18/cx18-i2c.c
+++ b/drivers/media/pci/cx18/cx18-i2c.c
@@ -116,9 +116,6 @@ int cx18_i2c_register(struct cx18 *cx, unsigned idx)
116 const char *type = hw_devicenames[idx]; 116 const char *type = hw_devicenames[idx];
117 u32 hw = 1 << idx; 117 u32 hw = 1 << idx;
118 118
119 if (idx >= ARRAY_SIZE(hw_addrs))
120 return -1;
121
122 if (hw == CX18_HW_TUNER) { 119 if (hw == CX18_HW_TUNER) {
123 /* special tuner group handling */ 120 /* special tuner group handling */
124 sd = v4l2_i2c_new_subdev(&cx->v4l2_dev, 121 sd = v4l2_i2c_new_subdev(&cx->v4l2_dev,
@@ -240,15 +237,13 @@ int init_cx18_i2c(struct cx18 *cx)
240 237
241 for (i = 0; i < 2; i++) { 238 for (i = 0; i < 2; i++) {
242 /* Setup algorithm for adapter */ 239 /* Setup algorithm for adapter */
243 memcpy(&cx->i2c_algo[i], &cx18_i2c_algo_template, 240 cx->i2c_algo[i] = cx18_i2c_algo_template;
244 sizeof(struct i2c_algo_bit_data));
245 cx->i2c_algo_cb_data[i].cx = cx; 241 cx->i2c_algo_cb_data[i].cx = cx;
246 cx->i2c_algo_cb_data[i].bus_index = i; 242 cx->i2c_algo_cb_data[i].bus_index = i;
247 cx->i2c_algo[i].data = &cx->i2c_algo_cb_data[i]; 243 cx->i2c_algo[i].data = &cx->i2c_algo_cb_data[i];
248 244
249 /* Setup adapter */ 245 /* Setup adapter */
250 memcpy(&cx->i2c_adap[i], &cx18_i2c_adap_template, 246 cx->i2c_adap[i] = cx18_i2c_adap_template;
251 sizeof(struct i2c_adapter));
252 cx->i2c_adap[i].algo_data = &cx->i2c_algo[i]; 247 cx->i2c_adap[i].algo_data = &cx->i2c_algo[i];
253 sprintf(cx->i2c_adap[i].name + strlen(cx->i2c_adap[i].name), 248 sprintf(cx->i2c_adap[i].name + strlen(cx->i2c_adap[i].name),
254 " #%d-%d", cx->instance, i); 249 " #%d-%d", cx->instance, i);
diff --git a/drivers/media/pci/cx18/cx18-vbi.c b/drivers/media/pci/cx18/cx18-vbi.c
index 6d3121ff45a2..add99642f1e2 100644
--- a/drivers/media/pci/cx18/cx18-vbi.c
+++ b/drivers/media/pci/cx18/cx18-vbi.c
@@ -84,7 +84,7 @@ static void copy_vbi_data(struct cx18 *cx, int lines, u32 pts_stamp)
84 (the max size of the VBI data is 36 * 43 + 4 bytes). 84 (the max size of the VBI data is 36 * 43 + 4 bytes).
85 So in this case we use the magic number 'ITV0'. */ 85 So in this case we use the magic number 'ITV0'. */
86 memcpy(dst + sd, "ITV0", 4); 86 memcpy(dst + sd, "ITV0", 4);
87 memcpy(dst + sd + 4, dst + sd + 12, line * 43); 87 memmove(dst + sd + 4, dst + sd + 12, line * 43);
88 size = 4 + ((43 * line + 3) & ~3); 88 size = 4 + ((43 * line + 3) & ~3);
89 } else { 89 } else {
90 memcpy(dst + sd, "itv0", 4); 90 memcpy(dst + sd, "itv0", 4);
diff --git a/drivers/media/pci/cx23885/Kconfig b/drivers/media/pci/cx23885/Kconfig
index eafa1144b17d..b3688aa8acc3 100644
--- a/drivers/media/pci/cx23885/Kconfig
+++ b/drivers/media/pci/cx23885/Kconfig
@@ -25,7 +25,10 @@ config VIDEO_CX23885
25 select DVB_CX24116 if MEDIA_SUBDRV_AUTOSELECT 25 select DVB_CX24116 if MEDIA_SUBDRV_AUTOSELECT
26 select DVB_STV0900 if MEDIA_SUBDRV_AUTOSELECT 26 select DVB_STV0900 if MEDIA_SUBDRV_AUTOSELECT
27 select DVB_DS3000 if MEDIA_SUBDRV_AUTOSELECT 27 select DVB_DS3000 if MEDIA_SUBDRV_AUTOSELECT
28 select DVB_TS2020 if MEDIA_SUBDRV_AUTOSELECT
28 select DVB_STV0367 if MEDIA_SUBDRV_AUTOSELECT 29 select DVB_STV0367 if MEDIA_SUBDRV_AUTOSELECT
30 select DVB_TDA10071 if MEDIA_SUBDRV_AUTOSELECT
31 select DVB_A8293 if MEDIA_SUBDRV_AUTOSELECT
29 select MEDIA_TUNER_MT2063 if MEDIA_SUBDRV_AUTOSELECT 32 select MEDIA_TUNER_MT2063 if MEDIA_SUBDRV_AUTOSELECT
30 select MEDIA_TUNER_MT2131 if MEDIA_SUBDRV_AUTOSELECT 33 select MEDIA_TUNER_MT2131 if MEDIA_SUBDRV_AUTOSELECT
31 select MEDIA_TUNER_XC2028 if MEDIA_SUBDRV_AUTOSELECT 34 select MEDIA_TUNER_XC2028 if MEDIA_SUBDRV_AUTOSELECT
diff --git a/drivers/media/pci/cx23885/Makefile b/drivers/media/pci/cx23885/Makefile
index a2cbdcf15a8c..2a2cafb8cf5b 100644
--- a/drivers/media/pci/cx23885/Makefile
+++ b/drivers/media/pci/cx23885/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_VIDEO_CX23885) += cx23885.o
8obj-$(CONFIG_MEDIA_ALTERA_CI) += altera-ci.o 8obj-$(CONFIG_MEDIA_ALTERA_CI) += altera-ci.o
9 9
10ccflags-y += -Idrivers/media/i2c 10ccflags-y += -Idrivers/media/i2c
11ccflags-y += -Idrivers/media/common
11ccflags-y += -Idrivers/media/tuners 12ccflags-y += -Idrivers/media/tuners
12ccflags-y += -Idrivers/media/dvb-core 13ccflags-y += -Idrivers/media/dvb-core
13ccflags-y += -Idrivers/media/dvb-frontends 14ccflags-y += -Idrivers/media/dvb-frontends
diff --git a/drivers/media/pci/cx23885/cx23885-cards.c b/drivers/media/pci/cx23885/cx23885-cards.c
index 6277e145f0b8..7e923f8dd2f5 100644
--- a/drivers/media/pci/cx23885/cx23885-cards.c
+++ b/drivers/media/pci/cx23885/cx23885-cards.c
@@ -572,6 +572,39 @@ struct cx23885_board cx23885_boards[] = {
572 [CX23885_BOARD_PROF_8000] = { 572 [CX23885_BOARD_PROF_8000] = {
573 .name = "Prof Revolution DVB-S2 8000", 573 .name = "Prof Revolution DVB-S2 8000",
574 .portb = CX23885_MPEG_DVB, 574 .portb = CX23885_MPEG_DVB,
575 },
576 [CX23885_BOARD_HAUPPAUGE_HVR4400] = {
577 .name = "Hauppauge WinTV-HVR4400",
578 .portb = CX23885_MPEG_DVB,
579 },
580 [CX23885_BOARD_AVERMEDIA_HC81R] = {
581 .name = "AVerTV Hybrid Express Slim HC81R",
582 .tuner_type = TUNER_XC2028,
583 .tuner_addr = 0x61, /* 0xc2 >> 1 */
584 .tuner_bus = 1,
585 .porta = CX23885_ANALOG_VIDEO,
586 .input = {{
587 .type = CX23885_VMUX_TELEVISION,
588 .vmux = CX25840_VIN2_CH1 |
589 CX25840_VIN5_CH2 |
590 CX25840_NONE0_CH3 |
591 CX25840_NONE1_CH3,
592 .amux = CX25840_AUDIO8,
593 }, {
594 .type = CX23885_VMUX_SVIDEO,
595 .vmux = CX25840_VIN8_CH1 |
596 CX25840_NONE_CH2 |
597 CX25840_VIN7_CH3 |
598 CX25840_SVIDEO_ON,
599 .amux = CX25840_AUDIO6,
600 }, {
601 .type = CX23885_VMUX_COMPONENT,
602 .vmux = CX25840_VIN1_CH1 |
603 CX25840_NONE_CH2 |
604 CX25840_NONE0_CH3 |
605 CX25840_NONE1_CH3,
606 .amux = CX25840_AUDIO6,
607 } },
575 } 608 }
576}; 609};
577const unsigned int cx23885_bcount = ARRAY_SIZE(cx23885_boards); 610const unsigned int cx23885_bcount = ARRAY_SIZE(cx23885_boards);
@@ -788,6 +821,26 @@ struct cx23885_subid cx23885_subids[] = {
788 .subvendor = 0x8000, 821 .subvendor = 0x8000,
789 .subdevice = 0x3034, 822 .subdevice = 0x3034,
790 .card = CX23885_BOARD_PROF_8000, 823 .card = CX23885_BOARD_PROF_8000,
824 }, {
825 .subvendor = 0x0070,
826 .subdevice = 0xc108,
827 .card = CX23885_BOARD_HAUPPAUGE_HVR4400,
828 }, {
829 .subvendor = 0x0070,
830 .subdevice = 0xc138,
831 .card = CX23885_BOARD_HAUPPAUGE_HVR4400,
832 }, {
833 .subvendor = 0x0070,
834 .subdevice = 0xc12a,
835 .card = CX23885_BOARD_HAUPPAUGE_HVR4400,
836 }, {
837 .subvendor = 0x0070,
838 .subdevice = 0xc1f8,
839 .card = CX23885_BOARD_HAUPPAUGE_HVR4400,
840 }, {
841 .subvendor = 0x1461,
842 .subdevice = 0xd939,
843 .card = CX23885_BOARD_AVERMEDIA_HC81R,
791 }, 844 },
792}; 845};
793const unsigned int cx23885_idcount = ARRAY_SIZE(cx23885_subids); 846const unsigned int cx23885_idcount = ARRAY_SIZE(cx23885_subids);
@@ -1012,6 +1065,10 @@ int cx23885_tuner_callback(void *priv, int component, int command, int arg)
1012 case CX23885_BOARD_NETUP_DUAL_DVB_T_C_CI_RF: 1065 case CX23885_BOARD_NETUP_DUAL_DVB_T_C_CI_RF:
1013 altera_ci_tuner_reset(dev, port->nr); 1066 altera_ci_tuner_reset(dev, port->nr);
1014 break; 1067 break;
1068 case CX23885_BOARD_AVERMEDIA_HC81R:
1069 /* XC3028L Reset Command */
1070 bitmask = 1 << 2;
1071 break;
1015 } 1072 }
1016 1073
1017 if (bitmask) { 1074 if (bitmask) {
@@ -1301,6 +1358,42 @@ void cx23885_gpio_setup(struct cx23885_dev *dev)
1301 /* enable irq */ 1358 /* enable irq */
1302 cx_write(GPIO_ISM, 0x00000000);/* INTERRUPTS active low*/ 1359 cx_write(GPIO_ISM, 0x00000000);/* INTERRUPTS active low*/
1303 break; 1360 break;
1361 case CX23885_BOARD_HAUPPAUGE_HVR4400:
1362 /* GPIO-8 tda10071 demod reset */
1363
1364 /* Put the parts into reset and back */
1365 cx23885_gpio_enable(dev, GPIO_8, 1);
1366 cx23885_gpio_clear(dev, GPIO_8);
1367 mdelay(100);
1368 cx23885_gpio_set(dev, GPIO_8);
1369 mdelay(100);
1370 break;
1371 case CX23885_BOARD_AVERMEDIA_HC81R:
1372 cx_clear(MC417_CTL, 1);
1373 /* GPIO-0,1,2 setup direction as output */
1374 cx_set(GP0_IO, 0x00070000);
1375 mdelay(10);
1376 /* AF9013 demod reset */
1377 cx_set(GP0_IO, 0x00010001);
1378 mdelay(10);
1379 cx_clear(GP0_IO, 0x00010001);
1380 mdelay(10);
1381 cx_set(GP0_IO, 0x00010001);
1382 mdelay(10);
1383 /* demod tune? */
1384 cx_clear(GP0_IO, 0x00030003);
1385 mdelay(10);
1386 cx_set(GP0_IO, 0x00020002);
1387 mdelay(10);
1388 cx_set(GP0_IO, 0x00010001);
1389 mdelay(10);
1390 cx_clear(GP0_IO, 0x00020002);
1391 /* XC3028L tuner reset */
1392 cx_set(GP0_IO, 0x00040004);
1393 cx_clear(GP0_IO, 0x00040004);
1394 cx_set(GP0_IO, 0x00040004);
1395 mdelay(60);
1396 break;
1304 } 1397 }
1305} 1398}
1306 1399
@@ -1378,6 +1471,7 @@ int cx23885_ir_init(struct cx23885_dev *dev)
1378 break; 1471 break;
1379 case CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL: 1472 case CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL:
1380 case CX23885_BOARD_TEVII_S470: 1473 case CX23885_BOARD_TEVII_S470:
1474 case CX23885_BOARD_MYGICA_X8507:
1381 if (!enable_885_ir) 1475 if (!enable_885_ir)
1382 break; 1476 break;
1383 dev->sd_ir = cx23885_find_hw(dev, CX23885_HW_AV_CORE); 1477 dev->sd_ir = cx23885_find_hw(dev, CX23885_HW_AV_CORE);
@@ -1420,6 +1514,7 @@ void cx23885_ir_fini(struct cx23885_dev *dev)
1420 case CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL: 1514 case CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL:
1421 case CX23885_BOARD_TEVII_S470: 1515 case CX23885_BOARD_TEVII_S470:
1422 case CX23885_BOARD_HAUPPAUGE_HVR1250: 1516 case CX23885_BOARD_HAUPPAUGE_HVR1250:
1517 case CX23885_BOARD_MYGICA_X8507:
1423 cx23885_irq_remove(dev, PCI_MSK_AV_CORE); 1518 cx23885_irq_remove(dev, PCI_MSK_AV_CORE);
1424 /* sd_ir is a duplicate pointer to the AV Core, just clear it */ 1519 /* sd_ir is a duplicate pointer to the AV Core, just clear it */
1425 dev->sd_ir = NULL; 1520 dev->sd_ir = NULL;
@@ -1464,6 +1559,7 @@ void cx23885_ir_pci_int_enable(struct cx23885_dev *dev)
1464 case CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL: 1559 case CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL:
1465 case CX23885_BOARD_TEVII_S470: 1560 case CX23885_BOARD_TEVII_S470:
1466 case CX23885_BOARD_HAUPPAUGE_HVR1250: 1561 case CX23885_BOARD_HAUPPAUGE_HVR1250:
1562 case CX23885_BOARD_MYGICA_X8507:
1467 if (dev->sd_ir) 1563 if (dev->sd_ir)
1468 cx23885_irq_add_enable(dev, PCI_MSK_AV_CORE); 1564 cx23885_irq_add_enable(dev, PCI_MSK_AV_CORE);
1469 break; 1565 break;
@@ -1509,12 +1605,24 @@ void cx23885_card_setup(struct cx23885_dev *dev)
1509 case CX23885_BOARD_HAUPPAUGE_HVR1210: 1605 case CX23885_BOARD_HAUPPAUGE_HVR1210:
1510 case CX23885_BOARD_HAUPPAUGE_HVR1850: 1606 case CX23885_BOARD_HAUPPAUGE_HVR1850:
1511 case CX23885_BOARD_HAUPPAUGE_HVR1290: 1607 case CX23885_BOARD_HAUPPAUGE_HVR1290:
1608 case CX23885_BOARD_HAUPPAUGE_HVR4400:
1512 if (dev->i2c_bus[0].i2c_rc == 0) 1609 if (dev->i2c_bus[0].i2c_rc == 0)
1513 hauppauge_eeprom(dev, eeprom+0xc0); 1610 hauppauge_eeprom(dev, eeprom+0xc0);
1514 break; 1611 break;
1515 } 1612 }
1516 1613
1517 switch (dev->board) { 1614 switch (dev->board) {
1615 case CX23885_BOARD_AVERMEDIA_HC81R:
1616 /* Defaults for VID B */
1617 ts1->gen_ctrl_val = 0x4; /* Parallel */
1618 ts1->ts_clk_en_val = 0x1; /* Enable TS_CLK */
1619 ts1->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
1620 /* Defaults for VID C */
1621 /* DREQ_POL, SMODE, PUNC_CLK, MCLK_POL Serial bus + punc clk */
1622 ts2->gen_ctrl_val = 0x10e;
1623 ts2->ts_clk_en_val = 0x1; /* Enable TS_CLK */
1624 ts2->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
1625 break;
1518 case CX23885_BOARD_DVICO_FUSIONHDTV_7_DUAL_EXP: 1626 case CX23885_BOARD_DVICO_FUSIONHDTV_7_DUAL_EXP:
1519 case CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP: 1627 case CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP:
1520 ts2->gen_ctrl_val = 0xc; /* Serial bus + punctured clock */ 1628 ts2->gen_ctrl_val = 0xc; /* Serial bus + punctured clock */
@@ -1581,6 +1689,11 @@ void cx23885_card_setup(struct cx23885_dev *dev)
1581 ts2->ts_clk_en_val = 0x1; /* Enable TS_CLK */ 1689 ts2->ts_clk_en_val = 0x1; /* Enable TS_CLK */
1582 ts2->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO; 1690 ts2->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
1583 break; 1691 break;
1692 case CX23885_BOARD_HAUPPAUGE_HVR4400:
1693 ts1->gen_ctrl_val = 0xc; /* Serial bus + punctured clock */
1694 ts1->ts_clk_en_val = 0x1; /* Enable TS_CLK */
1695 ts1->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
1696 break;
1584 case CX23885_BOARD_HAUPPAUGE_HVR1250: 1697 case CX23885_BOARD_HAUPPAUGE_HVR1250:
1585 case CX23885_BOARD_HAUPPAUGE_HVR1500: 1698 case CX23885_BOARD_HAUPPAUGE_HVR1500:
1586 case CX23885_BOARD_HAUPPAUGE_HVR1500Q: 1699 case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
@@ -1636,6 +1749,7 @@ void cx23885_card_setup(struct cx23885_dev *dev)
1636 case CX23885_BOARD_MPX885: 1749 case CX23885_BOARD_MPX885:
1637 case CX23885_BOARD_MYGICA_X8507: 1750 case CX23885_BOARD_MYGICA_X8507:
1638 case CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL: 1751 case CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL:
1752 case CX23885_BOARD_AVERMEDIA_HC81R:
1639 dev->sd_cx25840 = v4l2_i2c_new_subdev(&dev->v4l2_dev, 1753 dev->sd_cx25840 = v4l2_i2c_new_subdev(&dev->v4l2_dev,
1640 &dev->i2c_bus[2].i2c_adap, 1754 &dev->i2c_bus[2].i2c_adap,
1641 "cx25840", 0x88 >> 1, NULL); 1755 "cx25840", 0x88 >> 1, NULL);
diff --git a/drivers/media/pci/cx23885/cx23885-core.c b/drivers/media/pci/cx23885/cx23885-core.c
index f0416a668b4c..268654ac9a9f 100644
--- a/drivers/media/pci/cx23885/cx23885-core.c
+++ b/drivers/media/pci/cx23885/cx23885-core.c
@@ -439,7 +439,7 @@ void cx23885_wakeup(struct cx23885_tsport *port,
439 if ((s16) (count - buf->count) < 0) 439 if ((s16) (count - buf->count) < 0)
440 break; 440 break;
441 441
442 do_gettimeofday(&buf->vb.ts); 442 v4l2_get_timestamp(&buf->vb.ts);
443 dprintk(2, "[%p/%d] wakeup reg=%d buf=%d\n", buf, buf->vb.i, 443 dprintk(2, "[%p/%d] wakeup reg=%d buf=%d\n", buf, buf->vb.i,
444 count, buf->count); 444 count, buf->count);
445 buf->vb.state = VIDEOBUF_DONE; 445 buf->vb.state = VIDEOBUF_DONE;
diff --git a/drivers/media/pci/cx23885/cx23885-dvb.c b/drivers/media/pci/cx23885/cx23885-dvb.c
index 2f5b902e63ae..9c5ed10b2c5e 100644
--- a/drivers/media/pci/cx23885/cx23885-dvb.c
+++ b/drivers/media/pci/cx23885/cx23885-dvb.c
@@ -57,6 +57,7 @@
57#include "netup-init.h" 57#include "netup-init.h"
58#include "lgdt3305.h" 58#include "lgdt3305.h"
59#include "atbm8830.h" 59#include "atbm8830.h"
60#include "ts2020.h"
60#include "ds3000.h" 61#include "ds3000.h"
61#include "cx23885-f300.h" 62#include "cx23885-f300.h"
62#include "altera-ci.h" 63#include "altera-ci.h"
@@ -66,6 +67,8 @@
66#include "stv090x.h" 67#include "stv090x.h"
67#include "stb6100.h" 68#include "stb6100.h"
68#include "stb6100_cfg.h" 69#include "stb6100_cfg.h"
70#include "tda10071.h"
71#include "a8293.h"
69 72
70static unsigned int debug; 73static unsigned int debug;
71 74
@@ -469,6 +472,11 @@ static struct ds3000_config tevii_ds3000_config = {
469 .demod_address = 0x68, 472 .demod_address = 0x68,
470}; 473};
471 474
475static struct ts2020_config tevii_ts2020_config = {
476 .tuner_address = 0x60,
477 .clk_out_div = 1,
478};
479
472static struct cx24116_config dvbworld_cx24116_config = { 480static struct cx24116_config dvbworld_cx24116_config = {
473 .demod_address = 0x05, 481 .demod_address = 0x05,
474}; 482};
@@ -493,20 +501,20 @@ static struct xc5000_config mygica_x8506_xc5000_config = {
493}; 501};
494 502
495static struct stv090x_config prof_8000_stv090x_config = { 503static struct stv090x_config prof_8000_stv090x_config = {
496 .device = STV0903, 504 .device = STV0903,
497 .demod_mode = STV090x_SINGLE, 505 .demod_mode = STV090x_SINGLE,
498 .clk_mode = STV090x_CLK_EXT, 506 .clk_mode = STV090x_CLK_EXT,
499 .xtal = 27000000, 507 .xtal = 27000000,
500 .address = 0x6A, 508 .address = 0x6A,
501 .ts1_mode = STV090x_TSMODE_PARALLEL_PUNCTURED, 509 .ts1_mode = STV090x_TSMODE_PARALLEL_PUNCTURED,
502 .repeater_level = STV090x_RPTLEVEL_64, 510 .repeater_level = STV090x_RPTLEVEL_64,
503 .adc1_range = STV090x_ADC_2Vpp, 511 .adc1_range = STV090x_ADC_2Vpp,
504 .diseqc_envelope_mode = false, 512 .diseqc_envelope_mode = false,
505 513
506 .tuner_get_frequency = stb6100_get_frequency, 514 .tuner_get_frequency = stb6100_get_frequency,
507 .tuner_set_frequency = stb6100_set_frequency, 515 .tuner_set_frequency = stb6100_set_frequency,
508 .tuner_set_bandwidth = stb6100_set_bandwidth, 516 .tuner_set_bandwidth = stb6100_set_bandwidth,
509 .tuner_get_bandwidth = stb6100_get_bandwidth, 517 .tuner_get_bandwidth = stb6100_get_bandwidth,
510}; 518};
511 519
512static struct stb6100_config prof_8000_stb6100_config = { 520static struct stb6100_config prof_8000_stb6100_config = {
@@ -659,6 +667,20 @@ static struct mt2063_config terratec_mt2063_config[] = {
659 }, 667 },
660}; 668};
661 669
670static const struct tda10071_config hauppauge_tda10071_config = {
671 .demod_i2c_addr = 0x05,
672 .tuner_i2c_addr = 0x54,
673 .i2c_wr_max = 64,
674 .ts_mode = TDA10071_TS_SERIAL,
675 .spec_inv = 0,
676 .xtal = 40444000, /* 40.444 MHz */
677 .pll_multiplier = 20,
678};
679
680static const struct a8293_config hauppauge_a8293_config = {
681 .i2c_addr = 0x0b,
682};
683
662static int netup_altera_fpga_rw(void *device, int flag, int data, int read) 684static int netup_altera_fpga_rw(void *device, int flag, int data, int read)
663{ 685{
664 struct cx23885_dev *dev = (struct cx23885_dev *)device; 686 struct cx23885_dev *dev = (struct cx23885_dev *)device;
@@ -1011,8 +1033,11 @@ static int dvb_register(struct cx23885_tsport *port)
1011 fe0->dvb.frontend = dvb_attach(ds3000_attach, 1033 fe0->dvb.frontend = dvb_attach(ds3000_attach,
1012 &tevii_ds3000_config, 1034 &tevii_ds3000_config,
1013 &i2c_bus->i2c_adap); 1035 &i2c_bus->i2c_adap);
1014 if (fe0->dvb.frontend != NULL) 1036 if (fe0->dvb.frontend != NULL) {
1037 dvb_attach(ts2020_attach, fe0->dvb.frontend,
1038 &tevii_ts2020_config, &i2c_bus->i2c_adap);
1015 fe0->dvb.frontend->ops.set_voltage = f300_set_voltage; 1039 fe0->dvb.frontend->ops.set_voltage = f300_set_voltage;
1040 }
1016 1041
1017 break; 1042 break;
1018 case CX23885_BOARD_DVBWORLD_2005: 1043 case CX23885_BOARD_DVBWORLD_2005:
@@ -1242,6 +1267,17 @@ static int dvb_register(struct cx23885_tsport *port)
1242 fe0->dvb.frontend->ops.set_voltage = p8000_set_voltage; 1267 fe0->dvb.frontend->ops.set_voltage = p8000_set_voltage;
1243 } 1268 }
1244 break; 1269 break;
1270 case CX23885_BOARD_HAUPPAUGE_HVR4400:
1271 i2c_bus = &dev->i2c_bus[0];
1272 fe0->dvb.frontend = dvb_attach(tda10071_attach,
1273 &hauppauge_tda10071_config,
1274 &i2c_bus->i2c_adap);
1275 if (fe0->dvb.frontend != NULL) {
1276 dvb_attach(a8293_attach, fe0->dvb.frontend,
1277 &i2c_bus->i2c_adap,
1278 &hauppauge_a8293_config);
1279 }
1280 break;
1245 default: 1281 default:
1246 printk(KERN_INFO "%s: The frontend of your DVB/ATSC card " 1282 printk(KERN_INFO "%s: The frontend of your DVB/ATSC card "
1247 " isn't supported yet\n", 1283 " isn't supported yet\n",
diff --git a/drivers/media/pci/cx23885/cx23885-input.c b/drivers/media/pci/cx23885/cx23885-input.c
index 4f1055a194b5..7875dfbe09ff 100644
--- a/drivers/media/pci/cx23885/cx23885-input.c
+++ b/drivers/media/pci/cx23885/cx23885-input.c
@@ -89,6 +89,7 @@ void cx23885_input_rx_work_handler(struct cx23885_dev *dev, u32 events)
89 case CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL: 89 case CX23885_BOARD_TERRATEC_CINERGY_T_PCIE_DUAL:
90 case CX23885_BOARD_TEVII_S470: 90 case CX23885_BOARD_TEVII_S470:
91 case CX23885_BOARD_HAUPPAUGE_HVR1250: 91 case CX23885_BOARD_HAUPPAUGE_HVR1250:
92 case CX23885_BOARD_MYGICA_X8507:
92 /* 93 /*
93 * The only boards we handle right now. However other boards 94 * The only boards we handle right now. However other boards
94 * using the CX2388x integrated IR controller should be similar 95 * using the CX2388x integrated IR controller should be similar
@@ -140,6 +141,7 @@ static int cx23885_input_ir_start(struct cx23885_dev *dev)
140 case CX23885_BOARD_HAUPPAUGE_HVR1850: 141 case CX23885_BOARD_HAUPPAUGE_HVR1850:
141 case CX23885_BOARD_HAUPPAUGE_HVR1290: 142 case CX23885_BOARD_HAUPPAUGE_HVR1290:
142 case CX23885_BOARD_HAUPPAUGE_HVR1250: 143 case CX23885_BOARD_HAUPPAUGE_HVR1250:
144 case CX23885_BOARD_MYGICA_X8507:
143 /* 145 /*
144 * The IR controller on this board only returns pulse widths. 146 * The IR controller on this board only returns pulse widths.
145 * Any other mode setting will fail to set up the device. 147 * Any other mode setting will fail to set up the device.
@@ -289,6 +291,13 @@ int cx23885_input_init(struct cx23885_dev *dev)
289 /* A guess at the remote */ 291 /* A guess at the remote */
290 rc_map = RC_MAP_TEVII_NEC; 292 rc_map = RC_MAP_TEVII_NEC;
291 break; 293 break;
294 case CX23885_BOARD_MYGICA_X8507:
295 /* Integrated CX23885 IR controller */
296 driver_type = RC_DRIVER_IR_RAW;
297 allowed_protos = RC_BIT_ALL;
298 /* A guess at the remote */
299 rc_map = RC_MAP_TOTAL_MEDIA_IN_HAND_02;
300 break;
292 default: 301 default:
293 return -ENODEV; 302 return -ENODEV;
294 } 303 }
diff --git a/drivers/media/pci/cx23885/cx23885-video.c b/drivers/media/pci/cx23885/cx23885-video.c
index 1a21926ca412..5991bc8dc158 100644
--- a/drivers/media/pci/cx23885/cx23885-video.c
+++ b/drivers/media/pci/cx23885/cx23885-video.c
@@ -300,7 +300,7 @@ void cx23885_video_wakeup(struct cx23885_dev *dev,
300 if ((s16) (count - buf->count) < 0) 300 if ((s16) (count - buf->count) < 0)
301 break; 301 break;
302 302
303 do_gettimeofday(&buf->vb.ts); 303 v4l2_get_timestamp(&buf->vb.ts);
304 dprintk(2, "[%p/%d] wakeup reg=%d buf=%d\n", buf, buf->vb.i, 304 dprintk(2, "[%p/%d] wakeup reg=%d buf=%d\n", buf, buf->vb.i,
305 count, buf->count); 305 count, buf->count);
306 buf->vb.state = VIDEOBUF_DONE; 306 buf->vb.state = VIDEOBUF_DONE;
@@ -509,7 +509,8 @@ static int cx23885_video_mux(struct cx23885_dev *dev, unsigned int input)
509 (dev->board == CX23885_BOARD_HAUPPAUGE_HVR1255) || 509 (dev->board == CX23885_BOARD_HAUPPAUGE_HVR1255) ||
510 (dev->board == CX23885_BOARD_HAUPPAUGE_HVR1255_22111) || 510 (dev->board == CX23885_BOARD_HAUPPAUGE_HVR1255_22111) ||
511 (dev->board == CX23885_BOARD_HAUPPAUGE_HVR1850) || 511 (dev->board == CX23885_BOARD_HAUPPAUGE_HVR1850) ||
512 (dev->board == CX23885_BOARD_MYGICA_X8507)) { 512 (dev->board == CX23885_BOARD_MYGICA_X8507) ||
513 (dev->board == CX23885_BOARD_AVERMEDIA_HC81R)) {
513 /* Configure audio routing */ 514 /* Configure audio routing */
514 v4l2_subdev_call(dev->sd_cx25840, audio, s_routing, 515 v4l2_subdev_call(dev->sd_cx25840, audio, s_routing,
515 INPUT(input)->amux, 0, 0); 516 INPUT(input)->amux, 0, 0);
@@ -1818,8 +1819,7 @@ int cx23885_video_register(struct cx23885_dev *dev)
1818 spin_lock_init(&dev->slock); 1819 spin_lock_init(&dev->slock);
1819 1820
1820 /* Initialize VBI template */ 1821 /* Initialize VBI template */
1821 memcpy(&cx23885_vbi_template, &cx23885_video_template, 1822 cx23885_vbi_template = cx23885_video_template;
1822 sizeof(cx23885_vbi_template));
1823 strcpy(cx23885_vbi_template.name, "cx23885-vbi"); 1823 strcpy(cx23885_vbi_template.name, "cx23885-vbi");
1824 1824
1825 dev->tvnorm = cx23885_video_template.current_norm; 1825 dev->tvnorm = cx23885_video_template.current_norm;
@@ -1878,6 +1878,18 @@ int cx23885_video_register(struct cx23885_dev *dev)
1878 }; 1878 };
1879 v4l2_subdev_call(sd, tuner, s_config, &cfg); 1879 v4l2_subdev_call(sd, tuner, s_config, &cfg);
1880 } 1880 }
1881
1882 if (dev->board == CX23885_BOARD_AVERMEDIA_HC81R) {
1883 struct xc2028_ctrl ctrl = {
1884 .fname = "xc3028L-v36.fw",
1885 .max_len = 64
1886 };
1887 struct v4l2_priv_tun_config cfg = {
1888 .tuner = dev->tuner_type,
1889 .priv = &ctrl
1890 };
1891 v4l2_subdev_call(sd, tuner, s_config, &cfg);
1892 }
1881 } 1893 }
1882 } 1894 }
1883 1895
diff --git a/drivers/media/pci/cx23885/cx23885.h b/drivers/media/pci/cx23885/cx23885.h
index 67f40d31450b..59c322d870f2 100644
--- a/drivers/media/pci/cx23885/cx23885.h
+++ b/drivers/media/pci/cx23885/cx23885.h
@@ -91,6 +91,8 @@
91#define CX23885_BOARD_TEVII_S471 35 91#define CX23885_BOARD_TEVII_S471 35
92#define CX23885_BOARD_HAUPPAUGE_HVR1255_22111 36 92#define CX23885_BOARD_HAUPPAUGE_HVR1255_22111 36
93#define CX23885_BOARD_PROF_8000 37 93#define CX23885_BOARD_PROF_8000 37
94#define CX23885_BOARD_HAUPPAUGE_HVR4400 38
95#define CX23885_BOARD_AVERMEDIA_HC81R 39
94 96
95#define GPIO_0 0x00000001 97#define GPIO_0 0x00000001
96#define GPIO_1 0x00000002 98#define GPIO_1 0x00000002
diff --git a/drivers/media/pci/cx23885/cx23888-ir.c b/drivers/media/pci/cx23885/cx23888-ir.c
index c4bd1e95d33f..d51eed051d59 100644
--- a/drivers/media/pci/cx23885/cx23888-ir.c
+++ b/drivers/media/pci/cx23885/cx23888-ir.c
@@ -1237,13 +1237,11 @@ int cx23888_ir_probe(struct cx23885_dev *dev)
1237 cx23888_ir_write4(dev, CX23888_IR_IRQEN_REG, 0); 1237 cx23888_ir_write4(dev, CX23888_IR_IRQEN_REG, 0);
1238 1238
1239 mutex_init(&state->rx_params_lock); 1239 mutex_init(&state->rx_params_lock);
1240 memcpy(&default_params, &default_rx_params, 1240 default_params = default_rx_params;
1241 sizeof(struct v4l2_subdev_ir_parameters));
1242 v4l2_subdev_call(sd, ir, rx_s_parameters, &default_params); 1241 v4l2_subdev_call(sd, ir, rx_s_parameters, &default_params);
1243 1242
1244 mutex_init(&state->tx_params_lock); 1243 mutex_init(&state->tx_params_lock);
1245 memcpy(&default_params, &default_tx_params, 1244 default_params = default_tx_params;
1246 sizeof(struct v4l2_subdev_ir_parameters));
1247 v4l2_subdev_call(sd, ir, tx_s_parameters, &default_params); 1245 v4l2_subdev_call(sd, ir, tx_s_parameters, &default_params);
1248 } else { 1246 } else {
1249 kfifo_free(&state->rx_kfifo); 1247 kfifo_free(&state->rx_kfifo);
diff --git a/drivers/media/pci/cx25821/Makefile b/drivers/media/pci/cx25821/Makefile
index 5bf3ea4c1556..caa32b7b51f8 100644
--- a/drivers/media/pci/cx25821/Makefile
+++ b/drivers/media/pci/cx25821/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_VIDEO_CX25821) += cx25821.o
8obj-$(CONFIG_VIDEO_CX25821_ALSA) += cx25821-alsa.o 8obj-$(CONFIG_VIDEO_CX25821_ALSA) += cx25821-alsa.o
9 9
10ccflags-y += -Idrivers/media/i2c 10ccflags-y += -Idrivers/media/i2c
11ccflags-y += -Idrivers/media/common
11ccflags-y += -Idrivers/media/tuners 12ccflags-y += -Idrivers/media/tuners
12ccflags-y += -Idrivers/media/dvb-core 13ccflags-y += -Idrivers/media/dvb-core
13ccflags-y += -Idrivers/media/dvb-frontends 14ccflags-y += -Idrivers/media/dvb-frontends
diff --git a/drivers/media/pci/cx25821/cx25821-video.c b/drivers/media/pci/cx25821/cx25821-video.c
index 53b16dd70320..d4de021dc844 100644
--- a/drivers/media/pci/cx25821/cx25821-video.c
+++ b/drivers/media/pci/cx25821/cx25821-video.c
@@ -130,7 +130,7 @@ void cx25821_video_wakeup(struct cx25821_dev *dev, struct cx25821_dmaqueue *q,
130 if ((s16) (count - buf->count) < 0) 130 if ((s16) (count - buf->count) < 0)
131 break; 131 break;
132 132
133 do_gettimeofday(&buf->vb.ts); 133 v4l2_get_timestamp(&buf->vb.ts);
134 buf->vb.state = VIDEOBUF_DONE; 134 buf->vb.state = VIDEOBUF_DONE;
135 list_del(&buf->vb.queue); 135 list_del(&buf->vb.queue);
136 wake_up(&buf->vb.done); 136 wake_up(&buf->vb.done);
diff --git a/drivers/media/pci/cx88/Kconfig b/drivers/media/pci/cx88/Kconfig
index d27fccbf03c4..bb05eca2da29 100644
--- a/drivers/media/pci/cx88/Kconfig
+++ b/drivers/media/pci/cx88/Kconfig
@@ -62,6 +62,8 @@ config VIDEO_CX88_DVB
62 select DVB_STB6000 if MEDIA_SUBDRV_AUTOSELECT 62 select DVB_STB6000 if MEDIA_SUBDRV_AUTOSELECT
63 select DVB_STV0900 if MEDIA_SUBDRV_AUTOSELECT 63 select DVB_STV0900 if MEDIA_SUBDRV_AUTOSELECT
64 select DVB_STB6100 if MEDIA_SUBDRV_AUTOSELECT 64 select DVB_STB6100 if MEDIA_SUBDRV_AUTOSELECT
65 select DVB_DS3000 if MEDIA_SUBDRV_AUTOSELECT
66 select DVB_TS2020 if MEDIA_SUBDRV_AUTOSELECT
65 select MEDIA_TUNER_SIMPLE if MEDIA_SUBDRV_AUTOSELECT 67 select MEDIA_TUNER_SIMPLE if MEDIA_SUBDRV_AUTOSELECT
66 ---help--- 68 ---help---
67 This adds support for DVB/ATSC cards based on the 69 This adds support for DVB/ATSC cards based on the
diff --git a/drivers/media/pci/cx88/Makefile b/drivers/media/pci/cx88/Makefile
index d3679c3ee248..8619c1becee2 100644
--- a/drivers/media/pci/cx88/Makefile
+++ b/drivers/media/pci/cx88/Makefile
@@ -11,6 +11,7 @@ obj-$(CONFIG_VIDEO_CX88_DVB) += cx88-dvb.o
11obj-$(CONFIG_VIDEO_CX88_VP3054) += cx88-vp3054-i2c.o 11obj-$(CONFIG_VIDEO_CX88_VP3054) += cx88-vp3054-i2c.o
12 12
13ccflags-y += -Idrivers/media/i2c 13ccflags-y += -Idrivers/media/i2c
14ccflags-y += -Idrivers/media/common
14ccflags-y += -Idrivers/media/tuners 15ccflags-y += -Idrivers/media/tuners
15ccflags-y += -Idrivers/media/dvb-core 16ccflags-y += -Idrivers/media/dvb-core
16ccflags-y += -Idrivers/media/dvb-frontends 17ccflags-y += -Idrivers/media/dvb-frontends
diff --git a/drivers/media/pci/cx88/cx88-cards.c b/drivers/media/pci/cx88/cx88-cards.c
index 0c255248cbcd..e2e0b8faf7a4 100644
--- a/drivers/media/pci/cx88/cx88-cards.c
+++ b/drivers/media/pci/cx88/cx88-cards.c
@@ -3743,7 +3743,7 @@ struct cx88_core *cx88_core_create(struct pci_dev *pci, int nr)
3743 cx88_card_list(core, pci); 3743 cx88_card_list(core, pci);
3744 } 3744 }
3745 3745
3746 memcpy(&core->board, &cx88_boards[core->boardnr], sizeof(core->board)); 3746 core->board = cx88_boards[core->boardnr];
3747 3747
3748 if (!core->board.num_frontends && (core->board.mpeg & CX88_MPEG_DVB)) 3748 if (!core->board.num_frontends && (core->board.mpeg & CX88_MPEG_DVB))
3749 core->board.num_frontends = 1; 3749 core->board.num_frontends = 1;
diff --git a/drivers/media/pci/cx88/cx88-core.c b/drivers/media/pci/cx88/cx88-core.c
index 19a58754c6e1..39f095c37ffd 100644
--- a/drivers/media/pci/cx88/cx88-core.c
+++ b/drivers/media/pci/cx88/cx88-core.c
@@ -549,7 +549,7 @@ void cx88_wakeup(struct cx88_core *core,
549 * up to 32767 buffers in flight... */ 549 * up to 32767 buffers in flight... */
550 if ((s16) (count - buf->count) < 0) 550 if ((s16) (count - buf->count) < 0)
551 break; 551 break;
552 do_gettimeofday(&buf->vb.ts); 552 v4l2_get_timestamp(&buf->vb.ts);
553 dprintk(2,"[%p/%d] wakeup reg=%d buf=%d\n",buf,buf->vb.i, 553 dprintk(2,"[%p/%d] wakeup reg=%d buf=%d\n",buf,buf->vb.i,
554 count, buf->count); 554 count, buf->count);
555 buf->vb.state = VIDEOBUF_DONE; 555 buf->vb.state = VIDEOBUF_DONE;
diff --git a/drivers/media/pci/cx88/cx88-dvb.c b/drivers/media/pci/cx88/cx88-dvb.c
index 666f83b2f3c0..672b267a2d3e 100644
--- a/drivers/media/pci/cx88/cx88-dvb.c
+++ b/drivers/media/pci/cx88/cx88-dvb.c
@@ -58,6 +58,7 @@
58#include "stb6100.h" 58#include "stb6100.h"
59#include "stb6100_proc.h" 59#include "stb6100_proc.h"
60#include "mb86a16.h" 60#include "mb86a16.h"
61#include "ts2020.h"
61#include "ds3000.h" 62#include "ds3000.h"
62 63
63MODULE_DESCRIPTION("driver for cx2388x based DVB cards"); 64MODULE_DESCRIPTION("driver for cx2388x based DVB cards");
@@ -264,7 +265,7 @@ static struct mb86a16_config twinhan_vp1027 = {
264 .demod_address = 0x08, 265 .demod_address = 0x08,
265}; 266};
266 267
267#if defined(CONFIG_VIDEO_CX88_VP3054) || (defined(CONFIG_VIDEO_CX88_VP3054_MODULE) && defined(MODULE)) 268#if IS_ENABLED(CONFIG_VIDEO_CX88_VP3054)
268static int dntv_live_dvbt_pro_demod_init(struct dvb_frontend* fe) 269static int dntv_live_dvbt_pro_demod_init(struct dvb_frontend* fe)
269{ 270{
270 static const u8 clock_config [] = { 0x89, 0x38, 0x38 }; 271 static const u8 clock_config [] = { 0x89, 0x38, 0x38 };
@@ -700,6 +701,11 @@ static struct ds3000_config tevii_ds3000_config = {
700 .set_ts_params = ds3000_set_ts_param, 701 .set_ts_params = ds3000_set_ts_param,
701}; 702};
702 703
704static struct ts2020_config tevii_ts2020_config = {
705 .tuner_address = 0x60,
706 .clk_out_div = 1,
707};
708
703static const struct stv0900_config prof_7301_stv0900_config = { 709static const struct stv0900_config prof_7301_stv0900_config = {
704 .demod_address = 0x6a, 710 .demod_address = 0x6a,
705/* demod_mode = 0,*/ 711/* demod_mode = 0,*/
@@ -1121,7 +1127,7 @@ static int dvb_register(struct cx8802_dev *dev)
1121 } 1127 }
1122 break; 1128 break;
1123 case CX88_BOARD_DNTV_LIVE_DVB_T_PRO: 1129 case CX88_BOARD_DNTV_LIVE_DVB_T_PRO:
1124#if defined(CONFIG_VIDEO_CX88_VP3054) || (defined(CONFIG_VIDEO_CX88_VP3054_MODULE) && defined(MODULE)) 1130#if IS_ENABLED(CONFIG_VIDEO_CX88_VP3054)
1125 /* MT352 is on a secondary I2C bus made from some GPIO lines */ 1131 /* MT352 is on a secondary I2C bus made from some GPIO lines */
1126 fe0->dvb.frontend = dvb_attach(mt352_attach, &dntv_live_dvbt_pro_config, 1132 fe0->dvb.frontend = dvb_attach(mt352_attach, &dntv_live_dvbt_pro_config,
1127 &dev->vp3054->adap); 1133 &dev->vp3054->adap);
@@ -1466,9 +1472,12 @@ static int dvb_register(struct cx8802_dev *dev)
1466 fe0->dvb.frontend = dvb_attach(ds3000_attach, 1472 fe0->dvb.frontend = dvb_attach(ds3000_attach,
1467 &tevii_ds3000_config, 1473 &tevii_ds3000_config,
1468 &core->i2c_adap); 1474 &core->i2c_adap);
1469 if (fe0->dvb.frontend != NULL) 1475 if (fe0->dvb.frontend != NULL) {
1476 dvb_attach(ts2020_attach, fe0->dvb.frontend,
1477 &tevii_ts2020_config, &core->i2c_adap);
1470 fe0->dvb.frontend->ops.set_voltage = 1478 fe0->dvb.frontend->ops.set_voltage =
1471 tevii_dvbs_set_voltage; 1479 tevii_dvbs_set_voltage;
1480 }
1472 break; 1481 break;
1473 case CX88_BOARD_OMICOM_SS4_PCI: 1482 case CX88_BOARD_OMICOM_SS4_PCI:
1474 case CX88_BOARD_TBS_8920: 1483 case CX88_BOARD_TBS_8920:
diff --git a/drivers/media/pci/cx88/cx88-i2c.c b/drivers/media/pci/cx88/cx88-i2c.c
index de0f1af74e41..cf2d69615838 100644
--- a/drivers/media/pci/cx88/cx88-i2c.c
+++ b/drivers/media/pci/cx88/cx88-i2c.c
@@ -139,8 +139,7 @@ int cx88_i2c_init(struct cx88_core *core, struct pci_dev *pci)
139 if (i2c_udelay<5) 139 if (i2c_udelay<5)
140 i2c_udelay=5; 140 i2c_udelay=5;
141 141
142 memcpy(&core->i2c_algo, &cx8800_i2c_algo_template, 142 core->i2c_algo = cx8800_i2c_algo_template;
143 sizeof(core->i2c_algo));
144 143
145 144
146 core->i2c_adap.dev.parent = &pci->dev; 145 core->i2c_adap.dev.parent = &pci->dev;
diff --git a/drivers/media/pci/cx88/cx88-vp3054-i2c.c b/drivers/media/pci/cx88/cx88-vp3054-i2c.c
index d77f8ecab9d7..deede6e25d94 100644
--- a/drivers/media/pci/cx88/cx88-vp3054-i2c.c
+++ b/drivers/media/pci/cx88/cx88-vp3054-i2c.c
@@ -118,8 +118,7 @@ int vp3054_i2c_probe(struct cx8802_dev *dev)
118 return -ENOMEM; 118 return -ENOMEM;
119 dev->vp3054 = vp3054_i2c; 119 dev->vp3054 = vp3054_i2c;
120 120
121 memcpy(&vp3054_i2c->algo, &vp3054_i2c_algo_template, 121 vp3054_i2c->algo = vp3054_i2c_algo_template;
122 sizeof(vp3054_i2c->algo));
123 122
124 vp3054_i2c->adap.dev.parent = &dev->pci->dev; 123 vp3054_i2c->adap.dev.parent = &dev->pci->dev;
125 strlcpy(vp3054_i2c->adap.name, core->name, 124 strlcpy(vp3054_i2c->adap.name, core->name,
diff --git a/drivers/media/pci/cx88/cx88-vp3054-i2c.h b/drivers/media/pci/cx88/cx88-vp3054-i2c.h
index be99c931dc3e..95d0c60a35e1 100644
--- a/drivers/media/pci/cx88/cx88-vp3054-i2c.h
+++ b/drivers/media/pci/cx88/cx88-vp3054-i2c.h
@@ -30,7 +30,7 @@ struct vp3054_i2c_state {
30}; 30};
31 31
32/* ----------------------------------------------------------------------- */ 32/* ----------------------------------------------------------------------- */
33#if defined(CONFIG_VIDEO_CX88_VP3054) || (defined(CONFIG_VIDEO_CX88_VP3054_MODULE) && defined(MODULE)) 33#if IS_ENABLED(CONFIG_VIDEO_CX88_VP3054)
34int vp3054_i2c_probe(struct cx8802_dev *dev); 34int vp3054_i2c_probe(struct cx8802_dev *dev);
35void vp3054_i2c_remove(struct cx8802_dev *dev); 35void vp3054_i2c_remove(struct cx8802_dev *dev);
36#else 36#else
diff --git a/drivers/media/pci/cx88/cx88.h b/drivers/media/pci/cx88/cx88.h
index ba0dba4a4d22..feff53c0a251 100644
--- a/drivers/media/pci/cx88/cx88.h
+++ b/drivers/media/pci/cx88/cx88.h
@@ -363,7 +363,7 @@ struct cx88_core {
363 unsigned int tuner_formats; 363 unsigned int tuner_formats;
364 364
365 /* config info -- dvb */ 365 /* config info -- dvb */
366#if defined(CONFIG_VIDEO_CX88_DVB) || defined(CONFIG_VIDEO_CX88_DVB_MODULE) 366#if IS_ENABLED(CONFIG_VIDEO_CX88_DVB)
367 int (*prev_set_voltage)(struct dvb_frontend *fe, fe_sec_voltage_t voltage); 367 int (*prev_set_voltage)(struct dvb_frontend *fe, fe_sec_voltage_t voltage);
368#endif 368#endif
369 void (*gate_ctrl)(struct cx88_core *core, int open); 369 void (*gate_ctrl)(struct cx88_core *core, int open);
@@ -562,8 +562,7 @@ struct cx8802_dev {
562 562
563 /* for blackbird only */ 563 /* for blackbird only */
564 struct list_head devlist; 564 struct list_head devlist;
565#if defined(CONFIG_VIDEO_CX88_BLACKBIRD) || \ 565#if IS_ENABLED(CONFIG_VIDEO_CX88_BLACKBIRD)
566 defined(CONFIG_VIDEO_CX88_BLACKBIRD_MODULE)
567 struct video_device *mpeg_dev; 566 struct video_device *mpeg_dev;
568 u32 mailbox; 567 u32 mailbox;
569 int width; 568 int width;
@@ -574,13 +573,12 @@ struct cx8802_dev {
574 struct cx2341x_handler cxhdl; 573 struct cx2341x_handler cxhdl;
575#endif 574#endif
576 575
577#if defined(CONFIG_VIDEO_CX88_DVB) || defined(CONFIG_VIDEO_CX88_DVB_MODULE) 576#if IS_ENABLED(CONFIG_VIDEO_CX88_DVB)
578 /* for dvb only */ 577 /* for dvb only */
579 struct videobuf_dvb_frontends frontends; 578 struct videobuf_dvb_frontends frontends;
580#endif 579#endif
581 580
582#if defined(CONFIG_VIDEO_CX88_VP3054) || \ 581#if IS_ENABLED(CONFIG_VIDEO_CX88_VP3054)
583 defined(CONFIG_VIDEO_CX88_VP3054_MODULE)
584 /* For VP3045 secondary I2C bus support */ 582 /* For VP3045 secondary I2C bus support */
585 struct vp3054_i2c_state *vp3054; 583 struct vp3054_i2c_state *vp3054;
586#endif 584#endif
diff --git a/drivers/media/pci/dm1105/Kconfig b/drivers/media/pci/dm1105/Kconfig
index 013df4e015cd..173daf0c0847 100644
--- a/drivers/media/pci/dm1105/Kconfig
+++ b/drivers/media/pci/dm1105/Kconfig
@@ -8,6 +8,7 @@ config DVB_DM1105
8 select DVB_CX24116 if MEDIA_SUBDRV_AUTOSELECT 8 select DVB_CX24116 if MEDIA_SUBDRV_AUTOSELECT
9 select DVB_SI21XX if MEDIA_SUBDRV_AUTOSELECT 9 select DVB_SI21XX if MEDIA_SUBDRV_AUTOSELECT
10 select DVB_DS3000 if MEDIA_SUBDRV_AUTOSELECT 10 select DVB_DS3000 if MEDIA_SUBDRV_AUTOSELECT
11 select DVB_TS2020 if MEDIA_SUBDRV_AUTOSELECT
11 depends on RC_CORE 12 depends on RC_CORE
12 help 13 help
13 Support for cards based on the SDMC DM1105 PCI chip like 14 Support for cards based on the SDMC DM1105 PCI chip like
diff --git a/drivers/media/pci/dm1105/dm1105.c b/drivers/media/pci/dm1105/dm1105.c
index 904c3ea350f5..026767bed5cd 100644
--- a/drivers/media/pci/dm1105/dm1105.c
+++ b/drivers/media/pci/dm1105/dm1105.c
@@ -45,6 +45,7 @@
45#include "si21xx.h" 45#include "si21xx.h"
46#include "cx24116.h" 46#include "cx24116.h"
47#include "z0194a.h" 47#include "z0194a.h"
48#include "ts2020.h"
48#include "ds3000.h" 49#include "ds3000.h"
49 50
50#define MODULE_NAME "dm1105" 51#define MODULE_NAME "dm1105"
@@ -849,6 +850,11 @@ static struct ds3000_config dvbworld_ds3000_config = {
849 .demod_address = 0x68, 850 .demod_address = 0x68,
850}; 851};
851 852
853static struct ts2020_config dvbworld_ts2020_config = {
854 .tuner_address = 0x60,
855 .clk_out_div = 1,
856};
857
852static int frontend_init(struct dm1105_dev *dev) 858static int frontend_init(struct dm1105_dev *dev)
853{ 859{
854 int ret; 860 int ret;
@@ -898,8 +904,11 @@ static int frontend_init(struct dm1105_dev *dev)
898 dev->fe = dvb_attach( 904 dev->fe = dvb_attach(
899 ds3000_attach, &dvbworld_ds3000_config, 905 ds3000_attach, &dvbworld_ds3000_config,
900 &dev->i2c_adap); 906 &dev->i2c_adap);
901 if (dev->fe) 907 if (dev->fe) {
908 dvb_attach(ts2020_attach, dev->fe,
909 &dvbworld_ts2020_config, &dev->i2c_adap);
902 dev->fe->ops.set_voltage = dm1105_set_voltage; 910 dev->fe->ops.set_voltage = dm1105_set_voltage;
911 }
903 912
904 break; 913 break;
905 case DM1105_BOARD_DVBWORLD_2002: 914 case DM1105_BOARD_DVBWORLD_2002:
diff --git a/drivers/media/pci/ivtv/ivtv-alsa-main.c b/drivers/media/pci/ivtv/ivtv-alsa-main.c
index 4a221c693995..e970cface70e 100644
--- a/drivers/media/pci/ivtv/ivtv-alsa-main.c
+++ b/drivers/media/pci/ivtv/ivtv-alsa-main.c
@@ -205,7 +205,7 @@ err_exit:
205 return ret; 205 return ret;
206} 206}
207 207
208static int __init ivtv_alsa_load(struct ivtv *itv) 208static int ivtv_alsa_load(struct ivtv *itv)
209{ 209{
210 struct v4l2_device *v4l2_dev = &itv->v4l2_dev; 210 struct v4l2_device *v4l2_dev = &itv->v4l2_dev;
211 struct ivtv_stream *s; 211 struct ivtv_stream *s;
diff --git a/drivers/media/pci/ivtv/ivtv-alsa-pcm.h b/drivers/media/pci/ivtv/ivtv-alsa-pcm.h
index 23dfe0d12400..186814e0b2d4 100644
--- a/drivers/media/pci/ivtv/ivtv-alsa-pcm.h
+++ b/drivers/media/pci/ivtv/ivtv-alsa-pcm.h
@@ -20,4 +20,4 @@
20 * 02111-1307 USA 20 * 02111-1307 USA
21 */ 21 */
22 22
23int __init snd_ivtv_pcm_create(struct snd_ivtv_card *itvsc); 23int snd_ivtv_pcm_create(struct snd_ivtv_card *itvsc);
diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
index df88dc4ab555..2928e7287da8 100644
--- a/drivers/media/pci/ivtv/ivtv-driver.c
+++ b/drivers/media/pci/ivtv/ivtv-driver.c
@@ -304,7 +304,7 @@ static void request_modules(struct ivtv *dev)
304 304
305static void flush_request_modules(struct ivtv *dev) 305static void flush_request_modules(struct ivtv *dev)
306{ 306{
307 flush_work_sync(&dev->request_module_wk); 307 flush_work(&dev->request_module_wk);
308} 308}
309#else 309#else
310#define request_modules(dev) 310#define request_modules(dev)
diff --git a/drivers/media/pci/ivtv/ivtv-i2c.c b/drivers/media/pci/ivtv/ivtv-i2c.c
index 46e262becb67..ceed2d87abfd 100644
--- a/drivers/media/pci/ivtv/ivtv-i2c.c
+++ b/drivers/media/pci/ivtv/ivtv-i2c.c
@@ -267,8 +267,6 @@ int ivtv_i2c_register(struct ivtv *itv, unsigned idx)
267 const char *type = hw_devicenames[idx]; 267 const char *type = hw_devicenames[idx];
268 u32 hw = 1 << idx; 268 u32 hw = 1 << idx;
269 269
270 if (idx >= ARRAY_SIZE(hw_addrs))
271 return -1;
272 if (hw == IVTV_HW_TUNER) { 270 if (hw == IVTV_HW_TUNER) {
273 /* special tuner handling */ 271 /* special tuner handling */
274 sd = v4l2_i2c_new_subdev(&itv->v4l2_dev, adap, type, 0, 272 sd = v4l2_i2c_new_subdev(&itv->v4l2_dev, adap, type, 0,
@@ -719,13 +717,10 @@ int init_ivtv_i2c(struct ivtv *itv)
719 return -ENODEV; 717 return -ENODEV;
720 } 718 }
721 if (itv->options.newi2c > 0) { 719 if (itv->options.newi2c > 0) {
722 memcpy(&itv->i2c_adap, &ivtv_i2c_adap_hw_template, 720 itv->i2c_adap = ivtv_i2c_adap_hw_template;
723 sizeof(struct i2c_adapter));
724 } else { 721 } else {
725 memcpy(&itv->i2c_adap, &ivtv_i2c_adap_template, 722 itv->i2c_adap = ivtv_i2c_adap_template;
726 sizeof(struct i2c_adapter)); 723 itv->i2c_algo = ivtv_i2c_algo_template;
727 memcpy(&itv->i2c_algo, &ivtv_i2c_algo_template,
728 sizeof(struct i2c_algo_bit_data));
729 } 724 }
730 itv->i2c_algo.udelay = itv->options.i2c_clock_period / 2; 725 itv->i2c_algo.udelay = itv->options.i2c_clock_period / 2;
731 itv->i2c_algo.data = itv; 726 itv->i2c_algo.data = itv;
@@ -735,8 +730,7 @@ int init_ivtv_i2c(struct ivtv *itv)
735 itv->instance); 730 itv->instance);
736 i2c_set_adapdata(&itv->i2c_adap, &itv->v4l2_dev); 731 i2c_set_adapdata(&itv->i2c_adap, &itv->v4l2_dev);
737 732
738 memcpy(&itv->i2c_client, &ivtv_i2c_client_template, 733 itv->i2c_client = ivtv_i2c_client_template;
739 sizeof(struct i2c_client));
740 itv->i2c_client.adapter = &itv->i2c_adap; 734 itv->i2c_client.adapter = &itv->i2c_adap;
741 itv->i2c_adap.dev.parent = &itv->pdev->dev; 735 itv->i2c_adap.dev.parent = &itv->pdev->dev;
742 736
diff --git a/drivers/media/pci/ivtv/ivtv-vbi.c b/drivers/media/pci/ivtv/ivtv-vbi.c
index 293db806d936..3c156bc70fb4 100644
--- a/drivers/media/pci/ivtv/ivtv-vbi.c
+++ b/drivers/media/pci/ivtv/ivtv-vbi.c
@@ -224,7 +224,7 @@ static void copy_vbi_data(struct ivtv *itv, int lines, u32 pts_stamp)
224 (the max size of the VBI data is 36 * 43 + 4 bytes). 224 (the max size of the VBI data is 36 * 43 + 4 bytes).
225 So in this case we use the magic number 'ITV0'. */ 225 So in this case we use the magic number 'ITV0'. */
226 memcpy(dst + sd, "ITV0", 4); 226 memcpy(dst + sd, "ITV0", 4);
227 memcpy(dst + sd + 4, dst + sd + 12, line * 43); 227 memmove(dst + sd + 4, dst + sd + 12, line * 43);
228 size = 4 + ((43 * line + 3) & ~3); 228 size = 4 + ((43 * line + 3) & ~3);
229 } else { 229 } else {
230 memcpy(dst + sd, "itv0", 4); 230 memcpy(dst + sd, "itv0", 4);
@@ -532,7 +532,7 @@ void ivtv_vbi_work_handler(struct ivtv *itv)
532 while (vi->cc_payload_idx) { 532 while (vi->cc_payload_idx) {
533 cc = vi->cc_payload[0]; 533 cc = vi->cc_payload[0];
534 534
535 memcpy(vi->cc_payload, vi->cc_payload + 1, 535 memmove(vi->cc_payload, vi->cc_payload + 1,
536 sizeof(vi->cc_payload) - sizeof(vi->cc_payload[0])); 536 sizeof(vi->cc_payload) - sizeof(vi->cc_payload[0]));
537 vi->cc_payload_idx--; 537 vi->cc_payload_idx--;
538 if (vi->cc_payload_idx && cc.odd[0] == 0x80 && cc.odd[1] == 0x80) 538 if (vi->cc_payload_idx && cc.odd[0] == 0x80 && cc.odd[1] == 0x80)
diff --git a/drivers/media/pci/mantis/mantis_ca.c b/drivers/media/pci/mantis/mantis_ca.c
index 3d7046909009..60c6c2f24066 100644
--- a/drivers/media/pci/mantis/mantis_ca.c
+++ b/drivers/media/pci/mantis/mantis_ca.c
@@ -198,11 +198,12 @@ void mantis_ca_exit(struct mantis_pci *mantis)
198 struct mantis_ca *ca = mantis->mantis_ca; 198 struct mantis_ca *ca = mantis->mantis_ca;
199 199
200 dprintk(MANTIS_DEBUG, 1, "Mantis CA exit"); 200 dprintk(MANTIS_DEBUG, 1, "Mantis CA exit");
201 if (!ca)
202 return;
201 203
202 mantis_evmgr_exit(ca); 204 mantis_evmgr_exit(ca);
203 dprintk(MANTIS_ERROR, 1, "Unregistering EN50221 device"); 205 dprintk(MANTIS_ERROR, 1, "Unregistering EN50221 device");
204 if (ca) 206 dvb_ca_en50221_release(&ca->en50221);
205 dvb_ca_en50221_release(&ca->en50221);
206 207
207 kfree(ca); 208 kfree(ca);
208} 209}
diff --git a/drivers/media/pci/meye/meye.c b/drivers/media/pci/meye/meye.c
index 049e18667cd0..7859c43479d7 100644
--- a/drivers/media/pci/meye/meye.c
+++ b/drivers/media/pci/meye/meye.c
@@ -35,6 +35,8 @@
35#include <media/v4l2-common.h> 35#include <media/v4l2-common.h>
36#include <media/v4l2-device.h> 36#include <media/v4l2-device.h>
37#include <media/v4l2-ioctl.h> 37#include <media/v4l2-ioctl.h>
38#include <media/v4l2-fh.h>
39#include <media/v4l2-event.h>
38#include <asm/uaccess.h> 40#include <asm/uaccess.h>
39#include <asm/io.h> 41#include <asm/io.h>
40#include <linux/delay.h> 42#include <linux/delay.h>
@@ -811,7 +813,7 @@ again:
811 mchip_hsize() * mchip_vsize() * 2); 813 mchip_hsize() * mchip_vsize() * 2);
812 meye.grab_buffer[reqnr].size = mchip_hsize() * mchip_vsize() * 2; 814 meye.grab_buffer[reqnr].size = mchip_hsize() * mchip_vsize() * 2;
813 meye.grab_buffer[reqnr].state = MEYE_BUF_DONE; 815 meye.grab_buffer[reqnr].state = MEYE_BUF_DONE;
814 do_gettimeofday(&meye.grab_buffer[reqnr].timestamp); 816 v4l2_get_timestamp(&meye.grab_buffer[reqnr].timestamp);
815 meye.grab_buffer[reqnr].sequence = sequence++; 817 meye.grab_buffer[reqnr].sequence = sequence++;
816 kfifo_in_locked(&meye.doneq, (unsigned char *)&reqnr, 818 kfifo_in_locked(&meye.doneq, (unsigned char *)&reqnr,
817 sizeof(int), &meye.doneq_lock); 819 sizeof(int), &meye.doneq_lock);
@@ -832,7 +834,7 @@ again:
832 size); 834 size);
833 meye.grab_buffer[reqnr].size = size; 835 meye.grab_buffer[reqnr].size = size;
834 meye.grab_buffer[reqnr].state = MEYE_BUF_DONE; 836 meye.grab_buffer[reqnr].state = MEYE_BUF_DONE;
835 do_gettimeofday(&meye.grab_buffer[reqnr].timestamp); 837 v4l2_get_timestamp(&meye.grab_buffer[reqnr].timestamp);
836 meye.grab_buffer[reqnr].sequence = sequence++; 838 meye.grab_buffer[reqnr].sequence = sequence++;
837 kfifo_in_locked(&meye.doneq, (unsigned char *)&reqnr, 839 kfifo_in_locked(&meye.doneq, (unsigned char *)&reqnr,
838 sizeof(int), &meye.doneq_lock); 840 sizeof(int), &meye.doneq_lock);
@@ -865,7 +867,7 @@ static int meye_open(struct file *file)
865 meye.grab_buffer[i].state = MEYE_BUF_UNUSED; 867 meye.grab_buffer[i].state = MEYE_BUF_UNUSED;
866 kfifo_reset(&meye.grabq); 868 kfifo_reset(&meye.grabq);
867 kfifo_reset(&meye.doneq); 869 kfifo_reset(&meye.doneq);
868 return 0; 870 return v4l2_fh_open(file);
869} 871}
870 872
871static int meye_release(struct file *file) 873static int meye_release(struct file *file)
@@ -873,7 +875,7 @@ static int meye_release(struct file *file)
873 mchip_hic_stop(); 875 mchip_hic_stop();
874 mchip_dma_free(); 876 mchip_dma_free();
875 clear_bit(0, &meye.in_use); 877 clear_bit(0, &meye.in_use);
876 return 0; 878 return v4l2_fh_release(file);
877} 879}
878 880
879static int meyeioc_g_params(struct meye_params *p) 881static int meyeioc_g_params(struct meye_params *p)
@@ -1032,8 +1034,9 @@ static int vidioc_querycap(struct file *file, void *fh,
1032 cap->version = (MEYE_DRIVER_MAJORVERSION << 8) + 1034 cap->version = (MEYE_DRIVER_MAJORVERSION << 8) +
1033 MEYE_DRIVER_MINORVERSION; 1035 MEYE_DRIVER_MINORVERSION;
1034 1036
1035 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | 1037 cap->device_caps = V4L2_CAP_VIDEO_CAPTURE |
1036 V4L2_CAP_STREAMING; 1038 V4L2_CAP_STREAMING;
1039 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
1037 1040
1038 return 0; 1041 return 0;
1039} 1042}
@@ -1063,191 +1066,50 @@ static int vidioc_s_input(struct file *file, void *fh, unsigned int i)
1063 return 0; 1066 return 0;
1064} 1067}
1065 1068
1066static int vidioc_queryctrl(struct file *file, void *fh, 1069static int meye_s_ctrl(struct v4l2_ctrl *ctrl)
1067 struct v4l2_queryctrl *c)
1068{
1069 switch (c->id) {
1070
1071 case V4L2_CID_BRIGHTNESS:
1072 c->type = V4L2_CTRL_TYPE_INTEGER;
1073 strcpy(c->name, "Brightness");
1074 c->minimum = 0;
1075 c->maximum = 63;
1076 c->step = 1;
1077 c->default_value = 32;
1078 c->flags = 0;
1079 break;
1080 case V4L2_CID_HUE:
1081 c->type = V4L2_CTRL_TYPE_INTEGER;
1082 strcpy(c->name, "Hue");
1083 c->minimum = 0;
1084 c->maximum = 63;
1085 c->step = 1;
1086 c->default_value = 32;
1087 c->flags = 0;
1088 break;
1089 case V4L2_CID_CONTRAST:
1090 c->type = V4L2_CTRL_TYPE_INTEGER;
1091 strcpy(c->name, "Contrast");
1092 c->minimum = 0;
1093 c->maximum = 63;
1094 c->step = 1;
1095 c->default_value = 32;
1096 c->flags = 0;
1097 break;
1098 case V4L2_CID_SATURATION:
1099 c->type = V4L2_CTRL_TYPE_INTEGER;
1100 strcpy(c->name, "Saturation");
1101 c->minimum = 0;
1102 c->maximum = 63;
1103 c->step = 1;
1104 c->default_value = 32;
1105 c->flags = 0;
1106 break;
1107 case V4L2_CID_AGC:
1108 c->type = V4L2_CTRL_TYPE_INTEGER;
1109 strcpy(c->name, "Agc");
1110 c->minimum = 0;
1111 c->maximum = 63;
1112 c->step = 1;
1113 c->default_value = 48;
1114 c->flags = 0;
1115 break;
1116 case V4L2_CID_MEYE_SHARPNESS:
1117 case V4L2_CID_SHARPNESS:
1118 c->type = V4L2_CTRL_TYPE_INTEGER;
1119 strcpy(c->name, "Sharpness");
1120 c->minimum = 0;
1121 c->maximum = 63;
1122 c->step = 1;
1123 c->default_value = 32;
1124
1125 /* Continue to report legacy private SHARPNESS ctrl but
1126 * say it is disabled in preference to ctrl in the spec
1127 */
1128 c->flags = (c->id == V4L2_CID_SHARPNESS) ? 0 :
1129 V4L2_CTRL_FLAG_DISABLED;
1130 break;
1131 case V4L2_CID_PICTURE:
1132 c->type = V4L2_CTRL_TYPE_INTEGER;
1133 strcpy(c->name, "Picture");
1134 c->minimum = 0;
1135 c->maximum = 63;
1136 c->step = 1;
1137 c->default_value = 0;
1138 c->flags = 0;
1139 break;
1140 case V4L2_CID_JPEGQUAL:
1141 c->type = V4L2_CTRL_TYPE_INTEGER;
1142 strcpy(c->name, "JPEG quality");
1143 c->minimum = 0;
1144 c->maximum = 10;
1145 c->step = 1;
1146 c->default_value = 8;
1147 c->flags = 0;
1148 break;
1149 case V4L2_CID_FRAMERATE:
1150 c->type = V4L2_CTRL_TYPE_INTEGER;
1151 strcpy(c->name, "Framerate");
1152 c->minimum = 0;
1153 c->maximum = 31;
1154 c->step = 1;
1155 c->default_value = 0;
1156 c->flags = 0;
1157 break;
1158 default:
1159 return -EINVAL;
1160 }
1161
1162 return 0;
1163}
1164
1165static int vidioc_s_ctrl(struct file *file, void *fh, struct v4l2_control *c)
1166{ 1070{
1167 mutex_lock(&meye.lock); 1071 mutex_lock(&meye.lock);
1168 switch (c->id) { 1072 switch (ctrl->id) {
1169 case V4L2_CID_BRIGHTNESS: 1073 case V4L2_CID_BRIGHTNESS:
1170 sony_pic_camera_command( 1074 sony_pic_camera_command(
1171 SONY_PIC_COMMAND_SETCAMERABRIGHTNESS, c->value); 1075 SONY_PIC_COMMAND_SETCAMERABRIGHTNESS, ctrl->val);
1172 meye.brightness = c->value << 10; 1076 meye.brightness = ctrl->val << 10;
1173 break; 1077 break;
1174 case V4L2_CID_HUE: 1078 case V4L2_CID_HUE:
1175 sony_pic_camera_command( 1079 sony_pic_camera_command(
1176 SONY_PIC_COMMAND_SETCAMERAHUE, c->value); 1080 SONY_PIC_COMMAND_SETCAMERAHUE, ctrl->val);
1177 meye.hue = c->value << 10; 1081 meye.hue = ctrl->val << 10;
1178 break; 1082 break;
1179 case V4L2_CID_CONTRAST: 1083 case V4L2_CID_CONTRAST:
1180 sony_pic_camera_command( 1084 sony_pic_camera_command(
1181 SONY_PIC_COMMAND_SETCAMERACONTRAST, c->value); 1085 SONY_PIC_COMMAND_SETCAMERACONTRAST, ctrl->val);
1182 meye.contrast = c->value << 10; 1086 meye.contrast = ctrl->val << 10;
1183 break; 1087 break;
1184 case V4L2_CID_SATURATION: 1088 case V4L2_CID_SATURATION:
1185 sony_pic_camera_command( 1089 sony_pic_camera_command(
1186 SONY_PIC_COMMAND_SETCAMERACOLOR, c->value); 1090 SONY_PIC_COMMAND_SETCAMERACOLOR, ctrl->val);
1187 meye.colour = c->value << 10; 1091 meye.colour = ctrl->val << 10;
1188 break; 1092 break;
1189 case V4L2_CID_AGC: 1093 case V4L2_CID_MEYE_AGC:
1190 sony_pic_camera_command( 1094 sony_pic_camera_command(
1191 SONY_PIC_COMMAND_SETCAMERAAGC, c->value); 1095 SONY_PIC_COMMAND_SETCAMERAAGC, ctrl->val);
1192 meye.params.agc = c->value; 1096 meye.params.agc = ctrl->val;
1193 break; 1097 break;
1194 case V4L2_CID_SHARPNESS: 1098 case V4L2_CID_SHARPNESS:
1195 case V4L2_CID_MEYE_SHARPNESS:
1196 sony_pic_camera_command( 1099 sony_pic_camera_command(
1197 SONY_PIC_COMMAND_SETCAMERASHARPNESS, c->value); 1100 SONY_PIC_COMMAND_SETCAMERASHARPNESS, ctrl->val);
1198 meye.params.sharpness = c->value; 1101 meye.params.sharpness = ctrl->val;
1199 break; 1102 break;
1200 case V4L2_CID_PICTURE: 1103 case V4L2_CID_MEYE_PICTURE:
1201 sony_pic_camera_command( 1104 sony_pic_camera_command(
1202 SONY_PIC_COMMAND_SETCAMERAPICTURE, c->value); 1105 SONY_PIC_COMMAND_SETCAMERAPICTURE, ctrl->val);
1203 meye.params.picture = c->value; 1106 meye.params.picture = ctrl->val;
1204 break; 1107 break;
1205 case V4L2_CID_JPEGQUAL: 1108 case V4L2_CID_JPEG_COMPRESSION_QUALITY:
1206 meye.params.quality = c->value; 1109 meye.params.quality = ctrl->val;
1207 break; 1110 break;
1208 case V4L2_CID_FRAMERATE: 1111 case V4L2_CID_MEYE_FRAMERATE:
1209 meye.params.framerate = c->value; 1112 meye.params.framerate = ctrl->val;
1210 break;
1211 default:
1212 mutex_unlock(&meye.lock);
1213 return -EINVAL;
1214 }
1215 mutex_unlock(&meye.lock);
1216
1217 return 0;
1218}
1219
1220static int vidioc_g_ctrl(struct file *file, void *fh, struct v4l2_control *c)
1221{
1222 mutex_lock(&meye.lock);
1223 switch (c->id) {
1224 case V4L2_CID_BRIGHTNESS:
1225 c->value = meye.brightness >> 10;
1226 break;
1227 case V4L2_CID_HUE:
1228 c->value = meye.hue >> 10;
1229 break;
1230 case V4L2_CID_CONTRAST:
1231 c->value = meye.contrast >> 10;
1232 break;
1233 case V4L2_CID_SATURATION:
1234 c->value = meye.colour >> 10;
1235 break;
1236 case V4L2_CID_AGC:
1237 c->value = meye.params.agc;
1238 break;
1239 case V4L2_CID_SHARPNESS:
1240 case V4L2_CID_MEYE_SHARPNESS:
1241 c->value = meye.params.sharpness;
1242 break;
1243 case V4L2_CID_PICTURE:
1244 c->value = meye.params.picture;
1245 break;
1246 case V4L2_CID_JPEGQUAL:
1247 c->value = meye.params.quality;
1248 break;
1249 case V4L2_CID_FRAMERATE:
1250 c->value = meye.params.framerate;
1251 break; 1113 break;
1252 default: 1114 default:
1253 mutex_unlock(&meye.lock); 1115 mutex_unlock(&meye.lock);
@@ -1426,7 +1288,7 @@ static int vidioc_querybuf(struct file *file, void *fh, struct v4l2_buffer *buf)
1426 return -EINVAL; 1288 return -EINVAL;
1427 1289
1428 buf->bytesused = meye.grab_buffer[index].size; 1290 buf->bytesused = meye.grab_buffer[index].size;
1429 buf->flags = V4L2_BUF_FLAG_MAPPED; 1291 buf->flags = V4L2_BUF_FLAG_MAPPED | V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1430 1292
1431 if (meye.grab_buffer[index].state == MEYE_BUF_USING) 1293 if (meye.grab_buffer[index].state == MEYE_BUF_USING)
1432 buf->flags |= V4L2_BUF_FLAG_QUEUED; 1294 buf->flags |= V4L2_BUF_FLAG_QUEUED;
@@ -1499,7 +1361,7 @@ static int vidioc_dqbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
1499 1361
1500 buf->index = reqnr; 1362 buf->index = reqnr;
1501 buf->bytesused = meye.grab_buffer[reqnr].size; 1363 buf->bytesused = meye.grab_buffer[reqnr].size;
1502 buf->flags = V4L2_BUF_FLAG_MAPPED; 1364 buf->flags = V4L2_BUF_FLAG_MAPPED | V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1503 buf->field = V4L2_FIELD_NONE; 1365 buf->field = V4L2_FIELD_NONE;
1504 buf->timestamp = meye.grab_buffer[reqnr].timestamp; 1366 buf->timestamp = meye.grab_buffer[reqnr].timestamp;
1505 buf->sequence = meye.grab_buffer[reqnr].sequence; 1367 buf->sequence = meye.grab_buffer[reqnr].sequence;
@@ -1577,12 +1439,12 @@ static long vidioc_default(struct file *file, void *fh, bool valid_prio,
1577 1439
1578static unsigned int meye_poll(struct file *file, poll_table *wait) 1440static unsigned int meye_poll(struct file *file, poll_table *wait)
1579{ 1441{
1580 unsigned int res = 0; 1442 unsigned int res = v4l2_ctrl_poll(file, wait);
1581 1443
1582 mutex_lock(&meye.lock); 1444 mutex_lock(&meye.lock);
1583 poll_wait(file, &meye.proc_list, wait); 1445 poll_wait(file, &meye.proc_list, wait);
1584 if (kfifo_len(&meye.doneq)) 1446 if (kfifo_len(&meye.doneq))
1585 res = POLLIN | POLLRDNORM; 1447 res |= POLLIN | POLLRDNORM;
1586 mutex_unlock(&meye.lock); 1448 mutex_unlock(&meye.lock);
1587 return res; 1449 return res;
1588} 1450}
@@ -1669,9 +1531,6 @@ static const struct v4l2_ioctl_ops meye_ioctl_ops = {
1669 .vidioc_enum_input = vidioc_enum_input, 1531 .vidioc_enum_input = vidioc_enum_input,
1670 .vidioc_g_input = vidioc_g_input, 1532 .vidioc_g_input = vidioc_g_input,
1671 .vidioc_s_input = vidioc_s_input, 1533 .vidioc_s_input = vidioc_s_input,
1672 .vidioc_queryctrl = vidioc_queryctrl,
1673 .vidioc_s_ctrl = vidioc_s_ctrl,
1674 .vidioc_g_ctrl = vidioc_g_ctrl,
1675 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, 1534 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
1676 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap, 1535 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
1677 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, 1536 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
@@ -1682,6 +1541,9 @@ static const struct v4l2_ioctl_ops meye_ioctl_ops = {
1682 .vidioc_dqbuf = vidioc_dqbuf, 1541 .vidioc_dqbuf = vidioc_dqbuf,
1683 .vidioc_streamon = vidioc_streamon, 1542 .vidioc_streamon = vidioc_streamon,
1684 .vidioc_streamoff = vidioc_streamoff, 1543 .vidioc_streamoff = vidioc_streamoff,
1544 .vidioc_log_status = v4l2_ctrl_log_status,
1545 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1546 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1685 .vidioc_default = vidioc_default, 1547 .vidioc_default = vidioc_default,
1686}; 1548};
1687 1549
@@ -1692,6 +1554,10 @@ static struct video_device meye_template = {
1692 .release = video_device_release, 1554 .release = video_device_release,
1693}; 1555};
1694 1556
1557static const struct v4l2_ctrl_ops meye_ctrl_ops = {
1558 .s_ctrl = meye_s_ctrl,
1559};
1560
1695#ifdef CONFIG_PM 1561#ifdef CONFIG_PM
1696static int meye_suspend(struct pci_dev *pdev, pm_message_t state) 1562static int meye_suspend(struct pci_dev *pdev, pm_message_t state)
1697{ 1563{
@@ -1730,6 +1596,32 @@ static int meye_resume(struct pci_dev *pdev)
1730 1596
1731static int meye_probe(struct pci_dev *pcidev, const struct pci_device_id *ent) 1597static int meye_probe(struct pci_dev *pcidev, const struct pci_device_id *ent)
1732{ 1598{
1599 static const struct v4l2_ctrl_config ctrl_agc = {
1600 .id = V4L2_CID_MEYE_AGC,
1601 .type = V4L2_CTRL_TYPE_INTEGER,
1602 .ops = &meye_ctrl_ops,
1603 .name = "AGC",
1604 .max = 63,
1605 .step = 1,
1606 .def = 48,
1607 .flags = V4L2_CTRL_FLAG_SLIDER,
1608 };
1609 static const struct v4l2_ctrl_config ctrl_picture = {
1610 .id = V4L2_CID_MEYE_PICTURE,
1611 .type = V4L2_CTRL_TYPE_INTEGER,
1612 .ops = &meye_ctrl_ops,
1613 .name = "Picture",
1614 .max = 63,
1615 .step = 1,
1616 };
1617 static const struct v4l2_ctrl_config ctrl_framerate = {
1618 .id = V4L2_CID_MEYE_FRAMERATE,
1619 .type = V4L2_CTRL_TYPE_INTEGER,
1620 .ops = &meye_ctrl_ops,
1621 .name = "Framerate",
1622 .max = 31,
1623 .step = 1,
1624 };
1733 struct v4l2_device *v4l2_dev = &meye.v4l2_dev; 1625 struct v4l2_device *v4l2_dev = &meye.v4l2_dev;
1734 int ret = -EBUSY; 1626 int ret = -EBUSY;
1735 unsigned long mchip_adr; 1627 unsigned long mchip_adr;
@@ -1833,24 +1725,31 @@ static int meye_probe(struct pci_dev *pcidev, const struct pci_device_id *ent)
1833 1725
1834 mutex_init(&meye.lock); 1726 mutex_init(&meye.lock);
1835 init_waitqueue_head(&meye.proc_list); 1727 init_waitqueue_head(&meye.proc_list);
1836 meye.brightness = 32 << 10; 1728
1837 meye.hue = 32 << 10; 1729 v4l2_ctrl_handler_init(&meye.hdl, 3);
1838 meye.colour = 32 << 10; 1730 v4l2_ctrl_new_std(&meye.hdl, &meye_ctrl_ops,
1839 meye.contrast = 32 << 10; 1731 V4L2_CID_BRIGHTNESS, 0, 63, 1, 32);
1840 meye.params.subsample = 0; 1732 v4l2_ctrl_new_std(&meye.hdl, &meye_ctrl_ops,
1841 meye.params.quality = 8; 1733 V4L2_CID_HUE, 0, 63, 1, 32);
1842 meye.params.sharpness = 32; 1734 v4l2_ctrl_new_std(&meye.hdl, &meye_ctrl_ops,
1843 meye.params.agc = 48; 1735 V4L2_CID_CONTRAST, 0, 63, 1, 32);
1844 meye.params.picture = 0; 1736 v4l2_ctrl_new_std(&meye.hdl, &meye_ctrl_ops,
1845 meye.params.framerate = 0; 1737 V4L2_CID_SATURATION, 0, 63, 1, 32);
1846 1738 v4l2_ctrl_new_custom(&meye.hdl, &ctrl_agc, NULL);
1847 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERABRIGHTNESS, 32); 1739 v4l2_ctrl_new_std(&meye.hdl, &meye_ctrl_ops,
1848 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERAHUE, 32); 1740 V4L2_CID_SHARPNESS, 0, 63, 1, 32);
1849 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERACOLOR, 32); 1741 v4l2_ctrl_new_custom(&meye.hdl, &ctrl_picture, NULL);
1850 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERACONTRAST, 32); 1742 v4l2_ctrl_new_std(&meye.hdl, &meye_ctrl_ops,
1851 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERASHARPNESS, 32); 1743 V4L2_CID_JPEG_COMPRESSION_QUALITY, 0, 10, 1, 8);
1852 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERAPICTURE, 0); 1744 v4l2_ctrl_new_custom(&meye.hdl, &ctrl_framerate, NULL);
1853 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERAAGC, 48); 1745 if (meye.hdl.error) {
1746 v4l2_err(v4l2_dev, "couldn't register controls\n");
1747 goto outvideoreg;
1748 }
1749
1750 v4l2_ctrl_handler_setup(&meye.hdl);
1751 meye.vdev->ctrl_handler = &meye.hdl;
1752 set_bit(V4L2_FL_USE_FH_PRIO, &meye.vdev->flags);
1854 1753
1855 if (video_register_device(meye.vdev, VFL_TYPE_GRABBER, 1754 if (video_register_device(meye.vdev, VFL_TYPE_GRABBER,
1856 video_nr) < 0) { 1755 video_nr) < 0) {
@@ -1866,6 +1765,7 @@ static int meye_probe(struct pci_dev *pcidev, const struct pci_device_id *ent)
1866 return 0; 1765 return 0;
1867 1766
1868outvideoreg: 1767outvideoreg:
1768 v4l2_ctrl_handler_free(&meye.hdl);
1869 free_irq(meye.mchip_irq, meye_irq); 1769 free_irq(meye.mchip_irq, meye_irq);
1870outreqirq: 1770outreqirq:
1871 iounmap(meye.mchip_mmregs); 1771 iounmap(meye.mchip_mmregs);
diff --git a/drivers/media/pci/meye/meye.h b/drivers/media/pci/meye/meye.h
index 4bdeb03f1644..6fed9274cfa5 100644
--- a/drivers/media/pci/meye/meye.h
+++ b/drivers/media/pci/meye/meye.h
@@ -39,6 +39,7 @@
39#include <linux/types.h> 39#include <linux/types.h>
40#include <linux/pci.h> 40#include <linux/pci.h>
41#include <linux/kfifo.h> 41#include <linux/kfifo.h>
42#include <media/v4l2-ctrls.h>
42 43
43/****************************************************************************/ 44/****************************************************************************/
44/* Motion JPEG chip registers */ 45/* Motion JPEG chip registers */
@@ -290,6 +291,7 @@ struct meye_grab_buffer {
290/* Motion Eye device structure */ 291/* Motion Eye device structure */
291struct meye { 292struct meye {
292 struct v4l2_device v4l2_dev; /* Main v4l2_device struct */ 293 struct v4l2_device v4l2_dev; /* Main v4l2_device struct */
294 struct v4l2_ctrl_handler hdl;
293 struct pci_dev *mchip_dev; /* pci device */ 295 struct pci_dev *mchip_dev; /* pci device */
294 u8 mchip_irq; /* irq */ 296 u8 mchip_irq; /* irq */
295 u8 mchip_mode; /* actual mchip mode: HIC_MODE... */ 297 u8 mchip_mode; /* actual mchip mode: HIC_MODE... */
diff --git a/drivers/media/pci/ngene/ngene-cards.c b/drivers/media/pci/ngene/ngene-cards.c
index fad214113669..9e82d2105d53 100644
--- a/drivers/media/pci/ngene/ngene-cards.c
+++ b/drivers/media/pci/ngene/ngene-cards.c
@@ -327,6 +327,14 @@ static int demod_attach_drxd(struct ngene_channel *chan)
327 pr_err("No DRXD found!\n"); 327 pr_err("No DRXD found!\n");
328 return -ENODEV; 328 return -ENODEV;
329 } 329 }
330 return 0;
331}
332
333static int tuner_attach_dtt7520x(struct ngene_channel *chan)
334{
335 struct drxd_config *feconf;
336
337 feconf = chan->dev->card_info->fe_config[chan->number];
330 338
331 if (!dvb_attach(dvb_pll_attach, chan->fe, feconf->pll_address, 339 if (!dvb_attach(dvb_pll_attach, chan->fe, feconf->pll_address,
332 &chan->i2c_adapter, 340 &chan->i2c_adapter,
@@ -724,6 +732,7 @@ static struct ngene_info ngene_info_terratec = {
724 .name = "Terratec Integra/Cinergy2400i Dual DVB-T", 732 .name = "Terratec Integra/Cinergy2400i Dual DVB-T",
725 .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN}, 733 .io_type = {NGENE_IO_TSIN, NGENE_IO_TSIN},
726 .demod_attach = {demod_attach_drxd, demod_attach_drxd}, 734 .demod_attach = {demod_attach_drxd, demod_attach_drxd},
735 .tuner_attach = {tuner_attach_dtt7520x, tuner_attach_dtt7520x},
727 .fe_config = {&fe_terratec_dvbt_0, &fe_terratec_dvbt_1}, 736 .fe_config = {&fe_terratec_dvbt_0, &fe_terratec_dvbt_1},
728 .i2c_access = 1, 737 .i2c_access = 1,
729}; 738};
diff --git a/drivers/media/pci/saa7134/saa7134-cards.c b/drivers/media/pci/saa7134/saa7134-cards.c
index bc08f1dbc293..dc68cf1070f7 100644
--- a/drivers/media/pci/saa7134/saa7134-cards.c
+++ b/drivers/media/pci/saa7134/saa7134-cards.c
@@ -5773,6 +5773,23 @@ struct saa7134_board saa7134_boards[] = {
5773 .gpio = 0x0000000, 5773 .gpio = 0x0000000,
5774 }, 5774 },
5775 }, 5775 },
5776 [SAA7134_BOARD_HAWELL_HW_9004V1] = {
5777 /* Hawell HW-9004V1 */
5778 /* Vadim Frolov <fralik@gmail.com> */
5779 .name = "Hawell HW-9004V1",
5780 .audio_clock = 0x00200000,
5781 .tuner_type = UNSET,
5782 .radio_type = UNSET,
5783 .tuner_addr = ADDR_UNSET,
5784 .radio_addr = ADDR_UNSET,
5785 .gpiomask = 0x618E700,
5786 .inputs = {{
5787 .name = name_comp1,
5788 .vmux = 3,
5789 .amux = LINE1,
5790 .gpio = 0x6010000,
5791 } },
5792 },
5776 5793
5777}; 5794};
5778 5795
diff --git a/drivers/media/pci/saa7134/saa7134-core.c b/drivers/media/pci/saa7134/saa7134-core.c
index e359d200d698..8fd24e7c9403 100644
--- a/drivers/media/pci/saa7134/saa7134-core.c
+++ b/drivers/media/pci/saa7134/saa7134-core.c
@@ -308,7 +308,7 @@ void saa7134_buffer_finish(struct saa7134_dev *dev,
308 308
309 /* finish current buffer */ 309 /* finish current buffer */
310 q->curr->vb.state = state; 310 q->curr->vb.state = state;
311 do_gettimeofday(&q->curr->vb.ts); 311 v4l2_get_timestamp(&q->curr->vb.ts);
312 wake_up(&q->curr->vb.done); 312 wake_up(&q->curr->vb.done);
313 q->curr = NULL; 313 q->curr = NULL;
314} 314}
diff --git a/drivers/media/pci/saa7134/saa7134-dvb.c b/drivers/media/pci/saa7134/saa7134-dvb.c
index b209de40a4f8..27915e501db9 100644
--- a/drivers/media/pci/saa7134/saa7134-dvb.c
+++ b/drivers/media/pci/saa7134/saa7134-dvb.c
@@ -607,6 +607,9 @@ static int configure_tda827x_fe(struct saa7134_dev *dev,
607 /* Get the first frontend */ 607 /* Get the first frontend */
608 fe0 = videobuf_dvb_get_frontend(&dev->frontends, 1); 608 fe0 = videobuf_dvb_get_frontend(&dev->frontends, 1);
609 609
610 if (!fe0)
611 return -EINVAL;
612
610 fe0->dvb.frontend = dvb_attach(tda10046_attach, cdec_conf, &dev->i2c_adap); 613 fe0->dvb.frontend = dvb_attach(tda10046_attach, cdec_conf, &dev->i2c_adap);
611 if (fe0->dvb.frontend) { 614 if (fe0->dvb.frontend) {
612 if (cdec_conf->i2c_gate) 615 if (cdec_conf->i2c_gate)
diff --git a/drivers/media/pci/saa7134/saa7134-video.c b/drivers/media/pci/saa7134/saa7134-video.c
index 3abf52711e13..7c503fb68526 100644
--- a/drivers/media/pci/saa7134/saa7134-video.c
+++ b/drivers/media/pci/saa7134/saa7134-video.c
@@ -2248,6 +2248,17 @@ static int saa7134_streamon(struct file *file, void *priv,
2248 if (!res_get(dev, fh, res)) 2248 if (!res_get(dev, fh, res))
2249 return -EBUSY; 2249 return -EBUSY;
2250 2250
2251 /* The SAA7134 has a 1K FIFO; the datasheet suggests that when
2252 * configured conservatively, there's 22 usec of buffering for video.
2253 * We therefore request a DMA latency of 20 usec, giving us 2 usec of
2254 * margin in case the FIFO is configured differently to the datasheet.
2255 * Unfortunately, I lack register-level documentation to check the
2256 * Linux FIFO setup and confirm the perfect value.
2257 */
2258 pm_qos_add_request(&fh->qos_request,
2259 PM_QOS_CPU_DMA_LATENCY,
2260 20);
2261
2251 return videobuf_streamon(saa7134_queue(fh)); 2262 return videobuf_streamon(saa7134_queue(fh));
2252} 2263}
2253 2264
@@ -2259,6 +2270,8 @@ static int saa7134_streamoff(struct file *file, void *priv,
2259 struct saa7134_dev *dev = fh->dev; 2270 struct saa7134_dev *dev = fh->dev;
2260 int res = saa7134_resource(fh); 2271 int res = saa7134_resource(fh);
2261 2272
2273 pm_qos_remove_request(&fh->qos_request);
2274
2262 err = videobuf_streamoff(saa7134_queue(fh)); 2275 err = videobuf_streamoff(saa7134_queue(fh));
2263 if (err < 0) 2276 if (err < 0)
2264 return err; 2277 return err;
diff --git a/drivers/media/pci/saa7134/saa7134.h b/drivers/media/pci/saa7134/saa7134.h
index 075908fae4d9..71eefef5e324 100644
--- a/drivers/media/pci/saa7134/saa7134.h
+++ b/drivers/media/pci/saa7134/saa7134.h
@@ -29,6 +29,7 @@
29#include <linux/notifier.h> 29#include <linux/notifier.h>
30#include <linux/delay.h> 30#include <linux/delay.h>
31#include <linux/mutex.h> 31#include <linux/mutex.h>
32#include <linux/pm_qos.h>
32 33
33#include <asm/io.h> 34#include <asm/io.h>
34 35
@@ -41,7 +42,7 @@
41#include <media/videobuf-dma-sg.h> 42#include <media/videobuf-dma-sg.h>
42#include <sound/core.h> 43#include <sound/core.h>
43#include <sound/pcm.h> 44#include <sound/pcm.h>
44#if defined(CONFIG_VIDEO_SAA7134_DVB) || defined(CONFIG_VIDEO_SAA7134_DVB_MODULE) 45#if IS_ENABLED(CONFIG_VIDEO_SAA7134_DVB)
45#include <media/videobuf-dvb.h> 46#include <media/videobuf-dvb.h>
46#endif 47#endif
47 48
@@ -332,6 +333,7 @@ struct saa7134_card_ir {
332#define SAA7134_BOARD_SENSORAY811_911 188 333#define SAA7134_BOARD_SENSORAY811_911 188
333#define SAA7134_BOARD_KWORLD_PC150U 189 334#define SAA7134_BOARD_KWORLD_PC150U 189
334#define SAA7134_BOARD_ASUSTeK_PS3_100 190 335#define SAA7134_BOARD_ASUSTeK_PS3_100 190
336#define SAA7134_BOARD_HAWELL_HW_9004V1 191
335 337
336#define SAA7134_MAXBOARDS 32 338#define SAA7134_MAXBOARDS 32
337#define SAA7134_INPUT_MAX 8 339#define SAA7134_INPUT_MAX 8
@@ -469,6 +471,7 @@ struct saa7134_fh {
469 enum v4l2_buf_type type; 471 enum v4l2_buf_type type;
470 unsigned int resources; 472 unsigned int resources;
471 enum v4l2_priority prio; 473 enum v4l2_priority prio;
474 struct pm_qos_request qos_request;
472 475
473 /* video overlay */ 476 /* video overlay */
474 struct v4l2_window win; 477 struct v4l2_window win;
@@ -642,7 +645,7 @@ struct saa7134_dev {
642 struct work_struct empress_workqueue; 645 struct work_struct empress_workqueue;
643 int empress_started; 646 int empress_started;
644 647
645#if defined(CONFIG_VIDEO_SAA7134_DVB) || defined(CONFIG_VIDEO_SAA7134_DVB_MODULE) 648#if IS_ENABLED(CONFIG_VIDEO_SAA7134_DVB)
646 /* SAA7134_MPEG_DVB only */ 649 /* SAA7134_MPEG_DVB only */
647 struct videobuf_dvb_frontends frontends; 650 struct videobuf_dvb_frontends frontends;
648 int (*original_demod_sleep)(struct dvb_frontend *fe); 651 int (*original_demod_sleep)(struct dvb_frontend *fe);
diff --git a/drivers/media/pci/saa7164/saa7164-encoder.c b/drivers/media/pci/saa7164/saa7164-encoder.c
index 994018e2d0d6..9bb0903ee5f1 100644
--- a/drivers/media/pci/saa7164/saa7164-encoder.c
+++ b/drivers/media/pci/saa7164/saa7164-encoder.c
@@ -1298,6 +1298,7 @@ static int saa7164_g_chip_ident(struct file *file, void *fh,
1298 return 0; 1298 return 0;
1299} 1299}
1300 1300
1301#ifdef CONFIG_VIDEO_ADV_DEBUG
1301static int saa7164_g_register(struct file *file, void *fh, 1302static int saa7164_g_register(struct file *file, void *fh,
1302 struct v4l2_dbg_register *reg) 1303 struct v4l2_dbg_register *reg)
1303{ 1304{
@@ -1323,6 +1324,7 @@ static int saa7164_s_register(struct file *file, void *fh,
1323 1324
1324 return 0; 1325 return 0;
1325} 1326}
1327#endif
1326 1328
1327static const struct v4l2_ioctl_ops mpeg_ioctl_ops = { 1329static const struct v4l2_ioctl_ops mpeg_ioctl_ops = {
1328 .vidioc_s_std = vidioc_s_std, 1330 .vidioc_s_std = vidioc_s_std,
diff --git a/drivers/media/pci/sta2x11/Kconfig b/drivers/media/pci/sta2x11/Kconfig
index 6749f67cab8a..a94ccad02066 100644
--- a/drivers/media/pci/sta2x11/Kconfig
+++ b/drivers/media/pci/sta2x11/Kconfig
@@ -2,7 +2,7 @@ config STA2X11_VIP
2 tristate "STA2X11 VIP Video For Linux" 2 tristate "STA2X11 VIP Video For Linux"
3 depends on STA2X11 3 depends on STA2X11
4 select VIDEO_ADV7180 if MEDIA_SUBDRV_AUTOSELECT 4 select VIDEO_ADV7180 if MEDIA_SUBDRV_AUTOSELECT
5 select VIDEOBUF_DMA_CONTIG 5 select VIDEOBUF2_DMA_CONTIG
6 depends on PCI && VIDEO_V4L2 && VIRT_TO_BUS 6 depends on PCI && VIDEO_V4L2 && VIRT_TO_BUS
7 help 7 help
8 Say Y for support for STA2X11 VIP (Video Input Port) capture 8 Say Y for support for STA2X11 VIP (Video Input Port) capture
diff --git a/drivers/media/pci/sta2x11/sta2x11_vip.c b/drivers/media/pci/sta2x11/sta2x11_vip.c
index 27ae48842656..4b703fe8c953 100644
--- a/drivers/media/pci/sta2x11/sta2x11_vip.c
+++ b/drivers/media/pci/sta2x11/sta2x11_vip.c
@@ -1,7 +1,11 @@
1/* 1/*
2 * This is the driver for the STA2x11 Video Input Port. 2 * This is the driver for the STA2x11 Video Input Port.
3 * 3 *
4 * Copyright (C) 2012 ST Microelectronics
5 * author: Federico Vaga <federico.vaga@gmail.com>
4 * Copyright (C) 2010 WindRiver Systems, Inc. 6 * Copyright (C) 2010 WindRiver Systems, Inc.
7 * authors: Andreas Kies <andreas.kies@windriver.com>
8 * Vlad Lungu <vlad.lungu@windriver.com>
5 * 9 *
6 * This program is free software; you can redistribute it and/or modify it 10 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License, 11 * under the terms and conditions of the GNU General Public License,
@@ -19,36 +23,30 @@
19 * The full GNU General Public License is included in this distribution in 23 * The full GNU General Public License is included in this distribution in
20 * the file called "COPYING". 24 * the file called "COPYING".
21 * 25 *
22 * Author: Andreas Kies <andreas.kies@windriver.com>
23 * Vlad Lungu <vlad.lungu@windriver.com>
24 *
25 */ 26 */
26 27
27#include <linux/types.h> 28#include <linux/types.h>
28#include <linux/kernel.h> 29#include <linux/kernel.h>
29#include <linux/module.h> 30#include <linux/module.h>
30#include <linux/init.h> 31#include <linux/init.h>
31#include <linux/vmalloc.h>
32
33#include <linux/videodev2.h> 32#include <linux/videodev2.h>
34
35#include <linux/kmod.h> 33#include <linux/kmod.h>
36
37#include <linux/pci.h> 34#include <linux/pci.h>
38#include <linux/interrupt.h> 35#include <linux/interrupt.h>
39#include <linux/mutex.h>
40#include <linux/io.h> 36#include <linux/io.h>
41#include <linux/gpio.h> 37#include <linux/gpio.h>
42#include <linux/i2c.h> 38#include <linux/i2c.h>
43#include <linux/delay.h> 39#include <linux/delay.h>
44#include <media/v4l2-common.h> 40#include <media/v4l2-common.h>
45#include <media/v4l2-device.h> 41#include <media/v4l2-device.h>
42#include <media/v4l2-ctrls.h>
46#include <media/v4l2-ioctl.h> 43#include <media/v4l2-ioctl.h>
47#include <media/videobuf-dma-contig.h> 44#include <media/v4l2-fh.h>
45#include <media/v4l2-event.h>
46#include <media/videobuf2-dma-contig.h>
48 47
49#include "sta2x11_vip.h" 48#include "sta2x11_vip.h"
50 49
51#define DRV_NAME "sta2x11_vip"
52#define DRV_VERSION "1.3" 50#define DRV_VERSION "1.3"
53 51
54#ifndef PCI_DEVICE_ID_STMICRO_VIP 52#ifndef PCI_DEVICE_ID_STMICRO_VIP
@@ -63,8 +61,8 @@
63#define DVP_TFS 0x08 61#define DVP_TFS 0x08
64#define DVP_BFO 0x0C 62#define DVP_BFO 0x0C
65#define DVP_BFS 0x10 63#define DVP_BFS 0x10
66#define DVP_VTP 0x14 64#define DVP_VTP 0x14
67#define DVP_VBP 0x18 65#define DVP_VBP 0x18
68#define DVP_VMP 0x1C 66#define DVP_VMP 0x1C
69#define DVP_ITM 0x98 67#define DVP_ITM 0x98
70#define DVP_ITS 0x9C 68#define DVP_ITS 0x9C
@@ -84,13 +82,21 @@
84 82
85#define DVP_HLFLN_SD 0x00000001 83#define DVP_HLFLN_SD 0x00000001
86 84
87#define REG_WRITE(vip, reg, value) iowrite32((value), (vip->iomem)+(reg))
88#define REG_READ(vip, reg) ioread32((vip->iomem)+(reg))
89
90#define SAVE_COUNT 8 85#define SAVE_COUNT 8
91#define AUX_COUNT 3 86#define AUX_COUNT 3
92#define IRQ_COUNT 1 87#define IRQ_COUNT 1
93 88
89
90struct vip_buffer {
91 struct vb2_buffer vb;
92 struct list_head list;
93 dma_addr_t dma;
94};
95static inline struct vip_buffer *to_vip_buffer(struct vb2_buffer *vb2)
96{
97 return container_of(vb2, struct vip_buffer, vb);
98}
99
94/** 100/**
95 * struct sta2x11_vip - All internal data for one instance of device 101 * struct sta2x11_vip - All internal data for one instance of device
96 * @v4l2_dev: device registered in v4l layer 102 * @v4l2_dev: device registered in v4l layer
@@ -99,29 +105,26 @@
99 * @adapter: contains I2C adapter information 105 * @adapter: contains I2C adapter information
100 * @register_save_area: All relevant register are saved here during suspend 106 * @register_save_area: All relevant register are saved here during suspend
101 * @decoder: contains information about video DAC 107 * @decoder: contains information about video DAC
108 * @ctrl_hdl: handler for control framework
102 * @format: pixel format, fixed UYVY 109 * @format: pixel format, fixed UYVY
103 * @std: video standard (e.g. PAL/NTSC) 110 * @std: video standard (e.g. PAL/NTSC)
104 * @input: input line for video signal ( 0 or 1 ) 111 * @input: input line for video signal ( 0 or 1 )
105 * @users: Number of open of device ( max. 1 )
106 * @disabled: Device is in power down state 112 * @disabled: Device is in power down state
107 * @mutex: ensures exclusive opening of device
108 * @slock: for excluse acces of registers 113 * @slock: for excluse acces of registers
109 * @vb_vidq: queue maintained by videobuf layer 114 * @alloc_ctx: context for videobuf2
110 * @capture: linked list of capture buffer 115 * @vb_vidq: queue maintained by videobuf2 layer
111 * @active: struct videobuf_buffer currently beingg filled 116 * @buffer_list: list of buffer in use
112 * @started: device is ready to capture frame 117 * @sequence: sequence number of acquired buffer
113 * @closing: device will be shut down 118 * @active: current active buffer
119 * @lock: used in videobuf2 callback
114 * @tcount: Number of top frames 120 * @tcount: Number of top frames
115 * @bcount: Number of bottom frames 121 * @bcount: Number of bottom frames
116 * @overflow: Number of FIFO overflows 122 * @overflow: Number of FIFO overflows
117 * @mem_spare: small buffer of unused frame
118 * @dma_spare: dma addres of mem_spare
119 * @iomem: hardware base address 123 * @iomem: hardware base address
120 * @config: I2C and gpio config from platform 124 * @config: I2C and gpio config from platform
121 * 125 *
122 * All non-local data is accessed via this structure. 126 * All non-local data is accessed via this structure.
123 */ 127 */
124
125struct sta2x11_vip { 128struct sta2x11_vip {
126 struct v4l2_device v4l2_dev; 129 struct v4l2_device v4l2_dev;
127 struct video_device *video_dev; 130 struct video_device *video_dev;
@@ -129,21 +132,27 @@ struct sta2x11_vip {
129 struct i2c_adapter *adapter; 132 struct i2c_adapter *adapter;
130 unsigned int register_save_area[IRQ_COUNT + SAVE_COUNT + AUX_COUNT]; 133 unsigned int register_save_area[IRQ_COUNT + SAVE_COUNT + AUX_COUNT];
131 struct v4l2_subdev *decoder; 134 struct v4l2_subdev *decoder;
135 struct v4l2_ctrl_handler ctrl_hdl;
136
137
132 struct v4l2_pix_format format; 138 struct v4l2_pix_format format;
133 v4l2_std_id std; 139 v4l2_std_id std;
134 unsigned int input; 140 unsigned int input;
135 int users;
136 int disabled; 141 int disabled;
137 struct mutex mutex; /* exclusive access during open */ 142 spinlock_t slock;
138 spinlock_t slock; /* spin lock for hardware and queue access */ 143
139 struct videobuf_queue vb_vidq; 144 struct vb2_alloc_ctx *alloc_ctx;
140 struct list_head capture; 145 struct vb2_queue vb_vidq;
141 struct videobuf_buffer *active; 146 struct list_head buffer_list;
142 int started, closing, tcount, bcount; 147 unsigned int sequence;
148 struct vip_buffer *active; /* current active buffer */
149 spinlock_t lock; /* Used in videobuf2 callback */
150
151 /* Interrupt counters */
152 int tcount, bcount;
143 int overflow; 153 int overflow;
144 void *mem_spare; 154
145 dma_addr_t dma_spare; 155 void *iomem; /* I/O Memory */
146 void *iomem;
147 struct vip_config *config; 156 struct vip_config *config;
148}; 157};
149 158
@@ -206,318 +215,195 @@ static struct v4l2_pix_format formats_60[] = {
206 .colorspace = V4L2_COLORSPACE_SMPTE170M}, 215 .colorspace = V4L2_COLORSPACE_SMPTE170M},
207}; 216};
208 217
209/** 218/* Write VIP register */
210 * buf_setup - Get size and number of video buffer 219static inline void reg_write(struct sta2x11_vip *vip, unsigned int reg, u32 val)
211 * @vq: queue in videobuf
212 * @count: Number of buffers (1..MAX_FRAMES).
213 * 0 use default value.
214 * @size: size of buffer in bytes
215 *
216 * returns size and number of buffers
217 * a preset value of 0 returns the default number.
218 * return value: 0, always succesfull.
219 */
220static int buf_setup(struct videobuf_queue *vq, unsigned int *count,
221 unsigned int *size)
222{ 220{
223 struct sta2x11_vip *vip = vq->priv_data; 221 iowrite32((val), (vip->iomem)+(reg));
224 222}
225 *size = vip->format.width * vip->format.height * 2; 223/* Read VIP register */
226 if (0 == *count || MAX_FRAMES < *count) 224static inline u32 reg_read(struct sta2x11_vip *vip, unsigned int reg)
227 *count = MAX_FRAMES;
228 return 0;
229};
230
231/**
232 * buf_prepare - prepare buffer for usage
233 * @vq: queue in videobuf layer
234 * @vb: buffer to be prepared
235 * @field: type of video data (interlaced/non-interlaced)
236 *
237 * Allocate or realloc buffer
238 * return value: 0, successful.
239 *
240 * -EINVAL, supplied buffer is too small.
241 *
242 * other, buffer could not be locked.
243 */
244static int buf_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
245 enum v4l2_field field)
246{ 225{
247 struct sta2x11_vip *vip = vq->priv_data; 226 return ioread32((vip->iomem)+(reg));
248 int ret;
249
250 vb->size = vip->format.width * vip->format.height * 2;
251 if ((0 != vb->baddr) && (vb->bsize < vb->size))
252 return -EINVAL;
253 vb->width = vip->format.width;
254 vb->height = vip->format.height;
255 vb->field = field;
256
257 if (VIDEOBUF_NEEDS_INIT == vb->state) {
258 ret = videobuf_iolock(vq, vb, NULL);
259 if (ret)
260 goto fail;
261 }
262 vb->state = VIDEOBUF_PREPARED;
263 return 0;
264fail:
265 videobuf_dma_contig_free(vq, vb);
266 vb->state = VIDEOBUF_NEEDS_INIT;
267 return ret;
268} 227}
269 228/* Start DMA acquisition */
270/** 229static void start_dma(struct sta2x11_vip *vip, struct vip_buffer *vip_buf)
271 * buf_queu - queue buffer for filling
272 * @vq: queue in videobuf layer
273 * @vb: buffer to be queued
274 *
275 * if capturing is already running, the buffer will be queued. Otherwise
276 * capture is started and the buffer is used directly.
277 */
278static void buf_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
279{ 230{
280 struct sta2x11_vip *vip = vq->priv_data; 231 unsigned long offset = 0;
281 u32 dma; 232
233 if (vip->format.field == V4L2_FIELD_INTERLACED)
234 offset = vip->format.width * 2;
282 235
283 vb->state = VIDEOBUF_QUEUED; 236 spin_lock_irq(&vip->slock);
237 /* Enable acquisition */
238 reg_write(vip, DVP_CTL, reg_read(vip, DVP_CTL) | DVP_CTL_ENA);
239 /* Set Top and Bottom Field memory address */
240 reg_write(vip, DVP_VTP, (u32)vip_buf->dma);
241 reg_write(vip, DVP_VBP, (u32)vip_buf->dma + offset);
242 spin_unlock_irq(&vip->slock);
243}
284 244
285 if (vip->active) { 245/* Fetch the next buffer to activate */
286 list_add_tail(&vb->queue, &vip->capture); 246static void vip_active_buf_next(struct sta2x11_vip *vip)
247{
248 /* Get the next buffer */
249 spin_lock(&vip->lock);
250 if (list_empty(&vip->buffer_list)) {/* No available buffer */
251 spin_unlock(&vip->lock);
287 return; 252 return;
288 } 253 }
289 254 vip->active = list_first_entry(&vip->buffer_list,
290 vip->started = 1; 255 struct vip_buffer,
256 list);
257 /* Reset Top and Bottom counter */
291 vip->tcount = 0; 258 vip->tcount = 0;
292 vip->bcount = 0; 259 vip->bcount = 0;
293 vip->active = vb; 260 spin_unlock(&vip->lock);
294 vb->state = VIDEOBUF_ACTIVE; 261 if (vb2_is_streaming(&vip->vb_vidq)) { /* streaming is on */
262 start_dma(vip, vip->active); /* start dma capture */
263 }
264}
295 265
296 dma = videobuf_to_dma_contig(vb);
297 266
298 REG_WRITE(vip, DVP_TFO, (0 << 16) | (0)); 267/* Videobuf2 Operations */
299 /* despite of interlace mode, upper and lower frames start at zero */ 268static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
300 REG_WRITE(vip, DVP_BFO, (0 << 16) | (0)); 269 unsigned int *nbuffers, unsigned int *nplanes,
270 unsigned int sizes[], void *alloc_ctxs[])
271{
272 struct sta2x11_vip *vip = vb2_get_drv_priv(vq);
301 273
302 switch (vip->format.field) { 274 if (!(*nbuffers) || *nbuffers < MAX_FRAMES)
303 case V4L2_FIELD_INTERLACED: 275 *nbuffers = MAX_FRAMES;
304 REG_WRITE(vip, DVP_TFS,
305 ((vip->format.height / 2 - 1) << 16) |
306 (2 * vip->format.width - 1));
307 REG_WRITE(vip, DVP_BFS, ((vip->format.height / 2 - 1) << 16) |
308 (2 * vip->format.width - 1));
309 REG_WRITE(vip, DVP_VTP, dma);
310 REG_WRITE(vip, DVP_VBP, dma + vip->format.width * 2);
311 REG_WRITE(vip, DVP_VMP, 4 * vip->format.width);
312 break;
313 case V4L2_FIELD_TOP:
314 REG_WRITE(vip, DVP_TFS,
315 ((vip->format.height - 1) << 16) |
316 (2 * vip->format.width - 1));
317 REG_WRITE(vip, DVP_BFS, ((0) << 16) |
318 (2 * vip->format.width - 1));
319 REG_WRITE(vip, DVP_VTP, dma);
320 REG_WRITE(vip, DVP_VBP, dma);
321 REG_WRITE(vip, DVP_VMP, 2 * vip->format.width);
322 break;
323 case V4L2_FIELD_BOTTOM:
324 REG_WRITE(vip, DVP_TFS, ((0) << 16) |
325 (2 * vip->format.width - 1));
326 REG_WRITE(vip, DVP_BFS,
327 ((vip->format.height) << 16) |
328 (2 * vip->format.width - 1));
329 REG_WRITE(vip, DVP_VTP, dma);
330 REG_WRITE(vip, DVP_VBP, dma);
331 REG_WRITE(vip, DVP_VMP, 2 * vip->format.width);
332 break;
333 276
334 default: 277 *nplanes = 1;
335 pr_warning("VIP: unknown field format\n"); 278 sizes[0] = vip->format.sizeimage;
336 return; 279 alloc_ctxs[0] = vip->alloc_ctx;
337 }
338 280
339 REG_WRITE(vip, DVP_CTL, DVP_CTL_ENA); 281 vip->sequence = 0;
340} 282 vip->active = NULL;
283 vip->tcount = 0;
284 vip->bcount = 0;
341 285
342/** 286 return 0;
343 * buff_release - release buffer 287};
344 * @vq: queue in videobuf layer 288static int buffer_init(struct vb2_buffer *vb)
345 * @vb: buffer to be released
346 *
347 * release buffer in videobuf layer
348 */
349static void buf_release(struct videobuf_queue *vq, struct videobuf_buffer *vb)
350{ 289{
290 struct vip_buffer *vip_buf = to_vip_buffer(vb);
351 291
352 videobuf_dma_contig_free(vq, vb); 292 vip_buf->dma = vb2_dma_contig_plane_dma_addr(vb, 0);
353 vb->state = VIDEOBUF_NEEDS_INIT; 293 INIT_LIST_HEAD(&vip_buf->list);
294 return 0;
354} 295}
355 296
356static struct videobuf_queue_ops vip_qops = { 297static int buffer_prepare(struct vb2_buffer *vb)
357 .buf_setup = buf_setup,
358 .buf_prepare = buf_prepare,
359 .buf_queue = buf_queue,
360 .buf_release = buf_release,
361};
362
363/**
364 * vip_open - open video device
365 * @file: descriptor of device
366 *
367 * open device, make sure it is only opened once.
368 * return value: 0, no error.
369 *
370 * -EBUSY, device is already opened
371 *
372 * -ENOMEM, no memory for auxiliary DMA buffer
373 */
374static int vip_open(struct file *file)
375{ 298{
376 struct video_device *dev = video_devdata(file); 299 struct sta2x11_vip *vip = vb2_get_drv_priv(vb->vb2_queue);
377 struct sta2x11_vip *vip = video_get_drvdata(dev); 300 struct vip_buffer *vip_buf = to_vip_buffer(vb);
301 unsigned long size;
302
303 size = vip->format.sizeimage;
304 if (vb2_plane_size(vb, 0) < size) {
305 v4l2_err(&vip->v4l2_dev, "buffer too small (%lu < %lu)\n",
306 vb2_plane_size(vb, 0), size);
307 return -EINVAL;
308 }
378 309
379 mutex_lock(&vip->mutex); 310 vb2_set_plane_payload(&vip_buf->vb, 0, size);
380 vip->users++;
381 311
382 if (vip->users > 1) { 312 return 0;
383 vip->users--; 313}
384 mutex_unlock(&vip->mutex); 314static void buffer_queue(struct vb2_buffer *vb)
385 return -EBUSY; 315{
316 struct sta2x11_vip *vip = vb2_get_drv_priv(vb->vb2_queue);
317 struct vip_buffer *vip_buf = to_vip_buffer(vb);
318
319 spin_lock(&vip->lock);
320 list_add_tail(&vip_buf->list, &vip->buffer_list);
321 if (!vip->active) { /* No active buffer, active the first one */
322 vip->active = list_first_entry(&vip->buffer_list,
323 struct vip_buffer,
324 list);
325 if (vb2_is_streaming(&vip->vb_vidq)) /* streaming is on */
326 start_dma(vip, vip_buf); /* start dma capture */
386 } 327 }
328 spin_unlock(&vip->lock);
329}
330static int buffer_finish(struct vb2_buffer *vb)
331{
332 struct sta2x11_vip *vip = vb2_get_drv_priv(vb->vb2_queue);
333 struct vip_buffer *vip_buf = to_vip_buffer(vb);
387 334
388 file->private_data = dev; 335 /* Buffer handled, remove it from the list */
389 vip->overflow = 0; 336 spin_lock(&vip->lock);
390 vip->started = 0; 337 list_del_init(&vip_buf->list);
391 vip->closing = 0; 338 spin_unlock(&vip->lock);
392 vip->active = NULL;
393 339
394 INIT_LIST_HEAD(&vip->capture); 340 vip_active_buf_next(vip);
395 vip->mem_spare = dma_alloc_coherent(&vip->pdev->dev, 64,
396 &vip->dma_spare, GFP_KERNEL);
397 if (!vip->mem_spare) {
398 vip->users--;
399 mutex_unlock(&vip->mutex);
400 return -ENOMEM;
401 }
402 341
403 mutex_unlock(&vip->mutex);
404 videobuf_queue_dma_contig_init_cached(&vip->vb_vidq,
405 &vip_qops,
406 &vip->pdev->dev,
407 &vip->slock,
408 V4L2_BUF_TYPE_VIDEO_CAPTURE,
409 V4L2_FIELD_INTERLACED,
410 sizeof(struct videobuf_buffer),
411 vip, NULL);
412 REG_READ(vip, DVP_ITS);
413 REG_WRITE(vip, DVP_HLFLN, DVP_HLFLN_SD);
414 REG_WRITE(vip, DVP_ITM, DVP_IT_VSB | DVP_IT_VST);
415 REG_WRITE(vip, DVP_CTL, DVP_CTL_RST);
416 REG_WRITE(vip, DVP_CTL, 0);
417 REG_READ(vip, DVP_ITS);
418 return 0; 342 return 0;
419} 343}
420 344
421/** 345static int start_streaming(struct vb2_queue *vq, unsigned int count)
422 * vip_close - close video device
423 * @file: descriptor of device
424 *
425 * close video device, wait until all pending operations are finished
426 * ( maximum FRAME_MAX buffers pending )
427 * Turn off interrupts.
428 *
429 * return value: 0, always succesful.
430 */
431static int vip_close(struct file *file)
432{ 346{
433 struct video_device *dev = video_devdata(file); 347 struct sta2x11_vip *vip = vb2_get_drv_priv(vq);
434 struct sta2x11_vip *vip = video_get_drvdata(dev);
435 348
436 vip->closing = 1;
437 if (vip->active)
438 videobuf_waiton(&vip->vb_vidq, vip->active, 0, 0);
439 spin_lock_irq(&vip->slock); 349 spin_lock_irq(&vip->slock);
440 350 /* Enable interrupt VSYNC Top and Bottom*/
441 REG_WRITE(vip, DVP_ITM, 0); 351 reg_write(vip, DVP_ITM, DVP_IT_VSB | DVP_IT_VST);
442 REG_WRITE(vip, DVP_CTL, DVP_CTL_RST);
443 REG_WRITE(vip, DVP_CTL, 0);
444 REG_READ(vip, DVP_ITS);
445
446 vip->started = 0;
447 vip->active = NULL;
448
449 spin_unlock_irq(&vip->slock); 352 spin_unlock_irq(&vip->slock);
450 353
451 videobuf_stop(&vip->vb_vidq); 354 if (count)
452 videobuf_mmap_free(&vip->vb_vidq); 355 start_dma(vip, vip->active);
453 356
454 dma_free_coherent(&vip->pdev->dev, 64, vip->mem_spare, vip->dma_spare);
455 file->private_data = NULL;
456 mutex_lock(&vip->mutex);
457 vip->users--;
458 mutex_unlock(&vip->mutex);
459 return 0; 357 return 0;
460} 358}
461 359
462/** 360/* abort streaming and wait for last buffer */
463 * vip_read - read from video input 361static int stop_streaming(struct vb2_queue *vq)
464 * @file: descriptor of device
465 * @data: user buffer
466 * @count: number of bytes to be read
467 * @ppos: position within stream
468 *
469 * read video data from video device.
470 * handling is done in generic videobuf layer
471 * return value: provided by videobuf layer
472 */
473static ssize_t vip_read(struct file *file, char __user *data,
474 size_t count, loff_t *ppos)
475{ 362{
476 struct video_device *dev = file->private_data; 363 struct sta2x11_vip *vip = vb2_get_drv_priv(vq);
477 struct sta2x11_vip *vip = video_get_drvdata(dev); 364 struct vip_buffer *vip_buf, *node;
478 365
479 return videobuf_read_stream(&vip->vb_vidq, data, count, ppos, 0, 366 /* Disable acquisition */
480 file->f_flags & O_NONBLOCK); 367 reg_write(vip, DVP_CTL, reg_read(vip, DVP_CTL) & ~DVP_CTL_ENA);
368 /* Disable all interrupts */
369 reg_write(vip, DVP_ITM, 0);
370
371 /* Release all active buffers */
372 spin_lock(&vip->lock);
373 list_for_each_entry_safe(vip_buf, node, &vip->buffer_list, list) {
374 vb2_buffer_done(&vip_buf->vb, VB2_BUF_STATE_ERROR);
375 list_del(&vip_buf->list);
376 }
377 spin_unlock(&vip->lock);
378 return 0;
481} 379}
482 380
483/** 381static struct vb2_ops vip_video_qops = {
484 * vip_mmap - map user buffer 382 .queue_setup = queue_setup,
485 * @file: descriptor of device 383 .buf_init = buffer_init,
486 * @vma: user buffer 384 .buf_prepare = buffer_prepare,
487 * 385 .buf_finish = buffer_finish,
488 * map user space buffer into kernel mode, including DMA address. 386 .buf_queue = buffer_queue,
489 * handling is done in generic videobuf layer. 387 .start_streaming = start_streaming,
490 * return value: provided by videobuf layer 388 .stop_streaming = stop_streaming,
491 */ 389};
492static int vip_mmap(struct file *file, struct vm_area_struct *vma)
493{
494 struct video_device *dev = file->private_data;
495 struct sta2x11_vip *vip = video_get_drvdata(dev);
496 390
497 return videobuf_mmap_mapper(&vip->vb_vidq, vma);
498}
499 391
500/** 392/* File Operations */
501 * vip_poll - poll for event 393static const struct v4l2_file_operations vip_fops = {
502 * @file: descriptor of device 394 .owner = THIS_MODULE,
503 * @wait: contains events to be waited for 395 .open = v4l2_fh_open,
504 * 396 .release = vb2_fop_release,
505 * wait for event related to video device. 397 .unlocked_ioctl = video_ioctl2,
506 * handling is done in generic videobuf layer. 398 .read = vb2_fop_read,
507 * return value: provided by videobuf layer 399 .mmap = vb2_fop_mmap,
508 */ 400 .poll = vb2_fop_poll
509static unsigned int vip_poll(struct file *file, struct poll_table_struct *wait) 401};
510{
511 struct video_device *dev = file->private_data;
512 struct sta2x11_vip *vip = video_get_drvdata(dev);
513 402
514 return videobuf_poll_stream(file, &vip->vb_vidq, wait);
515}
516 403
517/** 404/**
518 * vidioc_querycap - return capabilities of device 405 * vidioc_querycap - return capabilities of device
519 * @file: descriptor of device (not used) 406 * @file: descriptor of device
520 * @priv: points to current videodevice
521 * @cap: contains return values 407 * @cap: contains return values
522 * 408 *
523 * the capabilities of the device are returned 409 * the capabilities of the device are returned
@@ -527,25 +413,22 @@ static unsigned int vip_poll(struct file *file, struct poll_table_struct *wait)
527static int vidioc_querycap(struct file *file, void *priv, 413static int vidioc_querycap(struct file *file, void *priv,
528 struct v4l2_capability *cap) 414 struct v4l2_capability *cap)
529{ 415{
530 struct video_device *dev = priv; 416 struct sta2x11_vip *vip = video_drvdata(file);
531 struct sta2x11_vip *vip = video_get_drvdata(dev);
532 417
533 memset(cap, 0, sizeof(struct v4l2_capability)); 418 strcpy(cap->driver, KBUILD_MODNAME);
534 strcpy(cap->driver, DRV_NAME); 419 strcpy(cap->card, KBUILD_MODNAME);
535 strcpy(cap->card, DRV_NAME);
536 cap->version = 0;
537 snprintf(cap->bus_info, sizeof(cap->bus_info), "PCI:%s", 420 snprintf(cap->bus_info, sizeof(cap->bus_info), "PCI:%s",
538 pci_name(vip->pdev)); 421 pci_name(vip->pdev));
539 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE | 422 cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE |
540 V4L2_CAP_STREAMING; 423 V4L2_CAP_STREAMING;
424 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
541 425
542 return 0; 426 return 0;
543} 427}
544 428
545/** 429/**
546 * vidioc_s_std - set video standard 430 * vidioc_s_std - set video standard
547 * @file: descriptor of device (not used) 431 * @file: descriptor of device
548 * @priv: points to current videodevice
549 * @std: contains standard to be set 432 * @std: contains standard to be set
550 * 433 *
551 * the video standard is set 434 * the video standard is set
@@ -558,8 +441,7 @@ static int vidioc_querycap(struct file *file, void *priv,
558 */ 441 */
559static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *std) 442static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *std)
560{ 443{
561 struct video_device *dev = priv; 444 struct sta2x11_vip *vip = video_drvdata(file);
562 struct sta2x11_vip *vip = video_get_drvdata(dev);
563 v4l2_std_id oldstd = vip->std, newstd; 445 v4l2_std_id oldstd = vip->std, newstd;
564 int status; 446 int status;
565 447
@@ -592,8 +474,7 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *std)
592 474
593/** 475/**
594 * vidioc_g_std - get video standard 476 * vidioc_g_std - get video standard
595 * @file: descriptor of device (not used) 477 * @file: descriptor of device
596 * @priv: points to current videodevice
597 * @std: contains return values 478 * @std: contains return values
598 * 479 *
599 * the current video standard is returned 480 * the current video standard is returned
@@ -602,8 +483,7 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *std)
602 */ 483 */
603static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *std) 484static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *std)
604{ 485{
605 struct video_device *dev = priv; 486 struct sta2x11_vip *vip = video_drvdata(file);
606 struct sta2x11_vip *vip = video_get_drvdata(dev);
607 487
608 *std = vip->std; 488 *std = vip->std;
609 return 0; 489 return 0;
@@ -611,8 +491,7 @@ static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *std)
611 491
612/** 492/**
613 * vidioc_querystd - get possible video standards 493 * vidioc_querystd - get possible video standards
614 * @file: descriptor of device (not used) 494 * @file: descriptor of device
615 * @priv: points to current videodevice
616 * @std: contains return values 495 * @std: contains return values
617 * 496 *
618 * all possible video standards are returned 497 * all possible video standards are returned
@@ -621,79 +500,11 @@ static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *std)
621 */ 500 */
622static int vidioc_querystd(struct file *file, void *priv, v4l2_std_id *std) 501static int vidioc_querystd(struct file *file, void *priv, v4l2_std_id *std)
623{ 502{
624 struct video_device *dev = priv; 503 struct sta2x11_vip *vip = video_drvdata(file);
625 struct sta2x11_vip *vip = video_get_drvdata(dev);
626 504
627 return v4l2_subdev_call(vip->decoder, video, querystd, std); 505 return v4l2_subdev_call(vip->decoder, video, querystd, std);
628
629} 506}
630 507
631/**
632 * vidioc_queryctl - get possible control settings
633 * @file: descriptor of device (not used)
634 * @priv: points to current videodevice
635 * @ctrl: contains return values
636 *
637 * return possible values for a control
638 * return value: delivered by video DAC routine.
639 */
640static int vidioc_queryctrl(struct file *file, void *priv,
641 struct v4l2_queryctrl *ctrl)
642{
643 struct video_device *dev = priv;
644 struct sta2x11_vip *vip = video_get_drvdata(dev);
645
646 return v4l2_subdev_call(vip->decoder, core, queryctrl, ctrl);
647}
648
649/**
650 * vidioc_g_ctl - get control value
651 * @file: descriptor of device (not used)
652 * @priv: points to current videodevice
653 * @ctrl: contains return values
654 *
655 * return setting for a control value
656 * return value: delivered by video DAC routine.
657 */
658static int vidioc_g_ctrl(struct file *file, void *priv,
659 struct v4l2_control *ctrl)
660{
661 struct video_device *dev = priv;
662 struct sta2x11_vip *vip = video_get_drvdata(dev);
663
664 return v4l2_subdev_call(vip->decoder, core, g_ctrl, ctrl);
665}
666
667/**
668 * vidioc_s_ctl - set control value
669 * @file: descriptor of device (not used)
670 * @priv: points to current videodevice
671 * @ctrl: contains value to be set
672 *
673 * set value for a specific control
674 * return value: delivered by video DAC routine.
675 */
676static int vidioc_s_ctrl(struct file *file, void *priv,
677 struct v4l2_control *ctrl)
678{
679 struct video_device *dev = priv;
680 struct sta2x11_vip *vip = video_get_drvdata(dev);
681
682 return v4l2_subdev_call(vip->decoder, core, s_ctrl, ctrl);
683}
684
685/**
686 * vidioc_enum_input - return name of input line
687 * @file: descriptor of device (not used)
688 * @priv: points to current videodevice
689 * @inp: contains return values
690 *
691 * the user friendly name of the input line is returned
692 *
693 * return value: 0, no error.
694 *
695 * -EINVAL, input line number out of range
696 */
697static int vidioc_enum_input(struct file *file, void *priv, 508static int vidioc_enum_input(struct file *file, void *priv,
698 struct v4l2_input *inp) 509 struct v4l2_input *inp)
699{ 510{
@@ -709,8 +520,7 @@ static int vidioc_enum_input(struct file *file, void *priv,
709 520
710/** 521/**
711 * vidioc_s_input - set input line 522 * vidioc_s_input - set input line
712 * @file: descriptor of device ( not used) 523 * @file: descriptor of device
713 * @priv: points to current videodevice
714 * @i: new input line number 524 * @i: new input line number
715 * 525 *
716 * the current active input line is set 526 * the current active input line is set
@@ -721,8 +531,7 @@ static int vidioc_enum_input(struct file *file, void *priv,
721 */ 531 */
722static int vidioc_s_input(struct file *file, void *priv, unsigned int i) 532static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
723{ 533{
724 struct video_device *dev = priv; 534 struct sta2x11_vip *vip = video_drvdata(file);
725 struct sta2x11_vip *vip = video_get_drvdata(dev);
726 int ret; 535 int ret;
727 536
728 if (i > 1) 537 if (i > 1)
@@ -737,8 +546,7 @@ static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
737 546
738/** 547/**
739 * vidioc_g_input - return input line 548 * vidioc_g_input - return input line
740 * @file: descriptor of device ( not used) 549 * @file: descriptor of device
741 * @priv: points to current videodevice
742 * @i: returned input line number 550 * @i: returned input line number
743 * 551 *
744 * the current active input line is returned 552 * the current active input line is returned
@@ -747,8 +555,7 @@ static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
747 */ 555 */
748static int vidioc_g_input(struct file *file, void *priv, unsigned int *i) 556static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
749{ 557{
750 struct video_device *dev = priv; 558 struct sta2x11_vip *vip = video_drvdata(file);
751 struct sta2x11_vip *vip = video_get_drvdata(dev);
752 559
753 *i = vip->input; 560 *i = vip->input;
754 return 0; 561 return 0;
@@ -756,8 +563,6 @@ static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
756 563
757/** 564/**
758 * vidioc_enum_fmt_vid_cap - return video capture format 565 * vidioc_enum_fmt_vid_cap - return video capture format
759 * @file: descriptor of device ( not used)
760 * @priv: points to current videodevice
761 * @f: returned format information 566 * @f: returned format information
762 * 567 *
763 * returns name and format of video capture 568 * returns name and format of video capture
@@ -780,8 +585,7 @@ static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
780 585
781/** 586/**
782 * vidioc_try_fmt_vid_cap - set video capture format 587 * vidioc_try_fmt_vid_cap - set video capture format
783 * @file: descriptor of device ( not used) 588 * @file: descriptor of device
784 * @priv: points to current videodevice
785 * @f: new format 589 * @f: new format
786 * 590 *
787 * new video format is set which includes width and 591 * new video format is set which includes width and
@@ -797,12 +601,13 @@ static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
797static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, 601static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
798 struct v4l2_format *f) 602 struct v4l2_format *f)
799{ 603{
800 struct video_device *dev = priv; 604 struct sta2x11_vip *vip = video_drvdata(file);
801 struct sta2x11_vip *vip = video_get_drvdata(dev);
802 int interlace_lim; 605 int interlace_lim;
803 606
804 if (V4L2_PIX_FMT_UYVY != f->fmt.pix.pixelformat) 607 if (V4L2_PIX_FMT_UYVY != f->fmt.pix.pixelformat) {
608 v4l2_warn(&vip->v4l2_dev, "Invalid format, only UYVY supported\n");
805 return -EINVAL; 609 return -EINVAL;
610 }
806 611
807 if (V4L2_STD_525_60 & vip->std) 612 if (V4L2_STD_525_60 & vip->std)
808 interlace_lim = 240; 613 interlace_lim = 240;
@@ -810,6 +615,7 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
810 interlace_lim = 288; 615 interlace_lim = 288;
811 616
812 switch (f->fmt.pix.field) { 617 switch (f->fmt.pix.field) {
618 default:
813 case V4L2_FIELD_ANY: 619 case V4L2_FIELD_ANY:
814 if (interlace_lim < f->fmt.pix.height) 620 if (interlace_lim < f->fmt.pix.height)
815 f->fmt.pix.field = V4L2_FIELD_INTERLACED; 621 f->fmt.pix.field = V4L2_FIELD_INTERLACED;
@@ -823,10 +629,10 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
823 break; 629 break;
824 case V4L2_FIELD_INTERLACED: 630 case V4L2_FIELD_INTERLACED:
825 break; 631 break;
826 default:
827 return -EINVAL;
828 } 632 }
829 633
634 /* It is the only supported format */
635 f->fmt.pix.pixelformat = V4L2_PIX_FMT_UYVY;
830 f->fmt.pix.height &= ~1; 636 f->fmt.pix.height &= ~1;
831 if (2 * interlace_lim < f->fmt.pix.height) 637 if (2 * interlace_lim < f->fmt.pix.height)
832 f->fmt.pix.height = 2 * interlace_lim; 638 f->fmt.pix.height = 2 * interlace_lim;
@@ -842,8 +648,7 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
842 648
843/** 649/**
844 * vidioc_s_fmt_vid_cap - set current video format parameters 650 * vidioc_s_fmt_vid_cap - set current video format parameters
845 * @file: descriptor of device ( not used) 651 * @file: descriptor of device
846 * @priv: points to current videodevice
847 * @f: returned format information 652 * @f: returned format information
848 * 653 *
849 * set new capture format 654 * set new capture format
@@ -854,22 +659,63 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
854static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, 659static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
855 struct v4l2_format *f) 660 struct v4l2_format *f)
856{ 661{
857 struct video_device *dev = priv; 662 struct sta2x11_vip *vip = video_drvdata(file);
858 struct sta2x11_vip *vip = video_get_drvdata(dev); 663 unsigned int t_stop, b_stop, pitch;
859 int ret; 664 int ret;
860 665
861 ret = vidioc_try_fmt_vid_cap(file, priv, f); 666 ret = vidioc_try_fmt_vid_cap(file, priv, f);
862 if (ret) 667 if (ret)
863 return ret; 668 return ret;
864 669
865 memcpy(&vip->format, &f->fmt.pix, sizeof(struct v4l2_pix_format)); 670 if (vb2_is_busy(&vip->vb_vidq)) {
671 /* Can't change format during acquisition */
672 v4l2_err(&vip->v4l2_dev, "device busy\n");
673 return -EBUSY;
674 }
675 vip->format = f->fmt.pix;
676 switch (vip->format.field) {
677 case V4L2_FIELD_INTERLACED:
678 t_stop = ((vip->format.height / 2 - 1) << 16) |
679 (2 * vip->format.width - 1);
680 b_stop = t_stop;
681 pitch = 4 * vip->format.width;
682 break;
683 case V4L2_FIELD_TOP:
684 t_stop = ((vip->format.height - 1) << 16) |
685 (2 * vip->format.width - 1);
686 b_stop = (0 << 16) | (2 * vip->format.width - 1);
687 pitch = 2 * vip->format.width;
688 break;
689 case V4L2_FIELD_BOTTOM:
690 t_stop = (0 << 16) | (2 * vip->format.width - 1);
691 b_stop = (vip->format.height << 16) |
692 (2 * vip->format.width - 1);
693 pitch = 2 * vip->format.width;
694 break;
695 default:
696 v4l2_err(&vip->v4l2_dev, "unknown field format\n");
697 return -EINVAL;
698 }
699
700 spin_lock_irq(&vip->slock);
701 /* Y-X Top Field Offset */
702 reg_write(vip, DVP_TFO, 0);
703 /* Y-X Bottom Field Offset */
704 reg_write(vip, DVP_BFO, 0);
705 /* Y-X Top Field Stop*/
706 reg_write(vip, DVP_TFS, t_stop);
707 /* Y-X Bottom Field Stop */
708 reg_write(vip, DVP_BFS, b_stop);
709 /* Video Memory Pitch */
710 reg_write(vip, DVP_VMP, pitch);
711 spin_unlock_irq(&vip->slock);
712
866 return 0; 713 return 0;
867} 714}
868 715
869/** 716/**
870 * vidioc_g_fmt_vid_cap - get current video format parameters 717 * vidioc_g_fmt_vid_cap - get current video format parameters
871 * @file: descriptor of device ( not used) 718 * @file: descriptor of device
872 * @priv: points to current videodevice
873 * @f: contains format information 719 * @f: contains format information
874 * 720 *
875 * returns current video format parameters 721 * returns current video format parameters
@@ -879,150 +725,47 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
879static int vidioc_g_fmt_vid_cap(struct file *file, void *priv, 725static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
880 struct v4l2_format *f) 726 struct v4l2_format *f)
881{ 727{
882 struct video_device *dev = priv; 728 struct sta2x11_vip *vip = video_drvdata(file);
883 struct sta2x11_vip *vip = video_get_drvdata(dev);
884
885 memcpy(&f->fmt.pix, &vip->format, sizeof(struct v4l2_pix_format));
886 return 0;
887}
888
889/**
890 * vidioc_reqfs - request buffer
891 * @file: descriptor of device ( not used)
892 * @priv: points to current videodevice
893 * @p: video buffer
894 *
895 * Handling is done in generic videobuf layer.
896 */
897static int vidioc_reqbufs(struct file *file, void *priv,
898 struct v4l2_requestbuffers *p)
899{
900 struct video_device *dev = priv;
901 struct sta2x11_vip *vip = video_get_drvdata(dev);
902
903 return videobuf_reqbufs(&vip->vb_vidq, p);
904}
905
906/**
907 * vidioc_querybuf - query buffer
908 * @file: descriptor of device ( not used)
909 * @priv: points to current videodevice
910 * @p: video buffer
911 *
912 * query buffer state.
913 * Handling is done in generic videobuf layer.
914 */
915static int vidioc_querybuf(struct file *file, void *priv, struct v4l2_buffer *p)
916{
917 struct video_device *dev = priv;
918 struct sta2x11_vip *vip = video_get_drvdata(dev);
919 729
920 return videobuf_querybuf(&vip->vb_vidq, p); 730 f->fmt.pix = vip->format;
921}
922 731
923/** 732 return 0;
924 * vidioc_qbuf - queue a buffer
925 * @file: descriptor of device ( not used)
926 * @priv: points to current videodevice
927 * @p: video buffer
928 *
929 * Handling is done in generic videobuf layer.
930 */
931static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *p)
932{
933 struct video_device *dev = priv;
934 struct sta2x11_vip *vip = video_get_drvdata(dev);
935
936 return videobuf_qbuf(&vip->vb_vidq, p);
937}
938
939/**
940 * vidioc_dqbuf - dequeue a buffer
941 * @file: descriptor of device ( not used)
942 * @priv: points to current videodevice
943 * @p: video buffer
944 *
945 * Handling is done in generic videobuf layer.
946 */
947static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
948{
949 struct video_device *dev = priv;
950 struct sta2x11_vip *vip = video_get_drvdata(dev);
951
952 return videobuf_dqbuf(&vip->vb_vidq, p, file->f_flags & O_NONBLOCK);
953}
954
955/**
956 * vidioc_streamon - turn on streaming
957 * @file: descriptor of device ( not used)
958 * @priv: points to current videodevice
959 * @type: type of capture
960 *
961 * turn on streaming.
962 * Handling is done in generic videobuf layer.
963 */
964static int vidioc_streamon(struct file *file, void *priv,
965 enum v4l2_buf_type type)
966{
967 struct video_device *dev = priv;
968 struct sta2x11_vip *vip = video_get_drvdata(dev);
969
970 return videobuf_streamon(&vip->vb_vidq);
971}
972
973/**
974 * vidioc_streamoff - turn off streaming
975 * @file: descriptor of device ( not used)
976 * @priv: points to current videodevice
977 * @type: type of capture
978 *
979 * turn off streaming.
980 * Handling is done in generic videobuf layer.
981 */
982static int vidioc_streamoff(struct file *file, void *priv,
983 enum v4l2_buf_type type)
984{
985 struct video_device *dev = priv;
986 struct sta2x11_vip *vip = video_get_drvdata(dev);
987
988 return videobuf_streamoff(&vip->vb_vidq);
989} 733}
990 734
991static const struct v4l2_file_operations vip_fops = {
992 .owner = THIS_MODULE,
993 .open = vip_open,
994 .release = vip_close,
995 .ioctl = video_ioctl2,
996 .read = vip_read,
997 .mmap = vip_mmap,
998 .poll = vip_poll
999};
1000
1001static const struct v4l2_ioctl_ops vip_ioctl_ops = { 735static const struct v4l2_ioctl_ops vip_ioctl_ops = {
1002 .vidioc_querycap = vidioc_querycap, 736 .vidioc_querycap = vidioc_querycap,
1003 .vidioc_s_std = vidioc_s_std, 737 /* FMT handling */
738 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
739 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
740 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
741 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
742 /* Buffer handlers */
743 .vidioc_create_bufs = vb2_ioctl_create_bufs,
744 .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
745 .vidioc_reqbufs = vb2_ioctl_reqbufs,
746 .vidioc_querybuf = vb2_ioctl_querybuf,
747 .vidioc_qbuf = vb2_ioctl_qbuf,
748 .vidioc_dqbuf = vb2_ioctl_dqbuf,
749 /* Stream on/off */
750 .vidioc_streamon = vb2_ioctl_streamon,
751 .vidioc_streamoff = vb2_ioctl_streamoff,
752 /* Standard handling */
1004 .vidioc_g_std = vidioc_g_std, 753 .vidioc_g_std = vidioc_g_std,
754 .vidioc_s_std = vidioc_s_std,
1005 .vidioc_querystd = vidioc_querystd, 755 .vidioc_querystd = vidioc_querystd,
1006 .vidioc_queryctrl = vidioc_queryctrl, 756 /* Input handling */
1007 .vidioc_g_ctrl = vidioc_g_ctrl,
1008 .vidioc_s_ctrl = vidioc_s_ctrl,
1009 .vidioc_enum_input = vidioc_enum_input, 757 .vidioc_enum_input = vidioc_enum_input,
1010 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
1011 .vidioc_s_input = vidioc_s_input,
1012 .vidioc_g_input = vidioc_g_input, 758 .vidioc_g_input = vidioc_g_input,
1013 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, 759 .vidioc_s_input = vidioc_s_input,
1014 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, 760 /* Log status ioctl */
1015 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, 761 .vidioc_log_status = v4l2_ctrl_log_status,
1016 .vidioc_reqbufs = vidioc_reqbufs, 762 /* Event handling */
1017 .vidioc_querybuf = vidioc_querybuf, 763 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1018 .vidioc_qbuf = vidioc_qbuf, 764 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1019 .vidioc_dqbuf = vidioc_dqbuf,
1020 .vidioc_streamon = vidioc_streamon,
1021 .vidioc_streamoff = vidioc_streamoff,
1022}; 765};
1023 766
1024static struct video_device video_dev_template = { 767static struct video_device video_dev_template = {
1025 .name = DRV_NAME, 768 .name = KBUILD_MODNAME,
1026 .release = video_device_release, 769 .release = video_device_release,
1027 .fops = &vip_fops, 770 .fops = &vip_fops,
1028 .ioctl_ops = &vip_ioctl_ops, 771 .ioctl_ops = &vip_ioctl_ops,
@@ -1036,9 +779,7 @@ static struct video_device video_dev_template = {
1036 * 779 *
1037 * check for both frame interrupts set ( top and bottom ). 780 * check for both frame interrupts set ( top and bottom ).
1038 * check FIFO overflow, but limit number of log messages after open. 781 * check FIFO overflow, but limit number of log messages after open.
1039 * signal a complete buffer if done. 782 * signal a complete buffer if done
1040 * dequeue a new buffer if available.
1041 * disable VIP if no buffer available.
1042 * 783 *
1043 * return value: IRQ_NONE, interrupt was not generated by VIP 784 * return value: IRQ_NONE, interrupt was not generated by VIP
1044 * 785 *
@@ -1046,88 +787,122 @@ static struct video_device video_dev_template = {
1046 */ 787 */
1047static irqreturn_t vip_irq(int irq, struct sta2x11_vip *vip) 788static irqreturn_t vip_irq(int irq, struct sta2x11_vip *vip)
1048{ 789{
1049 u32 status, dma; 790 unsigned int status;
1050 unsigned long flags;
1051 struct videobuf_buffer *vb;
1052 791
1053 status = REG_READ(vip, DVP_ITS); 792 status = reg_read(vip, DVP_ITS);
1054 793
1055 if (!status) { 794 if (!status) /* No interrupt to handle */
1056 pr_debug("VIP: irq ignored\n");
1057 return IRQ_NONE; 795 return IRQ_NONE;
1058 }
1059
1060 if (!vip->started)
1061 return IRQ_HANDLED;
1062 796
1063 if (status & DVP_IT_VSB) 797 if (status & DVP_IT_FIFO)
1064 vip->bcount++; 798 if (vip->overflow++ > 5)
1065 799 pr_info("VIP: fifo overflow\n");
1066 if (status & DVP_IT_VST)
1067 vip->tcount++;
1068 800
1069 if ((DVP_IT_VSB | DVP_IT_VST) == (status & (DVP_IT_VST | DVP_IT_VSB))) { 801 if ((status & DVP_IT_VST) && (status & DVP_IT_VSB)) {
1070 /* this is bad, we are too slow, hope the condition is gone 802 /* this is bad, we are too slow, hope the condition is gone
1071 * on the next frame */ 803 * on the next frame */
1072 pr_info("VIP: both irqs\n");
1073 return IRQ_HANDLED; 804 return IRQ_HANDLED;
1074 } 805 }
1075 806
1076 if (status & DVP_IT_FIFO) { 807 if (status & DVP_IT_VST)
1077 if (5 > vip->overflow++) 808 if ((++vip->tcount) < 2)
1078 pr_info("VIP: fifo overflow\n"); 809 return IRQ_HANDLED;
810 if (status & DVP_IT_VSB) {
811 vip->bcount++;
812 return IRQ_HANDLED;
1079 } 813 }
1080 814
1081 if (2 > vip->tcount) 815 if (vip->active) { /* Acquisition is over on this buffer */
1082 return IRQ_HANDLED; 816 /* Disable acquisition */
817 reg_write(vip, DVP_CTL, reg_read(vip, DVP_CTL) & ~DVP_CTL_ENA);
818 /* Remove the active buffer from the list */
819 do_gettimeofday(&vip->active->vb.v4l2_buf.timestamp);
820 vip->active->vb.v4l2_buf.sequence = vip->sequence++;
821 vb2_buffer_done(&vip->active->vb, VB2_BUF_STATE_DONE);
822 }
1083 823
1084 if (status & DVP_IT_VSB) 824 return IRQ_HANDLED;
1085 return IRQ_HANDLED; 825}
1086 826
1087 spin_lock_irqsave(&vip->slock, flags); 827static void sta2x11_vip_init_register(struct sta2x11_vip *vip)
828{
829 /* Register initialization */
830 spin_lock_irq(&vip->slock);
831 /* Clean interrupt */
832 reg_read(vip, DVP_ITS);
833 /* Enable Half Line per vertical */
834 reg_write(vip, DVP_HLFLN, DVP_HLFLN_SD);
835 /* Reset VIP control */
836 reg_write(vip, DVP_CTL, DVP_CTL_RST);
837 /* Clear VIP control */
838 reg_write(vip, DVP_CTL, 0);
839 spin_unlock_irq(&vip->slock);
840}
841static void sta2x11_vip_clear_register(struct sta2x11_vip *vip)
842{
843 spin_lock_irq(&vip->slock);
844 /* Disable interrupt */
845 reg_write(vip, DVP_ITM, 0);
846 /* Reset VIP Control */
847 reg_write(vip, DVP_CTL, DVP_CTL_RST);
848 /* Clear VIP Control */
849 reg_write(vip, DVP_CTL, 0);
850 /* Clean VIP Interrupt */
851 reg_read(vip, DVP_ITS);
852 spin_unlock_irq(&vip->slock);
853}
854static int sta2x11_vip_init_buffer(struct sta2x11_vip *vip)
855{
856 int err;
1088 857
1089 REG_WRITE(vip, DVP_CTL, REG_READ(vip, DVP_CTL) & ~DVP_CTL_ENA); 858 err = dma_set_coherent_mask(&vip->pdev->dev, DMA_BIT_MASK(29));
1090 if (vip->active) { 859 if (err) {
1091 do_gettimeofday(&vip->active->ts); 860 v4l2_err(&vip->v4l2_dev, "Cannot configure coherent mask");
1092 vip->active->field_count++; 861 return err;
1093 vip->active->state = VIDEOBUF_DONE;
1094 wake_up(&vip->active->done);
1095 vip->active = NULL;
1096 } 862 }
1097 if (!vip->closing) { 863 memset(&vip->vb_vidq, 0, sizeof(struct vb2_queue));
1098 if (list_empty(&vip->capture)) 864 vip->vb_vidq.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1099 goto done; 865 vip->vb_vidq.io_modes = VB2_MMAP | VB2_READ;
1100 866 vip->vb_vidq.drv_priv = vip;
1101 vb = list_first_entry(&vip->capture, struct videobuf_buffer, 867 vip->vb_vidq.buf_struct_size = sizeof(struct vip_buffer);
1102 queue); 868 vip->vb_vidq.ops = &vip_video_qops;
1103 if (NULL == vb) { 869 vip->vb_vidq.mem_ops = &vb2_dma_contig_memops;
1104 pr_info("VIP: no buffer\n"); 870 err = vb2_queue_init(&vip->vb_vidq);
1105 goto done; 871 if (err)
1106 } 872 return err;
1107 vb->state = VIDEOBUF_ACTIVE; 873 INIT_LIST_HEAD(&vip->buffer_list);
1108 list_del(&vb->queue); 874 spin_lock_init(&vip->lock);
1109 vip->active = vb; 875
1110 dma = videobuf_to_dma_contig(vb); 876
1111 switch (vip->format.field) { 877 vip->alloc_ctx = vb2_dma_contig_init_ctx(&vip->pdev->dev);
1112 case V4L2_FIELD_INTERLACED: 878 if (IS_ERR(vip->alloc_ctx)) {
1113 REG_WRITE(vip, DVP_VTP, dma); 879 v4l2_err(&vip->v4l2_dev, "Can't allocate buffer context");
1114 REG_WRITE(vip, DVP_VBP, dma + vip->format.width * 2); 880 return PTR_ERR(vip->alloc_ctx);
1115 break;
1116 case V4L2_FIELD_TOP:
1117 case V4L2_FIELD_BOTTOM:
1118 REG_WRITE(vip, DVP_VTP, dma);
1119 REG_WRITE(vip, DVP_VBP, dma);
1120 break;
1121 default:
1122 pr_warning("VIP: unknown field format\n");
1123 goto done;
1124 break;
1125 }
1126 REG_WRITE(vip, DVP_CTL, REG_READ(vip, DVP_CTL) | DVP_CTL_ENA);
1127 } 881 }
1128done: 882
1129 spin_unlock_irqrestore(&vip->slock, flags); 883 return 0;
1130 return IRQ_HANDLED; 884}
885static void sta2x11_vip_release_buffer(struct sta2x11_vip *vip)
886{
887 vb2_dma_contig_cleanup_ctx(vip->alloc_ctx);
888}
889static int sta2x11_vip_init_controls(struct sta2x11_vip *vip)
890{
891 /*
892 * Inititialize an empty control so VIP can inerithing controls
893 * from ADV7180
894 */
895 v4l2_ctrl_handler_init(&vip->ctrl_hdl, 0);
896
897 vip->v4l2_dev.ctrl_handler = &vip->ctrl_hdl;
898 if (vip->ctrl_hdl.error) {
899 int err = vip->ctrl_hdl.error;
900
901 v4l2_ctrl_handler_free(&vip->ctrl_hdl);
902 return err;
903 }
904
905 return 0;
1131} 906}
1132 907
1133/** 908/**
@@ -1212,10 +987,17 @@ static int sta2x11_vip_init_one(struct pci_dev *pdev,
1212 struct sta2x11_vip *vip; 987 struct sta2x11_vip *vip;
1213 struct vip_config *config; 988 struct vip_config *config;
1214 989
990 /* Check if hardware support 26-bit DMA */
991 if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(26))) {
992 dev_err(&pdev->dev, "26-bit DMA addressing not available\n");
993 return -EINVAL;
994 }
995 /* Enable PCI */
1215 ret = pci_enable_device(pdev); 996 ret = pci_enable_device(pdev);
1216 if (ret) 997 if (ret)
1217 return ret; 998 return ret;
1218 999
1000 /* Get VIP platform data */
1219 config = dev_get_platdata(&pdev->dev); 1001 config = dev_get_platdata(&pdev->dev);
1220 if (!config) { 1002 if (!config) {
1221 dev_info(&pdev->dev, "VIP slot disabled\n"); 1003 dev_info(&pdev->dev, "VIP slot disabled\n");
@@ -1223,6 +1005,7 @@ static int sta2x11_vip_init_one(struct pci_dev *pdev,
1223 goto disable; 1005 goto disable;
1224 } 1006 }
1225 1007
1008 /* Power configuration */
1226 ret = vip_gpio_reserve(&pdev->dev, config->pwr_pin, 0, 1009 ret = vip_gpio_reserve(&pdev->dev, config->pwr_pin, 0,
1227 config->pwr_name); 1010 config->pwr_name);
1228 if (ret) 1011 if (ret)
@@ -1237,7 +1020,6 @@ static int sta2x11_vip_init_one(struct pci_dev *pdev,
1237 goto disable; 1020 goto disable;
1238 } 1021 }
1239 } 1022 }
1240
1241 if (config->pwr_pin != -1) { 1023 if (config->pwr_pin != -1) {
1242 /* Datasheet says 5ms between PWR and RST */ 1024 /* Datasheet says 5ms between PWR and RST */
1243 usleep_range(5000, 25000); 1025 usleep_range(5000, 25000);
@@ -1251,17 +1033,20 @@ static int sta2x11_vip_init_one(struct pci_dev *pdev,
1251 } 1033 }
1252 usleep_range(5000, 25000); 1034 usleep_range(5000, 25000);
1253 1035
1036 /* Allocate a new VIP instance */
1254 vip = kzalloc(sizeof(struct sta2x11_vip), GFP_KERNEL); 1037 vip = kzalloc(sizeof(struct sta2x11_vip), GFP_KERNEL);
1255 if (!vip) { 1038 if (!vip) {
1256 ret = -ENOMEM; 1039 ret = -ENOMEM;
1257 goto release_gpios; 1040 goto release_gpios;
1258 } 1041 }
1259
1260 vip->pdev = pdev; 1042 vip->pdev = pdev;
1261 vip->std = V4L2_STD_PAL; 1043 vip->std = V4L2_STD_PAL;
1262 vip->format = formats_50[0]; 1044 vip->format = formats_50[0];
1263 vip->config = config; 1045 vip->config = config;
1264 1046
1047 ret = sta2x11_vip_init_controls(vip);
1048 if (ret)
1049 goto free_mem;
1265 if (v4l2_device_register(&pdev->dev, &vip->v4l2_dev)) 1050 if (v4l2_device_register(&pdev->dev, &vip->v4l2_dev))
1266 goto free_mem; 1051 goto free_mem;
1267 1052
@@ -1271,46 +1056,52 @@ static int sta2x11_vip_init_one(struct pci_dev *pdev,
1271 1056
1272 pci_set_master(pdev); 1057 pci_set_master(pdev);
1273 1058
1274 ret = pci_request_regions(pdev, DRV_NAME); 1059 ret = pci_request_regions(pdev, KBUILD_MODNAME);
1275 if (ret) 1060 if (ret)
1276 goto unreg; 1061 goto unreg;
1277 1062
1278 vip->iomem = pci_iomap(pdev, 0, 0x100); 1063 vip->iomem = pci_iomap(pdev, 0, 0x100);
1279 if (!vip->iomem) { 1064 if (!vip->iomem) {
1280 ret = -ENOMEM; /* FIXME */ 1065 ret = -ENOMEM;
1281 goto release; 1066 goto release;
1282 } 1067 }
1283 1068
1284 pci_enable_msi(pdev); 1069 pci_enable_msi(pdev);
1285 1070
1286 INIT_LIST_HEAD(&vip->capture); 1071 /* Initialize buffer */
1072 ret = sta2x11_vip_init_buffer(vip);
1073 if (ret)
1074 goto unmap;
1075
1287 spin_lock_init(&vip->slock); 1076 spin_lock_init(&vip->slock);
1288 mutex_init(&vip->mutex);
1289 vip->started = 0;
1290 vip->disabled = 0;
1291 1077
1292 ret = request_irq(pdev->irq, 1078 ret = request_irq(pdev->irq,
1293 (irq_handler_t) vip_irq, 1079 (irq_handler_t) vip_irq,
1294 IRQF_SHARED, DRV_NAME, vip); 1080 IRQF_SHARED, KBUILD_MODNAME, vip);
1295 if (ret) { 1081 if (ret) {
1296 dev_err(&pdev->dev, "request_irq failed\n"); 1082 dev_err(&pdev->dev, "request_irq failed\n");
1297 ret = -ENODEV; 1083 ret = -ENODEV;
1298 goto unmap; 1084 goto release_buf;
1299 } 1085 }
1300 1086
1087 /* Alloc, initialize and register video device */
1301 vip->video_dev = video_device_alloc(); 1088 vip->video_dev = video_device_alloc();
1302 if (!vip->video_dev) { 1089 if (!vip->video_dev) {
1303 ret = -ENOMEM; 1090 ret = -ENOMEM;
1304 goto release_irq; 1091 goto release_irq;
1305 } 1092 }
1306 1093
1307 *(vip->video_dev) = video_dev_template; 1094 vip->video_dev = &video_dev_template;
1095 vip->video_dev->v4l2_dev = &vip->v4l2_dev;
1096 vip->video_dev->queue = &vip->vb_vidq;
1097 set_bit(V4L2_FL_USE_FH_PRIO, &vip->video_dev->flags);
1308 video_set_drvdata(vip->video_dev, vip); 1098 video_set_drvdata(vip->video_dev, vip);
1309 1099
1310 ret = video_register_device(vip->video_dev, VFL_TYPE_GRABBER, -1); 1100 ret = video_register_device(vip->video_dev, VFL_TYPE_GRABBER, -1);
1311 if (ret) 1101 if (ret)
1312 goto vrelease; 1102 goto vrelease;
1313 1103
1104 /* Get ADV7180 subdevice */
1314 vip->adapter = i2c_get_adapter(vip->config->i2c_id); 1105 vip->adapter = i2c_get_adapter(vip->config->i2c_id);
1315 if (!vip->adapter) { 1106 if (!vip->adapter) {
1316 ret = -ENODEV; 1107 ret = -ENODEV;
@@ -1328,10 +1119,11 @@ static int sta2x11_vip_init_one(struct pci_dev *pdev,
1328 } 1119 }
1329 1120
1330 i2c_put_adapter(vip->adapter); 1121 i2c_put_adapter(vip->adapter);
1331
1332 v4l2_subdev_call(vip->decoder, core, init, 0); 1122 v4l2_subdev_call(vip->decoder, core, init, 0);
1333 1123
1334 pr_info("STA2X11 Video Input Port (VIP) loaded\n"); 1124 sta2x11_vip_init_register(vip);
1125
1126 dev_info(&pdev->dev, "STA2X11 Video Input Port (VIP) loaded\n");
1335 return 0; 1127 return 0;
1336 1128
1337vunreg: 1129vunreg:
@@ -1343,10 +1135,12 @@ vrelease:
1343 video_device_release(vip->video_dev); 1135 video_device_release(vip->video_dev);
1344release_irq: 1136release_irq:
1345 free_irq(pdev->irq, vip); 1137 free_irq(pdev->irq, vip);
1138release_buf:
1139 sta2x11_vip_release_buffer(vip);
1346 pci_disable_msi(pdev); 1140 pci_disable_msi(pdev);
1347unmap: 1141unmap:
1142 vb2_queue_release(&vip->vb_vidq);
1348 pci_iounmap(pdev, vip->iomem); 1143 pci_iounmap(pdev, vip->iomem);
1349 mutex_destroy(&vip->mutex);
1350release: 1144release:
1351 pci_release_regions(pdev); 1145 pci_release_regions(pdev);
1352unreg: 1146unreg:
@@ -1382,16 +1176,18 @@ static void sta2x11_vip_remove_one(struct pci_dev *pdev)
1382 struct sta2x11_vip *vip = 1176 struct sta2x11_vip *vip =
1383 container_of(v4l2_dev, struct sta2x11_vip, v4l2_dev); 1177 container_of(v4l2_dev, struct sta2x11_vip, v4l2_dev);
1384 1178
1179 sta2x11_vip_clear_register(vip);
1180
1385 video_set_drvdata(vip->video_dev, NULL); 1181 video_set_drvdata(vip->video_dev, NULL);
1386 video_unregister_device(vip->video_dev); 1182 video_unregister_device(vip->video_dev);
1387 /*do not call video_device_release() here, is already done */ 1183 /*do not call video_device_release() here, is already done */
1388 free_irq(pdev->irq, vip); 1184 free_irq(pdev->irq, vip);
1389 pci_disable_msi(pdev); 1185 pci_disable_msi(pdev);
1186 vb2_queue_release(&vip->vb_vidq);
1390 pci_iounmap(pdev, vip->iomem); 1187 pci_iounmap(pdev, vip->iomem);
1391 pci_release_regions(pdev); 1188 pci_release_regions(pdev);
1392 1189
1393 v4l2_device_unregister(&vip->v4l2_dev); 1190 v4l2_device_unregister(&vip->v4l2_dev);
1394 mutex_destroy(&vip->mutex);
1395 1191
1396 vip_gpio_release(&pdev->dev, vip->config->pwr_pin, 1192 vip_gpio_release(&pdev->dev, vip->config->pwr_pin,
1397 vip->config->pwr_name); 1193 vip->config->pwr_name);
@@ -1416,9 +1212,6 @@ static void sta2x11_vip_remove_one(struct pci_dev *pdev)
1416 * 1212 *
1417 * return value: 0 always indicate success, 1213 * return value: 0 always indicate success,
1418 * even if device could not be disabled. (workaround for hardware problem) 1214 * even if device could not be disabled. (workaround for hardware problem)
1419 *
1420 * reurn value : 0, always succesful, even if hardware does not not support
1421 * power down mode.
1422 */ 1215 */
1423static int sta2x11_vip_suspend(struct pci_dev *pdev, pm_message_t state) 1216static int sta2x11_vip_suspend(struct pci_dev *pdev, pm_message_t state)
1424{ 1217{
@@ -1429,15 +1222,15 @@ static int sta2x11_vip_suspend(struct pci_dev *pdev, pm_message_t state)
1429 int i; 1222 int i;
1430 1223
1431 spin_lock_irqsave(&vip->slock, flags); 1224 spin_lock_irqsave(&vip->slock, flags);
1432 vip->register_save_area[0] = REG_READ(vip, DVP_CTL); 1225 vip->register_save_area[0] = reg_read(vip, DVP_CTL);
1433 REG_WRITE(vip, DVP_CTL, vip->register_save_area[0] & DVP_CTL_DIS); 1226 reg_write(vip, DVP_CTL, vip->register_save_area[0] & DVP_CTL_DIS);
1434 vip->register_save_area[SAVE_COUNT] = REG_READ(vip, DVP_ITM); 1227 vip->register_save_area[SAVE_COUNT] = reg_read(vip, DVP_ITM);
1435 REG_WRITE(vip, DVP_ITM, 0); 1228 reg_write(vip, DVP_ITM, 0);
1436 for (i = 1; i < SAVE_COUNT; i++) 1229 for (i = 1; i < SAVE_COUNT; i++)
1437 vip->register_save_area[i] = REG_READ(vip, 4 * i); 1230 vip->register_save_area[i] = reg_read(vip, 4 * i);
1438 for (i = 0; i < AUX_COUNT; i++) 1231 for (i = 0; i < AUX_COUNT; i++)
1439 vip->register_save_area[SAVE_COUNT + IRQ_COUNT + i] = 1232 vip->register_save_area[SAVE_COUNT + IRQ_COUNT + i] =
1440 REG_READ(vip, registers_to_save[i]); 1233 reg_read(vip, registers_to_save[i]);
1441 spin_unlock_irqrestore(&vip->slock, flags); 1234 spin_unlock_irqrestore(&vip->slock, flags);
1442 /* save pci state */ 1235 /* save pci state */
1443 pci_save_state(pdev); 1236 pci_save_state(pdev);
@@ -1477,7 +1270,7 @@ static int sta2x11_vip_resume(struct pci_dev *pdev)
1477 if (vip->disabled) { 1270 if (vip->disabled) {
1478 ret = pci_enable_device(pdev); 1271 ret = pci_enable_device(pdev);
1479 if (ret) { 1272 if (ret) {
1480 pr_warning("VIP: Can't enable device.\n"); 1273 pr_warn("VIP: Can't enable device.\n");
1481 return ret; 1274 return ret;
1482 } 1275 }
1483 vip->disabled = 0; 1276 vip->disabled = 0;
@@ -1488,7 +1281,7 @@ static int sta2x11_vip_resume(struct pci_dev *pdev)
1488 * do not call pci_disable_device on sta2x11 because it 1281 * do not call pci_disable_device on sta2x11 because it
1489 * break all other Bus masters on this EP 1282 * break all other Bus masters on this EP
1490 */ 1283 */
1491 pr_warning("VIP: Can't enable device.\n"); 1284 pr_warn("VIP: Can't enable device.\n");
1492 vip->disabled = 1; 1285 vip->disabled = 1;
1493 return ret; 1286 return ret;
1494 } 1287 }
@@ -1497,12 +1290,12 @@ static int sta2x11_vip_resume(struct pci_dev *pdev)
1497 1290
1498 spin_lock_irqsave(&vip->slock, flags); 1291 spin_lock_irqsave(&vip->slock, flags);
1499 for (i = 1; i < SAVE_COUNT; i++) 1292 for (i = 1; i < SAVE_COUNT; i++)
1500 REG_WRITE(vip, 4 * i, vip->register_save_area[i]); 1293 reg_write(vip, 4 * i, vip->register_save_area[i]);
1501 for (i = 0; i < AUX_COUNT; i++) 1294 for (i = 0; i < AUX_COUNT; i++)
1502 REG_WRITE(vip, registers_to_save[i], 1295 reg_write(vip, registers_to_save[i],
1503 vip->register_save_area[SAVE_COUNT + IRQ_COUNT + i]); 1296 vip->register_save_area[SAVE_COUNT + IRQ_COUNT + i]);
1504 REG_WRITE(vip, DVP_CTL, vip->register_save_area[0]); 1297 reg_write(vip, DVP_CTL, vip->register_save_area[0]);
1505 REG_WRITE(vip, DVP_ITM, vip->register_save_area[SAVE_COUNT]); 1298 reg_write(vip, DVP_ITM, vip->register_save_area[SAVE_COUNT]);
1506 spin_unlock_irqrestore(&vip->slock, flags); 1299 spin_unlock_irqrestore(&vip->slock, flags);
1507 return 0; 1300 return 0;
1508} 1301}
@@ -1515,7 +1308,7 @@ static DEFINE_PCI_DEVICE_TABLE(sta2x11_vip_pci_tbl) = {
1515}; 1308};
1516 1309
1517static struct pci_driver sta2x11_vip_driver = { 1310static struct pci_driver sta2x11_vip_driver = {
1518 .name = DRV_NAME, 1311 .name = KBUILD_MODNAME,
1519 .probe = sta2x11_vip_init_one, 1312 .probe = sta2x11_vip_init_one,
1520 .remove = sta2x11_vip_remove_one, 1313 .remove = sta2x11_vip_remove_one,
1521 .id_table = sta2x11_vip_pci_tbl, 1314 .id_table = sta2x11_vip_pci_tbl,
diff --git a/drivers/media/pci/ttpci/Kconfig b/drivers/media/pci/ttpci/Kconfig
index 314e417addae..0dcb8cd77676 100644
--- a/drivers/media/pci/ttpci/Kconfig
+++ b/drivers/media/pci/ttpci/Kconfig
@@ -1,8 +1,3 @@
1config TTPCI_EEPROM
2 tristate
3 depends on I2C
4 default n
5
6config DVB_AV7110 1config DVB_AV7110
7 tristate "AV7110 cards" 2 tristate "AV7110 cards"
8 depends on DVB_CORE && PCI && I2C 3 depends on DVB_CORE && PCI && I2C
diff --git a/drivers/media/pci/ttpci/av7110.c b/drivers/media/pci/ttpci/av7110.c
index 4656d4a10af0..3dc7aa9b6f40 100644
--- a/drivers/media/pci/ttpci/av7110.c
+++ b/drivers/media/pci/ttpci/av7110.c
@@ -235,7 +235,7 @@ static void recover_arm(struct av7110 *av7110)
235 235
236 restart_feeds(av7110); 236 restart_feeds(av7110);
237 237
238#if defined(CONFIG_INPUT_EVDEV) || defined(CONFIG_INPUT_EVDEV_MODULE) 238#if IS_ENABLED(CONFIG_INPUT_EVDEV)
239 av7110_check_ir_config(av7110, true); 239 av7110_check_ir_config(av7110, true);
240#endif 240#endif
241} 241}
@@ -268,7 +268,7 @@ static int arm_thread(void *data)
268 if (!av7110->arm_ready) 268 if (!av7110->arm_ready)
269 continue; 269 continue;
270 270
271#if defined(CONFIG_INPUT_EVDEV) || defined(CONFIG_INPUT_EVDEV_MODULE) 271#if IS_ENABLED(CONFIG_INPUT_EVDEV)
272 av7110_check_ir_config(av7110, false); 272 av7110_check_ir_config(av7110, false);
273#endif 273#endif
274 274
@@ -1730,7 +1730,7 @@ static int alps_tdlb7_tuner_set_params(struct dvb_frontend *fe)
1730 1730
1731static int alps_tdlb7_request_firmware(struct dvb_frontend* fe, const struct firmware **fw, char* name) 1731static int alps_tdlb7_request_firmware(struct dvb_frontend* fe, const struct firmware **fw, char* name)
1732{ 1732{
1733#if defined(CONFIG_DVB_SP8870) || defined(CONFIG_DVB_SP8870_MODULE) 1733#if IS_ENABLED(CONFIG_DVB_SP8870)
1734 struct av7110* av7110 = fe->dvb->priv; 1734 struct av7110* av7110 = fe->dvb->priv;
1735 1735
1736 return request_firmware(fw, name, &av7110->dev->pci->dev); 1736 return request_firmware(fw, name, &av7110->dev->pci->dev);
@@ -2723,7 +2723,9 @@ static int av7110_attach(struct saa7146_dev* dev,
2723 if (ret < 0) 2723 if (ret < 0)
2724 goto err_av7110_exit_v4l_12; 2724 goto err_av7110_exit_v4l_12;
2725 2725
2726#if defined(CONFIG_INPUT_EVDEV) || defined(CONFIG_INPUT_EVDEV_MODULE) 2726 mutex_init(&av7110->ioctl_mutex);
2727
2728#if IS_ENABLED(CONFIG_INPUT_EVDEV)
2727 av7110_ir_init(av7110); 2729 av7110_ir_init(av7110);
2728#endif 2730#endif
2729 printk(KERN_INFO "dvb-ttpci: found av7110-%d.\n", av7110_num); 2731 printk(KERN_INFO "dvb-ttpci: found av7110-%d.\n", av7110_num);
@@ -2766,7 +2768,7 @@ static int av7110_detach(struct saa7146_dev* saa)
2766 struct av7110 *av7110 = saa->ext_priv; 2768 struct av7110 *av7110 = saa->ext_priv;
2767 dprintk(4, "%p\n", av7110); 2769 dprintk(4, "%p\n", av7110);
2768 2770
2769#if defined(CONFIG_INPUT_EVDEV) || defined(CONFIG_INPUT_EVDEV_MODULE) 2771#if IS_ENABLED(CONFIG_INPUT_EVDEV)
2770 av7110_ir_exit(av7110); 2772 av7110_ir_exit(av7110);
2771#endif 2773#endif
2772 if (budgetpatch || av7110->full_ts) { 2774 if (budgetpatch || av7110->full_ts) {
diff --git a/drivers/media/pci/ttpci/av7110.h b/drivers/media/pci/ttpci/av7110.h
index a378662b1dcf..ef3d9606b269 100644
--- a/drivers/media/pci/ttpci/av7110.h
+++ b/drivers/media/pci/ttpci/av7110.h
@@ -271,6 +271,8 @@ struct av7110 {
271 struct dvb_frontend* fe; 271 struct dvb_frontend* fe;
272 fe_status_t fe_status; 272 fe_status_t fe_status;
273 273
274 struct mutex ioctl_mutex;
275
274 /* crash recovery */ 276 /* crash recovery */
275 void (*recover)(struct av7110* av7110); 277 void (*recover)(struct av7110* av7110);
276 fe_sec_voltage_t saved_voltage; 278 fe_sec_voltage_t saved_voltage;
diff --git a/drivers/media/pci/ttpci/av7110_av.c b/drivers/media/pci/ttpci/av7110_av.c
index 952b33dbac4f..301029ca4535 100644
--- a/drivers/media/pci/ttpci/av7110_av.c
+++ b/drivers/media/pci/ttpci/av7110_av.c
@@ -1109,6 +1109,9 @@ static int dvb_video_ioctl(struct file *file,
1109 } 1109 }
1110 } 1110 }
1111 1111
1112 if (mutex_lock_interruptible(&av7110->ioctl_mutex))
1113 return -ERESTARTSYS;
1114
1112 switch (cmd) { 1115 switch (cmd) {
1113 case VIDEO_STOP: 1116 case VIDEO_STOP:
1114 av7110->videostate.play_state = VIDEO_STOPPED; 1117 av7110->videostate.play_state = VIDEO_STOPPED;
@@ -1297,6 +1300,7 @@ static int dvb_video_ioctl(struct file *file,
1297 break; 1300 break;
1298 } 1301 }
1299 1302
1303 mutex_unlock(&av7110->ioctl_mutex);
1300 return ret; 1304 return ret;
1301} 1305}
1302 1306
@@ -1314,6 +1318,9 @@ static int dvb_audio_ioctl(struct file *file,
1314 (cmd != AUDIO_GET_STATUS)) 1318 (cmd != AUDIO_GET_STATUS))
1315 return -EPERM; 1319 return -EPERM;
1316 1320
1321 if (mutex_lock_interruptible(&av7110->ioctl_mutex))
1322 return -ERESTARTSYS;
1323
1317 switch (cmd) { 1324 switch (cmd) {
1318 case AUDIO_STOP: 1325 case AUDIO_STOP:
1319 if (av7110->audiostate.stream_source == AUDIO_SOURCE_MEMORY) 1326 if (av7110->audiostate.stream_source == AUDIO_SOURCE_MEMORY)
@@ -1442,6 +1449,7 @@ static int dvb_audio_ioctl(struct file *file,
1442 ret = -ENOIOCTLCMD; 1449 ret = -ENOIOCTLCMD;
1443 } 1450 }
1444 1451
1452 mutex_unlock(&av7110->ioctl_mutex);
1445 return ret; 1453 return ret;
1446} 1454}
1447 1455
diff --git a/drivers/media/pci/ttpci/av7110_ca.c b/drivers/media/pci/ttpci/av7110_ca.c
index 9fc1dd0ba4c3..a6079b90252a 100644
--- a/drivers/media/pci/ttpci/av7110_ca.c
+++ b/drivers/media/pci/ttpci/av7110_ca.c
@@ -253,12 +253,17 @@ static int dvb_ca_ioctl(struct file *file, unsigned int cmd, void *parg)
253 struct dvb_device *dvbdev = file->private_data; 253 struct dvb_device *dvbdev = file->private_data;
254 struct av7110 *av7110 = dvbdev->priv; 254 struct av7110 *av7110 = dvbdev->priv;
255 unsigned long arg = (unsigned long) parg; 255 unsigned long arg = (unsigned long) parg;
256 int ret = 0;
256 257
257 dprintk(8, "av7110:%p\n",av7110); 258 dprintk(8, "av7110:%p\n",av7110);
258 259
260 if (mutex_lock_interruptible(&av7110->ioctl_mutex))
261 return -ERESTARTSYS;
262
259 switch (cmd) { 263 switch (cmd) {
260 case CA_RESET: 264 case CA_RESET:
261 return ci_ll_reset(&av7110->ci_wbuffer, file, arg, &av7110->ci_slot[0]); 265 ret = ci_ll_reset(&av7110->ci_wbuffer, file, arg,
266 &av7110->ci_slot[0]);
262 break; 267 break;
263 case CA_GET_CAP: 268 case CA_GET_CAP:
264 { 269 {
@@ -277,8 +282,10 @@ static int dvb_ca_ioctl(struct file *file, unsigned int cmd, void *parg)
277 { 282 {
278 ca_slot_info_t *info=(ca_slot_info_t *)parg; 283 ca_slot_info_t *info=(ca_slot_info_t *)parg;
279 284
280 if (info->num < 0 || info->num > 1) 285 if (info->num < 0 || info->num > 1) {
286 mutex_unlock(&av7110->ioctl_mutex);
281 return -EINVAL; 287 return -EINVAL;
288 }
282 av7110->ci_slot[info->num].num = info->num; 289 av7110->ci_slot[info->num].num = info->num;
283 av7110->ci_slot[info->num].type = FW_CI_LL_SUPPORT(av7110->arm_app) ? 290 av7110->ci_slot[info->num].type = FW_CI_LL_SUPPORT(av7110->arm_app) ?
284 CA_CI_LINK : CA_CI; 291 CA_CI_LINK : CA_CI;
@@ -306,10 +313,10 @@ static int dvb_ca_ioctl(struct file *file, unsigned int cmd, void *parg)
306 { 313 {
307 ca_descr_t *descr = (ca_descr_t*) parg; 314 ca_descr_t *descr = (ca_descr_t*) parg;
308 315
309 if (descr->index >= 16) 316 if (descr->index >= 16 || descr->parity > 1) {
310 return -EINVAL; 317 mutex_unlock(&av7110->ioctl_mutex);
311 if (descr->parity > 1)
312 return -EINVAL; 318 return -EINVAL;
319 }
313 av7110_fw_cmd(av7110, COMTYPE_PIDFILTER, SetDescr, 5, 320 av7110_fw_cmd(av7110, COMTYPE_PIDFILTER, SetDescr, 5,
314 (descr->index<<8)|descr->parity, 321 (descr->index<<8)|descr->parity,
315 (descr->cw[0]<<8)|descr->cw[1], 322 (descr->cw[0]<<8)|descr->cw[1],
@@ -320,9 +327,12 @@ static int dvb_ca_ioctl(struct file *file, unsigned int cmd, void *parg)
320 } 327 }
321 328
322 default: 329 default:
323 return -EINVAL; 330 ret = -EINVAL;
331 break;
324 } 332 }
325 return 0; 333
334 mutex_unlock(&av7110->ioctl_mutex);
335 return ret;
326} 336}
327 337
328static ssize_t dvb_ca_write(struct file *file, const char __user *buf, 338static ssize_t dvb_ca_write(struct file *file, const char __user *buf,
diff --git a/drivers/media/pci/zoran/zoran_card.c b/drivers/media/pci/zoran/zoran_card.c
index a90a3b9b09bf..bb53d2488ad0 100644
--- a/drivers/media/pci/zoran/zoran_card.c
+++ b/drivers/media/pci/zoran/zoran_card.c
@@ -708,8 +708,7 @@ static const struct i2c_algo_bit_data zoran_i2c_bit_data_template = {
708static int 708static int
709zoran_register_i2c (struct zoran *zr) 709zoran_register_i2c (struct zoran *zr)
710{ 710{
711 memcpy(&zr->i2c_algo, &zoran_i2c_bit_data_template, 711 zr->i2c_algo = zoran_i2c_bit_data_template;
712 sizeof(struct i2c_algo_bit_data));
713 zr->i2c_algo.data = zr; 712 zr->i2c_algo.data = zr;
714 strlcpy(zr->i2c_adapter.name, ZR_DEVNAME(zr), 713 strlcpy(zr->i2c_adapter.name, ZR_DEVNAME(zr),
715 sizeof(zr->i2c_adapter.name)); 714 sizeof(zr->i2c_adapter.name));
diff --git a/drivers/media/pci/zoran/zoran_device.c b/drivers/media/pci/zoran/zoran_device.c
index a4cd504b8eee..519164c572c8 100644
--- a/drivers/media/pci/zoran/zoran_device.c
+++ b/drivers/media/pci/zoran/zoran_device.c
@@ -1169,7 +1169,7 @@ zoran_reap_stat_com (struct zoran *zr)
1169 } 1169 }
1170 frame = zr->jpg_pend[zr->jpg_dma_tail & BUZ_MASK_FRAME]; 1170 frame = zr->jpg_pend[zr->jpg_dma_tail & BUZ_MASK_FRAME];
1171 buffer = &zr->jpg_buffers.buffer[frame]; 1171 buffer = &zr->jpg_buffers.buffer[frame];
1172 do_gettimeofday(&buffer->bs.timestamp); 1172 v4l2_get_timestamp(&buffer->bs.timestamp);
1173 1173
1174 if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) { 1174 if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
1175 buffer->bs.length = (stat_com & 0x7fffff) >> 1; 1175 buffer->bs.length = (stat_com & 0x7fffff) >> 1;
@@ -1407,7 +1407,7 @@ zoran_irq (int irq,
1407 1407
1408 zr->v4l_buffers.buffer[zr->v4l_grab_frame].state = BUZ_STATE_DONE; 1408 zr->v4l_buffers.buffer[zr->v4l_grab_frame].state = BUZ_STATE_DONE;
1409 zr->v4l_buffers.buffer[zr->v4l_grab_frame].bs.seq = zr->v4l_grab_seq; 1409 zr->v4l_buffers.buffer[zr->v4l_grab_frame].bs.seq = zr->v4l_grab_seq;
1410 do_gettimeofday(&zr->v4l_buffers.buffer[zr->v4l_grab_frame].bs.timestamp); 1410 v4l2_get_timestamp(&zr->v4l_buffers.buffer[zr->v4l_grab_frame].bs.timestamp);
1411 zr->v4l_grab_frame = NO_GRAB_ACTIVE; 1411 zr->v4l_grab_frame = NO_GRAB_ACTIVE;
1412 zr->v4l_pend_tail++; 1412 zr->v4l_pend_tail++;
1413 } 1413 }
diff --git a/drivers/media/pci/zoran/zoran_driver.c b/drivers/media/pci/zoran/zoran_driver.c
index e60ae41e2319..2e8f518f298f 100644
--- a/drivers/media/pci/zoran/zoran_driver.c
+++ b/drivers/media/pci/zoran/zoran_driver.c
@@ -1334,7 +1334,7 @@ static int zoran_v4l2_buffer_status(struct zoran_fh *fh,
1334 struct zoran *zr = fh->zr; 1334 struct zoran *zr = fh->zr;
1335 unsigned long flags; 1335 unsigned long flags;
1336 1336
1337 buf->flags = V4L2_BUF_FLAG_MAPPED; 1337 buf->flags = V4L2_BUF_FLAG_MAPPED | V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1338 1338
1339 switch (fh->map_mode) { 1339 switch (fh->map_mode) {
1340 case ZORAN_MAP_MODE_RAW: 1340 case ZORAN_MAP_MODE_RAW:
diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index 33241120a58c..05d7b6333461 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -92,7 +92,7 @@ config VIDEO_M32R_AR_M64278
92 92
93config VIDEO_OMAP2 93config VIDEO_OMAP2
94 tristate "OMAP2 Camera Capture Interface driver" 94 tristate "OMAP2 Camera Capture Interface driver"
95 depends on VIDEO_DEV && ARCH_OMAP2 95 depends on VIDEO_DEV && ARCH_OMAP2 && VIDEO_V4L2_INT_DEVICE
96 select VIDEOBUF_DMA_SG 96 select VIDEOBUF_DMA_SG
97 ---help--- 97 ---help---
98 This is a v4l2 driver for the TI OMAP2 camera capture interface 98 This is a v4l2 driver for the TI OMAP2 camera capture interface
@@ -202,6 +202,15 @@ config VIDEO_SAMSUNG_EXYNOS_GSC
202 help 202 help
203 This is a v4l2 driver for Samsung EXYNOS5 SoC G-Scaler. 203 This is a v4l2 driver for Samsung EXYNOS5 SoC G-Scaler.
204 204
205config VIDEO_SH_VEU
206 tristate "SuperH VEU mem2mem video processing driver"
207 depends on VIDEO_DEV && VIDEO_V4L2
208 select VIDEOBUF2_DMA_CONTIG
209 select V4L2_MEM2MEM_DEV
210 help
211 Support for the Video Engine Unit (VEU) on SuperH and
212 SH-Mobile SoCs.
213
205endif # V4L_MEM2MEM_DRIVERS 214endif # V4L_MEM2MEM_DRIVERS
206 215
207menuconfig V4L_TEST_DRIVERS 216menuconfig V4L_TEST_DRIVERS
diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
index 4817d2802171..42089ba3600f 100644
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -25,6 +25,8 @@ obj-$(CONFIG_VIDEO_MEM2MEM_TESTDEV) += mem2mem_testdev.o
25obj-$(CONFIG_VIDEO_MX2_EMMAPRP) += mx2_emmaprp.o 25obj-$(CONFIG_VIDEO_MX2_EMMAPRP) += mx2_emmaprp.o
26obj-$(CONFIG_VIDEO_CODA) += coda.o 26obj-$(CONFIG_VIDEO_CODA) += coda.o
27 27
28obj-$(CONFIG_VIDEO_SH_VEU) += sh_veu.o
29
28obj-$(CONFIG_VIDEO_MEM2MEM_DEINTERLACE) += m2m-deinterlace.o 30obj-$(CONFIG_VIDEO_MEM2MEM_DEINTERLACE) += m2m-deinterlace.o
29 31
30obj-$(CONFIG_VIDEO_S3C_CAMIF) += s3c-camif/ 32obj-$(CONFIG_VIDEO_S3C_CAMIF) += s3c-camif/
diff --git a/drivers/media/platform/blackfin/Kconfig b/drivers/media/platform/blackfin/Kconfig
index ecd5323768b7..cc239972fa2c 100644
--- a/drivers/media/platform/blackfin/Kconfig
+++ b/drivers/media/platform/blackfin/Kconfig
@@ -7,4 +7,9 @@ config VIDEO_BLACKFIN_CAPTURE
7 Choose PPI or EPPI as its interface. 7 Choose PPI or EPPI as its interface.
8 8
9 To compile this driver as a module, choose M here: the 9 To compile this driver as a module, choose M here: the
10 module will be called bfin_video_capture. 10 module will be called bfin_capture.
11
12config VIDEO_BLACKFIN_PPI
13 tristate
14 depends on VIDEO_BLACKFIN_CAPTURE
15 default VIDEO_BLACKFIN_CAPTURE
diff --git a/drivers/media/platform/blackfin/Makefile b/drivers/media/platform/blackfin/Makefile
index aa3a0a216387..30421bc23080 100644
--- a/drivers/media/platform/blackfin/Makefile
+++ b/drivers/media/platform/blackfin/Makefile
@@ -1,2 +1,2 @@
1bfin_video_capture-objs := bfin_capture.o ppi.o 1obj-$(CONFIG_VIDEO_BLACKFIN_CAPTURE) += bfin_capture.o
2obj-$(CONFIG_VIDEO_BLACKFIN_CAPTURE) += bfin_video_capture.o 2obj-$(CONFIG_VIDEO_BLACKFIN_PPI) += ppi.o
diff --git a/drivers/media/platform/blackfin/bfin_capture.c b/drivers/media/platform/blackfin/bfin_capture.c
index 1aad2a65d2f3..5f209d5810dc 100644
--- a/drivers/media/platform/blackfin/bfin_capture.c
+++ b/drivers/media/platform/blackfin/bfin_capture.c
@@ -52,6 +52,7 @@ struct bcap_format {
52 u32 pixelformat; 52 u32 pixelformat;
53 enum v4l2_mbus_pixelcode mbus_code; 53 enum v4l2_mbus_pixelcode mbus_code;
54 int bpp; /* bits per pixel */ 54 int bpp; /* bits per pixel */
55 int dlen; /* data length for ppi in bits */
55}; 56};
56 57
57struct bcap_buffer { 58struct bcap_buffer {
@@ -76,18 +77,20 @@ struct bcap_device {
76 unsigned int cur_input; 77 unsigned int cur_input;
77 /* current selected standard */ 78 /* current selected standard */
78 v4l2_std_id std; 79 v4l2_std_id std;
80 /* current selected dv_timings */
81 struct v4l2_dv_timings dv_timings;
79 /* used to store pixel format */ 82 /* used to store pixel format */
80 struct v4l2_pix_format fmt; 83 struct v4l2_pix_format fmt;
81 /* bits per pixel*/ 84 /* bits per pixel*/
82 int bpp; 85 int bpp;
86 /* data length for ppi in bits */
87 int dlen;
83 /* used to store sensor supported format */ 88 /* used to store sensor supported format */
84 struct bcap_format *sensor_formats; 89 struct bcap_format *sensor_formats;
85 /* number of sensor formats array */ 90 /* number of sensor formats array */
86 int num_sensor_formats; 91 int num_sensor_formats;
87 /* pointing to current video buffer */ 92 /* pointing to current video buffer */
88 struct bcap_buffer *cur_frm; 93 struct bcap_buffer *cur_frm;
89 /* pointing to next video buffer */
90 struct bcap_buffer *next_frm;
91 /* buffer queue used in videobuf2 */ 94 /* buffer queue used in videobuf2 */
92 struct vb2_queue buffer_queue; 95 struct vb2_queue buffer_queue;
93 /* allocator-specific contexts for each plane */ 96 /* allocator-specific contexts for each plane */
@@ -116,24 +119,35 @@ static const struct bcap_format bcap_formats[] = {
116 .pixelformat = V4L2_PIX_FMT_UYVY, 119 .pixelformat = V4L2_PIX_FMT_UYVY,
117 .mbus_code = V4L2_MBUS_FMT_UYVY8_2X8, 120 .mbus_code = V4L2_MBUS_FMT_UYVY8_2X8,
118 .bpp = 16, 121 .bpp = 16,
122 .dlen = 8,
119 }, 123 },
120 { 124 {
121 .desc = "YCbCr 4:2:2 Interleaved YUYV", 125 .desc = "YCbCr 4:2:2 Interleaved YUYV",
122 .pixelformat = V4L2_PIX_FMT_YUYV, 126 .pixelformat = V4L2_PIX_FMT_YUYV,
123 .mbus_code = V4L2_MBUS_FMT_YUYV8_2X8, 127 .mbus_code = V4L2_MBUS_FMT_YUYV8_2X8,
124 .bpp = 16, 128 .bpp = 16,
129 .dlen = 8,
130 },
131 {
132 .desc = "YCbCr 4:2:2 Interleaved UYVY",
133 .pixelformat = V4L2_PIX_FMT_UYVY,
134 .mbus_code = V4L2_MBUS_FMT_UYVY8_1X16,
135 .bpp = 16,
136 .dlen = 16,
125 }, 137 },
126 { 138 {
127 .desc = "RGB 565", 139 .desc = "RGB 565",
128 .pixelformat = V4L2_PIX_FMT_RGB565, 140 .pixelformat = V4L2_PIX_FMT_RGB565,
129 .mbus_code = V4L2_MBUS_FMT_RGB565_2X8_LE, 141 .mbus_code = V4L2_MBUS_FMT_RGB565_2X8_LE,
130 .bpp = 16, 142 .bpp = 16,
143 .dlen = 8,
131 }, 144 },
132 { 145 {
133 .desc = "RGB 444", 146 .desc = "RGB 444",
134 .pixelformat = V4L2_PIX_FMT_RGB444, 147 .pixelformat = V4L2_PIX_FMT_RGB444,
135 .mbus_code = V4L2_MBUS_FMT_RGB444_2X8_PADHI_LE, 148 .mbus_code = V4L2_MBUS_FMT_RGB444_2X8_PADHI_LE,
136 .bpp = 16, 149 .bpp = 16,
150 .dlen = 8,
137 }, 151 },
138 152
139}; 153};
@@ -366,9 +380,39 @@ static int bcap_start_streaming(struct vb2_queue *vq, unsigned int count)
366 params.width = bcap_dev->fmt.width; 380 params.width = bcap_dev->fmt.width;
367 params.height = bcap_dev->fmt.height; 381 params.height = bcap_dev->fmt.height;
368 params.bpp = bcap_dev->bpp; 382 params.bpp = bcap_dev->bpp;
383 params.dlen = bcap_dev->dlen;
369 params.ppi_control = bcap_dev->cfg->ppi_control; 384 params.ppi_control = bcap_dev->cfg->ppi_control;
370 params.int_mask = bcap_dev->cfg->int_mask; 385 params.int_mask = bcap_dev->cfg->int_mask;
371 params.blank_clocks = bcap_dev->cfg->blank_clocks; 386 if (bcap_dev->cfg->inputs[bcap_dev->cur_input].capabilities
387 & V4L2_IN_CAP_CUSTOM_TIMINGS) {
388 struct v4l2_bt_timings *bt = &bcap_dev->dv_timings.bt;
389
390 params.hdelay = bt->hsync + bt->hbackporch;
391 params.vdelay = bt->vsync + bt->vbackporch;
392 params.line = bt->hfrontporch + bt->hsync
393 + bt->hbackporch + bt->width;
394 params.frame = bt->vfrontporch + bt->vsync
395 + bt->vbackporch + bt->height;
396 if (bt->interlaced)
397 params.frame += bt->il_vfrontporch + bt->il_vsync
398 + bt->il_vbackporch;
399 } else if (bcap_dev->cfg->inputs[bcap_dev->cur_input].capabilities
400 & V4L2_IN_CAP_STD) {
401 params.hdelay = 0;
402 params.vdelay = 0;
403 if (bcap_dev->std & V4L2_STD_525_60) {
404 params.line = 858;
405 params.frame = 525;
406 } else {
407 params.line = 864;
408 params.frame = 625;
409 }
410 } else {
411 params.hdelay = 0;
412 params.vdelay = 0;
413 params.line = params.width + bcap_dev->cfg->blank_pixels;
414 params.frame = params.height;
415 }
372 ret = ppi->ops->set_params(ppi, &params); 416 ret = ppi->ops->set_params(ppi, &params);
373 if (ret < 0) { 417 if (ret < 0) {
374 v4l2_err(&bcap_dev->v4l2_dev, 418 v4l2_err(&bcap_dev->v4l2_dev,
@@ -409,10 +453,10 @@ static int bcap_stop_streaming(struct vb2_queue *vq)
409 453
410 /* release all active buffers */ 454 /* release all active buffers */
411 while (!list_empty(&bcap_dev->dma_queue)) { 455 while (!list_empty(&bcap_dev->dma_queue)) {
412 bcap_dev->next_frm = list_entry(bcap_dev->dma_queue.next, 456 bcap_dev->cur_frm = list_entry(bcap_dev->dma_queue.next,
413 struct bcap_buffer, list); 457 struct bcap_buffer, list);
414 list_del(&bcap_dev->next_frm->list); 458 list_del(&bcap_dev->cur_frm->list);
415 vb2_buffer_done(&bcap_dev->next_frm->vb, VB2_BUF_STATE_ERROR); 459 vb2_buffer_done(&bcap_dev->cur_frm->vb, VB2_BUF_STATE_ERROR);
416 } 460 }
417 return 0; 461 return 0;
418} 462}
@@ -484,17 +528,26 @@ static irqreturn_t bcap_isr(int irq, void *dev_id)
484{ 528{
485 struct ppi_if *ppi = dev_id; 529 struct ppi_if *ppi = dev_id;
486 struct bcap_device *bcap_dev = ppi->priv; 530 struct bcap_device *bcap_dev = ppi->priv;
487 struct timeval timevalue;
488 struct vb2_buffer *vb = &bcap_dev->cur_frm->vb; 531 struct vb2_buffer *vb = &bcap_dev->cur_frm->vb;
489 dma_addr_t addr; 532 dma_addr_t addr;
490 533
491 spin_lock(&bcap_dev->lock); 534 spin_lock(&bcap_dev->lock);
492 535
493 if (bcap_dev->cur_frm != bcap_dev->next_frm) { 536 if (!list_empty(&bcap_dev->dma_queue)) {
494 do_gettimeofday(&timevalue); 537 v4l2_get_timestamp(&vb->v4l2_buf.timestamp);
495 vb->v4l2_buf.timestamp = timevalue; 538 if (ppi->err) {
496 vb2_buffer_done(vb, VB2_BUF_STATE_DONE); 539 vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
497 bcap_dev->cur_frm = bcap_dev->next_frm; 540 ppi->err = false;
541 } else {
542 vb2_buffer_done(vb, VB2_BUF_STATE_DONE);
543 }
544 bcap_dev->cur_frm = list_entry(bcap_dev->dma_queue.next,
545 struct bcap_buffer, list);
546 list_del(&bcap_dev->cur_frm->list);
547 } else {
548 /* clear error flag, we will get a new frame */
549 if (ppi->err)
550 ppi->err = false;
498 } 551 }
499 552
500 ppi->ops->stop(ppi); 553 ppi->ops->stop(ppi);
@@ -502,13 +555,8 @@ static irqreturn_t bcap_isr(int irq, void *dev_id)
502 if (bcap_dev->stop) { 555 if (bcap_dev->stop) {
503 complete(&bcap_dev->comp); 556 complete(&bcap_dev->comp);
504 } else { 557 } else {
505 if (!list_empty(&bcap_dev->dma_queue)) { 558 addr = vb2_dma_contig_plane_dma_addr(&bcap_dev->cur_frm->vb, 0);
506 bcap_dev->next_frm = list_entry(bcap_dev->dma_queue.next, 559 ppi->ops->update_addr(ppi, (unsigned long)addr);
507 struct bcap_buffer, list);
508 list_del(&bcap_dev->next_frm->list);
509 addr = vb2_dma_contig_plane_dma_addr(&bcap_dev->next_frm->vb, 0);
510 ppi->ops->update_addr(ppi, (unsigned long)addr);
511 }
512 ppi->ops->start(ppi); 560 ppi->ops->start(ppi);
513 } 561 }
514 562
@@ -542,9 +590,8 @@ static int bcap_streamon(struct file *file, void *priv,
542 } 590 }
543 591
544 /* get the next frame from the dma queue */ 592 /* get the next frame from the dma queue */
545 bcap_dev->next_frm = list_entry(bcap_dev->dma_queue.next, 593 bcap_dev->cur_frm = list_entry(bcap_dev->dma_queue.next,
546 struct bcap_buffer, list); 594 struct bcap_buffer, list);
547 bcap_dev->cur_frm = bcap_dev->next_frm;
548 /* remove buffer from the dma queue */ 595 /* remove buffer from the dma queue */
549 list_del(&bcap_dev->cur_frm->list); 596 list_del(&bcap_dev->cur_frm->list);
550 addr = vb2_dma_contig_plane_dma_addr(&bcap_dev->cur_frm->vb, 0); 597 addr = vb2_dma_contig_plane_dma_addr(&bcap_dev->cur_frm->vb, 0);
@@ -602,6 +649,37 @@ static int bcap_s_std(struct file *file, void *priv, v4l2_std_id *std)
602 return 0; 649 return 0;
603} 650}
604 651
652static int bcap_g_dv_timings(struct file *file, void *priv,
653 struct v4l2_dv_timings *timings)
654{
655 struct bcap_device *bcap_dev = video_drvdata(file);
656 int ret;
657
658 ret = v4l2_subdev_call(bcap_dev->sd, video,
659 g_dv_timings, timings);
660 if (ret < 0)
661 return ret;
662
663 bcap_dev->dv_timings = *timings;
664 return 0;
665}
666
667static int bcap_s_dv_timings(struct file *file, void *priv,
668 struct v4l2_dv_timings *timings)
669{
670 struct bcap_device *bcap_dev = video_drvdata(file);
671 int ret;
672 if (vb2_is_busy(&bcap_dev->buffer_queue))
673 return -EBUSY;
674
675 ret = v4l2_subdev_call(bcap_dev->sd, video, s_dv_timings, timings);
676 if (ret < 0)
677 return ret;
678
679 bcap_dev->dv_timings = *timings;
680 return 0;
681}
682
605static int bcap_enum_input(struct file *file, void *priv, 683static int bcap_enum_input(struct file *file, void *priv,
606 struct v4l2_input *input) 684 struct v4l2_input *input)
607{ 685{
@@ -650,13 +728,15 @@ static int bcap_s_input(struct file *file, void *priv, unsigned int index)
650 return ret; 728 return ret;
651 } 729 }
652 bcap_dev->cur_input = index; 730 bcap_dev->cur_input = index;
731 /* if this route has specific config, update ppi control */
732 if (route->ppi_control)
733 config->ppi_control = route->ppi_control;
653 return 0; 734 return 0;
654} 735}
655 736
656static int bcap_try_format(struct bcap_device *bcap, 737static int bcap_try_format(struct bcap_device *bcap,
657 struct v4l2_pix_format *pixfmt, 738 struct v4l2_pix_format *pixfmt,
658 enum v4l2_mbus_pixelcode *mbus_code, 739 struct bcap_format *bcap_fmt)
659 int *bpp)
660{ 740{
661 struct bcap_format *sf = bcap->sensor_formats; 741 struct bcap_format *sf = bcap->sensor_formats;
662 struct bcap_format *fmt = NULL; 742 struct bcap_format *fmt = NULL;
@@ -671,16 +751,20 @@ static int bcap_try_format(struct bcap_device *bcap,
671 if (i == bcap->num_sensor_formats) 751 if (i == bcap->num_sensor_formats)
672 fmt = &sf[0]; 752 fmt = &sf[0];
673 753
674 if (mbus_code)
675 *mbus_code = fmt->mbus_code;
676 if (bpp)
677 *bpp = fmt->bpp;
678 v4l2_fill_mbus_format(&mbus_fmt, pixfmt, fmt->mbus_code); 754 v4l2_fill_mbus_format(&mbus_fmt, pixfmt, fmt->mbus_code);
679 ret = v4l2_subdev_call(bcap->sd, video, 755 ret = v4l2_subdev_call(bcap->sd, video,
680 try_mbus_fmt, &mbus_fmt); 756 try_mbus_fmt, &mbus_fmt);
681 if (ret < 0) 757 if (ret < 0)
682 return ret; 758 return ret;
683 v4l2_fill_pix_format(pixfmt, &mbus_fmt); 759 v4l2_fill_pix_format(pixfmt, &mbus_fmt);
760 if (bcap_fmt) {
761 for (i = 0; i < bcap->num_sensor_formats; i++) {
762 fmt = &sf[i];
763 if (mbus_fmt.code == fmt->mbus_code)
764 break;
765 }
766 *bcap_fmt = *fmt;
767 }
684 pixfmt->bytesperline = pixfmt->width * fmt->bpp / 8; 768 pixfmt->bytesperline = pixfmt->width * fmt->bpp / 8;
685 pixfmt->sizeimage = pixfmt->bytesperline * pixfmt->height; 769 pixfmt->sizeimage = pixfmt->bytesperline * pixfmt->height;
686 return 0; 770 return 0;
@@ -709,7 +793,7 @@ static int bcap_try_fmt_vid_cap(struct file *file, void *priv,
709 struct bcap_device *bcap_dev = video_drvdata(file); 793 struct bcap_device *bcap_dev = video_drvdata(file);
710 struct v4l2_pix_format *pixfmt = &fmt->fmt.pix; 794 struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
711 795
712 return bcap_try_format(bcap_dev, pixfmt, NULL, NULL); 796 return bcap_try_format(bcap_dev, pixfmt, NULL);
713} 797}
714 798
715static int bcap_g_fmt_vid_cap(struct file *file, void *priv, 799static int bcap_g_fmt_vid_cap(struct file *file, void *priv,
@@ -726,24 +810,25 @@ static int bcap_s_fmt_vid_cap(struct file *file, void *priv,
726{ 810{
727 struct bcap_device *bcap_dev = video_drvdata(file); 811 struct bcap_device *bcap_dev = video_drvdata(file);
728 struct v4l2_mbus_framefmt mbus_fmt; 812 struct v4l2_mbus_framefmt mbus_fmt;
729 enum v4l2_mbus_pixelcode mbus_code; 813 struct bcap_format bcap_fmt;
730 struct v4l2_pix_format *pixfmt = &fmt->fmt.pix; 814 struct v4l2_pix_format *pixfmt = &fmt->fmt.pix;
731 int ret, bpp; 815 int ret;
732 816
733 if (vb2_is_busy(&bcap_dev->buffer_queue)) 817 if (vb2_is_busy(&bcap_dev->buffer_queue))
734 return -EBUSY; 818 return -EBUSY;
735 819
736 /* see if format works */ 820 /* see if format works */
737 ret = bcap_try_format(bcap_dev, pixfmt, &mbus_code, &bpp); 821 ret = bcap_try_format(bcap_dev, pixfmt, &bcap_fmt);
738 if (ret < 0) 822 if (ret < 0)
739 return ret; 823 return ret;
740 824
741 v4l2_fill_mbus_format(&mbus_fmt, pixfmt, mbus_code); 825 v4l2_fill_mbus_format(&mbus_fmt, pixfmt, bcap_fmt.mbus_code);
742 ret = v4l2_subdev_call(bcap_dev->sd, video, s_mbus_fmt, &mbus_fmt); 826 ret = v4l2_subdev_call(bcap_dev->sd, video, s_mbus_fmt, &mbus_fmt);
743 if (ret < 0) 827 if (ret < 0)
744 return ret; 828 return ret;
745 bcap_dev->fmt = *pixfmt; 829 bcap_dev->fmt = *pixfmt;
746 bcap_dev->bpp = bpp; 830 bcap_dev->bpp = bcap_fmt.bpp;
831 bcap_dev->dlen = bcap_fmt.dlen;
747 return 0; 832 return 0;
748} 833}
749 834
@@ -834,6 +919,8 @@ static const struct v4l2_ioctl_ops bcap_ioctl_ops = {
834 .vidioc_querystd = bcap_querystd, 919 .vidioc_querystd = bcap_querystd,
835 .vidioc_s_std = bcap_s_std, 920 .vidioc_s_std = bcap_s_std,
836 .vidioc_g_std = bcap_g_std, 921 .vidioc_g_std = bcap_g_std,
922 .vidioc_s_dv_timings = bcap_s_dv_timings,
923 .vidioc_g_dv_timings = bcap_g_dv_timings,
837 .vidioc_reqbufs = bcap_reqbufs, 924 .vidioc_reqbufs = bcap_reqbufs,
838 .vidioc_querybuf = bcap_querybuf, 925 .vidioc_querybuf = bcap_querybuf,
839 .vidioc_qbuf = bcap_qbuf, 926 .vidioc_qbuf = bcap_qbuf,
@@ -869,6 +956,7 @@ static int bcap_probe(struct platform_device *pdev)
869 struct i2c_adapter *i2c_adap; 956 struct i2c_adapter *i2c_adap;
870 struct bfin_capture_config *config; 957 struct bfin_capture_config *config;
871 struct vb2_queue *q; 958 struct vb2_queue *q;
959 struct bcap_route *route;
872 int ret; 960 int ret;
873 961
874 config = pdev->dev.platform_data; 962 config = pdev->dev.platform_data;
@@ -978,6 +1066,12 @@ static int bcap_probe(struct platform_device *pdev)
978 NULL); 1066 NULL);
979 if (bcap_dev->sd) { 1067 if (bcap_dev->sd) {
980 int i; 1068 int i;
1069 if (!config->num_inputs) {
1070 v4l2_err(&bcap_dev->v4l2_dev,
1071 "Unable to work without input\n");
1072 goto err_unreg_vdev;
1073 }
1074
981 /* update tvnorms from the sub devices */ 1075 /* update tvnorms from the sub devices */
982 for (i = 0; i < config->num_inputs; i++) 1076 for (i = 0; i < config->num_inputs; i++)
983 vfd->tvnorms |= config->inputs[i].std; 1077 vfd->tvnorms |= config->inputs[i].std;
@@ -989,8 +1083,24 @@ static int bcap_probe(struct platform_device *pdev)
989 1083
990 v4l2_info(&bcap_dev->v4l2_dev, "v4l2 sub device registered\n"); 1084 v4l2_info(&bcap_dev->v4l2_dev, "v4l2 sub device registered\n");
991 1085
1086 /*
1087 * explicitly set input, otherwise some boards
1088 * may not work at the state as we expected
1089 */
1090 route = &config->routes[0];
1091 ret = v4l2_subdev_call(bcap_dev->sd, video, s_routing,
1092 route->input, route->output, 0);
1093 if ((ret < 0) && (ret != -ENOIOCTLCMD)) {
1094 v4l2_err(&bcap_dev->v4l2_dev, "Failed to set input\n");
1095 goto err_unreg_vdev;
1096 }
1097 bcap_dev->cur_input = 0;
1098 /* if this route has specific config, update ppi control */
1099 if (route->ppi_control)
1100 config->ppi_control = route->ppi_control;
1101
992 /* now we can probe the default state */ 1102 /* now we can probe the default state */
993 if (vfd->tvnorms) { 1103 if (config->inputs[0].capabilities & V4L2_IN_CAP_STD) {
994 v4l2_std_id std; 1104 v4l2_std_id std;
995 ret = v4l2_subdev_call(bcap_dev->sd, core, g_std, &std); 1105 ret = v4l2_subdev_call(bcap_dev->sd, core, g_std, &std);
996 if (ret) { 1106 if (ret) {
@@ -1000,6 +1110,17 @@ static int bcap_probe(struct platform_device *pdev)
1000 } 1110 }
1001 bcap_dev->std = std; 1111 bcap_dev->std = std;
1002 } 1112 }
1113 if (config->inputs[0].capabilities & V4L2_IN_CAP_CUSTOM_TIMINGS) {
1114 struct v4l2_dv_timings dv_timings;
1115 ret = v4l2_subdev_call(bcap_dev->sd, video,
1116 g_dv_timings, &dv_timings);
1117 if (ret) {
1118 v4l2_err(&bcap_dev->v4l2_dev,
1119 "Unable to get dv timings\n");
1120 goto err_unreg_vdev;
1121 }
1122 bcap_dev->dv_timings = dv_timings;
1123 }
1003 ret = bcap_init_sensor_formats(bcap_dev); 1124 ret = bcap_init_sensor_formats(bcap_dev);
1004 if (ret) { 1125 if (ret) {
1005 v4l2_err(&bcap_dev->v4l2_dev, 1126 v4l2_err(&bcap_dev->v4l2_dev,
diff --git a/drivers/media/platform/blackfin/ppi.c b/drivers/media/platform/blackfin/ppi.c
index d29592186b02..01b5b501347e 100644
--- a/drivers/media/platform/blackfin/ppi.c
+++ b/drivers/media/platform/blackfin/ppi.c
@@ -17,6 +17,7 @@
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */ 18 */
19 19
20#include <linux/module.h>
20#include <linux/slab.h> 21#include <linux/slab.h>
21 22
22#include <asm/bfin_ppi.h> 23#include <asm/bfin_ppi.h>
@@ -58,15 +59,33 @@ static irqreturn_t ppi_irq_err(int irq, void *dev_id)
58 * others are W1C 59 * others are W1C
59 */ 60 */
60 status = bfin_read16(&reg->status); 61 status = bfin_read16(&reg->status);
62 if (status & 0x3000)
63 ppi->err = true;
61 bfin_write16(&reg->status, 0xff00); 64 bfin_write16(&reg->status, 0xff00);
62 break; 65 break;
63 } 66 }
64 case PPI_TYPE_EPPI: 67 case PPI_TYPE_EPPI:
65 { 68 {
66 struct bfin_eppi_regs *reg = info->base; 69 struct bfin_eppi_regs *reg = info->base;
70 unsigned short status;
71
72 status = bfin_read16(&reg->status);
73 if (status & 0x2)
74 ppi->err = true;
67 bfin_write16(&reg->status, 0xffff); 75 bfin_write16(&reg->status, 0xffff);
68 break; 76 break;
69 } 77 }
78 case PPI_TYPE_EPPI3:
79 {
80 struct bfin_eppi3_regs *reg = info->base;
81 unsigned long stat;
82
83 stat = bfin_read32(&reg->stat);
84 if (stat & 0x2)
85 ppi->err = true;
86 bfin_write32(&reg->stat, 0xc0ff);
87 break;
88 }
70 default: 89 default:
71 break; 90 break;
72 } 91 }
@@ -128,6 +147,12 @@ static int ppi_start(struct ppi_if *ppi)
128 bfin_write32(&reg->control, ppi->ppi_control); 147 bfin_write32(&reg->control, ppi->ppi_control);
129 break; 148 break;
130 } 149 }
150 case PPI_TYPE_EPPI3:
151 {
152 struct bfin_eppi3_regs *reg = info->base;
153 bfin_write32(&reg->ctl, ppi->ppi_control);
154 break;
155 }
131 default: 156 default:
132 return -EINVAL; 157 return -EINVAL;
133 } 158 }
@@ -155,6 +180,12 @@ static int ppi_stop(struct ppi_if *ppi)
155 bfin_write32(&reg->control, ppi->ppi_control); 180 bfin_write32(&reg->control, ppi->ppi_control);
156 break; 181 break;
157 } 182 }
183 case PPI_TYPE_EPPI3:
184 {
185 struct bfin_eppi3_regs *reg = info->base;
186 bfin_write32(&reg->ctl, ppi->ppi_control);
187 break;
188 }
158 default: 189 default:
159 return -EINVAL; 190 return -EINVAL;
160 } 191 }
@@ -171,17 +202,23 @@ static int ppi_set_params(struct ppi_if *ppi, struct ppi_params *params)
171{ 202{
172 const struct ppi_info *info = ppi->info; 203 const struct ppi_info *info = ppi->info;
173 int dma32 = 0; 204 int dma32 = 0;
174 int dma_config, bytes_per_line, lines_per_frame; 205 int dma_config, bytes_per_line;
206 int hcount, hdelay, samples_per_line;
175 207
176 bytes_per_line = params->width * params->bpp / 8; 208 bytes_per_line = params->width * params->bpp / 8;
177 lines_per_frame = params->height; 209 /* convert parameters unit from pixels to samples */
210 hcount = params->width * params->bpp / params->dlen;
211 hdelay = params->hdelay * params->bpp / params->dlen;
212 samples_per_line = params->line * params->bpp / params->dlen;
178 if (params->int_mask == 0xFFFFFFFF) 213 if (params->int_mask == 0xFFFFFFFF)
179 ppi->err_int = false; 214 ppi->err_int = false;
180 else 215 else
181 ppi->err_int = true; 216 ppi->err_int = true;
182 217
183 dma_config = (DMA_FLOW_STOP | WNR | RESTART | DMA2D | DI_EN); 218 dma_config = (DMA_FLOW_STOP | RESTART | DMA2D | DI_EN_Y);
184 ppi->ppi_control = params->ppi_control & ~PORT_EN; 219 ppi->ppi_control = params->ppi_control & ~PORT_EN;
220 if (!(ppi->ppi_control & PORT_DIR))
221 dma_config |= WNR;
185 switch (info->type) { 222 switch (info->type) {
186 case PPI_TYPE_PPI: 223 case PPI_TYPE_PPI:
187 { 224 {
@@ -191,8 +228,8 @@ static int ppi_set_params(struct ppi_if *ppi, struct ppi_params *params)
191 dma32 = 1; 228 dma32 = 1;
192 229
193 bfin_write16(&reg->control, ppi->ppi_control); 230 bfin_write16(&reg->control, ppi->ppi_control);
194 bfin_write16(&reg->count, bytes_per_line - 1); 231 bfin_write16(&reg->count, samples_per_line - 1);
195 bfin_write16(&reg->frame, lines_per_frame); 232 bfin_write16(&reg->frame, params->frame);
196 break; 233 break;
197 } 234 }
198 case PPI_TYPE_EPPI: 235 case PPI_TYPE_EPPI:
@@ -204,12 +241,31 @@ static int ppi_set_params(struct ppi_if *ppi, struct ppi_params *params)
204 dma32 = 1; 241 dma32 = 1;
205 242
206 bfin_write32(&reg->control, ppi->ppi_control); 243 bfin_write32(&reg->control, ppi->ppi_control);
207 bfin_write16(&reg->line, bytes_per_line + params->blank_clocks); 244 bfin_write16(&reg->line, samples_per_line);
208 bfin_write16(&reg->frame, lines_per_frame); 245 bfin_write16(&reg->frame, params->frame);
209 bfin_write16(&reg->hdelay, 0); 246 bfin_write16(&reg->hdelay, hdelay);
210 bfin_write16(&reg->vdelay, 0); 247 bfin_write16(&reg->vdelay, params->vdelay);
211 bfin_write16(&reg->hcount, bytes_per_line); 248 bfin_write16(&reg->hcount, hcount);
212 bfin_write16(&reg->vcount, lines_per_frame); 249 bfin_write16(&reg->vcount, params->height);
250 break;
251 }
252 case PPI_TYPE_EPPI3:
253 {
254 struct bfin_eppi3_regs *reg = info->base;
255
256 if ((params->ppi_control & PACK_EN)
257 || (params->ppi_control & 0x70000) > DLEN_16)
258 dma32 = 1;
259
260 bfin_write32(&reg->ctl, ppi->ppi_control);
261 bfin_write32(&reg->line, samples_per_line);
262 bfin_write32(&reg->frame, params->frame);
263 bfin_write32(&reg->hdly, hdelay);
264 bfin_write32(&reg->vdly, params->vdelay);
265 bfin_write32(&reg->hcnt, hcount);
266 bfin_write32(&reg->vcnt, params->height);
267 if (params->int_mask)
268 bfin_write32(&reg->imsk, params->int_mask & 0xFF);
213 break; 269 break;
214 } 270 }
215 default: 271 default:
@@ -217,17 +273,17 @@ static int ppi_set_params(struct ppi_if *ppi, struct ppi_params *params)
217 } 273 }
218 274
219 if (dma32) { 275 if (dma32) {
220 dma_config |= WDSIZE_32; 276 dma_config |= WDSIZE_32 | PSIZE_32;
221 set_dma_x_count(info->dma_ch, bytes_per_line >> 2); 277 set_dma_x_count(info->dma_ch, bytes_per_line >> 2);
222 set_dma_x_modify(info->dma_ch, 4); 278 set_dma_x_modify(info->dma_ch, 4);
223 set_dma_y_modify(info->dma_ch, 4); 279 set_dma_y_modify(info->dma_ch, 4);
224 } else { 280 } else {
225 dma_config |= WDSIZE_16; 281 dma_config |= WDSIZE_16 | PSIZE_16;
226 set_dma_x_count(info->dma_ch, bytes_per_line >> 1); 282 set_dma_x_count(info->dma_ch, bytes_per_line >> 1);
227 set_dma_x_modify(info->dma_ch, 2); 283 set_dma_x_modify(info->dma_ch, 2);
228 set_dma_y_modify(info->dma_ch, 2); 284 set_dma_y_modify(info->dma_ch, 2);
229 } 285 }
230 set_dma_y_count(info->dma_ch, lines_per_frame); 286 set_dma_y_count(info->dma_ch, params->height);
231 set_dma_config(info->dma_ch, dma_config); 287 set_dma_config(info->dma_ch, dma_config);
232 288
233 SSYNC(); 289 SSYNC();
@@ -263,9 +319,15 @@ struct ppi_if *ppi_create_instance(const struct ppi_info *info)
263 pr_info("ppi probe success\n"); 319 pr_info("ppi probe success\n");
264 return ppi; 320 return ppi;
265} 321}
322EXPORT_SYMBOL(ppi_create_instance);
266 323
267void ppi_delete_instance(struct ppi_if *ppi) 324void ppi_delete_instance(struct ppi_if *ppi)
268{ 325{
269 peripheral_free_list(ppi->info->pin_req); 326 peripheral_free_list(ppi->info->pin_req);
270 kfree(ppi); 327 kfree(ppi);
271} 328}
329EXPORT_SYMBOL(ppi_delete_instance);
330
331MODULE_DESCRIPTION("Analog Devices PPI driver");
332MODULE_AUTHOR("Scott Jiang <Scott.Jiang.Linux@gmail.com>");
333MODULE_LICENSE("GPL v2");
diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index 4a980e029ca7..20827ba168fc 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -178,6 +178,10 @@ struct coda_ctx {
178 int idx; 178 int idx;
179}; 179};
180 180
181static const u8 coda_filler_nal[14] = { 0x00, 0x00, 0x00, 0x01, 0x0c, 0xff,
182 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80 };
183static const u8 coda_filler_size[8] = { 0, 7, 14, 13, 12, 11, 10, 9 };
184
181static inline void coda_write(struct coda_dev *dev, u32 data, u32 reg) 185static inline void coda_write(struct coda_dev *dev, u32 data, u32 reg)
182{ 186{
183 v4l2_dbg(1, coda_debug, &dev->v4l2_dev, 187 v4l2_dbg(1, coda_debug, &dev->v4l2_dev,
@@ -944,6 +948,24 @@ static int coda_alloc_framebuffers(struct coda_ctx *ctx, struct coda_q_data *q_d
944 return 0; 948 return 0;
945} 949}
946 950
951static int coda_h264_padding(int size, char *p)
952{
953 int nal_size;
954 int diff;
955
956 diff = size - (size & ~0x7);
957 if (diff == 0)
958 return 0;
959
960 nal_size = coda_filler_size[diff];
961 memcpy(p, coda_filler_nal, nal_size);
962
963 /* Add rbsp stop bit and trailing at the end */
964 *(p + nal_size - 1) = 0x80;
965
966 return nal_size;
967}
968
947static int coda_start_streaming(struct vb2_queue *q, unsigned int count) 969static int coda_start_streaming(struct vb2_queue *q, unsigned int count)
948{ 970{
949 struct coda_ctx *ctx = vb2_get_drv_priv(q); 971 struct coda_ctx *ctx = vb2_get_drv_priv(q);
@@ -1171,7 +1193,15 @@ static int coda_start_streaming(struct vb2_queue *q, unsigned int count)
1171 coda_read(dev, CODA_CMD_ENC_HEADER_BB_START); 1193 coda_read(dev, CODA_CMD_ENC_HEADER_BB_START);
1172 memcpy(&ctx->vpu_header[1][0], vb2_plane_vaddr(buf, 0), 1194 memcpy(&ctx->vpu_header[1][0], vb2_plane_vaddr(buf, 0),
1173 ctx->vpu_header_size[1]); 1195 ctx->vpu_header_size[1]);
1174 ctx->vpu_header_size[2] = 0; 1196 /*
1197 * Length of H.264 headers is variable and thus it might not be
1198 * aligned for the coda to append the encoded frame. In that is
1199 * the case a filler NAL must be added to header 2.
1200 */
1201 ctx->vpu_header_size[2] = coda_h264_padding(
1202 (ctx->vpu_header_size[0] +
1203 ctx->vpu_header_size[1]),
1204 ctx->vpu_header[2]);
1175 break; 1205 break;
1176 case V4L2_PIX_FMT_MPEG4: 1206 case V4L2_PIX_FMT_MPEG4:
1177 /* 1207 /*
diff --git a/drivers/media/platform/davinci/Kconfig b/drivers/media/platform/davinci/Kconfig
index 3c56037c82fc..ccfde4eb626a 100644
--- a/drivers/media/platform/davinci/Kconfig
+++ b/drivers/media/platform/davinci/Kconfig
@@ -97,25 +97,15 @@ config VIDEO_ISIF
97 To compile this driver as a module, choose M here: the 97 To compile this driver as a module, choose M here: the
98 module will be called vpfe. 98 module will be called vpfe.
99 99
100config VIDEO_DM644X_VPBE 100config VIDEO_DAVINCI_VPBE_DISPLAY
101 tristate "DM644X VPBE HW module" 101 tristate "DM644X/DM365/DM355 VPBE HW module"
102 depends on ARCH_DAVINCI_DM644x 102 depends on ARCH_DAVINCI_DM644x || ARCH_DAVINCI_DM355 || ARCH_DAVINCI_DM365
103 select VIDEO_VPSS_SYSTEM 103 select VIDEO_VPSS_SYSTEM
104 select VIDEOBUF2_DMA_CONTIG 104 select VIDEOBUF2_DMA_CONTIG
105 help 105 help
106 Enables VPBE modules used for display on a DM644x 106 Enables Davinci VPBE module used for display devices.
107 SoC. 107 This module is common for following DM644x/DM365/DM355
108 based display devices.
108 109
109 To compile this driver as a module, choose M here: the 110 To compile this driver as a module, choose M here: the
110 module will be called vpbe. 111 module will be called vpbe.
111
112
113config VIDEO_VPBE_DISPLAY
114 tristate "VPBE V4L2 Display driver"
115 depends on ARCH_DAVINCI_DM644x
116 select VIDEO_DM644X_VPBE
117 help
118 Enables VPBE V4L2 Display driver on a DM644x device
119
120 To compile this driver as a module, choose M here: the
121 module will be called vpbe_display.
diff --git a/drivers/media/platform/davinci/Makefile b/drivers/media/platform/davinci/Makefile
index 74ed92d09257..f40f5219ca50 100644
--- a/drivers/media/platform/davinci/Makefile
+++ b/drivers/media/platform/davinci/Makefile
@@ -16,5 +16,5 @@ obj-$(CONFIG_VIDEO_VPFE_CAPTURE) += vpfe_capture.o
16obj-$(CONFIG_VIDEO_DM6446_CCDC) += dm644x_ccdc.o 16obj-$(CONFIG_VIDEO_DM6446_CCDC) += dm644x_ccdc.o
17obj-$(CONFIG_VIDEO_DM355_CCDC) += dm355_ccdc.o 17obj-$(CONFIG_VIDEO_DM355_CCDC) += dm355_ccdc.o
18obj-$(CONFIG_VIDEO_ISIF) += isif.o 18obj-$(CONFIG_VIDEO_ISIF) += isif.o
19obj-$(CONFIG_VIDEO_DM644X_VPBE) += vpbe.o vpbe_osd.o vpbe_venc.o 19obj-$(CONFIG_VIDEO_DAVINCI_VPBE_DISPLAY) += vpbe.o vpbe_osd.o \
20obj-$(CONFIG_VIDEO_VPBE_DISPLAY) += vpbe_display.o 20 vpbe_venc.o vpbe_display.o
diff --git a/drivers/media/platform/davinci/dm355_ccdc.c b/drivers/media/platform/davinci/dm355_ccdc.c
index f263cabade7a..4277e4ad810c 100644
--- a/drivers/media/platform/davinci/dm355_ccdc.c
+++ b/drivers/media/platform/davinci/dm355_ccdc.c
@@ -557,7 +557,7 @@ static int ccdc_config_vdfc(struct ccdc_vertical_dft *dfc)
557 */ 557 */
558static void ccdc_config_csc(struct ccdc_csc *csc) 558static void ccdc_config_csc(struct ccdc_csc *csc)
559{ 559{
560 u32 val1, val2; 560 u32 val1 = 0, val2;
561 int i; 561 int i;
562 562
563 if (!csc->enable) 563 if (!csc->enable)
diff --git a/drivers/media/platform/davinci/vpbe.c b/drivers/media/platform/davinci/vpbe.c
index 841b91a3d255..4ca0f9a2ad8a 100644
--- a/drivers/media/platform/davinci/vpbe.c
+++ b/drivers/media/platform/davinci/vpbe.c
@@ -558,9 +558,9 @@ static int platform_device_get(struct device *dev, void *data)
558 struct platform_device *pdev = to_platform_device(dev); 558 struct platform_device *pdev = to_platform_device(dev);
559 struct vpbe_device *vpbe_dev = data; 559 struct vpbe_device *vpbe_dev = data;
560 560
561 if (strcmp("vpbe-osd", pdev->name) == 0) 561 if (strstr(pdev->name, "vpbe-osd") != NULL)
562 vpbe_dev->osd_device = platform_get_drvdata(pdev); 562 vpbe_dev->osd_device = platform_get_drvdata(pdev);
563 if (strcmp("vpbe-venc", pdev->name) == 0) 563 if (strstr(pdev->name, "vpbe-venc") != NULL)
564 vpbe_dev->venc_device = dev_get_platdata(&pdev->dev); 564 vpbe_dev->venc_device = dev_get_platdata(&pdev->dev);
565 565
566 return 0; 566 return 0;
@@ -584,7 +584,6 @@ static int vpbe_initialize(struct device *dev, struct vpbe_device *vpbe_dev)
584 struct v4l2_subdev **enc_subdev; 584 struct v4l2_subdev **enc_subdev;
585 struct osd_state *osd_device; 585 struct osd_state *osd_device;
586 struct i2c_adapter *i2c_adap; 586 struct i2c_adapter *i2c_adap;
587 int output_index;
588 int num_encoders; 587 int num_encoders;
589 int ret = 0; 588 int ret = 0;
590 int err; 589 int err;
@@ -632,8 +631,10 @@ static int vpbe_initialize(struct device *dev, struct vpbe_device *vpbe_dev)
632 631
633 err = bus_for_each_dev(&platform_bus_type, NULL, vpbe_dev, 632 err = bus_for_each_dev(&platform_bus_type, NULL, vpbe_dev,
634 platform_device_get); 633 platform_device_get);
635 if (err < 0) 634 if (err < 0) {
636 return err; 635 ret = err;
636 goto fail_dev_unregister;
637 }
637 638
638 vpbe_dev->venc = venc_sub_dev_init(&vpbe_dev->v4l2_dev, 639 vpbe_dev->venc = venc_sub_dev_init(&vpbe_dev->v4l2_dev,
639 vpbe_dev->cfg->venc.module_name); 640 vpbe_dev->cfg->venc.module_name);
@@ -731,7 +732,6 @@ static int vpbe_initialize(struct device *dev, struct vpbe_device *vpbe_dev)
731 /* set the current encoder and output to that of venc by default */ 732 /* set the current encoder and output to that of venc by default */
732 vpbe_dev->current_sd_index = 0; 733 vpbe_dev->current_sd_index = 0;
733 vpbe_dev->current_out_index = 0; 734 vpbe_dev->current_out_index = 0;
734 output_index = 0;
735 735
736 mutex_unlock(&vpbe_dev->lock); 736 mutex_unlock(&vpbe_dev->lock);
737 737
diff --git a/drivers/media/platform/davinci/vpbe_display.c b/drivers/media/platform/davinci/vpbe_display.c
index e707a6f2325b..5e6b0cab514b 100644
--- a/drivers/media/platform/davinci/vpbe_display.c
+++ b/drivers/media/platform/davinci/vpbe_display.c
@@ -791,7 +791,6 @@ static int vpbe_display_g_crop(struct file *file, void *priv,
791 struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev; 791 struct vpbe_device *vpbe_dev = fh->disp_dev->vpbe_dev;
792 struct osd_state *osd_device = fh->disp_dev->osd_device; 792 struct osd_state *osd_device = fh->disp_dev->osd_device;
793 struct v4l2_rect *rect = &crop->c; 793 struct v4l2_rect *rect = &crop->c;
794 int ret;
795 794
796 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev, 795 v4l2_dbg(1, debug, &vpbe_dev->v4l2_dev,
797 "VIDIOC_G_CROP, layer id = %d\n", 796 "VIDIOC_G_CROP, layer id = %d\n",
@@ -799,7 +798,7 @@ static int vpbe_display_g_crop(struct file *file, void *priv,
799 798
800 if (crop->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) { 799 if (crop->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) {
801 v4l2_err(&vpbe_dev->v4l2_dev, "Invalid buf type\n"); 800 v4l2_err(&vpbe_dev->v4l2_dev, "Invalid buf type\n");
802 ret = -EINVAL; 801 return -EINVAL;
803 } 802 }
804 osd_device->ops.get_layer_config(osd_device, 803 osd_device->ops.get_layer_config(osd_device,
805 layer->layer_info.id, cfg); 804 layer->layer_info.id, cfg);
@@ -1393,9 +1392,9 @@ static int vpbe_display_reqbufs(struct file *file, void *priv,
1393 } 1392 }
1394 /* Initialize videobuf queue as per the buffer type */ 1393 /* Initialize videobuf queue as per the buffer type */
1395 layer->alloc_ctx = vb2_dma_contig_init_ctx(vpbe_dev->pdev); 1394 layer->alloc_ctx = vb2_dma_contig_init_ctx(vpbe_dev->pdev);
1396 if (!layer->alloc_ctx) { 1395 if (IS_ERR(layer->alloc_ctx)) {
1397 v4l2_err(&vpbe_dev->v4l2_dev, "Failed to get the context\n"); 1396 v4l2_err(&vpbe_dev->v4l2_dev, "Failed to get the context\n");
1398 return -EINVAL; 1397 return PTR_ERR(layer->alloc_ctx);
1399 } 1398 }
1400 q = &layer->buffer_queue; 1399 q = &layer->buffer_queue;
1401 memset(q, 0, sizeof(*q)); 1400 memset(q, 0, sizeof(*q));
@@ -1656,7 +1655,7 @@ static int vpbe_device_get(struct device *dev, void *data)
1656 if (strcmp("vpbe_controller", pdev->name) == 0) 1655 if (strcmp("vpbe_controller", pdev->name) == 0)
1657 vpbe_disp->vpbe_dev = platform_get_drvdata(pdev); 1656 vpbe_disp->vpbe_dev = platform_get_drvdata(pdev);
1658 1657
1659 if (strcmp("vpbe-osd", pdev->name) == 0) 1658 if (strstr(pdev->name, "vpbe-osd") != NULL)
1660 vpbe_disp->osd_device = platform_get_drvdata(pdev); 1659 vpbe_disp->osd_device = platform_get_drvdata(pdev);
1661 1660
1662 return 0; 1661 return 0;
diff --git a/drivers/media/platform/davinci/vpbe_osd.c b/drivers/media/platform/davinci/vpbe_osd.c
index 707f243f810d..12ad17c52ef3 100644
--- a/drivers/media/platform/davinci/vpbe_osd.c
+++ b/drivers/media/platform/davinci/vpbe_osd.c
@@ -39,7 +39,22 @@
39#include <linux/io.h> 39#include <linux/io.h>
40#include "vpbe_osd_regs.h" 40#include "vpbe_osd_regs.h"
41 41
42#define MODULE_NAME VPBE_OSD_SUBDEV_NAME 42#define MODULE_NAME "davinci-vpbe-osd"
43
44static struct platform_device_id vpbe_osd_devtype[] = {
45 {
46 .name = DM644X_VPBE_OSD_SUBDEV_NAME,
47 .driver_data = VPBE_VERSION_1,
48 }, {
49 .name = DM365_VPBE_OSD_SUBDEV_NAME,
50 .driver_data = VPBE_VERSION_2,
51 }, {
52 .name = DM355_VPBE_OSD_SUBDEV_NAME,
53 .driver_data = VPBE_VERSION_3,
54 },
55};
56
57MODULE_DEVICE_TABLE(platform, vpbe_osd_devtype);
43 58
44/* register access routines */ 59/* register access routines */
45static inline u32 osd_read(struct osd_state *sd, u32 offset) 60static inline u32 osd_read(struct osd_state *sd, u32 offset)
@@ -129,7 +144,7 @@ static int _osd_dm6446_vid0_pingpong(struct osd_state *sd,
129 struct osd_platform_data *pdata; 144 struct osd_platform_data *pdata;
130 145
131 pdata = (struct osd_platform_data *)sd->dev->platform_data; 146 pdata = (struct osd_platform_data *)sd->dev->platform_data;
132 if (pdata->field_inv_wa_enable) { 147 if (pdata != NULL && pdata->field_inv_wa_enable) {
133 148
134 if (!field_inversion || !lconfig->interlaced) { 149 if (!field_inversion || !lconfig->interlaced) {
135 osd_write(sd, fb_base_phys & ~0x1F, OSD_VIDWIN0ADR); 150 osd_write(sd, fb_base_phys & ~0x1F, OSD_VIDWIN0ADR);
@@ -1526,7 +1541,7 @@ static const struct vpbe_osd_ops osd_ops = {
1526 1541
1527static int osd_probe(struct platform_device *pdev) 1542static int osd_probe(struct platform_device *pdev)
1528{ 1543{
1529 struct osd_platform_data *pdata; 1544 const struct platform_device_id *pdev_id;
1530 struct osd_state *osd; 1545 struct osd_state *osd;
1531 struct resource *res; 1546 struct resource *res;
1532 int ret = 0; 1547 int ret = 0;
@@ -1535,16 +1550,15 @@ static int osd_probe(struct platform_device *pdev)
1535 if (osd == NULL) 1550 if (osd == NULL)
1536 return -ENOMEM; 1551 return -ENOMEM;
1537 1552
1538 osd->dev = &pdev->dev; 1553 pdev_id = platform_get_device_id(pdev);
1539 pdata = (struct osd_platform_data *)pdev->dev.platform_data; 1554 if (!pdev_id) {
1540 osd->vpbe_type = (enum vpbe_version)pdata->vpbe_type; 1555 ret = -EINVAL;
1541 if (NULL == pdev->dev.platform_data) {
1542 dev_err(osd->dev, "No platform data defined for OSD"
1543 " sub device\n");
1544 ret = -ENOENT;
1545 goto free_mem; 1556 goto free_mem;
1546 } 1557 }
1547 1558
1559 osd->dev = &pdev->dev;
1560 osd->vpbe_type = pdev_id->driver_data;
1561
1548 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1562 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1549 if (!res) { 1563 if (!res) {
1550 dev_err(osd->dev, "Unable to get OSD register address map\n"); 1564 dev_err(osd->dev, "Unable to get OSD register address map\n");
@@ -1595,6 +1609,7 @@ static struct platform_driver osd_driver = {
1595 .name = MODULE_NAME, 1609 .name = MODULE_NAME,
1596 .owner = THIS_MODULE, 1610 .owner = THIS_MODULE,
1597 }, 1611 },
1612 .id_table = vpbe_osd_devtype
1598}; 1613};
1599 1614
1600module_platform_driver(osd_driver); 1615module_platform_driver(osd_driver);
diff --git a/drivers/media/platform/davinci/vpbe_venc.c b/drivers/media/platform/davinci/vpbe_venc.c
index aed7369b962a..bdbebd59df98 100644
--- a/drivers/media/platform/davinci/vpbe_venc.c
+++ b/drivers/media/platform/davinci/vpbe_venc.c
@@ -38,7 +38,22 @@
38 38
39#include "vpbe_venc_regs.h" 39#include "vpbe_venc_regs.h"
40 40
41#define MODULE_NAME VPBE_VENC_SUBDEV_NAME 41#define MODULE_NAME "davinci-vpbe-venc"
42
43static struct platform_device_id vpbe_venc_devtype[] = {
44 {
45 .name = DM644X_VPBE_VENC_SUBDEV_NAME,
46 .driver_data = VPBE_VERSION_1,
47 }, {
48 .name = DM365_VPBE_VENC_SUBDEV_NAME,
49 .driver_data = VPBE_VERSION_2,
50 }, {
51 .name = DM355_VPBE_VENC_SUBDEV_NAME,
52 .driver_data = VPBE_VERSION_3,
53 },
54};
55
56MODULE_DEVICE_TABLE(platform, vpbe_venc_devtype);
42 57
43static int debug = 2; 58static int debug = 2;
44module_param(debug, int, 0644); 59module_param(debug, int, 0644);
@@ -54,6 +69,7 @@ struct venc_state {
54 spinlock_t lock; 69 spinlock_t lock;
55 void __iomem *venc_base; 70 void __iomem *venc_base;
56 void __iomem *vdaccfg_reg; 71 void __iomem *vdaccfg_reg;
72 enum vpbe_version venc_type;
57}; 73};
58 74
59static inline struct venc_state *to_state(struct v4l2_subdev *sd) 75static inline struct venc_state *to_state(struct v4l2_subdev *sd)
@@ -127,7 +143,7 @@ static int venc_set_dac(struct v4l2_subdev *sd, u32 out_index)
127static void venc_enabledigitaloutput(struct v4l2_subdev *sd, int benable) 143static void venc_enabledigitaloutput(struct v4l2_subdev *sd, int benable)
128{ 144{
129 struct venc_state *venc = to_state(sd); 145 struct venc_state *venc = to_state(sd);
130 struct venc_platform_data *pdata = venc->pdata; 146
131 v4l2_dbg(debug, 2, sd, "venc_enabledigitaloutput\n"); 147 v4l2_dbg(debug, 2, sd, "venc_enabledigitaloutput\n");
132 148
133 if (benable) { 149 if (benable) {
@@ -159,7 +175,7 @@ static void venc_enabledigitaloutput(struct v4l2_subdev *sd, int benable)
159 175
160 /* Disable LCD output control (accepting default polarity) */ 176 /* Disable LCD output control (accepting default polarity) */
161 venc_write(sd, VENC_LCDOUT, 0); 177 venc_write(sd, VENC_LCDOUT, 0);
162 if (pdata->venc_type != VPBE_VERSION_3) 178 if (venc->venc_type != VPBE_VERSION_3)
163 venc_write(sd, VENC_CMPNT, 0x100); 179 venc_write(sd, VENC_CMPNT, 0x100);
164 venc_write(sd, VENC_HSPLS, 0); 180 venc_write(sd, VENC_HSPLS, 0);
165 venc_write(sd, VENC_HINT, 0); 181 venc_write(sd, VENC_HINT, 0);
@@ -203,11 +219,11 @@ static int venc_set_ntsc(struct v4l2_subdev *sd)
203 219
204 venc_enabledigitaloutput(sd, 0); 220 venc_enabledigitaloutput(sd, 0);
205 221
206 if (pdata->venc_type == VPBE_VERSION_3) { 222 if (venc->venc_type == VPBE_VERSION_3) {
207 venc_write(sd, VENC_CLKCTL, 0x01); 223 venc_write(sd, VENC_CLKCTL, 0x01);
208 venc_write(sd, VENC_VIDCTL, 0); 224 venc_write(sd, VENC_VIDCTL, 0);
209 val = vdaccfg_write(sd, VDAC_CONFIG_SD_V3); 225 val = vdaccfg_write(sd, VDAC_CONFIG_SD_V3);
210 } else if (pdata->venc_type == VPBE_VERSION_2) { 226 } else if (venc->venc_type == VPBE_VERSION_2) {
211 venc_write(sd, VENC_CLKCTL, 0x01); 227 venc_write(sd, VENC_CLKCTL, 0x01);
212 venc_write(sd, VENC_VIDCTL, 0); 228 venc_write(sd, VENC_VIDCTL, 0);
213 vdaccfg_write(sd, VDAC_CONFIG_SD_V2); 229 vdaccfg_write(sd, VDAC_CONFIG_SD_V2);
@@ -238,7 +254,6 @@ static int venc_set_ntsc(struct v4l2_subdev *sd)
238static int venc_set_pal(struct v4l2_subdev *sd) 254static int venc_set_pal(struct v4l2_subdev *sd)
239{ 255{
240 struct venc_state *venc = to_state(sd); 256 struct venc_state *venc = to_state(sd);
241 struct venc_platform_data *pdata = venc->pdata;
242 257
243 v4l2_dbg(debug, 2, sd, "venc_set_pal\n"); 258 v4l2_dbg(debug, 2, sd, "venc_set_pal\n");
244 259
@@ -249,11 +264,11 @@ static int venc_set_pal(struct v4l2_subdev *sd)
249 264
250 venc_enabledigitaloutput(sd, 0); 265 venc_enabledigitaloutput(sd, 0);
251 266
252 if (pdata->venc_type == VPBE_VERSION_3) { 267 if (venc->venc_type == VPBE_VERSION_3) {
253 venc_write(sd, VENC_CLKCTL, 0x1); 268 venc_write(sd, VENC_CLKCTL, 0x1);
254 venc_write(sd, VENC_VIDCTL, 0); 269 venc_write(sd, VENC_VIDCTL, 0);
255 vdaccfg_write(sd, VDAC_CONFIG_SD_V3); 270 vdaccfg_write(sd, VDAC_CONFIG_SD_V3);
256 } else if (pdata->venc_type == VPBE_VERSION_2) { 271 } else if (venc->venc_type == VPBE_VERSION_2) {
257 venc_write(sd, VENC_CLKCTL, 0x1); 272 venc_write(sd, VENC_CLKCTL, 0x1);
258 venc_write(sd, VENC_VIDCTL, 0); 273 venc_write(sd, VENC_VIDCTL, 0);
259 vdaccfg_write(sd, VDAC_CONFIG_SD_V2); 274 vdaccfg_write(sd, VDAC_CONFIG_SD_V2);
@@ -293,8 +308,8 @@ static int venc_set_480p59_94(struct v4l2_subdev *sd)
293 struct venc_platform_data *pdata = venc->pdata; 308 struct venc_platform_data *pdata = venc->pdata;
294 309
295 v4l2_dbg(debug, 2, sd, "venc_set_480p59_94\n"); 310 v4l2_dbg(debug, 2, sd, "venc_set_480p59_94\n");
296 if ((pdata->venc_type != VPBE_VERSION_1) && 311 if (venc->venc_type != VPBE_VERSION_1 &&
297 (pdata->venc_type != VPBE_VERSION_2)) 312 venc->venc_type != VPBE_VERSION_2)
298 return -EINVAL; 313 return -EINVAL;
299 314
300 /* Setup clock at VPSS & VENC for SD */ 315 /* Setup clock at VPSS & VENC for SD */
@@ -303,12 +318,12 @@ static int venc_set_480p59_94(struct v4l2_subdev *sd)
303 318
304 venc_enabledigitaloutput(sd, 0); 319 venc_enabledigitaloutput(sd, 0);
305 320
306 if (pdata->venc_type == VPBE_VERSION_2) 321 if (venc->venc_type == VPBE_VERSION_2)
307 vdaccfg_write(sd, VDAC_CONFIG_HD_V2); 322 vdaccfg_write(sd, VDAC_CONFIG_HD_V2);
308 venc_write(sd, VENC_OSDCLK0, 0); 323 venc_write(sd, VENC_OSDCLK0, 0);
309 venc_write(sd, VENC_OSDCLK1, 1); 324 venc_write(sd, VENC_OSDCLK1, 1);
310 325
311 if (pdata->venc_type == VPBE_VERSION_1) { 326 if (venc->venc_type == VPBE_VERSION_1) {
312 venc_modify(sd, VENC_VDPRO, VENC_VDPRO_DAFRQ, 327 venc_modify(sd, VENC_VDPRO, VENC_VDPRO_DAFRQ,
313 VENC_VDPRO_DAFRQ); 328 VENC_VDPRO_DAFRQ);
314 venc_modify(sd, VENC_VDPRO, VENC_VDPRO_DAUPS, 329 venc_modify(sd, VENC_VDPRO, VENC_VDPRO_DAUPS,
@@ -341,8 +356,8 @@ static int venc_set_576p50(struct v4l2_subdev *sd)
341 356
342 v4l2_dbg(debug, 2, sd, "venc_set_576p50\n"); 357 v4l2_dbg(debug, 2, sd, "venc_set_576p50\n");
343 358
344 if ((pdata->venc_type != VPBE_VERSION_1) && 359 if (venc->venc_type != VPBE_VERSION_1 &&
345 (pdata->venc_type != VPBE_VERSION_2)) 360 venc->venc_type != VPBE_VERSION_2)
346 return -EINVAL; 361 return -EINVAL;
347 /* Setup clock at VPSS & VENC for SD */ 362 /* Setup clock at VPSS & VENC for SD */
348 if (pdata->setup_clock(VPBE_ENC_CUSTOM_TIMINGS, 27000000) < 0) 363 if (pdata->setup_clock(VPBE_ENC_CUSTOM_TIMINGS, 27000000) < 0)
@@ -350,13 +365,13 @@ static int venc_set_576p50(struct v4l2_subdev *sd)
350 365
351 venc_enabledigitaloutput(sd, 0); 366 venc_enabledigitaloutput(sd, 0);
352 367
353 if (pdata->venc_type == VPBE_VERSION_2) 368 if (venc->venc_type == VPBE_VERSION_2)
354 vdaccfg_write(sd, VDAC_CONFIG_HD_V2); 369 vdaccfg_write(sd, VDAC_CONFIG_HD_V2);
355 370
356 venc_write(sd, VENC_OSDCLK0, 0); 371 venc_write(sd, VENC_OSDCLK0, 0);
357 venc_write(sd, VENC_OSDCLK1, 1); 372 venc_write(sd, VENC_OSDCLK1, 1);
358 373
359 if (pdata->venc_type == VPBE_VERSION_1) { 374 if (venc->venc_type == VPBE_VERSION_1) {
360 venc_modify(sd, VENC_VDPRO, VENC_VDPRO_DAFRQ, 375 venc_modify(sd, VENC_VDPRO, VENC_VDPRO_DAFRQ,
361 VENC_VDPRO_DAFRQ); 376 VENC_VDPRO_DAFRQ);
362 venc_modify(sd, VENC_VDPRO, VENC_VDPRO_DAUPS, 377 venc_modify(sd, VENC_VDPRO, VENC_VDPRO_DAUPS,
@@ -460,14 +475,14 @@ static int venc_s_dv_timings(struct v4l2_subdev *sd,
460 else if (height == 480) 475 else if (height == 480)
461 return venc_set_480p59_94(sd); 476 return venc_set_480p59_94(sd);
462 else if ((height == 720) && 477 else if ((height == 720) &&
463 (venc->pdata->venc_type == VPBE_VERSION_2)) { 478 (venc->venc_type == VPBE_VERSION_2)) {
464 /* TBD setup internal 720p mode here */ 479 /* TBD setup internal 720p mode here */
465 ret = venc_set_720p60_internal(sd); 480 ret = venc_set_720p60_internal(sd);
466 /* for DM365 VPBE, there is DAC inside */ 481 /* for DM365 VPBE, there is DAC inside */
467 vdaccfg_write(sd, VDAC_CONFIG_HD_V2); 482 vdaccfg_write(sd, VDAC_CONFIG_HD_V2);
468 return ret; 483 return ret;
469 } else if ((height == 1080) && 484 } else if ((height == 1080) &&
470 (venc->pdata->venc_type == VPBE_VERSION_2)) { 485 (venc->venc_type == VPBE_VERSION_2)) {
471 /* TBD setup internal 1080i mode here */ 486 /* TBD setup internal 1080i mode here */
472 ret = venc_set_1080i30_internal(sd); 487 ret = venc_set_1080i30_internal(sd);
473 /* for DM365 VPBE, there is DAC inside */ 488 /* for DM365 VPBE, there is DAC inside */
@@ -556,7 +571,7 @@ static int venc_device_get(struct device *dev, void *data)
556 struct platform_device *pdev = to_platform_device(dev); 571 struct platform_device *pdev = to_platform_device(dev);
557 struct venc_state **venc = data; 572 struct venc_state **venc = data;
558 573
559 if (strcmp(MODULE_NAME, pdev->name) == 0) 574 if (strstr(pdev->name, "vpbe-venc") != NULL)
560 *venc = platform_get_drvdata(pdev); 575 *venc = platform_get_drvdata(pdev);
561 576
562 return 0; 577 return 0;
@@ -593,6 +608,7 @@ EXPORT_SYMBOL(venc_sub_dev_init);
593 608
594static int venc_probe(struct platform_device *pdev) 609static int venc_probe(struct platform_device *pdev)
595{ 610{
611 const struct platform_device_id *pdev_id;
596 struct venc_state *venc; 612 struct venc_state *venc;
597 struct resource *res; 613 struct resource *res;
598 int ret; 614 int ret;
@@ -601,6 +617,12 @@ static int venc_probe(struct platform_device *pdev)
601 if (venc == NULL) 617 if (venc == NULL)
602 return -ENOMEM; 618 return -ENOMEM;
603 619
620 pdev_id = platform_get_device_id(pdev);
621 if (!pdev_id) {
622 ret = -EINVAL;
623 goto free_mem;
624 }
625 venc->venc_type = pdev_id->driver_data;
604 venc->pdev = &pdev->dev; 626 venc->pdev = &pdev->dev;
605 venc->pdata = pdev->dev.platform_data; 627 venc->pdata = pdev->dev.platform_data;
606 if (NULL == venc->pdata) { 628 if (NULL == venc->pdata) {
@@ -630,7 +652,7 @@ static int venc_probe(struct platform_device *pdev)
630 goto release_venc_mem_region; 652 goto release_venc_mem_region;
631 } 653 }
632 654
633 if (venc->pdata->venc_type != VPBE_VERSION_1) { 655 if (venc->venc_type != VPBE_VERSION_1) {
634 res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 656 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
635 if (!res) { 657 if (!res) {
636 dev_err(venc->pdev, 658 dev_err(venc->pdev,
@@ -681,7 +703,7 @@ static int venc_remove(struct platform_device *pdev)
681 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 703 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
682 iounmap((void *)venc->venc_base); 704 iounmap((void *)venc->venc_base);
683 release_mem_region(res->start, resource_size(res)); 705 release_mem_region(res->start, resource_size(res));
684 if (venc->pdata->venc_type != VPBE_VERSION_1) { 706 if (venc->venc_type != VPBE_VERSION_1) {
685 res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 707 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
686 iounmap((void *)venc->vdaccfg_reg); 708 iounmap((void *)venc->vdaccfg_reg);
687 release_mem_region(res->start, resource_size(res)); 709 release_mem_region(res->start, resource_size(res));
@@ -698,6 +720,7 @@ static struct platform_driver venc_driver = {
698 .name = MODULE_NAME, 720 .name = MODULE_NAME,
699 .owner = THIS_MODULE, 721 .owner = THIS_MODULE,
700 }, 722 },
723 .id_table = vpbe_venc_devtype
701}; 724};
702 725
703module_platform_driver(venc_driver); 726module_platform_driver(venc_driver);
diff --git a/drivers/media/platform/davinci/vpfe_capture.c b/drivers/media/platform/davinci/vpfe_capture.c
index be9d3e1b4868..28d019da4c01 100644
--- a/drivers/media/platform/davinci/vpfe_capture.c
+++ b/drivers/media/platform/davinci/vpfe_capture.c
@@ -560,10 +560,7 @@ static void vpfe_schedule_bottom_field(struct vpfe_device *vpfe_dev)
560 560
561static void vpfe_process_buffer_complete(struct vpfe_device *vpfe_dev) 561static void vpfe_process_buffer_complete(struct vpfe_device *vpfe_dev)
562{ 562{
563 struct timeval timevalue; 563 v4l2_get_timestamp(&vpfe_dev->cur_frm->ts);
564
565 do_gettimeofday(&timevalue);
566 vpfe_dev->cur_frm->ts = timevalue;
567 vpfe_dev->cur_frm->state = VIDEOBUF_DONE; 564 vpfe_dev->cur_frm->state = VIDEOBUF_DONE;
568 vpfe_dev->cur_frm->size = vpfe_dev->fmt.fmt.pix.sizeimage; 565 vpfe_dev->cur_frm->size = vpfe_dev->fmt.fmt.pix.sizeimage;
569 wake_up_interruptible(&vpfe_dev->cur_frm->done); 566 wake_up_interruptible(&vpfe_dev->cur_frm->done);
diff --git a/drivers/media/platform/davinci/vpif_capture.c b/drivers/media/platform/davinci/vpif_capture.c
index a409ccefb380..5892d2bc8eee 100644
--- a/drivers/media/platform/davinci/vpif_capture.c
+++ b/drivers/media/platform/davinci/vpif_capture.c
@@ -411,7 +411,7 @@ static struct vb2_ops video_qops = {
411 */ 411 */
412static void vpif_process_buffer_complete(struct common_obj *common) 412static void vpif_process_buffer_complete(struct common_obj *common)
413{ 413{
414 do_gettimeofday(&common->cur_frm->vb.v4l2_buf.timestamp); 414 v4l2_get_timestamp(&common->cur_frm->vb.v4l2_buf.timestamp);
415 vb2_buffer_done(&common->cur_frm->vb, 415 vb2_buffer_done(&common->cur_frm->vb,
416 VB2_BUF_STATE_DONE); 416 VB2_BUF_STATE_DONE);
417 /* Make curFrm pointing to nextFrm */ 417 /* Make curFrm pointing to nextFrm */
diff --git a/drivers/media/platform/davinci/vpif_display.c b/drivers/media/platform/davinci/vpif_display.c
index 9f2b603be9c9..dd249c96126d 100644
--- a/drivers/media/platform/davinci/vpif_display.c
+++ b/drivers/media/platform/davinci/vpif_display.c
@@ -402,7 +402,7 @@ static void process_interlaced_mode(int fid, struct common_obj *common)
402 /* one frame is displayed If next frame is 402 /* one frame is displayed If next frame is
403 * available, release cur_frm and move on */ 403 * available, release cur_frm and move on */
404 /* Copy frame display time */ 404 /* Copy frame display time */
405 do_gettimeofday(&common->cur_frm->vb.v4l2_buf.timestamp); 405 v4l2_get_timestamp(&common->cur_frm->vb.v4l2_buf.timestamp);
406 /* Change status of the cur_frm */ 406 /* Change status of the cur_frm */
407 vb2_buffer_done(&common->cur_frm->vb, 407 vb2_buffer_done(&common->cur_frm->vb,
408 VB2_BUF_STATE_DONE); 408 VB2_BUF_STATE_DONE);
@@ -462,8 +462,8 @@ static irqreturn_t vpif_channel_isr(int irq, void *dev_id)
462 if (!channel_first_int[i][channel_id]) { 462 if (!channel_first_int[i][channel_id]) {
463 /* Mark status of the cur_frm to 463 /* Mark status of the cur_frm to
464 * done and unlock semaphore on it */ 464 * done and unlock semaphore on it */
465 do_gettimeofday(&common->cur_frm->vb. 465 v4l2_get_timestamp(&common->cur_frm->vb.
466 v4l2_buf.timestamp); 466 v4l2_buf.timestamp);
467 vb2_buffer_done(&common->cur_frm->vb, 467 vb2_buffer_done(&common->cur_frm->vb,
468 VB2_BUF_STATE_DONE); 468 VB2_BUF_STATE_DONE);
469 /* Make cur_frm pointing to next_frm */ 469 /* Make cur_frm pointing to next_frm */
diff --git a/drivers/media/platform/davinci/vpss.c b/drivers/media/platform/davinci/vpss.c
index 684e815a81b6..a19c552232d1 100644
--- a/drivers/media/platform/davinci/vpss.c
+++ b/drivers/media/platform/davinci/vpss.c
@@ -50,13 +50,29 @@ MODULE_AUTHOR("Texas Instruments");
50/* VENCINT - vpss_int8 */ 50/* VENCINT - vpss_int8 */
51#define DM355_VPSSBL_EVTSEL_DEFAULT 0x4 51#define DM355_VPSSBL_EVTSEL_DEFAULT 0x4
52 52
53#define DM365_ISP5_PCCR 0x04 53#define DM365_ISP5_PCCR 0x04
54#define DM365_ISP5_PCCR_BL_CLK_ENABLE BIT(0)
55#define DM365_ISP5_PCCR_ISIF_CLK_ENABLE BIT(1)
56#define DM365_ISP5_PCCR_H3A_CLK_ENABLE BIT(2)
57#define DM365_ISP5_PCCR_RSZ_CLK_ENABLE BIT(3)
58#define DM365_ISP5_PCCR_IPIPE_CLK_ENABLE BIT(4)
59#define DM365_ISP5_PCCR_IPIPEIF_CLK_ENABLE BIT(5)
60#define DM365_ISP5_PCCR_RSV BIT(6)
61
62#define DM365_ISP5_BCR 0x08
63#define DM365_ISP5_BCR_ISIF_OUT_ENABLE BIT(1)
64
54#define DM365_ISP5_INTSEL1 0x10 65#define DM365_ISP5_INTSEL1 0x10
55#define DM365_ISP5_INTSEL2 0x14 66#define DM365_ISP5_INTSEL2 0x14
56#define DM365_ISP5_INTSEL3 0x18 67#define DM365_ISP5_INTSEL3 0x18
57#define DM365_ISP5_CCDCMUX 0x20 68#define DM365_ISP5_CCDCMUX 0x20
58#define DM365_ISP5_PG_FRAME_SIZE 0x28 69#define DM365_ISP5_PG_FRAME_SIZE 0x28
59#define DM365_VPBE_CLK_CTRL 0x00 70#define DM365_VPBE_CLK_CTRL 0x00
71
72#define VPSS_CLK_CTRL 0x01c40044
73#define VPSS_CLK_CTRL_VENCCLKEN BIT(3)
74#define VPSS_CLK_CTRL_DACCLKEN BIT(4)
75
60/* 76/*
61 * vpss interrupts. VDINT0 - vpss_int0, VDINT1 - vpss_int1, 77 * vpss interrupts. VDINT0 - vpss_int0, VDINT1 - vpss_int1,
62 * AF - vpss_int3 78 * AF - vpss_int3
@@ -94,12 +110,19 @@ struct vpss_hw_ops {
94 void (*select_ccdc_source)(enum vpss_ccdc_source_sel src_sel); 110 void (*select_ccdc_source)(enum vpss_ccdc_source_sel src_sel);
95 /* clear wbl overflow bit */ 111 /* clear wbl overflow bit */
96 int (*clear_wbl_overflow)(enum vpss_wbl_sel wbl_sel); 112 int (*clear_wbl_overflow)(enum vpss_wbl_sel wbl_sel);
113 /* set sync polarity */
114 void (*set_sync_pol)(struct vpss_sync_pol);
115 /* set the PG_FRAME_SIZE register*/
116 void (*set_pg_frame_size)(struct vpss_pg_frame_size);
117 /* check and clear interrupt if occured */
118 int (*dma_complete_interrupt)(void);
97}; 119};
98 120
99/* vpss configuration */ 121/* vpss configuration */
100struct vpss_oper_config { 122struct vpss_oper_config {
101 __iomem void *vpss_regs_base0; 123 __iomem void *vpss_regs_base0;
102 __iomem void *vpss_regs_base1; 124 __iomem void *vpss_regs_base1;
125 resource_size_t *vpss_regs_base2;
103 enum vpss_platform_type platform; 126 enum vpss_platform_type platform;
104 spinlock_t vpss_lock; 127 spinlock_t vpss_lock;
105 struct vpss_hw_ops hw_ops; 128 struct vpss_hw_ops hw_ops;
@@ -157,6 +180,14 @@ static void dm355_select_ccdc_source(enum vpss_ccdc_source_sel src_sel)
157 bl_regw(src_sel << VPSS_HSSISEL_SHIFT, DM355_VPSSBL_CCDCMUX); 180 bl_regw(src_sel << VPSS_HSSISEL_SHIFT, DM355_VPSSBL_CCDCMUX);
158} 181}
159 182
183int vpss_dma_complete_interrupt(void)
184{
185 if (!oper_cfg.hw_ops.dma_complete_interrupt)
186 return 2;
187 return oper_cfg.hw_ops.dma_complete_interrupt();
188}
189EXPORT_SYMBOL(vpss_dma_complete_interrupt);
190
160int vpss_select_ccdc_source(enum vpss_ccdc_source_sel src_sel) 191int vpss_select_ccdc_source(enum vpss_ccdc_source_sel src_sel)
161{ 192{
162 if (!oper_cfg.hw_ops.select_ccdc_source) 193 if (!oper_cfg.hw_ops.select_ccdc_source)
@@ -182,6 +213,15 @@ static int dm644x_clear_wbl_overflow(enum vpss_wbl_sel wbl_sel)
182 return 0; 213 return 0;
183} 214}
184 215
216void vpss_set_sync_pol(struct vpss_sync_pol sync)
217{
218 if (!oper_cfg.hw_ops.set_sync_pol)
219 return;
220
221 oper_cfg.hw_ops.set_sync_pol(sync);
222}
223EXPORT_SYMBOL(vpss_set_sync_pol);
224
185int vpss_clear_wbl_overflow(enum vpss_wbl_sel wbl_sel) 225int vpss_clear_wbl_overflow(enum vpss_wbl_sel wbl_sel)
186{ 226{
187 if (!oper_cfg.hw_ops.clear_wbl_overflow) 227 if (!oper_cfg.hw_ops.clear_wbl_overflow)
@@ -347,6 +387,15 @@ void dm365_vpss_set_sync_pol(struct vpss_sync_pol sync)
347} 387}
348EXPORT_SYMBOL(dm365_vpss_set_sync_pol); 388EXPORT_SYMBOL(dm365_vpss_set_sync_pol);
349 389
390void vpss_set_pg_frame_size(struct vpss_pg_frame_size frame_size)
391{
392 if (!oper_cfg.hw_ops.set_pg_frame_size)
393 return;
394
395 oper_cfg.hw_ops.set_pg_frame_size(frame_size);
396}
397EXPORT_SYMBOL(vpss_set_pg_frame_size);
398
350void dm365_vpss_set_pg_frame_size(struct vpss_pg_frame_size frame_size) 399void dm365_vpss_set_pg_frame_size(struct vpss_pg_frame_size frame_size)
351{ 400{
352 int current_reg = ((frame_size.hlpfr >> 1) - 1) << 16; 401 int current_reg = ((frame_size.hlpfr >> 1) - 1) << 16;
@@ -425,6 +474,16 @@ static int vpss_probe(struct platform_device *pdev)
425 oper_cfg.hw_ops.enable_clock = dm365_enable_clock; 474 oper_cfg.hw_ops.enable_clock = dm365_enable_clock;
426 oper_cfg.hw_ops.select_ccdc_source = dm365_select_ccdc_source; 475 oper_cfg.hw_ops.select_ccdc_source = dm365_select_ccdc_source;
427 /* Setup vpss interrupts */ 476 /* Setup vpss interrupts */
477 isp5_write((isp5_read(DM365_ISP5_PCCR) |
478 DM365_ISP5_PCCR_BL_CLK_ENABLE |
479 DM365_ISP5_PCCR_ISIF_CLK_ENABLE |
480 DM365_ISP5_PCCR_H3A_CLK_ENABLE |
481 DM365_ISP5_PCCR_RSZ_CLK_ENABLE |
482 DM365_ISP5_PCCR_IPIPE_CLK_ENABLE |
483 DM365_ISP5_PCCR_IPIPEIF_CLK_ENABLE |
484 DM365_ISP5_PCCR_RSV), DM365_ISP5_PCCR);
485 isp5_write((isp5_read(DM365_ISP5_BCR) |
486 DM365_ISP5_BCR_ISIF_OUT_ENABLE), DM365_ISP5_BCR);
428 isp5_write(DM365_ISP5_INTSEL1_DEFAULT, DM365_ISP5_INTSEL1); 487 isp5_write(DM365_ISP5_INTSEL1_DEFAULT, DM365_ISP5_INTSEL1);
429 isp5_write(DM365_ISP5_INTSEL2_DEFAULT, DM365_ISP5_INTSEL2); 488 isp5_write(DM365_ISP5_INTSEL2_DEFAULT, DM365_ISP5_INTSEL2);
430 isp5_write(DM365_ISP5_INTSEL3_DEFAULT, DM365_ISP5_INTSEL3); 489 isp5_write(DM365_ISP5_INTSEL3_DEFAULT, DM365_ISP5_INTSEL3);
@@ -470,11 +529,20 @@ static struct platform_driver vpss_driver = {
470 529
471static void vpss_exit(void) 530static void vpss_exit(void)
472{ 531{
532 iounmap(oper_cfg.vpss_regs_base2);
533 release_mem_region(VPSS_CLK_CTRL, 4);
473 platform_driver_unregister(&vpss_driver); 534 platform_driver_unregister(&vpss_driver);
474} 535}
475 536
476static int __init vpss_init(void) 537static int __init vpss_init(void)
477{ 538{
539 if (!request_mem_region(VPSS_CLK_CTRL, 4, "vpss_clock_control"))
540 return -EBUSY;
541
542 oper_cfg.vpss_regs_base2 = ioremap(VPSS_CLK_CTRL, 4);
543 writel(VPSS_CLK_CTRL_VENCCLKEN |
544 VPSS_CLK_CTRL_DACCLKEN, oper_cfg.vpss_regs_base2);
545
478 return platform_driver_register(&vpss_driver); 546 return platform_driver_register(&vpss_driver);
479} 547}
480subsys_initcall(vpss_init); 548subsys_initcall(vpss_init);
diff --git a/drivers/media/platform/exynos-gsc/gsc-core.c b/drivers/media/platform/exynos-gsc/gsc-core.c
index c1a07133cc56..82d9f6ac12f3 100644
--- a/drivers/media/platform/exynos-gsc/gsc-core.c
+++ b/drivers/media/platform/exynos-gsc/gsc-core.c
@@ -185,6 +185,15 @@ static const struct gsc_fmt gsc_formats[] = {
185 .corder = GSC_CRCB, 185 .corder = GSC_CRCB,
186 .num_planes = 3, 186 .num_planes = 3,
187 .num_comp = 3, 187 .num_comp = 3,
188 }, {
189 .name = "YUV 4:2:0 n.c. 2p, Y/CbCr tiled",
190 .pixelformat = V4L2_PIX_FMT_NV12MT_16X16,
191 .depth = { 8, 4 },
192 .color = GSC_YUV420,
193 .yorder = GSC_LSB_Y,
194 .corder = GSC_CBCR,
195 .num_planes = 2,
196 .num_comp = 2,
188 } 197 }
189}; 198};
190 199
@@ -935,8 +944,8 @@ static struct gsc_variant gsc_v_100_variant = {
935 .pix_max = &gsc_v_100_max, 944 .pix_max = &gsc_v_100_max,
936 .pix_min = &gsc_v_100_min, 945 .pix_min = &gsc_v_100_min,
937 .pix_align = &gsc_v_100_align, 946 .pix_align = &gsc_v_100_align,
938 .in_buf_cnt = 8, 947 .in_buf_cnt = 32,
939 .out_buf_cnt = 16, 948 .out_buf_cnt = 32,
940 .sc_up_max = 8, 949 .sc_up_max = 8,
941 .sc_down_max = 16, 950 .sc_down_max = 16,
942 .poly_sc_down_max = 4, 951 .poly_sc_down_max = 4,
@@ -993,12 +1002,8 @@ static void *gsc_get_drv_data(struct platform_device *pdev)
993 1002
994static void gsc_clk_put(struct gsc_dev *gsc) 1003static void gsc_clk_put(struct gsc_dev *gsc)
995{ 1004{
996 if (IS_ERR_OR_NULL(gsc->clock)) 1005 if (!IS_ERR(gsc->clock))
997 return; 1006 clk_unprepare(gsc->clock);
998
999 clk_unprepare(gsc->clock);
1000 clk_put(gsc->clock);
1001 gsc->clock = NULL;
1002} 1007}
1003 1008
1004static int gsc_clk_get(struct gsc_dev *gsc) 1009static int gsc_clk_get(struct gsc_dev *gsc)
@@ -1007,27 +1012,22 @@ static int gsc_clk_get(struct gsc_dev *gsc)
1007 1012
1008 dev_dbg(&gsc->pdev->dev, "gsc_clk_get Called\n"); 1013 dev_dbg(&gsc->pdev->dev, "gsc_clk_get Called\n");
1009 1014
1010 gsc->clock = clk_get(&gsc->pdev->dev, GSC_CLOCK_GATE_NAME); 1015 gsc->clock = devm_clk_get(&gsc->pdev->dev, GSC_CLOCK_GATE_NAME);
1011 if (IS_ERR(gsc->clock)) 1016 if (IS_ERR(gsc->clock)) {
1012 goto err_print; 1017 dev_err(&gsc->pdev->dev, "failed to get clock~~~: %s\n",
1018 GSC_CLOCK_GATE_NAME);
1019 return PTR_ERR(gsc->clock);
1020 }
1013 1021
1014 ret = clk_prepare(gsc->clock); 1022 ret = clk_prepare(gsc->clock);
1015 if (ret < 0) { 1023 if (ret < 0) {
1016 clk_put(gsc->clock); 1024 dev_err(&gsc->pdev->dev, "clock prepare failed for clock: %s\n",
1017 gsc->clock = NULL; 1025 GSC_CLOCK_GATE_NAME);
1018 goto err; 1026 gsc->clock = ERR_PTR(-EINVAL);
1027 return ret;
1019 } 1028 }
1020 1029
1021 return 0; 1030 return 0;
1022
1023err:
1024 dev_err(&gsc->pdev->dev, "clock prepare failed for clock: %s\n",
1025 GSC_CLOCK_GATE_NAME);
1026 gsc_clk_put(gsc);
1027err_print:
1028 dev_err(&gsc->pdev->dev, "failed to get clock~~~: %s\n",
1029 GSC_CLOCK_GATE_NAME);
1030 return -ENXIO;
1031} 1031}
1032 1032
1033static int gsc_m2m_suspend(struct gsc_dev *gsc) 1033static int gsc_m2m_suspend(struct gsc_dev *gsc)
@@ -1096,6 +1096,7 @@ static int gsc_probe(struct platform_device *pdev)
1096 init_waitqueue_head(&gsc->irq_queue); 1096 init_waitqueue_head(&gsc->irq_queue);
1097 spin_lock_init(&gsc->slock); 1097 spin_lock_init(&gsc->slock);
1098 mutex_init(&gsc->lock); 1098 mutex_init(&gsc->lock);
1099 gsc->clock = ERR_PTR(-EINVAL);
1099 1100
1100 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1101 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1101 gsc->regs = devm_ioremap_resource(dev, res); 1102 gsc->regs = devm_ioremap_resource(dev, res);
@@ -1157,6 +1158,7 @@ static int gsc_remove(struct platform_device *pdev)
1157 1158
1158 vb2_dma_contig_cleanup_ctx(gsc->alloc_ctx); 1159 vb2_dma_contig_cleanup_ctx(gsc->alloc_ctx);
1159 pm_runtime_disable(&pdev->dev); 1160 pm_runtime_disable(&pdev->dev);
1161 gsc_clk_put(gsc);
1160 1162
1161 dev_dbg(&pdev->dev, "%s driver unloaded\n", pdev->name); 1163 dev_dbg(&pdev->dev, "%s driver unloaded\n", pdev->name);
1162 return 0; 1164 return 0;
diff --git a/drivers/media/platform/exynos-gsc/gsc-core.h b/drivers/media/platform/exynos-gsc/gsc-core.h
index 5f157efd24f0..cc19bba09bd1 100644
--- a/drivers/media/platform/exynos-gsc/gsc-core.h
+++ b/drivers/media/platform/exynos-gsc/gsc-core.h
@@ -427,6 +427,11 @@ static inline void gsc_ctx_state_lock_clear(u32 state, struct gsc_ctx *ctx)
427 spin_unlock_irqrestore(&ctx->gsc_dev->slock, flags); 427 spin_unlock_irqrestore(&ctx->gsc_dev->slock, flags);
428} 428}
429 429
430static inline int is_tiled(const struct gsc_fmt *fmt)
431{
432 return fmt->pixelformat == V4L2_PIX_FMT_NV12MT_16X16;
433}
434
430static inline void gsc_hw_enable_control(struct gsc_dev *dev, bool on) 435static inline void gsc_hw_enable_control(struct gsc_dev *dev, bool on)
431{ 436{
432 u32 cfg = readl(dev->regs + GSC_ENABLE); 437 u32 cfg = readl(dev->regs + GSC_ENABLE);
diff --git a/drivers/media/platform/exynos-gsc/gsc-m2m.c b/drivers/media/platform/exynos-gsc/gsc-m2m.c
index c267c57c76fd..386c0a7a3a52 100644
--- a/drivers/media/platform/exynos-gsc/gsc-m2m.c
+++ b/drivers/media/platform/exynos-gsc/gsc-m2m.c
@@ -99,22 +99,28 @@ static void gsc_m2m_job_abort(void *priv)
99 gsc_m2m_job_finish(ctx, VB2_BUF_STATE_ERROR); 99 gsc_m2m_job_finish(ctx, VB2_BUF_STATE_ERROR);
100} 100}
101 101
102static int gsc_fill_addr(struct gsc_ctx *ctx) 102static int gsc_get_bufs(struct gsc_ctx *ctx)
103{ 103{
104 struct gsc_frame *s_frame, *d_frame; 104 struct gsc_frame *s_frame, *d_frame;
105 struct vb2_buffer *vb = NULL; 105 struct vb2_buffer *src_vb, *dst_vb;
106 int ret; 106 int ret;
107 107
108 s_frame = &ctx->s_frame; 108 s_frame = &ctx->s_frame;
109 d_frame = &ctx->d_frame; 109 d_frame = &ctx->d_frame;
110 110
111 vb = v4l2_m2m_next_src_buf(ctx->m2m_ctx); 111 src_vb = v4l2_m2m_next_src_buf(ctx->m2m_ctx);
112 ret = gsc_prepare_addr(ctx, vb, s_frame, &s_frame->addr); 112 ret = gsc_prepare_addr(ctx, src_vb, s_frame, &s_frame->addr);
113 if (ret) 113 if (ret)
114 return ret; 114 return ret;
115 115
116 vb = v4l2_m2m_next_dst_buf(ctx->m2m_ctx); 116 dst_vb = v4l2_m2m_next_dst_buf(ctx->m2m_ctx);
117 return gsc_prepare_addr(ctx, vb, d_frame, &d_frame->addr); 117 ret = gsc_prepare_addr(ctx, dst_vb, d_frame, &d_frame->addr);
118 if (ret)
119 return ret;
120
121 dst_vb->v4l2_buf.timestamp = src_vb->v4l2_buf.timestamp;
122
123 return 0;
118} 124}
119 125
120static void gsc_m2m_device_run(void *priv) 126static void gsc_m2m_device_run(void *priv)
@@ -148,7 +154,7 @@ static void gsc_m2m_device_run(void *priv)
148 goto put_device; 154 goto put_device;
149 } 155 }
150 156
151 ret = gsc_fill_addr(ctx); 157 ret = gsc_get_bufs(ctx);
152 if (ret) { 158 if (ret) {
153 pr_err("Wrong address"); 159 pr_err("Wrong address");
154 goto put_device; 160 goto put_device;
@@ -367,6 +373,13 @@ static int gsc_m2m_reqbufs(struct file *file, void *fh,
367 return v4l2_m2m_reqbufs(file, ctx->m2m_ctx, reqbufs); 373 return v4l2_m2m_reqbufs(file, ctx->m2m_ctx, reqbufs);
368} 374}
369 375
376static int gsc_m2m_expbuf(struct file *file, void *fh,
377 struct v4l2_exportbuffer *eb)
378{
379 struct gsc_ctx *ctx = fh_to_ctx(fh);
380 return v4l2_m2m_expbuf(file, ctx->m2m_ctx, eb);
381}
382
370static int gsc_m2m_querybuf(struct file *file, void *fh, 383static int gsc_m2m_querybuf(struct file *file, void *fh,
371 struct v4l2_buffer *buf) 384 struct v4l2_buffer *buf)
372{ 385{
@@ -548,6 +561,7 @@ static const struct v4l2_ioctl_ops gsc_m2m_ioctl_ops = {
548 .vidioc_s_fmt_vid_cap_mplane = gsc_m2m_s_fmt_mplane, 561 .vidioc_s_fmt_vid_cap_mplane = gsc_m2m_s_fmt_mplane,
549 .vidioc_s_fmt_vid_out_mplane = gsc_m2m_s_fmt_mplane, 562 .vidioc_s_fmt_vid_out_mplane = gsc_m2m_s_fmt_mplane,
550 .vidioc_reqbufs = gsc_m2m_reqbufs, 563 .vidioc_reqbufs = gsc_m2m_reqbufs,
564 .vidioc_expbuf = gsc_m2m_expbuf,
551 .vidioc_querybuf = gsc_m2m_querybuf, 565 .vidioc_querybuf = gsc_m2m_querybuf,
552 .vidioc_qbuf = gsc_m2m_qbuf, 566 .vidioc_qbuf = gsc_m2m_qbuf,
553 .vidioc_dqbuf = gsc_m2m_dqbuf, 567 .vidioc_dqbuf = gsc_m2m_dqbuf,
@@ -565,7 +579,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq,
565 579
566 memset(src_vq, 0, sizeof(*src_vq)); 580 memset(src_vq, 0, sizeof(*src_vq));
567 src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; 581 src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
568 src_vq->io_modes = VB2_MMAP | VB2_USERPTR; 582 src_vq->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF;
569 src_vq->drv_priv = ctx; 583 src_vq->drv_priv = ctx;
570 src_vq->ops = &gsc_m2m_qops; 584 src_vq->ops = &gsc_m2m_qops;
571 src_vq->mem_ops = &vb2_dma_contig_memops; 585 src_vq->mem_ops = &vb2_dma_contig_memops;
@@ -577,7 +591,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq,
577 591
578 memset(dst_vq, 0, sizeof(*dst_vq)); 592 memset(dst_vq, 0, sizeof(*dst_vq));
579 dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; 593 dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
580 dst_vq->io_modes = VB2_MMAP | VB2_USERPTR; 594 dst_vq->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF;
581 dst_vq->drv_priv = ctx; 595 dst_vq->drv_priv = ctx;
582 dst_vq->ops = &gsc_m2m_qops; 596 dst_vq->ops = &gsc_m2m_qops;
583 dst_vq->mem_ops = &vb2_dma_contig_memops; 597 dst_vq->mem_ops = &vb2_dma_contig_memops;
@@ -597,7 +611,7 @@ static int gsc_m2m_open(struct file *file)
597 if (mutex_lock_interruptible(&gsc->lock)) 611 if (mutex_lock_interruptible(&gsc->lock))
598 return -ERESTARTSYS; 612 return -ERESTARTSYS;
599 613
600 ctx = kzalloc(sizeof (*ctx), GFP_KERNEL); 614 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
601 if (!ctx) { 615 if (!ctx) {
602 ret = -ENOMEM; 616 ret = -ENOMEM;
603 goto unlock; 617 goto unlock;
diff --git a/drivers/media/platform/exynos-gsc/gsc-regs.c b/drivers/media/platform/exynos-gsc/gsc-regs.c
index 0146b354dc22..6f5b5a486cf3 100644
--- a/drivers/media/platform/exynos-gsc/gsc-regs.c
+++ b/drivers/media/platform/exynos-gsc/gsc-regs.c
@@ -214,6 +214,9 @@ void gsc_hw_set_in_image_format(struct gsc_ctx *ctx)
214 break; 214 break;
215 } 215 }
216 216
217 if (is_tiled(frame->fmt))
218 cfg |= GSC_IN_TILE_C_16x8 | GSC_IN_TILE_MODE;
219
217 writel(cfg, dev->regs + GSC_IN_CON); 220 writel(cfg, dev->regs + GSC_IN_CON);
218} 221}
219 222
@@ -334,6 +337,9 @@ void gsc_hw_set_out_image_format(struct gsc_ctx *ctx)
334 break; 337 break;
335 } 338 }
336 339
340 if (is_tiled(frame->fmt))
341 cfg |= GSC_OUT_TILE_C_16x8 | GSC_OUT_TILE_MODE;
342
337end_set: 343end_set:
338 writel(cfg, dev->regs + GSC_OUT_CON); 344 writel(cfg, dev->regs + GSC_OUT_CON);
339} 345}
diff --git a/drivers/media/platform/fsl-viu.c b/drivers/media/platform/fsl-viu.c
index 9115a2c8d075..5f7db3f1f6f5 100644
--- a/drivers/media/platform/fsl-viu.c
+++ b/drivers/media/platform/fsl-viu.c
@@ -1181,7 +1181,7 @@ static void viu_capture_intr(struct viu_dev *dev, u32 status)
1181 1181
1182 if (waitqueue_active(&buf->vb.done)) { 1182 if (waitqueue_active(&buf->vb.done)) {
1183 list_del(&buf->vb.queue); 1183 list_del(&buf->vb.queue);
1184 do_gettimeofday(&buf->vb.ts); 1184 v4l2_get_timestamp(&buf->vb.ts);
1185 buf->vb.state = VIDEOBUF_DONE; 1185 buf->vb.state = VIDEOBUF_DONE;
1186 buf->vb.field_count++; 1186 buf->vb.field_count++;
1187 wake_up(&buf->vb.done); 1187 wake_up(&buf->vb.done);
diff --git a/drivers/media/platform/m2m-deinterlace.c b/drivers/media/platform/m2m-deinterlace.c
index 05c560f2ef06..6c4db9b98989 100644
--- a/drivers/media/platform/m2m-deinterlace.c
+++ b/drivers/media/platform/m2m-deinterlace.c
@@ -28,7 +28,7 @@ MODULE_AUTHOR("Javier Martin <javier.martin@vista-silicon.com");
28MODULE_LICENSE("GPL"); 28MODULE_LICENSE("GPL");
29MODULE_VERSION("0.0.1"); 29MODULE_VERSION("0.0.1");
30 30
31static bool debug = true; 31static bool debug;
32module_param(debug, bool, 0644); 32module_param(debug, bool, 0644);
33 33
34/* Flags that indicate a format can be used for capture/output */ 34/* Flags that indicate a format can be used for capture/output */
@@ -917,10 +917,8 @@ static int deinterlace_open(struct file *file)
917 ctx->xt = kzalloc(sizeof(struct dma_async_tx_descriptor) + 917 ctx->xt = kzalloc(sizeof(struct dma_async_tx_descriptor) +
918 sizeof(struct data_chunk), GFP_KERNEL); 918 sizeof(struct data_chunk), GFP_KERNEL);
919 if (!ctx->xt) { 919 if (!ctx->xt) {
920 int ret = PTR_ERR(ctx->xt);
921
922 kfree(ctx); 920 kfree(ctx);
923 return ret; 921 return -ENOMEM;
924 } 922 }
925 923
926 ctx->colorspace = V4L2_COLORSPACE_REC709; 924 ctx->colorspace = V4L2_COLORSPACE_REC709;
diff --git a/drivers/media/platform/marvell-ccic/mcam-core.c b/drivers/media/platform/marvell-ccic/mcam-core.c
index ce2b7b4788d6..92a33f081852 100644
--- a/drivers/media/platform/marvell-ccic/mcam-core.c
+++ b/drivers/media/platform/marvell-ccic/mcam-core.c
@@ -22,6 +22,7 @@
22#include <linux/videodev2.h> 22#include <linux/videodev2.h>
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-chip-ident.h> 26#include <media/v4l2-chip-ident.h>
26#include <media/ov7670.h> 27#include <media/ov7670.h>
27#include <media/videobuf2-vmalloc.h> 28#include <media/videobuf2-vmalloc.h>
@@ -30,13 +31,6 @@
30 31
31#include "mcam-core.h" 32#include "mcam-core.h"
32 33
33/*
34 * Basic frame stats - to be deleted shortly
35 */
36static int frames;
37static int singles;
38static int delivered;
39
40#ifdef MCAM_MODE_VMALLOC 34#ifdef MCAM_MODE_VMALLOC
41/* 35/*
42 * Internal DMA buffer management. Since the controller cannot do S/G I/O, 36 * Internal DMA buffer management. Since the controller cannot do S/G I/O,
@@ -367,10 +361,10 @@ static void mcam_frame_tasklet(unsigned long data)
367 if (!test_bit(bufno, &cam->flags)) 361 if (!test_bit(bufno, &cam->flags))
368 continue; 362 continue;
369 if (list_empty(&cam->buffers)) { 363 if (list_empty(&cam->buffers)) {
370 singles++; 364 cam->frame_state.singles++;
371 break; /* Leave it valid, hope for better later */ 365 break; /* Leave it valid, hope for better later */
372 } 366 }
373 delivered++; 367 cam->frame_state.delivered++;
374 clear_bit(bufno, &cam->flags); 368 clear_bit(bufno, &cam->flags);
375 buf = list_first_entry(&cam->buffers, struct mcam_vb_buffer, 369 buf = list_first_entry(&cam->buffers, struct mcam_vb_buffer,
376 queue); 370 queue);
@@ -452,7 +446,7 @@ static void mcam_set_contig_buffer(struct mcam_camera *cam, int frame)
452 mcam_reg_write(cam, frame == 0 ? REG_Y0BAR : REG_Y1BAR, 446 mcam_reg_write(cam, frame == 0 ? REG_Y0BAR : REG_Y1BAR,
453 vb2_dma_contig_plane_dma_addr(&buf->vb_buf, 0)); 447 vb2_dma_contig_plane_dma_addr(&buf->vb_buf, 0));
454 set_bit(CF_SINGLE_BUFFER, &cam->flags); 448 set_bit(CF_SINGLE_BUFFER, &cam->flags);
455 singles++; 449 cam->frame_state.singles++;
456 return; 450 return;
457 } 451 }
458 /* 452 /*
@@ -485,7 +479,7 @@ static void mcam_dma_contig_done(struct mcam_camera *cam, int frame)
485 struct mcam_vb_buffer *buf = cam->vb_bufs[frame]; 479 struct mcam_vb_buffer *buf = cam->vb_bufs[frame];
486 480
487 if (!test_bit(CF_SINGLE_BUFFER, &cam->flags)) { 481 if (!test_bit(CF_SINGLE_BUFFER, &cam->flags)) {
488 delivered++; 482 cam->frame_state.delivered++;
489 mcam_buffer_done(cam, frame, &buf->vb_buf); 483 mcam_buffer_done(cam, frame, &buf->vb_buf);
490 } 484 }
491 mcam_set_contig_buffer(cam, frame); 485 mcam_set_contig_buffer(cam, frame);
@@ -578,13 +572,13 @@ static void mcam_dma_sg_done(struct mcam_camera *cam, int frame)
578 */ 572 */
579 } else { 573 } else {
580 set_bit(CF_SG_RESTART, &cam->flags); 574 set_bit(CF_SG_RESTART, &cam->flags);
581 singles++; 575 cam->frame_state.singles++;
582 cam->vb_bufs[0] = NULL; 576 cam->vb_bufs[0] = NULL;
583 } 577 }
584 /* 578 /*
585 * Now we can give the completed frame back to user space. 579 * Now we can give the completed frame back to user space.
586 */ 580 */
587 delivered++; 581 cam->frame_state.delivered++;
588 mcam_buffer_done(cam, frame, &buf->vb_buf); 582 mcam_buffer_done(cam, frame, &buf->vb_buf);
589} 583}
590 584
@@ -1232,47 +1226,6 @@ static int mcam_vidioc_dqbuf(struct file *filp, void *priv,
1232 return ret; 1226 return ret;
1233} 1227}
1234 1228
1235
1236
1237static int mcam_vidioc_queryctrl(struct file *filp, void *priv,
1238 struct v4l2_queryctrl *qc)
1239{
1240 struct mcam_camera *cam = priv;
1241 int ret;
1242
1243 mutex_lock(&cam->s_mutex);
1244 ret = sensor_call(cam, core, queryctrl, qc);
1245 mutex_unlock(&cam->s_mutex);
1246 return ret;
1247}
1248
1249
1250static int mcam_vidioc_g_ctrl(struct file *filp, void *priv,
1251 struct v4l2_control *ctrl)
1252{
1253 struct mcam_camera *cam = priv;
1254 int ret;
1255
1256 mutex_lock(&cam->s_mutex);
1257 ret = sensor_call(cam, core, g_ctrl, ctrl);
1258 mutex_unlock(&cam->s_mutex);
1259 return ret;
1260}
1261
1262
1263static int mcam_vidioc_s_ctrl(struct file *filp, void *priv,
1264 struct v4l2_control *ctrl)
1265{
1266 struct mcam_camera *cam = priv;
1267 int ret;
1268
1269 mutex_lock(&cam->s_mutex);
1270 ret = sensor_call(cam, core, s_ctrl, ctrl);
1271 mutex_unlock(&cam->s_mutex);
1272 return ret;
1273}
1274
1275
1276static int mcam_vidioc_querycap(struct file *file, void *priv, 1229static int mcam_vidioc_querycap(struct file *file, void *priv,
1277 struct v4l2_capability *cap) 1230 struct v4l2_capability *cap)
1278{ 1231{
@@ -1520,9 +1473,6 @@ static const struct v4l2_ioctl_ops mcam_v4l_ioctl_ops = {
1520 .vidioc_dqbuf = mcam_vidioc_dqbuf, 1473 .vidioc_dqbuf = mcam_vidioc_dqbuf,
1521 .vidioc_streamon = mcam_vidioc_streamon, 1474 .vidioc_streamon = mcam_vidioc_streamon,
1522 .vidioc_streamoff = mcam_vidioc_streamoff, 1475 .vidioc_streamoff = mcam_vidioc_streamoff,
1523 .vidioc_queryctrl = mcam_vidioc_queryctrl,
1524 .vidioc_g_ctrl = mcam_vidioc_g_ctrl,
1525 .vidioc_s_ctrl = mcam_vidioc_s_ctrl,
1526 .vidioc_g_parm = mcam_vidioc_g_parm, 1476 .vidioc_g_parm = mcam_vidioc_g_parm,
1527 .vidioc_s_parm = mcam_vidioc_s_parm, 1477 .vidioc_s_parm = mcam_vidioc_s_parm,
1528 .vidioc_enum_framesizes = mcam_vidioc_enum_framesizes, 1478 .vidioc_enum_framesizes = mcam_vidioc_enum_framesizes,
@@ -1545,7 +1495,9 @@ static int mcam_v4l_open(struct file *filp)
1545 1495
1546 filp->private_data = cam; 1496 filp->private_data = cam;
1547 1497
1548 frames = singles = delivered = 0; 1498 cam->frame_state.frames = 0;
1499 cam->frame_state.singles = 0;
1500 cam->frame_state.delivered = 0;
1549 mutex_lock(&cam->s_mutex); 1501 mutex_lock(&cam->s_mutex);
1550 if (cam->users == 0) { 1502 if (cam->users == 0) {
1551 ret = mcam_setup_vb2(cam); 1503 ret = mcam_setup_vb2(cam);
@@ -1566,8 +1518,9 @@ static int mcam_v4l_release(struct file *filp)
1566{ 1518{
1567 struct mcam_camera *cam = filp->private_data; 1519 struct mcam_camera *cam = filp->private_data;
1568 1520
1569 cam_dbg(cam, "Release, %d frames, %d singles, %d delivered\n", frames, 1521 cam_dbg(cam, "Release, %d frames, %d singles, %d delivered\n",
1570 singles, delivered); 1522 cam->frame_state.frames, cam->frame_state.singles,
1523 cam->frame_state.delivered);
1571 mutex_lock(&cam->s_mutex); 1524 mutex_lock(&cam->s_mutex);
1572 (cam->users)--; 1525 (cam->users)--;
1573 if (cam->users == 0) { 1526 if (cam->users == 0) {
@@ -1660,7 +1613,7 @@ static void mcam_frame_complete(struct mcam_camera *cam, int frame)
1660 clear_bit(CF_DMA_ACTIVE, &cam->flags); 1613 clear_bit(CF_DMA_ACTIVE, &cam->flags);
1661 cam->next_buf = frame; 1614 cam->next_buf = frame;
1662 cam->buf_seq[frame] = ++(cam->sequence); 1615 cam->buf_seq[frame] = ++(cam->sequence);
1663 frames++; 1616 cam->frame_state.frames++;
1664 /* 1617 /*
1665 * "This should never happen" 1618 * "This should never happen"
1666 */ 1619 */
@@ -1786,14 +1739,19 @@ int mccic_register(struct mcam_camera *cam)
1786 /* 1739 /*
1787 * Get the v4l2 setup done. 1740 * Get the v4l2 setup done.
1788 */ 1741 */
1742 ret = v4l2_ctrl_handler_init(&cam->ctrl_handler, 10);
1743 if (ret)
1744 goto out_unregister;
1745 cam->v4l2_dev.ctrl_handler = &cam->ctrl_handler;
1746
1789 mutex_lock(&cam->s_mutex); 1747 mutex_lock(&cam->s_mutex);
1790 cam->vdev = mcam_v4l_template; 1748 cam->vdev = mcam_v4l_template;
1791 cam->vdev.debug = 0; 1749 cam->vdev.debug = 0;
1792 cam->vdev.v4l2_dev = &cam->v4l2_dev; 1750 cam->vdev.v4l2_dev = &cam->v4l2_dev;
1751 video_set_drvdata(&cam->vdev, cam);
1793 ret = video_register_device(&cam->vdev, VFL_TYPE_GRABBER, -1); 1752 ret = video_register_device(&cam->vdev, VFL_TYPE_GRABBER, -1);
1794 if (ret) 1753 if (ret)
1795 goto out; 1754 goto out;
1796 video_set_drvdata(&cam->vdev, cam);
1797 1755
1798 /* 1756 /*
1799 * If so requested, try to get our DMA buffers now. 1757 * If so requested, try to get our DMA buffers now.
@@ -1805,6 +1763,7 @@ int mccic_register(struct mcam_camera *cam)
1805 } 1763 }
1806 1764
1807out: 1765out:
1766 v4l2_ctrl_handler_free(&cam->ctrl_handler);
1808 mutex_unlock(&cam->s_mutex); 1767 mutex_unlock(&cam->s_mutex);
1809 return ret; 1768 return ret;
1810out_unregister: 1769out_unregister:
@@ -1829,6 +1788,7 @@ void mccic_shutdown(struct mcam_camera *cam)
1829 if (cam->buffer_mode == B_vmalloc) 1788 if (cam->buffer_mode == B_vmalloc)
1830 mcam_free_dma_bufs(cam); 1789 mcam_free_dma_bufs(cam);
1831 video_unregister_device(&cam->vdev); 1790 video_unregister_device(&cam->vdev);
1791 v4l2_ctrl_handler_free(&cam->ctrl_handler);
1832 v4l2_device_unregister(&cam->v4l2_dev); 1792 v4l2_device_unregister(&cam->v4l2_dev);
1833} 1793}
1834 1794
diff --git a/drivers/media/platform/marvell-ccic/mcam-core.h b/drivers/media/platform/marvell-ccic/mcam-core.h
index bd6acba9fb37..01dec9e5fc2b 100644
--- a/drivers/media/platform/marvell-ccic/mcam-core.h
+++ b/drivers/media/platform/marvell-ccic/mcam-core.h
@@ -8,6 +8,7 @@
8 8
9#include <linux/list.h> 9#include <linux/list.h>
10#include <media/v4l2-common.h> 10#include <media/v4l2-common.h>
11#include <media/v4l2-ctrls.h>
11#include <media/v4l2-dev.h> 12#include <media/v4l2-dev.h>
12#include <media/videobuf2-core.h> 13#include <media/videobuf2-core.h>
13 14
@@ -15,15 +16,15 @@
15 * Create our own symbols for the supported buffer modes, but, for now, 16 * Create our own symbols for the supported buffer modes, but, for now,
16 * base them entirely on which videobuf2 options have been selected. 17 * base them entirely on which videobuf2 options have been selected.
17 */ 18 */
18#if defined(CONFIG_VIDEOBUF2_VMALLOC) || defined(CONFIG_VIDEOBUF2_VMALLOC_MODULE) 19#if IS_ENABLED(CONFIG_VIDEOBUF2_VMALLOC)
19#define MCAM_MODE_VMALLOC 1 20#define MCAM_MODE_VMALLOC 1
20#endif 21#endif
21 22
22#if defined(CONFIG_VIDEOBUF2_DMA_CONTIG) || defined(CONFIG_VIDEOBUF2_DMA_CONTIG_MODULE) 23#if IS_ENABLED(CONFIG_VIDEOBUF2_DMA_CONTIG)
23#define MCAM_MODE_DMA_CONTIG 1 24#define MCAM_MODE_DMA_CONTIG 1
24#endif 25#endif
25 26
26#if defined(CONFIG_VIDEOBUF2_DMA_SG) || defined(CONFIG_VIDEOBUF2_DMA_SG_MODULE) 27#if IS_ENABLED(CONFIG_VIDEOBUF2_DMA_SG)
27#define MCAM_MODE_DMA_SG 1 28#define MCAM_MODE_DMA_SG 1
28#endif 29#endif
29 30
@@ -73,6 +74,14 @@ static inline int mcam_buffer_mode_supported(enum mcam_buffer_mode mode)
73 } 74 }
74} 75}
75 76
77/*
78 * Basic frame states
79 */
80struct mcam_frame_state {
81 unsigned int frames;
82 unsigned int singles;
83 unsigned int delivered;
84};
76 85
77/* 86/*
78 * A description of one of our devices. 87 * A description of one of our devices.
@@ -104,10 +113,12 @@ struct mcam_camera {
104 * should not be touched by the platform code. 113 * should not be touched by the platform code.
105 */ 114 */
106 struct v4l2_device v4l2_dev; 115 struct v4l2_device v4l2_dev;
116 struct v4l2_ctrl_handler ctrl_handler;
107 enum mcam_state state; 117 enum mcam_state state;
108 unsigned long flags; /* Buffer status, mainly (dev_lock) */ 118 unsigned long flags; /* Buffer status, mainly (dev_lock) */
109 int users; /* How many open FDs */ 119 int users; /* How many open FDs */
110 120
121 struct mcam_frame_state frame_state; /* Frame state counter */
111 /* 122 /*
112 * Subsystem structures. 123 * Subsystem structures.
113 */ 124 */
diff --git a/drivers/media/platform/omap/Kconfig b/drivers/media/platform/omap/Kconfig
index 390ab094f9f2..37ad446b35b3 100644
--- a/drivers/media/platform/omap/Kconfig
+++ b/drivers/media/platform/omap/Kconfig
@@ -6,7 +6,7 @@ config VIDEO_OMAP2_VOUT
6 depends on ARCH_OMAP2 || ARCH_OMAP3 6 depends on ARCH_OMAP2 || ARCH_OMAP3
7 select VIDEOBUF_GEN 7 select VIDEOBUF_GEN
8 select VIDEOBUF_DMA_CONTIG 8 select VIDEOBUF_DMA_CONTIG
9 select OMAP2_DSS 9 select OMAP2_DSS if HAS_IOMEM && ARCH_OMAP2PLUS
10 select OMAP2_VRFB if ARCH_OMAP2 || ARCH_OMAP3 10 select OMAP2_VRFB if ARCH_OMAP2 || ARCH_OMAP3
11 select VIDEO_OMAP2_VOUT_VRFB if VIDEO_OMAP2_VOUT && OMAP2_VRFB 11 select VIDEO_OMAP2_VOUT_VRFB if VIDEO_OMAP2_VOUT && OMAP2_VRFB
12 default n 12 default n
diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
index 35cc526e6c93..96c4a17e4280 100644
--- a/drivers/media/platform/omap/omap_vout.c
+++ b/drivers/media/platform/omap/omap_vout.c
@@ -205,19 +205,21 @@ static u32 omap_vout_uservirt_to_phys(u32 virtp)
205 struct vm_area_struct *vma; 205 struct vm_area_struct *vma;
206 struct mm_struct *mm = current->mm; 206 struct mm_struct *mm = current->mm;
207 207
208 vma = find_vma(mm, virtp);
209 /* For kernel direct-mapped memory, take the easy way */ 208 /* For kernel direct-mapped memory, take the easy way */
210 if (virtp >= PAGE_OFFSET) { 209 if (virtp >= PAGE_OFFSET)
211 physp = virt_to_phys((void *) virtp); 210 return virt_to_phys((void *) virtp);
212 } else if (vma && (vma->vm_flags & VM_IO) && vma->vm_pgoff) { 211
212 down_read(&current->mm->mmap_sem);
213 vma = find_vma(mm, virtp);
214 if (vma && (vma->vm_flags & VM_IO) && vma->vm_pgoff) {
213 /* this will catch, kernel-allocated, mmaped-to-usermode 215 /* this will catch, kernel-allocated, mmaped-to-usermode
214 addresses */ 216 addresses */
215 physp = (vma->vm_pgoff << PAGE_SHIFT) + (virtp - vma->vm_start); 217 physp = (vma->vm_pgoff << PAGE_SHIFT) + (virtp - vma->vm_start);
218 up_read(&current->mm->mmap_sem);
216 } else { 219 } else {
217 /* otherwise, use get_user_pages() for general userland pages */ 220 /* otherwise, use get_user_pages() for general userland pages */
218 int res, nr_pages = 1; 221 int res, nr_pages = 1;
219 struct page *pages; 222 struct page *pages;
220 down_read(&current->mm->mmap_sem);
221 223
222 res = get_user_pages(current, current->mm, virtp, nr_pages, 1, 224 res = get_user_pages(current, current->mm, virtp, nr_pages, 1,
223 0, &pages, NULL); 225 0, &pages, NULL);
@@ -595,7 +597,7 @@ static void omap_vout_isr(void *arg, unsigned int irqstatus)
595 return; 597 return;
596 598
597 spin_lock(&vout->vbq_lock); 599 spin_lock(&vout->vbq_lock);
598 do_gettimeofday(&timevalue); 600 v4l2_get_timestamp(&timevalue);
599 601
600 switch (cur_display->type) { 602 switch (cur_display->type) {
601 case OMAP_DISPLAY_TYPE_DSI: 603 case OMAP_DISPLAY_TYPE_DSI:
@@ -1230,21 +1232,6 @@ static int vidioc_s_fmt_vid_overlay(struct file *file, void *fh,
1230 return ret; 1232 return ret;
1231} 1233}
1232 1234
1233static int vidioc_enum_fmt_vid_overlay(struct file *file, void *fh,
1234 struct v4l2_fmtdesc *fmt)
1235{
1236 int index = fmt->index;
1237
1238 if (index >= NUM_OUTPUT_FORMATS)
1239 return -EINVAL;
1240
1241 fmt->flags = omap_formats[index].flags;
1242 strlcpy(fmt->description, omap_formats[index].description,
1243 sizeof(fmt->description));
1244 fmt->pixelformat = omap_formats[index].pixelformat;
1245 return 0;
1246}
1247
1248static int vidioc_g_fmt_vid_overlay(struct file *file, void *fh, 1235static int vidioc_g_fmt_vid_overlay(struct file *file, void *fh,
1249 struct v4l2_format *f) 1236 struct v4l2_format *f)
1250{ 1237{
@@ -1858,10 +1845,9 @@ static const struct v4l2_ioctl_ops vout_ioctl_ops = {
1858 .vidioc_s_fbuf = vidioc_s_fbuf, 1845 .vidioc_s_fbuf = vidioc_s_fbuf,
1859 .vidioc_g_fbuf = vidioc_g_fbuf, 1846 .vidioc_g_fbuf = vidioc_g_fbuf,
1860 .vidioc_s_ctrl = vidioc_s_ctrl, 1847 .vidioc_s_ctrl = vidioc_s_ctrl,
1861 .vidioc_try_fmt_vid_overlay = vidioc_try_fmt_vid_overlay, 1848 .vidioc_try_fmt_vid_out_overlay = vidioc_try_fmt_vid_overlay,
1862 .vidioc_s_fmt_vid_overlay = vidioc_s_fmt_vid_overlay, 1849 .vidioc_s_fmt_vid_out_overlay = vidioc_s_fmt_vid_overlay,
1863 .vidioc_enum_fmt_vid_overlay = vidioc_enum_fmt_vid_overlay, 1850 .vidioc_g_fmt_vid_out_overlay = vidioc_g_fmt_vid_overlay,
1864 .vidioc_g_fmt_vid_overlay = vidioc_g_fmt_vid_overlay,
1865 .vidioc_cropcap = vidioc_cropcap, 1851 .vidioc_cropcap = vidioc_cropcap,
1866 .vidioc_g_crop = vidioc_g_crop, 1852 .vidioc_g_crop = vidioc_g_crop,
1867 .vidioc_s_crop = vidioc_s_crop, 1853 .vidioc_s_crop = vidioc_s_crop,
diff --git a/drivers/media/platform/omap24xxcam.c b/drivers/media/platform/omap24xxcam.c
index 8b7ccea982e7..debb44ceb185 100644
--- a/drivers/media/platform/omap24xxcam.c
+++ b/drivers/media/platform/omap24xxcam.c
@@ -402,7 +402,7 @@ static void omap24xxcam_vbq_complete(struct omap24xxcam_sgdma *sgdma,
402 omap24xxcam_core_disable(cam); 402 omap24xxcam_core_disable(cam);
403 spin_unlock_irqrestore(&cam->core_enable_disable_lock, flags); 403 spin_unlock_irqrestore(&cam->core_enable_disable_lock, flags);
404 404
405 do_gettimeofday(&vb->ts); 405 v4l2_get_timestamp(&vb->ts);
406 vb->field_count = atomic_add_return(2, &fh->field_count); 406 vb->field_count = atomic_add_return(2, &fh->field_count);
407 if (csr & csr_error) { 407 if (csr & csr_error) {
408 vb->state = VIDEOBUF_ERROR; 408 vb->state = VIDEOBUF_ERROR;
diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
index e4aaee91201d..383a727b8aa0 100644
--- a/drivers/media/platform/omap3isp/isp.c
+++ b/drivers/media/platform/omap3isp/isp.c
@@ -1406,28 +1406,15 @@ static const char *isp_clocks[] = {
1406 "l3_ick", 1406 "l3_ick",
1407}; 1407};
1408 1408
1409static void isp_put_clocks(struct isp_device *isp)
1410{
1411 unsigned int i;
1412
1413 for (i = 0; i < ARRAY_SIZE(isp_clocks); ++i) {
1414 if (isp->clock[i]) {
1415 clk_put(isp->clock[i]);
1416 isp->clock[i] = NULL;
1417 }
1418 }
1419}
1420
1421static int isp_get_clocks(struct isp_device *isp) 1409static int isp_get_clocks(struct isp_device *isp)
1422{ 1410{
1423 struct clk *clk; 1411 struct clk *clk;
1424 unsigned int i; 1412 unsigned int i;
1425 1413
1426 for (i = 0; i < ARRAY_SIZE(isp_clocks); ++i) { 1414 for (i = 0; i < ARRAY_SIZE(isp_clocks); ++i) {
1427 clk = clk_get(isp->dev, isp_clocks[i]); 1415 clk = devm_clk_get(isp->dev, isp_clocks[i]);
1428 if (IS_ERR(clk)) { 1416 if (IS_ERR(clk)) {
1429 dev_err(isp->dev, "clk_get %s failed\n", isp_clocks[i]); 1417 dev_err(isp->dev, "clk_get %s failed\n", isp_clocks[i]);
1430 isp_put_clocks(isp);
1431 return PTR_ERR(clk); 1418 return PTR_ERR(clk);
1432 } 1419 }
1433 1420
@@ -1993,7 +1980,6 @@ error_csiphy:
1993static int isp_remove(struct platform_device *pdev) 1980static int isp_remove(struct platform_device *pdev)
1994{ 1981{
1995 struct isp_device *isp = platform_get_drvdata(pdev); 1982 struct isp_device *isp = platform_get_drvdata(pdev);
1996 int i;
1997 1983
1998 isp_unregister_entities(isp); 1984 isp_unregister_entities(isp);
1999 isp_cleanup_modules(isp); 1985 isp_cleanup_modules(isp);
@@ -2004,26 +1990,6 @@ static int isp_remove(struct platform_device *pdev)
2004 isp->domain = NULL; 1990 isp->domain = NULL;
2005 omap3isp_put(isp); 1991 omap3isp_put(isp);
2006 1992
2007 free_irq(isp->irq_num, isp);
2008 isp_put_clocks(isp);
2009
2010 for (i = 0; i < OMAP3_ISP_IOMEM_LAST; i++) {
2011 if (isp->mmio_base[i]) {
2012 iounmap(isp->mmio_base[i]);
2013 isp->mmio_base[i] = NULL;
2014 }
2015
2016 if (isp->mmio_base_phys[i]) {
2017 release_mem_region(isp->mmio_base_phys[i],
2018 isp->mmio_size[i]);
2019 isp->mmio_base_phys[i] = 0;
2020 }
2021 }
2022
2023 regulator_put(isp->isp_csiphy1.vdd);
2024 regulator_put(isp->isp_csiphy2.vdd);
2025 kfree(isp);
2026
2027 return 0; 1993 return 0;
2028} 1994}
2029 1995
@@ -2041,7 +2007,8 @@ static int isp_map_mem_resource(struct platform_device *pdev,
2041 return -ENODEV; 2007 return -ENODEV;
2042 } 2008 }
2043 2009
2044 if (!request_mem_region(mem->start, resource_size(mem), pdev->name)) { 2010 if (!devm_request_mem_region(isp->dev, mem->start, resource_size(mem),
2011 pdev->name)) {
2045 dev_err(isp->dev, 2012 dev_err(isp->dev,
2046 "cannot reserve camera register I/O region\n"); 2013 "cannot reserve camera register I/O region\n");
2047 return -ENODEV; 2014 return -ENODEV;
@@ -2050,8 +2017,9 @@ static int isp_map_mem_resource(struct platform_device *pdev,
2050 isp->mmio_size[res] = resource_size(mem); 2017 isp->mmio_size[res] = resource_size(mem);
2051 2018
2052 /* map the region */ 2019 /* map the region */
2053 isp->mmio_base[res] = ioremap_nocache(isp->mmio_base_phys[res], 2020 isp->mmio_base[res] = devm_ioremap_nocache(isp->dev,
2054 isp->mmio_size[res]); 2021 isp->mmio_base_phys[res],
2022 isp->mmio_size[res]);
2055 if (!isp->mmio_base[res]) { 2023 if (!isp->mmio_base[res]) {
2056 dev_err(isp->dev, "cannot map camera register I/O region\n"); 2024 dev_err(isp->dev, "cannot map camera register I/O region\n");
2057 return -ENODEV; 2025 return -ENODEV;
@@ -2081,7 +2049,7 @@ static int isp_probe(struct platform_device *pdev)
2081 if (pdata == NULL) 2049 if (pdata == NULL)
2082 return -EINVAL; 2050 return -EINVAL;
2083 2051
2084 isp = kzalloc(sizeof(*isp), GFP_KERNEL); 2052 isp = devm_kzalloc(&pdev->dev, sizeof(*isp), GFP_KERNEL);
2085 if (!isp) { 2053 if (!isp) {
2086 dev_err(&pdev->dev, "could not allocate memory\n"); 2054 dev_err(&pdev->dev, "could not allocate memory\n");
2087 return -ENOMEM; 2055 return -ENOMEM;
@@ -2104,8 +2072,8 @@ static int isp_probe(struct platform_device *pdev)
2104 platform_set_drvdata(pdev, isp); 2072 platform_set_drvdata(pdev, isp);
2105 2073
2106 /* Regulators */ 2074 /* Regulators */
2107 isp->isp_csiphy1.vdd = regulator_get(&pdev->dev, "VDD_CSIPHY1"); 2075 isp->isp_csiphy1.vdd = devm_regulator_get(&pdev->dev, "VDD_CSIPHY1");
2108 isp->isp_csiphy2.vdd = regulator_get(&pdev->dev, "VDD_CSIPHY2"); 2076 isp->isp_csiphy2.vdd = devm_regulator_get(&pdev->dev, "VDD_CSIPHY2");
2109 2077
2110 /* Clocks 2078 /* Clocks
2111 * 2079 *
@@ -2180,7 +2148,8 @@ static int isp_probe(struct platform_device *pdev)
2180 goto detach_dev; 2148 goto detach_dev;
2181 } 2149 }
2182 2150
2183 if (request_irq(isp->irq_num, isp_isr, IRQF_SHARED, "OMAP3 ISP", isp)) { 2151 if (devm_request_irq(isp->dev, isp->irq_num, isp_isr, IRQF_SHARED,
2152 "OMAP3 ISP", isp)) {
2184 dev_err(isp->dev, "Unable to request IRQ\n"); 2153 dev_err(isp->dev, "Unable to request IRQ\n");
2185 ret = -EINVAL; 2154 ret = -EINVAL;
2186 goto detach_dev; 2155 goto detach_dev;
@@ -2189,7 +2158,7 @@ static int isp_probe(struct platform_device *pdev)
2189 /* Entities */ 2158 /* Entities */
2190 ret = isp_initialize_modules(isp); 2159 ret = isp_initialize_modules(isp);
2191 if (ret < 0) 2160 if (ret < 0)
2192 goto error_irq; 2161 goto detach_dev;
2193 2162
2194 ret = isp_register_entities(isp); 2163 ret = isp_register_entities(isp);
2195 if (ret < 0) 2164 if (ret < 0)
@@ -2202,8 +2171,6 @@ static int isp_probe(struct platform_device *pdev)
2202 2171
2203error_modules: 2172error_modules:
2204 isp_cleanup_modules(isp); 2173 isp_cleanup_modules(isp);
2205error_irq:
2206 free_irq(isp->irq_num, isp);
2207detach_dev: 2174detach_dev:
2208 iommu_detach_device(isp->domain, &pdev->dev); 2175 iommu_detach_device(isp->domain, &pdev->dev);
2209free_domain: 2176free_domain:
@@ -2211,26 +2178,9 @@ free_domain:
2211error_isp: 2178error_isp:
2212 omap3isp_put(isp); 2179 omap3isp_put(isp);
2213error: 2180error:
2214 isp_put_clocks(isp);
2215
2216 for (i = 0; i < OMAP3_ISP_IOMEM_LAST; i++) {
2217 if (isp->mmio_base[i]) {
2218 iounmap(isp->mmio_base[i]);
2219 isp->mmio_base[i] = NULL;
2220 }
2221
2222 if (isp->mmio_base_phys[i]) {
2223 release_mem_region(isp->mmio_base_phys[i],
2224 isp->mmio_size[i]);
2225 isp->mmio_base_phys[i] = 0;
2226 }
2227 }
2228 regulator_put(isp->isp_csiphy2.vdd);
2229 regulator_put(isp->isp_csiphy1.vdd);
2230 platform_set_drvdata(pdev, NULL); 2181 platform_set_drvdata(pdev, NULL);
2231 2182
2232 mutex_destroy(&isp->isp_mutex); 2183 mutex_destroy(&isp->isp_mutex);
2233 kfree(isp);
2234 2184
2235 return ret; 2185 return ret;
2236} 2186}
diff --git a/drivers/media/platform/omap3isp/ispccp2.c b/drivers/media/platform/omap3isp/ispccp2.c
index 85f0de85f37c..c5d84c977e29 100644
--- a/drivers/media/platform/omap3isp/ispccp2.c
+++ b/drivers/media/platform/omap3isp/ispccp2.c
@@ -1136,7 +1136,7 @@ int omap3isp_ccp2_init(struct isp_device *isp)
1136 * TODO: Don't hardcode the usage of PHY1 (shared with CSI2c). 1136 * TODO: Don't hardcode the usage of PHY1 (shared with CSI2c).
1137 */ 1137 */
1138 if (isp->revision == ISP_REVISION_2_0) { 1138 if (isp->revision == ISP_REVISION_2_0) {
1139 ccp2->vdds_csib = regulator_get(isp->dev, "vdds_csib"); 1139 ccp2->vdds_csib = devm_regulator_get(isp->dev, "vdds_csib");
1140 if (IS_ERR(ccp2->vdds_csib)) { 1140 if (IS_ERR(ccp2->vdds_csib)) {
1141 dev_dbg(isp->dev, 1141 dev_dbg(isp->dev,
1142 "Could not get regulator vdds_csib\n"); 1142 "Could not get regulator vdds_csib\n");
@@ -1147,10 +1147,8 @@ int omap3isp_ccp2_init(struct isp_device *isp)
1147 } 1147 }
1148 1148
1149 ret = ccp2_init_entities(ccp2); 1149 ret = ccp2_init_entities(ccp2);
1150 if (ret < 0) { 1150 if (ret < 0)
1151 regulator_put(ccp2->vdds_csib);
1152 return ret; 1151 return ret;
1153 }
1154 1152
1155 ccp2_reset(ccp2); 1153 ccp2_reset(ccp2);
1156 return 0; 1154 return 0;
@@ -1166,6 +1164,4 @@ void omap3isp_ccp2_cleanup(struct isp_device *isp)
1166 1164
1167 omap3isp_video_cleanup(&ccp2->video_in); 1165 omap3isp_video_cleanup(&ccp2->video_in);
1168 media_entity_cleanup(&ccp2->subdev.entity); 1166 media_entity_cleanup(&ccp2->subdev.entity);
1169
1170 regulator_put(ccp2->vdds_csib);
1171} 1167}
diff --git a/drivers/media/platform/omap3isp/ispcsiphy.c b/drivers/media/platform/omap3isp/ispcsiphy.c
index 3d56b33f85e8..c09de32f986a 100644
--- a/drivers/media/platform/omap3isp/ispcsiphy.c
+++ b/drivers/media/platform/omap3isp/ispcsiphy.c
@@ -32,7 +32,8 @@
32#include "ispreg.h" 32#include "ispreg.h"
33#include "ispcsiphy.h" 33#include "ispcsiphy.h"
34 34
35static void csiphy_routing_cfg_3630(struct isp_csiphy *phy, u32 iface, 35static void csiphy_routing_cfg_3630(struct isp_csiphy *phy,
36 enum isp_interface_type iface,
36 bool ccp2_strobe) 37 bool ccp2_strobe)
37{ 38{
38 u32 reg = isp_reg_readl( 39 u32 reg = isp_reg_readl(
@@ -40,6 +41,8 @@ static void csiphy_routing_cfg_3630(struct isp_csiphy *phy, u32 iface,
40 u32 shift, mode; 41 u32 shift, mode;
41 42
42 switch (iface) { 43 switch (iface) {
44 default:
45 /* Should not happen in practice, but let's keep the compiler happy. */
43 case ISP_INTERFACE_CCP2B_PHY1: 46 case ISP_INTERFACE_CCP2B_PHY1:
44 reg &= ~OMAP3630_CONTROL_CAMERA_PHY_CTRL_CSI1_RX_SEL_PHY2; 47 reg &= ~OMAP3630_CONTROL_CAMERA_PHY_CTRL_CSI1_RX_SEL_PHY2;
45 shift = OMAP3630_CONTROL_CAMERA_PHY_CTRL_CAMMODE_PHY1_SHIFT; 48 shift = OMAP3630_CONTROL_CAMERA_PHY_CTRL_CAMMODE_PHY1_SHIFT;
@@ -59,9 +62,8 @@ static void csiphy_routing_cfg_3630(struct isp_csiphy *phy, u32 iface,
59 } 62 }
60 63
61 /* Select data/clock or data/strobe mode for CCP2 */ 64 /* Select data/clock or data/strobe mode for CCP2 */
62 switch (iface) { 65 if (iface == ISP_INTERFACE_CCP2B_PHY1 ||
63 case ISP_INTERFACE_CCP2B_PHY1: 66 iface == ISP_INTERFACE_CCP2B_PHY2) {
64 case ISP_INTERFACE_CCP2B_PHY2:
65 if (ccp2_strobe) 67 if (ccp2_strobe)
66 mode = OMAP3630_CONTROL_CAMERA_PHY_CTRL_CAMMODE_CCP2_DATA_STROBE; 68 mode = OMAP3630_CONTROL_CAMERA_PHY_CTRL_CAMMODE_CCP2_DATA_STROBE;
67 else 69 else
@@ -110,7 +112,8 @@ static void csiphy_routing_cfg_3430(struct isp_csiphy *phy, u32 iface, bool on,
110 * and 3630, so they will not hold their contents in off-mode. This isn't an 112 * and 3630, so they will not hold their contents in off-mode. This isn't an
111 * issue since the MPU power domain is forced on whilst the ISP is in use. 113 * issue since the MPU power domain is forced on whilst the ISP is in use.
112 */ 114 */
113static void csiphy_routing_cfg(struct isp_csiphy *phy, u32 iface, bool on, 115static void csiphy_routing_cfg(struct isp_csiphy *phy,
116 enum isp_interface_type iface, bool on,
114 bool ccp2_strobe) 117 bool ccp2_strobe)
115{ 118{
116 if (phy->isp->mmio_base[OMAP3_ISP_IOMEM_3630_CONTROL_CAMERA_PHY_CTRL] 119 if (phy->isp->mmio_base[OMAP3_ISP_IOMEM_3630_CONTROL_CAMERA_PHY_CTRL]
diff --git a/drivers/media/platform/omap3isp/isph3a_aewb.c b/drivers/media/platform/omap3isp/isph3a_aewb.c
index 036e9961d027..75fd82b152ba 100644
--- a/drivers/media/platform/omap3isp/isph3a_aewb.c
+++ b/drivers/media/platform/omap3isp/isph3a_aewb.c
@@ -300,13 +300,11 @@ int omap3isp_h3a_aewb_init(struct isp_device *isp)
300 struct ispstat *aewb = &isp->isp_aewb; 300 struct ispstat *aewb = &isp->isp_aewb;
301 struct omap3isp_h3a_aewb_config *aewb_cfg; 301 struct omap3isp_h3a_aewb_config *aewb_cfg;
302 struct omap3isp_h3a_aewb_config *aewb_recover_cfg; 302 struct omap3isp_h3a_aewb_config *aewb_recover_cfg;
303 int ret;
304 303
305 aewb_cfg = kzalloc(sizeof(*aewb_cfg), GFP_KERNEL); 304 aewb_cfg = devm_kzalloc(isp->dev, sizeof(*aewb_cfg), GFP_KERNEL);
306 if (!aewb_cfg) 305 if (!aewb_cfg)
307 return -ENOMEM; 306 return -ENOMEM;
308 307
309 memset(aewb, 0, sizeof(*aewb));
310 aewb->ops = &h3a_aewb_ops; 308 aewb->ops = &h3a_aewb_ops;
311 aewb->priv = aewb_cfg; 309 aewb->priv = aewb_cfg;
312 aewb->dma_ch = -1; 310 aewb->dma_ch = -1;
@@ -314,12 +312,12 @@ int omap3isp_h3a_aewb_init(struct isp_device *isp)
314 aewb->isp = isp; 312 aewb->isp = isp;
315 313
316 /* Set recover state configuration */ 314 /* Set recover state configuration */
317 aewb_recover_cfg = kzalloc(sizeof(*aewb_recover_cfg), GFP_KERNEL); 315 aewb_recover_cfg = devm_kzalloc(isp->dev, sizeof(*aewb_recover_cfg),
316 GFP_KERNEL);
318 if (!aewb_recover_cfg) { 317 if (!aewb_recover_cfg) {
319 dev_err(aewb->isp->dev, "AEWB: cannot allocate memory for " 318 dev_err(aewb->isp->dev, "AEWB: cannot allocate memory for "
320 "recover configuration.\n"); 319 "recover configuration.\n");
321 ret = -ENOMEM; 320 return -ENOMEM;
322 goto err_recover_alloc;
323 } 321 }
324 322
325 aewb_recover_cfg->saturation_limit = OMAP3ISP_AEWB_MAX_SATURATION_LIM; 323 aewb_recover_cfg->saturation_limit = OMAP3ISP_AEWB_MAX_SATURATION_LIM;
@@ -336,25 +334,13 @@ int omap3isp_h3a_aewb_init(struct isp_device *isp)
336 if (h3a_aewb_validate_params(aewb, aewb_recover_cfg)) { 334 if (h3a_aewb_validate_params(aewb, aewb_recover_cfg)) {
337 dev_err(aewb->isp->dev, "AEWB: recover configuration is " 335 dev_err(aewb->isp->dev, "AEWB: recover configuration is "
338 "invalid.\n"); 336 "invalid.\n");
339 ret = -EINVAL; 337 return -EINVAL;
340 goto err_conf;
341 } 338 }
342 339
343 aewb_recover_cfg->buf_size = h3a_aewb_get_buf_size(aewb_recover_cfg); 340 aewb_recover_cfg->buf_size = h3a_aewb_get_buf_size(aewb_recover_cfg);
344 aewb->recover_priv = aewb_recover_cfg; 341 aewb->recover_priv = aewb_recover_cfg;
345 342
346 ret = omap3isp_stat_init(aewb, "AEWB", &h3a_aewb_subdev_ops); 343 return omap3isp_stat_init(aewb, "AEWB", &h3a_aewb_subdev_ops);
347 if (ret)
348 goto err_conf;
349
350 return 0;
351
352err_conf:
353 kfree(aewb_recover_cfg);
354err_recover_alloc:
355 kfree(aewb_cfg);
356
357 return ret;
358} 344}
359 345
360/* 346/*
@@ -362,7 +348,5 @@ err_recover_alloc:
362 */ 348 */
363void omap3isp_h3a_aewb_cleanup(struct isp_device *isp) 349void omap3isp_h3a_aewb_cleanup(struct isp_device *isp)
364{ 350{
365 kfree(isp->isp_aewb.priv);
366 kfree(isp->isp_aewb.recover_priv);
367 omap3isp_stat_cleanup(&isp->isp_aewb); 351 omap3isp_stat_cleanup(&isp->isp_aewb);
368} 352}
diff --git a/drivers/media/platform/omap3isp/isph3a_af.c b/drivers/media/platform/omap3isp/isph3a_af.c
index 42ccce318d5d..a0bf5af32438 100644
--- a/drivers/media/platform/omap3isp/isph3a_af.c
+++ b/drivers/media/platform/omap3isp/isph3a_af.c
@@ -363,13 +363,11 @@ int omap3isp_h3a_af_init(struct isp_device *isp)
363 struct ispstat *af = &isp->isp_af; 363 struct ispstat *af = &isp->isp_af;
364 struct omap3isp_h3a_af_config *af_cfg; 364 struct omap3isp_h3a_af_config *af_cfg;
365 struct omap3isp_h3a_af_config *af_recover_cfg; 365 struct omap3isp_h3a_af_config *af_recover_cfg;
366 int ret;
367 366
368 af_cfg = kzalloc(sizeof(*af_cfg), GFP_KERNEL); 367 af_cfg = devm_kzalloc(isp->dev, sizeof(*af_cfg), GFP_KERNEL);
369 if (af_cfg == NULL) 368 if (af_cfg == NULL)
370 return -ENOMEM; 369 return -ENOMEM;
371 370
372 memset(af, 0, sizeof(*af));
373 af->ops = &h3a_af_ops; 371 af->ops = &h3a_af_ops;
374 af->priv = af_cfg; 372 af->priv = af_cfg;
375 af->dma_ch = -1; 373 af->dma_ch = -1;
@@ -377,12 +375,12 @@ int omap3isp_h3a_af_init(struct isp_device *isp)
377 af->isp = isp; 375 af->isp = isp;
378 376
379 /* Set recover state configuration */ 377 /* Set recover state configuration */
380 af_recover_cfg = kzalloc(sizeof(*af_recover_cfg), GFP_KERNEL); 378 af_recover_cfg = devm_kzalloc(isp->dev, sizeof(*af_recover_cfg),
379 GFP_KERNEL);
381 if (!af_recover_cfg) { 380 if (!af_recover_cfg) {
382 dev_err(af->isp->dev, "AF: cannot allocate memory for recover " 381 dev_err(af->isp->dev, "AF: cannot allocate memory for recover "
383 "configuration.\n"); 382 "configuration.\n");
384 ret = -ENOMEM; 383 return -ENOMEM;
385 goto err_recover_alloc;
386 } 384 }
387 385
388 af_recover_cfg->paxel.h_start = OMAP3ISP_AF_PAXEL_HZSTART_MIN; 386 af_recover_cfg->paxel.h_start = OMAP3ISP_AF_PAXEL_HZSTART_MIN;
@@ -394,30 +392,16 @@ int omap3isp_h3a_af_init(struct isp_device *isp)
394 if (h3a_af_validate_params(af, af_recover_cfg)) { 392 if (h3a_af_validate_params(af, af_recover_cfg)) {
395 dev_err(af->isp->dev, "AF: recover configuration is " 393 dev_err(af->isp->dev, "AF: recover configuration is "
396 "invalid.\n"); 394 "invalid.\n");
397 ret = -EINVAL; 395 return -EINVAL;
398 goto err_conf;
399 } 396 }
400 397
401 af_recover_cfg->buf_size = h3a_af_get_buf_size(af_recover_cfg); 398 af_recover_cfg->buf_size = h3a_af_get_buf_size(af_recover_cfg);
402 af->recover_priv = af_recover_cfg; 399 af->recover_priv = af_recover_cfg;
403 400
404 ret = omap3isp_stat_init(af, "AF", &h3a_af_subdev_ops); 401 return omap3isp_stat_init(af, "AF", &h3a_af_subdev_ops);
405 if (ret)
406 goto err_conf;
407
408 return 0;
409
410err_conf:
411 kfree(af_recover_cfg);
412err_recover_alloc:
413 kfree(af_cfg);
414
415 return ret;
416} 402}
417 403
418void omap3isp_h3a_af_cleanup(struct isp_device *isp) 404void omap3isp_h3a_af_cleanup(struct isp_device *isp)
419{ 405{
420 kfree(isp->isp_af.priv);
421 kfree(isp->isp_af.recover_priv);
422 omap3isp_stat_cleanup(&isp->isp_af); 406 omap3isp_stat_cleanup(&isp->isp_af);
423} 407}
diff --git a/drivers/media/platform/omap3isp/isphist.c b/drivers/media/platform/omap3isp/isphist.c
index 2d759c56f37c..e070c24048ef 100644
--- a/drivers/media/platform/omap3isp/isphist.c
+++ b/drivers/media/platform/omap3isp/isphist.c
@@ -114,14 +114,14 @@ static void hist_setup_regs(struct ispstat *hist, void *priv)
114 /* Regions size and position */ 114 /* Regions size and position */
115 for (c = 0; c < OMAP3ISP_HIST_MAX_REGIONS; c++) { 115 for (c = 0; c < OMAP3ISP_HIST_MAX_REGIONS; c++) {
116 if (c < conf->num_regions) { 116 if (c < conf->num_regions) {
117 reg_hor[c] = conf->region[c].h_start << 117 reg_hor[c] = (conf->region[c].h_start <<
118 ISPHIST_REG_START_SHIFT; 118 ISPHIST_REG_START_SHIFT)
119 reg_hor[c] = conf->region[c].h_end << 119 | (conf->region[c].h_end <<
120 ISPHIST_REG_END_SHIFT; 120 ISPHIST_REG_END_SHIFT);
121 reg_ver[c] = conf->region[c].v_start << 121 reg_ver[c] = (conf->region[c].v_start <<
122 ISPHIST_REG_START_SHIFT; 122 ISPHIST_REG_START_SHIFT)
123 reg_ver[c] = conf->region[c].v_end << 123 | (conf->region[c].v_end <<
124 ISPHIST_REG_END_SHIFT; 124 ISPHIST_REG_END_SHIFT);
125 } else { 125 } else {
126 reg_hor[c] = 0; 126 reg_hor[c] = 0;
127 reg_ver[c] = 0; 127 reg_ver[c] = 0;
@@ -477,11 +477,10 @@ int omap3isp_hist_init(struct isp_device *isp)
477 struct omap3isp_hist_config *hist_cfg; 477 struct omap3isp_hist_config *hist_cfg;
478 int ret = -1; 478 int ret = -1;
479 479
480 hist_cfg = kzalloc(sizeof(*hist_cfg), GFP_KERNEL); 480 hist_cfg = devm_kzalloc(isp->dev, sizeof(*hist_cfg), GFP_KERNEL);
481 if (hist_cfg == NULL) 481 if (hist_cfg == NULL)
482 return -ENOMEM; 482 return -ENOMEM;
483 483
484 memset(hist, 0, sizeof(*hist));
485 hist->isp = isp; 484 hist->isp = isp;
486 485
487 if (HIST_CONFIG_DMA) 486 if (HIST_CONFIG_DMA)
@@ -504,7 +503,6 @@ int omap3isp_hist_init(struct isp_device *isp)
504 503
505 ret = omap3isp_stat_init(hist, "histogram", &hist_subdev_ops); 504 ret = omap3isp_stat_init(hist, "histogram", &hist_subdev_ops);
506 if (ret) { 505 if (ret) {
507 kfree(hist_cfg);
508 if (HIST_USING_DMA(hist)) 506 if (HIST_USING_DMA(hist))
509 omap_free_dma(hist->dma_ch); 507 omap_free_dma(hist->dma_ch);
510 } 508 }
@@ -519,6 +517,5 @@ void omap3isp_hist_cleanup(struct isp_device *isp)
519{ 517{
520 if (HIST_USING_DMA(&isp->isp_hist)) 518 if (HIST_USING_DMA(&isp->isp_hist))
521 omap_free_dma(isp->isp_hist.dma_ch); 519 omap_free_dma(isp->isp_hist.dma_ch);
522 kfree(isp->isp_hist.priv);
523 omap3isp_stat_cleanup(&isp->isp_hist); 520 omap3isp_stat_cleanup(&isp->isp_hist);
524} 521}
diff --git a/drivers/media/platform/omap3isp/isppreview.c b/drivers/media/platform/omap3isp/isppreview.c
index 691b92a3c3e7..cd8831aebdeb 100644
--- a/drivers/media/platform/omap3isp/isppreview.c
+++ b/drivers/media/platform/omap3isp/isppreview.c
@@ -82,8 +82,9 @@ static struct omap3isp_prev_csc flr_prev_csc = {
82 * The preview engine crops several rows and columns internally depending on 82 * The preview engine crops several rows and columns internally depending on
83 * which filters are enabled. To avoid format changes when the filters are 83 * which filters are enabled. To avoid format changes when the filters are
84 * enabled or disabled (which would prevent them from being turned on or off 84 * enabled or disabled (which would prevent them from being turned on or off
85 * during streaming), the driver assumes all the filters are enabled when 85 * during streaming), the driver assumes all filters that can be configured
86 * computing sink crop and source format limits. 86 * during streaming are enabled when computing sink crop and source format
87 * limits.
87 * 88 *
88 * If a filter is disabled, additional cropping is automatically added at the 89 * If a filter is disabled, additional cropping is automatically added at the
89 * preview engine input by the driver to avoid overflow at line and frame end. 90 * preview engine input by the driver to avoid overflow at line and frame end.
@@ -92,25 +93,23 @@ static struct omap3isp_prev_csc flr_prev_csc = {
92 * Median filter 4 pixels 93 * Median filter 4 pixels
93 * Noise filter, 94 * Noise filter,
94 * Faulty pixels correction 4 pixels, 4 lines 95 * Faulty pixels correction 4 pixels, 4 lines
95 * CFA filter 4 pixels, 4 lines in Bayer mode
96 * 2 lines in other modes
97 * Color suppression 2 pixels 96 * Color suppression 2 pixels
98 * or luma enhancement 97 * or luma enhancement
99 * ------------------------------------------------------------- 98 * -------------------------------------------------------------
100 * Maximum total 14 pixels, 8 lines 99 * Maximum total 10 pixels, 4 lines
101 * 100 *
102 * The color suppression and luma enhancement filters are applied after bayer to 101 * The color suppression and luma enhancement filters are applied after bayer to
103 * YUV conversion. They thus can crop one pixel on the left and one pixel on the 102 * YUV conversion. They thus can crop one pixel on the left and one pixel on the
104 * right side of the image without changing the color pattern. When both those 103 * right side of the image without changing the color pattern. When both those
105 * filters are disabled, the driver must crop the two pixels on the same side of 104 * filters are disabled, the driver must crop the two pixels on the same side of
106 * the image to avoid changing the bayer pattern. The left margin is thus set to 105 * the image to avoid changing the bayer pattern. The left margin is thus set to
107 * 8 pixels and the right margin to 6 pixels. 106 * 6 pixels and the right margin to 4 pixels.
108 */ 107 */
109 108
110#define PREV_MARGIN_LEFT 8 109#define PREV_MARGIN_LEFT 6
111#define PREV_MARGIN_RIGHT 6 110#define PREV_MARGIN_RIGHT 4
112#define PREV_MARGIN_TOP 4 111#define PREV_MARGIN_TOP 2
113#define PREV_MARGIN_BOTTOM 4 112#define PREV_MARGIN_BOTTOM 2
114 113
115#define PREV_MIN_IN_WIDTH 64 114#define PREV_MIN_IN_WIDTH 64
116#define PREV_MIN_IN_HEIGHT 8 115#define PREV_MIN_IN_HEIGHT 8
@@ -1080,7 +1079,6 @@ static void preview_config_input_format(struct isp_prev_device *prev,
1080 */ 1079 */
1081static void preview_config_input_size(struct isp_prev_device *prev, u32 active) 1080static void preview_config_input_size(struct isp_prev_device *prev, u32 active)
1082{ 1081{
1083 const struct v4l2_mbus_framefmt *format = &prev->formats[PREV_PAD_SINK];
1084 struct isp_device *isp = to_isp_device(prev); 1082 struct isp_device *isp = to_isp_device(prev);
1085 unsigned int sph = prev->crop.left; 1083 unsigned int sph = prev->crop.left;
1086 unsigned int eph = prev->crop.left + prev->crop.width - 1; 1084 unsigned int eph = prev->crop.left + prev->crop.width - 1;
@@ -1088,14 +1086,6 @@ static void preview_config_input_size(struct isp_prev_device *prev, u32 active)
1088 unsigned int elv = prev->crop.top + prev->crop.height - 1; 1086 unsigned int elv = prev->crop.top + prev->crop.height - 1;
1089 u32 features; 1087 u32 features;
1090 1088
1091 if (format->code != V4L2_MBUS_FMT_Y8_1X8 &&
1092 format->code != V4L2_MBUS_FMT_Y10_1X10) {
1093 sph -= 2;
1094 eph += 2;
1095 slv -= 2;
1096 elv += 2;
1097 }
1098
1099 features = (prev->params.params[0].features & active) 1089 features = (prev->params.params[0].features & active)
1100 | (prev->params.params[1].features & ~active); 1090 | (prev->params.params[1].features & ~active);
1101 1091
@@ -1849,6 +1839,18 @@ static void preview_try_crop(struct isp_prev_device *prev,
1849 right -= 2; 1839 right -= 2;
1850 } 1840 }
1851 1841
1842 /* The CFA filter crops 4 lines and 4 columns in Bayer mode, and 2 lines
1843 * and no columns in other modes. Increase the margins based on the sink
1844 * format.
1845 */
1846 if (sink->code != V4L2_MBUS_FMT_Y8_1X8 &&
1847 sink->code != V4L2_MBUS_FMT_Y10_1X10) {
1848 left += 2;
1849 right -= 2;
1850 top += 2;
1851 bottom -= 2;
1852 }
1853
1852 /* Restrict left/top to even values to keep the Bayer pattern. */ 1854 /* Restrict left/top to even values to keep the Bayer pattern. */
1853 crop->left &= ~1; 1855 crop->left &= ~1;
1854 crop->top &= ~1; 1856 crop->top &= ~1;
diff --git a/drivers/media/platform/omap3isp/ispqueue.c b/drivers/media/platform/omap3isp/ispqueue.c
index 15bf3eab2224..e15f01342058 100644
--- a/drivers/media/platform/omap3isp/ispqueue.c
+++ b/drivers/media/platform/omap3isp/ispqueue.c
@@ -366,7 +366,7 @@ static int isp_video_buffer_prepare_pfnmap(struct isp_video_buffer *buf)
366 unsigned long this_pfn; 366 unsigned long this_pfn;
367 unsigned long start; 367 unsigned long start;
368 unsigned long end; 368 unsigned long end;
369 dma_addr_t pa; 369 dma_addr_t pa = 0;
370 int ret = -EFAULT; 370 int ret = -EFAULT;
371 371
372 start = buf->vbuf.m.userptr; 372 start = buf->vbuf.m.userptr;
@@ -419,7 +419,7 @@ done:
419static int isp_video_buffer_prepare_vm_flags(struct isp_video_buffer *buf) 419static int isp_video_buffer_prepare_vm_flags(struct isp_video_buffer *buf)
420{ 420{
421 struct vm_area_struct *vma; 421 struct vm_area_struct *vma;
422 pgprot_t vm_page_prot; 422 pgprot_t uninitialized_var(vm_page_prot);
423 unsigned long start; 423 unsigned long start;
424 unsigned long end; 424 unsigned long end;
425 int ret = -EFAULT; 425 int ret = -EFAULT;
@@ -674,6 +674,7 @@ static int isp_video_queue_alloc(struct isp_video_queue *queue,
674 buf->vbuf.index = i; 674 buf->vbuf.index = i;
675 buf->vbuf.length = size; 675 buf->vbuf.length = size;
676 buf->vbuf.type = queue->type; 676 buf->vbuf.type = queue->type;
677 buf->vbuf.flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
677 buf->vbuf.field = V4L2_FIELD_NONE; 678 buf->vbuf.field = V4L2_FIELD_NONE;
678 buf->vbuf.memory = memory; 679 buf->vbuf.memory = memory;
679 680
diff --git a/drivers/media/platform/s3c-camif/camif-core.c b/drivers/media/platform/s3c-camif/camif-core.c
index 09a8c9cac5c9..0d0fab1a7b5e 100644
--- a/drivers/media/platform/s3c-camif/camif-core.c
+++ b/drivers/media/platform/s3c-camif/camif-core.c
@@ -27,6 +27,7 @@
27#include <linux/pm_runtime.h> 27#include <linux/pm_runtime.h>
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/types.h> 29#include <linux/types.h>
30#include <linux/version.h>
30 31
31#include <media/media-device.h> 32#include <media/media-device.h>
32#include <media/v4l2-ctrls.h> 33#include <media/v4l2-ctrls.h>
diff --git a/drivers/media/platform/s5p-fimc/fimc-capture.c b/drivers/media/platform/s5p-fimc/fimc-capture.c
index fdb6740248a7..f553cc2a8ee8 100644
--- a/drivers/media/platform/s5p-fimc/fimc-capture.c
+++ b/drivers/media/platform/s5p-fimc/fimc-capture.c
@@ -486,6 +486,7 @@ static struct vb2_ops fimc_capture_qops = {
486int fimc_capture_ctrls_create(struct fimc_dev *fimc) 486int fimc_capture_ctrls_create(struct fimc_dev *fimc)
487{ 487{
488 struct fimc_vid_cap *vid_cap = &fimc->vid_cap; 488 struct fimc_vid_cap *vid_cap = &fimc->vid_cap;
489 struct v4l2_subdev *sensor = fimc->pipeline.subdevs[IDX_SENSOR];
489 int ret; 490 int ret;
490 491
491 if (WARN_ON(vid_cap->ctx == NULL)) 492 if (WARN_ON(vid_cap->ctx == NULL))
@@ -494,11 +495,13 @@ int fimc_capture_ctrls_create(struct fimc_dev *fimc)
494 return 0; 495 return 0;
495 496
496 ret = fimc_ctrls_create(vid_cap->ctx); 497 ret = fimc_ctrls_create(vid_cap->ctx);
497 if (ret || vid_cap->user_subdev_api || !vid_cap->ctx->ctrls.ready) 498
499 if (ret || vid_cap->user_subdev_api || !sensor ||
500 !vid_cap->ctx->ctrls.ready)
498 return ret; 501 return ret;
499 502
500 return v4l2_ctrl_add_handler(&vid_cap->ctx->ctrls.handler, 503 return v4l2_ctrl_add_handler(&vid_cap->ctx->ctrls.handler,
501 fimc->pipeline.subdevs[IDX_SENSOR]->ctrl_handler, NULL); 504 sensor->ctrl_handler, NULL);
502} 505}
503 506
504static int fimc_capture_set_default_format(struct fimc_dev *fimc); 507static int fimc_capture_set_default_format(struct fimc_dev *fimc);
@@ -510,8 +513,8 @@ static int fimc_capture_open(struct file *file)
510 513
511 dbg("pid: %d, state: 0x%lx", task_pid_nr(current), fimc->state); 514 dbg("pid: %d, state: 0x%lx", task_pid_nr(current), fimc->state);
512 515
513 if (mutex_lock_interruptible(&fimc->lock)) 516 fimc_md_graph_lock(fimc);
514 return -ERESTARTSYS; 517 mutex_lock(&fimc->lock);
515 518
516 if (fimc_m2m_active(fimc)) 519 if (fimc_m2m_active(fimc))
517 goto unlock; 520 goto unlock;
@@ -546,6 +549,7 @@ static int fimc_capture_open(struct file *file)
546 } 549 }
547unlock: 550unlock:
548 mutex_unlock(&fimc->lock); 551 mutex_unlock(&fimc->lock);
552 fimc_md_graph_unlock(fimc);
549 return ret; 553 return ret;
550} 554}
551 555
@@ -626,8 +630,8 @@ static struct fimc_fmt *fimc_capture_try_format(struct fimc_ctx *ctx,
626{ 630{
627 bool rotation = ctx->rotation == 90 || ctx->rotation == 270; 631 bool rotation = ctx->rotation == 90 || ctx->rotation == 270;
628 struct fimc_dev *fimc = ctx->fimc_dev; 632 struct fimc_dev *fimc = ctx->fimc_dev;
629 struct fimc_variant *var = fimc->variant; 633 const struct fimc_variant *var = fimc->variant;
630 struct fimc_pix_limit *pl = var->pix_limit; 634 const struct fimc_pix_limit *pl = var->pix_limit;
631 struct fimc_frame *dst = &ctx->d_frame; 635 struct fimc_frame *dst = &ctx->d_frame;
632 u32 depth, min_w, max_w, min_h, align_h = 3; 636 u32 depth, min_w, max_w, min_h, align_h = 3;
633 u32 mask = FMT_FLAGS_CAM; 637 u32 mask = FMT_FLAGS_CAM;
@@ -699,8 +703,8 @@ static void fimc_capture_try_selection(struct fimc_ctx *ctx,
699{ 703{
700 bool rotate = ctx->rotation == 90 || ctx->rotation == 270; 704 bool rotate = ctx->rotation == 90 || ctx->rotation == 270;
701 struct fimc_dev *fimc = ctx->fimc_dev; 705 struct fimc_dev *fimc = ctx->fimc_dev;
702 struct fimc_variant *var = fimc->variant; 706 const struct fimc_variant *var = fimc->variant;
703 struct fimc_pix_limit *pl = var->pix_limit; 707 const struct fimc_pix_limit *pl = var->pix_limit;
704 struct fimc_frame *sink = &ctx->s_frame; 708 struct fimc_frame *sink = &ctx->s_frame;
705 u32 max_w, max_h, min_w = 0, min_h = 0, min_sz; 709 u32 max_w, max_h, min_w = 0, min_h = 0, min_sz;
706 u32 align_sz = 0, align_h = 4; 710 u32 align_sz = 0, align_h = 4;
@@ -793,6 +797,21 @@ static int fimc_cap_enum_fmt_mplane(struct file *file, void *priv,
793 return 0; 797 return 0;
794} 798}
795 799
800static struct media_entity *fimc_pipeline_get_head(struct media_entity *me)
801{
802 struct media_pad *pad = &me->pads[0];
803
804 while (!(pad->flags & MEDIA_PAD_FL_SOURCE)) {
805 pad = media_entity_remote_source(pad);
806 if (!pad)
807 break;
808 me = pad->entity;
809 pad = &me->pads[0];
810 }
811
812 return me;
813}
814
796/** 815/**
797 * fimc_pipeline_try_format - negotiate and/or set formats at pipeline 816 * fimc_pipeline_try_format - negotiate and/or set formats at pipeline
798 * elements 817 * elements
@@ -808,19 +827,23 @@ static int fimc_pipeline_try_format(struct fimc_ctx *ctx,
808{ 827{
809 struct fimc_dev *fimc = ctx->fimc_dev; 828 struct fimc_dev *fimc = ctx->fimc_dev;
810 struct v4l2_subdev *sd = fimc->pipeline.subdevs[IDX_SENSOR]; 829 struct v4l2_subdev *sd = fimc->pipeline.subdevs[IDX_SENSOR];
811 struct v4l2_subdev *csis = fimc->pipeline.subdevs[IDX_CSIS];
812 struct v4l2_subdev_format sfmt; 830 struct v4l2_subdev_format sfmt;
813 struct v4l2_mbus_framefmt *mf = &sfmt.format; 831 struct v4l2_mbus_framefmt *mf = &sfmt.format;
814 struct fimc_fmt *ffmt = NULL; 832 struct media_entity *me;
815 int ret, i = 0; 833 struct fimc_fmt *ffmt;
834 struct media_pad *pad;
835 int ret, i = 1;
836 u32 fcc;
816 837
817 if (WARN_ON(!sd || !tfmt)) 838 if (WARN_ON(!sd || !tfmt))
818 return -EINVAL; 839 return -EINVAL;
819 840
820 memset(&sfmt, 0, sizeof(sfmt)); 841 memset(&sfmt, 0, sizeof(sfmt));
821 sfmt.format = *tfmt; 842 sfmt.format = *tfmt;
822
823 sfmt.which = set ? V4L2_SUBDEV_FORMAT_ACTIVE : V4L2_SUBDEV_FORMAT_TRY; 843 sfmt.which = set ? V4L2_SUBDEV_FORMAT_ACTIVE : V4L2_SUBDEV_FORMAT_TRY;
844
845 me = fimc_pipeline_get_head(&sd->entity);
846
824 while (1) { 847 while (1) {
825 ffmt = fimc_find_format(NULL, mf->code != 0 ? &mf->code : NULL, 848 ffmt = fimc_find_format(NULL, mf->code != 0 ? &mf->code : NULL,
826 FMT_FLAGS_CAM, i++); 849 FMT_FLAGS_CAM, i++);
@@ -833,40 +856,52 @@ static int fimc_pipeline_try_format(struct fimc_ctx *ctx,
833 } 856 }
834 mf->code = tfmt->code = ffmt->mbus_code; 857 mf->code = tfmt->code = ffmt->mbus_code;
835 858
836 ret = v4l2_subdev_call(sd, pad, set_fmt, NULL, &sfmt); 859 /* set format on all pipeline subdevs */
837 if (ret) 860 while (me != &fimc->vid_cap.subdev.entity) {
838 return ret; 861 sd = media_entity_to_v4l2_subdev(me);
839 if (mf->code != tfmt->code) { 862
840 mf->code = 0; 863 sfmt.pad = 0;
841 continue; 864 ret = v4l2_subdev_call(sd, pad, set_fmt, NULL, &sfmt);
865 if (ret)
866 return ret;
867
868 if (me->pads[0].flags & MEDIA_PAD_FL_SINK) {
869 sfmt.pad = me->num_pads - 1;
870 mf->code = tfmt->code;
871 ret = v4l2_subdev_call(sd, pad, set_fmt, NULL,
872 &sfmt);
873 if (ret)
874 return ret;
875 }
876
877 pad = media_entity_remote_source(&me->pads[sfmt.pad]);
878 if (!pad)
879 return -EINVAL;
880 me = pad->entity;
842 } 881 }
843 if (mf->width != tfmt->width || mf->height != tfmt->height) {
844 u32 fcc = ffmt->fourcc;
845 tfmt->width = mf->width;
846 tfmt->height = mf->height;
847 ffmt = fimc_capture_try_format(ctx,
848 &tfmt->width, &tfmt->height,
849 NULL, &fcc, FIMC_SD_PAD_SOURCE);
850 if (ffmt && ffmt->mbus_code)
851 mf->code = ffmt->mbus_code;
852 if (mf->width != tfmt->width ||
853 mf->height != tfmt->height)
854 continue;
855 tfmt->code = mf->code;
856 }
857 if (csis)
858 ret = v4l2_subdev_call(csis, pad, set_fmt, NULL, &sfmt);
859 882
860 if (mf->code == tfmt->code && 883 if (mf->code != tfmt->code)
861 mf->width == tfmt->width && mf->height == tfmt->height) 884 continue;
862 break; 885
886 fcc = ffmt->fourcc;
887 tfmt->width = mf->width;
888 tfmt->height = mf->height;
889 ffmt = fimc_capture_try_format(ctx, &tfmt->width, &tfmt->height,
890 NULL, &fcc, FIMC_SD_PAD_SINK);
891 ffmt = fimc_capture_try_format(ctx, &tfmt->width, &tfmt->height,
892 NULL, &fcc, FIMC_SD_PAD_SOURCE);
893 if (ffmt && ffmt->mbus_code)
894 mf->code = ffmt->mbus_code;
895 if (mf->width != tfmt->width || mf->height != tfmt->height)
896 continue;
897 tfmt->code = mf->code;
898 break;
863 } 899 }
864 900
865 if (fmt_id && ffmt) 901 if (fmt_id && ffmt)
866 *fmt_id = ffmt; 902 *fmt_id = ffmt;
867 *tfmt = *mf; 903 *tfmt = *mf;
868 904
869 dbg("code: 0x%x, %dx%d, %p", mf->code, mf->width, mf->height, ffmt);
870 return 0; 905 return 0;
871} 906}
872 907
@@ -884,14 +919,16 @@ static int fimc_get_sensor_frame_desc(struct v4l2_subdev *sensor,
884{ 919{
885 struct v4l2_mbus_frame_desc fd; 920 struct v4l2_mbus_frame_desc fd;
886 int i, ret; 921 int i, ret;
922 int pad;
887 923
888 for (i = 0; i < num_planes; i++) 924 for (i = 0; i < num_planes; i++)
889 fd.entry[i].length = plane_fmt[i].sizeimage; 925 fd.entry[i].length = plane_fmt[i].sizeimage;
890 926
927 pad = sensor->entity.num_pads - 1;
891 if (try) 928 if (try)
892 ret = v4l2_subdev_call(sensor, pad, set_frame_desc, 0, &fd); 929 ret = v4l2_subdev_call(sensor, pad, set_frame_desc, pad, &fd);
893 else 930 else
894 ret = v4l2_subdev_call(sensor, pad, get_frame_desc, 0, &fd); 931 ret = v4l2_subdev_call(sensor, pad, get_frame_desc, pad, &fd);
895 932
896 if (ret < 0) 933 if (ret < 0)
897 return ret; 934 return ret;
@@ -916,9 +953,9 @@ static int fimc_cap_g_fmt_mplane(struct file *file, void *fh,
916 struct v4l2_format *f) 953 struct v4l2_format *f)
917{ 954{
918 struct fimc_dev *fimc = video_drvdata(file); 955 struct fimc_dev *fimc = video_drvdata(file);
919 struct fimc_ctx *ctx = fimc->vid_cap.ctx;
920 956
921 return fimc_fill_format(&ctx->d_frame, f); 957 __fimc_get_format(&fimc->vid_cap.ctx->d_frame, f);
958 return 0;
922} 959}
923 960
924static int fimc_cap_try_fmt_mplane(struct file *file, void *fh, 961static int fimc_cap_try_fmt_mplane(struct file *file, void *fh,
@@ -929,6 +966,10 @@ static int fimc_cap_try_fmt_mplane(struct file *file, void *fh,
929 struct fimc_ctx *ctx = fimc->vid_cap.ctx; 966 struct fimc_ctx *ctx = fimc->vid_cap.ctx;
930 struct v4l2_mbus_framefmt mf; 967 struct v4l2_mbus_framefmt mf;
931 struct fimc_fmt *ffmt = NULL; 968 struct fimc_fmt *ffmt = NULL;
969 int ret = 0;
970
971 fimc_md_graph_lock(fimc);
972 mutex_lock(&fimc->lock);
932 973
933 if (fimc_jpeg_fourcc(pix->pixelformat)) { 974 if (fimc_jpeg_fourcc(pix->pixelformat)) {
934 fimc_capture_try_format(ctx, &pix->width, &pix->height, 975 fimc_capture_try_format(ctx, &pix->width, &pix->height,
@@ -940,16 +981,16 @@ static int fimc_cap_try_fmt_mplane(struct file *file, void *fh,
940 ffmt = fimc_capture_try_format(ctx, &pix->width, &pix->height, 981 ffmt = fimc_capture_try_format(ctx, &pix->width, &pix->height,
941 NULL, &pix->pixelformat, 982 NULL, &pix->pixelformat,
942 FIMC_SD_PAD_SOURCE); 983 FIMC_SD_PAD_SOURCE);
943 if (!ffmt) 984 if (!ffmt) {
944 return -EINVAL; 985 ret = -EINVAL;
986 goto unlock;
987 }
945 988
946 if (!fimc->vid_cap.user_subdev_api) { 989 if (!fimc->vid_cap.user_subdev_api) {
947 mf.width = pix->width; 990 mf.width = pix->width;
948 mf.height = pix->height; 991 mf.height = pix->height;
949 mf.code = ffmt->mbus_code; 992 mf.code = ffmt->mbus_code;
950 fimc_md_graph_lock(fimc);
951 fimc_pipeline_try_format(ctx, &mf, &ffmt, false); 993 fimc_pipeline_try_format(ctx, &mf, &ffmt, false);
952 fimc_md_graph_unlock(fimc);
953 pix->width = mf.width; 994 pix->width = mf.width;
954 pix->height = mf.height; 995 pix->height = mf.height;
955 if (ffmt) 996 if (ffmt)
@@ -961,8 +1002,11 @@ static int fimc_cap_try_fmt_mplane(struct file *file, void *fh,
961 if (ffmt->flags & FMT_FLAGS_COMPRESSED) 1002 if (ffmt->flags & FMT_FLAGS_COMPRESSED)
962 fimc_get_sensor_frame_desc(fimc->pipeline.subdevs[IDX_SENSOR], 1003 fimc_get_sensor_frame_desc(fimc->pipeline.subdevs[IDX_SENSOR],
963 pix->plane_fmt, ffmt->memplanes, true); 1004 pix->plane_fmt, ffmt->memplanes, true);
1005unlock:
1006 mutex_unlock(&fimc->lock);
1007 fimc_md_graph_unlock(fimc);
964 1008
965 return 0; 1009 return ret;
966} 1010}
967 1011
968static void fimc_capture_mark_jpeg_xfer(struct fimc_ctx *ctx, 1012static void fimc_capture_mark_jpeg_xfer(struct fimc_ctx *ctx,
@@ -979,7 +1023,8 @@ static void fimc_capture_mark_jpeg_xfer(struct fimc_ctx *ctx,
979 clear_bit(ST_CAPT_JPEG, &ctx->fimc_dev->state); 1023 clear_bit(ST_CAPT_JPEG, &ctx->fimc_dev->state);
980} 1024}
981 1025
982static int fimc_capture_set_format(struct fimc_dev *fimc, struct v4l2_format *f) 1026static int __fimc_capture_set_format(struct fimc_dev *fimc,
1027 struct v4l2_format *f)
983{ 1028{
984 struct fimc_ctx *ctx = fimc->vid_cap.ctx; 1029 struct fimc_ctx *ctx = fimc->vid_cap.ctx;
985 struct v4l2_pix_format_mplane *pix = &f->fmt.pix_mp; 1030 struct v4l2_pix_format_mplane *pix = &f->fmt.pix_mp;
@@ -1014,12 +1059,10 @@ static int fimc_capture_set_format(struct fimc_dev *fimc, struct v4l2_format *f)
1014 mf->code = ff->fmt->mbus_code; 1059 mf->code = ff->fmt->mbus_code;
1015 mf->width = pix->width; 1060 mf->width = pix->width;
1016 mf->height = pix->height; 1061 mf->height = pix->height;
1017
1018 fimc_md_graph_lock(fimc);
1019 ret = fimc_pipeline_try_format(ctx, mf, &s_fmt, true); 1062 ret = fimc_pipeline_try_format(ctx, mf, &s_fmt, true);
1020 fimc_md_graph_unlock(fimc);
1021 if (ret) 1063 if (ret)
1022 return ret; 1064 return ret;
1065
1023 pix->width = mf->width; 1066 pix->width = mf->width;
1024 pix->height = mf->height; 1067 pix->height = mf->height;
1025 } 1068 }
@@ -1034,8 +1077,10 @@ static int fimc_capture_set_format(struct fimc_dev *fimc, struct v4l2_format *f)
1034 return ret; 1077 return ret;
1035 } 1078 }
1036 1079
1037 for (i = 0; i < ff->fmt->memplanes; i++) 1080 for (i = 0; i < ff->fmt->memplanes; i++) {
1081 ff->bytesperline[i] = pix->plane_fmt[i].bytesperline;
1038 ff->payload[i] = pix->plane_fmt[i].sizeimage; 1082 ff->payload[i] = pix->plane_fmt[i].sizeimage;
1083 }
1039 1084
1040 set_frame_bounds(ff, pix->width, pix->height); 1085 set_frame_bounds(ff, pix->width, pix->height);
1041 /* Reset the composition rectangle if not yet configured */ 1086 /* Reset the composition rectangle if not yet configured */
@@ -1058,8 +1103,23 @@ static int fimc_cap_s_fmt_mplane(struct file *file, void *priv,
1058 struct v4l2_format *f) 1103 struct v4l2_format *f)
1059{ 1104{
1060 struct fimc_dev *fimc = video_drvdata(file); 1105 struct fimc_dev *fimc = video_drvdata(file);
1106 int ret;
1107
1108 fimc_md_graph_lock(fimc);
1109 mutex_lock(&fimc->lock);
1110 /*
1111 * The graph is walked within __fimc_capture_set_format() to set
1112 * the format at subdevs thus the graph mutex needs to be held at
1113 * this point and acquired before the video mutex, to avoid AB-BA
1114 * deadlock when fimc_md_link_notify() is called by other thread.
1115 * Ideally the graph walking and setting format at the whole pipeline
1116 * should be removed from this driver and handled in userspace only.
1117 */
1118 ret = __fimc_capture_set_format(fimc, f);
1061 1119
1062 return fimc_capture_set_format(fimc, f); 1120 mutex_unlock(&fimc->lock);
1121 fimc_md_graph_unlock(fimc);
1122 return ret;
1063} 1123}
1064 1124
1065static int fimc_cap_enum_input(struct file *file, void *priv, 1125static int fimc_cap_enum_input(struct file *file, void *priv,
@@ -1528,6 +1588,10 @@ static int fimc_subdev_set_fmt(struct v4l2_subdev *sd,
1528 *mf = fmt->format; 1588 *mf = fmt->format;
1529 return 0; 1589 return 0;
1530 } 1590 }
1591 /* There must be a bug in the driver if this happens */
1592 if (WARN_ON(ffmt == NULL))
1593 return -EINVAL;
1594
1531 /* Update RGB Alpha control state and value range */ 1595 /* Update RGB Alpha control state and value range */
1532 fimc_alpha_ctrl_update(ctx); 1596 fimc_alpha_ctrl_update(ctx);
1533 1597
@@ -1624,16 +1688,6 @@ static int fimc_subdev_set_selection(struct v4l2_subdev *sd,
1624 fimc_capture_try_selection(ctx, r, V4L2_SEL_TGT_CROP); 1688 fimc_capture_try_selection(ctx, r, V4L2_SEL_TGT_CROP);
1625 1689
1626 switch (sel->target) { 1690 switch (sel->target) {
1627 case V4L2_SEL_TGT_COMPOSE_BOUNDS:
1628 f = &ctx->d_frame;
1629 case V4L2_SEL_TGT_CROP_BOUNDS:
1630 r->width = f->o_width;
1631 r->height = f->o_height;
1632 r->left = 0;
1633 r->top = 0;
1634 mutex_unlock(&fimc->lock);
1635 return 0;
1636
1637 case V4L2_SEL_TGT_CROP: 1691 case V4L2_SEL_TGT_CROP:
1638 try_sel = v4l2_subdev_get_try_crop(fh, sel->pad); 1692 try_sel = v4l2_subdev_get_try_crop(fh, sel->pad);
1639 break; 1693 break;
@@ -1652,9 +1706,9 @@ static int fimc_subdev_set_selection(struct v4l2_subdev *sd,
1652 spin_lock_irqsave(&fimc->slock, flags); 1706 spin_lock_irqsave(&fimc->slock, flags);
1653 set_frame_crop(f, r->left, r->top, r->width, r->height); 1707 set_frame_crop(f, r->left, r->top, r->width, r->height);
1654 set_bit(ST_CAPT_APPLY_CFG, &fimc->state); 1708 set_bit(ST_CAPT_APPLY_CFG, &fimc->state);
1655 spin_unlock_irqrestore(&fimc->slock, flags);
1656 if (sel->target == V4L2_SEL_TGT_COMPOSE) 1709 if (sel->target == V4L2_SEL_TGT_COMPOSE)
1657 ctx->state |= FIMC_COMPOSE; 1710 ctx->state |= FIMC_COMPOSE;
1711 spin_unlock_irqrestore(&fimc->slock, flags);
1658 } 1712 }
1659 1713
1660 dbg("target %#x: (%d,%d)/%dx%d", sel->target, r->left, r->top, 1714 dbg("target %#x: (%d,%d)/%dx%d", sel->target, r->left, r->top,
@@ -1690,7 +1744,7 @@ static int fimc_capture_set_default_format(struct fimc_dev *fimc)
1690 }, 1744 },
1691 }; 1745 };
1692 1746
1693 return fimc_capture_set_format(fimc, &fmt); 1747 return __fimc_capture_set_format(fimc, &fmt);
1694} 1748}
1695 1749
1696/* fimc->lock must be already initialized */ 1750/* fimc->lock must be already initialized */
@@ -1752,6 +1806,12 @@ static int fimc_register_capture_device(struct fimc_dev *fimc,
1752 ret = media_entity_init(&vfd->entity, 1, &vid_cap->vd_pad, 0); 1806 ret = media_entity_init(&vfd->entity, 1, &vid_cap->vd_pad, 0);
1753 if (ret) 1807 if (ret)
1754 goto err_ent; 1808 goto err_ent;
1809 /*
1810 * For proper order of acquiring/releasing the video
1811 * and the graph mutex.
1812 */
1813 v4l2_disable_ioctl_locking(vfd, VIDIOC_TRY_FMT);
1814 v4l2_disable_ioctl_locking(vfd, VIDIOC_S_FMT);
1755 1815
1756 ret = video_register_device(vfd, VFL_TYPE_GRABBER, -1); 1816 ret = video_register_device(vfd, VFL_TYPE_GRABBER, -1);
1757 if (ret) 1817 if (ret)
diff --git a/drivers/media/platform/s5p-fimc/fimc-core.c b/drivers/media/platform/s5p-fimc/fimc-core.c
index acc0f84ffa56..e3916bde45cf 100644
--- a/drivers/media/platform/s5p-fimc/fimc-core.c
+++ b/drivers/media/platform/s5p-fimc/fimc-core.c
@@ -241,7 +241,7 @@ static int fimc_get_scaler_factor(u32 src, u32 tar, u32 *ratio, u32 *shift)
241 241
242int fimc_set_scaler_info(struct fimc_ctx *ctx) 242int fimc_set_scaler_info(struct fimc_ctx *ctx)
243{ 243{
244 struct fimc_variant *variant = ctx->fimc_dev->variant; 244 const struct fimc_variant *variant = ctx->fimc_dev->variant;
245 struct device *dev = &ctx->fimc_dev->pdev->dev; 245 struct device *dev = &ctx->fimc_dev->pdev->dev;
246 struct fimc_scaler *sc = &ctx->scaler; 246 struct fimc_scaler *sc = &ctx->scaler;
247 struct fimc_frame *s_frame = &ctx->s_frame; 247 struct fimc_frame *s_frame = &ctx->s_frame;
@@ -257,14 +257,14 @@ int fimc_set_scaler_info(struct fimc_ctx *ctx)
257 ty = d_frame->height; 257 ty = d_frame->height;
258 } 258 }
259 if (tx <= 0 || ty <= 0) { 259 if (tx <= 0 || ty <= 0) {
260 dev_err(dev, "Invalid target size: %dx%d", tx, ty); 260 dev_err(dev, "Invalid target size: %dx%d\n", tx, ty);
261 return -EINVAL; 261 return -EINVAL;
262 } 262 }
263 263
264 sx = s_frame->width; 264 sx = s_frame->width;
265 sy = s_frame->height; 265 sy = s_frame->height;
266 if (sx <= 0 || sy <= 0) { 266 if (sx <= 0 || sy <= 0) {
267 dev_err(dev, "Invalid source size: %dx%d", sx, sy); 267 dev_err(dev, "Invalid source size: %dx%d\n", sx, sy);
268 return -EINVAL; 268 return -EINVAL;
269 } 269 }
270 sc->real_width = sx; 270 sc->real_width = sx;
@@ -440,7 +440,7 @@ void fimc_set_yuv_order(struct fimc_ctx *ctx)
440 440
441void fimc_prepare_dma_offset(struct fimc_ctx *ctx, struct fimc_frame *f) 441void fimc_prepare_dma_offset(struct fimc_ctx *ctx, struct fimc_frame *f)
442{ 442{
443 struct fimc_variant *variant = ctx->fimc_dev->variant; 443 const struct fimc_variant *variant = ctx->fimc_dev->variant;
444 u32 i, depth = 0; 444 u32 i, depth = 0;
445 445
446 for (i = 0; i < f->fmt->colplanes; i++) 446 for (i = 0; i < f->fmt->colplanes; i++)
@@ -524,8 +524,7 @@ static int fimc_set_color_effect(struct fimc_ctx *ctx, enum v4l2_colorfx colorfx
524static int __fimc_s_ctrl(struct fimc_ctx *ctx, struct v4l2_ctrl *ctrl) 524static int __fimc_s_ctrl(struct fimc_ctx *ctx, struct v4l2_ctrl *ctrl)
525{ 525{
526 struct fimc_dev *fimc = ctx->fimc_dev; 526 struct fimc_dev *fimc = ctx->fimc_dev;
527 struct fimc_variant *variant = fimc->variant; 527 const struct fimc_variant *variant = fimc->variant;
528 unsigned int flags = FIMC_DST_FMT | FIMC_SRC_FMT;
529 int ret = 0; 528 int ret = 0;
530 529
531 if (ctrl->flags & V4L2_CTRL_FLAG_INACTIVE) 530 if (ctrl->flags & V4L2_CTRL_FLAG_INACTIVE)
@@ -541,8 +540,7 @@ static int __fimc_s_ctrl(struct fimc_ctx *ctx, struct v4l2_ctrl *ctrl)
541 break; 540 break;
542 541
543 case V4L2_CID_ROTATE: 542 case V4L2_CID_ROTATE:
544 if (fimc_capture_pending(fimc) || 543 if (fimc_capture_pending(fimc)) {
545 (ctx->state & flags) == flags) {
546 ret = fimc_check_scaler_ratio(ctx, ctx->s_frame.width, 544 ret = fimc_check_scaler_ratio(ctx, ctx->s_frame.width,
547 ctx->s_frame.height, ctx->d_frame.width, 545 ctx->s_frame.height, ctx->d_frame.width,
548 ctx->d_frame.height, ctrl->val); 546 ctx->d_frame.height, ctrl->val);
@@ -591,7 +589,7 @@ static const struct v4l2_ctrl_ops fimc_ctrl_ops = {
591 589
592int fimc_ctrls_create(struct fimc_ctx *ctx) 590int fimc_ctrls_create(struct fimc_ctx *ctx)
593{ 591{
594 struct fimc_variant *variant = ctx->fimc_dev->variant; 592 const struct fimc_variant *variant = ctx->fimc_dev->variant;
595 unsigned int max_alpha = fimc_get_alpha_mask(ctx->d_frame.fmt); 593 unsigned int max_alpha = fimc_get_alpha_mask(ctx->d_frame.fmt);
596 struct fimc_ctrls *ctrls = &ctx->ctrls; 594 struct fimc_ctrls *ctrls = &ctx->ctrls;
597 struct v4l2_ctrl_handler *handler = &ctrls->handler; 595 struct v4l2_ctrl_handler *handler = &ctrls->handler;
@@ -691,7 +689,7 @@ void fimc_alpha_ctrl_update(struct fimc_ctx *ctx)
691 v4l2_ctrl_unlock(ctrl); 689 v4l2_ctrl_unlock(ctrl);
692} 690}
693 691
694int fimc_fill_format(struct fimc_frame *frame, struct v4l2_format *f) 692void __fimc_get_format(struct fimc_frame *frame, struct v4l2_format *f)
695{ 693{
696 struct v4l2_pix_format_mplane *pixm = &f->fmt.pix_mp; 694 struct v4l2_pix_format_mplane *pixm = &f->fmt.pix_mp;
697 int i; 695 int i;
@@ -704,35 +702,9 @@ int fimc_fill_format(struct fimc_frame *frame, struct v4l2_format *f)
704 pixm->num_planes = frame->fmt->memplanes; 702 pixm->num_planes = frame->fmt->memplanes;
705 703
706 for (i = 0; i < pixm->num_planes; ++i) { 704 for (i = 0; i < pixm->num_planes; ++i) {
707 int bpl = frame->f_width; 705 pixm->plane_fmt[i].bytesperline = frame->bytesperline[i];
708 if (frame->fmt->colplanes == 1) /* packed formats */ 706 pixm->plane_fmt[i].sizeimage = frame->payload[i];
709 bpl = (bpl * frame->fmt->depth[0]) / 8;
710 pixm->plane_fmt[i].bytesperline = bpl;
711
712 if (frame->fmt->flags & FMT_FLAGS_COMPRESSED) {
713 pixm->plane_fmt[i].sizeimage = frame->payload[i];
714 continue;
715 }
716 pixm->plane_fmt[i].sizeimage = (frame->o_width *
717 frame->o_height * frame->fmt->depth[i]) / 8;
718 } 707 }
719 return 0;
720}
721
722void fimc_fill_frame(struct fimc_frame *frame, struct v4l2_format *f)
723{
724 struct v4l2_pix_format_mplane *pixm = &f->fmt.pix_mp;
725
726 frame->f_width = pixm->plane_fmt[0].bytesperline;
727 if (frame->fmt->colplanes == 1)
728 frame->f_width = (frame->f_width * 8) / frame->fmt->depth[0];
729 frame->f_height = pixm->height;
730 frame->width = pixm->width;
731 frame->height = pixm->height;
732 frame->o_width = pixm->width;
733 frame->o_height = pixm->height;
734 frame->offs_h = 0;
735 frame->offs_v = 0;
736} 708}
737 709
738/** 710/**
@@ -765,9 +737,16 @@ void fimc_adjust_mplane_format(struct fimc_fmt *fmt, u32 width, u32 height,
765 if (fmt->colplanes == 1 && /* Packed */ 737 if (fmt->colplanes == 1 && /* Packed */
766 (bpl == 0 || ((bpl * 8) / fmt->depth[i]) < pix->width)) 738 (bpl == 0 || ((bpl * 8) / fmt->depth[i]) < pix->width))
767 bpl = (pix->width * fmt->depth[0]) / 8; 739 bpl = (pix->width * fmt->depth[0]) / 8;
768 740 /*
769 if (i == 0) /* Same bytesperline for each plane. */ 741 * Currently bytesperline for each plane is same, except
742 * V4L2_PIX_FMT_YUV420M format. This calculation may need
743 * to be changed when other multi-planar formats are added
744 * to the fimc_formats[] array.
745 */
746 if (i == 0)
770 bytesperline = bpl; 747 bytesperline = bpl;
748 else if (i == 1 && fmt->memplanes == 3)
749 bytesperline /= 2;
771 750
772 plane_fmt->bytesperline = bytesperline; 751 plane_fmt->bytesperline = bytesperline;
773 plane_fmt->sizeimage = max((pix->width * pix->height * 752 plane_fmt->sizeimage = max((pix->width * pix->height *
@@ -811,11 +790,11 @@ static void fimc_clk_put(struct fimc_dev *fimc)
811{ 790{
812 int i; 791 int i;
813 for (i = 0; i < MAX_FIMC_CLOCKS; i++) { 792 for (i = 0; i < MAX_FIMC_CLOCKS; i++) {
814 if (IS_ERR_OR_NULL(fimc->clock[i])) 793 if (IS_ERR(fimc->clock[i]))
815 continue; 794 continue;
816 clk_unprepare(fimc->clock[i]); 795 clk_unprepare(fimc->clock[i]);
817 clk_put(fimc->clock[i]); 796 clk_put(fimc->clock[i]);
818 fimc->clock[i] = NULL; 797 fimc->clock[i] = ERR_PTR(-EINVAL);
819 } 798 }
820} 799}
821 800
@@ -823,14 +802,19 @@ static int fimc_clk_get(struct fimc_dev *fimc)
823{ 802{
824 int i, ret; 803 int i, ret;
825 804
805 for (i = 0; i < MAX_FIMC_CLOCKS; i++)
806 fimc->clock[i] = ERR_PTR(-EINVAL);
807
826 for (i = 0; i < MAX_FIMC_CLOCKS; i++) { 808 for (i = 0; i < MAX_FIMC_CLOCKS; i++) {
827 fimc->clock[i] = clk_get(&fimc->pdev->dev, fimc_clocks[i]); 809 fimc->clock[i] = clk_get(&fimc->pdev->dev, fimc_clocks[i]);
828 if (IS_ERR(fimc->clock[i])) 810 if (IS_ERR(fimc->clock[i])) {
811 ret = PTR_ERR(fimc->clock[i]);
829 goto err; 812 goto err;
813 }
830 ret = clk_prepare(fimc->clock[i]); 814 ret = clk_prepare(fimc->clock[i]);
831 if (ret < 0) { 815 if (ret < 0) {
832 clk_put(fimc->clock[i]); 816 clk_put(fimc->clock[i]);
833 fimc->clock[i] = NULL; 817 fimc->clock[i] = ERR_PTR(-EINVAL);
834 goto err; 818 goto err;
835 } 819 }
836 } 820 }
@@ -881,7 +865,7 @@ static int fimc_m2m_resume(struct fimc_dev *fimc)
881 865
882static int fimc_probe(struct platform_device *pdev) 866static int fimc_probe(struct platform_device *pdev)
883{ 867{
884 struct fimc_drvdata *drv_data = fimc_get_drvdata(pdev); 868 const struct fimc_drvdata *drv_data = fimc_get_drvdata(pdev);
885 struct s5p_platform_fimc *pdata; 869 struct s5p_platform_fimc *pdata;
886 struct fimc_dev *fimc; 870 struct fimc_dev *fimc;
887 struct resource *res; 871 struct resource *res;
@@ -922,8 +906,14 @@ static int fimc_probe(struct platform_device *pdev)
922 ret = fimc_clk_get(fimc); 906 ret = fimc_clk_get(fimc);
923 if (ret) 907 if (ret)
924 return ret; 908 return ret;
925 clk_set_rate(fimc->clock[CLK_BUS], drv_data->lclk_frequency); 909
926 clk_enable(fimc->clock[CLK_BUS]); 910 ret = clk_set_rate(fimc->clock[CLK_BUS], drv_data->lclk_frequency);
911 if (ret < 0)
912 return ret;
913
914 ret = clk_enable(fimc->clock[CLK_BUS]);
915 if (ret < 0)
916 return ret;
927 917
928 ret = devm_request_irq(&pdev->dev, res->start, fimc_irq_handler, 918 ret = devm_request_irq(&pdev->dev, res->start, fimc_irq_handler,
929 0, dev_name(&pdev->dev), fimc); 919 0, dev_name(&pdev->dev), fimc);
@@ -957,6 +947,7 @@ err_pm:
957err_sd: 947err_sd:
958 fimc_unregister_capture_subdev(fimc); 948 fimc_unregister_capture_subdev(fimc);
959err_clk: 949err_clk:
950 clk_disable(fimc->clock[CLK_BUS]);
960 fimc_clk_put(fimc); 951 fimc_clk_put(fimc);
961 return ret; 952 return ret;
962} 953}
@@ -1051,7 +1042,7 @@ static int fimc_remove(struct platform_device *pdev)
1051} 1042}
1052 1043
1053/* Image pixel limits, similar across several FIMC HW revisions. */ 1044/* Image pixel limits, similar across several FIMC HW revisions. */
1054static struct fimc_pix_limit s5p_pix_limit[4] = { 1045static const struct fimc_pix_limit s5p_pix_limit[4] = {
1055 [0] = { 1046 [0] = {
1056 .scaler_en_w = 3264, 1047 .scaler_en_w = 3264,
1057 .scaler_dis_w = 8192, 1048 .scaler_dis_w = 8192,
@@ -1086,7 +1077,7 @@ static struct fimc_pix_limit s5p_pix_limit[4] = {
1086 }, 1077 },
1087}; 1078};
1088 1079
1089static struct fimc_variant fimc0_variant_s5p = { 1080static const struct fimc_variant fimc0_variant_s5p = {
1090 .has_inp_rot = 1, 1081 .has_inp_rot = 1,
1091 .has_out_rot = 1, 1082 .has_out_rot = 1,
1092 .has_cam_if = 1, 1083 .has_cam_if = 1,
@@ -1098,7 +1089,7 @@ static struct fimc_variant fimc0_variant_s5p = {
1098 .pix_limit = &s5p_pix_limit[0], 1089 .pix_limit = &s5p_pix_limit[0],
1099}; 1090};
1100 1091
1101static struct fimc_variant fimc2_variant_s5p = { 1092static const struct fimc_variant fimc2_variant_s5p = {
1102 .has_cam_if = 1, 1093 .has_cam_if = 1,
1103 .min_inp_pixsize = 16, 1094 .min_inp_pixsize = 16,
1104 .min_out_pixsize = 16, 1095 .min_out_pixsize = 16,
@@ -1108,7 +1099,7 @@ static struct fimc_variant fimc2_variant_s5p = {
1108 .pix_limit = &s5p_pix_limit[1], 1099 .pix_limit = &s5p_pix_limit[1],
1109}; 1100};
1110 1101
1111static struct fimc_variant fimc0_variant_s5pv210 = { 1102static const struct fimc_variant fimc0_variant_s5pv210 = {
1112 .pix_hoff = 1, 1103 .pix_hoff = 1,
1113 .has_inp_rot = 1, 1104 .has_inp_rot = 1,
1114 .has_out_rot = 1, 1105 .has_out_rot = 1,
@@ -1121,7 +1112,7 @@ static struct fimc_variant fimc0_variant_s5pv210 = {
1121 .pix_limit = &s5p_pix_limit[1], 1112 .pix_limit = &s5p_pix_limit[1],
1122}; 1113};
1123 1114
1124static struct fimc_variant fimc1_variant_s5pv210 = { 1115static const struct fimc_variant fimc1_variant_s5pv210 = {
1125 .pix_hoff = 1, 1116 .pix_hoff = 1,
1126 .has_inp_rot = 1, 1117 .has_inp_rot = 1,
1127 .has_out_rot = 1, 1118 .has_out_rot = 1,
@@ -1135,7 +1126,7 @@ static struct fimc_variant fimc1_variant_s5pv210 = {
1135 .pix_limit = &s5p_pix_limit[2], 1126 .pix_limit = &s5p_pix_limit[2],
1136}; 1127};
1137 1128
1138static struct fimc_variant fimc2_variant_s5pv210 = { 1129static const struct fimc_variant fimc2_variant_s5pv210 = {
1139 .has_cam_if = 1, 1130 .has_cam_if = 1,
1140 .pix_hoff = 1, 1131 .pix_hoff = 1,
1141 .min_inp_pixsize = 16, 1132 .min_inp_pixsize = 16,
@@ -1146,7 +1137,7 @@ static struct fimc_variant fimc2_variant_s5pv210 = {
1146 .pix_limit = &s5p_pix_limit[2], 1137 .pix_limit = &s5p_pix_limit[2],
1147}; 1138};
1148 1139
1149static struct fimc_variant fimc0_variant_exynos4 = { 1140static const struct fimc_variant fimc0_variant_exynos4210 = {
1150 .pix_hoff = 1, 1141 .pix_hoff = 1,
1151 .has_inp_rot = 1, 1142 .has_inp_rot = 1,
1152 .has_out_rot = 1, 1143 .has_out_rot = 1,
@@ -1162,9 +1153,8 @@ static struct fimc_variant fimc0_variant_exynos4 = {
1162 .pix_limit = &s5p_pix_limit[1], 1153 .pix_limit = &s5p_pix_limit[1],
1163}; 1154};
1164 1155
1165static struct fimc_variant fimc3_variant_exynos4 = { 1156static const struct fimc_variant fimc3_variant_exynos4210 = {
1166 .pix_hoff = 1, 1157 .pix_hoff = 1,
1167 .has_cam_if = 1,
1168 .has_cistatus2 = 1, 1158 .has_cistatus2 = 1,
1169 .has_mainscaler_ext = 1, 1159 .has_mainscaler_ext = 1,
1170 .has_alpha = 1, 1160 .has_alpha = 1,
@@ -1176,8 +1166,38 @@ static struct fimc_variant fimc3_variant_exynos4 = {
1176 .pix_limit = &s5p_pix_limit[3], 1166 .pix_limit = &s5p_pix_limit[3],
1177}; 1167};
1178 1168
1169static const struct fimc_variant fimc0_variant_exynos4x12 = {
1170 .pix_hoff = 1,
1171 .has_inp_rot = 1,
1172 .has_out_rot = 1,
1173 .has_cam_if = 1,
1174 .has_isp_wb = 1,
1175 .has_cistatus2 = 1,
1176 .has_mainscaler_ext = 1,
1177 .has_alpha = 1,
1178 .min_inp_pixsize = 16,
1179 .min_out_pixsize = 16,
1180 .hor_offs_align = 2,
1181 .min_vsize_align = 1,
1182 .out_buf_count = 32,
1183 .pix_limit = &s5p_pix_limit[1],
1184};
1185
1186static const struct fimc_variant fimc3_variant_exynos4x12 = {
1187 .pix_hoff = 1,
1188 .has_cistatus2 = 1,
1189 .has_mainscaler_ext = 1,
1190 .has_alpha = 1,
1191 .min_inp_pixsize = 16,
1192 .min_out_pixsize = 16,
1193 .hor_offs_align = 2,
1194 .min_vsize_align = 1,
1195 .out_buf_count = 32,
1196 .pix_limit = &s5p_pix_limit[3],
1197};
1198
1179/* S5PC100 */ 1199/* S5PC100 */
1180static struct fimc_drvdata fimc_drvdata_s5p = { 1200static const struct fimc_drvdata fimc_drvdata_s5p = {
1181 .variant = { 1201 .variant = {
1182 [0] = &fimc0_variant_s5p, 1202 [0] = &fimc0_variant_s5p,
1183 [1] = &fimc0_variant_s5p, 1203 [1] = &fimc0_variant_s5p,
@@ -1188,7 +1208,7 @@ static struct fimc_drvdata fimc_drvdata_s5p = {
1188}; 1208};
1189 1209
1190/* S5PV210, S5PC110 */ 1210/* S5PV210, S5PC110 */
1191static struct fimc_drvdata fimc_drvdata_s5pv210 = { 1211static const struct fimc_drvdata fimc_drvdata_s5pv210 = {
1192 .variant = { 1212 .variant = {
1193 [0] = &fimc0_variant_s5pv210, 1213 [0] = &fimc0_variant_s5pv210,
1194 [1] = &fimc1_variant_s5pv210, 1214 [1] = &fimc1_variant_s5pv210,
@@ -1199,18 +1219,30 @@ static struct fimc_drvdata fimc_drvdata_s5pv210 = {
1199}; 1219};
1200 1220
1201/* EXYNOS4210, S5PV310, S5PC210 */ 1221/* EXYNOS4210, S5PV310, S5PC210 */
1202static struct fimc_drvdata fimc_drvdata_exynos4 = { 1222static const struct fimc_drvdata fimc_drvdata_exynos4210 = {
1223 .variant = {
1224 [0] = &fimc0_variant_exynos4210,
1225 [1] = &fimc0_variant_exynos4210,
1226 [2] = &fimc0_variant_exynos4210,
1227 [3] = &fimc3_variant_exynos4210,
1228 },
1229 .num_entities = 4,
1230 .lclk_frequency = 166000000UL,
1231};
1232
1233/* EXYNOS4212, EXYNOS4412 */
1234static const struct fimc_drvdata fimc_drvdata_exynos4x12 = {
1203 .variant = { 1235 .variant = {
1204 [0] = &fimc0_variant_exynos4, 1236 [0] = &fimc0_variant_exynos4x12,
1205 [1] = &fimc0_variant_exynos4, 1237 [1] = &fimc0_variant_exynos4x12,
1206 [2] = &fimc0_variant_exynos4, 1238 [2] = &fimc0_variant_exynos4x12,
1207 [3] = &fimc3_variant_exynos4, 1239 [3] = &fimc3_variant_exynos4x12,
1208 }, 1240 },
1209 .num_entities = 4, 1241 .num_entities = 4,
1210 .lclk_frequency = 166000000UL, 1242 .lclk_frequency = 166000000UL,
1211}; 1243};
1212 1244
1213static struct platform_device_id fimc_driver_ids[] = { 1245static const struct platform_device_id fimc_driver_ids[] = {
1214 { 1246 {
1215 .name = "s5p-fimc", 1247 .name = "s5p-fimc",
1216 .driver_data = (unsigned long)&fimc_drvdata_s5p, 1248 .driver_data = (unsigned long)&fimc_drvdata_s5p,
@@ -1219,7 +1251,10 @@ static struct platform_device_id fimc_driver_ids[] = {
1219 .driver_data = (unsigned long)&fimc_drvdata_s5pv210, 1251 .driver_data = (unsigned long)&fimc_drvdata_s5pv210,
1220 }, { 1252 }, {
1221 .name = "exynos4-fimc", 1253 .name = "exynos4-fimc",
1222 .driver_data = (unsigned long)&fimc_drvdata_exynos4, 1254 .driver_data = (unsigned long)&fimc_drvdata_exynos4210,
1255 }, {
1256 .name = "exynos4x12-fimc",
1257 .driver_data = (unsigned long)&fimc_drvdata_exynos4x12,
1223 }, 1258 },
1224 {}, 1259 {},
1225}; 1260};
diff --git a/drivers/media/platform/s5p-fimc/fimc-core.h b/drivers/media/platform/s5p-fimc/fimc-core.h
index c0040d792499..412d50708f75 100644
--- a/drivers/media/platform/s5p-fimc/fimc-core.h
+++ b/drivers/media/platform/s5p-fimc/fimc-core.h
@@ -112,9 +112,7 @@ enum fimc_color_fmt {
112 112
113/* The hardware context state. */ 113/* The hardware context state. */
114#define FIMC_PARAMS (1 << 0) 114#define FIMC_PARAMS (1 << 0)
115#define FIMC_SRC_FMT (1 << 3) 115#define FIMC_COMPOSE (1 << 1)
116#define FIMC_DST_FMT (1 << 4)
117#define FIMC_COMPOSE (1 << 5)
118#define FIMC_CTX_M2M (1 << 16) 116#define FIMC_CTX_M2M (1 << 16)
119#define FIMC_CTX_CAP (1 << 17) 117#define FIMC_CTX_CAP (1 << 17)
120#define FIMC_CTX_SHUT (1 << 18) 118#define FIMC_CTX_SHUT (1 << 18)
@@ -265,6 +263,7 @@ struct fimc_vid_buffer {
265 * @width: image pixel width 263 * @width: image pixel width
266 * @height: image pixel weight 264 * @height: image pixel weight
267 * @payload: image size in bytes (w x h x bpp) 265 * @payload: image size in bytes (w x h x bpp)
266 * @bytesperline: bytesperline value for each plane
268 * @paddr: image frame buffer physical addresses 267 * @paddr: image frame buffer physical addresses
269 * @dma_offset: DMA offset in bytes 268 * @dma_offset: DMA offset in bytes
270 * @fmt: fimc color format pointer 269 * @fmt: fimc color format pointer
@@ -279,6 +278,7 @@ struct fimc_frame {
279 u32 width; 278 u32 width;
280 u32 height; 279 u32 height;
281 unsigned int payload[VIDEO_MAX_PLANES]; 280 unsigned int payload[VIDEO_MAX_PLANES];
281 unsigned int bytesperline[VIDEO_MAX_PLANES];
282 struct fimc_addr paddr; 282 struct fimc_addr paddr;
283 struct fimc_dma_offset dma_offset; 283 struct fimc_dma_offset dma_offset;
284 struct fimc_fmt *fmt; 284 struct fimc_fmt *fmt;
@@ -372,6 +372,7 @@ struct fimc_pix_limit {
372 * @has_mainscaler_ext: 1 if extended mainscaler ratios in CIEXTEN register 372 * @has_mainscaler_ext: 1 if extended mainscaler ratios in CIEXTEN register
373 * are present in this IP revision 373 * are present in this IP revision
374 * @has_cam_if: set if this instance has a camera input interface 374 * @has_cam_if: set if this instance has a camera input interface
375 * @has_isp_wb: set if this instance has ISP writeback input
375 * @pix_limit: pixel size constraints for the scaler 376 * @pix_limit: pixel size constraints for the scaler
376 * @min_inp_pixsize: minimum input pixel size 377 * @min_inp_pixsize: minimum input pixel size
377 * @min_out_pixsize: minimum output pixel size 378 * @min_out_pixsize: minimum output pixel size
@@ -386,8 +387,9 @@ struct fimc_variant {
386 unsigned int has_cistatus2:1; 387 unsigned int has_cistatus2:1;
387 unsigned int has_mainscaler_ext:1; 388 unsigned int has_mainscaler_ext:1;
388 unsigned int has_cam_if:1; 389 unsigned int has_cam_if:1;
390 unsigned int has_isp_wb:1;
389 unsigned int has_alpha:1; 391 unsigned int has_alpha:1;
390 struct fimc_pix_limit *pix_limit; 392 const struct fimc_pix_limit *pix_limit;
391 u16 min_inp_pixsize; 393 u16 min_inp_pixsize;
392 u16 min_out_pixsize; 394 u16 min_out_pixsize;
393 u16 hor_offs_align; 395 u16 hor_offs_align;
@@ -402,7 +404,7 @@ struct fimc_variant {
402 * @lclk_frequency: local bus clock frequency 404 * @lclk_frequency: local bus clock frequency
403 */ 405 */
404struct fimc_drvdata { 406struct fimc_drvdata {
405 struct fimc_variant *variant[FIMC_MAX_DEVS]; 407 const struct fimc_variant *variant[FIMC_MAX_DEVS];
406 int num_entities; 408 int num_entities;
407 unsigned long lclk_frequency; 409 unsigned long lclk_frequency;
408}; 410};
@@ -435,7 +437,7 @@ struct fimc_dev {
435 struct mutex lock; 437 struct mutex lock;
436 struct platform_device *pdev; 438 struct platform_device *pdev;
437 struct s5p_platform_fimc *pdata; 439 struct s5p_platform_fimc *pdata;
438 struct fimc_variant *variant; 440 const struct fimc_variant *variant;
439 u16 id; 441 u16 id;
440 struct clk *clock[MAX_FIMC_CLOCKS]; 442 struct clk *clock[MAX_FIMC_CLOCKS];
441 void __iomem *regs; 443 void __iomem *regs;
@@ -635,7 +637,7 @@ int fimc_ctrls_create(struct fimc_ctx *ctx);
635void fimc_ctrls_delete(struct fimc_ctx *ctx); 637void fimc_ctrls_delete(struct fimc_ctx *ctx);
636void fimc_ctrls_activate(struct fimc_ctx *ctx, bool active); 638void fimc_ctrls_activate(struct fimc_ctx *ctx, bool active);
637void fimc_alpha_ctrl_update(struct fimc_ctx *ctx); 639void fimc_alpha_ctrl_update(struct fimc_ctx *ctx);
638int fimc_fill_format(struct fimc_frame *frame, struct v4l2_format *f); 640void __fimc_get_format(struct fimc_frame *frame, struct v4l2_format *f);
639void fimc_adjust_mplane_format(struct fimc_fmt *fmt, u32 width, u32 height, 641void fimc_adjust_mplane_format(struct fimc_fmt *fmt, u32 width, u32 height,
640 struct v4l2_pix_format_mplane *pix); 642 struct v4l2_pix_format_mplane *pix);
641struct fimc_fmt *fimc_find_format(const u32 *pixelformat, const u32 *mbus_code, 643struct fimc_fmt *fimc_find_format(const u32 *pixelformat, const u32 *mbus_code,
@@ -650,7 +652,6 @@ int fimc_prepare_addr(struct fimc_ctx *ctx, struct vb2_buffer *vb,
650 struct fimc_frame *frame, struct fimc_addr *paddr); 652 struct fimc_frame *frame, struct fimc_addr *paddr);
651void fimc_prepare_dma_offset(struct fimc_ctx *ctx, struct fimc_frame *f); 653void fimc_prepare_dma_offset(struct fimc_ctx *ctx, struct fimc_frame *f);
652void fimc_set_yuv_order(struct fimc_ctx *ctx); 654void fimc_set_yuv_order(struct fimc_ctx *ctx);
653void fimc_fill_frame(struct fimc_frame *frame, struct v4l2_format *f);
654void fimc_capture_irq_handler(struct fimc_dev *fimc, int deq_buf); 655void fimc_capture_irq_handler(struct fimc_dev *fimc, int deq_buf);
655 656
656int fimc_register_m2m_device(struct fimc_dev *fimc, 657int fimc_register_m2m_device(struct fimc_dev *fimc,
diff --git a/drivers/media/platform/s5p-fimc/fimc-lite-reg.c b/drivers/media/platform/s5p-fimc/fimc-lite-reg.c
index a22d7eb05c82..f0af0754a7b4 100644
--- a/drivers/media/platform/s5p-fimc/fimc-lite-reg.c
+++ b/drivers/media/platform/s5p-fimc/fimc-lite-reg.c
@@ -65,7 +65,7 @@ void flite_hw_set_interrupt_mask(struct fimc_lite *dev)
65 u32 cfg, intsrc; 65 u32 cfg, intsrc;
66 66
67 /* Select interrupts to be enabled for each output mode */ 67 /* Select interrupts to be enabled for each output mode */
68 if (dev->out_path == FIMC_IO_DMA) { 68 if (atomic_read(&dev->out_path) == FIMC_IO_DMA) {
69 intsrc = FLITE_REG_CIGCTRL_IRQ_OVFEN | 69 intsrc = FLITE_REG_CIGCTRL_IRQ_OVFEN |
70 FLITE_REG_CIGCTRL_IRQ_LASTEN | 70 FLITE_REG_CIGCTRL_IRQ_LASTEN |
71 FLITE_REG_CIGCTRL_IRQ_STARTEN; 71 FLITE_REG_CIGCTRL_IRQ_STARTEN;
@@ -187,12 +187,12 @@ static void flite_hw_set_camera_port(struct fimc_lite *dev, int id)
187 187
188/* Select serial or parallel bus, camera port (A,B) and set signals polarity */ 188/* Select serial or parallel bus, camera port (A,B) and set signals polarity */
189void flite_hw_set_camera_bus(struct fimc_lite *dev, 189void flite_hw_set_camera_bus(struct fimc_lite *dev,
190 struct s5p_fimc_isp_info *s_info) 190 struct fimc_source_info *si)
191{ 191{
192 u32 cfg = readl(dev->regs + FLITE_REG_CIGCTRL); 192 u32 cfg = readl(dev->regs + FLITE_REG_CIGCTRL);
193 unsigned int flags = s_info->flags; 193 unsigned int flags = si->flags;
194 194
195 if (s_info->bus_type != FIMC_MIPI_CSI2) { 195 if (si->sensor_bus_type != FIMC_BUS_TYPE_MIPI_CSI2) {
196 cfg &= ~(FLITE_REG_CIGCTRL_SELCAM_MIPI | 196 cfg &= ~(FLITE_REG_CIGCTRL_SELCAM_MIPI |
197 FLITE_REG_CIGCTRL_INVPOLPCLK | 197 FLITE_REG_CIGCTRL_INVPOLPCLK |
198 FLITE_REG_CIGCTRL_INVPOLVSYNC | 198 FLITE_REG_CIGCTRL_INVPOLVSYNC |
@@ -212,7 +212,7 @@ void flite_hw_set_camera_bus(struct fimc_lite *dev,
212 212
213 writel(cfg, dev->regs + FLITE_REG_CIGCTRL); 213 writel(cfg, dev->regs + FLITE_REG_CIGCTRL);
214 214
215 flite_hw_set_camera_port(dev, s_info->mux_id); 215 flite_hw_set_camera_port(dev, si->mux_id);
216} 216}
217 217
218static void flite_hw_set_out_order(struct fimc_lite *dev, struct flite_frame *f) 218static void flite_hw_set_out_order(struct fimc_lite *dev, struct flite_frame *f)
@@ -292,9 +292,11 @@ void flite_hw_dump_regs(struct fimc_lite *dev, const char *label)
292 }; 292 };
293 u32 i; 293 u32 i;
294 294
295 pr_info("--- %s ---\n", label); 295 v4l2_info(&dev->subdev, "--- %s ---\n", label);
296
296 for (i = 0; i < ARRAY_SIZE(registers); i++) { 297 for (i = 0; i < ARRAY_SIZE(registers); i++) {
297 u32 cfg = readl(dev->regs + registers[i].offset); 298 u32 cfg = readl(dev->regs + registers[i].offset);
298 pr_info("%s: %s:\t0x%08x\n", __func__, registers[i].name, cfg); 299 v4l2_info(&dev->subdev, "%9s: 0x%08x\n",
300 registers[i].name, cfg);
299 } 301 }
300} 302}
diff --git a/drivers/media/platform/s5p-fimc/fimc-lite-reg.h b/drivers/media/platform/s5p-fimc/fimc-lite-reg.h
index adb9e9e6f3c2..0e345844c13a 100644
--- a/drivers/media/platform/s5p-fimc/fimc-lite-reg.h
+++ b/drivers/media/platform/s5p-fimc/fimc-lite-reg.h
@@ -131,9 +131,9 @@ void flite_hw_set_interrupt_mask(struct fimc_lite *dev);
131void flite_hw_capture_start(struct fimc_lite *dev); 131void flite_hw_capture_start(struct fimc_lite *dev);
132void flite_hw_capture_stop(struct fimc_lite *dev); 132void flite_hw_capture_stop(struct fimc_lite *dev);
133void flite_hw_set_camera_bus(struct fimc_lite *dev, 133void flite_hw_set_camera_bus(struct fimc_lite *dev,
134 struct s5p_fimc_isp_info *s_info); 134 struct fimc_source_info *s_info);
135void flite_hw_set_camera_polarity(struct fimc_lite *dev, 135void flite_hw_set_camera_polarity(struct fimc_lite *dev,
136 struct s5p_fimc_isp_info *cam); 136 struct fimc_source_info *cam);
137void flite_hw_set_window_offset(struct fimc_lite *dev, struct flite_frame *f); 137void flite_hw_set_window_offset(struct fimc_lite *dev, struct flite_frame *f);
138void flite_hw_set_source_format(struct fimc_lite *dev, struct flite_frame *f); 138void flite_hw_set_source_format(struct fimc_lite *dev, struct flite_frame *f);
139 139
diff --git a/drivers/media/platform/s5p-fimc/fimc-lite.c b/drivers/media/platform/s5p-fimc/fimc-lite.c
index 67db9f8102e4..bfc4206935c8 100644
--- a/drivers/media/platform/s5p-fimc/fimc-lite.c
+++ b/drivers/media/platform/s5p-fimc/fimc-lite.c
@@ -120,25 +120,29 @@ static const struct fimc_fmt *fimc_lite_find_format(const u32 *pixelformat,
120 return def_fmt; 120 return def_fmt;
121} 121}
122 122
123static int fimc_lite_hw_init(struct fimc_lite *fimc) 123static int fimc_lite_hw_init(struct fimc_lite *fimc, bool isp_output)
124{ 124{
125 struct fimc_pipeline *pipeline = &fimc->pipeline; 125 struct fimc_pipeline *pipeline = &fimc->pipeline;
126 struct fimc_sensor_info *sensor; 126 struct v4l2_subdev *sensor;
127 struct fimc_sensor_info *si;
127 unsigned long flags; 128 unsigned long flags;
128 129
129 if (pipeline->subdevs[IDX_SENSOR] == NULL) 130 sensor = isp_output ? fimc->sensor : pipeline->subdevs[IDX_SENSOR];
131
132 if (sensor == NULL)
130 return -ENXIO; 133 return -ENXIO;
131 134
132 if (fimc->fmt == NULL) 135 if (fimc->fmt == NULL)
133 return -EINVAL; 136 return -EINVAL;
134 137
135 sensor = v4l2_get_subdev_hostdata(pipeline->subdevs[IDX_SENSOR]); 138 /* Get sensor configuration data from the sensor subdev */
139 si = v4l2_get_subdev_hostdata(sensor);
136 spin_lock_irqsave(&fimc->slock, flags); 140 spin_lock_irqsave(&fimc->slock, flags);
137 141
138 flite_hw_set_camera_bus(fimc, &sensor->pdata); 142 flite_hw_set_camera_bus(fimc, &si->pdata);
139 flite_hw_set_source_format(fimc, &fimc->inp_frame); 143 flite_hw_set_source_format(fimc, &fimc->inp_frame);
140 flite_hw_set_window_offset(fimc, &fimc->inp_frame); 144 flite_hw_set_window_offset(fimc, &fimc->inp_frame);
141 flite_hw_set_output_dma(fimc, &fimc->out_frame, true); 145 flite_hw_set_output_dma(fimc, &fimc->out_frame, !isp_output);
142 flite_hw_set_interrupt_mask(fimc); 146 flite_hw_set_interrupt_mask(fimc);
143 flite_hw_set_test_pattern(fimc, fimc->test_pattern->val); 147 flite_hw_set_test_pattern(fimc, fimc->test_pattern->val);
144 148
@@ -256,7 +260,7 @@ static irqreturn_t flite_irq_handler(int irq, void *priv)
256 wake_up(&fimc->irq_queue); 260 wake_up(&fimc->irq_queue);
257 } 261 }
258 262
259 if (fimc->out_path != FIMC_IO_DMA) 263 if (atomic_read(&fimc->out_path) != FIMC_IO_DMA)
260 goto done; 264 goto done;
261 265
262 if ((intsrc & FLITE_REG_CISTATUS_IRQ_SRC_FRMSTART) && 266 if ((intsrc & FLITE_REG_CISTATUS_IRQ_SRC_FRMSTART) &&
@@ -296,7 +300,7 @@ static int start_streaming(struct vb2_queue *q, unsigned int count)
296 300
297 fimc->frame_count = 0; 301 fimc->frame_count = 0;
298 302
299 ret = fimc_lite_hw_init(fimc); 303 ret = fimc_lite_hw_init(fimc, false);
300 if (ret) { 304 if (ret) {
301 fimc_lite_reinit(fimc, false); 305 fimc_lite_reinit(fimc, false);
302 return ret; 306 return ret;
@@ -455,10 +459,16 @@ static void fimc_lite_clear_event_counters(struct fimc_lite *fimc)
455static int fimc_lite_open(struct file *file) 459static int fimc_lite_open(struct file *file)
456{ 460{
457 struct fimc_lite *fimc = video_drvdata(file); 461 struct fimc_lite *fimc = video_drvdata(file);
462 struct media_entity *me = &fimc->vfd.entity;
458 int ret; 463 int ret;
459 464
460 if (mutex_lock_interruptible(&fimc->lock)) 465 mutex_lock(&me->parent->graph_mutex);
461 return -ERESTARTSYS; 466
467 mutex_lock(&fimc->lock);
468 if (atomic_read(&fimc->out_path) != FIMC_IO_DMA) {
469 ret = -EBUSY;
470 goto done;
471 }
462 472
463 set_bit(ST_FLITE_IN_USE, &fimc->state); 473 set_bit(ST_FLITE_IN_USE, &fimc->state);
464 ret = pm_runtime_get_sync(&fimc->pdev->dev); 474 ret = pm_runtime_get_sync(&fimc->pdev->dev);
@@ -469,7 +479,8 @@ static int fimc_lite_open(struct file *file)
469 if (ret < 0) 479 if (ret < 0)
470 goto done; 480 goto done;
471 481
472 if (++fimc->ref_count == 1 && fimc->out_path == FIMC_IO_DMA) { 482 if (++fimc->ref_count == 1 &&
483 atomic_read(&fimc->out_path) == FIMC_IO_DMA) {
473 ret = fimc_pipeline_call(fimc, open, &fimc->pipeline, 484 ret = fimc_pipeline_call(fimc, open, &fimc->pipeline,
474 &fimc->vfd.entity, true); 485 &fimc->vfd.entity, true);
475 if (ret < 0) { 486 if (ret < 0) {
@@ -483,6 +494,7 @@ static int fimc_lite_open(struct file *file)
483 } 494 }
484done: 495done:
485 mutex_unlock(&fimc->lock); 496 mutex_unlock(&fimc->lock);
497 mutex_unlock(&me->parent->graph_mutex);
486 return ret; 498 return ret;
487} 499}
488 500
@@ -493,7 +505,8 @@ static int fimc_lite_close(struct file *file)
493 505
494 mutex_lock(&fimc->lock); 506 mutex_lock(&fimc->lock);
495 507
496 if (--fimc->ref_count == 0 && fimc->out_path == FIMC_IO_DMA) { 508 if (--fimc->ref_count == 0 &&
509 atomic_read(&fimc->out_path) == FIMC_IO_DMA) {
497 clear_bit(ST_FLITE_IN_USE, &fimc->state); 510 clear_bit(ST_FLITE_IN_USE, &fimc->state);
498 fimc_lite_stop_capture(fimc, false); 511 fimc_lite_stop_capture(fimc, false);
499 fimc_pipeline_call(fimc, close, &fimc->pipeline); 512 fimc_pipeline_call(fimc, close, &fimc->pipeline);
@@ -598,7 +611,7 @@ static void fimc_lite_try_crop(struct fimc_lite *fimc, struct v4l2_rect *r)
598 r->left = round_down(r->left, fimc->variant->win_hor_offs_align); 611 r->left = round_down(r->left, fimc->variant->win_hor_offs_align);
599 r->top = clamp_t(u32, r->top, 0, frame->f_height - r->height); 612 r->top = clamp_t(u32, r->top, 0, frame->f_height - r->height);
600 613
601 v4l2_dbg(1, debug, &fimc->subdev, "(%d,%d)/%dx%d, sink fmt: %dx%d", 614 v4l2_dbg(1, debug, &fimc->subdev, "(%d,%d)/%dx%d, sink fmt: %dx%d\n",
602 r->left, r->top, r->width, r->height, 615 r->left, r->top, r->width, r->height,
603 frame->f_width, frame->f_height); 616 frame->f_width, frame->f_height);
604} 617}
@@ -618,7 +631,7 @@ static void fimc_lite_try_compose(struct fimc_lite *fimc, struct v4l2_rect *r)
618 r->left = round_down(r->left, fimc->variant->out_hor_offs_align); 631 r->left = round_down(r->left, fimc->variant->out_hor_offs_align);
619 r->top = clamp_t(u32, r->top, 0, fimc->out_frame.f_height - r->height); 632 r->top = clamp_t(u32, r->top, 0, fimc->out_frame.f_height - r->height);
620 633
621 v4l2_dbg(1, debug, &fimc->subdev, "(%d,%d)/%dx%d, source fmt: %dx%d", 634 v4l2_dbg(1, debug, &fimc->subdev, "(%d,%d)/%dx%d, source fmt: %dx%d\n",
622 r->left, r->top, r->width, r->height, 635 r->left, r->top, r->width, r->height,
623 frame->f_width, frame->f_height); 636 frame->f_width, frame->f_height);
624} 637}
@@ -962,6 +975,29 @@ static const struct v4l2_ioctl_ops fimc_lite_ioctl_ops = {
962 .vidioc_streamoff = fimc_lite_streamoff, 975 .vidioc_streamoff = fimc_lite_streamoff,
963}; 976};
964 977
978/* Called with the media graph mutex held */
979static struct v4l2_subdev *__find_remote_sensor(struct media_entity *me)
980{
981 struct media_pad *pad = &me->pads[0];
982 struct v4l2_subdev *sd;
983
984 while (pad->flags & MEDIA_PAD_FL_SINK) {
985 /* source pad */
986 pad = media_entity_remote_source(pad);
987 if (pad == NULL ||
988 media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
989 break;
990
991 sd = media_entity_to_v4l2_subdev(pad->entity);
992
993 if (sd->grp_id == GRP_ID_FIMC_IS_SENSOR)
994 return sd;
995 /* sink pad */
996 pad = &sd->entity.pads[0];
997 }
998 return NULL;
999}
1000
965/* Capture subdev media entity operations */ 1001/* Capture subdev media entity operations */
966static int fimc_lite_link_setup(struct media_entity *entity, 1002static int fimc_lite_link_setup(struct media_entity *entity,
967 const struct media_pad *local, 1003 const struct media_pad *local,
@@ -970,46 +1006,60 @@ static int fimc_lite_link_setup(struct media_entity *entity,
970 struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity); 1006 struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
971 struct fimc_lite *fimc = v4l2_get_subdevdata(sd); 1007 struct fimc_lite *fimc = v4l2_get_subdevdata(sd);
972 unsigned int remote_ent_type = media_entity_type(remote->entity); 1008 unsigned int remote_ent_type = media_entity_type(remote->entity);
1009 int ret = 0;
973 1010
974 if (WARN_ON(fimc == NULL)) 1011 if (WARN_ON(fimc == NULL))
975 return 0; 1012 return 0;
976 1013
977 v4l2_dbg(1, debug, sd, "%s: %s --> %s, flags: 0x%x. source_id: 0x%x", 1014 v4l2_dbg(1, debug, sd, "%s: %s --> %s, flags: 0x%x. source_id: 0x%x\n",
978 __func__, local->entity->name, remote->entity->name, 1015 __func__, remote->entity->name, local->entity->name,
979 flags, fimc->source_subdev_grp_id); 1016 flags, fimc->source_subdev_grp_id);
980 1017
981 switch (local->index) { 1018 mutex_lock(&fimc->lock);
982 case FIMC_SD_PAD_SINK:
983 if (remote_ent_type != MEDIA_ENT_T_V4L2_SUBDEV)
984 return -EINVAL;
985 1019
1020 switch (local->index) {
1021 case FLITE_SD_PAD_SINK:
1022 if (remote_ent_type != MEDIA_ENT_T_V4L2_SUBDEV) {
1023 ret = -EINVAL;
1024 break;
1025 }
986 if (flags & MEDIA_LNK_FL_ENABLED) { 1026 if (flags & MEDIA_LNK_FL_ENABLED) {
987 if (fimc->source_subdev_grp_id != 0) 1027 if (fimc->source_subdev_grp_id == 0)
988 return -EBUSY; 1028 fimc->source_subdev_grp_id = sd->grp_id;
989 fimc->source_subdev_grp_id = sd->grp_id; 1029 else
990 return 0; 1030 ret = -EBUSY;
1031 } else {
1032 fimc->source_subdev_grp_id = 0;
1033 fimc->sensor = NULL;
991 } 1034 }
1035 break;
992 1036
993 fimc->source_subdev_grp_id = 0; 1037 case FLITE_SD_PAD_SOURCE_DMA:
1038 if (!(flags & MEDIA_LNK_FL_ENABLED))
1039 atomic_set(&fimc->out_path, FIMC_IO_NONE);
1040 else if (remote_ent_type == MEDIA_ENT_T_DEVNODE)
1041 atomic_set(&fimc->out_path, FIMC_IO_DMA);
1042 else
1043 ret = -EINVAL;
994 break; 1044 break;
995 1045
996 case FIMC_SD_PAD_SOURCE: 1046 case FLITE_SD_PAD_SOURCE_ISP:
997 if (!(flags & MEDIA_LNK_FL_ENABLED)) { 1047 if (!(flags & MEDIA_LNK_FL_ENABLED))
998 fimc->out_path = FIMC_IO_NONE; 1048 atomic_set(&fimc->out_path, FIMC_IO_NONE);
999 return 0; 1049 else if (remote_ent_type == MEDIA_ENT_T_V4L2_SUBDEV)
1000 } 1050 atomic_set(&fimc->out_path, FIMC_IO_ISP);
1001 if (remote_ent_type == MEDIA_ENT_T_V4L2_SUBDEV)
1002 fimc->out_path = FIMC_IO_ISP;
1003 else 1051 else
1004 fimc->out_path = FIMC_IO_DMA; 1052 ret = -EINVAL;
1005 break; 1053 break;
1006 1054
1007 default: 1055 default:
1008 v4l2_err(sd, "Invalid pad index\n"); 1056 v4l2_err(sd, "Invalid pad index\n");
1009 return -EINVAL; 1057 ret = -EINVAL;
1010 } 1058 }
1059 mb();
1011 1060
1012 return 0; 1061 mutex_unlock(&fimc->lock);
1062 return ret;
1013} 1063}
1014 1064
1015static const struct media_entity_operations fimc_lite_subdev_media_ops = { 1065static const struct media_entity_operations fimc_lite_subdev_media_ops = {
@@ -1070,14 +1120,16 @@ static int fimc_lite_subdev_set_fmt(struct v4l2_subdev *sd,
1070 struct flite_frame *source = &fimc->out_frame; 1120 struct flite_frame *source = &fimc->out_frame;
1071 const struct fimc_fmt *ffmt; 1121 const struct fimc_fmt *ffmt;
1072 1122
1073 v4l2_dbg(1, debug, sd, "pad%d: code: 0x%x, %dx%d", 1123 v4l2_dbg(1, debug, sd, "pad%d: code: 0x%x, %dx%d\n",
1074 fmt->pad, mf->code, mf->width, mf->height); 1124 fmt->pad, mf->code, mf->width, mf->height);
1075 1125
1076 mf->colorspace = V4L2_COLORSPACE_JPEG; 1126 mf->colorspace = V4L2_COLORSPACE_JPEG;
1077 mutex_lock(&fimc->lock); 1127 mutex_lock(&fimc->lock);
1078 1128
1079 if ((fimc->out_path == FIMC_IO_ISP && sd->entity.stream_count > 0) || 1129 if ((atomic_read(&fimc->out_path) == FIMC_IO_ISP &&
1080 (fimc->out_path == FIMC_IO_DMA && vb2_is_busy(&fimc->vb_queue))) { 1130 sd->entity.stream_count > 0) ||
1131 (atomic_read(&fimc->out_path) == FIMC_IO_DMA &&
1132 vb2_is_busy(&fimc->vb_queue))) {
1081 mutex_unlock(&fimc->lock); 1133 mutex_unlock(&fimc->lock);
1082 return -EBUSY; 1134 return -EBUSY;
1083 } 1135 }
@@ -1144,7 +1196,7 @@ static int fimc_lite_subdev_get_selection(struct v4l2_subdev *sd,
1144 } 1196 }
1145 mutex_unlock(&fimc->lock); 1197 mutex_unlock(&fimc->lock);
1146 1198
1147 v4l2_dbg(1, debug, sd, "%s: (%d,%d) %dx%d, f_w: %d, f_h: %d", 1199 v4l2_dbg(1, debug, sd, "%s: (%d,%d) %dx%d, f_w: %d, f_h: %d\n",
1148 __func__, f->rect.left, f->rect.top, f->rect.width, 1200 __func__, f->rect.left, f->rect.top, f->rect.width,
1149 f->rect.height, f->f_width, f->f_height); 1201 f->rect.height, f->f_width, f->f_height);
1150 1202
@@ -1178,7 +1230,7 @@ static int fimc_lite_subdev_set_selection(struct v4l2_subdev *sd,
1178 } 1230 }
1179 mutex_unlock(&fimc->lock); 1231 mutex_unlock(&fimc->lock);
1180 1232
1181 v4l2_dbg(1, debug, sd, "%s: (%d,%d) %dx%d, f_w: %d, f_h: %d", 1233 v4l2_dbg(1, debug, sd, "%s: (%d,%d) %dx%d, f_w: %d, f_h: %d\n",
1182 __func__, f->rect.left, f->rect.top, f->rect.width, 1234 __func__, f->rect.left, f->rect.top, f->rect.width,
1183 f->rect.height, f->f_width, f->f_height); 1235 f->rect.height, f->f_width, f->f_height);
1184 1236
@@ -1188,25 +1240,47 @@ static int fimc_lite_subdev_set_selection(struct v4l2_subdev *sd,
1188static int fimc_lite_subdev_s_stream(struct v4l2_subdev *sd, int on) 1240static int fimc_lite_subdev_s_stream(struct v4l2_subdev *sd, int on)
1189{ 1241{
1190 struct fimc_lite *fimc = v4l2_get_subdevdata(sd); 1242 struct fimc_lite *fimc = v4l2_get_subdevdata(sd);
1243 unsigned long flags;
1244 int ret;
1191 1245
1192 if (fimc->out_path == FIMC_IO_DMA) 1246 /*
1193 return -ENOIOCTLCMD; 1247 * Find sensor subdev linked to FIMC-LITE directly or through
1194 1248 * MIPI-CSIS. This is required for configuration where FIMC-LITE
1195 /* TODO: */ 1249 * is used as a subdev only and feeds data internally to FIMC-IS.
1250 * The pipeline links are protected through entity.stream_count
1251 * so there is no need to take the media graph mutex here.
1252 */
1253 fimc->sensor = __find_remote_sensor(&sd->entity);
1196 1254
1197 return 0; 1255 if (atomic_read(&fimc->out_path) != FIMC_IO_ISP)
1198} 1256 return -ENOIOCTLCMD;
1199 1257
1200static int fimc_lite_subdev_s_power(struct v4l2_subdev *sd, int on) 1258 mutex_lock(&fimc->lock);
1201{ 1259 if (on) {
1202 struct fimc_lite *fimc = v4l2_get_subdevdata(sd); 1260 flite_hw_reset(fimc);
1261 ret = fimc_lite_hw_init(fimc, true);
1262 if (!ret) {
1263 spin_lock_irqsave(&fimc->slock, flags);
1264 flite_hw_capture_start(fimc);
1265 spin_unlock_irqrestore(&fimc->slock, flags);
1266 }
1267 } else {
1268 set_bit(ST_FLITE_OFF, &fimc->state);
1203 1269
1204 if (fimc->out_path == FIMC_IO_DMA) 1270 spin_lock_irqsave(&fimc->slock, flags);
1205 return -ENOIOCTLCMD; 1271 flite_hw_capture_stop(fimc);
1272 spin_unlock_irqrestore(&fimc->slock, flags);
1206 1273
1207 /* TODO: */ 1274 ret = wait_event_timeout(fimc->irq_queue,
1275 !test_bit(ST_FLITE_OFF, &fimc->state),
1276 msecs_to_jiffies(200));
1277 if (ret == 0)
1278 v4l2_err(sd, "s_stream(0) timeout\n");
1279 clear_bit(ST_FLITE_RUN, &fimc->state);
1280 }
1208 1281
1209 return 0; 1282 mutex_unlock(&fimc->lock);
1283 return ret;
1210} 1284}
1211 1285
1212static int fimc_lite_log_status(struct v4l2_subdev *sd) 1286static int fimc_lite_log_status(struct v4l2_subdev *sd)
@@ -1227,7 +1301,7 @@ static int fimc_lite_subdev_registered(struct v4l2_subdev *sd)
1227 memset(vfd, 0, sizeof(*vfd)); 1301 memset(vfd, 0, sizeof(*vfd));
1228 1302
1229 fimc->fmt = &fimc_lite_formats[0]; 1303 fimc->fmt = &fimc_lite_formats[0];
1230 fimc->out_path = FIMC_IO_DMA; 1304 atomic_set(&fimc->out_path, FIMC_IO_DMA);
1231 1305
1232 snprintf(vfd->name, sizeof(vfd->name), "fimc-lite.%d.capture", 1306 snprintf(vfd->name, sizeof(vfd->name), "fimc-lite.%d.capture",
1233 fimc->index); 1307 fimc->index);
@@ -1308,7 +1382,6 @@ static const struct v4l2_subdev_video_ops fimc_lite_subdev_video_ops = {
1308}; 1382};
1309 1383
1310static const struct v4l2_subdev_core_ops fimc_lite_core_ops = { 1384static const struct v4l2_subdev_core_ops fimc_lite_core_ops = {
1311 .s_power = fimc_lite_subdev_s_power,
1312 .log_status = fimc_lite_log_status, 1385 .log_status = fimc_lite_log_status,
1313}; 1386};
1314 1387
@@ -1347,9 +1420,10 @@ static int fimc_lite_create_capture_subdev(struct fimc_lite *fimc)
1347 sd->flags = V4L2_SUBDEV_FL_HAS_DEVNODE; 1420 sd->flags = V4L2_SUBDEV_FL_HAS_DEVNODE;
1348 snprintf(sd->name, sizeof(sd->name), "FIMC-LITE.%d", fimc->index); 1421 snprintf(sd->name, sizeof(sd->name), "FIMC-LITE.%d", fimc->index);
1349 1422
1350 fimc->subdev_pads[FIMC_SD_PAD_SINK].flags = MEDIA_PAD_FL_SINK; 1423 fimc->subdev_pads[FLITE_SD_PAD_SINK].flags = MEDIA_PAD_FL_SINK;
1351 fimc->subdev_pads[FIMC_SD_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE; 1424 fimc->subdev_pads[FLITE_SD_PAD_SOURCE_DMA].flags = MEDIA_PAD_FL_SOURCE;
1352 ret = media_entity_init(&sd->entity, FIMC_SD_PADS_NUM, 1425 fimc->subdev_pads[FLITE_SD_PAD_SOURCE_ISP].flags = MEDIA_PAD_FL_SOURCE;
1426 ret = media_entity_init(&sd->entity, FLITE_SD_PADS_NUM,
1353 fimc->subdev_pads, 0); 1427 fimc->subdev_pads, 0);
1354 if (ret) 1428 if (ret)
1355 return ret; 1429 return ret;
@@ -1516,7 +1590,7 @@ static int fimc_lite_resume(struct device *dev)
1516 INIT_LIST_HEAD(&fimc->active_buf_q); 1590 INIT_LIST_HEAD(&fimc->active_buf_q);
1517 fimc_pipeline_call(fimc, open, &fimc->pipeline, 1591 fimc_pipeline_call(fimc, open, &fimc->pipeline,
1518 &fimc->vfd.entity, false); 1592 &fimc->vfd.entity, false);
1519 fimc_lite_hw_init(fimc); 1593 fimc_lite_hw_init(fimc, atomic_read(&fimc->out_path) == FIMC_IO_ISP);
1520 clear_bit(ST_FLITE_SUSPENDED, &fimc->state); 1594 clear_bit(ST_FLITE_SUSPENDED, &fimc->state);
1521 1595
1522 for (i = 0; i < fimc->reqbufs_count; i++) { 1596 for (i = 0; i < fimc->reqbufs_count; i++) {
diff --git a/drivers/media/platform/s5p-fimc/fimc-lite.h b/drivers/media/platform/s5p-fimc/fimc-lite.h
index 3081db35c5b0..7085761f8c4b 100644
--- a/drivers/media/platform/s5p-fimc/fimc-lite.h
+++ b/drivers/media/platform/s5p-fimc/fimc-lite.h
@@ -45,8 +45,9 @@ enum {
45}; 45};
46 46
47#define FLITE_SD_PAD_SINK 0 47#define FLITE_SD_PAD_SINK 0
48#define FLITE_SD_PAD_SOURCE 1 48#define FLITE_SD_PAD_SOURCE_DMA 1
49#define FLITE_SD_PADS_NUM 2 49#define FLITE_SD_PAD_SOURCE_ISP 2
50#define FLITE_SD_PADS_NUM 3
50 51
51struct flite_variant { 52struct flite_variant {
52 unsigned short max_width; 53 unsigned short max_width;
@@ -104,6 +105,7 @@ struct flite_buffer {
104 * @subdev: FIMC-LITE subdev 105 * @subdev: FIMC-LITE subdev
105 * @vd_pad: media (sink) pad for the capture video node 106 * @vd_pad: media (sink) pad for the capture video node
106 * @subdev_pads: the subdev media pads 107 * @subdev_pads: the subdev media pads
108 * @sensor: sensor subdev attached to FIMC-LITE directly or through MIPI-CSIS
107 * @ctrl_handler: v4l2 control handler 109 * @ctrl_handler: v4l2 control handler
108 * @test_pattern: test pattern controls 110 * @test_pattern: test pattern controls
109 * @index: FIMC-LITE platform device index 111 * @index: FIMC-LITE platform device index
@@ -139,6 +141,7 @@ struct fimc_lite {
139 struct v4l2_subdev subdev; 141 struct v4l2_subdev subdev;
140 struct media_pad vd_pad; 142 struct media_pad vd_pad;
141 struct media_pad subdev_pads[FLITE_SD_PADS_NUM]; 143 struct media_pad subdev_pads[FLITE_SD_PADS_NUM];
144 struct v4l2_subdev *sensor;
142 struct v4l2_ctrl_handler ctrl_handler; 145 struct v4l2_ctrl_handler ctrl_handler;
143 struct v4l2_ctrl *test_pattern; 146 struct v4l2_ctrl *test_pattern;
144 u32 index; 147 u32 index;
@@ -156,7 +159,7 @@ struct fimc_lite {
156 unsigned long payload[FLITE_MAX_PLANES]; 159 unsigned long payload[FLITE_MAX_PLANES];
157 struct flite_frame inp_frame; 160 struct flite_frame inp_frame;
158 struct flite_frame out_frame; 161 struct flite_frame out_frame;
159 enum fimc_datapath out_path; 162 atomic_t out_path;
160 unsigned int source_subdev_grp_id; 163 unsigned int source_subdev_grp_id;
161 164
162 unsigned long state; 165 unsigned long state;
diff --git a/drivers/media/platform/s5p-fimc/fimc-m2m.c b/drivers/media/platform/s5p-fimc/fimc-m2m.c
index 1d21da4bd24b..f3d535cdd87f 100644
--- a/drivers/media/platform/s5p-fimc/fimc-m2m.c
+++ b/drivers/media/platform/s5p-fimc/fimc-m2m.c
@@ -1,8 +1,8 @@
1/* 1/*
2 * Samsung S5P/EXYNOS4 SoC series FIMC (video postprocessor) driver 2 * Samsung S5P/EXYNOS4 SoC series FIMC (video postprocessor) 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 * 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
@@ -160,8 +160,7 @@ static void fimc_device_run(void *priv)
160 fimc_hw_set_output_addr(fimc, &df->paddr, -1); 160 fimc_hw_set_output_addr(fimc, &df->paddr, -1);
161 161
162 fimc_activate_capture(ctx); 162 fimc_activate_capture(ctx);
163 ctx->state &= (FIMC_CTX_M2M | FIMC_CTX_CAP | 163 ctx->state &= (FIMC_CTX_M2M | FIMC_CTX_CAP);
164 FIMC_SRC_FMT | FIMC_DST_FMT);
165 fimc_hw_activate_input_dma(fimc, true); 164 fimc_hw_activate_input_dma(fimc, true);
166 165
167dma_unlock: 166dma_unlock:
@@ -294,13 +293,14 @@ static int fimc_m2m_g_fmt_mplane(struct file *file, void *fh,
294 if (IS_ERR(frame)) 293 if (IS_ERR(frame))
295 return PTR_ERR(frame); 294 return PTR_ERR(frame);
296 295
297 return fimc_fill_format(frame, f); 296 __fimc_get_format(frame, f);
297 return 0;
298} 298}
299 299
300static int fimc_try_fmt_mplane(struct fimc_ctx *ctx, struct v4l2_format *f) 300static int fimc_try_fmt_mplane(struct fimc_ctx *ctx, struct v4l2_format *f)
301{ 301{
302 struct fimc_dev *fimc = ctx->fimc_dev; 302 struct fimc_dev *fimc = ctx->fimc_dev;
303 struct fimc_variant *variant = fimc->variant; 303 const struct fimc_variant *variant = fimc->variant;
304 struct v4l2_pix_format_mplane *pix = &f->fmt.pix_mp; 304 struct v4l2_pix_format_mplane *pix = &f->fmt.pix_mp;
305 struct fimc_fmt *fmt; 305 struct fimc_fmt *fmt;
306 u32 max_w, mod_x, mod_y; 306 u32 max_w, mod_x, mod_y;
@@ -308,8 +308,6 @@ static int fimc_try_fmt_mplane(struct fimc_ctx *ctx, struct v4l2_format *f)
308 if (!IS_M2M(f->type)) 308 if (!IS_M2M(f->type))
309 return -EINVAL; 309 return -EINVAL;
310 310
311 dbg("w: %d, h: %d", pix->width, pix->height);
312
313 fmt = fimc_find_format(&pix->pixelformat, NULL, 311 fmt = fimc_find_format(&pix->pixelformat, NULL,
314 get_m2m_fmt_flags(f->type), 0); 312 get_m2m_fmt_flags(f->type), 0);
315 if (WARN(fmt == NULL, "Pixel format lookup failed")) 313 if (WARN(fmt == NULL, "Pixel format lookup failed"))
@@ -349,19 +347,39 @@ static int fimc_m2m_try_fmt_mplane(struct file *file, void *fh,
349 struct v4l2_format *f) 347 struct v4l2_format *f)
350{ 348{
351 struct fimc_ctx *ctx = fh_to_ctx(fh); 349 struct fimc_ctx *ctx = fh_to_ctx(fh);
352
353 return fimc_try_fmt_mplane(ctx, f); 350 return fimc_try_fmt_mplane(ctx, f);
354} 351}
355 352
353static void __set_frame_format(struct fimc_frame *frame, struct fimc_fmt *fmt,
354 struct v4l2_pix_format_mplane *pixm)
355{
356 int i;
357
358 for (i = 0; i < fmt->colplanes; i++) {
359 frame->bytesperline[i] = pixm->plane_fmt[i].bytesperline;
360 frame->payload[i] = pixm->plane_fmt[i].sizeimage;
361 }
362
363 frame->f_width = pixm->width;
364 frame->f_height = pixm->height;
365 frame->o_width = pixm->width;
366 frame->o_height = pixm->height;
367 frame->width = pixm->width;
368 frame->height = pixm->height;
369 frame->offs_h = 0;
370 frame->offs_v = 0;
371 frame->fmt = fmt;
372}
373
356static int fimc_m2m_s_fmt_mplane(struct file *file, void *fh, 374static int fimc_m2m_s_fmt_mplane(struct file *file, void *fh,
357 struct v4l2_format *f) 375 struct v4l2_format *f)
358{ 376{
359 struct fimc_ctx *ctx = fh_to_ctx(fh); 377 struct fimc_ctx *ctx = fh_to_ctx(fh);
360 struct fimc_dev *fimc = ctx->fimc_dev; 378 struct fimc_dev *fimc = ctx->fimc_dev;
379 struct fimc_fmt *fmt;
361 struct vb2_queue *vq; 380 struct vb2_queue *vq;
362 struct fimc_frame *frame; 381 struct fimc_frame *frame;
363 struct v4l2_pix_format_mplane *pix; 382 int ret;
364 int i, ret = 0;
365 383
366 ret = fimc_try_fmt_mplane(ctx, f); 384 ret = fimc_try_fmt_mplane(ctx, f);
367 if (ret) 385 if (ret)
@@ -379,31 +397,16 @@ static int fimc_m2m_s_fmt_mplane(struct file *file, void *fh,
379 else 397 else
380 frame = &ctx->d_frame; 398 frame = &ctx->d_frame;
381 399
382 pix = &f->fmt.pix_mp; 400 fmt = fimc_find_format(&f->fmt.pix_mp.pixelformat, NULL,
383 frame->fmt = fimc_find_format(&pix->pixelformat, NULL, 401 get_m2m_fmt_flags(f->type), 0);
384 get_m2m_fmt_flags(f->type), 0); 402 if (!fmt)
385 if (!frame->fmt)
386 return -EINVAL; 403 return -EINVAL;
387 404
405 __set_frame_format(frame, fmt, &f->fmt.pix_mp);
406
388 /* Update RGB Alpha control state and value range */ 407 /* Update RGB Alpha control state and value range */
389 fimc_alpha_ctrl_update(ctx); 408 fimc_alpha_ctrl_update(ctx);
390 409
391 for (i = 0; i < frame->fmt->colplanes; i++) {
392 frame->payload[i] =
393 (pix->width * pix->height * frame->fmt->depth[i]) / 8;
394 }
395
396 fimc_fill_frame(frame, f);
397
398 ctx->scaler.enabled = 1;
399
400 if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
401 fimc_ctx_state_set(FIMC_PARAMS | FIMC_DST_FMT, ctx);
402 else
403 fimc_ctx_state_set(FIMC_PARAMS | FIMC_SRC_FMT, ctx);
404
405 dbg("f_w: %d, f_h: %d", frame->f_width, frame->f_height);
406
407 return 0; 410 return 0;
408} 411}
409 412
@@ -411,7 +414,6 @@ static int fimc_m2m_reqbufs(struct file *file, void *fh,
411 struct v4l2_requestbuffers *reqbufs) 414 struct v4l2_requestbuffers *reqbufs)
412{ 415{
413 struct fimc_ctx *ctx = fh_to_ctx(fh); 416 struct fimc_ctx *ctx = fh_to_ctx(fh);
414
415 return v4l2_m2m_reqbufs(file, ctx->m2m_ctx, reqbufs); 417 return v4l2_m2m_reqbufs(file, ctx->m2m_ctx, reqbufs);
416} 418}
417 419
@@ -419,7 +421,6 @@ static int fimc_m2m_querybuf(struct file *file, void *fh,
419 struct v4l2_buffer *buf) 421 struct v4l2_buffer *buf)
420{ 422{
421 struct fimc_ctx *ctx = fh_to_ctx(fh); 423 struct fimc_ctx *ctx = fh_to_ctx(fh);
422
423 return v4l2_m2m_querybuf(file, ctx->m2m_ctx, buf); 424 return v4l2_m2m_querybuf(file, ctx->m2m_ctx, buf);
424} 425}
425 426
@@ -427,7 +428,6 @@ static int fimc_m2m_qbuf(struct file *file, void *fh,
427 struct v4l2_buffer *buf) 428 struct v4l2_buffer *buf)
428{ 429{
429 struct fimc_ctx *ctx = fh_to_ctx(fh); 430 struct fimc_ctx *ctx = fh_to_ctx(fh);
430
431 return v4l2_m2m_qbuf(file, ctx->m2m_ctx, buf); 431 return v4l2_m2m_qbuf(file, ctx->m2m_ctx, buf);
432} 432}
433 433
@@ -435,7 +435,6 @@ static int fimc_m2m_dqbuf(struct file *file, void *fh,
435 struct v4l2_buffer *buf) 435 struct v4l2_buffer *buf)
436{ 436{
437 struct fimc_ctx *ctx = fh_to_ctx(fh); 437 struct fimc_ctx *ctx = fh_to_ctx(fh);
438
439 return v4l2_m2m_dqbuf(file, ctx->m2m_ctx, buf); 438 return v4l2_m2m_dqbuf(file, ctx->m2m_ctx, buf);
440} 439}
441 440
@@ -443,7 +442,6 @@ static int fimc_m2m_expbuf(struct file *file, void *fh,
443 struct v4l2_exportbuffer *eb) 442 struct v4l2_exportbuffer *eb)
444{ 443{
445 struct fimc_ctx *ctx = fh_to_ctx(fh); 444 struct fimc_ctx *ctx = fh_to_ctx(fh);
446
447 return v4l2_m2m_expbuf(file, ctx->m2m_ctx, eb); 445 return v4l2_m2m_expbuf(file, ctx->m2m_ctx, eb);
448} 446}
449 447
@@ -452,15 +450,6 @@ static int fimc_m2m_streamon(struct file *file, void *fh,
452 enum v4l2_buf_type type) 450 enum v4l2_buf_type type)
453{ 451{
454 struct fimc_ctx *ctx = fh_to_ctx(fh); 452 struct fimc_ctx *ctx = fh_to_ctx(fh);
455
456 /* The source and target color format need to be set */
457 if (V4L2_TYPE_IS_OUTPUT(type)) {
458 if (!fimc_ctx_state_is_set(FIMC_SRC_FMT, ctx))
459 return -EINVAL;
460 } else if (!fimc_ctx_state_is_set(FIMC_DST_FMT, ctx)) {
461 return -EINVAL;
462 }
463
464 return v4l2_m2m_streamon(file, ctx->m2m_ctx, type); 453 return v4l2_m2m_streamon(file, ctx->m2m_ctx, type);
465} 454}
466 455
@@ -468,7 +457,6 @@ static int fimc_m2m_streamoff(struct file *file, void *fh,
468 enum v4l2_buf_type type) 457 enum v4l2_buf_type type)
469{ 458{
470 struct fimc_ctx *ctx = fh_to_ctx(fh); 459 struct fimc_ctx *ctx = fh_to_ctx(fh);
471
472 return v4l2_m2m_streamoff(file, ctx->m2m_ctx, type); 460 return v4l2_m2m_streamoff(file, ctx->m2m_ctx, type);
473} 461}
474 462
@@ -576,20 +564,18 @@ static int fimc_m2m_s_crop(struct file *file, void *fh, const struct v4l2_crop *
576 &ctx->s_frame : &ctx->d_frame; 564 &ctx->s_frame : &ctx->d_frame;
577 565
578 /* Check to see if scaling ratio is within supported range */ 566 /* Check to see if scaling ratio is within supported range */
579 if (fimc_ctx_state_is_set(FIMC_DST_FMT | FIMC_SRC_FMT, ctx)) { 567 if (cr.type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
580 if (cr.type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { 568 ret = fimc_check_scaler_ratio(ctx, cr.c.width,
581 ret = fimc_check_scaler_ratio(ctx, cr.c.width, 569 cr.c.height, ctx->d_frame.width,
582 cr.c.height, ctx->d_frame.width, 570 ctx->d_frame.height, ctx->rotation);
583 ctx->d_frame.height, ctx->rotation); 571 } else {
584 } else { 572 ret = fimc_check_scaler_ratio(ctx, ctx->s_frame.width,
585 ret = fimc_check_scaler_ratio(ctx, ctx->s_frame.width, 573 ctx->s_frame.height, cr.c.width,
586 ctx->s_frame.height, cr.c.width, 574 cr.c.height, ctx->rotation);
587 cr.c.height, ctx->rotation); 575 }
588 } 576 if (ret) {
589 if (ret) { 577 v4l2_err(&fimc->m2m.vfd, "Out of scaler range\n");
590 v4l2_err(&fimc->m2m.vfd, "Out of scaler range\n"); 578 return -EINVAL;
591 return -EINVAL;
592 }
593 } 579 }
594 580
595 f->offs_h = cr.c.left; 581 f->offs_h = cr.c.left;
@@ -652,6 +638,29 @@ static int queue_init(void *priv, struct vb2_queue *src_vq,
652 return vb2_queue_init(dst_vq); 638 return vb2_queue_init(dst_vq);
653} 639}
654 640
641static int fimc_m2m_set_default_format(struct fimc_ctx *ctx)
642{
643 struct v4l2_pix_format_mplane pixm = {
644 .pixelformat = V4L2_PIX_FMT_RGB32,
645 .width = 800,
646 .height = 600,
647 .plane_fmt[0] = {
648 .bytesperline = 800 * 4,
649 .sizeimage = 800 * 4 * 600,
650 },
651 };
652 struct fimc_fmt *fmt;
653
654 fmt = fimc_find_format(&pixm.pixelformat, NULL, FMT_FLAGS_M2M, 0);
655 if (!fmt)
656 return -EINVAL;
657
658 __set_frame_format(&ctx->s_frame, fmt, &pixm);
659 __set_frame_format(&ctx->d_frame, fmt, &pixm);
660
661 return 0;
662}
663
655static int fimc_m2m_open(struct file *file) 664static int fimc_m2m_open(struct file *file)
656{ 665{
657 struct fimc_dev *fimc = video_drvdata(file); 666 struct fimc_dev *fimc = video_drvdata(file);
@@ -696,6 +705,7 @@ static int fimc_m2m_open(struct file *file)
696 ctx->flags = 0; 705 ctx->flags = 0;
697 ctx->in_path = FIMC_IO_DMA; 706 ctx->in_path = FIMC_IO_DMA;
698 ctx->out_path = FIMC_IO_DMA; 707 ctx->out_path = FIMC_IO_DMA;
708 ctx->scaler.enabled = 1;
699 709
700 ctx->m2m_ctx = v4l2_m2m_ctx_init(fimc->m2m.m2m_dev, ctx, queue_init); 710 ctx->m2m_ctx = v4l2_m2m_ctx_init(fimc->m2m.m2m_dev, ctx, queue_init);
701 if (IS_ERR(ctx->m2m_ctx)) { 711 if (IS_ERR(ctx->m2m_ctx)) {
@@ -706,9 +716,15 @@ static int fimc_m2m_open(struct file *file)
706 if (fimc->m2m.refcnt++ == 0) 716 if (fimc->m2m.refcnt++ == 0)
707 set_bit(ST_M2M_RUN, &fimc->state); 717 set_bit(ST_M2M_RUN, &fimc->state);
708 718
719 ret = fimc_m2m_set_default_format(ctx);
720 if (ret < 0)
721 goto error_m2m_ctx;
722
709 mutex_unlock(&fimc->lock); 723 mutex_unlock(&fimc->lock);
710 return 0; 724 return 0;
711 725
726error_m2m_ctx:
727 v4l2_m2m_ctx_release(ctx->m2m_ctx);
712error_c: 728error_c:
713 fimc_ctrls_delete(ctx); 729 fimc_ctrls_delete(ctx);
714error_fh: 730error_fh:
diff --git a/drivers/media/platform/s5p-fimc/fimc-mdevice.c b/drivers/media/platform/s5p-fimc/fimc-mdevice.c
index b4a68ecf0ca7..a17fcb2d5d41 100644
--- a/drivers/media/platform/s5p-fimc/fimc-mdevice.c
+++ b/drivers/media/platform/s5p-fimc/fimc-mdevice.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 Samsung Electronics Co., Ltd. 4 * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd.
5 * Contact: Sylwester Nawrocki, <s.nawrocki@samsung.com> 5 * 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
@@ -62,16 +62,17 @@ static void fimc_pipeline_prepare(struct fimc_pipeline *p,
62 sd = media_entity_to_v4l2_subdev(pad->entity); 62 sd = media_entity_to_v4l2_subdev(pad->entity);
63 63
64 switch (sd->grp_id) { 64 switch (sd->grp_id) {
65 case SENSOR_GROUP_ID: 65 case GRP_ID_FIMC_IS_SENSOR:
66 case GRP_ID_SENSOR:
66 p->subdevs[IDX_SENSOR] = sd; 67 p->subdevs[IDX_SENSOR] = sd;
67 break; 68 break;
68 case CSIS_GROUP_ID: 69 case GRP_ID_CSIS:
69 p->subdevs[IDX_CSIS] = sd; 70 p->subdevs[IDX_CSIS] = sd;
70 break; 71 break;
71 case FLITE_GROUP_ID: 72 case GRP_ID_FLITE:
72 p->subdevs[IDX_FLITE] = sd; 73 p->subdevs[IDX_FLITE] = sd;
73 break; 74 break;
74 case FIMC_GROUP_ID: 75 case GRP_ID_FIMC:
75 /* No need to control FIMC subdev through subdev ops */ 76 /* No need to control FIMC subdev through subdev ops */
76 break; 77 break;
77 default: 78 default:
@@ -141,7 +142,7 @@ static int fimc_pipeline_s_power(struct fimc_pipeline *p, bool state)
141 * @me: media entity to start graph walk with 142 * @me: media entity to start graph walk with
142 * @prep: true to acquire sensor (and csis) subdevs 143 * @prep: true to acquire sensor (and csis) subdevs
143 * 144 *
144 * This function must be called with the graph mutex held. 145 * Called with the graph mutex held.
145 */ 146 */
146static int __fimc_pipeline_open(struct fimc_pipeline *p, 147static int __fimc_pipeline_open(struct fimc_pipeline *p,
147 struct media_entity *me, bool prep) 148 struct media_entity *me, bool prep)
@@ -161,30 +162,19 @@ static int __fimc_pipeline_open(struct fimc_pipeline *p,
161 return fimc_pipeline_s_power(p, 1); 162 return fimc_pipeline_s_power(p, 1);
162} 163}
163 164
164static int fimc_pipeline_open(struct fimc_pipeline *p,
165 struct media_entity *me, bool prep)
166{
167 int ret;
168
169 mutex_lock(&me->parent->graph_mutex);
170 ret = __fimc_pipeline_open(p, me, prep);
171 mutex_unlock(&me->parent->graph_mutex);
172
173 return ret;
174}
175
176/** 165/**
177 * __fimc_pipeline_close - disable the sensor clock and pipeline power 166 * __fimc_pipeline_close - disable the sensor clock and pipeline power
178 * @fimc: fimc device terminating the pipeline 167 * @fimc: fimc device terminating the pipeline
179 * 168 *
180 * Disable power of all subdevs in the pipeline and turn off the external 169 * Disable power of all subdevs and turn the external sensor clock off.
181 * sensor clock.
182 * Called with the graph mutex held.
183 */ 170 */
184static int __fimc_pipeline_close(struct fimc_pipeline *p) 171static int __fimc_pipeline_close(struct fimc_pipeline *p)
185{ 172{
186 int ret = 0; 173 int ret = 0;
187 174
175 if (!p || !p->subdevs[IDX_SENSOR])
176 return -EINVAL;
177
188 if (p->subdevs[IDX_SENSOR]) { 178 if (p->subdevs[IDX_SENSOR]) {
189 ret = fimc_pipeline_s_power(p, 0); 179 ret = fimc_pipeline_s_power(p, 0);
190 fimc_md_set_camclk(p->subdevs[IDX_SENSOR], false); 180 fimc_md_set_camclk(p->subdevs[IDX_SENSOR], false);
@@ -192,28 +182,12 @@ static int __fimc_pipeline_close(struct fimc_pipeline *p)
192 return ret == -ENXIO ? 0 : ret; 182 return ret == -ENXIO ? 0 : ret;
193} 183}
194 184
195static int fimc_pipeline_close(struct fimc_pipeline *p)
196{
197 struct media_entity *me;
198 int ret;
199
200 if (!p || !p->subdevs[IDX_SENSOR])
201 return -EINVAL;
202
203 me = &p->subdevs[IDX_SENSOR]->entity;
204 mutex_lock(&me->parent->graph_mutex);
205 ret = __fimc_pipeline_close(p);
206 mutex_unlock(&me->parent->graph_mutex);
207
208 return ret;
209}
210
211/** 185/**
212 * fimc_pipeline_s_stream - invoke s_stream on pipeline subdevs 186 * __fimc_pipeline_s_stream - invoke s_stream on pipeline subdevs
213 * @pipeline: video pipeline structure 187 * @pipeline: video pipeline structure
214 * @on: passed as the s_stream call argument 188 * @on: passed as the s_stream call argument
215 */ 189 */
216static int fimc_pipeline_s_stream(struct fimc_pipeline *p, bool on) 190static int __fimc_pipeline_s_stream(struct fimc_pipeline *p, bool on)
217{ 191{
218 int i, ret; 192 int i, ret;
219 193
@@ -235,9 +209,9 @@ static int fimc_pipeline_s_stream(struct fimc_pipeline *p, bool on)
235 209
236/* Media pipeline operations for the FIMC/FIMC-LITE video device driver */ 210/* Media pipeline operations for the FIMC/FIMC-LITE video device driver */
237static const struct fimc_pipeline_ops fimc_pipeline_ops = { 211static const struct fimc_pipeline_ops fimc_pipeline_ops = {
238 .open = fimc_pipeline_open, 212 .open = __fimc_pipeline_open,
239 .close = fimc_pipeline_close, 213 .close = __fimc_pipeline_close,
240 .set_stream = fimc_pipeline_s_stream, 214 .set_stream = __fimc_pipeline_s_stream,
241}; 215};
242 216
243/* 217/*
@@ -269,7 +243,7 @@ static struct v4l2_subdev *fimc_md_register_sensor(struct fimc_md *fmd,
269 return ERR_PTR(-EPROBE_DEFER); 243 return ERR_PTR(-EPROBE_DEFER);
270 } 244 }
271 v4l2_set_subdev_hostdata(sd, s_info); 245 v4l2_set_subdev_hostdata(sd, s_info);
272 sd->grp_id = SENSOR_GROUP_ID; 246 sd->grp_id = GRP_ID_SENSOR;
273 247
274 v4l2_info(&fmd->v4l2_dev, "Registered sensor subdevice %s\n", 248 v4l2_info(&fmd->v4l2_dev, "Registered sensor subdevice %s\n",
275 s_info->pdata.board_info->type); 249 s_info->pdata.board_info->type);
@@ -316,7 +290,7 @@ static int fimc_md_register_sensor_entities(struct fimc_md *fmd)
316 for (i = 0; i < num_clients; i++) { 290 for (i = 0; i < num_clients; i++) {
317 struct v4l2_subdev *sd; 291 struct v4l2_subdev *sd;
318 292
319 fmd->sensor[i].pdata = pdata->isp_info[i]; 293 fmd->sensor[i].pdata = pdata->source_info[i];
320 ret = __fimc_md_set_camclk(fmd, &fmd->sensor[i], true); 294 ret = __fimc_md_set_camclk(fmd, &fmd->sensor[i], true);
321 if (ret) 295 if (ret)
322 break; 296 break;
@@ -338,138 +312,149 @@ static int fimc_md_register_sensor_entities(struct fimc_md *fmd)
338} 312}
339 313
340/* 314/*
341 * MIPI CSIS and FIMC platform devices registration. 315 * MIPI-CSIS, FIMC and FIMC-LITE platform devices registration.
342 */ 316 */
343static int fimc_register_callback(struct device *dev, void *p) 317
318static int register_fimc_lite_entity(struct fimc_md *fmd,
319 struct fimc_lite *fimc_lite)
344{ 320{
345 struct fimc_dev *fimc = dev_get_drvdata(dev);
346 struct v4l2_subdev *sd; 321 struct v4l2_subdev *sd;
347 struct fimc_md *fmd = p;
348 int ret; 322 int ret;
349 323
350 if (fimc == NULL || fimc->id >= FIMC_MAX_DEVS) 324 if (WARN_ON(fimc_lite->index >= FIMC_LITE_MAX_DEVS ||
351 return 0; 325 fmd->fimc_lite[fimc_lite->index]))
326 return -EBUSY;
352 327
353 sd = &fimc->vid_cap.subdev; 328 sd = &fimc_lite->subdev;
354 sd->grp_id = FIMC_GROUP_ID; 329 sd->grp_id = GRP_ID_FLITE;
355 v4l2_set_subdev_hostdata(sd, (void *)&fimc_pipeline_ops); 330 v4l2_set_subdev_hostdata(sd, (void *)&fimc_pipeline_ops);
356 331
357 ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd); 332 ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd);
358 if (ret) { 333 if (!ret)
359 v4l2_err(&fmd->v4l2_dev, "Failed to register FIMC.%d (%d)\n", 334 fmd->fimc_lite[fimc_lite->index] = fimc_lite;
360 fimc->id, ret); 335 else
361 return ret; 336 v4l2_err(&fmd->v4l2_dev, "Failed to register FIMC.LITE%d\n",
362 } 337 fimc_lite->index);
363 338 return ret;
364 fmd->fimc[fimc->id] = fimc;
365 return 0;
366} 339}
367 340
368static int fimc_lite_register_callback(struct device *dev, void *p) 341static int register_fimc_entity(struct fimc_md *fmd, struct fimc_dev *fimc)
369{ 342{
370 struct fimc_lite *fimc = dev_get_drvdata(dev); 343 struct v4l2_subdev *sd;
371 struct fimc_md *fmd = p;
372 int ret; 344 int ret;
373 345
374 if (fimc == NULL || fimc->index >= FIMC_LITE_MAX_DEVS) 346 if (WARN_ON(fimc->id >= FIMC_MAX_DEVS || fmd->fimc[fimc->id]))
375 return 0; 347 return -EBUSY;
376 348
377 fimc->subdev.grp_id = FLITE_GROUP_ID; 349 sd = &fimc->vid_cap.subdev;
378 v4l2_set_subdev_hostdata(&fimc->subdev, (void *)&fimc_pipeline_ops); 350 sd->grp_id = GRP_ID_FIMC;
351 v4l2_set_subdev_hostdata(sd, (void *)&fimc_pipeline_ops);
379 352
380 ret = v4l2_device_register_subdev(&fmd->v4l2_dev, &fimc->subdev); 353 ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd);
381 if (ret) { 354 if (!ret) {
382 v4l2_err(&fmd->v4l2_dev, 355 fmd->fimc[fimc->id] = fimc;
383 "Failed to register FIMC-LITE.%d (%d)\n", 356 fimc->vid_cap.user_subdev_api = fmd->user_subdev_api;
384 fimc->index, ret); 357 } else {
385 return ret; 358 v4l2_err(&fmd->v4l2_dev, "Failed to register FIMC.%d (%d)\n",
359 fimc->id, ret);
386 } 360 }
387 361 return ret;
388 fmd->fimc_lite[fimc->index] = fimc;
389 return 0;
390} 362}
391 363
392static int csis_register_callback(struct device *dev, void *p) 364static int register_csis_entity(struct fimc_md *fmd,
365 struct platform_device *pdev,
366 struct v4l2_subdev *sd)
393{ 367{
394 struct v4l2_subdev *sd = dev_get_drvdata(dev); 368 struct device_node *node = pdev->dev.of_node;
395 struct platform_device *pdev;
396 struct fimc_md *fmd = p;
397 int id, ret; 369 int id, ret;
398 370
399 if (!sd) 371 id = node ? of_alias_get_id(node, "csis") : max(0, pdev->id);
400 return 0; 372
401 pdev = v4l2_get_subdevdata(sd); 373 if (WARN_ON(id >= CSIS_MAX_ENTITIES || fmd->csis[id].sd))
402 if (!pdev || pdev->id < 0 || pdev->id >= CSIS_MAX_ENTITIES) 374 return -EBUSY;
403 return 0;
404 v4l2_info(sd, "csis%d sd: %s\n", pdev->id, sd->name);
405 375
406 id = pdev->id < 0 ? 0 : pdev->id; 376 if (WARN_ON(id >= CSIS_MAX_ENTITIES))
407 sd->grp_id = CSIS_GROUP_ID; 377 return 0;
408 378
379 sd->grp_id = GRP_ID_CSIS;
409 ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd); 380 ret = v4l2_device_register_subdev(&fmd->v4l2_dev, sd);
410 if (!ret) 381 if (!ret)
411 fmd->csis[id].sd = sd; 382 fmd->csis[id].sd = sd;
412 else 383 else
413 v4l2_err(&fmd->v4l2_dev, 384 v4l2_err(&fmd->v4l2_dev,
414 "Failed to register CSIS subdevice: %d\n", ret); 385 "Failed to register MIPI-CSIS.%d (%d)\n", id, ret);
415 return ret; 386 return ret;
416} 387}
417 388
418/** 389static int fimc_md_register_platform_entity(struct fimc_md *fmd,
419 * fimc_md_register_platform_entities - register FIMC and CSIS media entities 390 struct platform_device *pdev,
420 */ 391 int plat_entity)
421static int fimc_md_register_platform_entities(struct fimc_md *fmd)
422{ 392{
423 struct s5p_platform_fimc *pdata = fmd->pdev->dev.platform_data; 393 struct device *dev = &pdev->dev;
424 struct device_driver *driver; 394 int ret = -EPROBE_DEFER;
425 int ret, i; 395 void *drvdata;
426 396
427 driver = driver_find(FIMC_MODULE_NAME, &platform_bus_type); 397 /* Lock to ensure dev->driver won't change. */
428 if (!driver) { 398 device_lock(dev);
429 v4l2_warn(&fmd->v4l2_dev, 399
430 "%s driver not found, deffering probe\n", 400 if (!dev->driver || !try_module_get(dev->driver->owner))
431 FIMC_MODULE_NAME); 401 goto dev_unlock;
432 return -EPROBE_DEFER; 402
433 } 403 drvdata = dev_get_drvdata(dev);
434 404 /* Some subdev didn't probe succesfully id drvdata is NULL */
435 ret = driver_for_each_device(driver, NULL, fmd, 405 if (drvdata) {
436 fimc_register_callback); 406 switch (plat_entity) {
437 if (ret) 407 case IDX_FIMC:
438 return ret; 408 ret = register_fimc_entity(fmd, drvdata);
439
440 driver = driver_find(FIMC_LITE_DRV_NAME, &platform_bus_type);
441 if (driver && try_module_get(driver->owner)) {
442 ret = driver_for_each_device(driver, NULL, fmd,
443 fimc_lite_register_callback);
444 if (ret)
445 return ret;
446 module_put(driver->owner);
447 }
448 /*
449 * Check if there is any sensor on the MIPI-CSI2 bus and
450 * if not skip the s5p-csis module loading.
451 */
452 if (pdata == NULL)
453 return 0;
454 for (i = 0; i < pdata->num_clients; i++) {
455 if (pdata->isp_info[i].bus_type == FIMC_MIPI_CSI2) {
456 ret = 1;
457 break; 409 break;
410 case IDX_FLITE:
411 ret = register_fimc_lite_entity(fmd, drvdata);
412 break;
413 case IDX_CSIS:
414 ret = register_csis_entity(fmd, pdev, drvdata);
415 break;
416 default:
417 ret = -ENODEV;
458 } 418 }
459 } 419 }
460 if (!ret)
461 return 0;
462 420
463 driver = driver_find(CSIS_DRIVER_NAME, &platform_bus_type); 421 module_put(dev->driver->owner);
464 if (!driver || !try_module_get(driver->owner)) { 422dev_unlock:
465 v4l2_warn(&fmd->v4l2_dev, 423 device_unlock(dev);
466 "%s driver not found, deffering probe\n", 424 if (ret == -EPROBE_DEFER)
467 CSIS_DRIVER_NAME); 425 dev_info(&fmd->pdev->dev, "deferring %s device registration\n",
468 return -EPROBE_DEFER; 426 dev_name(dev));
427 else if (ret < 0)
428 dev_err(&fmd->pdev->dev, "%s device registration failed (%d)\n",
429 dev_name(dev), ret);
430 return ret;
431}
432
433static int fimc_md_pdev_match(struct device *dev, void *data)
434{
435 struct platform_device *pdev = to_platform_device(dev);
436 int plat_entity = -1;
437 int ret;
438 char *p;
439
440 if (!get_device(dev))
441 return -ENODEV;
442
443 if (!strcmp(pdev->name, CSIS_DRIVER_NAME)) {
444 plat_entity = IDX_CSIS;
445 } else if (!strcmp(pdev->name, FIMC_LITE_DRV_NAME)) {
446 plat_entity = IDX_FLITE;
447 } else {
448 p = strstr(pdev->name, "fimc");
449 if (p && *(p + 4) == 0)
450 plat_entity = IDX_FIMC;
469 } 451 }
470 452
471 return driver_for_each_device(driver, NULL, fmd, 453 if (plat_entity >= 0)
472 csis_register_callback); 454 ret = fimc_md_register_platform_entity(data, pdev,
455 plat_entity);
456 put_device(dev);
457 return 0;
473} 458}
474 459
475static void fimc_md_unregister_entities(struct fimc_md *fmd) 460static void fimc_md_unregister_entities(struct fimc_md *fmd)
@@ -487,7 +472,7 @@ static void fimc_md_unregister_entities(struct fimc_md *fmd)
487 if (fmd->fimc_lite[i] == NULL) 472 if (fmd->fimc_lite[i] == NULL)
488 continue; 473 continue;
489 v4l2_device_unregister_subdev(&fmd->fimc_lite[i]->subdev); 474 v4l2_device_unregister_subdev(&fmd->fimc_lite[i]->subdev);
490 fmd->fimc[i]->pipeline_ops = NULL; 475 fmd->fimc_lite[i]->pipeline_ops = NULL;
491 fmd->fimc_lite[i] = NULL; 476 fmd->fimc_lite[i] = NULL;
492 } 477 }
493 for (i = 0; i < CSIS_MAX_ENTITIES; i++) { 478 for (i = 0; i < CSIS_MAX_ENTITIES; i++) {
@@ -503,6 +488,7 @@ static void fimc_md_unregister_entities(struct fimc_md *fmd)
503 fimc_md_unregister_sensor(fmd->sensor[i].subdev); 488 fimc_md_unregister_sensor(fmd->sensor[i].subdev);
504 fmd->sensor[i].subdev = NULL; 489 fmd->sensor[i].subdev = NULL;
505 } 490 }
491 v4l2_info(&fmd->v4l2_dev, "Unregistered all entities\n");
506} 492}
507 493
508/** 494/**
@@ -518,7 +504,7 @@ static int __fimc_md_create_fimc_sink_links(struct fimc_md *fmd,
518 struct v4l2_subdev *sensor, 504 struct v4l2_subdev *sensor,
519 int pad, int link_mask) 505 int pad, int link_mask)
520{ 506{
521 struct fimc_sensor_info *s_info; 507 struct fimc_sensor_info *s_info = NULL;
522 struct media_entity *sink; 508 struct media_entity *sink;
523 unsigned int flags = 0; 509 unsigned int flags = 0;
524 int ret, i; 510 int ret, i;
@@ -582,7 +568,7 @@ static int __fimc_md_create_fimc_sink_links(struct fimc_md *fmd,
582 if (ret) 568 if (ret)
583 break; 569 break;
584 570
585 v4l2_info(&fmd->v4l2_dev, "created link [%s] %c> [%s]", 571 v4l2_info(&fmd->v4l2_dev, "created link [%s] %c> [%s]\n",
586 source->name, flags ? '=' : '-', sink->name); 572 source->name, flags ? '=' : '-', sink->name);
587 } 573 }
588 return 0; 574 return 0;
@@ -602,7 +588,7 @@ static int __fimc_md_create_flite_source_links(struct fimc_md *fmd)
602 source = &fimc->subdev.entity; 588 source = &fimc->subdev.entity;
603 sink = &fimc->vfd.entity; 589 sink = &fimc->vfd.entity;
604 /* FIMC-LITE's subdev and video node */ 590 /* FIMC-LITE's subdev and video node */
605 ret = media_entity_create_link(source, FIMC_SD_PAD_SOURCE, 591 ret = media_entity_create_link(source, FLITE_SD_PAD_SOURCE_DMA,
606 sink, 0, flags); 592 sink, 0, flags);
607 if (ret) 593 if (ret)
608 break; 594 break;
@@ -626,9 +612,9 @@ static int __fimc_md_create_flite_source_links(struct fimc_md *fmd)
626 */ 612 */
627static int fimc_md_create_links(struct fimc_md *fmd) 613static int fimc_md_create_links(struct fimc_md *fmd)
628{ 614{
629 struct v4l2_subdev *csi_sensors[2] = { NULL }; 615 struct v4l2_subdev *csi_sensors[CSIS_MAX_ENTITIES] = { NULL };
630 struct v4l2_subdev *sensor, *csis; 616 struct v4l2_subdev *sensor, *csis;
631 struct s5p_fimc_isp_info *pdata; 617 struct fimc_source_info *pdata;
632 struct fimc_sensor_info *s_info; 618 struct fimc_sensor_info *s_info;
633 struct media_entity *source, *sink; 619 struct media_entity *source, *sink;
634 int i, pad, fimc_id = 0, ret = 0; 620 int i, pad, fimc_id = 0, ret = 0;
@@ -646,8 +632,8 @@ static int fimc_md_create_links(struct fimc_md *fmd)
646 source = NULL; 632 source = NULL;
647 pdata = &s_info->pdata; 633 pdata = &s_info->pdata;
648 634
649 switch (pdata->bus_type) { 635 switch (pdata->sensor_bus_type) {
650 case FIMC_MIPI_CSI2: 636 case FIMC_BUS_TYPE_MIPI_CSI2:
651 if (WARN(pdata->mux_id >= CSIS_MAX_ENTITIES, 637 if (WARN(pdata->mux_id >= CSIS_MAX_ENTITIES,
652 "Wrong CSI channel id: %d\n", pdata->mux_id)) 638 "Wrong CSI channel id: %d\n", pdata->mux_id))
653 return -EINVAL; 639 return -EINVAL;
@@ -658,28 +644,29 @@ static int fimc_md_create_links(struct fimc_md *fmd)
658 "but s5p-csis module is not loaded!\n")) 644 "but s5p-csis module is not loaded!\n"))
659 return -EINVAL; 645 return -EINVAL;
660 646
661 ret = media_entity_create_link(&sensor->entity, 0, 647 pad = sensor->entity.num_pads - 1;
648 ret = media_entity_create_link(&sensor->entity, pad,
662 &csis->entity, CSIS_PAD_SINK, 649 &csis->entity, CSIS_PAD_SINK,
663 MEDIA_LNK_FL_IMMUTABLE | 650 MEDIA_LNK_FL_IMMUTABLE |
664 MEDIA_LNK_FL_ENABLED); 651 MEDIA_LNK_FL_ENABLED);
665 if (ret) 652 if (ret)
666 return ret; 653 return ret;
667 654
668 v4l2_info(&fmd->v4l2_dev, "created link [%s] => [%s]", 655 v4l2_info(&fmd->v4l2_dev, "created link [%s] => [%s]\n",
669 sensor->entity.name, csis->entity.name); 656 sensor->entity.name, csis->entity.name);
670 657
671 source = NULL; 658 source = NULL;
672 csi_sensors[pdata->mux_id] = sensor; 659 csi_sensors[pdata->mux_id] = sensor;
673 break; 660 break;
674 661
675 case FIMC_ITU_601...FIMC_ITU_656: 662 case FIMC_BUS_TYPE_ITU_601...FIMC_BUS_TYPE_ITU_656:
676 source = &sensor->entity; 663 source = &sensor->entity;
677 pad = 0; 664 pad = 0;
678 break; 665 break;
679 666
680 default: 667 default:
681 v4l2_err(&fmd->v4l2_dev, "Wrong bus_type: %x\n", 668 v4l2_err(&fmd->v4l2_dev, "Wrong bus_type: %x\n",
682 pdata->bus_type); 669 pdata->sensor_bus_type);
683 return -EINVAL; 670 return -EINVAL;
684 } 671 }
685 if (source == NULL) 672 if (source == NULL)
@@ -690,7 +677,7 @@ static int fimc_md_create_links(struct fimc_md *fmd)
690 pad, link_mask); 677 pad, link_mask);
691 } 678 }
692 679
693 for (i = 0; i < ARRAY_SIZE(fmd->csis); i++) { 680 for (i = 0; i < CSIS_MAX_ENTITIES; i++) {
694 if (fmd->csis[i].sd == NULL) 681 if (fmd->csis[i].sd == NULL)
695 continue; 682 continue;
696 source = &fmd->csis[i].sd->entity; 683 source = &fmd->csis[i].sd->entity;
@@ -721,42 +708,61 @@ static int fimc_md_create_links(struct fimc_md *fmd)
721/* 708/*
722 * The peripheral sensor clock management. 709 * The peripheral sensor clock management.
723 */ 710 */
711static void fimc_md_put_clocks(struct fimc_md *fmd)
712{
713 int i = FIMC_MAX_CAMCLKS;
714
715 while (--i >= 0) {
716 if (IS_ERR(fmd->camclk[i].clock))
717 continue;
718 clk_unprepare(fmd->camclk[i].clock);
719 clk_put(fmd->camclk[i].clock);
720 fmd->camclk[i].clock = ERR_PTR(-EINVAL);
721 }
722}
723
724static int fimc_md_get_clocks(struct fimc_md *fmd) 724static int fimc_md_get_clocks(struct fimc_md *fmd)
725{ 725{
726 struct device *dev = NULL;
726 char clk_name[32]; 727 char clk_name[32];
727 struct clk *clock; 728 struct clk *clock;
728 int i; 729 int ret, i;
730
731 for (i = 0; i < FIMC_MAX_CAMCLKS; i++)
732 fmd->camclk[i].clock = ERR_PTR(-EINVAL);
733
734 if (fmd->pdev->dev.of_node)
735 dev = &fmd->pdev->dev;
729 736
730 for (i = 0; i < FIMC_MAX_CAMCLKS; i++) { 737 for (i = 0; i < FIMC_MAX_CAMCLKS; i++) {
731 snprintf(clk_name, sizeof(clk_name), "sclk_cam%u", i); 738 snprintf(clk_name, sizeof(clk_name), "sclk_cam%u", i);
732 clock = clk_get(NULL, clk_name); 739 clock = clk_get(dev, clk_name);
733 if (IS_ERR_OR_NULL(clock)) { 740
734 v4l2_err(&fmd->v4l2_dev, "Failed to get clock: %s", 741 if (IS_ERR(clock)) {
735 clk_name); 742 dev_err(&fmd->pdev->dev, "Failed to get clock: %s\n",
736 return -ENXIO; 743 clk_name);
744 ret = PTR_ERR(clock);
745 break;
746 }
747 ret = clk_prepare(clock);
748 if (ret < 0) {
749 clk_put(clock);
750 fmd->camclk[i].clock = ERR_PTR(-EINVAL);
751 break;
737 } 752 }
738 fmd->camclk[i].clock = clock; 753 fmd->camclk[i].clock = clock;
739 } 754 }
740 return 0; 755 if (ret)
741} 756 fimc_md_put_clocks(fmd);
742
743static void fimc_md_put_clocks(struct fimc_md *fmd)
744{
745 int i = FIMC_MAX_CAMCLKS;
746 757
747 while (--i >= 0) { 758 return ret;
748 if (IS_ERR_OR_NULL(fmd->camclk[i].clock))
749 continue;
750 clk_put(fmd->camclk[i].clock);
751 fmd->camclk[i].clock = NULL;
752 }
753} 759}
754 760
755static int __fimc_md_set_camclk(struct fimc_md *fmd, 761static int __fimc_md_set_camclk(struct fimc_md *fmd,
756 struct fimc_sensor_info *s_info, 762 struct fimc_sensor_info *s_info,
757 bool on) 763 bool on)
758{ 764{
759 struct s5p_fimc_isp_info *pdata = &s_info->pdata; 765 struct fimc_source_info *pdata = &s_info->pdata;
760 struct fimc_camclk_info *camclk; 766 struct fimc_camclk_info *camclk;
761 int ret = 0; 767 int ret = 0;
762 768
@@ -820,7 +826,9 @@ static int fimc_md_link_notify(struct media_pad *source,
820 struct fimc_dev *fimc = NULL; 826 struct fimc_dev *fimc = NULL;
821 struct fimc_pipeline *pipeline; 827 struct fimc_pipeline *pipeline;
822 struct v4l2_subdev *sd; 828 struct v4l2_subdev *sd;
829 struct mutex *lock;
823 int ret = 0; 830 int ret = 0;
831 int ref_count;
824 832
825 if (media_entity_type(sink->entity) != MEDIA_ENT_T_V4L2_SUBDEV) 833 if (media_entity_type(sink->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
826 return 0; 834 return 0;
@@ -828,28 +836,33 @@ static int fimc_md_link_notify(struct media_pad *source,
828 sd = media_entity_to_v4l2_subdev(sink->entity); 836 sd = media_entity_to_v4l2_subdev(sink->entity);
829 837
830 switch (sd->grp_id) { 838 switch (sd->grp_id) {
831 case FLITE_GROUP_ID: 839 case GRP_ID_FLITE:
832 fimc_lite = v4l2_get_subdevdata(sd); 840 fimc_lite = v4l2_get_subdevdata(sd);
841 if (WARN_ON(fimc_lite == NULL))
842 return 0;
833 pipeline = &fimc_lite->pipeline; 843 pipeline = &fimc_lite->pipeline;
844 lock = &fimc_lite->lock;
834 break; 845 break;
835 case FIMC_GROUP_ID: 846 case GRP_ID_FIMC:
836 fimc = v4l2_get_subdevdata(sd); 847 fimc = v4l2_get_subdevdata(sd);
848 if (WARN_ON(fimc == NULL))
849 return 0;
837 pipeline = &fimc->pipeline; 850 pipeline = &fimc->pipeline;
851 lock = &fimc->lock;
838 break; 852 break;
839 default: 853 default:
840 return 0; 854 return 0;
841 } 855 }
842 856
843 if (!(flags & MEDIA_LNK_FL_ENABLED)) { 857 if (!(flags & MEDIA_LNK_FL_ENABLED)) {
858 int i;
859 mutex_lock(lock);
844 ret = __fimc_pipeline_close(pipeline); 860 ret = __fimc_pipeline_close(pipeline);
845 pipeline->subdevs[IDX_SENSOR] = NULL; 861 for (i = 0; i < IDX_MAX; i++)
846 pipeline->subdevs[IDX_CSIS] = NULL; 862 pipeline->subdevs[i] = NULL;
847 863 if (fimc)
848 if (fimc) {
849 mutex_lock(&fimc->lock);
850 fimc_ctrls_delete(fimc->vid_cap.ctx); 864 fimc_ctrls_delete(fimc->vid_cap.ctx);
851 mutex_unlock(&fimc->lock); 865 mutex_unlock(lock);
852 }
853 return ret; 866 return ret;
854 } 867 }
855 /* 868 /*
@@ -857,23 +870,15 @@ static int fimc_md_link_notify(struct media_pad *source,
857 * pipeline is already in use, i.e. its video node is opened. 870 * pipeline is already in use, i.e. its video node is opened.
858 * Recreate the controls destroyed during the link deactivation. 871 * Recreate the controls destroyed during the link deactivation.
859 */ 872 */
860 if (fimc) { 873 mutex_lock(lock);
861 mutex_lock(&fimc->lock); 874
862 if (fimc->vid_cap.refcnt > 0) { 875 ref_count = fimc ? fimc->vid_cap.refcnt : fimc_lite->ref_count;
863 ret = __fimc_pipeline_open(pipeline, 876 if (ref_count > 0)
864 source->entity, true); 877 ret = __fimc_pipeline_open(pipeline, source->entity, true);
865 if (!ret) 878 if (!ret && fimc)
866 ret = fimc_capture_ctrls_create(fimc); 879 ret = fimc_capture_ctrls_create(fimc);
867 } 880
868 mutex_unlock(&fimc->lock); 881 mutex_unlock(lock);
869 } else {
870 mutex_lock(&fimc_lite->lock);
871 if (fimc_lite->ref_count > 0) {
872 ret = __fimc_pipeline_open(pipeline,
873 source->entity, true);
874 }
875 mutex_unlock(&fimc_lite->lock);
876 }
877 return ret ? -EPIPE : ret; 882 return ret ? -EPIPE : ret;
878} 883}
879 884
@@ -965,7 +970,8 @@ static int fimc_md_probe(struct platform_device *pdev)
965 /* Protect the media graph while we're registering entities */ 970 /* Protect the media graph while we're registering entities */
966 mutex_lock(&fmd->media_dev.graph_mutex); 971 mutex_lock(&fmd->media_dev.graph_mutex);
967 972
968 ret = fimc_md_register_platform_entities(fmd); 973 ret = bus_for_each_dev(&platform_bus_type, NULL, fmd,
974 fimc_md_pdev_match);
969 if (ret) 975 if (ret)
970 goto err_unlock; 976 goto err_unlock;
971 977
diff --git a/drivers/media/platform/s5p-fimc/fimc-mdevice.h b/drivers/media/platform/s5p-fimc/fimc-mdevice.h
index 2d8d41d82620..06b0d8276fd2 100644
--- a/drivers/media/platform/s5p-fimc/fimc-mdevice.h
+++ b/drivers/media/platform/s5p-fimc/fimc-mdevice.h
@@ -22,11 +22,13 @@
22#include "mipi-csis.h" 22#include "mipi-csis.h"
23 23
24/* Group IDs of sensor, MIPI-CSIS, FIMC-LITE and the writeback subdevs. */ 24/* Group IDs of sensor, MIPI-CSIS, FIMC-LITE and the writeback subdevs. */
25#define SENSOR_GROUP_ID (1 << 8) 25#define GRP_ID_SENSOR (1 << 8)
26#define CSIS_GROUP_ID (1 << 9) 26#define GRP_ID_FIMC_IS_SENSOR (1 << 9)
27#define WRITEBACK_GROUP_ID (1 << 10) 27#define GRP_ID_WRITEBACK (1 << 10)
28#define FIMC_GROUP_ID (1 << 11) 28#define GRP_ID_CSIS (1 << 11)
29#define FLITE_GROUP_ID (1 << 12) 29#define GRP_ID_FIMC (1 << 12)
30#define GRP_ID_FLITE (1 << 13)
31#define GRP_ID_FIMC_IS (1 << 14)
30 32
31#define FIMC_MAX_SENSORS 8 33#define FIMC_MAX_SENSORS 8
32#define FIMC_MAX_CAMCLKS 2 34#define FIMC_MAX_CAMCLKS 2
@@ -51,7 +53,7 @@ struct fimc_camclk_info {
51 * This data structure applies to image sensor and the writeback subdevs. 53 * This data structure applies to image sensor and the writeback subdevs.
52 */ 54 */
53struct fimc_sensor_info { 55struct fimc_sensor_info {
54 struct s5p_fimc_isp_info pdata; 56 struct fimc_source_info pdata;
55 struct v4l2_subdev *subdev; 57 struct v4l2_subdev *subdev;
56 struct fimc_dev *host; 58 struct fimc_dev *host;
57}; 59};
diff --git a/drivers/media/platform/s5p-fimc/fimc-reg.c b/drivers/media/platform/s5p-fimc/fimc-reg.c
index 2c9d0c06c9e8..50b97c75b956 100644
--- a/drivers/media/platform/s5p-fimc/fimc-reg.c
+++ b/drivers/media/platform/s5p-fimc/fimc-reg.c
@@ -44,9 +44,9 @@ static u32 fimc_hw_get_in_flip(struct fimc_ctx *ctx)
44 u32 flip = FIMC_REG_MSCTRL_FLIP_NORMAL; 44 u32 flip = FIMC_REG_MSCTRL_FLIP_NORMAL;
45 45
46 if (ctx->hflip) 46 if (ctx->hflip)
47 flip = FIMC_REG_MSCTRL_FLIP_X_MIRROR;
48 if (ctx->vflip)
49 flip = FIMC_REG_MSCTRL_FLIP_Y_MIRROR; 47 flip = FIMC_REG_MSCTRL_FLIP_Y_MIRROR;
48 if (ctx->vflip)
49 flip = FIMC_REG_MSCTRL_FLIP_X_MIRROR;
50 50
51 if (ctx->rotation <= 90) 51 if (ctx->rotation <= 90)
52 return flip; 52 return flip;
@@ -59,9 +59,9 @@ static u32 fimc_hw_get_target_flip(struct fimc_ctx *ctx)
59 u32 flip = FIMC_REG_CITRGFMT_FLIP_NORMAL; 59 u32 flip = FIMC_REG_CITRGFMT_FLIP_NORMAL;
60 60
61 if (ctx->hflip) 61 if (ctx->hflip)
62 flip |= FIMC_REG_CITRGFMT_FLIP_X_MIRROR;
63 if (ctx->vflip)
64 flip |= FIMC_REG_CITRGFMT_FLIP_Y_MIRROR; 62 flip |= FIMC_REG_CITRGFMT_FLIP_Y_MIRROR;
63 if (ctx->vflip)
64 flip |= FIMC_REG_CITRGFMT_FLIP_X_MIRROR;
65 65
66 if (ctx->rotation <= 90) 66 if (ctx->rotation <= 90)
67 return flip; 67 return flip;
@@ -312,7 +312,7 @@ static void fimc_hw_set_scaler(struct fimc_ctx *ctx)
312void fimc_hw_set_mainscaler(struct fimc_ctx *ctx) 312void fimc_hw_set_mainscaler(struct fimc_ctx *ctx)
313{ 313{
314 struct fimc_dev *dev = ctx->fimc_dev; 314 struct fimc_dev *dev = ctx->fimc_dev;
315 struct fimc_variant *variant = dev->variant; 315 const struct fimc_variant *variant = dev->variant;
316 struct fimc_scaler *sc = &ctx->scaler; 316 struct fimc_scaler *sc = &ctx->scaler;
317 u32 cfg; 317 u32 cfg;
318 318
@@ -344,30 +344,31 @@ void fimc_hw_set_mainscaler(struct fimc_ctx *ctx)
344 } 344 }
345} 345}
346 346
347void fimc_hw_en_capture(struct fimc_ctx *ctx) 347void fimc_hw_enable_capture(struct fimc_ctx *ctx)
348{ 348{
349 struct fimc_dev *dev = ctx->fimc_dev; 349 struct fimc_dev *dev = ctx->fimc_dev;
350 u32 cfg;
350 351
351 u32 cfg = readl(dev->regs + FIMC_REG_CIIMGCPT); 352 cfg = readl(dev->regs + FIMC_REG_CIIMGCPT);
352 353 cfg |= FIMC_REG_CIIMGCPT_CPT_FREN_ENABLE;
353 if (ctx->out_path == FIMC_IO_DMA) {
354 /* one shot mode */
355 cfg |= FIMC_REG_CIIMGCPT_CPT_FREN_ENABLE |
356 FIMC_REG_CIIMGCPT_IMGCPTEN;
357 } else {
358 /* Continuous frame capture mode (freerun). */
359 cfg &= ~(FIMC_REG_CIIMGCPT_CPT_FREN_ENABLE |
360 FIMC_REG_CIIMGCPT_CPT_FRMOD_CNT);
361 cfg |= FIMC_REG_CIIMGCPT_IMGCPTEN;
362 }
363 354
364 if (ctx->scaler.enabled) 355 if (ctx->scaler.enabled)
365 cfg |= FIMC_REG_CIIMGCPT_IMGCPTEN_SC; 356 cfg |= FIMC_REG_CIIMGCPT_IMGCPTEN_SC;
357 else
358 cfg &= FIMC_REG_CIIMGCPT_IMGCPTEN_SC;
366 359
367 cfg |= FIMC_REG_CIIMGCPT_IMGCPTEN; 360 cfg |= FIMC_REG_CIIMGCPT_IMGCPTEN;
368 writel(cfg, dev->regs + FIMC_REG_CIIMGCPT); 361 writel(cfg, dev->regs + FIMC_REG_CIIMGCPT);
369} 362}
370 363
364void fimc_hw_disable_capture(struct fimc_dev *dev)
365{
366 u32 cfg = readl(dev->regs + FIMC_REG_CIIMGCPT);
367 cfg &= ~(FIMC_REG_CIIMGCPT_IMGCPTEN |
368 FIMC_REG_CIIMGCPT_IMGCPTEN_SC);
369 writel(cfg, dev->regs + FIMC_REG_CIIMGCPT);
370}
371
371void fimc_hw_set_effect(struct fimc_ctx *ctx) 372void fimc_hw_set_effect(struct fimc_ctx *ctx)
372{ 373{
373 struct fimc_dev *dev = ctx->fimc_dev; 374 struct fimc_dev *dev = ctx->fimc_dev;
@@ -553,7 +554,7 @@ void fimc_hw_set_output_addr(struct fimc_dev *dev,
553} 554}
554 555
555int fimc_hw_set_camera_polarity(struct fimc_dev *fimc, 556int fimc_hw_set_camera_polarity(struct fimc_dev *fimc,
556 struct s5p_fimc_isp_info *cam) 557 struct fimc_source_info *cam)
557{ 558{
558 u32 cfg = readl(fimc->regs + FIMC_REG_CIGCTRL); 559 u32 cfg = readl(fimc->regs + FIMC_REG_CIGCTRL);
559 560
@@ -595,14 +596,15 @@ static const struct mbus_pixfmt_desc pix_desc[] = {
595}; 596};
596 597
597int fimc_hw_set_camera_source(struct fimc_dev *fimc, 598int fimc_hw_set_camera_source(struct fimc_dev *fimc,
598 struct s5p_fimc_isp_info *cam) 599 struct fimc_source_info *source)
599{ 600{
600 struct fimc_frame *f = &fimc->vid_cap.ctx->s_frame; 601 struct fimc_frame *f = &fimc->vid_cap.ctx->s_frame;
601 u32 cfg = 0; 602 u32 bus_width, cfg = 0;
602 u32 bus_width;
603 int i; 603 int i;
604 604
605 if (cam->bus_type == FIMC_ITU_601 || cam->bus_type == FIMC_ITU_656) { 605 switch (source->fimc_bus_type) {
606 case FIMC_BUS_TYPE_ITU_601:
607 case FIMC_BUS_TYPE_ITU_656:
606 for (i = 0; i < ARRAY_SIZE(pix_desc); i++) { 608 for (i = 0; i < ARRAY_SIZE(pix_desc); i++) {
607 if (fimc->vid_cap.mf.code == pix_desc[i].pixelcode) { 609 if (fimc->vid_cap.mf.code == pix_desc[i].pixelcode) {
608 cfg = pix_desc[i].cisrcfmt; 610 cfg = pix_desc[i].cisrcfmt;
@@ -618,15 +620,17 @@ int fimc_hw_set_camera_source(struct fimc_dev *fimc,
618 return -EINVAL; 620 return -EINVAL;
619 } 621 }
620 622
621 if (cam->bus_type == FIMC_ITU_601) { 623 if (source->fimc_bus_type == FIMC_BUS_TYPE_ITU_601) {
622 if (bus_width == 8) 624 if (bus_width == 8)
623 cfg |= FIMC_REG_CISRCFMT_ITU601_8BIT; 625 cfg |= FIMC_REG_CISRCFMT_ITU601_8BIT;
624 else if (bus_width == 16) 626 else if (bus_width == 16)
625 cfg |= FIMC_REG_CISRCFMT_ITU601_16BIT; 627 cfg |= FIMC_REG_CISRCFMT_ITU601_16BIT;
626 } /* else defaults to ITU-R BT.656 8-bit */ 628 } /* else defaults to ITU-R BT.656 8-bit */
627 } else if (cam->bus_type == FIMC_MIPI_CSI2) { 629 break;
630 case FIMC_BUS_TYPE_MIPI_CSI2:
628 if (fimc_fmt_is_user_defined(f->fmt->color)) 631 if (fimc_fmt_is_user_defined(f->fmt->color))
629 cfg |= FIMC_REG_CISRCFMT_ITU601_8BIT; 632 cfg |= FIMC_REG_CISRCFMT_ITU601_8BIT;
633 break;
630 } 634 }
631 635
632 cfg |= (f->o_width << 16) | f->o_height; 636 cfg |= (f->o_width << 16) | f->o_height;
@@ -654,7 +658,7 @@ void fimc_hw_set_camera_offset(struct fimc_dev *fimc, struct fimc_frame *f)
654} 658}
655 659
656int fimc_hw_set_camera_type(struct fimc_dev *fimc, 660int fimc_hw_set_camera_type(struct fimc_dev *fimc,
657 struct s5p_fimc_isp_info *cam) 661 struct fimc_source_info *source)
658{ 662{
659 u32 cfg, tmp; 663 u32 cfg, tmp;
660 struct fimc_vid_cap *vid_cap = &fimc->vid_cap; 664 struct fimc_vid_cap *vid_cap = &fimc->vid_cap;
@@ -667,11 +671,11 @@ int fimc_hw_set_camera_type(struct fimc_dev *fimc,
667 FIMC_REG_CIGCTRL_SELCAM_MIPI | FIMC_REG_CIGCTRL_CAMIF_SELWB | 671 FIMC_REG_CIGCTRL_SELCAM_MIPI | FIMC_REG_CIGCTRL_CAMIF_SELWB |
668 FIMC_REG_CIGCTRL_SELCAM_MIPI_A | FIMC_REG_CIGCTRL_CAM_JPEG); 672 FIMC_REG_CIGCTRL_SELCAM_MIPI_A | FIMC_REG_CIGCTRL_CAM_JPEG);
669 673
670 switch (cam->bus_type) { 674 switch (source->fimc_bus_type) {
671 case FIMC_MIPI_CSI2: 675 case FIMC_BUS_TYPE_MIPI_CSI2:
672 cfg |= FIMC_REG_CIGCTRL_SELCAM_MIPI; 676 cfg |= FIMC_REG_CIGCTRL_SELCAM_MIPI;
673 677
674 if (cam->mux_id == 0) 678 if (source->mux_id == 0)
675 cfg |= FIMC_REG_CIGCTRL_SELCAM_MIPI_A; 679 cfg |= FIMC_REG_CIGCTRL_SELCAM_MIPI_A;
676 680
677 /* TODO: add remaining supported formats. */ 681 /* TODO: add remaining supported formats. */
@@ -694,15 +698,16 @@ int fimc_hw_set_camera_type(struct fimc_dev *fimc,
694 698
695 writel(tmp, fimc->regs + FIMC_REG_CSIIMGFMT); 699 writel(tmp, fimc->regs + FIMC_REG_CSIIMGFMT);
696 break; 700 break;
697 case FIMC_ITU_601...FIMC_ITU_656: 701 case FIMC_BUS_TYPE_ITU_601...FIMC_BUS_TYPE_ITU_656:
698 if (cam->mux_id == 0) /* ITU-A, ITU-B: 0, 1 */ 702 if (source->mux_id == 0) /* ITU-A, ITU-B: 0, 1 */
699 cfg |= FIMC_REG_CIGCTRL_SELCAM_ITU_A; 703 cfg |= FIMC_REG_CIGCTRL_SELCAM_ITU_A;
700 break; 704 break;
701 case FIMC_LCD_WB: 705 case FIMC_BUS_TYPE_LCD_WRITEBACK_A:
702 cfg |= FIMC_REG_CIGCTRL_CAMIF_SELWB; 706 cfg |= FIMC_REG_CIGCTRL_CAMIF_SELWB;
703 break; 707 break;
704 default: 708 default:
705 v4l2_err(&vid_cap->vfd, "Invalid camera bus type selected\n"); 709 v4l2_err(&vid_cap->vfd, "Invalid FIMC bus type selected: %d\n",
710 source->fimc_bus_type);
706 return -EINVAL; 711 return -EINVAL;
707 } 712 }
708 writel(cfg, fimc->regs + FIMC_REG_CIGCTRL); 713 writel(cfg, fimc->regs + FIMC_REG_CIGCTRL);
@@ -737,13 +742,6 @@ void fimc_hw_activate_input_dma(struct fimc_dev *dev, bool on)
737 writel(cfg, dev->regs + FIMC_REG_MSCTRL); 742 writel(cfg, dev->regs + FIMC_REG_MSCTRL);
738} 743}
739 744
740void fimc_hw_dis_capture(struct fimc_dev *dev)
741{
742 u32 cfg = readl(dev->regs + FIMC_REG_CIIMGCPT);
743 cfg &= ~(FIMC_REG_CIIMGCPT_IMGCPTEN | FIMC_REG_CIIMGCPT_IMGCPTEN_SC);
744 writel(cfg, dev->regs + FIMC_REG_CIIMGCPT);
745}
746
747/* Return an index to the buffer actually being written. */ 745/* Return an index to the buffer actually being written. */
748s32 fimc_hw_get_frame_index(struct fimc_dev *dev) 746s32 fimc_hw_get_frame_index(struct fimc_dev *dev)
749{ 747{
@@ -776,13 +774,13 @@ s32 fimc_hw_get_prev_frame_index(struct fimc_dev *dev)
776void fimc_activate_capture(struct fimc_ctx *ctx) 774void fimc_activate_capture(struct fimc_ctx *ctx)
777{ 775{
778 fimc_hw_enable_scaler(ctx->fimc_dev, ctx->scaler.enabled); 776 fimc_hw_enable_scaler(ctx->fimc_dev, ctx->scaler.enabled);
779 fimc_hw_en_capture(ctx); 777 fimc_hw_enable_capture(ctx);
780} 778}
781 779
782void fimc_deactivate_capture(struct fimc_dev *fimc) 780void fimc_deactivate_capture(struct fimc_dev *fimc)
783{ 781{
784 fimc_hw_en_lastirq(fimc, true); 782 fimc_hw_en_lastirq(fimc, true);
785 fimc_hw_dis_capture(fimc); 783 fimc_hw_disable_capture(fimc);
786 fimc_hw_enable_scaler(fimc, false); 784 fimc_hw_enable_scaler(fimc, false);
787 fimc_hw_en_lastirq(fimc, false); 785 fimc_hw_en_lastirq(fimc, false);
788} 786}
diff --git a/drivers/media/platform/s5p-fimc/fimc-reg.h b/drivers/media/platform/s5p-fimc/fimc-reg.h
index b6abfc7b72ac..1a40df6d1a80 100644
--- a/drivers/media/platform/s5p-fimc/fimc-reg.h
+++ b/drivers/media/platform/s5p-fimc/fimc-reg.h
@@ -287,7 +287,7 @@ void fimc_hw_en_lastirq(struct fimc_dev *fimc, int enable);
287void fimc_hw_en_irq(struct fimc_dev *fimc, int enable); 287void fimc_hw_en_irq(struct fimc_dev *fimc, int enable);
288void fimc_hw_set_prescaler(struct fimc_ctx *ctx); 288void fimc_hw_set_prescaler(struct fimc_ctx *ctx);
289void fimc_hw_set_mainscaler(struct fimc_ctx *ctx); 289void fimc_hw_set_mainscaler(struct fimc_ctx *ctx);
290void fimc_hw_en_capture(struct fimc_ctx *ctx); 290void fimc_hw_enable_capture(struct fimc_ctx *ctx);
291void fimc_hw_set_effect(struct fimc_ctx *ctx); 291void fimc_hw_set_effect(struct fimc_ctx *ctx);
292void fimc_hw_set_rgb_alpha(struct fimc_ctx *ctx); 292void fimc_hw_set_rgb_alpha(struct fimc_ctx *ctx);
293void fimc_hw_set_in_dma(struct fimc_ctx *ctx); 293void fimc_hw_set_in_dma(struct fimc_ctx *ctx);
@@ -297,16 +297,16 @@ void fimc_hw_set_input_addr(struct fimc_dev *fimc, struct fimc_addr *paddr);
297void fimc_hw_set_output_addr(struct fimc_dev *fimc, struct fimc_addr *paddr, 297void fimc_hw_set_output_addr(struct fimc_dev *fimc, struct fimc_addr *paddr,
298 int index); 298 int index);
299int fimc_hw_set_camera_source(struct fimc_dev *fimc, 299int fimc_hw_set_camera_source(struct fimc_dev *fimc,
300 struct s5p_fimc_isp_info *cam); 300 struct fimc_source_info *cam);
301void fimc_hw_set_camera_offset(struct fimc_dev *fimc, struct fimc_frame *f); 301void fimc_hw_set_camera_offset(struct fimc_dev *fimc, struct fimc_frame *f);
302int fimc_hw_set_camera_polarity(struct fimc_dev *fimc, 302int fimc_hw_set_camera_polarity(struct fimc_dev *fimc,
303 struct s5p_fimc_isp_info *cam); 303 struct fimc_source_info *cam);
304int fimc_hw_set_camera_type(struct fimc_dev *fimc, 304int fimc_hw_set_camera_type(struct fimc_dev *fimc,
305 struct s5p_fimc_isp_info *cam); 305 struct fimc_source_info *cam);
306void fimc_hw_clear_irq(struct fimc_dev *dev); 306void fimc_hw_clear_irq(struct fimc_dev *dev);
307void fimc_hw_enable_scaler(struct fimc_dev *dev, bool on); 307void fimc_hw_enable_scaler(struct fimc_dev *dev, bool on);
308void fimc_hw_activate_input_dma(struct fimc_dev *dev, bool on); 308void fimc_hw_activate_input_dma(struct fimc_dev *dev, bool on);
309void fimc_hw_dis_capture(struct fimc_dev *dev); 309void fimc_hw_disable_capture(struct fimc_dev *dev);
310s32 fimc_hw_get_frame_index(struct fimc_dev *dev); 310s32 fimc_hw_get_frame_index(struct fimc_dev *dev);
311s32 fimc_hw_get_prev_frame_index(struct fimc_dev *dev); 311s32 fimc_hw_get_prev_frame_index(struct fimc_dev *dev);
312void fimc_activate_capture(struct fimc_ctx *ctx); 312void fimc_activate_capture(struct fimc_ctx *ctx);
diff --git a/drivers/media/platform/s5p-fimc/mipi-csis.c b/drivers/media/platform/s5p-fimc/mipi-csis.c
index 7abae012f55e..981863d05aaa 100644
--- a/drivers/media/platform/s5p-fimc/mipi-csis.c
+++ b/drivers/media/platform/s5p-fimc/mipi-csis.c
@@ -187,7 +187,7 @@ struct csis_state {
187 const struct csis_pix_format *csis_fmt; 187 const struct csis_pix_format *csis_fmt;
188 struct v4l2_mbus_framefmt format; 188 struct v4l2_mbus_framefmt format;
189 189
190 struct spinlock slock; 190 spinlock_t slock;
191 struct csis_pktbuf pkt_buf; 191 struct csis_pktbuf pkt_buf;
192 struct s5pcsis_event events[S5PCSIS_NUM_EVENTS]; 192 struct s5pcsis_event events[S5PCSIS_NUM_EVENTS];
193}; 193};
@@ -220,6 +220,18 @@ static const struct csis_pix_format s5pcsis_formats[] = {
220 .code = V4L2_MBUS_FMT_S5C_UYVY_JPEG_1X8, 220 .code = V4L2_MBUS_FMT_S5C_UYVY_JPEG_1X8,
221 .fmt_reg = S5PCSIS_CFG_FMT_USER(1), 221 .fmt_reg = S5PCSIS_CFG_FMT_USER(1),
222 .data_alignment = 32, 222 .data_alignment = 32,
223 }, {
224 .code = V4L2_MBUS_FMT_SGRBG8_1X8,
225 .fmt_reg = S5PCSIS_CFG_FMT_RAW8,
226 .data_alignment = 24,
227 }, {
228 .code = V4L2_MBUS_FMT_SGRBG10_1X10,
229 .fmt_reg = S5PCSIS_CFG_FMT_RAW10,
230 .data_alignment = 24,
231 }, {
232 .code = V4L2_MBUS_FMT_SGRBG12_1X12,
233 .fmt_reg = S5PCSIS_CFG_FMT_RAW12,
234 .data_alignment = 24,
223 } 235 }
224}; 236};
225 237
@@ -261,7 +273,8 @@ static void s5pcsis_reset(struct csis_state *state)
261 273
262static void s5pcsis_system_enable(struct csis_state *state, int on) 274static void s5pcsis_system_enable(struct csis_state *state, int on)
263{ 275{
264 u32 val; 276 struct s5p_platform_mipi_csis *pdata = state->pdev->dev.platform_data;
277 u32 val, mask;
265 278
266 val = s5pcsis_read(state, S5PCSIS_CTRL); 279 val = s5pcsis_read(state, S5PCSIS_CTRL);
267 if (on) 280 if (on)
@@ -271,10 +284,11 @@ static void s5pcsis_system_enable(struct csis_state *state, int on)
271 s5pcsis_write(state, S5PCSIS_CTRL, val); 284 s5pcsis_write(state, S5PCSIS_CTRL, val);
272 285
273 val = s5pcsis_read(state, S5PCSIS_DPHYCTRL); 286 val = s5pcsis_read(state, S5PCSIS_DPHYCTRL);
274 if (on) 287 val &= ~S5PCSIS_DPHYCTRL_ENABLE;
275 val |= S5PCSIS_DPHYCTRL_ENABLE; 288 if (on) {
276 else 289 mask = (1 << (pdata->lanes + 1)) - 1;
277 val &= ~S5PCSIS_DPHYCTRL_ENABLE; 290 val |= (mask & S5PCSIS_DPHYCTRL_ENABLE);
291 }
278 s5pcsis_write(state, S5PCSIS_DPHYCTRL, val); 292 s5pcsis_write(state, S5PCSIS_DPHYCTRL, val);
279} 293}
280 294
@@ -338,11 +352,11 @@ static void s5pcsis_clk_put(struct csis_state *state)
338 int i; 352 int i;
339 353
340 for (i = 0; i < NUM_CSIS_CLOCKS; i++) { 354 for (i = 0; i < NUM_CSIS_CLOCKS; i++) {
341 if (IS_ERR_OR_NULL(state->clock[i])) 355 if (IS_ERR(state->clock[i]))
342 continue; 356 continue;
343 clk_unprepare(state->clock[i]); 357 clk_unprepare(state->clock[i]);
344 clk_put(state->clock[i]); 358 clk_put(state->clock[i]);
345 state->clock[i] = NULL; 359 state->clock[i] = ERR_PTR(-EINVAL);
346 } 360 }
347} 361}
348 362
@@ -351,14 +365,19 @@ static int s5pcsis_clk_get(struct csis_state *state)
351 struct device *dev = &state->pdev->dev; 365 struct device *dev = &state->pdev->dev;
352 int i, ret; 366 int i, ret;
353 367
368 for (i = 0; i < NUM_CSIS_CLOCKS; i++)
369 state->clock[i] = ERR_PTR(-EINVAL);
370
354 for (i = 0; i < NUM_CSIS_CLOCKS; i++) { 371 for (i = 0; i < NUM_CSIS_CLOCKS; i++) {
355 state->clock[i] = clk_get(dev, csi_clock_name[i]); 372 state->clock[i] = clk_get(dev, csi_clock_name[i]);
356 if (IS_ERR(state->clock[i])) 373 if (IS_ERR(state->clock[i])) {
374 ret = PTR_ERR(state->clock[i]);
357 goto err; 375 goto err;
376 }
358 ret = clk_prepare(state->clock[i]); 377 ret = clk_prepare(state->clock[i]);
359 if (ret < 0) { 378 if (ret < 0) {
360 clk_put(state->clock[i]); 379 clk_put(state->clock[i]);
361 state->clock[i] = NULL; 380 state->clock[i] = ERR_PTR(-EINVAL);
362 goto err; 381 goto err;
363 } 382 }
364 } 383 }
@@ -366,7 +385,31 @@ static int s5pcsis_clk_get(struct csis_state *state)
366err: 385err:
367 s5pcsis_clk_put(state); 386 s5pcsis_clk_put(state);
368 dev_err(dev, "failed to get clock: %s\n", csi_clock_name[i]); 387 dev_err(dev, "failed to get clock: %s\n", csi_clock_name[i]);
369 return -ENXIO; 388 return ret;
389}
390
391static void dump_regs(struct csis_state *state, const char *label)
392{
393 struct {
394 u32 offset;
395 const char * const name;
396 } registers[] = {
397 { 0x00, "CTRL" },
398 { 0x04, "DPHYCTRL" },
399 { 0x08, "CONFIG" },
400 { 0x0c, "DPHYSTS" },
401 { 0x10, "INTMSK" },
402 { 0x2c, "RESOL" },
403 { 0x38, "SDW_CONFIG" },
404 };
405 u32 i;
406
407 v4l2_info(&state->sd, "--- %s ---\n", label);
408
409 for (i = 0; i < ARRAY_SIZE(registers); i++) {
410 u32 cfg = s5pcsis_read(state, registers[i].offset);
411 v4l2_info(&state->sd, "%10s: 0x%08x\n", registers[i].name, cfg);
412 }
370} 413}
371 414
372static void s5pcsis_start_stream(struct csis_state *state) 415static void s5pcsis_start_stream(struct csis_state *state)
@@ -401,12 +444,12 @@ static void s5pcsis_log_counters(struct csis_state *state, bool non_errors)
401 444
402 spin_lock_irqsave(&state->slock, flags); 445 spin_lock_irqsave(&state->slock, flags);
403 446
404 for (i--; i >= 0; i--) 447 for (i--; i >= 0; i--) {
405 if (state->events[i].counter >= 0) 448 if (state->events[i].counter > 0 || debug)
406 v4l2_info(&state->sd, "%s events: %d\n", 449 v4l2_info(&state->sd, "%s events: %d\n",
407 state->events[i].name, 450 state->events[i].name,
408 state->events[i].counter); 451 state->events[i].counter);
409 452 }
410 spin_unlock_irqrestore(&state->slock, flags); 453 spin_unlock_irqrestore(&state->slock, flags);
411} 454}
412 455
@@ -569,7 +612,11 @@ static int s5pcsis_log_status(struct v4l2_subdev *sd)
569{ 612{
570 struct csis_state *state = sd_to_csis_state(sd); 613 struct csis_state *state = sd_to_csis_state(sd);
571 614
615 mutex_lock(&state->lock);
572 s5pcsis_log_counters(state, true); 616 s5pcsis_log_counters(state, true);
617 if (debug && (state->flags & ST_POWERED))
618 dump_regs(state, __func__);
619 mutex_unlock(&state->lock);
573 return 0; 620 return 0;
574} 621}
575 622
@@ -699,26 +746,32 @@ static int s5pcsis_probe(struct platform_device *pdev)
699 for (i = 0; i < CSIS_NUM_SUPPLIES; i++) 746 for (i = 0; i < CSIS_NUM_SUPPLIES; i++)
700 state->supplies[i].supply = csis_supply_name[i]; 747 state->supplies[i].supply = csis_supply_name[i];
701 748
702 ret = regulator_bulk_get(&pdev->dev, CSIS_NUM_SUPPLIES, 749 ret = devm_regulator_bulk_get(&pdev->dev, CSIS_NUM_SUPPLIES,
703 state->supplies); 750 state->supplies);
704 if (ret) 751 if (ret)
705 return ret; 752 return ret;
706 753
707 ret = s5pcsis_clk_get(state); 754 ret = s5pcsis_clk_get(state);
708 if (ret) 755 if (ret < 0)
709 goto e_clkput; 756 return ret;
710 757
711 clk_enable(state->clock[CSIS_CLK_MUX]);
712 if (pdata->clk_rate) 758 if (pdata->clk_rate)
713 clk_set_rate(state->clock[CSIS_CLK_MUX], pdata->clk_rate); 759 ret = clk_set_rate(state->clock[CSIS_CLK_MUX],
760 pdata->clk_rate);
714 else 761 else
715 dev_WARN(&pdev->dev, "No clock frequency specified!\n"); 762 dev_WARN(&pdev->dev, "No clock frequency specified!\n");
763 if (ret < 0)
764 goto e_clkput;
765
766 ret = clk_enable(state->clock[CSIS_CLK_MUX]);
767 if (ret < 0)
768 goto e_clkput;
716 769
717 ret = devm_request_irq(&pdev->dev, state->irq, s5pcsis_irq_handler, 770 ret = devm_request_irq(&pdev->dev, state->irq, s5pcsis_irq_handler,
718 0, dev_name(&pdev->dev), state); 771 0, dev_name(&pdev->dev), state);
719 if (ret) { 772 if (ret) {
720 dev_err(&pdev->dev, "Interrupt request failed\n"); 773 dev_err(&pdev->dev, "Interrupt request failed\n");
721 goto e_regput; 774 goto e_clkdis;
722 } 775 }
723 776
724 v4l2_subdev_init(&state->sd, &s5pcsis_subdev_ops); 777 v4l2_subdev_init(&state->sd, &s5pcsis_subdev_ops);
@@ -736,7 +789,7 @@ static int s5pcsis_probe(struct platform_device *pdev)
736 ret = media_entity_init(&state->sd.entity, 789 ret = media_entity_init(&state->sd.entity,
737 CSIS_PADS_NUM, state->pads, 0); 790 CSIS_PADS_NUM, state->pads, 0);
738 if (ret < 0) 791 if (ret < 0)
739 goto e_clkput; 792 goto e_clkdis;
740 793
741 /* This allows to retrieve the platform device id by the host driver */ 794 /* This allows to retrieve the platform device id by the host driver */
742 v4l2_set_subdevdata(&state->sd, pdev); 795 v4l2_set_subdevdata(&state->sd, pdev);
@@ -749,10 +802,9 @@ static int s5pcsis_probe(struct platform_device *pdev)
749 pm_runtime_enable(&pdev->dev); 802 pm_runtime_enable(&pdev->dev);
750 return 0; 803 return 0;
751 804
752e_regput: 805e_clkdis:
753 regulator_bulk_free(CSIS_NUM_SUPPLIES, state->supplies);
754e_clkput:
755 clk_disable(state->clock[CSIS_CLK_MUX]); 806 clk_disable(state->clock[CSIS_CLK_MUX]);
807e_clkput:
756 s5pcsis_clk_put(state); 808 s5pcsis_clk_put(state);
757 return ret; 809 return ret;
758} 810}
@@ -859,7 +911,6 @@ static int s5pcsis_remove(struct platform_device *pdev)
859 clk_disable(state->clock[CSIS_CLK_MUX]); 911 clk_disable(state->clock[CSIS_CLK_MUX]);
860 pm_runtime_set_suspended(&pdev->dev); 912 pm_runtime_set_suspended(&pdev->dev);
861 s5pcsis_clk_put(state); 913 s5pcsis_clk_put(state);
862 regulator_bulk_free(CSIS_NUM_SUPPLIES, state->supplies);
863 914
864 media_entity_cleanup(&state->sd.entity); 915 media_entity_cleanup(&state->sd.entity);
865 916
diff --git a/drivers/media/platform/s5p-g2d/g2d-hw.c b/drivers/media/platform/s5p-g2d/g2d-hw.c
index 5b86cbe408e2..e87bd93811d4 100644
--- a/drivers/media/platform/s5p-g2d/g2d-hw.c
+++ b/drivers/media/platform/s5p-g2d/g2d-hw.c
@@ -28,6 +28,7 @@ void g2d_set_src_size(struct g2d_dev *d, struct g2d_frame *f)
28{ 28{
29 u32 n; 29 u32 n;
30 30
31 w(0, SRC_SELECT_REG);
31 w(f->stride & 0xFFFF, SRC_STRIDE_REG); 32 w(f->stride & 0xFFFF, SRC_STRIDE_REG);
32 33
33 n = f->o_height & 0xFFF; 34 n = f->o_height & 0xFFF;
@@ -52,6 +53,7 @@ void g2d_set_dst_size(struct g2d_dev *d, struct g2d_frame *f)
52{ 53{
53 u32 n; 54 u32 n;
54 55
56 w(0, DST_SELECT_REG);
55 w(f->stride & 0xFFFF, DST_STRIDE_REG); 57 w(f->stride & 0xFFFF, DST_STRIDE_REG);
56 58
57 n = f->o_height & 0xFFF; 59 n = f->o_height & 0xFFF;
@@ -82,10 +84,14 @@ void g2d_set_flip(struct g2d_dev *d, u32 r)
82 w(r, SRC_MSK_DIRECT_REG); 84 w(r, SRC_MSK_DIRECT_REG);
83} 85}
84 86
85u32 g2d_cmd_stretch(u32 e) 87void g2d_set_v41_stretch(struct g2d_dev *d, struct g2d_frame *src,
88 struct g2d_frame *dst)
86{ 89{
87 e &= 1; 90 w(DEFAULT_SCALE_MODE, SRC_SCALE_CTRL_REG);
88 return e << 4; 91
92 /* inversed scaling factor: src is numerator */
93 w((src->c_width << 16) / dst->c_width, SRC_XSCALE_REG);
94 w((src->c_height << 16) / dst->c_height, SRC_YSCALE_REG);
89} 95}
90 96
91void g2d_set_cmd(struct g2d_dev *d, u32 c) 97void g2d_set_cmd(struct g2d_dev *d, u32 c)
@@ -96,7 +102,9 @@ void g2d_set_cmd(struct g2d_dev *d, u32 c)
96void g2d_start(struct g2d_dev *d) 102void g2d_start(struct g2d_dev *d)
97{ 103{
98 /* Clear cache */ 104 /* Clear cache */
99 w(0x7, CACHECTL_REG); 105 if (d->variant->hw_rev == TYPE_G2D_3X)
106 w(0x7, CACHECTL_REG);
107
100 /* Enable interrupt */ 108 /* Enable interrupt */
101 w(1, INTEN_REG); 109 w(1, INTEN_REG);
102 /* Start G2D engine */ 110 /* Start G2D engine */
diff --git a/drivers/media/platform/s5p-g2d/g2d-regs.h b/drivers/media/platform/s5p-g2d/g2d-regs.h
index 02e1cf50da4e..9bf31ad35d47 100644
--- a/drivers/media/platform/s5p-g2d/g2d-regs.h
+++ b/drivers/media/platform/s5p-g2d/g2d-regs.h
@@ -35,6 +35,9 @@
35#define SRC_COLOR_MODE_REG 0x030C /* Src Image Color Mode reg */ 35#define SRC_COLOR_MODE_REG 0x030C /* Src Image Color Mode reg */
36#define SRC_LEFT_TOP_REG 0x0310 /* Src Left Top Coordinate reg */ 36#define SRC_LEFT_TOP_REG 0x0310 /* Src Left Top Coordinate reg */
37#define SRC_RIGHT_BOTTOM_REG 0x0314 /* Src Right Bottom Coordinate reg */ 37#define SRC_RIGHT_BOTTOM_REG 0x0314 /* Src Right Bottom Coordinate reg */
38#define SRC_SCALE_CTRL_REG 0x0328 /* Src Scaling type select */
39#define SRC_XSCALE_REG 0x032c /* Src X Scaling ratio */
40#define SRC_YSCALE_REG 0x0330 /* Src Y Scaling ratio */
38 41
39/* Parameter Setting Registers (Dest) */ 42/* Parameter Setting Registers (Dest) */
40#define DST_SELECT_REG 0x0400 /* Dest Image Selection reg */ 43#define DST_SELECT_REG 0x0400 /* Dest Image Selection reg */
@@ -113,3 +116,7 @@
113#define DEFAULT_WIDTH 100 116#define DEFAULT_WIDTH 100
114#define DEFAULT_HEIGHT 100 117#define DEFAULT_HEIGHT 100
115 118
119#define DEFAULT_SCALE_MODE (2 << 0)
120
121/* Command mode register values */
122#define CMD_V3_ENABLE_STRETCH (1 << 4)
diff --git a/drivers/media/platform/s5p-g2d/g2d.c b/drivers/media/platform/s5p-g2d/g2d.c
index 6ed259fb1046..aaaf276a5a6c 100644
--- a/drivers/media/platform/s5p-g2d/g2d.c
+++ b/drivers/media/platform/s5p-g2d/g2d.c
@@ -604,8 +604,13 @@ static void device_run(void *prv)
604 g2d_set_flip(dev, ctx->flip); 604 g2d_set_flip(dev, ctx->flip);
605 605
606 if (ctx->in.c_width != ctx->out.c_width || 606 if (ctx->in.c_width != ctx->out.c_width ||
607 ctx->in.c_height != ctx->out.c_height) 607 ctx->in.c_height != ctx->out.c_height) {
608 cmd |= g2d_cmd_stretch(1); 608 if (dev->variant->hw_rev == TYPE_G2D_3X)
609 cmd |= CMD_V3_ENABLE_STRETCH;
610 else
611 g2d_set_v41_stretch(dev, &ctx->in, &ctx->out);
612 }
613
609 g2d_set_cmd(dev, cmd); 614 g2d_set_cmd(dev, cmd);
610 g2d_start(dev); 615 g2d_start(dev);
611 616
@@ -713,7 +718,7 @@ static int g2d_probe(struct platform_device *pdev)
713 return PTR_ERR(dev->regs); 718 return PTR_ERR(dev->regs);
714 719
715 dev->clk = clk_get(&pdev->dev, "sclk_fimg2d"); 720 dev->clk = clk_get(&pdev->dev, "sclk_fimg2d");
716 if (IS_ERR_OR_NULL(dev->clk)) { 721 if (IS_ERR(dev->clk)) {
717 dev_err(&pdev->dev, "failed to get g2d clock\n"); 722 dev_err(&pdev->dev, "failed to get g2d clock\n");
718 return -ENXIO; 723 return -ENXIO;
719 } 724 }
@@ -725,7 +730,7 @@ static int g2d_probe(struct platform_device *pdev)
725 } 730 }
726 731
727 dev->gate = clk_get(&pdev->dev, "fimg2d"); 732 dev->gate = clk_get(&pdev->dev, "fimg2d");
728 if (IS_ERR_OR_NULL(dev->gate)) { 733 if (IS_ERR(dev->gate)) {
729 dev_err(&pdev->dev, "failed to get g2d clock gate\n"); 734 dev_err(&pdev->dev, "failed to get g2d clock gate\n");
730 ret = -ENXIO; 735 ret = -ENXIO;
731 goto unprep_clk; 736 goto unprep_clk;
@@ -789,6 +794,7 @@ static int g2d_probe(struct platform_device *pdev)
789 } 794 }
790 795
791 def_frame.stride = (def_frame.width * def_frame.fmt->depth) >> 3; 796 def_frame.stride = (def_frame.width * def_frame.fmt->depth) >> 3;
797 dev->variant = g2d_get_drv_data(pdev);
792 798
793 return 0; 799 return 0;
794 800
@@ -828,9 +834,30 @@ static int g2d_remove(struct platform_device *pdev)
828 return 0; 834 return 0;
829} 835}
830 836
837static struct g2d_variant g2d_drvdata_v3x = {
838 .hw_rev = TYPE_G2D_3X,
839};
840
841static struct g2d_variant g2d_drvdata_v4x = {
842 .hw_rev = TYPE_G2D_4X, /* Revision 4.1 for Exynos4X12 and Exynos5 */
843};
844
845static struct platform_device_id g2d_driver_ids[] = {
846 {
847 .name = "s5p-g2d",
848 .driver_data = (unsigned long)&g2d_drvdata_v3x,
849 }, {
850 .name = "s5p-g2d-v4x",
851 .driver_data = (unsigned long)&g2d_drvdata_v4x,
852 },
853 {},
854};
855MODULE_DEVICE_TABLE(platform, g2d_driver_ids);
856
831static struct platform_driver g2d_pdrv = { 857static struct platform_driver g2d_pdrv = {
832 .probe = g2d_probe, 858 .probe = g2d_probe,
833 .remove = g2d_remove, 859 .remove = g2d_remove,
860 .id_table = g2d_driver_ids,
834 .driver = { 861 .driver = {
835 .name = G2D_NAME, 862 .name = G2D_NAME,
836 .owner = THIS_MODULE, 863 .owner = THIS_MODULE,
diff --git a/drivers/media/platform/s5p-g2d/g2d.h b/drivers/media/platform/s5p-g2d/g2d.h
index 6b765b0216c5..300ca05ba404 100644
--- a/drivers/media/platform/s5p-g2d/g2d.h
+++ b/drivers/media/platform/s5p-g2d/g2d.h
@@ -10,10 +10,13 @@
10 * License, or (at your option) any later version 10 * License, or (at your option) any later version
11 */ 11 */
12 12
13#include <linux/platform_device.h>
13#include <media/v4l2-device.h> 14#include <media/v4l2-device.h>
14#include <media/v4l2-ctrls.h> 15#include <media/v4l2-ctrls.h>
15 16
16#define G2D_NAME "s5p-g2d" 17#define G2D_NAME "s5p-g2d"
18#define TYPE_G2D_3X 3
19#define TYPE_G2D_4X 4
17 20
18struct g2d_dev { 21struct g2d_dev {
19 struct v4l2_device v4l2_dev; 22 struct v4l2_device v4l2_dev;
@@ -27,6 +30,7 @@ struct g2d_dev {
27 struct clk *clk; 30 struct clk *clk;
28 struct clk *gate; 31 struct clk *gate;
29 struct g2d_ctx *curr; 32 struct g2d_ctx *curr;
33 struct g2d_variant *variant;
30 int irq; 34 int irq;
31 wait_queue_head_t irq_queue; 35 wait_queue_head_t irq_queue;
32}; 36};
@@ -53,7 +57,7 @@ struct g2d_frame {
53struct g2d_ctx { 57struct g2d_ctx {
54 struct v4l2_fh fh; 58 struct v4l2_fh fh;
55 struct g2d_dev *dev; 59 struct g2d_dev *dev;
56 struct v4l2_m2m_ctx *m2m_ctx; 60 struct v4l2_m2m_ctx *m2m_ctx;
57 struct g2d_frame in; 61 struct g2d_frame in;
58 struct g2d_frame out; 62 struct g2d_frame out;
59 struct v4l2_ctrl *ctrl_hflip; 63 struct v4l2_ctrl *ctrl_hflip;
@@ -70,6 +74,9 @@ struct g2d_fmt {
70 u32 hw; 74 u32 hw;
71}; 75};
72 76
77struct g2d_variant {
78 unsigned short hw_rev;
79};
73 80
74void g2d_reset(struct g2d_dev *d); 81void g2d_reset(struct g2d_dev *d);
75void g2d_set_src_size(struct g2d_dev *d, struct g2d_frame *f); 82void g2d_set_src_size(struct g2d_dev *d, struct g2d_frame *f);
@@ -80,7 +87,11 @@ void g2d_start(struct g2d_dev *d);
80void g2d_clear_int(struct g2d_dev *d); 87void g2d_clear_int(struct g2d_dev *d);
81void g2d_set_rop4(struct g2d_dev *d, u32 r); 88void g2d_set_rop4(struct g2d_dev *d, u32 r);
82void g2d_set_flip(struct g2d_dev *d, u32 r); 89void g2d_set_flip(struct g2d_dev *d, u32 r);
83u32 g2d_cmd_stretch(u32 e); 90void g2d_set_v41_stretch(struct g2d_dev *d,
91 struct g2d_frame *src, struct g2d_frame *dst);
84void g2d_set_cmd(struct g2d_dev *d, u32 c); 92void g2d_set_cmd(struct g2d_dev *d, u32 c);
85 93
86 94static inline struct g2d_variant *g2d_get_drv_data(struct platform_device *pdev)
95{
96 return (struct g2d_variant *)platform_get_device_id(pdev)->driver_data;
97}
diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.h b/drivers/media/platform/s5p-jpeg/jpeg-core.h
index 022b9b9baff9..8a4013e3aee7 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.h
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.h
@@ -62,7 +62,7 @@
62 */ 62 */
63struct s5p_jpeg { 63struct s5p_jpeg {
64 struct mutex lock; 64 struct mutex lock;
65 struct spinlock slock; 65 spinlock_t slock;
66 66
67 struct v4l2_device v4l2_dev; 67 struct v4l2_device v4l2_dev;
68 struct video_device *vfd_encoder; 68 struct video_device *vfd_encoder;
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c b/drivers/media/platform/s5p-mfc/s5p_mfc.c
index 8b7fbc7cc04d..e84703c314ce 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
@@ -21,6 +21,7 @@
21#include <linux/videodev2.h> 21#include <linux/videodev2.h>
22#include <media/v4l2-event.h> 22#include <media/v4l2-event.h>
23#include <linux/workqueue.h> 23#include <linux/workqueue.h>
24#include <linux/of.h>
24#include <media/videobuf2-core.h> 25#include <media/videobuf2-core.h>
25#include "s5p_mfc_common.h" 26#include "s5p_mfc_common.h"
26#include "s5p_mfc_ctrl.h" 27#include "s5p_mfc_ctrl.h"
@@ -273,7 +274,6 @@ static void s5p_mfc_handle_frame_new(struct s5p_mfc_ctx *ctx, unsigned int err)
273 struct s5p_mfc_buf *dst_buf; 274 struct s5p_mfc_buf *dst_buf;
274 size_t dspl_y_addr; 275 size_t dspl_y_addr;
275 unsigned int frame_type; 276 unsigned int frame_type;
276 unsigned int index;
277 277
278 dspl_y_addr = s5p_mfc_hw_call(dev->mfc_ops, get_dspl_y_adr, dev); 278 dspl_y_addr = s5p_mfc_hw_call(dev->mfc_ops, get_dspl_y_adr, dev);
279 frame_type = s5p_mfc_hw_call(dev->mfc_ops, get_dec_frame_type, dev); 279 frame_type = s5p_mfc_hw_call(dev->mfc_ops, get_dec_frame_type, dev);
@@ -310,7 +310,6 @@ static void s5p_mfc_handle_frame_new(struct s5p_mfc_ctx *ctx, unsigned int err)
310 vb2_buffer_done(dst_buf->b, 310 vb2_buffer_done(dst_buf->b,
311 err ? VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE); 311 err ? VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE);
312 312
313 index = dst_buf->b->v4l2_buf.index;
314 break; 313 break;
315 } 314 }
316 } 315 }
@@ -326,8 +325,6 @@ static void s5p_mfc_handle_frame(struct s5p_mfc_ctx *ctx,
326 unsigned long flags; 325 unsigned long flags;
327 unsigned int res_change; 326 unsigned int res_change;
328 327
329 unsigned int index;
330
331 dst_frame_status = s5p_mfc_hw_call(dev->mfc_ops, get_dspl_status, dev) 328 dst_frame_status = s5p_mfc_hw_call(dev->mfc_ops, get_dspl_status, dev)
332 & S5P_FIMV_DEC_STATUS_DECODING_STATUS_MASK; 329 & S5P_FIMV_DEC_STATUS_DECODING_STATUS_MASK;
333 res_change = (s5p_mfc_hw_call(dev->mfc_ops, get_dspl_status, dev) 330 res_change = (s5p_mfc_hw_call(dev->mfc_ops, get_dspl_status, dev)
@@ -387,7 +384,6 @@ static void s5p_mfc_handle_frame(struct s5p_mfc_ctx *ctx,
387 mfc_debug(2, "Running again the same buffer\n"); 384 mfc_debug(2, "Running again the same buffer\n");
388 ctx->after_packed_pb = 1; 385 ctx->after_packed_pb = 1;
389 } else { 386 } else {
390 index = src_buf->b->v4l2_buf.index;
391 mfc_debug(2, "MFC needs next buffer\n"); 387 mfc_debug(2, "MFC needs next buffer\n");
392 ctx->consumed_stream = 0; 388 ctx->consumed_stream = 0;
393 list_del(&src_buf->list); 389 list_del(&src_buf->list);
@@ -586,8 +582,7 @@ static void s5p_mfc_handle_stream_complete(struct s5p_mfc_ctx *ctx,
586 582
587 clear_work_bit(ctx); 583 clear_work_bit(ctx);
588 584
589 if (test_and_clear_bit(0, &dev->hw_lock) == 0) 585 WARN_ON(test_and_clear_bit(0, &dev->hw_lock) == 0);
590 WARN_ON(1);
591 586
592 s5p_mfc_clock_off(); 587 s5p_mfc_clock_off();
593 wake_up(&ctx->queue); 588 wake_up(&ctx->queue);
@@ -676,6 +671,12 @@ static irqreturn_t s5p_mfc_irq(int irq, void *priv)
676 s5p_mfc_handle_stream_complete(ctx, reason, err); 671 s5p_mfc_handle_stream_complete(ctx, reason, err);
677 break; 672 break;
678 673
674 case S5P_MFC_R2H_CMD_DPB_FLUSH_RET:
675 clear_work_bit(ctx);
676 ctx->state = MFCINST_RUNNING;
677 wake_up(&ctx->queue);
678 goto irq_cleanup_hw;
679
679 default: 680 default:
680 mfc_debug(2, "Unknown int reason\n"); 681 mfc_debug(2, "Unknown int reason\n");
681 s5p_mfc_hw_call(dev->mfc_ops, clear_int_flags, dev); 682 s5p_mfc_hw_call(dev->mfc_ops, clear_int_flags, dev);
@@ -777,14 +778,16 @@ static int s5p_mfc_open(struct file *file)
777 goto err_pwr_enable; 778 goto err_pwr_enable;
778 } 779 }
779 s5p_mfc_clock_on(); 780 s5p_mfc_clock_on();
780 ret = s5p_mfc_alloc_and_load_firmware(dev); 781 ret = s5p_mfc_load_firmware(dev);
781 if (ret) 782 if (ret) {
782 goto err_alloc_fw; 783 s5p_mfc_clock_off();
784 goto err_load_fw;
785 }
783 /* Init the FW */ 786 /* Init the FW */
784 ret = s5p_mfc_init_hw(dev); 787 ret = s5p_mfc_init_hw(dev);
788 s5p_mfc_clock_off();
785 if (ret) 789 if (ret)
786 goto err_init_hw; 790 goto err_init_hw;
787 s5p_mfc_clock_off();
788 } 791 }
789 /* Init videobuf2 queue for CAPTURE */ 792 /* Init videobuf2 queue for CAPTURE */
790 q = &ctx->vq_dst; 793 q = &ctx->vq_dst;
@@ -833,21 +836,20 @@ static int s5p_mfc_open(struct file *file)
833 return ret; 836 return ret;
834 /* Deinit when failure occured */ 837 /* Deinit when failure occured */
835err_queue_init: 838err_queue_init:
839 if (dev->num_inst == 1)
840 s5p_mfc_deinit_hw(dev);
836err_init_hw: 841err_init_hw:
837 s5p_mfc_release_firmware(dev); 842err_load_fw:
838err_alloc_fw:
839 dev->ctx[ctx->num] = NULL;
840 del_timer_sync(&dev->watchdog_timer);
841 s5p_mfc_clock_off();
842err_pwr_enable: 843err_pwr_enable:
843 if (dev->num_inst == 1) { 844 if (dev->num_inst == 1) {
844 if (s5p_mfc_power_off() < 0) 845 if (s5p_mfc_power_off() < 0)
845 mfc_err("power off failed\n"); 846 mfc_err("power off failed\n");
846 s5p_mfc_release_firmware(dev); 847 del_timer_sync(&dev->watchdog_timer);
847 } 848 }
848err_ctrls_setup: 849err_ctrls_setup:
849 s5p_mfc_dec_ctrls_delete(ctx); 850 s5p_mfc_dec_ctrls_delete(ctx);
850err_bad_node: 851err_bad_node:
852 dev->ctx[ctx->num] = NULL;
851err_no_ctx: 853err_no_ctx:
852 v4l2_fh_del(&ctx->fh); 854 v4l2_fh_del(&ctx->fh);
853 v4l2_fh_exit(&ctx->fh); 855 v4l2_fh_exit(&ctx->fh);
@@ -901,11 +903,8 @@ static int s5p_mfc_release(struct file *file)
901 clear_bit(0, &dev->hw_lock); 903 clear_bit(0, &dev->hw_lock);
902 dev->num_inst--; 904 dev->num_inst--;
903 if (dev->num_inst == 0) { 905 if (dev->num_inst == 0) {
904 mfc_debug(2, "Last instance - release firmware\n"); 906 mfc_debug(2, "Last instance\n");
905 /* reset <-> F/W release */
906 s5p_mfc_reset(dev);
907 s5p_mfc_deinit_hw(dev); 907 s5p_mfc_deinit_hw(dev);
908 s5p_mfc_release_firmware(dev);
909 del_timer_sync(&dev->watchdog_timer); 908 del_timer_sync(&dev->watchdog_timer);
910 if (s5p_mfc_power_off() < 0) 909 if (s5p_mfc_power_off() < 0)
911 mfc_err("Power off failed\n"); 910 mfc_err("Power off failed\n");
@@ -1013,6 +1012,48 @@ static int match_child(struct device *dev, void *data)
1013 return !strcmp(dev_name(dev), (char *)data); 1012 return !strcmp(dev_name(dev), (char *)data);
1014} 1013}
1015 1014
1015static void *mfc_get_drv_data(struct platform_device *pdev);
1016
1017static int s5p_mfc_alloc_memdevs(struct s5p_mfc_dev *dev)
1018{
1019 unsigned int mem_info[2];
1020
1021 dev->mem_dev_l = devm_kzalloc(&dev->plat_dev->dev,
1022 sizeof(struct device), GFP_KERNEL);
1023 if (!dev->mem_dev_l) {
1024 mfc_err("Not enough memory\n");
1025 return -ENOMEM;
1026 }
1027 device_initialize(dev->mem_dev_l);
1028 of_property_read_u32_array(dev->plat_dev->dev.of_node,
1029 "samsung,mfc-l", mem_info, 2);
1030 if (dma_declare_coherent_memory(dev->mem_dev_l, mem_info[0],
1031 mem_info[0], mem_info[1],
1032 DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE) == 0) {
1033 mfc_err("Failed to declare coherent memory for\n"
1034 "MFC device\n");
1035 return -ENOMEM;
1036 }
1037
1038 dev->mem_dev_r = devm_kzalloc(&dev->plat_dev->dev,
1039 sizeof(struct device), GFP_KERNEL);
1040 if (!dev->mem_dev_r) {
1041 mfc_err("Not enough memory\n");
1042 return -ENOMEM;
1043 }
1044 device_initialize(dev->mem_dev_r);
1045 of_property_read_u32_array(dev->plat_dev->dev.of_node,
1046 "samsung,mfc-r", mem_info, 2);
1047 if (dma_declare_coherent_memory(dev->mem_dev_r, mem_info[0],
1048 mem_info[0], mem_info[1],
1049 DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE) == 0) {
1050 pr_err("Failed to declare coherent memory for\n"
1051 "MFC device\n");
1052 return -ENOMEM;
1053 }
1054 return 0;
1055}
1056
1016/* MFC probe function */ 1057/* MFC probe function */
1017static int s5p_mfc_probe(struct platform_device *pdev) 1058static int s5p_mfc_probe(struct platform_device *pdev)
1018{ 1059{
@@ -1036,8 +1077,7 @@ static int s5p_mfc_probe(struct platform_device *pdev)
1036 return -ENODEV; 1077 return -ENODEV;
1037 } 1078 }
1038 1079
1039 dev->variant = (struct s5p_mfc_variant *) 1080 dev->variant = mfc_get_drv_data(pdev);
1040 platform_get_device_id(pdev)->driver_data;
1041 1081
1042 ret = s5p_mfc_init_pm(dev); 1082 ret = s5p_mfc_init_pm(dev);
1043 if (ret < 0) { 1083 if (ret < 0) {
@@ -1065,35 +1105,43 @@ static int s5p_mfc_probe(struct platform_device *pdev)
1065 goto err_res; 1105 goto err_res;
1066 } 1106 }
1067 1107
1068 dev->mem_dev_l = device_find_child(&dev->plat_dev->dev, "s5p-mfc-l", 1108 if (pdev->dev.of_node) {
1069 match_child); 1109 if (s5p_mfc_alloc_memdevs(dev) < 0)
1070 if (!dev->mem_dev_l) { 1110 goto err_res;
1071 mfc_err("Mem child (L) device get failed\n"); 1111 } else {
1072 ret = -ENODEV; 1112 dev->mem_dev_l = device_find_child(&dev->plat_dev->dev,
1073 goto err_res; 1113 "s5p-mfc-l", match_child);
1074 } 1114 if (!dev->mem_dev_l) {
1075 1115 mfc_err("Mem child (L) device get failed\n");
1076 dev->mem_dev_r = device_find_child(&dev->plat_dev->dev, "s5p-mfc-r", 1116 ret = -ENODEV;
1077 match_child); 1117 goto err_res;
1078 if (!dev->mem_dev_r) { 1118 }
1079 mfc_err("Mem child (R) device get failed\n"); 1119 dev->mem_dev_r = device_find_child(&dev->plat_dev->dev,
1080 ret = -ENODEV; 1120 "s5p-mfc-r", match_child);
1081 goto err_res; 1121 if (!dev->mem_dev_r) {
1122 mfc_err("Mem child (R) device get failed\n");
1123 ret = -ENODEV;
1124 goto err_res;
1125 }
1082 } 1126 }
1083 1127
1084 dev->alloc_ctx[0] = vb2_dma_contig_init_ctx(dev->mem_dev_l); 1128 dev->alloc_ctx[0] = vb2_dma_contig_init_ctx(dev->mem_dev_l);
1085 if (IS_ERR_OR_NULL(dev->alloc_ctx[0])) { 1129 if (IS_ERR(dev->alloc_ctx[0])) {
1086 ret = PTR_ERR(dev->alloc_ctx[0]); 1130 ret = PTR_ERR(dev->alloc_ctx[0]);
1087 goto err_res; 1131 goto err_res;
1088 } 1132 }
1089 dev->alloc_ctx[1] = vb2_dma_contig_init_ctx(dev->mem_dev_r); 1133 dev->alloc_ctx[1] = vb2_dma_contig_init_ctx(dev->mem_dev_r);
1090 if (IS_ERR_OR_NULL(dev->alloc_ctx[1])) { 1134 if (IS_ERR(dev->alloc_ctx[1])) {
1091 ret = PTR_ERR(dev->alloc_ctx[1]); 1135 ret = PTR_ERR(dev->alloc_ctx[1]);
1092 goto err_mem_init_ctx_1; 1136 goto err_mem_init_ctx_1;
1093 } 1137 }
1094 1138
1095 mutex_init(&dev->mfc_mutex); 1139 mutex_init(&dev->mfc_mutex);
1096 1140
1141 ret = s5p_mfc_alloc_firmware(dev);
1142 if (ret)
1143 goto err_alloc_fw;
1144
1097 ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev); 1145 ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev);
1098 if (ret) 1146 if (ret)
1099 goto err_v4l2_dev_reg; 1147 goto err_v4l2_dev_reg;
@@ -1175,6 +1223,8 @@ err_dec_reg:
1175err_dec_alloc: 1223err_dec_alloc:
1176 v4l2_device_unregister(&dev->v4l2_dev); 1224 v4l2_device_unregister(&dev->v4l2_dev);
1177err_v4l2_dev_reg: 1225err_v4l2_dev_reg:
1226 s5p_mfc_release_firmware(dev);
1227err_alloc_fw:
1178 vb2_dma_contig_cleanup_ctx(dev->alloc_ctx[1]); 1228 vb2_dma_contig_cleanup_ctx(dev->alloc_ctx[1]);
1179err_mem_init_ctx_1: 1229err_mem_init_ctx_1:
1180 vb2_dma_contig_cleanup_ctx(dev->alloc_ctx[0]); 1230 vb2_dma_contig_cleanup_ctx(dev->alloc_ctx[0]);
@@ -1200,8 +1250,13 @@ static int s5p_mfc_remove(struct platform_device *pdev)
1200 video_unregister_device(dev->vfd_enc); 1250 video_unregister_device(dev->vfd_enc);
1201 video_unregister_device(dev->vfd_dec); 1251 video_unregister_device(dev->vfd_dec);
1202 v4l2_device_unregister(&dev->v4l2_dev); 1252 v4l2_device_unregister(&dev->v4l2_dev);
1253 s5p_mfc_release_firmware(dev);
1203 vb2_dma_contig_cleanup_ctx(dev->alloc_ctx[0]); 1254 vb2_dma_contig_cleanup_ctx(dev->alloc_ctx[0]);
1204 vb2_dma_contig_cleanup_ctx(dev->alloc_ctx[1]); 1255 vb2_dma_contig_cleanup_ctx(dev->alloc_ctx[1]);
1256 if (pdev->dev.of_node) {
1257 put_device(dev->mem_dev_l);
1258 put_device(dev->mem_dev_r);
1259 }
1205 1260
1206 s5p_mfc_final_pm(dev); 1261 s5p_mfc_final_pm(dev);
1207 return 0; 1262 return 0;
@@ -1350,6 +1405,35 @@ static struct platform_device_id mfc_driver_ids[] = {
1350}; 1405};
1351MODULE_DEVICE_TABLE(platform, mfc_driver_ids); 1406MODULE_DEVICE_TABLE(platform, mfc_driver_ids);
1352 1407
1408static const struct of_device_id exynos_mfc_match[] = {
1409 {
1410 .compatible = "samsung,mfc-v5",
1411 .data = &mfc_drvdata_v5,
1412 }, {
1413 .compatible = "samsung,mfc-v6",
1414 .data = &mfc_drvdata_v6,
1415 },
1416 {},
1417};
1418MODULE_DEVICE_TABLE(of, exynos_mfc_match);
1419
1420static void *mfc_get_drv_data(struct platform_device *pdev)
1421{
1422 struct s5p_mfc_variant *driver_data = NULL;
1423
1424 if (pdev->dev.of_node) {
1425 const struct of_device_id *match;
1426 match = of_match_node(of_match_ptr(exynos_mfc_match),
1427 pdev->dev.of_node);
1428 if (match)
1429 driver_data = (struct s5p_mfc_variant *)match->data;
1430 } else {
1431 driver_data = (struct s5p_mfc_variant *)
1432 platform_get_device_id(pdev)->driver_data;
1433 }
1434 return driver_data;
1435}
1436
1353static struct platform_driver s5p_mfc_driver = { 1437static struct platform_driver s5p_mfc_driver = {
1354 .probe = s5p_mfc_probe, 1438 .probe = s5p_mfc_probe,
1355 .remove = s5p_mfc_remove, 1439 .remove = s5p_mfc_remove,
@@ -1357,7 +1441,8 @@ static struct platform_driver s5p_mfc_driver = {
1357 .driver = { 1441 .driver = {
1358 .name = S5P_MFC_NAME, 1442 .name = S5P_MFC_NAME,
1359 .owner = THIS_MODULE, 1443 .owner = THIS_MODULE,
1360 .pm = &s5p_mfc_pm_ops 1444 .pm = &s5p_mfc_pm_ops,
1445 .of_match_table = exynos_mfc_match,
1361 }, 1446 },
1362}; 1447};
1363 1448
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
index f02e0497ca98..202d1d7a37a8 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_common.h
@@ -145,6 +145,7 @@ enum s5p_mfc_inst_state {
145 MFCINST_RETURN_INST, 145 MFCINST_RETURN_INST,
146 MFCINST_ERROR, 146 MFCINST_ERROR,
147 MFCINST_ABORT, 147 MFCINST_ABORT,
148 MFCINST_FLUSH,
148 MFCINST_RES_CHANGE_INIT, 149 MFCINST_RES_CHANGE_INIT,
149 MFCINST_RES_CHANGE_FLUSH, 150 MFCINST_RES_CHANGE_FLUSH,
150 MFCINST_RES_CHANGE_END, 151 MFCINST_RES_CHANGE_END,
@@ -277,8 +278,9 @@ struct s5p_mfc_priv_buf {
277 * @int_err: error number for last interrupt 278 * @int_err: error number for last interrupt
278 * @queue: waitqueue for waiting for completion of device commands 279 * @queue: waitqueue for waiting for completion of device commands
279 * @fw_size: size of firmware 280 * @fw_size: size of firmware
280 * @bank1: address of the beggining of bank 1 memory 281 * @fw_virt_addr: virtual firmware address
281 * @bank2: address of the beggining of bank 2 memory 282 * @bank1: address of the beginning of bank 1 memory
283 * @bank2: address of the beginning of bank 2 memory
282 * @hw_lock: used for hardware locking 284 * @hw_lock: used for hardware locking
283 * @ctx: array of driver contexts 285 * @ctx: array of driver contexts
284 * @curr_ctx: number of the currently running context 286 * @curr_ctx: number of the currently running context
@@ -317,8 +319,9 @@ struct s5p_mfc_dev {
317 unsigned int int_err; 319 unsigned int int_err;
318 wait_queue_head_t queue; 320 wait_queue_head_t queue;
319 size_t fw_size; 321 size_t fw_size;
320 size_t bank1; 322 void *fw_virt_addr;
321 size_t bank2; 323 dma_addr_t bank1;
324 dma_addr_t bank2;
322 unsigned long hw_lock; 325 unsigned long hw_lock;
323 struct s5p_mfc_ctx *ctx[MFC_NUM_CONTEXTS]; 326 struct s5p_mfc_ctx *ctx[MFC_NUM_CONTEXTS];
324 int curr_ctx; 327 int curr_ctx;
@@ -493,15 +496,9 @@ struct s5p_mfc_codec_ops {
493 * flushed 496 * flushed
494 * @head_processed: flag mentioning whether the header data is processed 497 * @head_processed: flag mentioning whether the header data is processed
495 * completely or not 498 * completely or not
496 * @bank1_buf: handle to memory allocated for temporary buffers from 499 * @bank1: handle to memory allocated for temporary buffers from
497 * memory bank 1 500 * memory bank 1
498 * @bank1_phys: address of the temporary buffers from memory bank 1 501 * @bank2: handle to memory allocated for temporary buffers from
499 * @bank1_size: size of the memory allocated for temporary buffers from
500 * memory bank 1
501 * @bank2_buf: handle to memory allocated for temporary buffers from
502 * memory bank 2
503 * @bank2_phys: address of the temporary buffers from memory bank 2
504 * @bank2_size: size of the memory allocated for temporary buffers from
505 * memory bank 2 502 * memory bank 2
506 * @capture_state: state of the capture buffers queue 503 * @capture_state: state of the capture buffers queue
507 * @output_state: state of the output buffers queue 504 * @output_state: state of the output buffers queue
@@ -581,14 +578,8 @@ struct s5p_mfc_ctx {
581 unsigned int dpb_flush_flag; 578 unsigned int dpb_flush_flag;
582 unsigned int head_processed; 579 unsigned int head_processed;
583 580
584 /* Buffers */ 581 struct s5p_mfc_priv_buf bank1;
585 void *bank1_buf; 582 struct s5p_mfc_priv_buf bank2;
586 size_t bank1_phys;
587 size_t bank1_size;
588
589 void *bank2_buf;
590 size_t bank2_phys;
591 size_t bank2_size;
592 583
593 enum s5p_mfc_queue_state capture_state; 584 enum s5p_mfc_queue_state capture_state;
594 enum s5p_mfc_queue_state output_state; 585 enum s5p_mfc_queue_state output_state;
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
index 585b7b0ed8ec..2e5f30b40dea 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.c
@@ -22,16 +22,64 @@
22#include "s5p_mfc_opr.h" 22#include "s5p_mfc_opr.h"
23#include "s5p_mfc_pm.h" 23#include "s5p_mfc_pm.h"
24 24
25static void *s5p_mfc_bitproc_buf; 25/* Allocate memory for firmware */
26static size_t s5p_mfc_bitproc_phys; 26int s5p_mfc_alloc_firmware(struct s5p_mfc_dev *dev)
27static unsigned char *s5p_mfc_bitproc_virt; 27{
28 void *bank2_virt;
29 dma_addr_t bank2_dma_addr;
30
31 dev->fw_size = dev->variant->buf_size->fw;
32
33 if (dev->fw_virt_addr) {
34 mfc_err("Attempting to allocate firmware when it seems that it is already loaded\n");
35 return -ENOMEM;
36 }
37
38 dev->fw_virt_addr = dma_alloc_coherent(dev->mem_dev_l, dev->fw_size,
39 &dev->bank1, GFP_KERNEL);
40
41 if (IS_ERR(dev->fw_virt_addr)) {
42 dev->fw_virt_addr = NULL;
43 mfc_err("Allocating bitprocessor buffer failed\n");
44 return -ENOMEM;
45 }
46
47 dev->bank1 = dev->bank1;
48
49 if (HAS_PORTNUM(dev) && IS_TWOPORT(dev)) {
50 bank2_virt = dma_alloc_coherent(dev->mem_dev_r, 1 << MFC_BASE_ALIGN_ORDER,
51 &bank2_dma_addr, GFP_KERNEL);
52
53 if (IS_ERR(dev->fw_virt_addr)) {
54 mfc_err("Allocating bank2 base failed\n");
55 dma_free_coherent(dev->mem_dev_l, dev->fw_size,
56 dev->fw_virt_addr, dev->bank1);
57 dev->fw_virt_addr = NULL;
58 return -ENOMEM;
59 }
60
61 /* Valid buffers passed to MFC encoder with LAST_FRAME command
62 * should not have address of bank2 - MFC will treat it as a null frame.
63 * To avoid such situation we set bank2 address below the pool address.
64 */
65 dev->bank2 = bank2_dma_addr - (1 << MFC_BASE_ALIGN_ORDER);
66
67 dma_free_coherent(dev->mem_dev_r, 1 << MFC_BASE_ALIGN_ORDER,
68 bank2_virt, bank2_dma_addr);
69
70 } else {
71 /* In this case bank2 can point to the same address as bank1.
72 * Firmware will always occupy the beggining of this area so it is
73 * impossible having a video frame buffer with zero address. */
74 dev->bank2 = dev->bank1;
75 }
76 return 0;
77}
28 78
29/* Allocate and load firmware */ 79/* Load firmware */
30int s5p_mfc_alloc_and_load_firmware(struct s5p_mfc_dev *dev) 80int s5p_mfc_load_firmware(struct s5p_mfc_dev *dev)
31{ 81{
32 struct firmware *fw_blob; 82 struct firmware *fw_blob;
33 size_t bank2_base_phys;
34 void *b_base;
35 int err; 83 int err;
36 84
37 /* Firmare has to be present as a separate file or compiled 85 /* Firmare has to be present as a separate file or compiled
@@ -44,77 +92,17 @@ int s5p_mfc_alloc_and_load_firmware(struct s5p_mfc_dev *dev)
44 mfc_err("Firmware is not present in the /lib/firmware directory nor compiled in kernel\n"); 92 mfc_err("Firmware is not present in the /lib/firmware directory nor compiled in kernel\n");
45 return -EINVAL; 93 return -EINVAL;
46 } 94 }
47 dev->fw_size = dev->variant->buf_size->fw;
48 if (fw_blob->size > dev->fw_size) { 95 if (fw_blob->size > dev->fw_size) {
49 mfc_err("MFC firmware is too big to be loaded\n"); 96 mfc_err("MFC firmware is too big to be loaded\n");
50 release_firmware(fw_blob); 97 release_firmware(fw_blob);
51 return -ENOMEM; 98 return -ENOMEM;
52 } 99 }
53 if (s5p_mfc_bitproc_buf) { 100 if (!dev->fw_virt_addr) {
54 mfc_err("Attempting to allocate firmware when it seems that it is already loaded\n"); 101 mfc_err("MFC firmware is not allocated\n");
55 release_firmware(fw_blob);
56 return -ENOMEM;
57 }
58 s5p_mfc_bitproc_buf = vb2_dma_contig_memops.alloc(
59 dev->alloc_ctx[MFC_BANK1_ALLOC_CTX], dev->fw_size);
60 if (IS_ERR(s5p_mfc_bitproc_buf)) {
61 s5p_mfc_bitproc_buf = NULL;
62 mfc_err("Allocating bitprocessor buffer failed\n");
63 release_firmware(fw_blob); 102 release_firmware(fw_blob);
64 return -ENOMEM; 103 return -EINVAL;
65 }
66 s5p_mfc_bitproc_phys = s5p_mfc_mem_cookie(
67 dev->alloc_ctx[MFC_BANK1_ALLOC_CTX], s5p_mfc_bitproc_buf);
68 if (s5p_mfc_bitproc_phys & ((1 << MFC_BASE_ALIGN_ORDER) - 1)) {
69 mfc_err("The base memory for bank 1 is not aligned to 128KB\n");
70 vb2_dma_contig_memops.put(s5p_mfc_bitproc_buf);
71 s5p_mfc_bitproc_phys = 0;
72 s5p_mfc_bitproc_buf = NULL;
73 release_firmware(fw_blob);
74 return -EIO;
75 }
76 s5p_mfc_bitproc_virt = vb2_dma_contig_memops.vaddr(s5p_mfc_bitproc_buf);
77 if (!s5p_mfc_bitproc_virt) {
78 mfc_err("Bitprocessor memory remap failed\n");
79 vb2_dma_contig_memops.put(s5p_mfc_bitproc_buf);
80 s5p_mfc_bitproc_phys = 0;
81 s5p_mfc_bitproc_buf = NULL;
82 release_firmware(fw_blob);
83 return -EIO;
84 }
85 dev->bank1 = s5p_mfc_bitproc_phys;
86 if (HAS_PORTNUM(dev) && IS_TWOPORT(dev)) {
87 b_base = vb2_dma_contig_memops.alloc(
88 dev->alloc_ctx[MFC_BANK2_ALLOC_CTX],
89 1 << MFC_BASE_ALIGN_ORDER);
90 if (IS_ERR(b_base)) {
91 vb2_dma_contig_memops.put(s5p_mfc_bitproc_buf);
92 s5p_mfc_bitproc_phys = 0;
93 s5p_mfc_bitproc_buf = NULL;
94 mfc_err("Allocating bank2 base failed\n");
95 release_firmware(fw_blob);
96 return -ENOMEM;
97 }
98 bank2_base_phys = s5p_mfc_mem_cookie(
99 dev->alloc_ctx[MFC_BANK2_ALLOC_CTX], b_base);
100 vb2_dma_contig_memops.put(b_base);
101 if (bank2_base_phys & ((1 << MFC_BASE_ALIGN_ORDER) - 1)) {
102 mfc_err("The base memory for bank 2 is not aligned to 128KB\n");
103 vb2_dma_contig_memops.put(s5p_mfc_bitproc_buf);
104 s5p_mfc_bitproc_phys = 0;
105 s5p_mfc_bitproc_buf = NULL;
106 release_firmware(fw_blob);
107 return -EIO;
108 }
109 /* Valid buffers passed to MFC encoder with LAST_FRAME command
110 * should not have address of bank2 - MFC will treat it as a null frame.
111 * To avoid such situation we set bank2 address below the pool address.
112 */
113 dev->bank2 = bank2_base_phys - (1 << MFC_BASE_ALIGN_ORDER);
114 } else {
115 dev->bank2 = dev->bank1;
116 } 104 }
117 memcpy(s5p_mfc_bitproc_virt, fw_blob->data, fw_blob->size); 105 memcpy(dev->fw_virt_addr, fw_blob->data, fw_blob->size);
118 wmb(); 106 wmb();
119 release_firmware(fw_blob); 107 release_firmware(fw_blob);
120 mfc_debug_leave(); 108 mfc_debug_leave();
@@ -142,12 +130,12 @@ int s5p_mfc_reload_firmware(struct s5p_mfc_dev *dev)
142 release_firmware(fw_blob); 130 release_firmware(fw_blob);
143 return -ENOMEM; 131 return -ENOMEM;
144 } 132 }
145 if (s5p_mfc_bitproc_buf == NULL || s5p_mfc_bitproc_phys == 0) { 133 if (!dev->fw_virt_addr) {
146 mfc_err("MFC firmware is not allocated or was not mapped correctly\n"); 134 mfc_err("MFC firmware is not allocated\n");
147 release_firmware(fw_blob); 135 release_firmware(fw_blob);
148 return -EINVAL; 136 return -EINVAL;
149 } 137 }
150 memcpy(s5p_mfc_bitproc_virt, fw_blob->data, fw_blob->size); 138 memcpy(dev->fw_virt_addr, fw_blob->data, fw_blob->size);
151 wmb(); 139 wmb();
152 release_firmware(fw_blob); 140 release_firmware(fw_blob);
153 mfc_debug_leave(); 141 mfc_debug_leave();
@@ -159,12 +147,11 @@ int s5p_mfc_release_firmware(struct s5p_mfc_dev *dev)
159{ 147{
160 /* Before calling this function one has to make sure 148 /* Before calling this function one has to make sure
161 * that MFC is no longer processing */ 149 * that MFC is no longer processing */
162 if (!s5p_mfc_bitproc_buf) 150 if (!dev->fw_virt_addr)
163 return -EINVAL; 151 return -EINVAL;
164 vb2_dma_contig_memops.put(s5p_mfc_bitproc_buf); 152 dma_free_coherent(dev->mem_dev_l, dev->fw_size, dev->fw_virt_addr,
165 s5p_mfc_bitproc_virt = NULL; 153 dev->bank1);
166 s5p_mfc_bitproc_phys = 0; 154 dev->fw_virt_addr = NULL;
167 s5p_mfc_bitproc_buf = NULL;
168 return 0; 155 return 0;
169} 156}
170 157
@@ -257,8 +244,10 @@ int s5p_mfc_init_hw(struct s5p_mfc_dev *dev)
257 int ret; 244 int ret;
258 245
259 mfc_debug_enter(); 246 mfc_debug_enter();
260 if (!s5p_mfc_bitproc_buf) 247 if (!dev->fw_virt_addr) {
248 mfc_err("Firmware memory is not allocated.\n");
261 return -EINVAL; 249 return -EINVAL;
250 }
262 251
263 /* 0. MFC reset */ 252 /* 0. MFC reset */
264 mfc_debug(2, "MFC reset..\n"); 253 mfc_debug(2, "MFC reset..\n");
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.h b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.h
index 90aa9b9886d5..6a9b6f8606bb 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.h
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_ctrl.h
@@ -16,7 +16,8 @@
16#include "s5p_mfc_common.h" 16#include "s5p_mfc_common.h"
17 17
18int s5p_mfc_release_firmware(struct s5p_mfc_dev *dev); 18int s5p_mfc_release_firmware(struct s5p_mfc_dev *dev);
19int s5p_mfc_alloc_and_load_firmware(struct s5p_mfc_dev *dev); 19int s5p_mfc_alloc_firmware(struct s5p_mfc_dev *dev);
20int s5p_mfc_load_firmware(struct s5p_mfc_dev *dev);
20int s5p_mfc_reload_firmware(struct s5p_mfc_dev *dev); 21int s5p_mfc_reload_firmware(struct s5p_mfc_dev *dev);
21 22
22int s5p_mfc_init_hw(struct s5p_mfc_dev *dev); 23int s5p_mfc_init_hw(struct s5p_mfc_dev *dev);
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
index 6dad9a74f61c..4582473978ca 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
@@ -991,24 +991,35 @@ static int s5p_mfc_stop_streaming(struct vb2_queue *q)
991 S5P_MFC_R2H_CMD_FRAME_DONE_RET, 0); 991 S5P_MFC_R2H_CMD_FRAME_DONE_RET, 0);
992 aborted = 1; 992 aborted = 1;
993 } 993 }
994 spin_lock_irqsave(&dev->irqlock, flags);
995 if (q->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { 994 if (q->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
995 spin_lock_irqsave(&dev->irqlock, flags);
996 s5p_mfc_hw_call(dev->mfc_ops, cleanup_queue, &ctx->dst_queue, 996 s5p_mfc_hw_call(dev->mfc_ops, cleanup_queue, &ctx->dst_queue,
997 &ctx->vq_dst); 997 &ctx->vq_dst);
998 INIT_LIST_HEAD(&ctx->dst_queue); 998 INIT_LIST_HEAD(&ctx->dst_queue);
999 ctx->dst_queue_cnt = 0; 999 ctx->dst_queue_cnt = 0;
1000 ctx->dpb_flush_flag = 1; 1000 ctx->dpb_flush_flag = 1;
1001 ctx->dec_dst_flag = 0; 1001 ctx->dec_dst_flag = 0;
1002 spin_unlock_irqrestore(&dev->irqlock, flags);
1003 if (IS_MFCV6(dev) && (ctx->state == MFCINST_RUNNING)) {
1004 ctx->state = MFCINST_FLUSH;
1005 set_work_bit_irqsave(ctx);
1006 s5p_mfc_clean_ctx_int_flags(ctx);
1007 s5p_mfc_hw_call(dev->mfc_ops, try_run, dev);
1008 if (s5p_mfc_wait_for_done_ctx(ctx,
1009 S5P_MFC_R2H_CMD_DPB_FLUSH_RET, 0))
1010 mfc_err("Err flushing buffers\n");
1011 }
1002 } 1012 }
1003 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { 1013 if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
1014 spin_lock_irqsave(&dev->irqlock, flags);
1004 s5p_mfc_hw_call(dev->mfc_ops, cleanup_queue, &ctx->src_queue, 1015 s5p_mfc_hw_call(dev->mfc_ops, cleanup_queue, &ctx->src_queue,
1005 &ctx->vq_src); 1016 &ctx->vq_src);
1006 INIT_LIST_HEAD(&ctx->src_queue); 1017 INIT_LIST_HEAD(&ctx->src_queue);
1007 ctx->src_queue_cnt = 0; 1018 ctx->src_queue_cnt = 0;
1019 spin_unlock_irqrestore(&dev->irqlock, flags);
1008 } 1020 }
1009 if (aborted) 1021 if (aborted)
1010 ctx->state = MFCINST_RUNNING; 1022 ctx->state = MFCINST_RUNNING;
1011 spin_unlock_irqrestore(&dev->irqlock, flags);
1012 return 0; 1023 return 0;
1013} 1024}
1014 1025
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
index f92f6ddd739f..2356fd52a169 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
@@ -1534,6 +1534,8 @@ int vidioc_encoder_cmd(struct file *file, void *priv,
1534 if (list_empty(&ctx->src_queue)) { 1534 if (list_empty(&ctx->src_queue)) {
1535 mfc_debug(2, "EOS: empty src queue, entering finishing state"); 1535 mfc_debug(2, "EOS: empty src queue, entering finishing state");
1536 ctx->state = MFCINST_FINISHING; 1536 ctx->state = MFCINST_FINISHING;
1537 if (s5p_mfc_ctx_ready(ctx))
1538 set_work_bit_irqsave(ctx);
1537 spin_unlock_irqrestore(&dev->irqlock, flags); 1539 spin_unlock_irqrestore(&dev->irqlock, flags);
1538 s5p_mfc_hw_call(dev->mfc_ops, try_run, dev); 1540 s5p_mfc_hw_call(dev->mfc_ops, try_run, dev);
1539 } else { 1541 } else {
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_opr.c b/drivers/media/platform/s5p-mfc/s5p_mfc_opr.c
index 6932e90d4065..10f8ac37cecd 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_opr.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_opr.c
@@ -12,6 +12,7 @@
12 * published by the Free Software Foundation. 12 * published by the Free Software Foundation.
13 */ 13 */
14 14
15#include "s5p_mfc_debug.h"
15#include "s5p_mfc_opr.h" 16#include "s5p_mfc_opr.h"
16#include "s5p_mfc_opr_v5.h" 17#include "s5p_mfc_opr_v5.h"
17#include "s5p_mfc_opr_v6.h" 18#include "s5p_mfc_opr_v6.h"
@@ -29,3 +30,32 @@ void s5p_mfc_init_hw_ops(struct s5p_mfc_dev *dev)
29 } 30 }
30 dev->mfc_ops = s5p_mfc_ops; 31 dev->mfc_ops = s5p_mfc_ops;
31} 32}
33
34int s5p_mfc_alloc_priv_buf(struct device *dev,
35 struct s5p_mfc_priv_buf *b)
36{
37
38 mfc_debug(3, "Allocating priv: %d\n", b->size);
39
40 b->virt = dma_alloc_coherent(dev, b->size, &b->dma, GFP_KERNEL);
41
42 if (!b->virt) {
43 mfc_err("Allocating private buffer failed\n");
44 return -ENOMEM;
45 }
46
47 mfc_debug(3, "Allocated addr %p %08x\n", b->virt, b->dma);
48 return 0;
49}
50
51void s5p_mfc_release_priv_buf(struct device *dev,
52 struct s5p_mfc_priv_buf *b)
53{
54 if (b->virt) {
55 dma_free_coherent(dev, b->size, b->virt, b->dma);
56 b->virt = NULL;
57 b->dma = 0;
58 b->size = 0;
59 }
60}
61
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_opr.h b/drivers/media/platform/s5p-mfc/s5p_mfc_opr.h
index 420abecafec0..754c540e7a7e 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_opr.h
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_opr.h
@@ -80,5 +80,10 @@ struct s5p_mfc_hw_ops {
80}; 80};
81 81
82void s5p_mfc_init_hw_ops(struct s5p_mfc_dev *dev); 82void s5p_mfc_init_hw_ops(struct s5p_mfc_dev *dev);
83int s5p_mfc_alloc_priv_buf(struct device *dev,
84 struct s5p_mfc_priv_buf *b);
85void s5p_mfc_release_priv_buf(struct device *dev,
86 struct s5p_mfc_priv_buf *b);
87
83 88
84#endif /* S5P_MFC_OPR_H_ */ 89#endif /* S5P_MFC_OPR_H_ */
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c
index bf7d010a4107..f61dba837899 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v5.c
@@ -38,39 +38,26 @@ int s5p_mfc_alloc_dec_temp_buffers_v5(struct s5p_mfc_ctx *ctx)
38{ 38{
39 struct s5p_mfc_dev *dev = ctx->dev; 39 struct s5p_mfc_dev *dev = ctx->dev;
40 struct s5p_mfc_buf_size_v5 *buf_size = dev->variant->buf_size->priv; 40 struct s5p_mfc_buf_size_v5 *buf_size = dev->variant->buf_size->priv;
41 int ret;
41 42
42 ctx->dsc.alloc = vb2_dma_contig_memops.alloc( 43 ctx->dsc.size = buf_size->dsc;
43 dev->alloc_ctx[MFC_BANK1_ALLOC_CTX], 44 ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, &ctx->dsc);
44 buf_size->dsc); 45 if (ret) {
45 if (IS_ERR_VALUE((int)ctx->dsc.alloc)) { 46 mfc_err("Failed to allocate temporary buffer\n");
46 ctx->dsc.alloc = NULL; 47 return ret;
47 mfc_err("Allocating DESC buffer failed\n");
48 return -ENOMEM;
49 } 48 }
50 ctx->dsc.dma = s5p_mfc_mem_cookie( 49
51 dev->alloc_ctx[MFC_BANK1_ALLOC_CTX], ctx->dsc.alloc);
52 BUG_ON(ctx->dsc.dma & ((1 << MFC_BANK1_ALIGN_ORDER) - 1)); 50 BUG_ON(ctx->dsc.dma & ((1 << MFC_BANK1_ALIGN_ORDER) - 1));
53 ctx->dsc.virt = vb2_dma_contig_memops.vaddr(ctx->dsc.alloc); 51 memset(ctx->dsc.virt, 0, ctx->dsc.size);
54 if (ctx->dsc.virt == NULL) {
55 vb2_dma_contig_memops.put(ctx->dsc.alloc);
56 ctx->dsc.dma = 0;
57 ctx->dsc.alloc = NULL;
58 mfc_err("Remapping DESC buffer failed\n");
59 return -ENOMEM;
60 }
61 memset(ctx->dsc.virt, 0, buf_size->dsc);
62 wmb(); 52 wmb();
63 return 0; 53 return 0;
64} 54}
65 55
56
66/* Release temporary buffers for decoding */ 57/* Release temporary buffers for decoding */
67void s5p_mfc_release_dec_desc_buffer_v5(struct s5p_mfc_ctx *ctx) 58void s5p_mfc_release_dec_desc_buffer_v5(struct s5p_mfc_ctx *ctx)
68{ 59{
69 if (ctx->dsc.dma) { 60 s5p_mfc_release_priv_buf(ctx->dev->mem_dev_l, &ctx->dsc);
70 vb2_dma_contig_memops.put(ctx->dsc.alloc);
71 ctx->dsc.alloc = NULL;
72 ctx->dsc.dma = 0;
73 }
74} 61}
75 62
76/* Allocate codec buffers */ 63/* Allocate codec buffers */
@@ -80,6 +67,7 @@ int s5p_mfc_alloc_codec_buffers_v5(struct s5p_mfc_ctx *ctx)
80 unsigned int enc_ref_y_size = 0; 67 unsigned int enc_ref_y_size = 0;
81 unsigned int enc_ref_c_size = 0; 68 unsigned int enc_ref_c_size = 0;
82 unsigned int guard_width, guard_height; 69 unsigned int guard_width, guard_height;
70 int ret;
83 71
84 if (ctx->type == MFCINST_DECODER) { 72 if (ctx->type == MFCINST_DECODER) {
85 mfc_debug(2, "Luma size:%d Chroma size:%d MV size:%d\n", 73 mfc_debug(2, "Luma size:%d Chroma size:%d MV size:%d\n",
@@ -113,100 +101,93 @@ int s5p_mfc_alloc_codec_buffers_v5(struct s5p_mfc_ctx *ctx)
113 /* Codecs have different memory requirements */ 101 /* Codecs have different memory requirements */
114 switch (ctx->codec_mode) { 102 switch (ctx->codec_mode) {
115 case S5P_MFC_CODEC_H264_DEC: 103 case S5P_MFC_CODEC_H264_DEC:
116 ctx->bank1_size = 104 ctx->bank1.size =
117 ALIGN(S5P_FIMV_DEC_NB_IP_SIZE + 105 ALIGN(S5P_FIMV_DEC_NB_IP_SIZE +
118 S5P_FIMV_DEC_VERT_NB_MV_SIZE, 106 S5P_FIMV_DEC_VERT_NB_MV_SIZE,
119 S5P_FIMV_DEC_BUF_ALIGN); 107 S5P_FIMV_DEC_BUF_ALIGN);
120 ctx->bank2_size = ctx->total_dpb_count * ctx->mv_size; 108 ctx->bank2.size = ctx->total_dpb_count * ctx->mv_size;
121 break; 109 break;
122 case S5P_MFC_CODEC_MPEG4_DEC: 110 case S5P_MFC_CODEC_MPEG4_DEC:
123 ctx->bank1_size = 111 ctx->bank1.size =
124 ALIGN(S5P_FIMV_DEC_NB_DCAC_SIZE + 112 ALIGN(S5P_FIMV_DEC_NB_DCAC_SIZE +
125 S5P_FIMV_DEC_UPNB_MV_SIZE + 113 S5P_FIMV_DEC_UPNB_MV_SIZE +
126 S5P_FIMV_DEC_SUB_ANCHOR_MV_SIZE + 114 S5P_FIMV_DEC_SUB_ANCHOR_MV_SIZE +
127 S5P_FIMV_DEC_STX_PARSER_SIZE + 115 S5P_FIMV_DEC_STX_PARSER_SIZE +
128 S5P_FIMV_DEC_OVERLAP_TRANSFORM_SIZE, 116 S5P_FIMV_DEC_OVERLAP_TRANSFORM_SIZE,
129 S5P_FIMV_DEC_BUF_ALIGN); 117 S5P_FIMV_DEC_BUF_ALIGN);
130 ctx->bank2_size = 0; 118 ctx->bank2.size = 0;
131 break; 119 break;
132 case S5P_MFC_CODEC_VC1RCV_DEC: 120 case S5P_MFC_CODEC_VC1RCV_DEC:
133 case S5P_MFC_CODEC_VC1_DEC: 121 case S5P_MFC_CODEC_VC1_DEC:
134 ctx->bank1_size = 122 ctx->bank1.size =
135 ALIGN(S5P_FIMV_DEC_OVERLAP_TRANSFORM_SIZE + 123 ALIGN(S5P_FIMV_DEC_OVERLAP_TRANSFORM_SIZE +
136 S5P_FIMV_DEC_UPNB_MV_SIZE + 124 S5P_FIMV_DEC_UPNB_MV_SIZE +
137 S5P_FIMV_DEC_SUB_ANCHOR_MV_SIZE + 125 S5P_FIMV_DEC_SUB_ANCHOR_MV_SIZE +
138 S5P_FIMV_DEC_NB_DCAC_SIZE + 126 S5P_FIMV_DEC_NB_DCAC_SIZE +
139 3 * S5P_FIMV_DEC_VC1_BITPLANE_SIZE, 127 3 * S5P_FIMV_DEC_VC1_BITPLANE_SIZE,
140 S5P_FIMV_DEC_BUF_ALIGN); 128 S5P_FIMV_DEC_BUF_ALIGN);
141 ctx->bank2_size = 0; 129 ctx->bank2.size = 0;
142 break; 130 break;
143 case S5P_MFC_CODEC_MPEG2_DEC: 131 case S5P_MFC_CODEC_MPEG2_DEC:
144 ctx->bank1_size = 0; 132 ctx->bank1.size = 0;
145 ctx->bank2_size = 0; 133 ctx->bank2.size = 0;
146 break; 134 break;
147 case S5P_MFC_CODEC_H263_DEC: 135 case S5P_MFC_CODEC_H263_DEC:
148 ctx->bank1_size = 136 ctx->bank1.size =
149 ALIGN(S5P_FIMV_DEC_OVERLAP_TRANSFORM_SIZE + 137 ALIGN(S5P_FIMV_DEC_OVERLAP_TRANSFORM_SIZE +
150 S5P_FIMV_DEC_UPNB_MV_SIZE + 138 S5P_FIMV_DEC_UPNB_MV_SIZE +
151 S5P_FIMV_DEC_SUB_ANCHOR_MV_SIZE + 139 S5P_FIMV_DEC_SUB_ANCHOR_MV_SIZE +
152 S5P_FIMV_DEC_NB_DCAC_SIZE, 140 S5P_FIMV_DEC_NB_DCAC_SIZE,
153 S5P_FIMV_DEC_BUF_ALIGN); 141 S5P_FIMV_DEC_BUF_ALIGN);
154 ctx->bank2_size = 0; 142 ctx->bank2.size = 0;
155 break; 143 break;
156 case S5P_MFC_CODEC_H264_ENC: 144 case S5P_MFC_CODEC_H264_ENC:
157 ctx->bank1_size = (enc_ref_y_size * 2) + 145 ctx->bank1.size = (enc_ref_y_size * 2) +
158 S5P_FIMV_ENC_UPMV_SIZE + 146 S5P_FIMV_ENC_UPMV_SIZE +
159 S5P_FIMV_ENC_COLFLG_SIZE + 147 S5P_FIMV_ENC_COLFLG_SIZE +
160 S5P_FIMV_ENC_INTRAMD_SIZE + 148 S5P_FIMV_ENC_INTRAMD_SIZE +
161 S5P_FIMV_ENC_NBORINFO_SIZE; 149 S5P_FIMV_ENC_NBORINFO_SIZE;
162 ctx->bank2_size = (enc_ref_y_size * 2) + 150 ctx->bank2.size = (enc_ref_y_size * 2) +
163 (enc_ref_c_size * 4) + 151 (enc_ref_c_size * 4) +
164 S5P_FIMV_ENC_INTRAPRED_SIZE; 152 S5P_FIMV_ENC_INTRAPRED_SIZE;
165 break; 153 break;
166 case S5P_MFC_CODEC_MPEG4_ENC: 154 case S5P_MFC_CODEC_MPEG4_ENC:
167 ctx->bank1_size = (enc_ref_y_size * 2) + 155 ctx->bank1.size = (enc_ref_y_size * 2) +
168 S5P_FIMV_ENC_UPMV_SIZE + 156 S5P_FIMV_ENC_UPMV_SIZE +
169 S5P_FIMV_ENC_COLFLG_SIZE + 157 S5P_FIMV_ENC_COLFLG_SIZE +
170 S5P_FIMV_ENC_ACDCCOEF_SIZE; 158 S5P_FIMV_ENC_ACDCCOEF_SIZE;
171 ctx->bank2_size = (enc_ref_y_size * 2) + 159 ctx->bank2.size = (enc_ref_y_size * 2) +
172 (enc_ref_c_size * 4); 160 (enc_ref_c_size * 4);
173 break; 161 break;
174 case S5P_MFC_CODEC_H263_ENC: 162 case S5P_MFC_CODEC_H263_ENC:
175 ctx->bank1_size = (enc_ref_y_size * 2) + 163 ctx->bank1.size = (enc_ref_y_size * 2) +
176 S5P_FIMV_ENC_UPMV_SIZE + 164 S5P_FIMV_ENC_UPMV_SIZE +
177 S5P_FIMV_ENC_ACDCCOEF_SIZE; 165 S5P_FIMV_ENC_ACDCCOEF_SIZE;
178 ctx->bank2_size = (enc_ref_y_size * 2) + 166 ctx->bank2.size = (enc_ref_y_size * 2) +
179 (enc_ref_c_size * 4); 167 (enc_ref_c_size * 4);
180 break; 168 break;
181 default: 169 default:
182 break; 170 break;
183 } 171 }
184 /* Allocate only if memory from bank 1 is necessary */ 172 /* Allocate only if memory from bank 1 is necessary */
185 if (ctx->bank1_size > 0) { 173 if (ctx->bank1.size > 0) {
186 ctx->bank1_buf = vb2_dma_contig_memops.alloc( 174
187 dev->alloc_ctx[MFC_BANK1_ALLOC_CTX], ctx->bank1_size); 175 ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, &ctx->bank1);
188 if (IS_ERR(ctx->bank1_buf)) { 176 if (ret) {
189 ctx->bank1_buf = NULL; 177 mfc_err("Failed to allocate Bank1 temporary buffer\n");
190 printk(KERN_ERR 178 return ret;
191 "Buf alloc for decoding failed (port A)\n");
192 return -ENOMEM;
193 } 179 }
194 ctx->bank1_phys = s5p_mfc_mem_cookie( 180 BUG_ON(ctx->bank1.dma & ((1 << MFC_BANK1_ALIGN_ORDER) - 1));
195 dev->alloc_ctx[MFC_BANK1_ALLOC_CTX], ctx->bank1_buf);
196 BUG_ON(ctx->bank1_phys & ((1 << MFC_BANK1_ALIGN_ORDER) - 1));
197 } 181 }
198 /* Allocate only if memory from bank 2 is necessary */ 182 /* Allocate only if memory from bank 2 is necessary */
199 if (ctx->bank2_size > 0) { 183 if (ctx->bank2.size > 0) {
200 ctx->bank2_buf = vb2_dma_contig_memops.alloc( 184 ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_r, &ctx->bank2);
201 dev->alloc_ctx[MFC_BANK2_ALLOC_CTX], ctx->bank2_size); 185 if (ret) {
202 if (IS_ERR(ctx->bank2_buf)) { 186 mfc_err("Failed to allocate Bank2 temporary buffer\n");
203 ctx->bank2_buf = NULL; 187 s5p_mfc_release_priv_buf(ctx->dev->mem_dev_l, &ctx->bank1);
204 mfc_err("Buf alloc for decoding failed (port B)\n"); 188 return ret;
205 return -ENOMEM;
206 } 189 }
207 ctx->bank2_phys = s5p_mfc_mem_cookie( 190 BUG_ON(ctx->bank2.dma & ((1 << MFC_BANK2_ALIGN_ORDER) - 1));
208 dev->alloc_ctx[MFC_BANK2_ALLOC_CTX], ctx->bank2_buf);
209 BUG_ON(ctx->bank2_phys & ((1 << MFC_BANK2_ALIGN_ORDER) - 1));
210 } 191 }
211 return 0; 192 return 0;
212} 193}
@@ -214,18 +195,8 @@ int s5p_mfc_alloc_codec_buffers_v5(struct s5p_mfc_ctx *ctx)
214/* Release buffers allocated for codec */ 195/* Release buffers allocated for codec */
215void s5p_mfc_release_codec_buffers_v5(struct s5p_mfc_ctx *ctx) 196void s5p_mfc_release_codec_buffers_v5(struct s5p_mfc_ctx *ctx)
216{ 197{
217 if (ctx->bank1_buf) { 198 s5p_mfc_release_priv_buf(ctx->dev->mem_dev_l, &ctx->bank1);
218 vb2_dma_contig_memops.put(ctx->bank1_buf); 199 s5p_mfc_release_priv_buf(ctx->dev->mem_dev_r, &ctx->bank2);
219 ctx->bank1_buf = NULL;
220 ctx->bank1_phys = 0;
221 ctx->bank1_size = 0;
222 }
223 if (ctx->bank2_buf) {
224 vb2_dma_contig_memops.put(ctx->bank2_buf);
225 ctx->bank2_buf = NULL;
226 ctx->bank2_phys = 0;
227 ctx->bank2_size = 0;
228 }
229} 200}
230 201
231/* Allocate memory for instance data buffer */ 202/* Allocate memory for instance data buffer */
@@ -233,58 +204,38 @@ int s5p_mfc_alloc_instance_buffer_v5(struct s5p_mfc_ctx *ctx)
233{ 204{
234 struct s5p_mfc_dev *dev = ctx->dev; 205 struct s5p_mfc_dev *dev = ctx->dev;
235 struct s5p_mfc_buf_size_v5 *buf_size = dev->variant->buf_size->priv; 206 struct s5p_mfc_buf_size_v5 *buf_size = dev->variant->buf_size->priv;
207 int ret;
236 208
237 if (ctx->codec_mode == S5P_MFC_CODEC_H264_DEC || 209 if (ctx->codec_mode == S5P_MFC_CODEC_H264_DEC ||
238 ctx->codec_mode == S5P_MFC_CODEC_H264_ENC) 210 ctx->codec_mode == S5P_MFC_CODEC_H264_ENC)
239 ctx->ctx.size = buf_size->h264_ctx; 211 ctx->ctx.size = buf_size->h264_ctx;
240 else 212 else
241 ctx->ctx.size = buf_size->non_h264_ctx; 213 ctx->ctx.size = buf_size->non_h264_ctx;
242 ctx->ctx.alloc = vb2_dma_contig_memops.alloc( 214
243 dev->alloc_ctx[MFC_BANK1_ALLOC_CTX], ctx->ctx.size); 215 ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, &ctx->ctx);
244 if (IS_ERR(ctx->ctx.alloc)) { 216 if (ret) {
245 mfc_err("Allocating context buffer failed\n"); 217 mfc_err("Failed to allocate instance buffer\n");
246 ctx->ctx.alloc = NULL; 218 return ret;
247 return -ENOMEM;
248 } 219 }
249 ctx->ctx.dma = s5p_mfc_mem_cookie(
250 dev->alloc_ctx[MFC_BANK1_ALLOC_CTX], ctx->ctx.alloc);
251 BUG_ON(ctx->ctx.dma & ((1 << MFC_BANK1_ALIGN_ORDER) - 1));
252 ctx->ctx.ofs = OFFSETA(ctx->ctx.dma); 220 ctx->ctx.ofs = OFFSETA(ctx->ctx.dma);
253 ctx->ctx.virt = vb2_dma_contig_memops.vaddr(ctx->ctx.alloc); 221
254 if (!ctx->ctx.virt) {
255 mfc_err("Remapping instance buffer failed\n");
256 vb2_dma_contig_memops.put(ctx->ctx.alloc);
257 ctx->ctx.alloc = NULL;
258 ctx->ctx.ofs = 0;
259 ctx->ctx.dma = 0;
260 return -ENOMEM;
261 }
262 /* Zero content of the allocated memory */ 222 /* Zero content of the allocated memory */
263 memset(ctx->ctx.virt, 0, ctx->ctx.size); 223 memset(ctx->ctx.virt, 0, ctx->ctx.size);
264 wmb(); 224 wmb();
265 225
266 /* Initialize shared memory */ 226 /* Initialize shared memory */
267 ctx->shm.alloc = vb2_dma_contig_memops.alloc( 227 ctx->shm.size = buf_size->shm;
268 dev->alloc_ctx[MFC_BANK1_ALLOC_CTX], buf_size->shm); 228 ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, &ctx->shm);
269 if (IS_ERR(ctx->shm.alloc)) { 229 if (ret) {
270 mfc_err("failed to allocate shared memory\n"); 230 mfc_err("Failed to allocate shared memory buffer\n");
271 return PTR_ERR(ctx->shm.alloc); 231 return ret;
272 } 232 }
233
273 /* shared memory offset only keeps the offset from base (port a) */ 234 /* shared memory offset only keeps the offset from base (port a) */
274 ctx->shm.ofs = s5p_mfc_mem_cookie( 235 ctx->shm.ofs = ctx->shm.dma - dev->bank1;
275 dev->alloc_ctx[MFC_BANK1_ALLOC_CTX], ctx->shm.alloc)
276 - dev->bank1;
277 BUG_ON(ctx->shm.ofs & ((1 << MFC_BANK1_ALIGN_ORDER) - 1)); 236 BUG_ON(ctx->shm.ofs & ((1 << MFC_BANK1_ALIGN_ORDER) - 1));
278 237
279 ctx->shm.virt = vb2_dma_contig_memops.vaddr(ctx->shm.alloc); 238 memset(ctx->shm.virt, 0, buf_size->shm);
280 if (!ctx->shm.virt) {
281 vb2_dma_contig_memops.put(ctx->shm.alloc);
282 ctx->shm.alloc = NULL;
283 ctx->shm.ofs = 0;
284 mfc_err("failed to virt addr of shared memory\n");
285 return -ENOMEM;
286 }
287 memset((void *)ctx->shm.virt, 0, buf_size->shm);
288 wmb(); 239 wmb();
289 return 0; 240 return 0;
290} 241}
@@ -292,19 +243,8 @@ int s5p_mfc_alloc_instance_buffer_v5(struct s5p_mfc_ctx *ctx)
292/* Release instance buffer */ 243/* Release instance buffer */
293void s5p_mfc_release_instance_buffer_v5(struct s5p_mfc_ctx *ctx) 244void s5p_mfc_release_instance_buffer_v5(struct s5p_mfc_ctx *ctx)
294{ 245{
295 if (ctx->ctx.alloc) { 246 s5p_mfc_release_priv_buf(ctx->dev->mem_dev_l, &ctx->ctx);
296 vb2_dma_contig_memops.put(ctx->ctx.alloc); 247 s5p_mfc_release_priv_buf(ctx->dev->mem_dev_l, &ctx->shm);
297 ctx->ctx.alloc = NULL;
298 ctx->ctx.ofs = 0;
299 ctx->ctx.virt = NULL;
300 ctx->ctx.dma = 0;
301 }
302 if (ctx->shm.alloc) {
303 vb2_dma_contig_memops.put(ctx->shm.alloc);
304 ctx->shm.alloc = NULL;
305 ctx->shm.ofs = 0;
306 ctx->shm.virt = NULL;
307 }
308} 248}
309 249
310int s5p_mfc_alloc_dev_context_buffer_v5(struct s5p_mfc_dev *dev) 250int s5p_mfc_alloc_dev_context_buffer_v5(struct s5p_mfc_dev *dev)
@@ -443,10 +383,10 @@ int s5p_mfc_set_dec_frame_buffer_v5(struct s5p_mfc_ctx *ctx)
443 size_t buf_addr1, buf_addr2; 383 size_t buf_addr1, buf_addr2;
444 int buf_size1, buf_size2; 384 int buf_size1, buf_size2;
445 385
446 buf_addr1 = ctx->bank1_phys; 386 buf_addr1 = ctx->bank1.dma;
447 buf_size1 = ctx->bank1_size; 387 buf_size1 = ctx->bank1.size;
448 buf_addr2 = ctx->bank2_phys; 388 buf_addr2 = ctx->bank2.dma;
449 buf_size2 = ctx->bank2_size; 389 buf_size2 = ctx->bank2.size;
450 dpb = mfc_read(dev, S5P_FIMV_SI_CH0_DPB_CONF_CTRL) & 390 dpb = mfc_read(dev, S5P_FIMV_SI_CH0_DPB_CONF_CTRL) &
451 ~S5P_FIMV_DPB_COUNT_MASK; 391 ~S5P_FIMV_DPB_COUNT_MASK;
452 mfc_write(dev, ctx->total_dpb_count | dpb, 392 mfc_write(dev, ctx->total_dpb_count | dpb,
@@ -523,7 +463,6 @@ int s5p_mfc_set_dec_frame_buffer_v5(struct s5p_mfc_ctx *ctx)
523 mfc_err("Unknown codec for decoding (%x)\n", 463 mfc_err("Unknown codec for decoding (%x)\n",
524 ctx->codec_mode); 464 ctx->codec_mode);
525 return -EINVAL; 465 return -EINVAL;
526 break;
527 } 466 }
528 frame_size = ctx->luma_size; 467 frame_size = ctx->luma_size;
529 frame_size_ch = ctx->chroma_size; 468 frame_size_ch = ctx->chroma_size;
@@ -607,10 +546,10 @@ int s5p_mfc_set_enc_ref_buffer_v5(struct s5p_mfc_ctx *ctx)
607 unsigned int guard_width, guard_height; 546 unsigned int guard_width, guard_height;
608 int i; 547 int i;
609 548
610 buf_addr1 = ctx->bank1_phys; 549 buf_addr1 = ctx->bank1.dma;
611 buf_size1 = ctx->bank1_size; 550 buf_size1 = ctx->bank1.size;
612 buf_addr2 = ctx->bank2_phys; 551 buf_addr2 = ctx->bank2.dma;
613 buf_size2 = ctx->bank2_size; 552 buf_size2 = ctx->bank2.size;
614 enc_ref_y_size = ALIGN(ctx->img_width, S5P_FIMV_NV12MT_HALIGN) 553 enc_ref_y_size = ALIGN(ctx->img_width, S5P_FIMV_NV12MT_HALIGN)
615 * ALIGN(ctx->img_height, S5P_FIMV_NV12MT_VALIGN); 554 * ALIGN(ctx->img_height, S5P_FIMV_NV12MT_VALIGN);
616 enc_ref_y_size = ALIGN(enc_ref_y_size, S5P_FIMV_NV12MT_SALIGN); 555 enc_ref_y_size = ALIGN(enc_ref_y_size, S5P_FIMV_NV12MT_SALIGN);
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
index 3a8cfd9fc1bd..beb6dbacebd9 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
@@ -73,6 +73,7 @@ int s5p_mfc_alloc_codec_buffers_v6(struct s5p_mfc_ctx *ctx)
73{ 73{
74 struct s5p_mfc_dev *dev = ctx->dev; 74 struct s5p_mfc_dev *dev = ctx->dev;
75 unsigned int mb_width, mb_height; 75 unsigned int mb_width, mb_height;
76 int ret;
76 77
77 mb_width = MB_WIDTH(ctx->img_width); 78 mb_width = MB_WIDTH(ctx->img_width);
78 mb_height = MB_HEIGHT(ctx->img_height); 79 mb_height = MB_HEIGHT(ctx->img_height);
@@ -112,7 +113,7 @@ int s5p_mfc_alloc_codec_buffers_v6(struct s5p_mfc_ctx *ctx)
112 mb_height); 113 mb_height);
113 ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size, 114 ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
114 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6); 115 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
115 ctx->bank1_size = 116 ctx->bank1.size =
116 ctx->scratch_buf_size + 117 ctx->scratch_buf_size +
117 (ctx->mv_count * ctx->mv_size); 118 (ctx->mv_count * ctx->mv_size);
118 break; 119 break;
@@ -123,7 +124,7 @@ int s5p_mfc_alloc_codec_buffers_v6(struct s5p_mfc_ctx *ctx)
123 mb_height); 124 mb_height);
124 ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size, 125 ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
125 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6); 126 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
126 ctx->bank1_size = ctx->scratch_buf_size; 127 ctx->bank1.size = ctx->scratch_buf_size;
127 break; 128 break;
128 case S5P_MFC_CODEC_VC1RCV_DEC: 129 case S5P_MFC_CODEC_VC1RCV_DEC:
129 case S5P_MFC_CODEC_VC1_DEC: 130 case S5P_MFC_CODEC_VC1_DEC:
@@ -133,11 +134,11 @@ int s5p_mfc_alloc_codec_buffers_v6(struct s5p_mfc_ctx *ctx)
133 mb_height); 134 mb_height);
134 ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size, 135 ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
135 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6); 136 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
136 ctx->bank1_size = ctx->scratch_buf_size; 137 ctx->bank1.size = ctx->scratch_buf_size;
137 break; 138 break;
138 case S5P_MFC_CODEC_MPEG2_DEC: 139 case S5P_MFC_CODEC_MPEG2_DEC:
139 ctx->bank1_size = 0; 140 ctx->bank1.size = 0;
140 ctx->bank2_size = 0; 141 ctx->bank2.size = 0;
141 break; 142 break;
142 case S5P_MFC_CODEC_H263_DEC: 143 case S5P_MFC_CODEC_H263_DEC:
143 ctx->scratch_buf_size = 144 ctx->scratch_buf_size =
@@ -146,7 +147,7 @@ int s5p_mfc_alloc_codec_buffers_v6(struct s5p_mfc_ctx *ctx)
146 mb_height); 147 mb_height);
147 ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size, 148 ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
148 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6); 149 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
149 ctx->bank1_size = ctx->scratch_buf_size; 150 ctx->bank1.size = ctx->scratch_buf_size;
150 break; 151 break;
151 case S5P_MFC_CODEC_VP8_DEC: 152 case S5P_MFC_CODEC_VP8_DEC:
152 ctx->scratch_buf_size = 153 ctx->scratch_buf_size =
@@ -155,7 +156,7 @@ int s5p_mfc_alloc_codec_buffers_v6(struct s5p_mfc_ctx *ctx)
155 mb_height); 156 mb_height);
156 ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size, 157 ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
157 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6); 158 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
158 ctx->bank1_size = ctx->scratch_buf_size; 159 ctx->bank1.size = ctx->scratch_buf_size;
159 break; 160 break;
160 case S5P_MFC_CODEC_H264_ENC: 161 case S5P_MFC_CODEC_H264_ENC:
161 ctx->scratch_buf_size = 162 ctx->scratch_buf_size =
@@ -164,11 +165,11 @@ int s5p_mfc_alloc_codec_buffers_v6(struct s5p_mfc_ctx *ctx)
164 mb_height); 165 mb_height);
165 ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size, 166 ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
166 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6); 167 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
167 ctx->bank1_size = 168 ctx->bank1.size =
168 ctx->scratch_buf_size + ctx->tmv_buffer_size + 169 ctx->scratch_buf_size + ctx->tmv_buffer_size +
169 (ctx->dpb_count * (ctx->luma_dpb_size + 170 (ctx->dpb_count * (ctx->luma_dpb_size +
170 ctx->chroma_dpb_size + ctx->me_buffer_size)); 171 ctx->chroma_dpb_size + ctx->me_buffer_size));
171 ctx->bank2_size = 0; 172 ctx->bank2.size = 0;
172 break; 173 break;
173 case S5P_MFC_CODEC_MPEG4_ENC: 174 case S5P_MFC_CODEC_MPEG4_ENC:
174 case S5P_MFC_CODEC_H263_ENC: 175 case S5P_MFC_CODEC_H263_ENC:
@@ -178,28 +179,24 @@ int s5p_mfc_alloc_codec_buffers_v6(struct s5p_mfc_ctx *ctx)
178 mb_height); 179 mb_height);
179 ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size, 180 ctx->scratch_buf_size = ALIGN(ctx->scratch_buf_size,
180 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6); 181 S5P_FIMV_SCRATCH_BUFFER_ALIGN_V6);
181 ctx->bank1_size = 182 ctx->bank1.size =
182 ctx->scratch_buf_size + ctx->tmv_buffer_size + 183 ctx->scratch_buf_size + ctx->tmv_buffer_size +
183 (ctx->dpb_count * (ctx->luma_dpb_size + 184 (ctx->dpb_count * (ctx->luma_dpb_size +
184 ctx->chroma_dpb_size + ctx->me_buffer_size)); 185 ctx->chroma_dpb_size + ctx->me_buffer_size));
185 ctx->bank2_size = 0; 186 ctx->bank2.size = 0;
186 break; 187 break;
187 default: 188 default:
188 break; 189 break;
189 } 190 }
190 191
191 /* Allocate only if memory from bank 1 is necessary */ 192 /* Allocate only if memory from bank 1 is necessary */
192 if (ctx->bank1_size > 0) { 193 if (ctx->bank1.size > 0) {
193 ctx->bank1_buf = vb2_dma_contig_memops.alloc( 194 ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, &ctx->bank1);
194 dev->alloc_ctx[MFC_BANK1_ALLOC_CTX], ctx->bank1_size); 195 if (ret) {
195 if (IS_ERR(ctx->bank1_buf)) { 196 mfc_err("Failed to allocate Bank1 memory\n");
196 ctx->bank1_buf = 0; 197 return ret;
197 pr_err("Buf alloc for decoding failed (port A)\n");
198 return -ENOMEM;
199 } 198 }
200 ctx->bank1_phys = s5p_mfc_mem_cookie( 199 BUG_ON(ctx->bank1.dma & ((1 << MFC_BANK1_ALIGN_ORDER) - 1));
201 dev->alloc_ctx[MFC_BANK1_ALLOC_CTX], ctx->bank1_buf);
202 BUG_ON(ctx->bank1_phys & ((1 << MFC_BANK1_ALIGN_ORDER) - 1));
203 } 200 }
204 201
205 return 0; 202 return 0;
@@ -208,12 +205,7 @@ int s5p_mfc_alloc_codec_buffers_v6(struct s5p_mfc_ctx *ctx)
208/* Release buffers allocated for codec */ 205/* Release buffers allocated for codec */
209void s5p_mfc_release_codec_buffers_v6(struct s5p_mfc_ctx *ctx) 206void s5p_mfc_release_codec_buffers_v6(struct s5p_mfc_ctx *ctx)
210{ 207{
211 if (ctx->bank1_buf) { 208 s5p_mfc_release_priv_buf(ctx->dev->mem_dev_l, &ctx->bank1);
212 vb2_dma_contig_memops.put(ctx->bank1_buf);
213 ctx->bank1_buf = 0;
214 ctx->bank1_phys = 0;
215 ctx->bank1_size = 0;
216 }
217} 209}
218 210
219/* Allocate memory for instance data buffer */ 211/* Allocate memory for instance data buffer */
@@ -221,6 +213,7 @@ int s5p_mfc_alloc_instance_buffer_v6(struct s5p_mfc_ctx *ctx)
221{ 213{
222 struct s5p_mfc_dev *dev = ctx->dev; 214 struct s5p_mfc_dev *dev = ctx->dev;
223 struct s5p_mfc_buf_size_v6 *buf_size = dev->variant->buf_size->priv; 215 struct s5p_mfc_buf_size_v6 *buf_size = dev->variant->buf_size->priv;
216 int ret;
224 217
225 mfc_debug_enter(); 218 mfc_debug_enter();
226 219
@@ -250,25 +243,10 @@ int s5p_mfc_alloc_instance_buffer_v6(struct s5p_mfc_ctx *ctx)
250 break; 243 break;
251 } 244 }
252 245
253 ctx->ctx.alloc = vb2_dma_contig_memops.alloc( 246 ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, &ctx->ctx);
254 dev->alloc_ctx[MFC_BANK1_ALLOC_CTX], ctx->ctx.size); 247 if (ret) {
255 if (IS_ERR(ctx->ctx.alloc)) { 248 mfc_err("Failed to allocate instance buffer\n");
256 mfc_err("Allocating context buffer failed.\n"); 249 return ret;
257 return PTR_ERR(ctx->ctx.alloc);
258 }
259
260 ctx->ctx.dma = s5p_mfc_mem_cookie(
261 dev->alloc_ctx[MFC_BANK1_ALLOC_CTX], ctx->ctx.alloc);
262
263 ctx->ctx.virt = vb2_dma_contig_memops.vaddr(ctx->ctx.alloc);
264 if (!ctx->ctx.virt) {
265 vb2_dma_contig_memops.put(ctx->ctx.alloc);
266 ctx->ctx.alloc = NULL;
267 ctx->ctx.dma = 0;
268 ctx->ctx.virt = NULL;
269
270 mfc_err("Remapping context buffer failed.\n");
271 return -ENOMEM;
272 } 250 }
273 251
274 memset(ctx->ctx.virt, 0, ctx->ctx.size); 252 memset(ctx->ctx.virt, 0, ctx->ctx.size);
@@ -282,44 +260,22 @@ int s5p_mfc_alloc_instance_buffer_v6(struct s5p_mfc_ctx *ctx)
282/* Release instance buffer */ 260/* Release instance buffer */
283void s5p_mfc_release_instance_buffer_v6(struct s5p_mfc_ctx *ctx) 261void s5p_mfc_release_instance_buffer_v6(struct s5p_mfc_ctx *ctx)
284{ 262{
285 mfc_debug_enter(); 263 s5p_mfc_release_priv_buf(ctx->dev->mem_dev_l, &ctx->ctx);
286
287 if (ctx->ctx.alloc) {
288 vb2_dma_contig_memops.put(ctx->ctx.alloc);
289 ctx->ctx.alloc = NULL;
290 ctx->ctx.dma = 0;
291 ctx->ctx.virt = NULL;
292 }
293
294 mfc_debug_leave();
295} 264}
296 265
297/* Allocate context buffers for SYS_INIT */ 266/* Allocate context buffers for SYS_INIT */
298int s5p_mfc_alloc_dev_context_buffer_v6(struct s5p_mfc_dev *dev) 267int s5p_mfc_alloc_dev_context_buffer_v6(struct s5p_mfc_dev *dev)
299{ 268{
300 struct s5p_mfc_buf_size_v6 *buf_size = dev->variant->buf_size->priv; 269 struct s5p_mfc_buf_size_v6 *buf_size = dev->variant->buf_size->priv;
270 int ret;
301 271
302 mfc_debug_enter(); 272 mfc_debug_enter();
303 273
304 dev->ctx_buf.alloc = vb2_dma_contig_memops.alloc( 274 dev->ctx_buf.size = buf_size->dev_ctx;
305 dev->alloc_ctx[MFC_BANK1_ALLOC_CTX], buf_size->dev_ctx); 275 ret = s5p_mfc_alloc_priv_buf(dev->mem_dev_l, &dev->ctx_buf);
306 if (IS_ERR(dev->ctx_buf.alloc)) { 276 if (ret) {
307 mfc_err("Allocating DESC buffer failed.\n"); 277 mfc_err("Failed to allocate device context buffer\n");
308 return PTR_ERR(dev->ctx_buf.alloc); 278 return ret;
309 }
310
311 dev->ctx_buf.dma = s5p_mfc_mem_cookie(
312 dev->alloc_ctx[MFC_BANK1_ALLOC_CTX],
313 dev->ctx_buf.alloc);
314
315 dev->ctx_buf.virt = vb2_dma_contig_memops.vaddr(dev->ctx_buf.alloc);
316 if (!dev->ctx_buf.virt) {
317 vb2_dma_contig_memops.put(dev->ctx_buf.alloc);
318 dev->ctx_buf.alloc = NULL;
319 dev->ctx_buf.dma = 0;
320
321 mfc_err("Remapping DESC buffer failed.\n");
322 return -ENOMEM;
323 } 279 }
324 280
325 memset(dev->ctx_buf.virt, 0, buf_size->dev_ctx); 281 memset(dev->ctx_buf.virt, 0, buf_size->dev_ctx);
@@ -333,12 +289,7 @@ int s5p_mfc_alloc_dev_context_buffer_v6(struct s5p_mfc_dev *dev)
333/* Release context buffers for SYS_INIT */ 289/* Release context buffers for SYS_INIT */
334void s5p_mfc_release_dev_context_buffer_v6(struct s5p_mfc_dev *dev) 290void s5p_mfc_release_dev_context_buffer_v6(struct s5p_mfc_dev *dev)
335{ 291{
336 if (dev->ctx_buf.alloc) { 292 s5p_mfc_release_priv_buf(dev->mem_dev_l, &dev->ctx_buf);
337 vb2_dma_contig_memops.put(dev->ctx_buf.alloc);
338 dev->ctx_buf.alloc = NULL;
339 dev->ctx_buf.dma = 0;
340 dev->ctx_buf.virt = NULL;
341 }
342} 293}
343 294
344static int calc_plane(int width, int height) 295static int calc_plane(int width, int height)
@@ -417,8 +368,8 @@ int s5p_mfc_set_dec_frame_buffer_v6(struct s5p_mfc_ctx *ctx)
417 int buf_size1; 368 int buf_size1;
418 int align_gap; 369 int align_gap;
419 370
420 buf_addr1 = ctx->bank1_phys; 371 buf_addr1 = ctx->bank1.dma;
421 buf_size1 = ctx->bank1_size; 372 buf_size1 = ctx->bank1.size;
422 373
423 mfc_debug(2, "Buf1: %p (%d)\n", (void *)buf_addr1, buf_size1); 374 mfc_debug(2, "Buf1: %p (%d)\n", (void *)buf_addr1, buf_size1);
424 mfc_debug(2, "Total DPB COUNT: %d\n", ctx->total_dpb_count); 375 mfc_debug(2, "Total DPB COUNT: %d\n", ctx->total_dpb_count);
@@ -535,13 +486,13 @@ void s5p_mfc_get_enc_frame_buffer_v6(struct s5p_mfc_ctx *ctx,
535int s5p_mfc_set_enc_ref_buffer_v6(struct s5p_mfc_ctx *ctx) 486int s5p_mfc_set_enc_ref_buffer_v6(struct s5p_mfc_ctx *ctx)
536{ 487{
537 struct s5p_mfc_dev *dev = ctx->dev; 488 struct s5p_mfc_dev *dev = ctx->dev;
538 size_t buf_addr1, buf_size1; 489 size_t buf_addr1;
539 int i; 490 int i, buf_size1;
540 491
541 mfc_debug_enter(); 492 mfc_debug_enter();
542 493
543 buf_addr1 = ctx->bank1_phys; 494 buf_addr1 = ctx->bank1.dma;
544 buf_size1 = ctx->bank1_size; 495 buf_size1 = ctx->bank1.size;
545 496
546 mfc_debug(2, "Buf1: %p (%d)\n", (void *)buf_addr1, buf_size1); 497 mfc_debug(2, "Buf1: %p (%d)\n", (void *)buf_addr1, buf_size1);
547 498
@@ -1253,12 +1204,14 @@ int s5p_mfc_init_decode_v6(struct s5p_mfc_ctx *ctx)
1253static inline void s5p_mfc_set_flush(struct s5p_mfc_ctx *ctx, int flush) 1204static inline void s5p_mfc_set_flush(struct s5p_mfc_ctx *ctx, int flush)
1254{ 1205{
1255 struct s5p_mfc_dev *dev = ctx->dev; 1206 struct s5p_mfc_dev *dev = ctx->dev;
1256 unsigned int dpb; 1207
1257 if (flush) 1208 if (flush) {
1258 dpb = READL(S5P_FIMV_SI_CH0_DPB_CONF_CTRL) | (1 << 14); 1209 dev->curr_ctx = ctx->num;
1259 else 1210 s5p_mfc_clean_ctx_int_flags(ctx);
1260 dpb = READL(S5P_FIMV_SI_CH0_DPB_CONF_CTRL) & ~(1 << 14); 1211 WRITEL(ctx->inst_no, S5P_FIMV_INSTANCE_ID_V6);
1261 WRITEL(dpb, S5P_FIMV_SI_CH0_DPB_CONF_CTRL); 1212 s5p_mfc_hw_call(dev->mfc_cmds, cmd_host2risc, dev,
1213 S5P_FIMV_H2R_CMD_FLUSH_V6, NULL);
1214 }
1262} 1215}
1263 1216
1264/* Decode a single frame */ 1217/* Decode a single frame */
@@ -1408,7 +1361,6 @@ static inline int s5p_mfc_run_dec_frame(struct s5p_mfc_ctx *ctx)
1408 struct s5p_mfc_buf *temp_vb; 1361 struct s5p_mfc_buf *temp_vb;
1409 unsigned long flags; 1362 unsigned long flags;
1410 int last_frame = 0; 1363 int last_frame = 0;
1411 unsigned int index;
1412 1364
1413 spin_lock_irqsave(&dev->irqlock, flags); 1365 spin_lock_irqsave(&dev->irqlock, flags);
1414 1366
@@ -1427,8 +1379,6 @@ static inline int s5p_mfc_run_dec_frame(struct s5p_mfc_ctx *ctx)
1427 temp_vb->b->v4l2_planes[0].bytesused); 1379 temp_vb->b->v4l2_planes[0].bytesused);
1428 spin_unlock_irqrestore(&dev->irqlock, flags); 1380 spin_unlock_irqrestore(&dev->irqlock, flags);
1429 1381
1430 index = temp_vb->b->v4l2_buf.index;
1431
1432 dev->curr_ctx = ctx->num; 1382 dev->curr_ctx = ctx->num;
1433 s5p_mfc_clean_ctx_int_flags(ctx); 1383 s5p_mfc_clean_ctx_int_flags(ctx);
1434 if (temp_vb->b->v4l2_planes[0].bytesused == 0) { 1384 if (temp_vb->b->v4l2_planes[0].bytesused == 0) {
@@ -1452,7 +1402,6 @@ static inline int s5p_mfc_run_enc_frame(struct s5p_mfc_ctx *ctx)
1452 unsigned int src_y_size, src_c_size; 1402 unsigned int src_y_size, src_c_size;
1453 */ 1403 */
1454 unsigned int dst_size; 1404 unsigned int dst_size;
1455 unsigned int index;
1456 1405
1457 spin_lock_irqsave(&dev->irqlock, flags); 1406 spin_lock_irqsave(&dev->irqlock, flags);
1458 1407
@@ -1487,8 +1436,6 @@ static inline int s5p_mfc_run_enc_frame(struct s5p_mfc_ctx *ctx)
1487 1436
1488 spin_unlock_irqrestore(&dev->irqlock, flags); 1437 spin_unlock_irqrestore(&dev->irqlock, flags);
1489 1438
1490 index = src_mb->b->v4l2_buf.index;
1491
1492 dev->curr_ctx = ctx->num; 1439 dev->curr_ctx = ctx->num;
1493 s5p_mfc_clean_ctx_int_flags(ctx); 1440 s5p_mfc_clean_ctx_int_flags(ctx);
1494 s5p_mfc_encode_one_frame_v6(ctx); 1441 s5p_mfc_encode_one_frame_v6(ctx);
@@ -1656,6 +1603,9 @@ void s5p_mfc_try_run_v6(struct s5p_mfc_dev *dev)
1656 case MFCINST_HEAD_PARSED: 1603 case MFCINST_HEAD_PARSED:
1657 ret = s5p_mfc_run_init_dec_buffers(ctx); 1604 ret = s5p_mfc_run_init_dec_buffers(ctx);
1658 break; 1605 break;
1606 case MFCINST_FLUSH:
1607 s5p_mfc_set_flush(ctx, ctx->dpb_flush_flag);
1608 break;
1659 case MFCINST_RES_CHANGE_INIT: 1609 case MFCINST_RES_CHANGE_INIT:
1660 s5p_mfc_run_dec_last_frames(ctx); 1610 s5p_mfc_run_dec_last_frames(ctx);
1661 break; 1611 break;
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_pm.c b/drivers/media/platform/s5p-mfc/s5p_mfc_pm.c
index 2895333866fc..6aa38a56aaf2 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_pm.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_pm.c
@@ -46,7 +46,7 @@ int s5p_mfc_init_pm(struct s5p_mfc_dev *dev)
46 46
47 ret = clk_prepare(pm->clock_gate); 47 ret = clk_prepare(pm->clock_gate);
48 if (ret) { 48 if (ret) {
49 mfc_err("Failed to preapre clock-gating control\n"); 49 mfc_err("Failed to prepare clock-gating control\n");
50 goto err_p_ip_clk; 50 goto err_p_ip_clk;
51 } 51 }
52 52
diff --git a/drivers/media/platform/s5p-tv/hdmi_drv.c b/drivers/media/platform/s5p-tv/hdmi_drv.c
index 7c1116c73bf3..8de1b3dce459 100644
--- a/drivers/media/platform/s5p-tv/hdmi_drv.c
+++ b/drivers/media/platform/s5p-tv/hdmi_drv.c
@@ -656,7 +656,7 @@ static int hdmi_g_mbus_fmt(struct v4l2_subdev *sd,
656 dev_dbg(hdev->dev, "%s\n", __func__); 656 dev_dbg(hdev->dev, "%s\n", __func__);
657 if (!hdev->cur_conf) 657 if (!hdev->cur_conf)
658 return -EINVAL; 658 return -EINVAL;
659 memset(fmt, 0, sizeof *fmt); 659 memset(fmt, 0, sizeof(*fmt));
660 fmt->width = t->hact.end - t->hact.beg; 660 fmt->width = t->hact.end - t->hact.beg;
661 fmt->height = t->vact[0].end - t->vact[0].beg; 661 fmt->height = t->vact[0].end - t->vact[0].beg;
662 fmt->code = V4L2_MBUS_FMT_FIXED; /* means RGB888 */ 662 fmt->code = V4L2_MBUS_FMT_FIXED; /* means RGB888 */
@@ -760,7 +760,7 @@ static void hdmi_resources_cleanup(struct hdmi_device *hdev)
760 clk_put(res->sclk_hdmi); 760 clk_put(res->sclk_hdmi);
761 if (!IS_ERR_OR_NULL(res->hdmi)) 761 if (!IS_ERR_OR_NULL(res->hdmi))
762 clk_put(res->hdmi); 762 clk_put(res->hdmi);
763 memset(res, 0, sizeof *res); 763 memset(res, 0, sizeof(*res));
764} 764}
765 765
766static int hdmi_resources_init(struct hdmi_device *hdev) 766static int hdmi_resources_init(struct hdmi_device *hdev)
@@ -777,31 +777,31 @@ static int hdmi_resources_init(struct hdmi_device *hdev)
777 777
778 dev_dbg(dev, "HDMI resource init\n"); 778 dev_dbg(dev, "HDMI resource init\n");
779 779
780 memset(res, 0, sizeof *res); 780 memset(res, 0, sizeof(*res));
781 /* get clocks, power */ 781 /* get clocks, power */
782 782
783 res->hdmi = clk_get(dev, "hdmi"); 783 res->hdmi = clk_get(dev, "hdmi");
784 if (IS_ERR_OR_NULL(res->hdmi)) { 784 if (IS_ERR(res->hdmi)) {
785 dev_err(dev, "failed to get clock 'hdmi'\n"); 785 dev_err(dev, "failed to get clock 'hdmi'\n");
786 goto fail; 786 goto fail;
787 } 787 }
788 res->sclk_hdmi = clk_get(dev, "sclk_hdmi"); 788 res->sclk_hdmi = clk_get(dev, "sclk_hdmi");
789 if (IS_ERR_OR_NULL(res->sclk_hdmi)) { 789 if (IS_ERR(res->sclk_hdmi)) {
790 dev_err(dev, "failed to get clock 'sclk_hdmi'\n"); 790 dev_err(dev, "failed to get clock 'sclk_hdmi'\n");
791 goto fail; 791 goto fail;
792 } 792 }
793 res->sclk_pixel = clk_get(dev, "sclk_pixel"); 793 res->sclk_pixel = clk_get(dev, "sclk_pixel");
794 if (IS_ERR_OR_NULL(res->sclk_pixel)) { 794 if (IS_ERR(res->sclk_pixel)) {
795 dev_err(dev, "failed to get clock 'sclk_pixel'\n"); 795 dev_err(dev, "failed to get clock 'sclk_pixel'\n");
796 goto fail; 796 goto fail;
797 } 797 }
798 res->sclk_hdmiphy = clk_get(dev, "sclk_hdmiphy"); 798 res->sclk_hdmiphy = clk_get(dev, "sclk_hdmiphy");
799 if (IS_ERR_OR_NULL(res->sclk_hdmiphy)) { 799 if (IS_ERR(res->sclk_hdmiphy)) {
800 dev_err(dev, "failed to get clock 'sclk_hdmiphy'\n"); 800 dev_err(dev, "failed to get clock 'sclk_hdmiphy'\n");
801 goto fail; 801 goto fail;
802 } 802 }
803 res->hdmiphy = clk_get(dev, "hdmiphy"); 803 res->hdmiphy = clk_get(dev, "hdmiphy");
804 if (IS_ERR_OR_NULL(res->hdmiphy)) { 804 if (IS_ERR(res->hdmiphy)) {
805 dev_err(dev, "failed to get clock 'hdmiphy'\n"); 805 dev_err(dev, "failed to get clock 'hdmiphy'\n");
806 goto fail; 806 goto fail;
807 } 807 }
@@ -955,7 +955,7 @@ static int hdmi_probe(struct platform_device *pdev)
955 v4l2_subdev_init(sd, &hdmi_sd_ops); 955 v4l2_subdev_init(sd, &hdmi_sd_ops);
956 sd->owner = THIS_MODULE; 956 sd->owner = THIS_MODULE;
957 957
958 strlcpy(sd->name, "s5p-hdmi", sizeof sd->name); 958 strlcpy(sd->name, "s5p-hdmi", sizeof(sd->name));
959 hdmi_dev->cur_preset = HDMI_DEFAULT_PRESET; 959 hdmi_dev->cur_preset = HDMI_DEFAULT_PRESET;
960 /* FIXME: missing fail preset is not supported */ 960 /* FIXME: missing fail preset is not supported */
961 hdmi_dev->cur_conf = hdmi_preset2timings(hdmi_dev->cur_preset); 961 hdmi_dev->cur_conf = hdmi_preset2timings(hdmi_dev->cur_preset);
diff --git a/drivers/media/platform/s5p-tv/hdmiphy_drv.c b/drivers/media/platform/s5p-tv/hdmiphy_drv.c
index 06b5d2dbb2d9..80717cec76ae 100644
--- a/drivers/media/platform/s5p-tv/hdmiphy_drv.c
+++ b/drivers/media/platform/s5p-tv/hdmiphy_drv.c
@@ -284,7 +284,7 @@ static int hdmiphy_probe(struct i2c_client *client,
284{ 284{
285 struct hdmiphy_ctx *ctx; 285 struct hdmiphy_ctx *ctx;
286 286
287 ctx = kzalloc(sizeof *ctx, GFP_KERNEL); 287 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
288 if (!ctx) 288 if (!ctx)
289 return -ENOMEM; 289 return -ENOMEM;
290 290
diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
index b671e20e9318..04e6490a45be 100644
--- a/drivers/media/platform/s5p-tv/mixer.h
+++ b/drivers/media/platform/s5p-tv/mixer.h
@@ -19,6 +19,7 @@
19#endif 19#endif
20 20
21#include <linux/fb.h> 21#include <linux/fb.h>
22#include <linux/irqreturn.h>
22#include <linux/kernel.h> 23#include <linux/kernel.h>
23#include <linux/spinlock.h> 24#include <linux/spinlock.h>
24#include <linux/wait.h> 25#include <linux/wait.h>
diff --git a/drivers/media/platform/s5p-tv/mixer_drv.c b/drivers/media/platform/s5p-tv/mixer_drv.c
index 02faea03aa7d..5733033a6ead 100644
--- a/drivers/media/platform/s5p-tv/mixer_drv.c
+++ b/drivers/media/platform/s5p-tv/mixer_drv.c
@@ -240,27 +240,27 @@ static int mxr_acquire_clocks(struct mxr_device *mdev)
240 struct device *dev = mdev->dev; 240 struct device *dev = mdev->dev;
241 241
242 res->mixer = clk_get(dev, "mixer"); 242 res->mixer = clk_get(dev, "mixer");
243 if (IS_ERR_OR_NULL(res->mixer)) { 243 if (IS_ERR(res->mixer)) {
244 mxr_err(mdev, "failed to get clock 'mixer'\n"); 244 mxr_err(mdev, "failed to get clock 'mixer'\n");
245 goto fail; 245 goto fail;
246 } 246 }
247 res->vp = clk_get(dev, "vp"); 247 res->vp = clk_get(dev, "vp");
248 if (IS_ERR_OR_NULL(res->vp)) { 248 if (IS_ERR(res->vp)) {
249 mxr_err(mdev, "failed to get clock 'vp'\n"); 249 mxr_err(mdev, "failed to get clock 'vp'\n");
250 goto fail; 250 goto fail;
251 } 251 }
252 res->sclk_mixer = clk_get(dev, "sclk_mixer"); 252 res->sclk_mixer = clk_get(dev, "sclk_mixer");
253 if (IS_ERR_OR_NULL(res->sclk_mixer)) { 253 if (IS_ERR(res->sclk_mixer)) {
254 mxr_err(mdev, "failed to get clock 'sclk_mixer'\n"); 254 mxr_err(mdev, "failed to get clock 'sclk_mixer'\n");
255 goto fail; 255 goto fail;
256 } 256 }
257 res->sclk_hdmi = clk_get(dev, "sclk_hdmi"); 257 res->sclk_hdmi = clk_get(dev, "sclk_hdmi");
258 if (IS_ERR_OR_NULL(res->sclk_hdmi)) { 258 if (IS_ERR(res->sclk_hdmi)) {
259 mxr_err(mdev, "failed to get clock 'sclk_hdmi'\n"); 259 mxr_err(mdev, "failed to get clock 'sclk_hdmi'\n");
260 goto fail; 260 goto fail;
261 } 261 }
262 res->sclk_dac = clk_get(dev, "sclk_dac"); 262 res->sclk_dac = clk_get(dev, "sclk_dac");
263 if (IS_ERR_OR_NULL(res->sclk_dac)) { 263 if (IS_ERR(res->sclk_dac)) {
264 mxr_err(mdev, "failed to get clock 'sclk_dac'\n"); 264 mxr_err(mdev, "failed to get clock 'sclk_dac'\n");
265 goto fail; 265 goto fail;
266 } 266 }
@@ -298,7 +298,7 @@ static void mxr_release_resources(struct mxr_device *mdev)
298{ 298{
299 mxr_release_clocks(mdev); 299 mxr_release_clocks(mdev);
300 mxr_release_plat_resources(mdev); 300 mxr_release_plat_resources(mdev);
301 memset(&mdev->res, 0, sizeof mdev->res); 301 memset(&mdev->res, 0, sizeof(mdev->res));
302} 302}
303 303
304static void mxr_release_layers(struct mxr_device *mdev) 304static void mxr_release_layers(struct mxr_device *mdev)
@@ -382,7 +382,7 @@ static int mxr_probe(struct platform_device *pdev)
382 /* mdev does not exist yet so no mxr_dbg is used */ 382 /* mdev does not exist yet so no mxr_dbg is used */
383 dev_info(dev, "probe start\n"); 383 dev_info(dev, "probe start\n");
384 384
385 mdev = kzalloc(sizeof *mdev, GFP_KERNEL); 385 mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
386 if (!mdev) { 386 if (!mdev) {
387 dev_err(dev, "not enough memory.\n"); 387 dev_err(dev, "not enough memory.\n");
388 ret = -ENOMEM; 388 ret = -ENOMEM;
diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
index 3b1670a045f4..b713403024ef 100644
--- a/drivers/media/platform/s5p-tv/mixer_reg.c
+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
@@ -470,11 +470,11 @@ static inline void mxr_reg_vp_filter_set(struct mxr_device *mdev,
470static void mxr_reg_vp_default_filter(struct mxr_device *mdev) 470static void mxr_reg_vp_default_filter(struct mxr_device *mdev)
471{ 471{
472 mxr_reg_vp_filter_set(mdev, VP_POLY8_Y0_LL, 472 mxr_reg_vp_filter_set(mdev, VP_POLY8_Y0_LL,
473 filter_y_horiz_tap8, sizeof filter_y_horiz_tap8); 473 filter_y_horiz_tap8, sizeof(filter_y_horiz_tap8));
474 mxr_reg_vp_filter_set(mdev, VP_POLY4_Y0_LL, 474 mxr_reg_vp_filter_set(mdev, VP_POLY4_Y0_LL,
475 filter_y_vert_tap4, sizeof filter_y_vert_tap4); 475 filter_y_vert_tap4, sizeof(filter_y_vert_tap4));
476 mxr_reg_vp_filter_set(mdev, VP_POLY4_C0_LL, 476 mxr_reg_vp_filter_set(mdev, VP_POLY4_C0_LL,
477 filter_cr_horiz_tap4, sizeof filter_cr_horiz_tap4); 477 filter_cr_horiz_tap4, sizeof(filter_cr_horiz_tap4));
478} 478}
479 479
480static void mxr_reg_mxr_dump(struct mxr_device *mdev) 480static void mxr_reg_mxr_dump(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 1f3b7436511c..82142a2d6d93 100644
--- a/drivers/media/platform/s5p-tv/mixer_video.c
+++ b/drivers/media/platform/s5p-tv/mixer_video.c
@@ -19,6 +19,7 @@
19#include <linux/videodev2.h> 19#include <linux/videodev2.h>
20#include <linux/mm.h> 20#include <linux/mm.h>
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/platform_device.h>
22#include <linux/timer.h> 23#include <linux/timer.h>
23#include <media/videobuf2-dma-contig.h> 24#include <media/videobuf2-dma-contig.h>
24 25
@@ -95,7 +96,7 @@ int mxr_acquire_video(struct mxr_device *mdev,
95 /* trying to register next output */ 96 /* trying to register next output */
96 if (sd == NULL) 97 if (sd == NULL)
97 continue; 98 continue;
98 out = kzalloc(sizeof *out, GFP_KERNEL); 99 out = kzalloc(sizeof(*out), GFP_KERNEL);
99 if (out == NULL) { 100 if (out == NULL) {
100 mxr_err(mdev, "no memory for '%s'\n", 101 mxr_err(mdev, "no memory for '%s'\n",
101 conf->output_name); 102 conf->output_name);
@@ -127,7 +128,7 @@ fail_output:
127 /* kfree is NULL-safe */ 128 /* kfree is NULL-safe */
128 for (i = 0; i < mdev->output_cnt; ++i) 129 for (i = 0; i < mdev->output_cnt; ++i)
129 kfree(mdev->output[i]); 130 kfree(mdev->output[i]);
130 memset(mdev->output, 0, sizeof mdev->output); 131 memset(mdev->output, 0, sizeof(mdev->output));
131 132
132fail_vb2_allocator: 133fail_vb2_allocator:
133 /* freeing allocator context */ 134 /* freeing allocator context */
@@ -160,8 +161,8 @@ static int mxr_querycap(struct file *file, void *priv,
160 161
161 mxr_dbg(layer->mdev, "%s:%d\n", __func__, __LINE__); 162 mxr_dbg(layer->mdev, "%s:%d\n", __func__, __LINE__);
162 163
163 strlcpy(cap->driver, MXR_DRIVER_NAME, sizeof cap->driver); 164 strlcpy(cap->driver, MXR_DRIVER_NAME, sizeof(cap->driver));
164 strlcpy(cap->card, layer->vfd.name, sizeof cap->card); 165 strlcpy(cap->card, layer->vfd.name, sizeof(cap->card));
165 sprintf(cap->bus_info, "%d", layer->idx); 166 sprintf(cap->bus_info, "%d", layer->idx);
166 cap->device_caps = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_OUTPUT_MPLANE; 167 cap->device_caps = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_OUTPUT_MPLANE;
167 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; 168 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
@@ -192,7 +193,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
192 struct mxr_device *mdev = layer->mdev; 193 struct mxr_device *mdev = layer->mdev;
193 struct v4l2_mbus_framefmt mbus_fmt; 194 struct v4l2_mbus_framefmt mbus_fmt;
194 195
195 memset(&layer->geo, 0, sizeof layer->geo); 196 memset(&layer->geo, 0, sizeof(layer->geo));
196 197
197 mxr_get_mbus_fmt(mdev, &mbus_fmt); 198 mxr_get_mbus_fmt(mdev, &mbus_fmt);
198 199
@@ -425,7 +426,7 @@ static int mxr_s_selection(struct file *file, void *fh,
425 struct mxr_geometry tmp; 426 struct mxr_geometry tmp;
426 struct v4l2_rect res; 427 struct v4l2_rect res;
427 428
428 memset(&res, 0, sizeof res); 429 memset(&res, 0, sizeof(res));
429 430
430 mxr_dbg(layer->mdev, "%s: rect: %dx%d@%d,%d\n", __func__, 431 mxr_dbg(layer->mdev, "%s: rect: %dx%d@%d,%d\n", __func__,
431 s->r.width, s->r.height, s->r.left, s->r.top); 432 s->r.width, s->r.height, s->r.left, s->r.top);
@@ -464,7 +465,7 @@ static int mxr_s_selection(struct file *file, void *fh,
464 /* apply change and update geometry if needed */ 465 /* apply change and update geometry if needed */
465 if (target) { 466 if (target) {
466 /* backup current geometry if setup fails */ 467 /* backup current geometry if setup fails */
467 memcpy(&tmp, geo, sizeof tmp); 468 memcpy(&tmp, geo, sizeof(tmp));
468 469
469 /* apply requested selection */ 470 /* apply requested selection */
470 target->x_offset = s->r.left; 471 target->x_offset = s->r.left;
@@ -496,7 +497,7 @@ static int mxr_s_selection(struct file *file, void *fh,
496fail: 497fail:
497 /* restore old geometry, which is not touched if target is NULL */ 498 /* restore old geometry, which is not touched if target is NULL */
498 if (target) 499 if (target)
499 memcpy(geo, &tmp, sizeof tmp); 500 memcpy(geo, &tmp, sizeof(tmp));
500 return -ERANGE; 501 return -ERANGE;
501} 502}
502 503
@@ -1071,7 +1072,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
1071{ 1072{
1072 struct mxr_layer *layer; 1073 struct mxr_layer *layer;
1073 1074
1074 layer = kzalloc(sizeof *layer, GFP_KERNEL); 1075 layer = kzalloc(sizeof(*layer), GFP_KERNEL);
1075 if (layer == NULL) { 1076 if (layer == NULL) {
1076 mxr_err(mdev, "not enough memory for layer.\n"); 1077 mxr_err(mdev, "not enough memory for layer.\n");
1077 goto fail; 1078 goto fail;
diff --git a/drivers/media/platform/s5p-tv/sdo_drv.c b/drivers/media/platform/s5p-tv/sdo_drv.c
index 91a6939a270a..ab6f9ef89423 100644
--- a/drivers/media/platform/s5p-tv/sdo_drv.c
+++ b/drivers/media/platform/s5p-tv/sdo_drv.c
@@ -301,7 +301,7 @@ static int sdo_probe(struct platform_device *pdev)
301 struct clk *sclk_vpll; 301 struct clk *sclk_vpll;
302 302
303 dev_info(dev, "probe start\n"); 303 dev_info(dev, "probe start\n");
304 sdev = devm_kzalloc(&pdev->dev, sizeof *sdev, GFP_KERNEL); 304 sdev = devm_kzalloc(&pdev->dev, sizeof(*sdev), GFP_KERNEL);
305 if (!sdev) { 305 if (!sdev) {
306 dev_err(dev, "not enough memory.\n"); 306 dev_err(dev, "not enough memory.\n");
307 ret = -ENOMEM; 307 ret = -ENOMEM;
@@ -341,47 +341,50 @@ static int sdo_probe(struct platform_device *pdev)
341 341
342 /* acquire clocks */ 342 /* acquire clocks */
343 sdev->sclk_dac = clk_get(dev, "sclk_dac"); 343 sdev->sclk_dac = clk_get(dev, "sclk_dac");
344 if (IS_ERR_OR_NULL(sdev->sclk_dac)) { 344 if (IS_ERR(sdev->sclk_dac)) {
345 dev_err(dev, "failed to get clock 'sclk_dac'\n"); 345 dev_err(dev, "failed to get clock 'sclk_dac'\n");
346 ret = -ENXIO; 346 ret = PTR_ERR(sdev->sclk_dac);
347 goto fail; 347 goto fail;
348 } 348 }
349 sdev->dac = clk_get(dev, "dac"); 349 sdev->dac = clk_get(dev, "dac");
350 if (IS_ERR_OR_NULL(sdev->dac)) { 350 if (IS_ERR(sdev->dac)) {
351 dev_err(dev, "failed to get clock 'dac'\n"); 351 dev_err(dev, "failed to get clock 'dac'\n");
352 ret = -ENXIO; 352 ret = PTR_ERR(sdev->dac);
353 goto fail_sclk_dac; 353 goto fail_sclk_dac;
354 } 354 }
355 sdev->dacphy = clk_get(dev, "dacphy"); 355 sdev->dacphy = clk_get(dev, "dacphy");
356 if (IS_ERR_OR_NULL(sdev->dacphy)) { 356 if (IS_ERR(sdev->dacphy)) {
357 dev_err(dev, "failed to get clock 'dacphy'\n"); 357 dev_err(dev, "failed to get clock 'dacphy'\n");
358 ret = -ENXIO; 358 ret = PTR_ERR(sdev->dacphy);
359 goto fail_dac; 359 goto fail_dac;
360 } 360 }
361 sclk_vpll = clk_get(dev, "sclk_vpll"); 361 sclk_vpll = clk_get(dev, "sclk_vpll");
362 if (IS_ERR_OR_NULL(sclk_vpll)) { 362 if (IS_ERR(sclk_vpll)) {
363 dev_err(dev, "failed to get clock 'sclk_vpll'\n"); 363 dev_err(dev, "failed to get clock 'sclk_vpll'\n");
364 ret = -ENXIO; 364 ret = PTR_ERR(sclk_vpll);
365 goto fail_dacphy; 365 goto fail_dacphy;
366 } 366 }
367 clk_set_parent(sdev->sclk_dac, sclk_vpll); 367 clk_set_parent(sdev->sclk_dac, sclk_vpll);
368 clk_put(sclk_vpll); 368 clk_put(sclk_vpll);
369 sdev->fout_vpll = clk_get(dev, "fout_vpll"); 369 sdev->fout_vpll = clk_get(dev, "fout_vpll");
370 if (IS_ERR_OR_NULL(sdev->fout_vpll)) { 370 if (IS_ERR(sdev->fout_vpll)) {
371 dev_err(dev, "failed to get clock 'fout_vpll'\n"); 371 dev_err(dev, "failed to get clock 'fout_vpll'\n");
372 ret = PTR_ERR(sdev->fout_vpll);
372 goto fail_dacphy; 373 goto fail_dacphy;
373 } 374 }
374 dev_info(dev, "fout_vpll.rate = %lu\n", clk_get_rate(sclk_vpll)); 375 dev_info(dev, "fout_vpll.rate = %lu\n", clk_get_rate(sclk_vpll));
375 376
376 /* acquire regulator */ 377 /* acquire regulator */
377 sdev->vdac = devm_regulator_get(dev, "vdd33a_dac"); 378 sdev->vdac = devm_regulator_get(dev, "vdd33a_dac");
378 if (IS_ERR_OR_NULL(sdev->vdac)) { 379 if (IS_ERR(sdev->vdac)) {
379 dev_err(dev, "failed to get regulator 'vdac'\n"); 380 dev_err(dev, "failed to get regulator 'vdac'\n");
381 ret = PTR_ERR(sdev->vdac);
380 goto fail_fout_vpll; 382 goto fail_fout_vpll;
381 } 383 }
382 sdev->vdet = devm_regulator_get(dev, "vdet"); 384 sdev->vdet = devm_regulator_get(dev, "vdet");
383 if (IS_ERR_OR_NULL(sdev->vdet)) { 385 if (IS_ERR(sdev->vdet)) {
384 dev_err(dev, "failed to get regulator 'vdet'\n"); 386 dev_err(dev, "failed to get regulator 'vdet'\n");
387 ret = PTR_ERR(sdev->vdet);
385 goto fail_fout_vpll; 388 goto fail_fout_vpll;
386 } 389 }
387 390
@@ -394,7 +397,7 @@ static int sdo_probe(struct platform_device *pdev)
394 /* configuration of interface subdevice */ 397 /* configuration of interface subdevice */
395 v4l2_subdev_init(&sdev->sd, &sdo_sd_ops); 398 v4l2_subdev_init(&sdev->sd, &sdo_sd_ops);
396 sdev->sd.owner = THIS_MODULE; 399 sdev->sd.owner = THIS_MODULE;
397 strlcpy(sdev->sd.name, "s5p-sdo", sizeof sdev->sd.name); 400 strlcpy(sdev->sd.name, "s5p-sdo", sizeof(sdev->sd.name));
398 401
399 /* set default format */ 402 /* set default format */
400 sdev->fmt = sdo_find_format(SDO_DEFAULT_STD); 403 sdev->fmt = sdo_find_format(SDO_DEFAULT_STD);
diff --git a/drivers/media/platform/s5p-tv/sii9234_drv.c b/drivers/media/platform/s5p-tv/sii9234_drv.c
index 49191aac9634..d90d2286090b 100644
--- a/drivers/media/platform/s5p-tv/sii9234_drv.c
+++ b/drivers/media/platform/s5p-tv/sii9234_drv.c
@@ -338,7 +338,7 @@ static int sii9234_probe(struct i2c_client *client,
338 } 338 }
339 339
340 ctx->gpio_n_reset = pdata->gpio_n_reset; 340 ctx->gpio_n_reset = pdata->gpio_n_reset;
341 ret = gpio_request(ctx->gpio_n_reset, "MHL_RST"); 341 ret = devm_gpio_request(dev, ctx->gpio_n_reset, "MHL_RST");
342 if (ret) { 342 if (ret) {
343 dev_err(dev, "failed to acquire MHL_RST gpio\n"); 343 dev_err(dev, "failed to acquire MHL_RST gpio\n");
344 return ret; 344 return ret;
@@ -370,7 +370,6 @@ fail_pm_get:
370 370
371fail_pm: 371fail_pm:
372 pm_runtime_disable(dev); 372 pm_runtime_disable(dev);
373 gpio_free(ctx->gpio_n_reset);
374 373
375fail: 374fail:
376 dev_err(dev, "probe failed\n"); 375 dev_err(dev, "probe failed\n");
@@ -381,11 +380,8 @@ fail:
381static int sii9234_remove(struct i2c_client *client) 380static int sii9234_remove(struct i2c_client *client)
382{ 381{
383 struct device *dev = &client->dev; 382 struct device *dev = &client->dev;
384 struct v4l2_subdev *sd = i2c_get_clientdata(client);
385 struct sii9234_context *ctx = sd_to_context(sd);
386 383
387 pm_runtime_disable(dev); 384 pm_runtime_disable(dev);
388 gpio_free(ctx->gpio_n_reset);
389 385
390 dev_info(dev, "remove successful\n"); 386 dev_info(dev, "remove successful\n");
391 387
diff --git a/drivers/media/platform/sh_veu.c b/drivers/media/platform/sh_veu.c
new file mode 100644
index 000000000000..cb54c69d5748
--- /dev/null
+++ b/drivers/media/platform/sh_veu.c
@@ -0,0 +1,1266 @@
1/*
2 * sh-mobile VEU mem2mem driver
3 *
4 * Copyright (C) 2012 Renesas Electronics Corporation
5 * Author: Guennadi Liakhovetski, <g.liakhovetski@gmx.de>
6 * Copyright (C) 2008 Magnus Damm
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the version 2 of the GNU General Public License as
10 * published by the Free Software Foundation
11 */
12
13#include <linux/fs.h>
14#include <linux/kernel.h>
15#include <linux/module.h>
16#include <linux/interrupt.h>
17#include <linux/io.h>
18#include <linux/platform_device.h>
19#include <linux/pm_runtime.h>
20#include <linux/slab.h>
21#include <linux/types.h>
22#include <linux/videodev2.h>
23
24#include <media/v4l2-dev.h>
25#include <media/v4l2-device.h>
26#include <media/v4l2-ioctl.h>
27#include <media/v4l2-mem2mem.h>
28#include <media/videobuf2-dma-contig.h>
29
30#define VEU_STR 0x00 /* start register */
31#define VEU_SWR 0x10 /* src: line length */
32#define VEU_SSR 0x14 /* src: image size */
33#define VEU_SAYR 0x18 /* src: y/rgb plane address */
34#define VEU_SACR 0x1c /* src: c plane address */
35#define VEU_BSSR 0x20 /* bundle mode register */
36#define VEU_EDWR 0x30 /* dst: line length */
37#define VEU_DAYR 0x34 /* dst: y/rgb plane address */
38#define VEU_DACR 0x38 /* dst: c plane address */
39#define VEU_TRCR 0x50 /* transform control */
40#define VEU_RFCR 0x54 /* resize scale */
41#define VEU_RFSR 0x58 /* resize clip */
42#define VEU_ENHR 0x5c /* enhance */
43#define VEU_FMCR 0x70 /* filter mode */
44#define VEU_VTCR 0x74 /* lowpass vertical */
45#define VEU_HTCR 0x78 /* lowpass horizontal */
46#define VEU_APCR 0x80 /* color match */
47#define VEU_ECCR 0x84 /* color replace */
48#define VEU_AFXR 0x90 /* fixed mode */
49#define VEU_SWPR 0x94 /* swap */
50#define VEU_EIER 0xa0 /* interrupt mask */
51#define VEU_EVTR 0xa4 /* interrupt event */
52#define VEU_STAR 0xb0 /* status */
53#define VEU_BSRR 0xb4 /* reset */
54
55#define VEU_MCR00 0x200 /* color conversion matrix coefficient 00 */
56#define VEU_MCR01 0x204 /* color conversion matrix coefficient 01 */
57#define VEU_MCR02 0x208 /* color conversion matrix coefficient 02 */
58#define VEU_MCR10 0x20c /* color conversion matrix coefficient 10 */
59#define VEU_MCR11 0x210 /* color conversion matrix coefficient 11 */
60#define VEU_MCR12 0x214 /* color conversion matrix coefficient 12 */
61#define VEU_MCR20 0x218 /* color conversion matrix coefficient 20 */
62#define VEU_MCR21 0x21c /* color conversion matrix coefficient 21 */
63#define VEU_MCR22 0x220 /* color conversion matrix coefficient 22 */
64#define VEU_COFFR 0x224 /* color conversion offset */
65#define VEU_CBR 0x228 /* color conversion clip */
66
67/*
68 * 4092x4092 max size is the normal case. In some cases it can be reduced to
69 * 2048x2048, in other cases it can be 4092x8188 or even 8188x8188.
70 */
71#define MAX_W 4092
72#define MAX_H 4092
73#define MIN_W 8
74#define MIN_H 8
75#define ALIGN_W 4
76
77/* 3 buffers of 2048 x 1536 - 3 megapixels @ 16bpp */
78#define VIDEO_MEM_LIMIT ALIGN(2048 * 1536 * 2 * 3, 1024 * 1024)
79
80#define MEM2MEM_DEF_TRANSLEN 1
81
82struct sh_veu_dev;
83
84struct sh_veu_file {
85 struct sh_veu_dev *veu_dev;
86 bool cfg_needed;
87};
88
89struct sh_veu_format {
90 char *name;
91 u32 fourcc;
92 unsigned int depth;
93 unsigned int ydepth;
94};
95
96/* video data format */
97struct sh_veu_vfmt {
98 /* Replace with v4l2_rect */
99 struct v4l2_rect frame;
100 unsigned int bytesperline;
101 unsigned int offset_y;
102 unsigned int offset_c;
103 const struct sh_veu_format *fmt;
104};
105
106struct sh_veu_dev {
107 struct v4l2_device v4l2_dev;
108 struct video_device vdev;
109 struct v4l2_m2m_dev *m2m_dev;
110 struct device *dev;
111 struct v4l2_m2m_ctx *m2m_ctx;
112 struct sh_veu_vfmt vfmt_out;
113 struct sh_veu_vfmt vfmt_in;
114 /* Only single user per direction so far */
115 struct sh_veu_file *capture;
116 struct sh_veu_file *output;
117 struct mutex fop_lock;
118 void __iomem *base;
119 struct vb2_alloc_ctx *alloc_ctx;
120 spinlock_t lock;
121 bool is_2h;
122 unsigned int xaction;
123 bool aborting;
124};
125
126enum sh_veu_fmt_idx {
127 SH_VEU_FMT_NV12,
128 SH_VEU_FMT_NV16,
129 SH_VEU_FMT_NV24,
130 SH_VEU_FMT_RGB332,
131 SH_VEU_FMT_RGB444,
132 SH_VEU_FMT_RGB565,
133 SH_VEU_FMT_RGB666,
134 SH_VEU_FMT_RGB24,
135};
136
137#define VGA_WIDTH 640
138#define VGA_HEIGHT 480
139
140#define DEFAULT_IN_WIDTH VGA_WIDTH
141#define DEFAULT_IN_HEIGHT VGA_HEIGHT
142#define DEFAULT_IN_FMTIDX SH_VEU_FMT_NV12
143#define DEFAULT_OUT_WIDTH VGA_WIDTH
144#define DEFAULT_OUT_HEIGHT VGA_HEIGHT
145#define DEFAULT_OUT_FMTIDX SH_VEU_FMT_RGB565
146
147/*
148 * Alignment: Y-plane should be 4-byte aligned for NV12 and NV16, and 8-byte
149 * aligned for NV24.
150 */
151static const struct sh_veu_format sh_veu_fmt[] = {
152 [SH_VEU_FMT_NV12] = { .ydepth = 8, .depth = 12, .name = "NV12", .fourcc = V4L2_PIX_FMT_NV12 },
153 [SH_VEU_FMT_NV16] = { .ydepth = 8, .depth = 16, .name = "NV16", .fourcc = V4L2_PIX_FMT_NV16 },
154 [SH_VEU_FMT_NV24] = { .ydepth = 8, .depth = 24, .name = "NV24", .fourcc = V4L2_PIX_FMT_NV24 },
155 [SH_VEU_FMT_RGB332] = { .ydepth = 8, .depth = 8, .name = "RGB332", .fourcc = V4L2_PIX_FMT_RGB332 },
156 [SH_VEU_FMT_RGB444] = { .ydepth = 16, .depth = 16, .name = "RGB444", .fourcc = V4L2_PIX_FMT_RGB444 },
157 [SH_VEU_FMT_RGB565] = { .ydepth = 16, .depth = 16, .name = "RGB565", .fourcc = V4L2_PIX_FMT_RGB565 },
158 [SH_VEU_FMT_RGB666] = { .ydepth = 32, .depth = 32, .name = "BGR666", .fourcc = V4L2_PIX_FMT_BGR666 },
159 [SH_VEU_FMT_RGB24] = { .ydepth = 24, .depth = 24, .name = "RGB24", .fourcc = V4L2_PIX_FMT_RGB24 },
160};
161
162#define DEFAULT_IN_VFMT (struct sh_veu_vfmt){ \
163 .frame = { \
164 .width = VGA_WIDTH, \
165 .height = VGA_HEIGHT, \
166 }, \
167 .bytesperline = (VGA_WIDTH * sh_veu_fmt[DEFAULT_IN_FMTIDX].ydepth) >> 3, \
168 .fmt = &sh_veu_fmt[DEFAULT_IN_FMTIDX], \
169}
170
171#define DEFAULT_OUT_VFMT (struct sh_veu_vfmt){ \
172 .frame = { \
173 .width = VGA_WIDTH, \
174 .height = VGA_HEIGHT, \
175 }, \
176 .bytesperline = (VGA_WIDTH * sh_veu_fmt[DEFAULT_OUT_FMTIDX].ydepth) >> 3, \
177 .fmt = &sh_veu_fmt[DEFAULT_OUT_FMTIDX], \
178}
179
180/*
181 * TODO: add support for further output formats:
182 * SH_VEU_FMT_NV12,
183 * SH_VEU_FMT_NV16,
184 * SH_VEU_FMT_NV24,
185 * SH_VEU_FMT_RGB332,
186 * SH_VEU_FMT_RGB444,
187 * SH_VEU_FMT_RGB666,
188 * SH_VEU_FMT_RGB24,
189 */
190
191static const int sh_veu_fmt_out[] = {
192 SH_VEU_FMT_RGB565,
193};
194
195/*
196 * TODO: add support for further input formats:
197 * SH_VEU_FMT_NV16,
198 * SH_VEU_FMT_NV24,
199 * SH_VEU_FMT_RGB565,
200 * SH_VEU_FMT_RGB666,
201 * SH_VEU_FMT_RGB24,
202 */
203static const int sh_veu_fmt_in[] = {
204 SH_VEU_FMT_NV12,
205};
206
207static enum v4l2_colorspace sh_veu_4cc2cspace(u32 fourcc)
208{
209 switch (fourcc) {
210 default:
211 BUG();
212 case V4L2_PIX_FMT_NV12:
213 case V4L2_PIX_FMT_NV16:
214 case V4L2_PIX_FMT_NV24:
215 return V4L2_COLORSPACE_JPEG;
216 case V4L2_PIX_FMT_RGB332:
217 case V4L2_PIX_FMT_RGB444:
218 case V4L2_PIX_FMT_RGB565:
219 case V4L2_PIX_FMT_BGR666:
220 case V4L2_PIX_FMT_RGB24:
221 return V4L2_COLORSPACE_SRGB;
222 }
223}
224
225static u32 sh_veu_reg_read(struct sh_veu_dev *veu, unsigned int reg)
226{
227 return ioread32(veu->base + reg);
228}
229
230static void sh_veu_reg_write(struct sh_veu_dev *veu, unsigned int reg,
231 u32 value)
232{
233 iowrite32(value, veu->base + reg);
234}
235
236 /* ========== mem2mem callbacks ========== */
237
238static void sh_veu_job_abort(void *priv)
239{
240 struct sh_veu_dev *veu = priv;
241
242 /* Will cancel the transaction in the next interrupt handler */
243 veu->aborting = true;
244}
245
246static void sh_veu_lock(void *priv)
247{
248 struct sh_veu_dev *veu = priv;
249
250 mutex_lock(&veu->fop_lock);
251}
252
253static void sh_veu_unlock(void *priv)
254{
255 struct sh_veu_dev *veu = priv;
256
257 mutex_unlock(&veu->fop_lock);
258}
259
260static void sh_veu_process(struct sh_veu_dev *veu,
261 struct vb2_buffer *src_buf,
262 struct vb2_buffer *dst_buf)
263{
264 dma_addr_t addr = vb2_dma_contig_plane_dma_addr(dst_buf, 0);
265
266 sh_veu_reg_write(veu, VEU_DAYR, addr + veu->vfmt_out.offset_y);
267 sh_veu_reg_write(veu, VEU_DACR, veu->vfmt_out.offset_c ?
268 addr + veu->vfmt_out.offset_c : 0);
269 dev_dbg(veu->dev, "%s(): dst base %lx, y: %x, c: %x\n", __func__,
270 (unsigned long)addr,
271 veu->vfmt_out.offset_y, veu->vfmt_out.offset_c);
272
273 addr = vb2_dma_contig_plane_dma_addr(src_buf, 0);
274 sh_veu_reg_write(veu, VEU_SAYR, addr + veu->vfmt_in.offset_y);
275 sh_veu_reg_write(veu, VEU_SACR, veu->vfmt_in.offset_c ?
276 addr + veu->vfmt_in.offset_c : 0);
277 dev_dbg(veu->dev, "%s(): src base %lx, y: %x, c: %x\n", __func__,
278 (unsigned long)addr,
279 veu->vfmt_in.offset_y, veu->vfmt_in.offset_c);
280
281 sh_veu_reg_write(veu, VEU_STR, 1);
282
283 sh_veu_reg_write(veu, VEU_EIER, 1); /* enable interrupt in VEU */
284}
285
286/**
287 * sh_veu_device_run() - prepares and starts the device
288 *
289 * This will be called by the framework when it decides to schedule a particular
290 * instance.
291 */
292static void sh_veu_device_run(void *priv)
293{
294 struct sh_veu_dev *veu = priv;
295 struct vb2_buffer *src_buf, *dst_buf;
296
297 src_buf = v4l2_m2m_next_src_buf(veu->m2m_ctx);
298 dst_buf = v4l2_m2m_next_dst_buf(veu->m2m_ctx);
299
300 if (src_buf && dst_buf)
301 sh_veu_process(veu, src_buf, dst_buf);
302}
303
304 /* ========== video ioctls ========== */
305
306static bool sh_veu_is_streamer(struct sh_veu_dev *veu, struct sh_veu_file *veu_file,
307 enum v4l2_buf_type type)
308{
309 return (type == V4L2_BUF_TYPE_VIDEO_CAPTURE &&
310 veu_file == veu->capture) ||
311 (type == V4L2_BUF_TYPE_VIDEO_OUTPUT &&
312 veu_file == veu->output);
313}
314
315static int sh_veu_queue_init(void *priv, struct vb2_queue *src_vq,
316 struct vb2_queue *dst_vq);
317
318/*
319 * It is not unusual to have video nodes open()ed multiple times. While some
320 * V4L2 operations are non-intrusive, like querying formats and various
321 * parameters, others, like setting formats, starting and stopping streaming,
322 * queuing and dequeuing buffers, directly affect hardware configuration and /
323 * or execution. This function verifies availability of the requested interface
324 * and, if available, reserves it for the requesting user.
325 */
326static int sh_veu_stream_init(struct sh_veu_dev *veu, struct sh_veu_file *veu_file,
327 enum v4l2_buf_type type)
328{
329 struct sh_veu_file **stream;
330
331 switch (type) {
332 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
333 stream = &veu->capture;
334 break;
335 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
336 stream = &veu->output;
337 break;
338 default:
339 return -EINVAL;
340 }
341
342 if (*stream == veu_file)
343 return 0;
344
345 if (*stream)
346 return -EBUSY;
347
348 *stream = veu_file;
349
350 return 0;
351}
352
353static int sh_veu_context_init(struct sh_veu_dev *veu)
354{
355 if (veu->m2m_ctx)
356 return 0;
357
358 veu->m2m_ctx = v4l2_m2m_ctx_init(veu->m2m_dev, veu,
359 sh_veu_queue_init);
360
361 if (IS_ERR(veu->m2m_ctx))
362 return PTR_ERR(veu->m2m_ctx);
363
364 return 0;
365}
366
367static int sh_veu_querycap(struct file *file, void *priv,
368 struct v4l2_capability *cap)
369{
370 strlcpy(cap->driver, "sh-veu", sizeof(cap->driver));
371 strlcpy(cap->card, "sh-mobile VEU", sizeof(cap->card));
372 strlcpy(cap->bus_info, "platform:sh-veu", sizeof(cap->bus_info));
373 cap->device_caps = V4L2_CAP_VIDEO_M2M | V4L2_CAP_STREAMING;
374 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
375
376 return 0;
377}
378
379static int sh_veu_enum_fmt(struct v4l2_fmtdesc *f, const int *fmt, int fmt_num)
380{
381 if (f->index >= fmt_num)
382 return -EINVAL;
383
384 strlcpy(f->description, sh_veu_fmt[fmt[f->index]].name, sizeof(f->description));
385 f->pixelformat = sh_veu_fmt[fmt[f->index]].fourcc;
386 return 0;
387}
388
389static int sh_veu_enum_fmt_vid_cap(struct file *file, void *priv,
390 struct v4l2_fmtdesc *f)
391{
392 return sh_veu_enum_fmt(f, sh_veu_fmt_out, ARRAY_SIZE(sh_veu_fmt_out));
393}
394
395static int sh_veu_enum_fmt_vid_out(struct file *file, void *priv,
396 struct v4l2_fmtdesc *f)
397{
398 return sh_veu_enum_fmt(f, sh_veu_fmt_in, ARRAY_SIZE(sh_veu_fmt_in));
399}
400
401static struct sh_veu_vfmt *sh_veu_get_vfmt(struct sh_veu_dev *veu,
402 enum v4l2_buf_type type)
403{
404 switch (type) {
405 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
406 return &veu->vfmt_out;
407 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
408 return &veu->vfmt_in;
409 default:
410 return NULL;
411 }
412}
413
414static int sh_veu_g_fmt(struct sh_veu_file *veu_file, struct v4l2_format *f)
415{
416 struct v4l2_pix_format *pix = &f->fmt.pix;
417 struct sh_veu_dev *veu = veu_file->veu_dev;
418 struct sh_veu_vfmt *vfmt;
419
420 vfmt = sh_veu_get_vfmt(veu, f->type);
421
422 pix->width = vfmt->frame.width;
423 pix->height = vfmt->frame.height;
424 pix->field = V4L2_FIELD_NONE;
425 pix->pixelformat = vfmt->fmt->fourcc;
426 pix->colorspace = sh_veu_4cc2cspace(pix->pixelformat);
427 pix->bytesperline = vfmt->bytesperline;
428 pix->sizeimage = vfmt->bytesperline * pix->height *
429 vfmt->fmt->depth / vfmt->fmt->ydepth;
430 pix->priv = 0;
431 dev_dbg(veu->dev, "%s(): type: %d, size %u @ %ux%u, fmt %x\n", __func__,
432 f->type, pix->sizeimage, pix->width, pix->height, pix->pixelformat);
433
434 return 0;
435}
436
437static int sh_veu_g_fmt_vid_out(struct file *file, void *priv,
438 struct v4l2_format *f)
439{
440 return sh_veu_g_fmt(priv, f);
441}
442
443static int sh_veu_g_fmt_vid_cap(struct file *file, void *priv,
444 struct v4l2_format *f)
445{
446 return sh_veu_g_fmt(priv, f);
447}
448
449static int sh_veu_try_fmt(struct v4l2_format *f, const struct sh_veu_format *fmt)
450{
451 struct v4l2_pix_format *pix = &f->fmt.pix;
452 unsigned int y_bytes_used;
453
454 /*
455 * V4L2 specification suggests, that the driver should correct the
456 * format struct if any of the dimensions is unsupported
457 */
458 switch (pix->field) {
459 default:
460 case V4L2_FIELD_ANY:
461 pix->field = V4L2_FIELD_NONE;
462 /* fall through: continue handling V4L2_FIELD_NONE */
463 case V4L2_FIELD_NONE:
464 break;
465 }
466
467 v4l_bound_align_image(&pix->width, MIN_W, MAX_W, ALIGN_W,
468 &pix->height, MIN_H, MAX_H, 0, 0);
469
470 y_bytes_used = (pix->width * fmt->ydepth) >> 3;
471
472 if (pix->bytesperline < y_bytes_used)
473 pix->bytesperline = y_bytes_used;
474 pix->sizeimage = pix->height * pix->bytesperline * fmt->depth / fmt->ydepth;
475
476 pix->pixelformat = fmt->fourcc;
477 pix->colorspace = sh_veu_4cc2cspace(pix->pixelformat);
478 pix->priv = 0;
479
480 pr_debug("%s(): type: %d, size %u\n", __func__, f->type, pix->sizeimage);
481
482 return 0;
483}
484
485static const struct sh_veu_format *sh_veu_find_fmt(const struct v4l2_format *f)
486{
487 const int *fmt;
488 int i, n, dflt;
489
490 pr_debug("%s(%d;%d)\n", __func__, f->type, f->fmt.pix.field);
491
492 switch (f->type) {
493 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
494 fmt = sh_veu_fmt_out;
495 n = ARRAY_SIZE(sh_veu_fmt_out);
496 dflt = DEFAULT_OUT_FMTIDX;
497 break;
498 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
499 default:
500 fmt = sh_veu_fmt_in;
501 n = ARRAY_SIZE(sh_veu_fmt_in);
502 dflt = DEFAULT_IN_FMTIDX;
503 break;
504 }
505
506 for (i = 0; i < n; i++)
507 if (sh_veu_fmt[fmt[i]].fourcc == f->fmt.pix.pixelformat)
508 return &sh_veu_fmt[fmt[i]];
509
510 return &sh_veu_fmt[dflt];
511}
512
513static int sh_veu_try_fmt_vid_cap(struct file *file, void *priv,
514 struct v4l2_format *f)
515{
516 const struct sh_veu_format *fmt;
517
518 fmt = sh_veu_find_fmt(f);
519 if (!fmt)
520 /* wrong buffer type */
521 return -EINVAL;
522
523 return sh_veu_try_fmt(f, fmt);
524}
525
526static int sh_veu_try_fmt_vid_out(struct file *file, void *priv,
527 struct v4l2_format *f)
528{
529 const struct sh_veu_format *fmt;
530
531 fmt = sh_veu_find_fmt(f);
532 if (!fmt)
533 /* wrong buffer type */
534 return -EINVAL;
535
536 return sh_veu_try_fmt(f, fmt);
537}
538
539static void sh_veu_colour_offset(struct sh_veu_dev *veu, struct sh_veu_vfmt *vfmt)
540{
541 /* dst_left and dst_top validity will be verified in CROP / COMPOSE */
542 unsigned int left = vfmt->frame.left & ~0x03;
543 unsigned int top = vfmt->frame.top;
544 dma_addr_t offset = ((left * veu->vfmt_out.fmt->depth) >> 3) +
545 top * veu->vfmt_out.bytesperline;
546 unsigned int y_line;
547
548 vfmt->offset_y = offset;
549
550 switch (vfmt->fmt->fourcc) {
551 case V4L2_PIX_FMT_NV12:
552 case V4L2_PIX_FMT_NV16:
553 case V4L2_PIX_FMT_NV24:
554 y_line = ALIGN(vfmt->frame.width, 16);
555 vfmt->offset_c = offset + y_line * vfmt->frame.height;
556 break;
557 case V4L2_PIX_FMT_RGB332:
558 case V4L2_PIX_FMT_RGB444:
559 case V4L2_PIX_FMT_RGB565:
560 case V4L2_PIX_FMT_BGR666:
561 case V4L2_PIX_FMT_RGB24:
562 vfmt->offset_c = 0;
563 break;
564 default:
565 BUG();
566 }
567}
568
569static int sh_veu_s_fmt(struct sh_veu_file *veu_file, struct v4l2_format *f)
570{
571 struct v4l2_pix_format *pix = &f->fmt.pix;
572 struct sh_veu_dev *veu = veu_file->veu_dev;
573 struct sh_veu_vfmt *vfmt;
574 struct vb2_queue *vq;
575 int ret = sh_veu_context_init(veu);
576 if (ret < 0)
577 return ret;
578
579 vq = v4l2_m2m_get_vq(veu->m2m_ctx, f->type);
580 if (!vq)
581 return -EINVAL;
582
583 if (vb2_is_busy(vq)) {
584 v4l2_err(&veu_file->veu_dev->v4l2_dev, "%s queue busy\n", __func__);
585 return -EBUSY;
586 }
587
588 vfmt = sh_veu_get_vfmt(veu, f->type);
589 /* called after try_fmt(), hence vfmt != NULL. Implicit BUG_ON() below */
590
591 vfmt->fmt = sh_veu_find_fmt(f);
592 /* vfmt->fmt != NULL following the same argument as above */
593 vfmt->frame.width = pix->width;
594 vfmt->frame.height = pix->height;
595 vfmt->bytesperline = pix->bytesperline;
596
597 sh_veu_colour_offset(veu, vfmt);
598
599 /*
600 * We could also verify and require configuration only if any parameters
601 * actually have changed, but it is unlikely, that the user requests the
602 * same configuration several times without closing the device.
603 */
604 veu_file->cfg_needed = true;
605
606 dev_dbg(veu->dev,
607 "Setting format for type %d, wxh: %dx%d, fmt: %x\n",
608 f->type, pix->width, pix->height, vfmt->fmt->fourcc);
609
610 return 0;
611}
612
613static int sh_veu_s_fmt_vid_cap(struct file *file, void *priv,
614 struct v4l2_format *f)
615{
616 int ret = sh_veu_try_fmt_vid_cap(file, priv, f);
617 if (ret)
618 return ret;
619
620 return sh_veu_s_fmt(priv, f);
621}
622
623static int sh_veu_s_fmt_vid_out(struct file *file, void *priv,
624 struct v4l2_format *f)
625{
626 int ret = sh_veu_try_fmt_vid_out(file, priv, f);
627 if (ret)
628 return ret;
629
630 return sh_veu_s_fmt(priv, f);
631}
632
633static int sh_veu_reqbufs(struct file *file, void *priv,
634 struct v4l2_requestbuffers *reqbufs)
635{
636 struct sh_veu_file *veu_file = priv;
637 struct sh_veu_dev *veu = veu_file->veu_dev;
638 int ret = sh_veu_context_init(veu);
639 if (ret < 0)
640 return ret;
641
642 ret = sh_veu_stream_init(veu, veu_file, reqbufs->type);
643 if (ret < 0)
644 return ret;
645
646 return v4l2_m2m_reqbufs(file, veu->m2m_ctx, reqbufs);
647}
648
649static int sh_veu_querybuf(struct file *file, void *priv,
650 struct v4l2_buffer *buf)
651{
652 struct sh_veu_file *veu_file = priv;
653
654 if (!sh_veu_is_streamer(veu_file->veu_dev, veu_file, buf->type))
655 return -EBUSY;
656
657 return v4l2_m2m_querybuf(file, veu_file->veu_dev->m2m_ctx, buf);
658}
659
660static int sh_veu_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
661{
662 struct sh_veu_file *veu_file = priv;
663
664 dev_dbg(veu_file->veu_dev->dev, "%s(%d)\n", __func__, buf->type);
665 if (!sh_veu_is_streamer(veu_file->veu_dev, veu_file, buf->type))
666 return -EBUSY;
667
668 return v4l2_m2m_qbuf(file, veu_file->veu_dev->m2m_ctx, buf);
669}
670
671static int sh_veu_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
672{
673 struct sh_veu_file *veu_file = priv;
674
675 dev_dbg(veu_file->veu_dev->dev, "%s(%d)\n", __func__, buf->type);
676 if (!sh_veu_is_streamer(veu_file->veu_dev, veu_file, buf->type))
677 return -EBUSY;
678
679 return v4l2_m2m_dqbuf(file, veu_file->veu_dev->m2m_ctx, buf);
680}
681
682static void sh_veu_calc_scale(struct sh_veu_dev *veu,
683 int size_in, int size_out, int crop_out,
684 u32 *mant, u32 *frac, u32 *rep)
685{
686 u32 fixpoint;
687
688 /* calculate FRAC and MANT */
689 *rep = *mant = *frac = 0;
690
691 if (size_in == size_out) {
692 if (crop_out != size_out)
693 *mant = 1; /* needed for cropping */
694 return;
695 }
696
697 /* VEU2H special upscale */
698 if (veu->is_2h && size_out > size_in) {
699 u32 fixpoint = (4096 * size_in) / size_out;
700 *mant = fixpoint / 4096;
701 *frac = (fixpoint - (*mant * 4096)) & ~0x07;
702
703 switch (*frac) {
704 case 0x800:
705 *rep = 1;
706 break;
707 case 0x400:
708 *rep = 3;
709 break;
710 case 0x200:
711 *rep = 7;
712 break;
713 }
714 if (*rep)
715 return;
716 }
717
718 fixpoint = (4096 * (size_in - 1)) / (size_out + 1);
719 *mant = fixpoint / 4096;
720 *frac = fixpoint - (*mant * 4096);
721
722 if (*frac & 0x07) {
723 /*
724 * FIXME: do we really have to round down twice in the
725 * up-scaling case?
726 */
727 *frac &= ~0x07;
728 if (size_out > size_in)
729 *frac -= 8; /* round down if scaling up */
730 else
731 *frac += 8; /* round up if scaling down */
732 }
733}
734
735static unsigned long sh_veu_scale_v(struct sh_veu_dev *veu,
736 int size_in, int size_out, int crop_out)
737{
738 u32 mant, frac, value, rep;
739
740 sh_veu_calc_scale(veu, size_in, size_out, crop_out, &mant, &frac, &rep);
741
742 /* set scale */
743 value = (sh_veu_reg_read(veu, VEU_RFCR) & ~0xffff0000) |
744 (((mant << 12) | frac) << 16);
745
746 sh_veu_reg_write(veu, VEU_RFCR, value);
747
748 /* set clip */
749 value = (sh_veu_reg_read(veu, VEU_RFSR) & ~0xffff0000) |
750 (((rep << 12) | crop_out) << 16);
751
752 sh_veu_reg_write(veu, VEU_RFSR, value);
753
754 return ALIGN((size_in * crop_out) / size_out, 4);
755}
756
757static unsigned long sh_veu_scale_h(struct sh_veu_dev *veu,
758 int size_in, int size_out, int crop_out)
759{
760 u32 mant, frac, value, rep;
761
762 sh_veu_calc_scale(veu, size_in, size_out, crop_out, &mant, &frac, &rep);
763
764 /* set scale */
765 value = (sh_veu_reg_read(veu, VEU_RFCR) & ~0xffff) |
766 (mant << 12) | frac;
767
768 sh_veu_reg_write(veu, VEU_RFCR, value);
769
770 /* set clip */
771 value = (sh_veu_reg_read(veu, VEU_RFSR) & ~0xffff) |
772 (rep << 12) | crop_out;
773
774 sh_veu_reg_write(veu, VEU_RFSR, value);
775
776 return ALIGN((size_in * crop_out) / size_out, 4);
777}
778
779static void sh_veu_configure(struct sh_veu_dev *veu)
780{
781 u32 src_width, src_stride, src_height;
782 u32 dst_width, dst_stride, dst_height;
783 u32 real_w, real_h;
784
785 /* reset VEU */
786 sh_veu_reg_write(veu, VEU_BSRR, 0x100);
787
788 src_width = veu->vfmt_in.frame.width;
789 src_height = veu->vfmt_in.frame.height;
790 src_stride = ALIGN(veu->vfmt_in.frame.width, 16);
791
792 dst_width = real_w = veu->vfmt_out.frame.width;
793 dst_height = real_h = veu->vfmt_out.frame.height;
794 /* Datasheet is unclear - whether it's always number of bytes or not */
795 dst_stride = veu->vfmt_out.bytesperline;
796
797 /*
798 * So far real_w == dst_width && real_h == dst_height, but it wasn't
799 * necessarily the case in the original vidix driver, so, it may change
800 * here in the future too.
801 */
802 src_width = sh_veu_scale_h(veu, src_width, real_w, dst_width);
803 src_height = sh_veu_scale_v(veu, src_height, real_h, dst_height);
804
805 sh_veu_reg_write(veu, VEU_SWR, src_stride);
806 sh_veu_reg_write(veu, VEU_SSR, src_width | (src_height << 16));
807 sh_veu_reg_write(veu, VEU_BSSR, 0); /* not using bundle mode */
808
809 sh_veu_reg_write(veu, VEU_EDWR, dst_stride);
810 sh_veu_reg_write(veu, VEU_DACR, 0); /* unused for RGB */
811
812 sh_veu_reg_write(veu, VEU_SWPR, 0x67);
813 sh_veu_reg_write(veu, VEU_TRCR, (6 << 16) | (0 << 14) | 2 | 4);
814
815 if (veu->is_2h) {
816 sh_veu_reg_write(veu, VEU_MCR00, 0x0cc5);
817 sh_veu_reg_write(veu, VEU_MCR01, 0x0950);
818 sh_veu_reg_write(veu, VEU_MCR02, 0x0000);
819
820 sh_veu_reg_write(veu, VEU_MCR10, 0x397f);
821 sh_veu_reg_write(veu, VEU_MCR11, 0x0950);
822 sh_veu_reg_write(veu, VEU_MCR12, 0x3ccd);
823
824 sh_veu_reg_write(veu, VEU_MCR20, 0x0000);
825 sh_veu_reg_write(veu, VEU_MCR21, 0x0950);
826 sh_veu_reg_write(veu, VEU_MCR22, 0x1023);
827
828 sh_veu_reg_write(veu, VEU_COFFR, 0x00800010);
829 }
830}
831
832static int sh_veu_streamon(struct file *file, void *priv,
833 enum v4l2_buf_type type)
834{
835 struct sh_veu_file *veu_file = priv;
836
837 if (!sh_veu_is_streamer(veu_file->veu_dev, veu_file, type))
838 return -EBUSY;
839
840 if (veu_file->cfg_needed) {
841 struct sh_veu_dev *veu = veu_file->veu_dev;
842 veu_file->cfg_needed = false;
843 sh_veu_configure(veu_file->veu_dev);
844 veu->xaction = 0;
845 veu->aborting = false;
846 }
847
848 return v4l2_m2m_streamon(file, veu_file->veu_dev->m2m_ctx, type);
849}
850
851static int sh_veu_streamoff(struct file *file, void *priv,
852 enum v4l2_buf_type type)
853{
854 struct sh_veu_file *veu_file = priv;
855
856 if (!sh_veu_is_streamer(veu_file->veu_dev, veu_file, type))
857 return -EBUSY;
858
859 return v4l2_m2m_streamoff(file, veu_file->veu_dev->m2m_ctx, type);
860}
861
862static const struct v4l2_ioctl_ops sh_veu_ioctl_ops = {
863 .vidioc_querycap = sh_veu_querycap,
864
865 .vidioc_enum_fmt_vid_cap = sh_veu_enum_fmt_vid_cap,
866 .vidioc_g_fmt_vid_cap = sh_veu_g_fmt_vid_cap,
867 .vidioc_try_fmt_vid_cap = sh_veu_try_fmt_vid_cap,
868 .vidioc_s_fmt_vid_cap = sh_veu_s_fmt_vid_cap,
869
870 .vidioc_enum_fmt_vid_out = sh_veu_enum_fmt_vid_out,
871 .vidioc_g_fmt_vid_out = sh_veu_g_fmt_vid_out,
872 .vidioc_try_fmt_vid_out = sh_veu_try_fmt_vid_out,
873 .vidioc_s_fmt_vid_out = sh_veu_s_fmt_vid_out,
874
875 .vidioc_reqbufs = sh_veu_reqbufs,
876 .vidioc_querybuf = sh_veu_querybuf,
877
878 .vidioc_qbuf = sh_veu_qbuf,
879 .vidioc_dqbuf = sh_veu_dqbuf,
880
881 .vidioc_streamon = sh_veu_streamon,
882 .vidioc_streamoff = sh_veu_streamoff,
883};
884
885 /* ========== Queue operations ========== */
886
887static int sh_veu_queue_setup(struct vb2_queue *vq,
888 const struct v4l2_format *f,
889 unsigned int *nbuffers, unsigned int *nplanes,
890 unsigned int sizes[], void *alloc_ctxs[])
891{
892 struct sh_veu_dev *veu = vb2_get_drv_priv(vq);
893 struct sh_veu_vfmt *vfmt;
894 unsigned int size, count = *nbuffers;
895
896 if (f) {
897 const struct v4l2_pix_format *pix = &f->fmt.pix;
898 const struct sh_veu_format *fmt = sh_veu_find_fmt(f);
899 struct v4l2_format ftmp = *f;
900
901 if (fmt->fourcc != pix->pixelformat)
902 return -EINVAL;
903 sh_veu_try_fmt(&ftmp, fmt);
904 if (ftmp.fmt.pix.width != pix->width ||
905 ftmp.fmt.pix.height != pix->height)
906 return -EINVAL;
907 size = pix->bytesperline ? pix->bytesperline * pix->height :
908 pix->width * pix->height * fmt->depth >> 3;
909 } else {
910 vfmt = sh_veu_get_vfmt(veu, vq->type);
911 size = vfmt->bytesperline * vfmt->frame.height;
912 }
913
914 if (count < 2)
915 *nbuffers = count = 2;
916
917 if (size * count > VIDEO_MEM_LIMIT) {
918 count = VIDEO_MEM_LIMIT / size;
919 *nbuffers = count;
920 }
921
922 *nplanes = 1;
923 sizes[0] = size;
924 alloc_ctxs[0] = veu->alloc_ctx;
925
926 dev_dbg(veu->dev, "get %d buffer(s) of size %d each.\n", count, size);
927
928 return 0;
929}
930
931static int sh_veu_buf_prepare(struct vb2_buffer *vb)
932{
933 struct sh_veu_dev *veu = vb2_get_drv_priv(vb->vb2_queue);
934 struct sh_veu_vfmt *vfmt;
935 unsigned int sizeimage;
936
937 vfmt = sh_veu_get_vfmt(veu, vb->vb2_queue->type);
938 sizeimage = vfmt->bytesperline * vfmt->frame.height *
939 vfmt->fmt->depth / vfmt->fmt->ydepth;
940
941 if (vb2_plane_size(vb, 0) < sizeimage) {
942 dev_dbg(veu->dev, "%s data will not fit into plane (%lu < %u)\n",
943 __func__, vb2_plane_size(vb, 0), sizeimage);
944 return -EINVAL;
945 }
946
947 vb2_set_plane_payload(vb, 0, sizeimage);
948
949 return 0;
950}
951
952static void sh_veu_buf_queue(struct vb2_buffer *vb)
953{
954 struct sh_veu_dev *veu = vb2_get_drv_priv(vb->vb2_queue);
955 dev_dbg(veu->dev, "%s(%d)\n", __func__, vb->v4l2_buf.type);
956 v4l2_m2m_buf_queue(veu->m2m_ctx, vb);
957}
958
959static void sh_veu_wait_prepare(struct vb2_queue *q)
960{
961 sh_veu_unlock(vb2_get_drv_priv(q));
962}
963
964static void sh_veu_wait_finish(struct vb2_queue *q)
965{
966 sh_veu_lock(vb2_get_drv_priv(q));
967}
968
969static const struct vb2_ops sh_veu_qops = {
970 .queue_setup = sh_veu_queue_setup,
971 .buf_prepare = sh_veu_buf_prepare,
972 .buf_queue = sh_veu_buf_queue,
973 .wait_prepare = sh_veu_wait_prepare,
974 .wait_finish = sh_veu_wait_finish,
975};
976
977static int sh_veu_queue_init(void *priv, struct vb2_queue *src_vq,
978 struct vb2_queue *dst_vq)
979{
980 int ret;
981
982 memset(src_vq, 0, sizeof(*src_vq));
983 src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
984 src_vq->io_modes = VB2_MMAP | VB2_USERPTR;
985 src_vq->drv_priv = priv;
986 src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
987 src_vq->ops = &sh_veu_qops;
988 src_vq->mem_ops = &vb2_dma_contig_memops;
989
990 ret = vb2_queue_init(src_vq);
991 if (ret < 0)
992 return ret;
993
994 memset(dst_vq, 0, sizeof(*dst_vq));
995 dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
996 dst_vq->io_modes = VB2_MMAP | VB2_USERPTR;
997 dst_vq->drv_priv = priv;
998 dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
999 dst_vq->ops = &sh_veu_qops;
1000 dst_vq->mem_ops = &vb2_dma_contig_memops;
1001
1002 return vb2_queue_init(dst_vq);
1003}
1004
1005 /* ========== File operations ========== */
1006
1007static int sh_veu_open(struct file *file)
1008{
1009 struct sh_veu_dev *veu = video_drvdata(file);
1010 struct sh_veu_file *veu_file;
1011
1012 veu_file = kzalloc(sizeof(*veu_file), GFP_KERNEL);
1013 if (!veu_file)
1014 return -ENOMEM;
1015
1016 veu_file->veu_dev = veu;
1017 veu_file->cfg_needed = true;
1018
1019 file->private_data = veu_file;
1020
1021 pm_runtime_get_sync(veu->dev);
1022
1023 dev_dbg(veu->dev, "Created instance %p\n", veu_file);
1024
1025 return 0;
1026}
1027
1028static int sh_veu_release(struct file *file)
1029{
1030 struct sh_veu_dev *veu = video_drvdata(file);
1031 struct sh_veu_file *veu_file = file->private_data;
1032
1033 dev_dbg(veu->dev, "Releasing instance %p\n", veu_file);
1034
1035 pm_runtime_put(veu->dev);
1036
1037 if (veu_file == veu->capture) {
1038 veu->capture = NULL;
1039 vb2_queue_release(v4l2_m2m_get_vq(veu->m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE));
1040 }
1041
1042 if (veu_file == veu->output) {
1043 veu->output = NULL;
1044 vb2_queue_release(v4l2_m2m_get_vq(veu->m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT));
1045 }
1046
1047 if (!veu->output && !veu->capture && veu->m2m_ctx) {
1048 v4l2_m2m_ctx_release(veu->m2m_ctx);
1049 veu->m2m_ctx = NULL;
1050 }
1051
1052 kfree(veu_file);
1053
1054 return 0;
1055}
1056
1057static unsigned int sh_veu_poll(struct file *file,
1058 struct poll_table_struct *wait)
1059{
1060 struct sh_veu_file *veu_file = file->private_data;
1061
1062 return v4l2_m2m_poll(file, veu_file->veu_dev->m2m_ctx, wait);
1063}
1064
1065static int sh_veu_mmap(struct file *file, struct vm_area_struct *vma)
1066{
1067 struct sh_veu_file *veu_file = file->private_data;
1068
1069 return v4l2_m2m_mmap(file, veu_file->veu_dev->m2m_ctx, vma);
1070}
1071
1072static const struct v4l2_file_operations sh_veu_fops = {
1073 .owner = THIS_MODULE,
1074 .open = sh_veu_open,
1075 .release = sh_veu_release,
1076 .poll = sh_veu_poll,
1077 .unlocked_ioctl = video_ioctl2,
1078 .mmap = sh_veu_mmap,
1079};
1080
1081static const struct video_device sh_veu_videodev = {
1082 .name = "sh-veu",
1083 .fops = &sh_veu_fops,
1084 .ioctl_ops = &sh_veu_ioctl_ops,
1085 .minor = -1,
1086 .release = video_device_release_empty,
1087 .vfl_dir = VFL_DIR_M2M,
1088};
1089
1090static const struct v4l2_m2m_ops sh_veu_m2m_ops = {
1091 .device_run = sh_veu_device_run,
1092 .job_abort = sh_veu_job_abort,
1093};
1094
1095static irqreturn_t sh_veu_bh(int irq, void *dev_id)
1096{
1097 struct sh_veu_dev *veu = dev_id;
1098
1099 if (veu->xaction == MEM2MEM_DEF_TRANSLEN || veu->aborting) {
1100 v4l2_m2m_job_finish(veu->m2m_dev, veu->m2m_ctx);
1101 veu->xaction = 0;
1102 } else {
1103 sh_veu_device_run(veu);
1104 }
1105
1106 return IRQ_HANDLED;
1107}
1108
1109static irqreturn_t sh_veu_isr(int irq, void *dev_id)
1110{
1111 struct sh_veu_dev *veu = dev_id;
1112 struct vb2_buffer *dst;
1113 struct vb2_buffer *src;
1114 u32 status = sh_veu_reg_read(veu, VEU_EVTR);
1115
1116 /* bundle read mode not used */
1117 if (!(status & 1))
1118 return IRQ_NONE;
1119
1120 /* disable interrupt in VEU */
1121 sh_veu_reg_write(veu, VEU_EIER, 0);
1122 /* halt operation */
1123 sh_veu_reg_write(veu, VEU_STR, 0);
1124 /* ack int, write 0 to clear bits */
1125 sh_veu_reg_write(veu, VEU_EVTR, status & ~1);
1126
1127 /* conversion completed */
1128 dst = v4l2_m2m_dst_buf_remove(veu->m2m_ctx);
1129 src = v4l2_m2m_src_buf_remove(veu->m2m_ctx);
1130 if (!src || !dst)
1131 return IRQ_NONE;
1132
1133 spin_lock(&veu->lock);
1134 v4l2_m2m_buf_done(src, VB2_BUF_STATE_DONE);
1135 v4l2_m2m_buf_done(dst, VB2_BUF_STATE_DONE);
1136 spin_unlock(&veu->lock);
1137
1138 veu->xaction++;
1139
1140 if (!veu->aborting)
1141 return IRQ_WAKE_THREAD;
1142
1143 return IRQ_HANDLED;
1144}
1145
1146static int sh_veu_probe(struct platform_device *pdev)
1147{
1148 struct sh_veu_dev *veu;
1149 struct resource *reg_res;
1150 struct video_device *vdev;
1151 int irq, ret;
1152
1153 reg_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1154 irq = platform_get_irq(pdev, 0);
1155
1156 if (!reg_res || irq <= 0) {
1157 dev_err(&pdev->dev, "Insufficient VEU platform information.\n");
1158 return -ENODEV;
1159 }
1160
1161 veu = devm_kzalloc(&pdev->dev, sizeof(*veu), GFP_KERNEL);
1162 if (!veu)
1163 return -ENOMEM;
1164
1165 veu->is_2h = resource_size(reg_res) == 0x22c;
1166
1167 veu->base = devm_request_and_ioremap(&pdev->dev, reg_res);
1168 if (!veu->base)
1169 return -ENOMEM;
1170
1171 ret = devm_request_threaded_irq(&pdev->dev, irq, sh_veu_isr, sh_veu_bh,
1172 0, "veu", veu);
1173 if (ret < 0)
1174 return ret;
1175
1176 ret = v4l2_device_register(&pdev->dev, &veu->v4l2_dev);
1177 if (ret < 0) {
1178 dev_err(&pdev->dev, "Error registering v4l2 device\n");
1179 return ret;
1180 }
1181
1182 vdev = &veu->vdev;
1183
1184 veu->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev);
1185 if (IS_ERR(veu->alloc_ctx)) {
1186 ret = PTR_ERR(veu->alloc_ctx);
1187 goto einitctx;
1188 }
1189
1190 *vdev = sh_veu_videodev;
1191 spin_lock_init(&veu->lock);
1192 mutex_init(&veu->fop_lock);
1193 vdev->lock = &veu->fop_lock;
1194
1195 video_set_drvdata(vdev, veu);
1196
1197 veu->dev = &pdev->dev;
1198 veu->vfmt_out = DEFAULT_OUT_VFMT;
1199 veu->vfmt_in = DEFAULT_IN_VFMT;
1200
1201 veu->m2m_dev = v4l2_m2m_init(&sh_veu_m2m_ops);
1202 if (IS_ERR(veu->m2m_dev)) {
1203 ret = PTR_ERR(veu->m2m_dev);
1204 v4l2_err(&veu->v4l2_dev, "Failed to init mem2mem device: %d\n", ret);
1205 goto em2minit;
1206 }
1207
1208 pm_runtime_enable(&pdev->dev);
1209 pm_runtime_resume(&pdev->dev);
1210
1211 ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
1212 pm_runtime_suspend(&pdev->dev);
1213 if (ret < 0)
1214 goto evidreg;
1215
1216 return ret;
1217
1218evidreg:
1219 pm_runtime_disable(&pdev->dev);
1220 v4l2_m2m_release(veu->m2m_dev);
1221em2minit:
1222 vb2_dma_contig_cleanup_ctx(veu->alloc_ctx);
1223einitctx:
1224 v4l2_device_unregister(&veu->v4l2_dev);
1225 return ret;
1226}
1227
1228static int sh_veu_remove(struct platform_device *pdev)
1229{
1230 struct v4l2_device *v4l2_dev = platform_get_drvdata(pdev);
1231 struct sh_veu_dev *veu = container_of(v4l2_dev,
1232 struct sh_veu_dev, v4l2_dev);
1233
1234 video_unregister_device(&veu->vdev);
1235 pm_runtime_disable(&pdev->dev);
1236 v4l2_m2m_release(veu->m2m_dev);
1237 vb2_dma_contig_cleanup_ctx(veu->alloc_ctx);
1238 v4l2_device_unregister(&veu->v4l2_dev);
1239
1240 return 0;
1241}
1242
1243static struct platform_driver __refdata sh_veu_pdrv = {
1244 .remove = sh_veu_remove,
1245 .driver = {
1246 .name = "sh_veu",
1247 .owner = THIS_MODULE,
1248 },
1249};
1250
1251static int __init sh_veu_init(void)
1252{
1253 return platform_driver_probe(&sh_veu_pdrv, sh_veu_probe);
1254}
1255
1256static void __exit sh_veu_exit(void)
1257{
1258 platform_driver_unregister(&sh_veu_pdrv);
1259}
1260
1261module_init(sh_veu_init);
1262module_exit(sh_veu_exit);
1263
1264MODULE_DESCRIPTION("sh-mobile VEU mem2mem driver");
1265MODULE_AUTHOR("Guennadi Liakhovetski, <g.liakhovetski@gmx.de>");
1266MODULE_LICENSE("GPL v2");
diff --git a/drivers/media/platform/sh_vou.c b/drivers/media/platform/sh_vou.c
index f3c4571ac01e..66c8da18df84 100644
--- a/drivers/media/platform/sh_vou.c
+++ b/drivers/media/platform/sh_vou.c
@@ -207,6 +207,7 @@ static void sh_vou_stream_start(struct sh_vou_device *vou_dev,
207#endif 207#endif
208 208
209 switch (vou_dev->pix.pixelformat) { 209 switch (vou_dev->pix.pixelformat) {
210 default:
210 case V4L2_PIX_FMT_NV12: 211 case V4L2_PIX_FMT_NV12:
211 case V4L2_PIX_FMT_NV16: 212 case V4L2_PIX_FMT_NV16:
212 row_coeff = 1; 213 row_coeff = 1;
@@ -253,7 +254,8 @@ static int sh_vou_buf_setup(struct videobuf_queue *vq, unsigned int *count,
253 if (PAGE_ALIGN(*size) * *count > 4 * 1024 * 1024) 254 if (PAGE_ALIGN(*size) * *count > 4 * 1024 * 1024)
254 *count = 4 * 1024 * 1024 / PAGE_ALIGN(*size); 255 *count = 4 * 1024 * 1024 / PAGE_ALIGN(*size);
255 256
256 dev_dbg(vq->dev, "%s(): count=%d, size=%d\n", __func__, *count, *size); 257 dev_dbg(vou_dev->v4l2_dev.dev, "%s(): count=%d, size=%d\n", __func__,
258 *count, *size);
257 259
258 return 0; 260 return 0;
259} 261}
@@ -269,7 +271,7 @@ static int sh_vou_buf_prepare(struct videobuf_queue *vq,
269 int bytes_per_line = vou_fmt[vou_dev->pix_idx].bpp * pix->width / 8; 271 int bytes_per_line = vou_fmt[vou_dev->pix_idx].bpp * pix->width / 8;
270 int ret; 272 int ret;
271 273
272 dev_dbg(vq->dev, "%s()\n", __func__); 274 dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__);
273 275
274 if (vb->width != pix->width || 276 if (vb->width != pix->width ||
275 vb->height != pix->height || 277 vb->height != pix->height ||
@@ -299,7 +301,7 @@ static int sh_vou_buf_prepare(struct videobuf_queue *vq,
299 vb->state = VIDEOBUF_PREPARED; 301 vb->state = VIDEOBUF_PREPARED;
300 } 302 }
301 303
302 dev_dbg(vq->dev, 304 dev_dbg(vou_dev->v4l2_dev.dev,
303 "%s(): fmt #%d, %u bytes per line, phys 0x%x, type %d, state %d\n", 305 "%s(): fmt #%d, %u bytes per line, phys 0x%x, type %d, state %d\n",
304 __func__, vou_dev->pix_idx, bytes_per_line, 306 __func__, vou_dev->pix_idx, bytes_per_line,
305 videobuf_to_dma_contig(vb), vb->memory, vb->state); 307 videobuf_to_dma_contig(vb), vb->memory, vb->state);
@@ -314,7 +316,7 @@ static void sh_vou_buf_queue(struct videobuf_queue *vq,
314 struct video_device *vdev = vq->priv_data; 316 struct video_device *vdev = vq->priv_data;
315 struct sh_vou_device *vou_dev = video_get_drvdata(vdev); 317 struct sh_vou_device *vou_dev = video_get_drvdata(vdev);
316 318
317 dev_dbg(vq->dev, "%s()\n", __func__); 319 dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__);
318 320
319 vb->state = VIDEOBUF_QUEUED; 321 vb->state = VIDEOBUF_QUEUED;
320 list_add_tail(&vb->queue, &vou_dev->queue); 322 list_add_tail(&vb->queue, &vou_dev->queue);
@@ -325,8 +327,8 @@ static void sh_vou_buf_queue(struct videobuf_queue *vq,
325 vou_dev->active = vb; 327 vou_dev->active = vb;
326 /* Start from side A: we use mirror addresses, so, set B */ 328 /* Start from side A: we use mirror addresses, so, set B */
327 sh_vou_reg_a_write(vou_dev, VOURPR, 1); 329 sh_vou_reg_a_write(vou_dev, VOURPR, 1);
328 dev_dbg(vq->dev, "%s: first buffer status 0x%x\n", __func__, 330 dev_dbg(vou_dev->v4l2_dev.dev, "%s: first buffer status 0x%x\n",
329 sh_vou_reg_a_read(vou_dev, VOUSTR)); 331 __func__, sh_vou_reg_a_read(vou_dev, VOUSTR));
330 sh_vou_schedule_next(vou_dev, vb); 332 sh_vou_schedule_next(vou_dev, vb);
331 /* Only activate VOU after the second buffer */ 333 /* Only activate VOU after the second buffer */
332 } else if (vou_dev->active->queue.next == &vb->queue) { 334 } else if (vou_dev->active->queue.next == &vb->queue) {
@@ -336,8 +338,8 @@ static void sh_vou_buf_queue(struct videobuf_queue *vq,
336 338
337 /* Register side switching with frame VSYNC */ 339 /* Register side switching with frame VSYNC */
338 sh_vou_reg_a_write(vou_dev, VOURCR, 5); 340 sh_vou_reg_a_write(vou_dev, VOURCR, 5);
339 dev_dbg(vq->dev, "%s: second buffer status 0x%x\n", __func__, 341 dev_dbg(vou_dev->v4l2_dev.dev, "%s: second buffer status 0x%x\n",
340 sh_vou_reg_a_read(vou_dev, VOUSTR)); 342 __func__, sh_vou_reg_a_read(vou_dev, VOUSTR));
341 343
342 /* Enable End-of-Frame (VSYNC) interrupts */ 344 /* Enable End-of-Frame (VSYNC) interrupts */
343 sh_vou_reg_a_write(vou_dev, VOUIR, 0x10004); 345 sh_vou_reg_a_write(vou_dev, VOUIR, 0x10004);
@@ -355,7 +357,7 @@ static void sh_vou_buf_release(struct videobuf_queue *vq,
355 struct sh_vou_device *vou_dev = video_get_drvdata(vdev); 357 struct sh_vou_device *vou_dev = video_get_drvdata(vdev);
356 unsigned long flags; 358 unsigned long flags;
357 359
358 dev_dbg(vq->dev, "%s()\n", __func__); 360 dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__);
359 361
360 spin_lock_irqsave(&vou_dev->lock, flags); 362 spin_lock_irqsave(&vou_dev->lock, flags);
361 363
@@ -388,9 +390,9 @@ static struct videobuf_queue_ops sh_vou_video_qops = {
388static int sh_vou_querycap(struct file *file, void *priv, 390static int sh_vou_querycap(struct file *file, void *priv,
389 struct v4l2_capability *cap) 391 struct v4l2_capability *cap)
390{ 392{
391 struct sh_vou_file *vou_file = priv; 393 struct sh_vou_device *vou_dev = video_drvdata(file);
392 394
393 dev_dbg(vou_file->vbq.dev, "%s()\n", __func__); 395 dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__);
394 396
395 strlcpy(cap->card, "SuperH VOU", sizeof(cap->card)); 397 strlcpy(cap->card, "SuperH VOU", sizeof(cap->card));
396 cap->capabilities = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING; 398 cap->capabilities = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING;
@@ -401,12 +403,12 @@ static int sh_vou_querycap(struct file *file, void *priv,
401static int sh_vou_enum_fmt_vid_out(struct file *file, void *priv, 403static int sh_vou_enum_fmt_vid_out(struct file *file, void *priv,
402 struct v4l2_fmtdesc *fmt) 404 struct v4l2_fmtdesc *fmt)
403{ 405{
404 struct sh_vou_file *vou_file = priv; 406 struct sh_vou_device *vou_dev = video_drvdata(file);
405 407
406 if (fmt->index >= ARRAY_SIZE(vou_fmt)) 408 if (fmt->index >= ARRAY_SIZE(vou_fmt))
407 return -EINVAL; 409 return -EINVAL;
408 410
409 dev_dbg(vou_file->vbq.dev, "%s()\n", __func__); 411 dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__);
410 412
411 fmt->type = V4L2_BUF_TYPE_VIDEO_OUTPUT; 413 fmt->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
412 strlcpy(fmt->description, vou_fmt[fmt->index].desc, 414 strlcpy(fmt->description, vou_fmt[fmt->index].desc,
@@ -419,8 +421,7 @@ static int sh_vou_enum_fmt_vid_out(struct file *file, void *priv,
419static int sh_vou_g_fmt_vid_out(struct file *file, void *priv, 421static int sh_vou_g_fmt_vid_out(struct file *file, void *priv,
420 struct v4l2_format *fmt) 422 struct v4l2_format *fmt)
421{ 423{
422 struct video_device *vdev = video_devdata(file); 424 struct sh_vou_device *vou_dev = video_drvdata(file);
423 struct sh_vou_device *vou_dev = video_get_drvdata(vdev);
424 425
425 dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__); 426 dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__);
426 427
@@ -595,9 +596,9 @@ static void vou_adjust_input(struct sh_vou_geometry *geo, v4l2_std_id std)
595 */ 596 */
596static void vou_adjust_output(struct sh_vou_geometry *geo, v4l2_std_id std) 597static void vou_adjust_output(struct sh_vou_geometry *geo, v4l2_std_id std)
597{ 598{
598 unsigned int best_err = UINT_MAX, best, width_max, height_max, 599 unsigned int best_err = UINT_MAX, best = geo->in_width,
599 img_height_max; 600 width_max, height_max, img_height_max;
600 int i, idx; 601 int i, idx = 0;
601 602
602 if (std & V4L2_STD_525_60) { 603 if (std & V4L2_STD_525_60) {
603 width_max = 858; 604 width_max = 858;
@@ -671,8 +672,7 @@ static void vou_adjust_output(struct sh_vou_geometry *geo, v4l2_std_id std)
671static int sh_vou_s_fmt_vid_out(struct file *file, void *priv, 672static int sh_vou_s_fmt_vid_out(struct file *file, void *priv,
672 struct v4l2_format *fmt) 673 struct v4l2_format *fmt)
673{ 674{
674 struct video_device *vdev = video_devdata(file); 675 struct sh_vou_device *vou_dev = video_drvdata(file);
675 struct sh_vou_device *vou_dev = video_get_drvdata(vdev);
676 struct v4l2_pix_format *pix = &fmt->fmt.pix; 676 struct v4l2_pix_format *pix = &fmt->fmt.pix;
677 unsigned int img_height_max; 677 unsigned int img_height_max;
678 int pix_idx; 678 int pix_idx;
@@ -764,11 +764,11 @@ static int sh_vou_s_fmt_vid_out(struct file *file, void *priv,
764static int sh_vou_try_fmt_vid_out(struct file *file, void *priv, 764static int sh_vou_try_fmt_vid_out(struct file *file, void *priv,
765 struct v4l2_format *fmt) 765 struct v4l2_format *fmt)
766{ 766{
767 struct sh_vou_file *vou_file = priv; 767 struct sh_vou_device *vou_dev = video_drvdata(file);
768 struct v4l2_pix_format *pix = &fmt->fmt.pix; 768 struct v4l2_pix_format *pix = &fmt->fmt.pix;
769 int i; 769 int i;
770 770
771 dev_dbg(vou_file->vbq.dev, "%s()\n", __func__); 771 dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__);
772 772
773 fmt->type = V4L2_BUF_TYPE_VIDEO_OUTPUT; 773 fmt->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
774 pix->field = V4L2_FIELD_NONE; 774 pix->field = V4L2_FIELD_NONE;
@@ -788,9 +788,10 @@ static int sh_vou_try_fmt_vid_out(struct file *file, void *priv,
788static int sh_vou_reqbufs(struct file *file, void *priv, 788static int sh_vou_reqbufs(struct file *file, void *priv,
789 struct v4l2_requestbuffers *req) 789 struct v4l2_requestbuffers *req)
790{ 790{
791 struct sh_vou_device *vou_dev = video_drvdata(file);
791 struct sh_vou_file *vou_file = priv; 792 struct sh_vou_file *vou_file = priv;
792 793
793 dev_dbg(vou_file->vbq.dev, "%s()\n", __func__); 794 dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__);
794 795
795 if (req->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) 796 if (req->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
796 return -EINVAL; 797 return -EINVAL;
@@ -801,27 +802,30 @@ static int sh_vou_reqbufs(struct file *file, void *priv,
801static int sh_vou_querybuf(struct file *file, void *priv, 802static int sh_vou_querybuf(struct file *file, void *priv,
802 struct v4l2_buffer *b) 803 struct v4l2_buffer *b)
803{ 804{
805 struct sh_vou_device *vou_dev = video_drvdata(file);
804 struct sh_vou_file *vou_file = priv; 806 struct sh_vou_file *vou_file = priv;
805 807
806 dev_dbg(vou_file->vbq.dev, "%s()\n", __func__); 808 dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__);
807 809
808 return videobuf_querybuf(&vou_file->vbq, b); 810 return videobuf_querybuf(&vou_file->vbq, b);
809} 811}
810 812
811static int sh_vou_qbuf(struct file *file, void *priv, struct v4l2_buffer *b) 813static int sh_vou_qbuf(struct file *file, void *priv, struct v4l2_buffer *b)
812{ 814{
815 struct sh_vou_device *vou_dev = video_drvdata(file);
813 struct sh_vou_file *vou_file = priv; 816 struct sh_vou_file *vou_file = priv;
814 817
815 dev_dbg(vou_file->vbq.dev, "%s()\n", __func__); 818 dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__);
816 819
817 return videobuf_qbuf(&vou_file->vbq, b); 820 return videobuf_qbuf(&vou_file->vbq, b);
818} 821}
819 822
820static int sh_vou_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b) 823static int sh_vou_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b)
821{ 824{
825 struct sh_vou_device *vou_dev = video_drvdata(file);
822 struct sh_vou_file *vou_file = priv; 826 struct sh_vou_file *vou_file = priv;
823 827
824 dev_dbg(vou_file->vbq.dev, "%s()\n", __func__); 828 dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__);
825 829
826 return videobuf_dqbuf(&vou_file->vbq, b, file->f_flags & O_NONBLOCK); 830 return videobuf_dqbuf(&vou_file->vbq, b, file->f_flags & O_NONBLOCK);
827} 831}
@@ -829,12 +833,11 @@ static int sh_vou_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b)
829static int sh_vou_streamon(struct file *file, void *priv, 833static int sh_vou_streamon(struct file *file, void *priv,
830 enum v4l2_buf_type buftype) 834 enum v4l2_buf_type buftype)
831{ 835{
832 struct video_device *vdev = video_devdata(file); 836 struct sh_vou_device *vou_dev = video_drvdata(file);
833 struct sh_vou_device *vou_dev = video_get_drvdata(vdev);
834 struct sh_vou_file *vou_file = priv; 837 struct sh_vou_file *vou_file = priv;
835 int ret; 838 int ret;
836 839
837 dev_dbg(vou_file->vbq.dev, "%s()\n", __func__); 840 dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__);
838 841
839 ret = v4l2_device_call_until_err(&vou_dev->v4l2_dev, 0, 842 ret = v4l2_device_call_until_err(&vou_dev->v4l2_dev, 0,
840 video, s_stream, 1); 843 video, s_stream, 1);
@@ -848,11 +851,10 @@ static int sh_vou_streamon(struct file *file, void *priv,
848static int sh_vou_streamoff(struct file *file, void *priv, 851static int sh_vou_streamoff(struct file *file, void *priv,
849 enum v4l2_buf_type buftype) 852 enum v4l2_buf_type buftype)
850{ 853{
851 struct video_device *vdev = video_devdata(file); 854 struct sh_vou_device *vou_dev = video_drvdata(file);
852 struct sh_vou_device *vou_dev = video_get_drvdata(vdev);
853 struct sh_vou_file *vou_file = priv; 855 struct sh_vou_file *vou_file = priv;
854 856
855 dev_dbg(vou_file->vbq.dev, "%s()\n", __func__); 857 dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__);
856 858
857 /* 859 /*
858 * This calls buf_release from host driver's videobuf_queue_ops for all 860 * This calls buf_release from host driver's videobuf_queue_ops for all
@@ -881,13 +883,12 @@ static u32 sh_vou_ntsc_mode(enum sh_vou_bus_fmt bus_fmt)
881 883
882static int sh_vou_s_std(struct file *file, void *priv, v4l2_std_id *std_id) 884static int sh_vou_s_std(struct file *file, void *priv, v4l2_std_id *std_id)
883{ 885{
884 struct video_device *vdev = video_devdata(file); 886 struct sh_vou_device *vou_dev = video_drvdata(file);
885 struct sh_vou_device *vou_dev = video_get_drvdata(vdev);
886 int ret; 887 int ret;
887 888
888 dev_dbg(vou_dev->v4l2_dev.dev, "%s(): 0x%llx\n", __func__, *std_id); 889 dev_dbg(vou_dev->v4l2_dev.dev, "%s(): 0x%llx\n", __func__, *std_id);
889 890
890 if (*std_id & ~vdev->tvnorms) 891 if (*std_id & ~vou_dev->vdev->tvnorms)
891 return -EINVAL; 892 return -EINVAL;
892 893
893 ret = v4l2_device_call_until_err(&vou_dev->v4l2_dev, 0, video, 894 ret = v4l2_device_call_until_err(&vou_dev->v4l2_dev, 0, video,
@@ -909,8 +910,7 @@ static int sh_vou_s_std(struct file *file, void *priv, v4l2_std_id *std_id)
909 910
910static int sh_vou_g_std(struct file *file, void *priv, v4l2_std_id *std) 911static int sh_vou_g_std(struct file *file, void *priv, v4l2_std_id *std)
911{ 912{
912 struct video_device *vdev = video_devdata(file); 913 struct sh_vou_device *vou_dev = video_drvdata(file);
913 struct sh_vou_device *vou_dev = video_get_drvdata(vdev);
914 914
915 dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__); 915 dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__);
916 916
@@ -921,8 +921,7 @@ static int sh_vou_g_std(struct file *file, void *priv, v4l2_std_id *std)
921 921
922static int sh_vou_g_crop(struct file *file, void *fh, struct v4l2_crop *a) 922static int sh_vou_g_crop(struct file *file, void *fh, struct v4l2_crop *a)
923{ 923{
924 struct video_device *vdev = video_devdata(file); 924 struct sh_vou_device *vou_dev = video_drvdata(file);
925 struct sh_vou_device *vou_dev = video_get_drvdata(vdev);
926 925
927 dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__); 926 dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__);
928 927
@@ -936,8 +935,7 @@ static int sh_vou_g_crop(struct file *file, void *fh, struct v4l2_crop *a)
936static int sh_vou_s_crop(struct file *file, void *fh, const struct v4l2_crop *a) 935static int sh_vou_s_crop(struct file *file, void *fh, const struct v4l2_crop *a)
937{ 936{
938 struct v4l2_crop a_writable = *a; 937 struct v4l2_crop a_writable = *a;
939 struct video_device *vdev = video_devdata(file); 938 struct sh_vou_device *vou_dev = video_drvdata(file);
940 struct sh_vou_device *vou_dev = video_get_drvdata(vdev);
941 struct v4l2_rect *rect = &a_writable.c; 939 struct v4l2_rect *rect = &a_writable.c;
942 struct v4l2_crop sd_crop = {.type = V4L2_BUF_TYPE_VIDEO_OUTPUT}; 940 struct v4l2_crop sd_crop = {.type = V4L2_BUF_TYPE_VIDEO_OUTPUT};
943 struct v4l2_pix_format *pix = &vou_dev->pix; 941 struct v4l2_pix_format *pix = &vou_dev->pix;
@@ -1028,9 +1026,9 @@ static int sh_vou_s_crop(struct file *file, void *fh, const struct v4l2_crop *a)
1028static int sh_vou_cropcap(struct file *file, void *priv, 1026static int sh_vou_cropcap(struct file *file, void *priv,
1029 struct v4l2_cropcap *a) 1027 struct v4l2_cropcap *a)
1030{ 1028{
1031 struct sh_vou_file *vou_file = priv; 1029 struct sh_vou_device *vou_dev = video_drvdata(file);
1032 1030
1033 dev_dbg(vou_file->vbq.dev, "%s()\n", __func__); 1031 dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__);
1034 1032
1035 a->type = V4L2_BUF_TYPE_VIDEO_OUTPUT; 1033 a->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
1036 a->bounds.left = 0; 1034 a->bounds.left = 0;
@@ -1091,7 +1089,7 @@ static irqreturn_t sh_vou_isr(int irq, void *dev_id)
1091 list_del(&vb->queue); 1089 list_del(&vb->queue);
1092 1090
1093 vb->state = VIDEOBUF_DONE; 1091 vb->state = VIDEOBUF_DONE;
1094 do_gettimeofday(&vb->ts); 1092 v4l2_get_timestamp(&vb->ts);
1095 vb->field_count++; 1093 vb->field_count++;
1096 wake_up(&vb->done); 1094 wake_up(&vb->done);
1097 1095
@@ -1160,8 +1158,7 @@ static int sh_vou_hw_init(struct sh_vou_device *vou_dev)
1160/* File operations */ 1158/* File operations */
1161static int sh_vou_open(struct file *file) 1159static int sh_vou_open(struct file *file)
1162{ 1160{
1163 struct video_device *vdev = video_devdata(file); 1161 struct sh_vou_device *vou_dev = video_drvdata(file);
1164 struct sh_vou_device *vou_dev = video_get_drvdata(vdev);
1165 struct sh_vou_file *vou_file = kzalloc(sizeof(struct sh_vou_file), 1162 struct sh_vou_file *vou_file = kzalloc(sizeof(struct sh_vou_file),
1166 GFP_KERNEL); 1163 GFP_KERNEL);
1167 1164
@@ -1178,11 +1175,11 @@ static int sh_vou_open(struct file *file)
1178 int ret; 1175 int ret;
1179 /* First open */ 1176 /* First open */
1180 vou_dev->status = SH_VOU_INITIALISING; 1177 vou_dev->status = SH_VOU_INITIALISING;
1181 pm_runtime_get_sync(vdev->v4l2_dev->dev); 1178 pm_runtime_get_sync(vou_dev->v4l2_dev.dev);
1182 ret = sh_vou_hw_init(vou_dev); 1179 ret = sh_vou_hw_init(vou_dev);
1183 if (ret < 0) { 1180 if (ret < 0) {
1184 atomic_dec(&vou_dev->use_count); 1181 atomic_dec(&vou_dev->use_count);
1185 pm_runtime_put(vdev->v4l2_dev->dev); 1182 pm_runtime_put(vou_dev->v4l2_dev.dev);
1186 vou_dev->status = SH_VOU_IDLE; 1183 vou_dev->status = SH_VOU_IDLE;
1187 mutex_unlock(&vou_dev->fop_lock); 1184 mutex_unlock(&vou_dev->fop_lock);
1188 return ret; 1185 return ret;
@@ -1193,8 +1190,8 @@ static int sh_vou_open(struct file *file)
1193 vou_dev->v4l2_dev.dev, &vou_dev->lock, 1190 vou_dev->v4l2_dev.dev, &vou_dev->lock,
1194 V4L2_BUF_TYPE_VIDEO_OUTPUT, 1191 V4L2_BUF_TYPE_VIDEO_OUTPUT,
1195 V4L2_FIELD_NONE, 1192 V4L2_FIELD_NONE,
1196 sizeof(struct videobuf_buffer), vdev, 1193 sizeof(struct videobuf_buffer),
1197 &vou_dev->fop_lock); 1194 vou_dev->vdev, &vou_dev->fop_lock);
1198 mutex_unlock(&vou_dev->fop_lock); 1195 mutex_unlock(&vou_dev->fop_lock);
1199 1196
1200 return 0; 1197 return 0;
@@ -1202,18 +1199,17 @@ static int sh_vou_open(struct file *file)
1202 1199
1203static int sh_vou_release(struct file *file) 1200static int sh_vou_release(struct file *file)
1204{ 1201{
1205 struct video_device *vdev = video_devdata(file); 1202 struct sh_vou_device *vou_dev = video_drvdata(file);
1206 struct sh_vou_device *vou_dev = video_get_drvdata(vdev);
1207 struct sh_vou_file *vou_file = file->private_data; 1203 struct sh_vou_file *vou_file = file->private_data;
1208 1204
1209 dev_dbg(vou_file->vbq.dev, "%s()\n", __func__); 1205 dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__);
1210 1206
1211 if (!atomic_dec_return(&vou_dev->use_count)) { 1207 if (!atomic_dec_return(&vou_dev->use_count)) {
1212 mutex_lock(&vou_dev->fop_lock); 1208 mutex_lock(&vou_dev->fop_lock);
1213 /* Last close */ 1209 /* Last close */
1214 vou_dev->status = SH_VOU_IDLE; 1210 vou_dev->status = SH_VOU_IDLE;
1215 sh_vou_reg_a_set(vou_dev, VOUER, 0, 0x101); 1211 sh_vou_reg_a_set(vou_dev, VOUER, 0, 0x101);
1216 pm_runtime_put(vdev->v4l2_dev->dev); 1212 pm_runtime_put(vou_dev->v4l2_dev.dev);
1217 mutex_unlock(&vou_dev->fop_lock); 1213 mutex_unlock(&vou_dev->fop_lock);
1218 } 1214 }
1219 1215
@@ -1225,12 +1221,11 @@ static int sh_vou_release(struct file *file)
1225 1221
1226static int sh_vou_mmap(struct file *file, struct vm_area_struct *vma) 1222static int sh_vou_mmap(struct file *file, struct vm_area_struct *vma)
1227{ 1223{
1228 struct video_device *vdev = video_devdata(file); 1224 struct sh_vou_device *vou_dev = video_drvdata(file);
1229 struct sh_vou_device *vou_dev = video_get_drvdata(vdev);
1230 struct sh_vou_file *vou_file = file->private_data; 1225 struct sh_vou_file *vou_file = file->private_data;
1231 int ret; 1226 int ret;
1232 1227
1233 dev_dbg(vou_file->vbq.dev, "%s()\n", __func__); 1228 dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__);
1234 1229
1235 if (mutex_lock_interruptible(&vou_dev->fop_lock)) 1230 if (mutex_lock_interruptible(&vou_dev->fop_lock))
1236 return -ERESTARTSYS; 1231 return -ERESTARTSYS;
@@ -1241,12 +1236,11 @@ static int sh_vou_mmap(struct file *file, struct vm_area_struct *vma)
1241 1236
1242static unsigned int sh_vou_poll(struct file *file, poll_table *wait) 1237static unsigned int sh_vou_poll(struct file *file, poll_table *wait)
1243{ 1238{
1244 struct video_device *vdev = video_devdata(file); 1239 struct sh_vou_device *vou_dev = video_drvdata(file);
1245 struct sh_vou_device *vou_dev = video_get_drvdata(vdev);
1246 struct sh_vou_file *vou_file = file->private_data; 1240 struct sh_vou_file *vou_file = file->private_data;
1247 unsigned int res; 1241 unsigned int res;
1248 1242
1249 dev_dbg(vou_file->vbq.dev, "%s()\n", __func__); 1243 dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__);
1250 1244
1251 mutex_lock(&vou_dev->fop_lock); 1245 mutex_lock(&vou_dev->fop_lock);
1252 res = videobuf_poll_stream(file, &vou_file->vbq, wait); 1246 res = videobuf_poll_stream(file, &vou_file->vbq, wait);
@@ -1257,8 +1251,7 @@ static unsigned int sh_vou_poll(struct file *file, poll_table *wait)
1257static int sh_vou_g_chip_ident(struct file *file, void *fh, 1251static int sh_vou_g_chip_ident(struct file *file, void *fh,
1258 struct v4l2_dbg_chip_ident *id) 1252 struct v4l2_dbg_chip_ident *id)
1259{ 1253{
1260 struct video_device *vdev = video_devdata(file); 1254 struct sh_vou_device *vou_dev = video_drvdata(file);
1261 struct sh_vou_device *vou_dev = video_get_drvdata(vdev);
1262 1255
1263 return v4l2_device_call_until_err(&vou_dev->v4l2_dev, 0, core, g_chip_ident, id); 1256 return v4l2_device_call_until_err(&vou_dev->v4l2_dev, 0, core, g_chip_ident, id);
1264} 1257}
@@ -1267,8 +1260,7 @@ static int sh_vou_g_chip_ident(struct file *file, void *fh,
1267static int sh_vou_g_register(struct file *file, void *fh, 1260static int sh_vou_g_register(struct file *file, void *fh,
1268 struct v4l2_dbg_register *reg) 1261 struct v4l2_dbg_register *reg)
1269{ 1262{
1270 struct video_device *vdev = video_devdata(file); 1263 struct sh_vou_device *vou_dev = video_drvdata(file);
1271 struct sh_vou_device *vou_dev = video_get_drvdata(vdev);
1272 1264
1273 return v4l2_device_call_until_err(&vou_dev->v4l2_dev, 0, core, g_register, reg); 1265 return v4l2_device_call_until_err(&vou_dev->v4l2_dev, 0, core, g_register, reg);
1274} 1266}
@@ -1276,8 +1268,7 @@ static int sh_vou_g_register(struct file *file, void *fh,
1276static int sh_vou_s_register(struct file *file, void *fh, 1268static int sh_vou_s_register(struct file *file, void *fh,
1277 struct v4l2_dbg_register *reg) 1269 struct v4l2_dbg_register *reg)
1278{ 1270{
1279 struct video_device *vdev = video_devdata(file); 1271 struct sh_vou_device *vou_dev = video_drvdata(file);
1280 struct sh_vou_device *vou_dev = video_get_drvdata(vdev);
1281 1272
1282 return v4l2_device_call_until_err(&vou_dev->v4l2_dev, 0, core, s_register, reg); 1273 return v4l2_device_call_until_err(&vou_dev->v4l2_dev, 0, core, s_register, reg);
1283} 1274}
diff --git a/drivers/media/platform/soc_camera/Kconfig b/drivers/media/platform/soc_camera/Kconfig
index cb6791e62bd4..b139b525bb16 100644
--- a/drivers/media/platform/soc_camera/Kconfig
+++ b/drivers/media/platform/soc_camera/Kconfig
@@ -70,13 +70,12 @@ config VIDEO_MX2_HOSTSUPPORT
70 bool 70 bool
71 71
72config VIDEO_MX2 72config VIDEO_MX2
73 tristate "i.MX27/i.MX25 Camera Sensor Interface driver" 73 tristate "i.MX27 Camera Sensor Interface driver"
74 depends on VIDEO_DEV && SOC_CAMERA && (MACH_MX27 || (ARCH_MX25 && BROKEN)) 74 depends on VIDEO_DEV && SOC_CAMERA && MACH_MX27
75 select VIDEOBUF2_DMA_CONTIG 75 select VIDEOBUF2_DMA_CONTIG
76 select VIDEO_MX2_HOSTSUPPORT 76 select VIDEO_MX2_HOSTSUPPORT
77 ---help--- 77 ---help---
78 This is a v4l2 driver for the i.MX27 and the i.MX25 Camera Sensor 78 This is a v4l2 driver for the i.MX27 Camera Sensor Interface
79 Interface
80 79
81config VIDEO_ATMEL_ISI 80config VIDEO_ATMEL_ISI
82 tristate "ATMEL Image Sensor Interface (ISI) support" 81 tristate "ATMEL Image Sensor Interface (ISI) support"
diff --git a/drivers/media/platform/soc_camera/atmel-isi.c b/drivers/media/platform/soc_camera/atmel-isi.c
index d96c8c7e01d9..82dbf99d347c 100644
--- a/drivers/media/platform/soc_camera/atmel-isi.c
+++ b/drivers/media/platform/soc_camera/atmel-isi.c
@@ -166,7 +166,7 @@ static irqreturn_t atmel_isi_handle_streaming(struct atmel_isi *isi)
166 struct frame_buffer *buf = isi->active; 166 struct frame_buffer *buf = isi->active;
167 167
168 list_del_init(&buf->list); 168 list_del_init(&buf->list);
169 do_gettimeofday(&vb->v4l2_buf.timestamp); 169 v4l2_get_timestamp(&vb->v4l2_buf.timestamp);
170 vb->v4l2_buf.sequence = isi->sequence++; 170 vb->v4l2_buf.sequence = isi->sequence++;
171 vb2_buffer_done(vb, VB2_BUF_STATE_DONE); 171 vb2_buffer_done(vb, VB2_BUF_STATE_DONE);
172 } 172 }
@@ -745,7 +745,7 @@ static int isi_camera_get_formats(struct soc_camera_device *icd,
745 return formats; 745 return formats;
746} 746}
747 747
748/* Called with .video_lock held */ 748/* Called with .host_lock held */
749static int isi_camera_add_device(struct soc_camera_device *icd) 749static int isi_camera_add_device(struct soc_camera_device *icd)
750{ 750{
751 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 751 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
@@ -770,7 +770,7 @@ static int isi_camera_add_device(struct soc_camera_device *icd)
770 icd->devnum); 770 icd->devnum);
771 return 0; 771 return 0;
772} 772}
773/* Called with .video_lock held */ 773/* Called with .host_lock held */
774static void isi_camera_remove_device(struct soc_camera_device *icd) 774static void isi_camera_remove_device(struct soc_camera_device *icd)
775{ 775{
776 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 776 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
diff --git a/drivers/media/platform/soc_camera/mx1_camera.c b/drivers/media/platform/soc_camera/mx1_camera.c
index 032b8c9097f9..25b2a285dc86 100644
--- a/drivers/media/platform/soc_camera/mx1_camera.c
+++ b/drivers/media/platform/soc_camera/mx1_camera.c
@@ -26,7 +26,6 @@
26#include <linux/mm.h> 26#include <linux/mm.h>
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/moduleparam.h> 28#include <linux/moduleparam.h>
29#include <linux/mutex.h>
30#include <linux/platform_device.h> 29#include <linux/platform_device.h>
31#include <linux/sched.h> 30#include <linux/sched.h>
32#include <linux/slab.h> 31#include <linux/slab.h>
@@ -307,7 +306,7 @@ static void mx1_camera_wakeup(struct mx1_camera_dev *pcdev,
307 /* _init is used to debug races, see comment in mx1_camera_reqbufs() */ 306 /* _init is used to debug races, see comment in mx1_camera_reqbufs() */
308 list_del_init(&vb->queue); 307 list_del_init(&vb->queue);
309 vb->state = VIDEOBUF_DONE; 308 vb->state = VIDEOBUF_DONE;
310 do_gettimeofday(&vb->ts); 309 v4l2_get_timestamp(&vb->ts);
311 vb->field_count++; 310 vb->field_count++;
312 wake_up(&vb->done); 311 wake_up(&vb->done);
313 312
@@ -373,7 +372,7 @@ static void mx1_camera_init_videobuf(struct videobuf_queue *q,
373 videobuf_queue_dma_contig_init(q, &mx1_videobuf_ops, icd->parent, 372 videobuf_queue_dma_contig_init(q, &mx1_videobuf_ops, icd->parent,
374 &pcdev->lock, V4L2_BUF_TYPE_VIDEO_CAPTURE, 373 &pcdev->lock, V4L2_BUF_TYPE_VIDEO_CAPTURE,
375 V4L2_FIELD_NONE, 374 V4L2_FIELD_NONE,
376 sizeof(struct mx1_buffer), icd, &icd->video_lock); 375 sizeof(struct mx1_buffer), icd, &ici->host_lock);
377} 376}
378 377
379static int mclk_get_divisor(struct mx1_camera_dev *pcdev) 378static int mclk_get_divisor(struct mx1_camera_dev *pcdev)
diff --git a/drivers/media/platform/soc_camera/mx2_camera.c b/drivers/media/platform/soc_camera/mx2_camera.c
index 4a574f3cfb2f..ffba7d91f413 100644
--- a/drivers/media/platform/soc_camera/mx2_camera.c
+++ b/drivers/media/platform/soc_camera/mx2_camera.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * V4L2 Driver for i.MX27/i.MX25 camera host 2 * V4L2 Driver for i.MX27 camera host
3 * 3 *
4 * Copyright (C) 2008, Sascha Hauer, Pengutronix 4 * Copyright (C) 2008, Sascha Hauer, Pengutronix
5 * Copyright (C) 2010, Baruch Siach, Orex Computed Radiography 5 * Copyright (C) 2010, Baruch Siach, Orex Computed Radiography
@@ -28,7 +28,6 @@
28#include <linux/time.h> 28#include <linux/time.h>
29#include <linux/device.h> 29#include <linux/device.h>
30#include <linux/platform_device.h> 30#include <linux/platform_device.h>
31#include <linux/mutex.h>
32#include <linux/clk.h> 31#include <linux/clk.h>
33 32
34#include <media/v4l2-common.h> 33#include <media/v4l2-common.h>
@@ -64,9 +63,7 @@
64#define CSICR1_RF_OR_INTEN (1 << 24) 63#define CSICR1_RF_OR_INTEN (1 << 24)
65#define CSICR1_STATFF_LEVEL (3 << 22) 64#define CSICR1_STATFF_LEVEL (3 << 22)
66#define CSICR1_STATFF_INTEN (1 << 21) 65#define CSICR1_STATFF_INTEN (1 << 21)
67#define CSICR1_RXFF_LEVEL(l) (((l) & 3) << 19) /* MX27 */ 66#define CSICR1_RXFF_LEVEL(l) (((l) & 3) << 19)
68#define CSICR1_FB2_DMA_INTEN (1 << 20) /* MX25 */
69#define CSICR1_FB1_DMA_INTEN (1 << 19) /* MX25 */
70#define CSICR1_RXFF_INTEN (1 << 18) 67#define CSICR1_RXFF_INTEN (1 << 18)
71#define CSICR1_SOF_POL (1 << 17) 68#define CSICR1_SOF_POL (1 << 17)
72#define CSICR1_SOF_INTEN (1 << 16) 69#define CSICR1_SOF_INTEN (1 << 16)
@@ -88,45 +85,15 @@
88#define SHIFT_RXFF_LEVEL 19 85#define SHIFT_RXFF_LEVEL 19
89#define SHIFT_MCLKDIV 12 86#define SHIFT_MCLKDIV 12
90 87
91/* control reg 3 */
92#define CSICR3_FRMCNT (0xFFFF << 16)
93#define CSICR3_FRMCNT_RST (1 << 15)
94#define CSICR3_DMA_REFLASH_RFF (1 << 14)
95#define CSICR3_DMA_REFLASH_SFF (1 << 13)
96#define CSICR3_DMA_REQ_EN_RFF (1 << 12)
97#define CSICR3_DMA_REQ_EN_SFF (1 << 11)
98#define CSICR3_RXFF_LEVEL(l) (((l) & 7) << 4) /* MX25 */
99#define CSICR3_CSI_SUP (1 << 3)
100#define CSICR3_ZERO_PACK_EN (1 << 2)
101#define CSICR3_ECC_INT_EN (1 << 1)
102#define CSICR3_ECC_AUTO_EN (1 << 0)
103
104#define SHIFT_FRMCNT 16 88#define SHIFT_FRMCNT 16
105 89
106/* csi status reg */
107#define CSISR_SFF_OR_INT (1 << 25)
108#define CSISR_RFF_OR_INT (1 << 24)
109#define CSISR_STATFF_INT (1 << 21)
110#define CSISR_DMA_TSF_FB2_INT (1 << 20) /* MX25 */
111#define CSISR_DMA_TSF_FB1_INT (1 << 19) /* MX25 */
112#define CSISR_RXFF_INT (1 << 18)
113#define CSISR_EOF_INT (1 << 17)
114#define CSISR_SOF_INT (1 << 16)
115#define CSISR_F2_INT (1 << 15)
116#define CSISR_F1_INT (1 << 14)
117#define CSISR_COF_INT (1 << 13)
118#define CSISR_ECC_INT (1 << 1)
119#define CSISR_DRDY (1 << 0)
120
121#define CSICR1 0x00 90#define CSICR1 0x00
122#define CSICR2 0x04 91#define CSICR2 0x04
123#define CSISR_IMX25 0x18 92#define CSISR 0x08
124#define CSISR_IMX27 0x08
125#define CSISTATFIFO 0x0c 93#define CSISTATFIFO 0x0c
126#define CSIRFIFO 0x10 94#define CSIRFIFO 0x10
127#define CSIRXCNT 0x14 95#define CSIRXCNT 0x14
128#define CSICR3_IMX25 0x08 96#define CSICR3 0x1c
129#define CSICR3_IMX27 0x1c
130#define CSIDMASA_STATFIFO 0x20 97#define CSIDMASA_STATFIFO 0x20
131#define CSIDMATA_STATFIFO 0x24 98#define CSIDMATA_STATFIFO 0x24
132#define CSIDMASA_FB1 0x28 99#define CSIDMASA_FB1 0x28
@@ -249,12 +216,6 @@ struct mx2_fmt_cfg {
249 struct mx2_prp_cfg cfg; 216 struct mx2_prp_cfg cfg;
250}; 217};
251 218
252enum mx2_buffer_state {
253 MX2_STATE_QUEUED,
254 MX2_STATE_ACTIVE,
255 MX2_STATE_DONE,
256};
257
258struct mx2_buf_internal { 219struct mx2_buf_internal {
259 struct list_head queue; 220 struct list_head queue;
260 int bufnum; 221 int bufnum;
@@ -265,12 +226,10 @@ struct mx2_buf_internal {
265struct mx2_buffer { 226struct mx2_buffer {
266 /* common v4l buffer stuff -- must be first */ 227 /* common v4l buffer stuff -- must be first */
267 struct vb2_buffer vb; 228 struct vb2_buffer vb;
268 enum mx2_buffer_state state;
269 struct mx2_buf_internal internal; 229 struct mx2_buf_internal internal;
270}; 230};
271 231
272enum mx2_camera_type { 232enum mx2_camera_type {
273 IMX25_CAMERA,
274 IMX27_CAMERA, 233 IMX27_CAMERA,
275}; 234};
276 235
@@ -298,8 +257,6 @@ struct mx2_camera_dev {
298 struct mx2_buffer *fb2_active; 257 struct mx2_buffer *fb2_active;
299 258
300 u32 csicr1; 259 u32 csicr1;
301 u32 reg_csisr;
302 u32 reg_csicr3;
303 enum mx2_camera_type devtype; 260 enum mx2_camera_type devtype;
304 261
305 struct mx2_buf_internal buf_discard[2]; 262 struct mx2_buf_internal buf_discard[2];
@@ -315,9 +272,6 @@ struct mx2_camera_dev {
315 272
316static struct platform_device_id mx2_camera_devtype[] = { 273static struct platform_device_id mx2_camera_devtype[] = {
317 { 274 {
318 .name = "imx25-camera",
319 .driver_data = IMX25_CAMERA,
320 }, {
321 .name = "imx27-camera", 275 .name = "imx27-camera",
322 .driver_data = IMX27_CAMERA, 276 .driver_data = IMX27_CAMERA,
323 }, { 277 }, {
@@ -326,16 +280,6 @@ static struct platform_device_id mx2_camera_devtype[] = {
326}; 280};
327MODULE_DEVICE_TABLE(platform, mx2_camera_devtype); 281MODULE_DEVICE_TABLE(platform, mx2_camera_devtype);
328 282
329static inline int is_imx25_camera(struct mx2_camera_dev *pcdev)
330{
331 return pcdev->devtype == IMX25_CAMERA;
332}
333
334static inline int is_imx27_camera(struct mx2_camera_dev *pcdev)
335{
336 return pcdev->devtype == IMX27_CAMERA;
337}
338
339static struct mx2_buffer *mx2_ibuf_to_buf(struct mx2_buf_internal *int_buf) 283static struct mx2_buffer *mx2_ibuf_to_buf(struct mx2_buf_internal *int_buf)
340{ 284{
341 return container_of(int_buf, struct mx2_buffer, internal); 285 return container_of(int_buf, struct mx2_buffer, internal);
@@ -463,21 +407,10 @@ static void mx27_update_emma_buf(struct mx2_camera_dev *pcdev,
463 407
464static void mx2_camera_deactivate(struct mx2_camera_dev *pcdev) 408static void mx2_camera_deactivate(struct mx2_camera_dev *pcdev)
465{ 409{
466 unsigned long flags;
467
468 clk_disable_unprepare(pcdev->clk_csi_ahb); 410 clk_disable_unprepare(pcdev->clk_csi_ahb);
469 clk_disable_unprepare(pcdev->clk_csi_per); 411 clk_disable_unprepare(pcdev->clk_csi_per);
470 writel(0, pcdev->base_csi + CSICR1); 412 writel(0, pcdev->base_csi + CSICR1);
471 if (is_imx27_camera(pcdev)) { 413 writel(0, pcdev->base_emma + PRP_CNTL);
472 writel(0, pcdev->base_emma + PRP_CNTL);
473 } else if (is_imx25_camera(pcdev)) {
474 spin_lock_irqsave(&pcdev->lock, flags);
475 pcdev->fb1_active = NULL;
476 pcdev->fb2_active = NULL;
477 writel(0, pcdev->base_csi + CSIDMASA_FB1);
478 writel(0, pcdev->base_csi + CSIDMASA_FB2);
479 spin_unlock_irqrestore(&pcdev->lock, flags);
480 }
481} 414}
482 415
483/* 416/*
@@ -502,11 +435,8 @@ static int mx2_camera_add_device(struct soc_camera_device *icd)
502 if (ret < 0) 435 if (ret < 0)
503 goto exit_csi_ahb; 436 goto exit_csi_ahb;
504 437
505 csicr1 = CSICR1_MCLKEN; 438 csicr1 = CSICR1_MCLKEN | CSICR1_PRP_IF_EN | CSICR1_FCC |
506 439 CSICR1_RXFF_LEVEL(0);
507 if (is_imx27_camera(pcdev))
508 csicr1 |= CSICR1_PRP_IF_EN | CSICR1_FCC |
509 CSICR1_RXFF_LEVEL(0);
510 440
511 pcdev->csicr1 = csicr1; 441 pcdev->csicr1 = csicr1;
512 writel(pcdev->csicr1, pcdev->base_csi + CSICR1); 442 writel(pcdev->csicr1, pcdev->base_csi + CSICR1);
@@ -540,65 +470,6 @@ static void mx2_camera_remove_device(struct soc_camera_device *icd)
540 pcdev->icd = NULL; 470 pcdev->icd = NULL;
541} 471}
542 472
543static void mx25_camera_frame_done(struct mx2_camera_dev *pcdev, int fb,
544 int state)
545{
546 struct vb2_buffer *vb;
547 struct mx2_buffer *buf;
548 struct mx2_buffer **fb_active = fb == 1 ? &pcdev->fb1_active :
549 &pcdev->fb2_active;
550 u32 fb_reg = fb == 1 ? CSIDMASA_FB1 : CSIDMASA_FB2;
551 unsigned long flags;
552
553 spin_lock_irqsave(&pcdev->lock, flags);
554
555 if (*fb_active == NULL)
556 goto out;
557
558 vb = &(*fb_active)->vb;
559 dev_dbg(pcdev->dev, "%s (vb=0x%p) 0x%p %lu\n", __func__,
560 vb, vb2_plane_vaddr(vb, 0), vb2_get_plane_payload(vb, 0));
561
562 do_gettimeofday(&vb->v4l2_buf.timestamp);
563 vb->v4l2_buf.sequence++;
564 vb2_buffer_done(vb, VB2_BUF_STATE_DONE);
565
566 if (list_empty(&pcdev->capture)) {
567 buf = NULL;
568 writel(0, pcdev->base_csi + fb_reg);
569 } else {
570 buf = list_first_entry(&pcdev->capture, struct mx2_buffer,
571 internal.queue);
572 vb = &buf->vb;
573 list_del(&buf->internal.queue);
574 buf->state = MX2_STATE_ACTIVE;
575 writel(vb2_dma_contig_plane_dma_addr(vb, 0),
576 pcdev->base_csi + fb_reg);
577 }
578
579 *fb_active = buf;
580
581out:
582 spin_unlock_irqrestore(&pcdev->lock, flags);
583}
584
585static irqreturn_t mx25_camera_irq(int irq_csi, void *data)
586{
587 struct mx2_camera_dev *pcdev = data;
588 u32 status = readl(pcdev->base_csi + pcdev->reg_csisr);
589
590 if (status & CSISR_DMA_TSF_FB1_INT)
591 mx25_camera_frame_done(pcdev, 1, MX2_STATE_DONE);
592 else if (status & CSISR_DMA_TSF_FB2_INT)
593 mx25_camera_frame_done(pcdev, 2, MX2_STATE_DONE);
594
595 /* FIXME: handle CSISR_RFF_OR_INT */
596
597 writel(status, pcdev->base_csi + pcdev->reg_csisr);
598
599 return IRQ_HANDLED;
600}
601
602/* 473/*
603 * Videobuf operations 474 * Videobuf operations
604 */ 475 */
@@ -676,97 +547,8 @@ static void mx2_videobuf_queue(struct vb2_buffer *vb)
676 547
677 spin_lock_irqsave(&pcdev->lock, flags); 548 spin_lock_irqsave(&pcdev->lock, flags);
678 549
679 buf->state = MX2_STATE_QUEUED;
680 list_add_tail(&buf->internal.queue, &pcdev->capture); 550 list_add_tail(&buf->internal.queue, &pcdev->capture);
681 551
682 if (is_imx25_camera(pcdev)) {
683 u32 csicr3, dma_inten = 0;
684
685 if (pcdev->fb1_active == NULL) {
686 writel(vb2_dma_contig_plane_dma_addr(vb, 0),
687 pcdev->base_csi + CSIDMASA_FB1);
688 pcdev->fb1_active = buf;
689 dma_inten = CSICR1_FB1_DMA_INTEN;
690 } else if (pcdev->fb2_active == NULL) {
691 writel(vb2_dma_contig_plane_dma_addr(vb, 0),
692 pcdev->base_csi + CSIDMASA_FB2);
693 pcdev->fb2_active = buf;
694 dma_inten = CSICR1_FB2_DMA_INTEN;
695 }
696
697 if (dma_inten) {
698 list_del(&buf->internal.queue);
699 buf->state = MX2_STATE_ACTIVE;
700
701 csicr3 = readl(pcdev->base_csi + pcdev->reg_csicr3);
702
703 /* Reflash DMA */
704 writel(csicr3 | CSICR3_DMA_REFLASH_RFF,
705 pcdev->base_csi + pcdev->reg_csicr3);
706
707 /* clear & enable interrupts */
708 writel(dma_inten, pcdev->base_csi + pcdev->reg_csisr);
709 pcdev->csicr1 |= dma_inten;
710 writel(pcdev->csicr1, pcdev->base_csi + CSICR1);
711
712 /* enable DMA */
713 csicr3 |= CSICR3_DMA_REQ_EN_RFF | CSICR3_RXFF_LEVEL(1);
714 writel(csicr3, pcdev->base_csi + pcdev->reg_csicr3);
715 }
716 }
717
718 spin_unlock_irqrestore(&pcdev->lock, flags);
719}
720
721static void mx2_videobuf_release(struct vb2_buffer *vb)
722{
723 struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2_queue);
724 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
725 struct mx2_camera_dev *pcdev = ici->priv;
726 struct mx2_buffer *buf = container_of(vb, struct mx2_buffer, vb);
727 unsigned long flags;
728
729#ifdef DEBUG
730 dev_dbg(icd->parent, "%s (vb=0x%p) 0x%p %lu\n", __func__,
731 vb, vb2_plane_vaddr(vb, 0), vb2_get_plane_payload(vb, 0));
732
733 switch (buf->state) {
734 case MX2_STATE_ACTIVE:
735 dev_info(icd->parent, "%s (active)\n", __func__);
736 break;
737 case MX2_STATE_QUEUED:
738 dev_info(icd->parent, "%s (queued)\n", __func__);
739 break;
740 default:
741 dev_info(icd->parent, "%s (unknown) %d\n", __func__,
742 buf->state);
743 break;
744 }
745#endif
746
747 /*
748 * Terminate only queued but inactive buffers. Active buffers are
749 * released when they become inactive after videobuf_waiton().
750 *
751 * FIXME: implement forced termination of active buffers for mx27 and
752 * mx27 eMMA, so that the user won't get stuck in an uninterruptible
753 * state. This requires a specific handling for each of the these DMA
754 * types.
755 */
756
757 spin_lock_irqsave(&pcdev->lock, flags);
758 if (is_imx25_camera(pcdev) && buf->state == MX2_STATE_ACTIVE) {
759 if (pcdev->fb1_active == buf) {
760 pcdev->csicr1 &= ~CSICR1_FB1_DMA_INTEN;
761 writel(0, pcdev->base_csi + CSIDMASA_FB1);
762 pcdev->fb1_active = NULL;
763 } else if (pcdev->fb2_active == buf) {
764 pcdev->csicr1 &= ~CSICR1_FB2_DMA_INTEN;
765 writel(0, pcdev->base_csi + CSIDMASA_FB2);
766 pcdev->fb2_active = NULL;
767 }
768 writel(pcdev->csicr1, pcdev->base_csi + CSICR1);
769 }
770 spin_unlock_irqrestore(&pcdev->lock, flags); 552 spin_unlock_irqrestore(&pcdev->lock, flags);
771} 553}
772 554
@@ -877,91 +659,87 @@ static int mx2_start_streaming(struct vb2_queue *q, unsigned int count)
877 struct mx2_buffer *buf; 659 struct mx2_buffer *buf;
878 unsigned long phys; 660 unsigned long phys;
879 int bytesperline; 661 int bytesperline;
662 unsigned long flags;
880 663
881 if (is_imx27_camera(pcdev)) { 664 if (count < 2)
882 unsigned long flags; 665 return -EINVAL;
883 if (count < 2)
884 return -EINVAL;
885 666
886 spin_lock_irqsave(&pcdev->lock, flags); 667 spin_lock_irqsave(&pcdev->lock, flags);
887 668
888 buf = list_first_entry(&pcdev->capture, struct mx2_buffer, 669 buf = list_first_entry(&pcdev->capture, struct mx2_buffer,
889 internal.queue); 670 internal.queue);
890 buf->internal.bufnum = 0; 671 buf->internal.bufnum = 0;
891 vb = &buf->vb; 672 vb = &buf->vb;
892 buf->state = MX2_STATE_ACTIVE;
893 673
894 phys = vb2_dma_contig_plane_dma_addr(vb, 0); 674 phys = vb2_dma_contig_plane_dma_addr(vb, 0);
895 mx27_update_emma_buf(pcdev, phys, buf->internal.bufnum); 675 mx27_update_emma_buf(pcdev, phys, buf->internal.bufnum);
896 list_move_tail(pcdev->capture.next, &pcdev->active_bufs); 676 list_move_tail(pcdev->capture.next, &pcdev->active_bufs);
897 677
898 buf = list_first_entry(&pcdev->capture, struct mx2_buffer, 678 buf = list_first_entry(&pcdev->capture, struct mx2_buffer,
899 internal.queue); 679 internal.queue);
900 buf->internal.bufnum = 1; 680 buf->internal.bufnum = 1;
901 vb = &buf->vb; 681 vb = &buf->vb;
902 buf->state = MX2_STATE_ACTIVE;
903 682
904 phys = vb2_dma_contig_plane_dma_addr(vb, 0); 683 phys = vb2_dma_contig_plane_dma_addr(vb, 0);
905 mx27_update_emma_buf(pcdev, phys, buf->internal.bufnum); 684 mx27_update_emma_buf(pcdev, phys, buf->internal.bufnum);
906 list_move_tail(pcdev->capture.next, &pcdev->active_bufs); 685 list_move_tail(pcdev->capture.next, &pcdev->active_bufs);
907
908 bytesperline = soc_mbus_bytes_per_line(icd->user_width,
909 icd->current_fmt->host_fmt);
910 if (bytesperline < 0) {
911 spin_unlock_irqrestore(&pcdev->lock, flags);
912 return bytesperline;
913 }
914 686
915 /* 687 bytesperline = soc_mbus_bytes_per_line(icd->user_width,
916 * I didn't manage to properly enable/disable the prp 688 icd->current_fmt->host_fmt);
917 * on a per frame basis during running transfers, 689 if (bytesperline < 0) {
918 * thus we allocate a buffer here and use it to 690 spin_unlock_irqrestore(&pcdev->lock, flags);
919 * discard frames when no buffer is available. 691 return bytesperline;
920 * Feel free to work on this ;) 692 }
921 */
922 pcdev->discard_size = icd->user_height * bytesperline;
923 pcdev->discard_buffer = dma_alloc_coherent(ici->v4l2_dev.dev,
924 pcdev->discard_size, &pcdev->discard_buffer_dma,
925 GFP_KERNEL);
926 if (!pcdev->discard_buffer) {
927 spin_unlock_irqrestore(&pcdev->lock, flags);
928 return -ENOMEM;
929 }
930 693
931 pcdev->buf_discard[0].discard = true; 694 /*
932 list_add_tail(&pcdev->buf_discard[0].queue, 695 * I didn't manage to properly enable/disable the prp
933 &pcdev->discard); 696 * on a per frame basis during running transfers,
697 * thus we allocate a buffer here and use it to
698 * discard frames when no buffer is available.
699 * Feel free to work on this ;)
700 */
701 pcdev->discard_size = icd->user_height * bytesperline;
702 pcdev->discard_buffer = dma_alloc_coherent(ici->v4l2_dev.dev,
703 pcdev->discard_size,
704 &pcdev->discard_buffer_dma, GFP_ATOMIC);
705 if (!pcdev->discard_buffer) {
706 spin_unlock_irqrestore(&pcdev->lock, flags);
707 return -ENOMEM;
708 }
934 709
935 pcdev->buf_discard[1].discard = true; 710 pcdev->buf_discard[0].discard = true;
936 list_add_tail(&pcdev->buf_discard[1].queue, 711 list_add_tail(&pcdev->buf_discard[0].queue,
937 &pcdev->discard); 712 &pcdev->discard);
938 713
939 mx2_prp_resize_commit(pcdev); 714 pcdev->buf_discard[1].discard = true;
715 list_add_tail(&pcdev->buf_discard[1].queue,
716 &pcdev->discard);
940 717
941 mx27_camera_emma_buf_init(icd, bytesperline); 718 mx2_prp_resize_commit(pcdev);
942 719
943 if (prp->cfg.channel == 1) { 720 mx27_camera_emma_buf_init(icd, bytesperline);
944 writel(PRP_CNTL_CH1EN | 721
945 PRP_CNTL_CSIEN | 722 if (prp->cfg.channel == 1) {
946 prp->cfg.in_fmt | 723 writel(PRP_CNTL_CH1EN |
947 prp->cfg.out_fmt | 724 PRP_CNTL_CSIEN |
948 PRP_CNTL_CH1_LEN | 725 prp->cfg.in_fmt |
949 PRP_CNTL_CH1BYP | 726 prp->cfg.out_fmt |
950 PRP_CNTL_CH1_TSKIP(0) | 727 PRP_CNTL_CH1_LEN |
951 PRP_CNTL_IN_TSKIP(0), 728 PRP_CNTL_CH1BYP |
952 pcdev->base_emma + PRP_CNTL); 729 PRP_CNTL_CH1_TSKIP(0) |
953 } else { 730 PRP_CNTL_IN_TSKIP(0),
954 writel(PRP_CNTL_CH2EN | 731 pcdev->base_emma + PRP_CNTL);
955 PRP_CNTL_CSIEN | 732 } else {
956 prp->cfg.in_fmt | 733 writel(PRP_CNTL_CH2EN |
957 prp->cfg.out_fmt | 734 PRP_CNTL_CSIEN |
958 PRP_CNTL_CH2_LEN | 735 prp->cfg.in_fmt |
959 PRP_CNTL_CH2_TSKIP(0) | 736 prp->cfg.out_fmt |
960 PRP_CNTL_IN_TSKIP(0), 737 PRP_CNTL_CH2_LEN |
961 pcdev->base_emma + PRP_CNTL); 738 PRP_CNTL_CH2_TSKIP(0) |
962 } 739 PRP_CNTL_IN_TSKIP(0),
963 spin_unlock_irqrestore(&pcdev->lock, flags); 740 pcdev->base_emma + PRP_CNTL);
964 } 741 }
742 spin_unlock_irqrestore(&pcdev->lock, flags);
965 743
966 return 0; 744 return 0;
967} 745}
@@ -977,29 +755,27 @@ static int mx2_stop_streaming(struct vb2_queue *q)
977 void *b; 755 void *b;
978 u32 cntl; 756 u32 cntl;
979 757
980 if (is_imx27_camera(pcdev)) { 758 spin_lock_irqsave(&pcdev->lock, flags);
981 spin_lock_irqsave(&pcdev->lock, flags);
982 759
983 cntl = readl(pcdev->base_emma + PRP_CNTL); 760 cntl = readl(pcdev->base_emma + PRP_CNTL);
984 if (prp->cfg.channel == 1) { 761 if (prp->cfg.channel == 1) {
985 writel(cntl & ~PRP_CNTL_CH1EN, 762 writel(cntl & ~PRP_CNTL_CH1EN,
986 pcdev->base_emma + PRP_CNTL); 763 pcdev->base_emma + PRP_CNTL);
987 } else { 764 } else {
988 writel(cntl & ~PRP_CNTL_CH2EN, 765 writel(cntl & ~PRP_CNTL_CH2EN,
989 pcdev->base_emma + PRP_CNTL); 766 pcdev->base_emma + PRP_CNTL);
990 } 767 }
991 INIT_LIST_HEAD(&pcdev->capture); 768 INIT_LIST_HEAD(&pcdev->capture);
992 INIT_LIST_HEAD(&pcdev->active_bufs); 769 INIT_LIST_HEAD(&pcdev->active_bufs);
993 INIT_LIST_HEAD(&pcdev->discard); 770 INIT_LIST_HEAD(&pcdev->discard);
994 771
995 b = pcdev->discard_buffer; 772 b = pcdev->discard_buffer;
996 pcdev->discard_buffer = NULL; 773 pcdev->discard_buffer = NULL;
997 774
998 spin_unlock_irqrestore(&pcdev->lock, flags); 775 spin_unlock_irqrestore(&pcdev->lock, flags);
999 776
1000 dma_free_coherent(ici->v4l2_dev.dev, 777 dma_free_coherent(ici->v4l2_dev.dev,
1001 pcdev->discard_size, b, pcdev->discard_buffer_dma); 778 pcdev->discard_size, b, pcdev->discard_buffer_dma);
1002 }
1003 779
1004 return 0; 780 return 0;
1005} 781}
@@ -1008,7 +784,6 @@ static struct vb2_ops mx2_videobuf_ops = {
1008 .queue_setup = mx2_videobuf_setup, 784 .queue_setup = mx2_videobuf_setup,
1009 .buf_prepare = mx2_videobuf_prepare, 785 .buf_prepare = mx2_videobuf_prepare,
1010 .buf_queue = mx2_videobuf_queue, 786 .buf_queue = mx2_videobuf_queue,
1011 .buf_cleanup = mx2_videobuf_release,
1012 .start_streaming = mx2_start_streaming, 787 .start_streaming = mx2_start_streaming,
1013 .stop_streaming = mx2_stop_streaming, 788 .stop_streaming = mx2_stop_streaming,
1014}; 789};
@@ -1129,16 +904,9 @@ static int mx2_camera_set_bus_param(struct soc_camera_device *icd)
1129 if (bytesperline < 0) 904 if (bytesperline < 0)
1130 return bytesperline; 905 return bytesperline;
1131 906
1132 if (is_imx27_camera(pcdev)) { 907 ret = mx27_camera_emma_prp_reset(pcdev);
1133 ret = mx27_camera_emma_prp_reset(pcdev); 908 if (ret)
1134 if (ret) 909 return ret;
1135 return ret;
1136 } else if (is_imx25_camera(pcdev)) {
1137 writel((bytesperline * icd->user_height) >> 2,
1138 pcdev->base_csi + CSIRXCNT);
1139 writel((bytesperline << 16) | icd->user_height,
1140 pcdev->base_csi + CSIIMAG_PARA);
1141 }
1142 910
1143 writel(pcdev->csicr1, pcdev->base_csi + CSICR1); 911 writel(pcdev->csicr1, pcdev->base_csi + CSICR1);
1144 912
@@ -1425,7 +1193,6 @@ static int mx2_camera_try_fmt(struct soc_camera_device *icd,
1425 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 1193 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
1426 struct mx2_camera_dev *pcdev = ici->priv; 1194 struct mx2_camera_dev *pcdev = ici->priv;
1427 struct mx2_fmt_cfg *emma_prp; 1195 struct mx2_fmt_cfg *emma_prp;
1428 unsigned int width_limit;
1429 int ret; 1196 int ret;
1430 1197
1431 dev_dbg(icd->parent, "%s: requested params: width = %d, height = %d\n", 1198 dev_dbg(icd->parent, "%s: requested params: width = %d, height = %d\n",
@@ -1437,40 +1204,11 @@ static int mx2_camera_try_fmt(struct soc_camera_device *icd,
1437 return -EINVAL; 1204 return -EINVAL;
1438 } 1205 }
1439 1206
1440 /* FIXME: implement MX27 limits */ 1207 /*
1441 1208 * limit to MX27 hardware capabilities: width must be a multiple of 8 as
1442 /* limit to MX25 hardware capabilities */ 1209 * requested by the CSI. (Table 39-2 in the i.MX27 Reference Manual).
1443 if (is_imx25_camera(pcdev)) { 1210 */
1444 if (xlate->host_fmt->bits_per_sample <= 8) 1211 pix->width &= ~0x7;
1445 width_limit = 0xffff * 4;
1446 else
1447 width_limit = 0xffff * 2;
1448 /* CSIIMAG_PARA limit */
1449 if (pix->width > width_limit)
1450 pix->width = width_limit;
1451 if (pix->height > 0xffff)
1452 pix->height = 0xffff;
1453
1454 pix->bytesperline = soc_mbus_bytes_per_line(pix->width,
1455 xlate->host_fmt);
1456 if (pix->bytesperline < 0)
1457 return pix->bytesperline;
1458 pix->sizeimage = soc_mbus_image_size(xlate->host_fmt,
1459 pix->bytesperline, pix->height);
1460 /* Check against the CSIRXCNT limit */
1461 if (pix->sizeimage > 4 * 0x3ffff) {
1462 /* Adjust geometry, preserve aspect ratio */
1463 unsigned int new_height = int_sqrt(div_u64(0x3ffffULL *
1464 4 * pix->height, pix->bytesperline));
1465 pix->width = new_height * pix->width / pix->height;
1466 pix->height = new_height;
1467 pix->bytesperline = soc_mbus_bytes_per_line(pix->width,
1468 xlate->host_fmt);
1469 BUG_ON(pix->bytesperline < 0);
1470 pix->sizeimage = soc_mbus_image_size(xlate->host_fmt,
1471 pix->bytesperline, pix->height);
1472 }
1473 }
1474 1212
1475 /* limit to sensor capabilities */ 1213 /* limit to sensor capabilities */
1476 mf.width = pix->width; 1214 mf.width = pix->width;
@@ -1488,7 +1226,7 @@ static int mx2_camera_try_fmt(struct soc_camera_device *icd,
1488 1226
1489 /* If the sensor does not support image size try PrP resizing */ 1227 /* If the sensor does not support image size try PrP resizing */
1490 emma_prp = mx27_emma_prp_get_format(xlate->code, 1228 emma_prp = mx27_emma_prp_get_format(xlate->code,
1491 xlate->host_fmt->fourcc); 1229 xlate->host_fmt->fourcc);
1492 1230
1493 if ((mf.width != pix->width || mf.height != pix->height) && 1231 if ((mf.width != pix->width || mf.height != pix->height) &&
1494 emma_prp->cfg.in_fmt == PRP_CNTL_DATA_IN_YUV422) { 1232 emma_prp->cfg.in_fmt == PRP_CNTL_DATA_IN_YUV422) {
@@ -1600,7 +1338,7 @@ static void mx27_camera_frame_done_emma(struct mx2_camera_dev *pcdev,
1600 vb2_get_plane_payload(vb, 0)); 1338 vb2_get_plane_payload(vb, 0));
1601 1339
1602 list_del_init(&buf->internal.queue); 1340 list_del_init(&buf->internal.queue);
1603 do_gettimeofday(&vb->v4l2_buf.timestamp); 1341 v4l2_get_timestamp(&vb->v4l2_buf.timestamp);
1604 vb->v4l2_buf.sequence = pcdev->frame_count; 1342 vb->v4l2_buf.sequence = pcdev->frame_count;
1605 if (err) 1343 if (err)
1606 vb2_buffer_done(vb, VB2_BUF_STATE_ERROR); 1344 vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
@@ -1634,7 +1372,6 @@ static void mx27_camera_frame_done_emma(struct mx2_camera_dev *pcdev,
1634 list_move_tail(pcdev->capture.next, &pcdev->active_bufs); 1372 list_move_tail(pcdev->capture.next, &pcdev->active_bufs);
1635 1373
1636 vb = &buf->vb; 1374 vb = &buf->vb;
1637 buf->state = MX2_STATE_ACTIVE;
1638 1375
1639 phys = vb2_dma_contig_plane_dma_addr(vb, 0); 1376 phys = vb2_dma_contig_plane_dma_addr(vb, 0);
1640 mx27_update_emma_buf(pcdev, phys, bufnum); 1377 mx27_update_emma_buf(pcdev, phys, bufnum);
@@ -1774,20 +1511,6 @@ static int mx2_camera_probe(struct platform_device *pdev)
1774 goto exit; 1511 goto exit;
1775 } 1512 }
1776 1513
1777 pcdev->devtype = pdev->id_entry->driver_data;
1778 switch (pcdev->devtype) {
1779 case IMX25_CAMERA:
1780 pcdev->reg_csisr = CSISR_IMX25;
1781 pcdev->reg_csicr3 = CSICR3_IMX25;
1782 break;
1783 case IMX27_CAMERA:
1784 pcdev->reg_csisr = CSISR_IMX27;
1785 pcdev->reg_csicr3 = CSICR3_IMX27;
1786 break;
1787 default:
1788 break;
1789 }
1790
1791 pcdev->clk_csi_ahb = devm_clk_get(&pdev->dev, "ahb"); 1514 pcdev->clk_csi_ahb = devm_clk_get(&pdev->dev, "ahb");
1792 if (IS_ERR(pcdev->clk_csi_ahb)) { 1515 if (IS_ERR(pcdev->clk_csi_ahb)) {
1793 dev_err(&pdev->dev, "Could not get csi ahb clock\n"); 1516 dev_err(&pdev->dev, "Could not get csi ahb clock\n");
@@ -1833,20 +1556,9 @@ static int mx2_camera_probe(struct platform_device *pdev)
1833 pcdev->dev = &pdev->dev; 1556 pcdev->dev = &pdev->dev;
1834 platform_set_drvdata(pdev, pcdev); 1557 platform_set_drvdata(pdev, pcdev);
1835 1558
1836 if (is_imx25_camera(pcdev)) { 1559 err = mx27_camera_emma_init(pdev);
1837 err = devm_request_irq(&pdev->dev, irq_csi, mx25_camera_irq, 0, 1560 if (err)
1838 MX2_CAM_DRV_NAME, pcdev); 1561 goto exit;
1839 if (err) {
1840 dev_err(pcdev->dev, "Camera interrupt register failed \n");
1841 goto exit;
1842 }
1843 }
1844
1845 if (is_imx27_camera(pcdev)) {
1846 err = mx27_camera_emma_init(pdev);
1847 if (err)
1848 goto exit;
1849 }
1850 1562
1851 /* 1563 /*
1852 * We're done with drvdata here. Clear the pointer so that 1564 * We're done with drvdata here. Clear the pointer so that
@@ -1859,8 +1571,6 @@ static int mx2_camera_probe(struct platform_device *pdev)
1859 pcdev->soc_host.priv = pcdev; 1571 pcdev->soc_host.priv = pcdev;
1860 pcdev->soc_host.v4l2_dev.dev = &pdev->dev; 1572 pcdev->soc_host.v4l2_dev.dev = &pdev->dev;
1861 pcdev->soc_host.nr = pdev->id; 1573 pcdev->soc_host.nr = pdev->id;
1862 if (is_imx25_camera(pcdev))
1863 pcdev->soc_host.capabilities = SOCAM_HOST_CAP_STRIDE;
1864 1574
1865 pcdev->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev); 1575 pcdev->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev);
1866 if (IS_ERR(pcdev->alloc_ctx)) { 1576 if (IS_ERR(pcdev->alloc_ctx)) {
@@ -1879,10 +1589,8 @@ static int mx2_camera_probe(struct platform_device *pdev)
1879exit_free_emma: 1589exit_free_emma:
1880 vb2_dma_contig_cleanup_ctx(pcdev->alloc_ctx); 1590 vb2_dma_contig_cleanup_ctx(pcdev->alloc_ctx);
1881eallocctx: 1591eallocctx:
1882 if (is_imx27_camera(pcdev)) { 1592 clk_disable_unprepare(pcdev->clk_emma_ipg);
1883 clk_disable_unprepare(pcdev->clk_emma_ipg); 1593 clk_disable_unprepare(pcdev->clk_emma_ahb);
1884 clk_disable_unprepare(pcdev->clk_emma_ahb);
1885 }
1886exit: 1594exit:
1887 return err; 1595 return err;
1888} 1596}
@@ -1897,10 +1605,8 @@ static int mx2_camera_remove(struct platform_device *pdev)
1897 1605
1898 vb2_dma_contig_cleanup_ctx(pcdev->alloc_ctx); 1606 vb2_dma_contig_cleanup_ctx(pcdev->alloc_ctx);
1899 1607
1900 if (is_imx27_camera(pcdev)) { 1608 clk_disable_unprepare(pcdev->clk_emma_ipg);
1901 clk_disable_unprepare(pcdev->clk_emma_ipg); 1609 clk_disable_unprepare(pcdev->clk_emma_ahb);
1902 clk_disable_unprepare(pcdev->clk_emma_ahb);
1903 }
1904 1610
1905 dev_info(&pdev->dev, "MX2 Camera driver unloaded\n"); 1611 dev_info(&pdev->dev, "MX2 Camera driver unloaded\n");
1906 1612
@@ -1913,23 +1619,12 @@ static struct platform_driver mx2_camera_driver = {
1913 }, 1619 },
1914 .id_table = mx2_camera_devtype, 1620 .id_table = mx2_camera_devtype,
1915 .remove = mx2_camera_remove, 1621 .remove = mx2_camera_remove,
1622 .probe = mx2_camera_probe,
1916}; 1623};
1917 1624
1625module_platform_driver(mx2_camera_driver);
1918 1626
1919static int __init mx2_camera_init(void) 1627MODULE_DESCRIPTION("i.MX27 SoC Camera Host driver");
1920{
1921 return platform_driver_probe(&mx2_camera_driver, &mx2_camera_probe);
1922}
1923
1924static void __exit mx2_camera_exit(void)
1925{
1926 return platform_driver_unregister(&mx2_camera_driver);
1927}
1928
1929module_init(mx2_camera_init);
1930module_exit(mx2_camera_exit);
1931
1932MODULE_DESCRIPTION("i.MX27/i.MX25 SoC Camera Host driver");
1933MODULE_AUTHOR("Sascha Hauer <sha@pengutronix.de>"); 1628MODULE_AUTHOR("Sascha Hauer <sha@pengutronix.de>");
1934MODULE_LICENSE("GPL"); 1629MODULE_LICENSE("GPL");
1935MODULE_VERSION(MX2_CAM_VERSION); 1630MODULE_VERSION(MX2_CAM_VERSION);
diff --git a/drivers/media/platform/soc_camera/mx3_camera.c b/drivers/media/platform/soc_camera/mx3_camera.c
index 45aef1053a49..f5cbb92db545 100644
--- a/drivers/media/platform/soc_camera/mx3_camera.c
+++ b/drivers/media/platform/soc_camera/mx3_camera.c
@@ -156,7 +156,7 @@ static void mx3_cam_dma_done(void *arg)
156 struct mx3_camera_buffer *buf = to_mx3_vb(vb); 156 struct mx3_camera_buffer *buf = to_mx3_vb(vb);
157 157
158 list_del_init(&buf->queue); 158 list_del_init(&buf->queue);
159 do_gettimeofday(&vb->v4l2_buf.timestamp); 159 v4l2_get_timestamp(&vb->v4l2_buf.timestamp);
160 vb->v4l2_buf.field = mx3_cam->field; 160 vb->v4l2_buf.field = mx3_cam->field;
161 vb->v4l2_buf.sequence = mx3_cam->sequence++; 161 vb->v4l2_buf.sequence = mx3_cam->sequence++;
162 vb2_buffer_done(vb, VB2_BUF_STATE_DONE); 162 vb2_buffer_done(vb, VB2_BUF_STATE_DONE);
@@ -510,7 +510,7 @@ static void mx3_camera_activate(struct mx3_camera_dev *mx3_cam,
510 clk_set_rate(mx3_cam->clk, rate); 510 clk_set_rate(mx3_cam->clk, rate);
511} 511}
512 512
513/* Called with .video_lock held */ 513/* Called with .host_lock held */
514static int mx3_camera_add_device(struct soc_camera_device *icd) 514static int mx3_camera_add_device(struct soc_camera_device *icd)
515{ 515{
516 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 516 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
@@ -530,7 +530,7 @@ static int mx3_camera_add_device(struct soc_camera_device *icd)
530 return 0; 530 return 0;
531} 531}
532 532
533/* Called with .video_lock held */ 533/* Called with .host_lock held */
534static void mx3_camera_remove_device(struct soc_camera_device *icd) 534static void mx3_camera_remove_device(struct soc_camera_device *icd)
535{ 535{
536 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 536 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
diff --git a/drivers/media/platform/soc_camera/omap1_camera.c b/drivers/media/platform/soc_camera/omap1_camera.c
index 39a77f0b8860..2547bf88f79f 100644
--- a/drivers/media/platform/soc_camera/omap1_camera.c
+++ b/drivers/media/platform/soc_camera/omap1_camera.c
@@ -592,7 +592,7 @@ static void videobuf_done(struct omap1_cam_dev *pcdev,
592 suspend_capture(pcdev); 592 suspend_capture(pcdev);
593 } 593 }
594 vb->state = result; 594 vb->state = result;
595 do_gettimeofday(&vb->ts); 595 v4l2_get_timestamp(&vb->ts);
596 if (result != VIDEOBUF_ERROR) 596 if (result != VIDEOBUF_ERROR)
597 vb->field_count++; 597 vb->field_count++;
598 wake_up(&vb->done); 598 wake_up(&vb->done);
@@ -1383,12 +1383,12 @@ static void omap1_cam_init_videobuf(struct videobuf_queue *q,
1383 videobuf_queue_dma_contig_init(q, &omap1_videobuf_ops, 1383 videobuf_queue_dma_contig_init(q, &omap1_videobuf_ops,
1384 icd->parent, &pcdev->lock, 1384 icd->parent, &pcdev->lock,
1385 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE, 1385 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE,
1386 sizeof(struct omap1_cam_buf), icd, &icd->video_lock); 1386 sizeof(struct omap1_cam_buf), icd, &ici->host_lock);
1387 else 1387 else
1388 videobuf_queue_sg_init(q, &omap1_videobuf_ops, 1388 videobuf_queue_sg_init(q, &omap1_videobuf_ops,
1389 icd->parent, &pcdev->lock, 1389 icd->parent, &pcdev->lock,
1390 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE, 1390 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE,
1391 sizeof(struct omap1_cam_buf), icd, &icd->video_lock); 1391 sizeof(struct omap1_cam_buf), icd, &ici->host_lock);
1392 1392
1393 /* use videobuf mode (auto)selected with the module parameter */ 1393 /* use videobuf mode (auto)selected with the module parameter */
1394 pcdev->vb_mode = sg_mode ? OMAP1_CAM_DMA_SG : OMAP1_CAM_DMA_CONTIG; 1394 pcdev->vb_mode = sg_mode ? OMAP1_CAM_DMA_SG : OMAP1_CAM_DMA_CONTIG;
diff --git a/drivers/media/platform/soc_camera/pxa_camera.c b/drivers/media/platform/soc_camera/pxa_camera.c
index 523330d00dee..395e2e043615 100644
--- a/drivers/media/platform/soc_camera/pxa_camera.c
+++ b/drivers/media/platform/soc_camera/pxa_camera.c
@@ -681,7 +681,7 @@ static void pxa_camera_wakeup(struct pxa_camera_dev *pcdev,
681 /* _init is used to debug races, see comment in pxa_camera_reqbufs() */ 681 /* _init is used to debug races, see comment in pxa_camera_reqbufs() */
682 list_del_init(&vb->queue); 682 list_del_init(&vb->queue);
683 vb->state = VIDEOBUF_DONE; 683 vb->state = VIDEOBUF_DONE;
684 do_gettimeofday(&vb->ts); 684 v4l2_get_timestamp(&vb->ts);
685 vb->field_count++; 685 vb->field_count++;
686 wake_up(&vb->done); 686 wake_up(&vb->done);
687 dev_dbg(pcdev->soc_host.v4l2_dev.dev, "%s dequeud buffer (vb=0x%p)\n", 687 dev_dbg(pcdev->soc_host.v4l2_dev.dev, "%s dequeud buffer (vb=0x%p)\n",
@@ -842,7 +842,7 @@ static void pxa_camera_init_videobuf(struct videobuf_queue *q,
842 */ 842 */
843 videobuf_queue_sg_init(q, &pxa_videobuf_ops, NULL, &pcdev->lock, 843 videobuf_queue_sg_init(q, &pxa_videobuf_ops, NULL, &pcdev->lock,
844 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE, 844 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE,
845 sizeof(struct pxa_buffer), icd, &icd->video_lock); 845 sizeof(struct pxa_buffer), icd, &ici->host_lock);
846} 846}
847 847
848static u32 mclk_get_divisor(struct platform_device *pdev, 848static u32 mclk_get_divisor(struct platform_device *pdev,
@@ -958,7 +958,7 @@ static irqreturn_t pxa_camera_irq(int irq, void *data)
958/* 958/*
959 * The following two functions absolutely depend on the fact, that 959 * The following two functions absolutely depend on the fact, that
960 * there can be only one camera on PXA quick capture interface 960 * there can be only one camera on PXA quick capture interface
961 * Called with .video_lock held 961 * Called with .host_lock held
962 */ 962 */
963static int pxa_camera_add_device(struct soc_camera_device *icd) 963static int pxa_camera_add_device(struct soc_camera_device *icd)
964{ 964{
@@ -978,7 +978,7 @@ static int pxa_camera_add_device(struct soc_camera_device *icd)
978 return 0; 978 return 0;
979} 979}
980 980
981/* Called with .video_lock held */ 981/* Called with .host_lock held */
982static void pxa_camera_remove_device(struct soc_camera_device *icd) 982static void pxa_camera_remove_device(struct soc_camera_device *icd)
983{ 983{
984 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 984 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
@@ -1661,23 +1661,18 @@ static int pxa_camera_probe(struct platform_device *pdev)
1661 1661
1662 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1662 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1663 irq = platform_get_irq(pdev, 0); 1663 irq = platform_get_irq(pdev, 0);
1664 if (!res || irq < 0) { 1664 if (!res || irq < 0)
1665 err = -ENODEV; 1665 return -ENODEV;
1666 goto exit;
1667 }
1668 1666
1669 pcdev = kzalloc(sizeof(*pcdev), GFP_KERNEL); 1667 pcdev = devm_kzalloc(&pdev->dev, sizeof(*pcdev), GFP_KERNEL);
1670 if (!pcdev) { 1668 if (!pcdev) {
1671 dev_err(&pdev->dev, "Could not allocate pcdev\n"); 1669 dev_err(&pdev->dev, "Could not allocate pcdev\n");
1672 err = -ENOMEM; 1670 return -ENOMEM;
1673 goto exit;
1674 } 1671 }
1675 1672
1676 pcdev->clk = clk_get(&pdev->dev, NULL); 1673 pcdev->clk = devm_clk_get(&pdev->dev, NULL);
1677 if (IS_ERR(pcdev->clk)) { 1674 if (IS_ERR(pcdev->clk))
1678 err = PTR_ERR(pcdev->clk); 1675 return PTR_ERR(pcdev->clk);
1679 goto exit_kfree;
1680 }
1681 1676
1682 pcdev->res = res; 1677 pcdev->res = res;
1683 1678
@@ -1715,17 +1710,9 @@ static int pxa_camera_probe(struct platform_device *pdev)
1715 /* 1710 /*
1716 * Request the regions. 1711 * Request the regions.
1717 */ 1712 */
1718 if (!request_mem_region(res->start, resource_size(res), 1713 base = devm_request_and_ioremap(&pdev->dev, res);
1719 PXA_CAM_DRV_NAME)) { 1714 if (!base)
1720 err = -EBUSY; 1715 return -ENOMEM;
1721 goto exit_clk;
1722 }
1723
1724 base = ioremap(res->start, resource_size(res));
1725 if (!base) {
1726 err = -ENOMEM;
1727 goto exit_release;
1728 }
1729 pcdev->irq = irq; 1716 pcdev->irq = irq;
1730 pcdev->base = base; 1717 pcdev->base = base;
1731 1718
@@ -1734,7 +1721,7 @@ static int pxa_camera_probe(struct platform_device *pdev)
1734 pxa_camera_dma_irq_y, pcdev); 1721 pxa_camera_dma_irq_y, pcdev);
1735 if (err < 0) { 1722 if (err < 0) {
1736 dev_err(&pdev->dev, "Can't request DMA for Y\n"); 1723 dev_err(&pdev->dev, "Can't request DMA for Y\n");
1737 goto exit_iounmap; 1724 return err;
1738 } 1725 }
1739 pcdev->dma_chans[0] = err; 1726 pcdev->dma_chans[0] = err;
1740 dev_dbg(&pdev->dev, "got DMA channel %d\n", pcdev->dma_chans[0]); 1727 dev_dbg(&pdev->dev, "got DMA channel %d\n", pcdev->dma_chans[0]);
@@ -1762,10 +1749,10 @@ static int pxa_camera_probe(struct platform_device *pdev)
1762 DRCMR(70) = pcdev->dma_chans[2] | DRCMR_MAPVLD; 1749 DRCMR(70) = pcdev->dma_chans[2] | DRCMR_MAPVLD;
1763 1750
1764 /* request irq */ 1751 /* request irq */
1765 err = request_irq(pcdev->irq, pxa_camera_irq, 0, PXA_CAM_DRV_NAME, 1752 err = devm_request_irq(&pdev->dev, pcdev->irq, pxa_camera_irq, 0,
1766 pcdev); 1753 PXA_CAM_DRV_NAME, pcdev);
1767 if (err) { 1754 if (err) {
1768 dev_err(&pdev->dev, "Camera interrupt register failed \n"); 1755 dev_err(&pdev->dev, "Camera interrupt register failed\n");
1769 goto exit_free_dma; 1756 goto exit_free_dma;
1770 } 1757 }
1771 1758
@@ -1777,27 +1764,16 @@ static int pxa_camera_probe(struct platform_device *pdev)
1777 1764
1778 err = soc_camera_host_register(&pcdev->soc_host); 1765 err = soc_camera_host_register(&pcdev->soc_host);
1779 if (err) 1766 if (err)
1780 goto exit_free_irq; 1767 goto exit_free_dma;
1781 1768
1782 return 0; 1769 return 0;
1783 1770
1784exit_free_irq:
1785 free_irq(pcdev->irq, pcdev);
1786exit_free_dma: 1771exit_free_dma:
1787 pxa_free_dma(pcdev->dma_chans[2]); 1772 pxa_free_dma(pcdev->dma_chans[2]);
1788exit_free_dma_u: 1773exit_free_dma_u:
1789 pxa_free_dma(pcdev->dma_chans[1]); 1774 pxa_free_dma(pcdev->dma_chans[1]);
1790exit_free_dma_y: 1775exit_free_dma_y:
1791 pxa_free_dma(pcdev->dma_chans[0]); 1776 pxa_free_dma(pcdev->dma_chans[0]);
1792exit_iounmap:
1793 iounmap(base);
1794exit_release:
1795 release_mem_region(res->start, resource_size(res));
1796exit_clk:
1797 clk_put(pcdev->clk);
1798exit_kfree:
1799 kfree(pcdev);
1800exit:
1801 return err; 1777 return err;
1802} 1778}
1803 1779
@@ -1806,24 +1782,13 @@ static int pxa_camera_remove(struct platform_device *pdev)
1806 struct soc_camera_host *soc_host = to_soc_camera_host(&pdev->dev); 1782 struct soc_camera_host *soc_host = to_soc_camera_host(&pdev->dev);
1807 struct pxa_camera_dev *pcdev = container_of(soc_host, 1783 struct pxa_camera_dev *pcdev = container_of(soc_host,
1808 struct pxa_camera_dev, soc_host); 1784 struct pxa_camera_dev, soc_host);
1809 struct resource *res;
1810
1811 clk_put(pcdev->clk);
1812 1785
1813 pxa_free_dma(pcdev->dma_chans[0]); 1786 pxa_free_dma(pcdev->dma_chans[0]);
1814 pxa_free_dma(pcdev->dma_chans[1]); 1787 pxa_free_dma(pcdev->dma_chans[1]);
1815 pxa_free_dma(pcdev->dma_chans[2]); 1788 pxa_free_dma(pcdev->dma_chans[2]);
1816 free_irq(pcdev->irq, pcdev);
1817 1789
1818 soc_camera_host_unregister(soc_host); 1790 soc_camera_host_unregister(soc_host);
1819 1791
1820 iounmap(pcdev->base);
1821
1822 res = pcdev->res;
1823 release_mem_region(res->start, resource_size(res));
1824
1825 kfree(pcdev);
1826
1827 dev_info(&pdev->dev, "PXA Camera driver unloaded\n"); 1792 dev_info(&pdev->dev, "PXA Camera driver unloaded\n");
1828 1793
1829 return 0; 1794 return 0;
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 ebbc126e71a6..bb08a46432f4 100644
--- a/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c
+++ b/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c
@@ -516,7 +516,7 @@ static irqreturn_t sh_mobile_ceu_irq(int irq, void *data)
516 pcdev->active = NULL; 516 pcdev->active = NULL;
517 517
518 ret = sh_mobile_ceu_capture(pcdev); 518 ret = sh_mobile_ceu_capture(pcdev);
519 do_gettimeofday(&vb->v4l2_buf.timestamp); 519 v4l2_get_timestamp(&vb->v4l2_buf.timestamp);
520 if (!ret) { 520 if (!ret) {
521 vb->v4l2_buf.field = pcdev->field; 521 vb->v4l2_buf.field = pcdev->field;
522 vb->v4l2_buf.sequence = pcdev->sequence++; 522 vb->v4l2_buf.sequence = pcdev->sequence++;
@@ -543,7 +543,7 @@ static struct v4l2_subdev *find_csi2(struct sh_mobile_ceu_dev *pcdev)
543 return NULL; 543 return NULL;
544} 544}
545 545
546/* Called with .video_lock held */ 546/* Called with .host_lock held */
547static int sh_mobile_ceu_add_device(struct soc_camera_device *icd) 547static int sh_mobile_ceu_add_device(struct soc_camera_device *icd)
548{ 548{
549 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 549 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
@@ -572,7 +572,7 @@ static int sh_mobile_ceu_add_device(struct soc_camera_device *icd)
572 572
573 ret = v4l2_subdev_call(csi2_sd, core, s_power, 1); 573 ret = v4l2_subdev_call(csi2_sd, core, s_power, 1);
574 if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV) { 574 if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV) {
575 pm_runtime_put_sync(ici->v4l2_dev.dev); 575 pm_runtime_put(ici->v4l2_dev.dev);
576 return ret; 576 return ret;
577 } 577 }
578 578
@@ -587,7 +587,7 @@ static int sh_mobile_ceu_add_device(struct soc_camera_device *icd)
587 return 0; 587 return 0;
588} 588}
589 589
590/* Called with .video_lock held */ 590/* Called with .host_lock held */
591static void sh_mobile_ceu_remove_device(struct soc_camera_device *icd) 591static void sh_mobile_ceu_remove_device(struct soc_camera_device *icd)
592{ 592{
593 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 593 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
@@ -612,7 +612,7 @@ static void sh_mobile_ceu_remove_device(struct soc_camera_device *icd)
612 } 612 }
613 spin_unlock_irq(&pcdev->lock); 613 spin_unlock_irq(&pcdev->lock);
614 614
615 pm_runtime_put_sync(ici->v4l2_dev.dev); 615 pm_runtime_put(ici->v4l2_dev.dev);
616 616
617 dev_info(icd->parent, 617 dev_info(icd->parent,
618 "SuperH Mobile CEU driver detached from camera %d\n", 618 "SuperH Mobile CEU driver detached from camera %d\n",
@@ -1064,7 +1064,7 @@ static int sh_mobile_ceu_get_formats(struct soc_camera_device *icd, unsigned int
1064 1064
1065 /* Add our control */ 1065 /* Add our control */
1066 v4l2_ctrl_new_std(&icd->ctrl_handler, &sh_mobile_ceu_ctrl_ops, 1066 v4l2_ctrl_new_std(&icd->ctrl_handler, &sh_mobile_ceu_ctrl_ops,
1067 V4L2_CID_SHARPNESS, 0, 1, 1, 0); 1067 V4L2_CID_SHARPNESS, 0, 1, 1, 1);
1068 if (icd->ctrl_handler.error) 1068 if (icd->ctrl_handler.error)
1069 return icd->ctrl_handler.error; 1069 return icd->ctrl_handler.error;
1070 1070
@@ -2088,15 +2088,13 @@ static int sh_mobile_ceu_probe(struct platform_device *pdev)
2088 irq = platform_get_irq(pdev, 0); 2088 irq = platform_get_irq(pdev, 0);
2089 if (!res || (int)irq <= 0) { 2089 if (!res || (int)irq <= 0) {
2090 dev_err(&pdev->dev, "Not enough CEU platform resources.\n"); 2090 dev_err(&pdev->dev, "Not enough CEU platform resources.\n");
2091 err = -ENODEV; 2091 return -ENODEV;
2092 goto exit;
2093 } 2092 }
2094 2093
2095 pcdev = kzalloc(sizeof(*pcdev), GFP_KERNEL); 2094 pcdev = devm_kzalloc(&pdev->dev, sizeof(*pcdev), GFP_KERNEL);
2096 if (!pcdev) { 2095 if (!pcdev) {
2097 dev_err(&pdev->dev, "Could not allocate pcdev\n"); 2096 dev_err(&pdev->dev, "Could not allocate pcdev\n");
2098 err = -ENOMEM; 2097 return -ENOMEM;
2099 goto exit;
2100 } 2098 }
2101 2099
2102 INIT_LIST_HEAD(&pcdev->capture); 2100 INIT_LIST_HEAD(&pcdev->capture);
@@ -2105,19 +2103,17 @@ static int sh_mobile_ceu_probe(struct platform_device *pdev)
2105 2103
2106 pcdev->pdata = pdev->dev.platform_data; 2104 pcdev->pdata = pdev->dev.platform_data;
2107 if (!pcdev->pdata) { 2105 if (!pcdev->pdata) {
2108 err = -EINVAL;
2109 dev_err(&pdev->dev, "CEU platform data not set.\n"); 2106 dev_err(&pdev->dev, "CEU platform data not set.\n");
2110 goto exit_kfree; 2107 return -EINVAL;
2111 } 2108 }
2112 2109
2113 pcdev->max_width = pcdev->pdata->max_width ? : 2560; 2110 pcdev->max_width = pcdev->pdata->max_width ? : 2560;
2114 pcdev->max_height = pcdev->pdata->max_height ? : 1920; 2111 pcdev->max_height = pcdev->pdata->max_height ? : 1920;
2115 2112
2116 base = ioremap_nocache(res->start, resource_size(res)); 2113 base = devm_request_and_ioremap(&pdev->dev, res);
2117 if (!base) { 2114 if (!base) {
2118 err = -ENXIO;
2119 dev_err(&pdev->dev, "Unable to ioremap CEU registers.\n"); 2115 dev_err(&pdev->dev, "Unable to ioremap CEU registers.\n");
2120 goto exit_kfree; 2116 return -ENXIO;
2121 } 2117 }
2122 2118
2123 pcdev->irq = irq; 2119 pcdev->irq = irq;
@@ -2133,16 +2129,15 @@ static int sh_mobile_ceu_probe(struct platform_device *pdev)
2133 DMA_MEMORY_EXCLUSIVE); 2129 DMA_MEMORY_EXCLUSIVE);
2134 if (!err) { 2130 if (!err) {
2135 dev_err(&pdev->dev, "Unable to declare CEU memory.\n"); 2131 dev_err(&pdev->dev, "Unable to declare CEU memory.\n");
2136 err = -ENXIO; 2132 return -ENXIO;
2137 goto exit_iounmap;
2138 } 2133 }
2139 2134
2140 pcdev->video_limit = resource_size(res); 2135 pcdev->video_limit = resource_size(res);
2141 } 2136 }
2142 2137
2143 /* request irq */ 2138 /* request irq */
2144 err = request_irq(pcdev->irq, sh_mobile_ceu_irq, IRQF_DISABLED, 2139 err = devm_request_irq(&pdev->dev, pcdev->irq, sh_mobile_ceu_irq,
2145 dev_name(&pdev->dev), pcdev); 2140 IRQF_DISABLED, dev_name(&pdev->dev), pcdev);
2146 if (err) { 2141 if (err) {
2147 dev_err(&pdev->dev, "Unable to register CEU interrupt.\n"); 2142 dev_err(&pdev->dev, "Unable to register CEU interrupt.\n");
2148 goto exit_release_mem; 2143 goto exit_release_mem;
@@ -2246,15 +2241,9 @@ exit_free_ctx:
2246 vb2_dma_contig_cleanup_ctx(pcdev->alloc_ctx); 2241 vb2_dma_contig_cleanup_ctx(pcdev->alloc_ctx);
2247exit_free_clk: 2242exit_free_clk:
2248 pm_runtime_disable(&pdev->dev); 2243 pm_runtime_disable(&pdev->dev);
2249 free_irq(pcdev->irq, pcdev);
2250exit_release_mem: 2244exit_release_mem:
2251 if (platform_get_resource(pdev, IORESOURCE_MEM, 1)) 2245 if (platform_get_resource(pdev, IORESOURCE_MEM, 1))
2252 dma_release_declared_memory(&pdev->dev); 2246 dma_release_declared_memory(&pdev->dev);
2253exit_iounmap:
2254 iounmap(base);
2255exit_kfree:
2256 kfree(pcdev);
2257exit:
2258 return err; 2247 return err;
2259} 2248}
2260 2249
@@ -2267,10 +2256,8 @@ static int sh_mobile_ceu_remove(struct platform_device *pdev)
2267 2256
2268 soc_camera_host_unregister(soc_host); 2257 soc_camera_host_unregister(soc_host);
2269 pm_runtime_disable(&pdev->dev); 2258 pm_runtime_disable(&pdev->dev);
2270 free_irq(pcdev->irq, pcdev);
2271 if (platform_get_resource(pdev, IORESOURCE_MEM, 1)) 2259 if (platform_get_resource(pdev, IORESOURCE_MEM, 1))
2272 dma_release_declared_memory(&pdev->dev); 2260 dma_release_declared_memory(&pdev->dev);
2273 iounmap(pcdev->base);
2274 vb2_dma_contig_cleanup_ctx(pcdev->alloc_ctx); 2261 vb2_dma_contig_cleanup_ctx(pcdev->alloc_ctx);
2275 if (csi2_pdev && csi2_pdev->dev.driver) { 2262 if (csi2_pdev && csi2_pdev->dev.driver) {
2276 struct module *csi2_drv = csi2_pdev->dev.driver->owner; 2263 struct module *csi2_drv = csi2_pdev->dev.driver->owner;
@@ -2279,7 +2266,6 @@ static int sh_mobile_ceu_remove(struct platform_device *pdev)
2279 platform_device_put(csi2_pdev); 2266 platform_device_put(csi2_pdev);
2280 module_put(csi2_drv); 2267 module_put(csi2_drv);
2281 } 2268 }
2282 kfree(pcdev);
2283 2269
2284 return 0; 2270 return 0;
2285} 2271}
diff --git a/drivers/media/platform/soc_camera/sh_mobile_csi2.c b/drivers/media/platform/soc_camera/sh_mobile_csi2.c
index a17aba9a0104..42c559eb4937 100644
--- a/drivers/media/platform/soc_camera/sh_mobile_csi2.c
+++ b/drivers/media/platform/soc_camera/sh_mobile_csi2.c
@@ -318,23 +318,16 @@ static int sh_csi2_probe(struct platform_device *pdev)
318 return -EINVAL; 318 return -EINVAL;
319 } 319 }
320 320
321 priv = kzalloc(sizeof(struct sh_csi2), GFP_KERNEL); 321 priv = devm_kzalloc(&pdev->dev, sizeof(struct sh_csi2), GFP_KERNEL);
322 if (!priv) 322 if (!priv)
323 return -ENOMEM; 323 return -ENOMEM;
324 324
325 priv->irq = irq; 325 priv->irq = irq;
326 326
327 if (!request_mem_region(res->start, resource_size(res), pdev->name)) { 327 priv->base = devm_request_and_ioremap(&pdev->dev, res);
328 dev_err(&pdev->dev, "CSI2 register region already claimed\n");
329 ret = -EBUSY;
330 goto ereqreg;
331 }
332
333 priv->base = ioremap(res->start, resource_size(res));
334 if (!priv->base) { 328 if (!priv->base) {
335 ret = -ENXIO;
336 dev_err(&pdev->dev, "Unable to ioremap CSI2 registers.\n"); 329 dev_err(&pdev->dev, "Unable to ioremap CSI2 registers.\n");
337 goto eremap; 330 return -ENXIO;
338 } 331 }
339 332
340 priv->pdev = pdev; 333 priv->pdev = pdev;
@@ -357,11 +350,7 @@ static int sh_csi2_probe(struct platform_device *pdev)
357 return 0; 350 return 0;
358 351
359esdreg: 352esdreg:
360 iounmap(priv->base); 353 platform_set_drvdata(pdev, NULL);
361eremap:
362 release_mem_region(res->start, resource_size(res));
363ereqreg:
364 kfree(priv);
365 354
366 return ret; 355 return ret;
367} 356}
@@ -369,14 +358,10 @@ ereqreg:
369static int sh_csi2_remove(struct platform_device *pdev) 358static int sh_csi2_remove(struct platform_device *pdev)
370{ 359{
371 struct sh_csi2 *priv = platform_get_drvdata(pdev); 360 struct sh_csi2 *priv = platform_get_drvdata(pdev);
372 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
373 361
374 v4l2_device_unregister_subdev(&priv->subdev); 362 v4l2_device_unregister_subdev(&priv->subdev);
375 pm_runtime_disable(&pdev->dev); 363 pm_runtime_disable(&pdev->dev);
376 iounmap(priv->base);
377 release_mem_region(res->start, resource_size(res));
378 platform_set_drvdata(pdev, NULL); 364 platform_set_drvdata(pdev, NULL);
379 kfree(priv);
380 365
381 return 0; 366 return 0;
382} 367}
diff --git a/drivers/media/platform/soc_camera/soc_camera.c b/drivers/media/platform/soc_camera/soc_camera.c
index 2ec90eae6ba0..8ec98051ea73 100644
--- a/drivers/media/platform/soc_camera/soc_camera.c
+++ b/drivers/media/platform/soc_camera/soc_camera.c
@@ -50,22 +50,22 @@ static LIST_HEAD(hosts);
50static LIST_HEAD(devices); 50static LIST_HEAD(devices);
51static DEFINE_MUTEX(list_lock); /* Protects the list of hosts */ 51static DEFINE_MUTEX(list_lock); /* Protects the list of hosts */
52 52
53int soc_camera_power_on(struct device *dev, struct soc_camera_link *icl) 53int soc_camera_power_on(struct device *dev, struct soc_camera_subdev_desc *ssdd)
54{ 54{
55 int ret = regulator_bulk_enable(icl->num_regulators, 55 int ret = regulator_bulk_enable(ssdd->num_regulators,
56 icl->regulators); 56 ssdd->regulators);
57 if (ret < 0) { 57 if (ret < 0) {
58 dev_err(dev, "Cannot enable regulators\n"); 58 dev_err(dev, "Cannot enable regulators\n");
59 return ret; 59 return ret;
60 } 60 }
61 61
62 if (icl->power) { 62 if (ssdd->power) {
63 ret = icl->power(dev, 1); 63 ret = ssdd->power(dev, 1);
64 if (ret < 0) { 64 if (ret < 0) {
65 dev_err(dev, 65 dev_err(dev,
66 "Platform failed to power-on the camera.\n"); 66 "Platform failed to power-on the camera.\n");
67 regulator_bulk_disable(icl->num_regulators, 67 regulator_bulk_disable(ssdd->num_regulators,
68 icl->regulators); 68 ssdd->regulators);
69 } 69 }
70 } 70 }
71 71
@@ -73,13 +73,13 @@ int soc_camera_power_on(struct device *dev, struct soc_camera_link *icl)
73} 73}
74EXPORT_SYMBOL(soc_camera_power_on); 74EXPORT_SYMBOL(soc_camera_power_on);
75 75
76int soc_camera_power_off(struct device *dev, struct soc_camera_link *icl) 76int soc_camera_power_off(struct device *dev, struct soc_camera_subdev_desc *ssdd)
77{ 77{
78 int ret = 0; 78 int ret = 0;
79 int err; 79 int err;
80 80
81 if (icl->power) { 81 if (ssdd->power) {
82 err = icl->power(dev, 0); 82 err = ssdd->power(dev, 0);
83 if (err < 0) { 83 if (err < 0) {
84 dev_err(dev, 84 dev_err(dev,
85 "Platform failed to power-off the camera.\n"); 85 "Platform failed to power-off the camera.\n");
@@ -87,8 +87,8 @@ int soc_camera_power_off(struct device *dev, struct soc_camera_link *icl)
87 } 87 }
88 } 88 }
89 89
90 err = regulator_bulk_disable(icl->num_regulators, 90 err = regulator_bulk_disable(ssdd->num_regulators,
91 icl->regulators); 91 ssdd->regulators);
92 if (err < 0) { 92 if (err < 0) {
93 dev_err(dev, "Cannot disable regulators\n"); 93 dev_err(dev, "Cannot disable regulators\n");
94 ret = ret ? : err; 94 ret = ret ? : err;
@@ -136,29 +136,29 @@ EXPORT_SYMBOL(soc_camera_xlate_by_fourcc);
136 136
137/** 137/**
138 * soc_camera_apply_board_flags() - apply platform SOCAM_SENSOR_INVERT_* flags 138 * soc_camera_apply_board_flags() - apply platform SOCAM_SENSOR_INVERT_* flags
139 * @icl: camera platform parameters 139 * @ssdd: camera platform parameters
140 * @cfg: media bus configuration 140 * @cfg: media bus configuration
141 * @return: resulting flags 141 * @return: resulting flags
142 */ 142 */
143unsigned long soc_camera_apply_board_flags(struct soc_camera_link *icl, 143unsigned long soc_camera_apply_board_flags(struct soc_camera_subdev_desc *ssdd,
144 const struct v4l2_mbus_config *cfg) 144 const struct v4l2_mbus_config *cfg)
145{ 145{
146 unsigned long f, flags = cfg->flags; 146 unsigned long f, flags = cfg->flags;
147 147
148 /* If only one of the two polarities is supported, switch to the opposite */ 148 /* If only one of the two polarities is supported, switch to the opposite */
149 if (icl->flags & SOCAM_SENSOR_INVERT_HSYNC) { 149 if (ssdd->flags & SOCAM_SENSOR_INVERT_HSYNC) {
150 f = flags & (V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_LOW); 150 f = flags & (V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_LOW);
151 if (f == V4L2_MBUS_HSYNC_ACTIVE_HIGH || f == V4L2_MBUS_HSYNC_ACTIVE_LOW) 151 if (f == V4L2_MBUS_HSYNC_ACTIVE_HIGH || f == V4L2_MBUS_HSYNC_ACTIVE_LOW)
152 flags ^= V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_LOW; 152 flags ^= V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_LOW;
153 } 153 }
154 154
155 if (icl->flags & SOCAM_SENSOR_INVERT_VSYNC) { 155 if (ssdd->flags & SOCAM_SENSOR_INVERT_VSYNC) {
156 f = flags & (V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_LOW); 156 f = flags & (V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_LOW);
157 if (f == V4L2_MBUS_VSYNC_ACTIVE_HIGH || f == V4L2_MBUS_VSYNC_ACTIVE_LOW) 157 if (f == V4L2_MBUS_VSYNC_ACTIVE_HIGH || f == V4L2_MBUS_VSYNC_ACTIVE_LOW)
158 flags ^= V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_LOW; 158 flags ^= V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_LOW;
159 } 159 }
160 160
161 if (icl->flags & SOCAM_SENSOR_INVERT_PCLK) { 161 if (ssdd->flags & SOCAM_SENSOR_INVERT_PCLK) {
162 f = flags & (V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING); 162 f = flags & (V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING);
163 if (f == V4L2_MBUS_PCLK_SAMPLE_RISING || f == V4L2_MBUS_PCLK_SAMPLE_FALLING) 163 if (f == V4L2_MBUS_PCLK_SAMPLE_RISING || f == V4L2_MBUS_PCLK_SAMPLE_FALLING)
164 flags ^= V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING; 164 flags ^= V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING;
@@ -383,7 +383,7 @@ static int soc_camera_prepare_buf(struct file *file, void *priv,
383 return vb2_prepare_buf(&icd->vb2_vidq, b); 383 return vb2_prepare_buf(&icd->vb2_vidq, b);
384} 384}
385 385
386/* Always entered with .video_lock held */ 386/* Always entered with .host_lock held */
387static int soc_camera_init_user_formats(struct soc_camera_device *icd) 387static int soc_camera_init_user_formats(struct soc_camera_device *icd)
388{ 388{
389 struct v4l2_subdev *sd = soc_camera_to_subdev(icd); 389 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
@@ -450,7 +450,7 @@ egfmt:
450 return ret; 450 return ret;
451} 451}
452 452
453/* Always entered with .video_lock held */ 453/* Always entered with .host_lock held */
454static void soc_camera_free_user_formats(struct soc_camera_device *icd) 454static void soc_camera_free_user_formats(struct soc_camera_device *icd)
455{ 455{
456 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 456 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
@@ -509,7 +509,7 @@ static int soc_camera_open(struct file *file)
509{ 509{
510 struct video_device *vdev = video_devdata(file); 510 struct video_device *vdev = video_devdata(file);
511 struct soc_camera_device *icd = dev_get_drvdata(vdev->parent); 511 struct soc_camera_device *icd = dev_get_drvdata(vdev->parent);
512 struct soc_camera_link *icl = to_soc_camera_link(icd); 512 struct soc_camera_desc *sdesc = to_soc_camera_desc(icd);
513 struct soc_camera_host *ici; 513 struct soc_camera_host *ici;
514 int ret; 514 int ret;
515 515
@@ -517,9 +517,16 @@ static int soc_camera_open(struct file *file)
517 /* No device driver attached */ 517 /* No device driver attached */
518 return -ENODEV; 518 return -ENODEV;
519 519
520 /*
521 * Don't mess with the host during probe: wait until the loop in
522 * scan_add_host() completes
523 */
524 if (mutex_lock_interruptible(&list_lock))
525 return -ERESTARTSYS;
520 ici = to_soc_camera_host(icd->parent); 526 ici = to_soc_camera_host(icd->parent);
527 mutex_unlock(&list_lock);
521 528
522 if (mutex_lock_interruptible(&icd->video_lock)) 529 if (mutex_lock_interruptible(&ici->host_lock))
523 return -ERESTARTSYS; 530 return -ERESTARTSYS;
524 if (!try_module_get(ici->ops->owner)) { 531 if (!try_module_get(ici->ops->owner)) {
525 dev_err(icd->pdev, "Couldn't lock capture bus driver.\n"); 532 dev_err(icd->pdev, "Couldn't lock capture bus driver.\n");
@@ -545,13 +552,10 @@ static int soc_camera_open(struct file *file)
545 }; 552 };
546 553
547 /* The camera could have been already on, try to reset */ 554 /* The camera could have been already on, try to reset */
548 if (icl->reset) 555 if (sdesc->subdev_desc.reset)
549 icl->reset(icd->pdev); 556 sdesc->subdev_desc.reset(icd->pdev);
550 557
551 /* Don't mess with the host during probe */
552 mutex_lock(&ici->host_lock);
553 ret = ici->ops->add(icd); 558 ret = ici->ops->add(icd);
554 mutex_unlock(&ici->host_lock);
555 if (ret < 0) { 559 if (ret < 0) {
556 dev_err(icd->pdev, "Couldn't activate the camera: %d\n", ret); 560 dev_err(icd->pdev, "Couldn't activate the camera: %d\n", ret);
557 goto eiciadd; 561 goto eiciadd;
@@ -570,7 +574,7 @@ static int soc_camera_open(struct file *file)
570 * Try to configure with default parameters. Notice: this is the 574 * Try to configure with default parameters. Notice: this is the
571 * very first open, so, we cannot race against other calls, 575 * very first open, so, we cannot race against other calls,
572 * apart from someone else calling open() simultaneously, but 576 * apart from someone else calling open() simultaneously, but
573 * .video_lock is protecting us against it. 577 * .host_lock is protecting us against it.
574 */ 578 */
575 ret = soc_camera_set_fmt(icd, &f); 579 ret = soc_camera_set_fmt(icd, &f);
576 if (ret < 0) 580 if (ret < 0)
@@ -585,7 +589,7 @@ static int soc_camera_open(struct file *file)
585 } 589 }
586 v4l2_ctrl_handler_setup(&icd->ctrl_handler); 590 v4l2_ctrl_handler_setup(&icd->ctrl_handler);
587 } 591 }
588 mutex_unlock(&icd->video_lock); 592 mutex_unlock(&ici->host_lock);
589 593
590 file->private_data = icd; 594 file->private_data = icd;
591 dev_dbg(icd->pdev, "camera device open\n"); 595 dev_dbg(icd->pdev, "camera device open\n");
@@ -593,7 +597,7 @@ static int soc_camera_open(struct file *file)
593 return 0; 597 return 0;
594 598
595 /* 599 /*
596 * First four errors are entered with the .video_lock held 600 * First four errors are entered with the .host_lock held
597 * and use_count == 1 601 * and use_count == 1
598 */ 602 */
599einitvb: 603einitvb:
@@ -607,7 +611,7 @@ eiciadd:
607 icd->use_count--; 611 icd->use_count--;
608 module_put(ici->ops->owner); 612 module_put(ici->ops->owner);
609emodule: 613emodule:
610 mutex_unlock(&icd->video_lock); 614 mutex_unlock(&ici->host_lock);
611 615
612 return ret; 616 return ret;
613} 617}
@@ -617,7 +621,7 @@ static int soc_camera_close(struct file *file)
617 struct soc_camera_device *icd = file->private_data; 621 struct soc_camera_device *icd = file->private_data;
618 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 622 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
619 623
620 mutex_lock(&icd->video_lock); 624 mutex_lock(&ici->host_lock);
621 icd->use_count--; 625 icd->use_count--;
622 if (!icd->use_count) { 626 if (!icd->use_count) {
623 pm_runtime_suspend(&icd->vdev->dev); 627 pm_runtime_suspend(&icd->vdev->dev);
@@ -632,7 +636,7 @@ static int soc_camera_close(struct file *file)
632 636
633 if (icd->streamer == file) 637 if (icd->streamer == file)
634 icd->streamer = NULL; 638 icd->streamer = NULL;
635 mutex_unlock(&icd->video_lock); 639 mutex_unlock(&ici->host_lock);
636 640
637 module_put(ici->ops->owner); 641 module_put(ici->ops->owner);
638 642
@@ -669,13 +673,13 @@ static int soc_camera_mmap(struct file *file, struct vm_area_struct *vma)
669 if (icd->streamer != file) 673 if (icd->streamer != file)
670 return -EBUSY; 674 return -EBUSY;
671 675
672 if (mutex_lock_interruptible(&icd->video_lock)) 676 if (mutex_lock_interruptible(&ici->host_lock))
673 return -ERESTARTSYS; 677 return -ERESTARTSYS;
674 if (ici->ops->init_videobuf) 678 if (ici->ops->init_videobuf)
675 err = videobuf_mmap_mapper(&icd->vb_vidq, vma); 679 err = videobuf_mmap_mapper(&icd->vb_vidq, vma);
676 else 680 else
677 err = vb2_mmap(&icd->vb2_vidq, vma); 681 err = vb2_mmap(&icd->vb2_vidq, vma);
678 mutex_unlock(&icd->video_lock); 682 mutex_unlock(&ici->host_lock);
679 683
680 dev_dbg(icd->pdev, "vma start=0x%08lx, size=%ld, ret=%d\n", 684 dev_dbg(icd->pdev, "vma start=0x%08lx, size=%ld, ret=%d\n",
681 (unsigned long)vma->vm_start, 685 (unsigned long)vma->vm_start,
@@ -694,26 +698,28 @@ static unsigned int soc_camera_poll(struct file *file, poll_table *pt)
694 if (icd->streamer != file) 698 if (icd->streamer != file)
695 return POLLERR; 699 return POLLERR;
696 700
697 mutex_lock(&icd->video_lock); 701 mutex_lock(&ici->host_lock);
698 if (ici->ops->init_videobuf && list_empty(&icd->vb_vidq.stream)) 702 if (ici->ops->init_videobuf && list_empty(&icd->vb_vidq.stream))
699 dev_err(icd->pdev, "Trying to poll with no queued buffers!\n"); 703 dev_err(icd->pdev, "Trying to poll with no queued buffers!\n");
700 else 704 else
701 res = ici->ops->poll(file, pt); 705 res = ici->ops->poll(file, pt);
702 mutex_unlock(&icd->video_lock); 706 mutex_unlock(&ici->host_lock);
703 return res; 707 return res;
704} 708}
705 709
706void soc_camera_lock(struct vb2_queue *vq) 710void soc_camera_lock(struct vb2_queue *vq)
707{ 711{
708 struct soc_camera_device *icd = vb2_get_drv_priv(vq); 712 struct soc_camera_device *icd = vb2_get_drv_priv(vq);
709 mutex_lock(&icd->video_lock); 713 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
714 mutex_lock(&ici->host_lock);
710} 715}
711EXPORT_SYMBOL(soc_camera_lock); 716EXPORT_SYMBOL(soc_camera_lock);
712 717
713void soc_camera_unlock(struct vb2_queue *vq) 718void soc_camera_unlock(struct vb2_queue *vq)
714{ 719{
715 struct soc_camera_device *icd = vb2_get_drv_priv(vq); 720 struct soc_camera_device *icd = vb2_get_drv_priv(vq);
716 mutex_unlock(&icd->video_lock); 721 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
722 mutex_unlock(&ici->host_lock);
717} 723}
718EXPORT_SYMBOL(soc_camera_unlock); 724EXPORT_SYMBOL(soc_camera_unlock);
719 725
@@ -908,6 +914,8 @@ static int soc_camera_s_crop(struct file *file, void *fh,
908 dev_dbg(icd->pdev, "S_CROP(%ux%u@%u:%u)\n", 914 dev_dbg(icd->pdev, "S_CROP(%ux%u@%u:%u)\n",
909 rect->width, rect->height, rect->left, rect->top); 915 rect->width, rect->height, rect->left, rect->top);
910 916
917 current_crop.type = a->type;
918
911 /* If get_crop fails, we'll let host and / or client drivers decide */ 919 /* If get_crop fails, we'll let host and / or client drivers decide */
912 ret = ici->ops->get_crop(icd, &current_crop); 920 ret = ici->ops->get_crop(icd, &current_crop);
913 921
@@ -1050,7 +1058,7 @@ static void scan_add_host(struct soc_camera_host *ici)
1050{ 1058{
1051 struct soc_camera_device *icd; 1059 struct soc_camera_device *icd;
1052 1060
1053 mutex_lock(&ici->host_lock); 1061 mutex_lock(&list_lock);
1054 1062
1055 list_for_each_entry(icd, &devices, list) { 1063 list_for_each_entry(icd, &devices, list) {
1056 if (icd->iface == ici->nr) { 1064 if (icd->iface == ici->nr) {
@@ -1059,28 +1067,29 @@ static void scan_add_host(struct soc_camera_host *ici)
1059 } 1067 }
1060 } 1068 }
1061 1069
1062 mutex_unlock(&ici->host_lock); 1070 mutex_unlock(&list_lock);
1063} 1071}
1064 1072
1065#ifdef CONFIG_I2C_BOARDINFO 1073#ifdef CONFIG_I2C_BOARDINFO
1066static int soc_camera_init_i2c(struct soc_camera_device *icd, 1074static int soc_camera_init_i2c(struct soc_camera_device *icd,
1067 struct soc_camera_link *icl) 1075 struct soc_camera_desc *sdesc)
1068{ 1076{
1069 struct i2c_client *client; 1077 struct i2c_client *client;
1070 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 1078 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
1071 struct i2c_adapter *adap = i2c_get_adapter(icl->i2c_adapter_id); 1079 struct soc_camera_host_desc *shd = &sdesc->host_desc;
1080 struct i2c_adapter *adap = i2c_get_adapter(shd->i2c_adapter_id);
1072 struct v4l2_subdev *subdev; 1081 struct v4l2_subdev *subdev;
1073 1082
1074 if (!adap) { 1083 if (!adap) {
1075 dev_err(icd->pdev, "Cannot get I2C adapter #%d. No driver?\n", 1084 dev_err(icd->pdev, "Cannot get I2C adapter #%d. No driver?\n",
1076 icl->i2c_adapter_id); 1085 shd->i2c_adapter_id);
1077 goto ei2cga; 1086 goto ei2cga;
1078 } 1087 }
1079 1088
1080 icl->board_info->platform_data = icl; 1089 shd->board_info->platform_data = &sdesc->subdev_desc;
1081 1090
1082 subdev = v4l2_i2c_new_subdev_board(&ici->v4l2_dev, adap, 1091 subdev = v4l2_i2c_new_subdev_board(&ici->v4l2_dev, adap,
1083 icl->board_info, NULL); 1092 shd->board_info, NULL);
1084 if (!subdev) 1093 if (!subdev)
1085 goto ei2cnd; 1094 goto ei2cnd;
1086 1095
@@ -1108,7 +1117,7 @@ static void soc_camera_free_i2c(struct soc_camera_device *icd)
1108 i2c_put_adapter(adap); 1117 i2c_put_adapter(adap);
1109} 1118}
1110#else 1119#else
1111#define soc_camera_init_i2c(icd, icl) (-ENODEV) 1120#define soc_camera_init_i2c(icd, sdesc) (-ENODEV)
1112#define soc_camera_free_i2c(icd) do {} while (0) 1121#define soc_camera_free_i2c(icd) do {} while (0)
1113#endif 1122#endif
1114 1123
@@ -1118,7 +1127,9 @@ static int video_dev_create(struct soc_camera_device *icd);
1118static int soc_camera_probe(struct soc_camera_device *icd) 1127static int soc_camera_probe(struct soc_camera_device *icd)
1119{ 1128{
1120 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 1129 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
1121 struct soc_camera_link *icl = to_soc_camera_link(icd); 1130 struct soc_camera_desc *sdesc = to_soc_camera_desc(icd);
1131 struct soc_camera_host_desc *shd = &sdesc->host_desc;
1132 struct soc_camera_subdev_desc *ssdd = &sdesc->subdev_desc;
1122 struct device *control = NULL; 1133 struct device *control = NULL;
1123 struct v4l2_subdev *sd; 1134 struct v4l2_subdev *sd;
1124 struct v4l2_mbus_framefmt mf; 1135 struct v4l2_mbus_framefmt mf;
@@ -1137,16 +1148,13 @@ static int soc_camera_probe(struct soc_camera_device *icd)
1137 if (ret < 0) 1148 if (ret < 0)
1138 return ret; 1149 return ret;
1139 1150
1140 ret = regulator_bulk_get(icd->pdev, icl->num_regulators,
1141 icl->regulators);
1142 if (ret < 0)
1143 goto ereg;
1144
1145 /* The camera could have been already on, try to reset */ 1151 /* The camera could have been already on, try to reset */
1146 if (icl->reset) 1152 if (ssdd->reset)
1147 icl->reset(icd->pdev); 1153 ssdd->reset(icd->pdev);
1148 1154
1155 mutex_lock(&ici->host_lock);
1149 ret = ici->ops->add(icd); 1156 ret = ici->ops->add(icd);
1157 mutex_unlock(&ici->host_lock);
1150 if (ret < 0) 1158 if (ret < 0)
1151 goto eadd; 1159 goto eadd;
1152 1160
@@ -1156,18 +1164,18 @@ static int soc_camera_probe(struct soc_camera_device *icd)
1156 goto evdc; 1164 goto evdc;
1157 1165
1158 /* Non-i2c cameras, e.g., soc_camera_platform, have no board_info */ 1166 /* Non-i2c cameras, e.g., soc_camera_platform, have no board_info */
1159 if (icl->board_info) { 1167 if (shd->board_info) {
1160 ret = soc_camera_init_i2c(icd, icl); 1168 ret = soc_camera_init_i2c(icd, sdesc);
1161 if (ret < 0) 1169 if (ret < 0)
1162 goto eadddev; 1170 goto eadddev;
1163 } else if (!icl->add_device || !icl->del_device) { 1171 } else if (!shd->add_device || !shd->del_device) {
1164 ret = -EINVAL; 1172 ret = -EINVAL;
1165 goto eadddev; 1173 goto eadddev;
1166 } else { 1174 } else {
1167 if (icl->module_name) 1175 if (shd->module_name)
1168 ret = request_module(icl->module_name); 1176 ret = request_module(shd->module_name);
1169 1177
1170 ret = icl->add_device(icd); 1178 ret = shd->add_device(icd);
1171 if (ret < 0) 1179 if (ret < 0)
1172 goto eadddev; 1180 goto eadddev;
1173 1181
@@ -1178,7 +1186,7 @@ static int soc_camera_probe(struct soc_camera_device *icd)
1178 control = to_soc_camera_control(icd); 1186 control = to_soc_camera_control(icd);
1179 if (!control || !control->driver || !dev_get_drvdata(control) || 1187 if (!control || !control->driver || !dev_get_drvdata(control) ||
1180 !try_module_get(control->driver->owner)) { 1188 !try_module_get(control->driver->owner)) {
1181 icl->del_device(icd); 1189 shd->del_device(icd);
1182 ret = -ENODEV; 1190 ret = -ENODEV;
1183 goto enodrv; 1191 goto enodrv;
1184 } 1192 }
@@ -1204,7 +1212,7 @@ static int soc_camera_probe(struct soc_camera_device *icd)
1204 * itself is protected against concurrent open() calls, but we also have 1212 * itself is protected against concurrent open() calls, but we also have
1205 * to protect our data. 1213 * to protect our data.
1206 */ 1214 */
1207 mutex_lock(&icd->video_lock); 1215 mutex_lock(&ici->host_lock);
1208 1216
1209 ret = soc_camera_video_start(icd); 1217 ret = soc_camera_video_start(icd);
1210 if (ret < 0) 1218 if (ret < 0)
@@ -1220,19 +1228,19 @@ static int soc_camera_probe(struct soc_camera_device *icd)
1220 1228
1221 ici->ops->remove(icd); 1229 ici->ops->remove(icd);
1222 1230
1223 mutex_unlock(&icd->video_lock); 1231 mutex_unlock(&ici->host_lock);
1224 1232
1225 return 0; 1233 return 0;
1226 1234
1227evidstart: 1235evidstart:
1228 mutex_unlock(&icd->video_lock); 1236 mutex_unlock(&ici->host_lock);
1229 soc_camera_free_user_formats(icd); 1237 soc_camera_free_user_formats(icd);
1230eiufmt: 1238eiufmt:
1231ectrl: 1239ectrl:
1232 if (icl->board_info) { 1240 if (shd->board_info) {
1233 soc_camera_free_i2c(icd); 1241 soc_camera_free_i2c(icd);
1234 } else { 1242 } else {
1235 icl->del_device(icd); 1243 shd->del_device(icd);
1236 module_put(control->driver->owner); 1244 module_put(control->driver->owner);
1237 } 1245 }
1238enodrv: 1246enodrv:
@@ -1240,10 +1248,10 @@ eadddev:
1240 video_device_release(icd->vdev); 1248 video_device_release(icd->vdev);
1241 icd->vdev = NULL; 1249 icd->vdev = NULL;
1242evdc: 1250evdc:
1251 mutex_lock(&ici->host_lock);
1243 ici->ops->remove(icd); 1252 ici->ops->remove(icd);
1253 mutex_unlock(&ici->host_lock);
1244eadd: 1254eadd:
1245 regulator_bulk_free(icl->num_regulators, icl->regulators);
1246ereg:
1247 v4l2_ctrl_handler_free(&icd->ctrl_handler); 1255 v4l2_ctrl_handler_free(&icd->ctrl_handler);
1248 return ret; 1256 return ret;
1249} 1257}
@@ -1254,7 +1262,7 @@ ereg:
1254 */ 1262 */
1255static int soc_camera_remove(struct soc_camera_device *icd) 1263static int soc_camera_remove(struct soc_camera_device *icd)
1256{ 1264{
1257 struct soc_camera_link *icl = to_soc_camera_link(icd); 1265 struct soc_camera_desc *sdesc = to_soc_camera_desc(icd);
1258 struct video_device *vdev = icd->vdev; 1266 struct video_device *vdev = icd->vdev;
1259 1267
1260 BUG_ON(!icd->parent); 1268 BUG_ON(!icd->parent);
@@ -1265,19 +1273,17 @@ static int soc_camera_remove(struct soc_camera_device *icd)
1265 icd->vdev = NULL; 1273 icd->vdev = NULL;
1266 } 1274 }
1267 1275
1268 if (icl->board_info) { 1276 if (sdesc->host_desc.board_info) {
1269 soc_camera_free_i2c(icd); 1277 soc_camera_free_i2c(icd);
1270 } else { 1278 } else {
1271 struct device_driver *drv = to_soc_camera_control(icd)->driver; 1279 struct device_driver *drv = to_soc_camera_control(icd)->driver;
1272 if (drv) { 1280 if (drv) {
1273 icl->del_device(icd); 1281 sdesc->host_desc.del_device(icd);
1274 module_put(drv->owner); 1282 module_put(drv->owner);
1275 } 1283 }
1276 } 1284 }
1277 soc_camera_free_user_formats(icd); 1285 soc_camera_free_user_formats(icd);
1278 1286
1279 regulator_bulk_free(icl->num_regulators, icl->regulators);
1280
1281 return 0; 1287 return 0;
1282} 1288}
1283 1289
@@ -1442,7 +1448,6 @@ static int soc_camera_device_register(struct soc_camera_device *icd)
1442 icd->devnum = num; 1448 icd->devnum = num;
1443 icd->use_count = 0; 1449 icd->use_count = 0;
1444 icd->host_priv = NULL; 1450 icd->host_priv = NULL;
1445 mutex_init(&icd->video_lock);
1446 1451
1447 list_add_tail(&icd->list, &devices); 1452 list_add_tail(&icd->list, &devices);
1448 1453
@@ -1500,7 +1505,7 @@ static int video_dev_create(struct soc_camera_device *icd)
1500 vdev->release = video_device_release; 1505 vdev->release = video_device_release;
1501 vdev->tvnorms = V4L2_STD_UNKNOWN; 1506 vdev->tvnorms = V4L2_STD_UNKNOWN;
1502 vdev->ctrl_handler = &icd->ctrl_handler; 1507 vdev->ctrl_handler = &icd->ctrl_handler;
1503 vdev->lock = &icd->video_lock; 1508 vdev->lock = &ici->host_lock;
1504 1509
1505 icd->vdev = vdev; 1510 icd->vdev = vdev;
1506 1511
@@ -1508,7 +1513,7 @@ static int video_dev_create(struct soc_camera_device *icd)
1508} 1513}
1509 1514
1510/* 1515/*
1511 * Called from soc_camera_probe() above (with .video_lock held???) 1516 * Called from soc_camera_probe() above with .host_lock held
1512 */ 1517 */
1513static int soc_camera_video_start(struct soc_camera_device *icd) 1518static int soc_camera_video_start(struct soc_camera_device *icd)
1514{ 1519{
@@ -1532,18 +1537,25 @@ static int soc_camera_video_start(struct soc_camera_device *icd)
1532 1537
1533static int soc_camera_pdrv_probe(struct platform_device *pdev) 1538static int soc_camera_pdrv_probe(struct platform_device *pdev)
1534{ 1539{
1535 struct soc_camera_link *icl = pdev->dev.platform_data; 1540 struct soc_camera_desc *sdesc = pdev->dev.platform_data;
1541 struct soc_camera_subdev_desc *ssdd = &sdesc->subdev_desc;
1536 struct soc_camera_device *icd; 1542 struct soc_camera_device *icd;
1543 int ret;
1537 1544
1538 if (!icl) 1545 if (!sdesc)
1539 return -EINVAL; 1546 return -EINVAL;
1540 1547
1541 icd = devm_kzalloc(&pdev->dev, sizeof(*icd), GFP_KERNEL); 1548 icd = devm_kzalloc(&pdev->dev, sizeof(*icd), GFP_KERNEL);
1542 if (!icd) 1549 if (!icd)
1543 return -ENOMEM; 1550 return -ENOMEM;
1544 1551
1545 icd->iface = icl->bus_id; 1552 ret = devm_regulator_bulk_get(&pdev->dev, ssdd->num_regulators,
1546 icd->link = icl; 1553 ssdd->regulators);
1554 if (ret < 0)
1555 return ret;
1556
1557 icd->iface = sdesc->host_desc.bus_id;
1558 icd->sdesc = sdesc;
1547 icd->pdev = &pdev->dev; 1559 icd->pdev = &pdev->dev;
1548 platform_set_drvdata(pdev, icd); 1560 platform_set_drvdata(pdev, icd);
1549 1561
diff --git a/drivers/media/platform/soc_camera/soc_camera_platform.c b/drivers/media/platform/soc_camera/soc_camera_platform.c
index 7cf7fd16481f..ce3b1d6a4734 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->link, on); 57 return soc_camera_set_power(p->icd->control, &p->icd->sdesc->subdev_desc, 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 = {
@@ -148,7 +148,7 @@ static int soc_camera_platform_probe(struct platform_device *pdev)
148 return -EINVAL; 148 return -EINVAL;
149 } 149 }
150 150
151 priv = kzalloc(sizeof(*priv), GFP_KERNEL); 151 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
152 if (!priv) 152 if (!priv)
153 return -ENOMEM; 153 return -ENOMEM;
154 154
@@ -173,7 +173,6 @@ static int soc_camera_platform_probe(struct platform_device *pdev)
173 173
174evdrs: 174evdrs:
175 platform_set_drvdata(pdev, NULL); 175 platform_set_drvdata(pdev, NULL);
176 kfree(priv);
177 return ret; 176 return ret;
178} 177}
179 178
@@ -185,7 +184,6 @@ static int soc_camera_platform_remove(struct platform_device *pdev)
185 p->icd->control = NULL; 184 p->icd->control = NULL;
186 v4l2_device_unregister_subdev(&priv->subdev); 185 v4l2_device_unregister_subdev(&priv->subdev);
187 platform_set_drvdata(pdev, NULL); 186 platform_set_drvdata(pdev, NULL);
188 kfree(priv);
189 return 0; 187 return 0;
190} 188}
191 189
diff --git a/drivers/media/platform/soc_camera/soc_mediabus.c b/drivers/media/platform/soc_camera/soc_mediabus.c
index a397812635d6..89dce097a827 100644
--- a/drivers/media/platform/soc_camera/soc_mediabus.c
+++ b/drivers/media/platform/soc_camera/soc_mediabus.c
@@ -378,9 +378,6 @@ EXPORT_SYMBOL(soc_mbus_samples_per_pixel);
378 378
379s32 soc_mbus_bytes_per_line(u32 width, const struct soc_mbus_pixelfmt *mf) 379s32 soc_mbus_bytes_per_line(u32 width, const struct soc_mbus_pixelfmt *mf)
380{ 380{
381 if (mf->fourcc == V4L2_PIX_FMT_JPEG)
382 return 0;
383
384 if (mf->layout != SOC_MBUS_LAYOUT_PACKED) 381 if (mf->layout != SOC_MBUS_LAYOUT_PACKED)
385 return width * mf->bits_per_sample / 8; 382 return width * mf->bits_per_sample / 8;
386 383
@@ -403,9 +400,6 @@ EXPORT_SYMBOL(soc_mbus_bytes_per_line);
403s32 soc_mbus_image_size(const struct soc_mbus_pixelfmt *mf, 400s32 soc_mbus_image_size(const struct soc_mbus_pixelfmt *mf,
404 u32 bytes_per_line, u32 height) 401 u32 bytes_per_line, u32 height)
405{ 402{
406 if (mf->fourcc == V4L2_PIX_FMT_JPEG)
407 return 0;
408
409 if (mf->layout == SOC_MBUS_LAYOUT_PACKED) 403 if (mf->layout == SOC_MBUS_LAYOUT_PACKED)
410 return bytes_per_line * height; 404 return bytes_per_line * height;
411 405
diff --git a/drivers/media/platform/timblogiw.c b/drivers/media/platform/timblogiw.c
index d854d08a6c7f..c3a2a4484401 100644
--- a/drivers/media/platform/timblogiw.c
+++ b/drivers/media/platform/timblogiw.c
@@ -130,7 +130,7 @@ static void timblogiw_dma_cb(void *data)
130 130
131 if (vb->state != VIDEOBUF_ERROR) { 131 if (vb->state != VIDEOBUF_ERROR) {
132 list_del(&vb->queue); 132 list_del(&vb->queue);
133 do_gettimeofday(&vb->ts); 133 v4l2_get_timestamp(&vb->ts);
134 vb->field_count = fh->frame_count * 2; 134 vb->field_count = fh->frame_count * 2;
135 vb->state = VIDEOBUF_DONE; 135 vb->state = VIDEOBUF_DONE;
136 136
diff --git a/drivers/media/platform/via-camera.c b/drivers/media/platform/via-camera.c
index 63e8c3461239..b051c4a28554 100644
--- a/drivers/media/platform/via-camera.c
+++ b/drivers/media/platform/via-camera.c
@@ -18,6 +18,7 @@
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> 20#include <media/v4l2-chip-ident.h>
21#include <media/v4l2-ctrls.h>
21#include <media/ov7670.h> 22#include <media/ov7670.h>
22#include <media/videobuf-dma-sg.h> 23#include <media/videobuf-dma-sg.h>
23#include <linux/delay.h> 24#include <linux/delay.h>
@@ -63,6 +64,7 @@ enum viacam_opstate { S_IDLE = 0, S_RUNNING = 1 };
63 64
64struct via_camera { 65struct via_camera {
65 struct v4l2_device v4l2_dev; 66 struct v4l2_device v4l2_dev;
67 struct v4l2_ctrl_handler ctrl_handler;
66 struct video_device vdev; 68 struct video_device vdev;
67 struct v4l2_subdev *sensor; 69 struct v4l2_subdev *sensor;
68 struct platform_device *platdev; 70 struct platform_device *platdev;
@@ -818,47 +820,6 @@ static int viacam_g_chip_ident(struct file *file, void *priv,
818} 820}
819 821
820/* 822/*
821 * Control ops are passed through to the sensor.
822 */
823static int viacam_queryctrl(struct file *filp, void *priv,
824 struct v4l2_queryctrl *qc)
825{
826 struct via_camera *cam = priv;
827 int ret;
828
829 mutex_lock(&cam->lock);
830 ret = sensor_call(cam, core, queryctrl, qc);
831 mutex_unlock(&cam->lock);
832 return ret;
833}
834
835
836static int viacam_g_ctrl(struct file *filp, void *priv,
837 struct v4l2_control *ctrl)
838{
839 struct via_camera *cam = priv;
840 int ret;
841
842 mutex_lock(&cam->lock);
843 ret = sensor_call(cam, core, g_ctrl, ctrl);
844 mutex_unlock(&cam->lock);
845 return ret;
846}
847
848
849static int viacam_s_ctrl(struct file *filp, void *priv,
850 struct v4l2_control *ctrl)
851{
852 struct via_camera *cam = priv;
853 int ret;
854
855 mutex_lock(&cam->lock);
856 ret = sensor_call(cam, core, s_ctrl, ctrl);
857 mutex_unlock(&cam->lock);
858 return ret;
859}
860
861/*
862 * Only one input. 823 * Only one input.
863 */ 824 */
864static int viacam_enum_input(struct file *filp, void *priv, 825static int viacam_enum_input(struct file *filp, void *priv,
@@ -1214,9 +1175,6 @@ static int viacam_enum_frameintervals(struct file *filp, void *priv,
1214 1175
1215static const struct v4l2_ioctl_ops viacam_ioctl_ops = { 1176static const struct v4l2_ioctl_ops viacam_ioctl_ops = {
1216 .vidioc_g_chip_ident = viacam_g_chip_ident, 1177 .vidioc_g_chip_ident = viacam_g_chip_ident,
1217 .vidioc_queryctrl = viacam_queryctrl,
1218 .vidioc_g_ctrl = viacam_g_ctrl,
1219 .vidioc_s_ctrl = viacam_s_ctrl,
1220 .vidioc_enum_input = viacam_enum_input, 1178 .vidioc_enum_input = viacam_enum_input,
1221 .vidioc_g_input = viacam_g_input, 1179 .vidioc_g_input = viacam_g_input,
1222 .vidioc_s_input = viacam_s_input, 1180 .vidioc_s_input = viacam_s_input,
@@ -1418,8 +1376,12 @@ static int viacam_probe(struct platform_device *pdev)
1418 ret = v4l2_device_register(&pdev->dev, &cam->v4l2_dev); 1376 ret = v4l2_device_register(&pdev->dev, &cam->v4l2_dev);
1419 if (ret) { 1377 if (ret) {
1420 dev_err(&pdev->dev, "Unable to register v4l2 device\n"); 1378 dev_err(&pdev->dev, "Unable to register v4l2 device\n");
1421 return ret; 1379 goto out_free;
1422 } 1380 }
1381 ret = v4l2_ctrl_handler_init(&cam->ctrl_handler, 10);
1382 if (ret)
1383 goto out_unregister;
1384 cam->v4l2_dev.ctrl_handler = &cam->ctrl_handler;
1423 /* 1385 /*
1424 * Convince the system that we can do DMA. 1386 * Convince the system that we can do DMA.
1425 */ 1387 */
@@ -1436,7 +1398,7 @@ static int viacam_probe(struct platform_device *pdev)
1436 */ 1398 */
1437 ret = via_sensor_power_setup(cam); 1399 ret = via_sensor_power_setup(cam);
1438 if (ret) 1400 if (ret)
1439 goto out_unregister; 1401 goto out_ctrl_hdl_free;
1440 via_sensor_power_up(cam); 1402 via_sensor_power_up(cam);
1441 1403
1442 /* 1404 /*
@@ -1485,8 +1447,12 @@ out_irq:
1485 free_irq(viadev->pdev->irq, cam); 1447 free_irq(viadev->pdev->irq, cam);
1486out_power_down: 1448out_power_down:
1487 via_sensor_power_release(cam); 1449 via_sensor_power_release(cam);
1450out_ctrl_hdl_free:
1451 v4l2_ctrl_handler_free(&cam->ctrl_handler);
1488out_unregister: 1452out_unregister:
1489 v4l2_device_unregister(&cam->v4l2_dev); 1453 v4l2_device_unregister(&cam->v4l2_dev);
1454out_free:
1455 kfree(cam);
1490 return ret; 1456 return ret;
1491} 1457}
1492 1458
@@ -1499,6 +1465,8 @@ static int viacam_remove(struct platform_device *pdev)
1499 v4l2_device_unregister(&cam->v4l2_dev); 1465 v4l2_device_unregister(&cam->v4l2_dev);
1500 free_irq(viadev->pdev->irq, cam); 1466 free_irq(viadev->pdev->irq, cam);
1501 via_sensor_power_release(cam); 1467 via_sensor_power_release(cam);
1468 v4l2_ctrl_handler_free(&cam->ctrl_handler);
1469 kfree(cam);
1502 via_cam_info = NULL; 1470 via_cam_info = NULL;
1503 return 0; 1471 return 0;
1504} 1472}
diff --git a/drivers/media/platform/vino.c b/drivers/media/platform/vino.c
index 70b0bf4b2900..eb5d6f955709 100644
--- a/drivers/media/platform/vino.c
+++ b/drivers/media/platform/vino.c
@@ -2474,8 +2474,8 @@ static irqreturn_t vino_interrupt(int irq, void *dev_id)
2474 2474
2475 if ((!handled_a) && (done_a || skip_a)) { 2475 if ((!handled_a) && (done_a || skip_a)) {
2476 if (!skip_a) { 2476 if (!skip_a) {
2477 do_gettimeofday(&vino_drvdata-> 2477 v4l2_get_timestamp(
2478 a.int_data.timestamp); 2478 &vino_drvdata->a.int_data.timestamp);
2479 vino_drvdata->a.int_data.frame_counter = fc_a; 2479 vino_drvdata->a.int_data.frame_counter = fc_a;
2480 } 2480 }
2481 vino_drvdata->a.int_data.skip = skip_a; 2481 vino_drvdata->a.int_data.skip = skip_a;
@@ -2489,8 +2489,8 @@ static irqreturn_t vino_interrupt(int irq, void *dev_id)
2489 2489
2490 if ((!handled_b) && (done_b || skip_b)) { 2490 if ((!handled_b) && (done_b || skip_b)) {
2491 if (!skip_b) { 2491 if (!skip_b) {
2492 do_gettimeofday(&vino_drvdata-> 2492 v4l2_get_timestamp(
2493 b.int_data.timestamp); 2493 &vino_drvdata->b.int_data.timestamp);
2494 vino_drvdata->b.int_data.frame_counter = fc_b; 2494 vino_drvdata->b.int_data.frame_counter = fc_b;
2495 } 2495 }
2496 vino_drvdata->b.int_data.skip = skip_b; 2496 vino_drvdata->b.int_data.skip = skip_b;
@@ -3410,6 +3410,9 @@ static void vino_v4l2_get_buffer_status(struct vino_channel_settings *vcs,
3410 if (fb->map_count > 0) 3410 if (fb->map_count > 0)
3411 b->flags |= V4L2_BUF_FLAG_MAPPED; 3411 b->flags |= V4L2_BUF_FLAG_MAPPED;
3412 3412
3413 b->flags &= ~V4L2_BUF_FLAG_TIMESTAMP_MASK;
3414 b->flags |= V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
3415
3413 b->index = fb->id; 3416 b->index = fb->id;
3414 b->memory = (vcs->fb_queue.type == VINO_MEMORY_MMAP) ? 3417 b->memory = (vcs->fb_queue.type == VINO_MEMORY_MMAP) ?
3415 V4L2_MEMORY_MMAP : V4L2_MEMORY_USERPTR; 3418 V4L2_MEMORY_MMAP : V4L2_MEMORY_USERPTR;
diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
index 0d59b9db83cb..8a33a712f480 100644
--- a/drivers/media/platform/vivi.c
+++ b/drivers/media/platform/vivi.c
@@ -36,9 +36,17 @@
36 36
37#define VIVI_MODULE_NAME "vivi" 37#define VIVI_MODULE_NAME "vivi"
38 38
39/* Wake up at about 30 fps */ 39/* Maximum allowed frame rate
40#define WAKE_NUMERATOR 30 40 *
41#define WAKE_DENOMINATOR 1001 41 * Vivi will allow setting timeperframe in [1/FPS_MAX - FPS_MAX/1] range.
42 *
43 * Ideally FPS_MAX should be infinity, i.e. practically UINT_MAX, but that
44 * might hit application errors when they manipulate these values.
45 *
46 * Besides, for tpf < 1ms image-generation logic should be changed, to avoid
47 * producing frames with equal content.
48 */
49#define FPS_MAX 1000
42 50
43#define MAX_WIDTH 1920 51#define MAX_WIDTH 1920
44#define MAX_HEIGHT 1200 52#define MAX_HEIGHT 1200
@@ -69,6 +77,12 @@ MODULE_PARM_DESC(vid_limit, "capture memory limit in megabytes");
69/* Global font descriptor */ 77/* Global font descriptor */
70static const u8 *font8x16; 78static const u8 *font8x16;
71 79
80/* timeperframe: min/max and default */
81static const struct v4l2_fract
82 tpf_min = {.numerator = 1, .denominator = FPS_MAX},
83 tpf_max = {.numerator = FPS_MAX, .denominator = 1},
84 tpf_default = {.numerator = 1001, .denominator = 30000}; /* NTSC */
85
72#define dprintk(dev, level, fmt, arg...) \ 86#define dprintk(dev, level, fmt, arg...) \
73 v4l2_dbg(level, debug, &dev->v4l2_dev, fmt, ## arg) 87 v4l2_dbg(level, debug, &dev->v4l2_dev, fmt, ## arg)
74 88
@@ -77,13 +91,13 @@ static const u8 *font8x16;
77 ------------------------------------------------------------------*/ 91 ------------------------------------------------------------------*/
78 92
79struct vivi_fmt { 93struct vivi_fmt {
80 char *name; 94 const char *name;
81 u32 fourcc; /* v4l2 format id */ 95 u32 fourcc; /* v4l2 format id */
82 u8 depth; 96 u8 depth;
83 bool is_yuv; 97 bool is_yuv;
84}; 98};
85 99
86static struct vivi_fmt formats[] = { 100static const struct vivi_fmt formats[] = {
87 { 101 {
88 .name = "4:2:2, packed, YUYV", 102 .name = "4:2:2, packed, YUYV",
89 .fourcc = V4L2_PIX_FMT_YUYV, 103 .fourcc = V4L2_PIX_FMT_YUYV,
@@ -150,14 +164,14 @@ static struct vivi_fmt formats[] = {
150 }, 164 },
151}; 165};
152 166
153static struct vivi_fmt *get_format(struct v4l2_format *f) 167static const struct vivi_fmt *__get_format(u32 pixelformat)
154{ 168{
155 struct vivi_fmt *fmt; 169 const struct vivi_fmt *fmt;
156 unsigned int k; 170 unsigned int k;
157 171
158 for (k = 0; k < ARRAY_SIZE(formats); k++) { 172 for (k = 0; k < ARRAY_SIZE(formats); k++) {
159 fmt = &formats[k]; 173 fmt = &formats[k];
160 if (fmt->fourcc == f->fmt.pix.pixelformat) 174 if (fmt->fourcc == pixelformat)
161 break; 175 break;
162 } 176 }
163 177
@@ -167,12 +181,17 @@ static struct vivi_fmt *get_format(struct v4l2_format *f)
167 return &formats[k]; 181 return &formats[k];
168} 182}
169 183
184static const struct vivi_fmt *get_format(struct v4l2_format *f)
185{
186 return __get_format(f->fmt.pix.pixelformat);
187}
188
170/* buffer for one video frame */ 189/* buffer for one video frame */
171struct vivi_buffer { 190struct vivi_buffer {
172 /* common v4l buffer stuff -- must be first */ 191 /* common v4l buffer stuff -- must be first */
173 struct vb2_buffer vb; 192 struct vb2_buffer vb;
174 struct list_head list; 193 struct list_head list;
175 struct vivi_fmt *fmt; 194 const struct vivi_fmt *fmt;
176}; 195};
177 196
178struct vivi_dmaqueue { 197struct vivi_dmaqueue {
@@ -231,15 +250,17 @@ struct vivi_dev {
231 int input; 250 int input;
232 251
233 /* video capture */ 252 /* video capture */
234 struct vivi_fmt *fmt; 253 const struct vivi_fmt *fmt;
254 struct v4l2_fract timeperframe;
235 unsigned int width, height; 255 unsigned int width, height;
236 struct vb2_queue vb_vidq; 256 struct vb2_queue vb_vidq;
237 unsigned int field_count; 257 unsigned int field_count;
238 258
239 u8 bars[9][3]; 259 u8 bars[9][3];
240 u8 line[MAX_WIDTH * 8]; 260 u8 line[MAX_WIDTH * 8] __attribute__((__aligned__(4)));
241 unsigned int pixelsize; 261 unsigned int pixelsize;
242 u8 alpha_component; 262 u8 alpha_component;
263 u32 textfg, textbg;
243}; 264};
244 265
245/* ------------------------------------------------------------------ 266/* ------------------------------------------------------------------
@@ -276,7 +297,7 @@ struct bar_std {
276 297
277/* Maximum number of bars are 10 - otherwise, the input print code 298/* Maximum number of bars are 10 - otherwise, the input print code
278 should be modified */ 299 should be modified */
279static struct bar_std bars[] = { 300static const struct bar_std bars[] = {
280 { /* Standard ITU-R color bar sequence */ 301 { /* Standard ITU-R color bar sequence */
281 { COLOR_WHITE, COLOR_AMBER, COLOR_CYAN, COLOR_GREEN, 302 { COLOR_WHITE, COLOR_AMBER, COLOR_CYAN, COLOR_GREEN,
282 COLOR_MAGENTA, COLOR_RED, COLOR_BLUE, COLOR_BLACK, COLOR_BLACK } 303 COLOR_MAGENTA, COLOR_RED, COLOR_BLUE, COLOR_BLACK, COLOR_BLACK }
@@ -511,66 +532,100 @@ static void gen_twopix(struct vivi_dev *dev, u8 *buf, int colorpos, bool odd)
511 532
512static void precalculate_line(struct vivi_dev *dev) 533static void precalculate_line(struct vivi_dev *dev)
513{ 534{
514 int w; 535 unsigned pixsize = dev->pixelsize;
515 536 unsigned pixsize2 = 2*pixsize;
516 for (w = 0; w < dev->width * 2; w++) { 537 int colorpos;
517 int colorpos = w / (dev->width / 8) % 8; 538 u8 *pos;
518 539
519 gen_twopix(dev, dev->line + w * dev->pixelsize, colorpos, w & 1); 540 for (colorpos = 0; colorpos < 16; ++colorpos) {
541 u8 pix[8];
542 int wstart = colorpos * dev->width / 8;
543 int wend = (colorpos+1) * dev->width / 8;
544 int w;
545
546 gen_twopix(dev, &pix[0], colorpos % 8, 0);
547 gen_twopix(dev, &pix[pixsize], colorpos % 8, 1);
548
549 for (w = wstart/2*2, pos = dev->line + w*pixsize; w < wend; w += 2, pos += pixsize2)
550 memcpy(pos, pix, pixsize2);
520 } 551 }
521} 552}
522 553
554/* need this to do rgb24 rendering */
555typedef struct { u16 __; u8 _; } __attribute__((packed)) x24;
556
523static void gen_text(struct vivi_dev *dev, char *basep, 557static void gen_text(struct vivi_dev *dev, char *basep,
524 int y, int x, char *text) 558 int y, int x, char *text)
525{ 559{
526 int line; 560 int line;
561 unsigned int width = dev->width;
527 562
528 /* Checks if it is possible to show string */ 563 /* Checks if it is possible to show string */
529 if (y + 16 >= dev->height || x + strlen(text) * 8 >= dev->width) 564 if (y + 16 >= dev->height || x + strlen(text) * 8 >= width)
530 return; 565 return;
531 566
532 /* Print stream time */ 567 /* Print stream time */
533 for (line = y; line < y + 16; line++) { 568#define PRINTSTR(PIXTYPE) do { \
534 int j = 0; 569 PIXTYPE fg; \
535 char *pos = basep + line * dev->width * dev->pixelsize + x * dev->pixelsize; 570 PIXTYPE bg; \
536 char *s; 571 memcpy(&fg, &dev->textfg, sizeof(PIXTYPE)); \
537 572 memcpy(&bg, &dev->textbg, sizeof(PIXTYPE)); \
538 for (s = text; *s; s++) { 573 \
539 u8 chr = font8x16[*s * 16 + line - y]; 574 for (line = 0; line < 16; line++) { \
540 int i; 575 PIXTYPE *pos = (PIXTYPE *)( basep + ((y + line) * width + x) * sizeof(PIXTYPE) ); \
541 576 u8 *s; \
542 for (i = 0; i < 7; i++, j++) { 577 \
543 /* Draw white font on black background */ 578 for (s = text; *s; s++) { \
544 if (chr & (1 << (7 - i))) 579 u8 chr = font8x16[*s * 16 + line]; \
545 gen_twopix(dev, pos + j * dev->pixelsize, WHITE, (x+y) & 1); 580 \
546 else 581 pos[0] = (chr & (0x01 << 7) ? fg : bg); \
547 gen_twopix(dev, pos + j * dev->pixelsize, TEXT_BLACK, (x+y) & 1); 582 pos[1] = (chr & (0x01 << 6) ? fg : bg); \
548 } 583 pos[2] = (chr & (0x01 << 5) ? fg : bg); \
549 } 584 pos[3] = (chr & (0x01 << 4) ? fg : bg); \
585 pos[4] = (chr & (0x01 << 3) ? fg : bg); \
586 pos[5] = (chr & (0x01 << 2) ? fg : bg); \
587 pos[6] = (chr & (0x01 << 1) ? fg : bg); \
588 pos[7] = (chr & (0x01 << 0) ? fg : bg); \
589 \
590 pos += 8; \
591 } \
592 } \
593} while (0)
594
595 switch (dev->pixelsize) {
596 case 2:
597 PRINTSTR(u16); break;
598 case 4:
599 PRINTSTR(u32); break;
600 case 3:
601 PRINTSTR(x24); break;
550 } 602 }
551} 603}
552 604
553static void vivi_fillbuff(struct vivi_dev *dev, struct vivi_buffer *buf) 605static void vivi_fillbuff(struct vivi_dev *dev, struct vivi_buffer *buf)
554{ 606{
555 int wmax = dev->width; 607 int stride = dev->width * dev->pixelsize;
556 int hmax = dev->height; 608 int hmax = dev->height;
557 struct timeval ts;
558 void *vbuf = vb2_plane_vaddr(&buf->vb, 0); 609 void *vbuf = vb2_plane_vaddr(&buf->vb, 0);
559 unsigned ms; 610 unsigned ms;
560 char str[100]; 611 char str[100];
561 int h, line = 1; 612 int h, line = 1;
613 u8 *linestart;
562 s32 gain; 614 s32 gain;
563 615
564 if (!vbuf) 616 if (!vbuf)
565 return; 617 return;
566 618
619 linestart = dev->line + (dev->mv_count % dev->width) * dev->pixelsize;
620
567 for (h = 0; h < hmax; h++) 621 for (h = 0; h < hmax; h++)
568 memcpy(vbuf + h * wmax * dev->pixelsize, 622 memcpy(vbuf + h * stride, linestart, stride);
569 dev->line + (dev->mv_count % wmax) * dev->pixelsize,
570 wmax * dev->pixelsize);
571 623
572 /* Updates stream time */ 624 /* Updates stream time */
573 625
626 gen_twopix(dev, (u8 *)&dev->textbg, TEXT_BLACK, /*odd=*/ 0);
627 gen_twopix(dev, (u8 *)&dev->textfg, WHITE, /*odd=*/ 0);
628
574 dev->ms += jiffies_to_msecs(jiffies - dev->jiffies); 629 dev->ms += jiffies_to_msecs(jiffies - dev->jiffies);
575 dev->jiffies = jiffies; 630 dev->jiffies = jiffies;
576 ms = dev->ms; 631 ms = dev->ms;
@@ -622,8 +677,7 @@ static void vivi_fillbuff(struct vivi_dev *dev, struct vivi_buffer *buf)
622 buf->vb.v4l2_buf.field = V4L2_FIELD_INTERLACED; 677 buf->vb.v4l2_buf.field = V4L2_FIELD_INTERLACED;
623 dev->field_count++; 678 dev->field_count++;
624 buf->vb.v4l2_buf.sequence = dev->field_count >> 1; 679 buf->vb.v4l2_buf.sequence = dev->field_count >> 1;
625 do_gettimeofday(&ts); 680 v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp);
626 buf->vb.v4l2_buf.timestamp = ts;
627} 681}
628 682
629static void vivi_thread_tick(struct vivi_dev *dev) 683static void vivi_thread_tick(struct vivi_dev *dev)
@@ -645,7 +699,7 @@ static void vivi_thread_tick(struct vivi_dev *dev)
645 list_del(&buf->list); 699 list_del(&buf->list);
646 spin_unlock_irqrestore(&dev->slock, flags); 700 spin_unlock_irqrestore(&dev->slock, flags);
647 701
648 do_gettimeofday(&buf->vb.v4l2_buf.timestamp); 702 v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp);
649 703
650 /* Fill buffer */ 704 /* Fill buffer */
651 vivi_fillbuff(dev, buf); 705 vivi_fillbuff(dev, buf);
@@ -655,8 +709,8 @@ static void vivi_thread_tick(struct vivi_dev *dev)
655 dprintk(dev, 2, "[%p/%d] done\n", buf, buf->vb.v4l2_buf.index); 709 dprintk(dev, 2, "[%p/%d] done\n", buf, buf->vb.v4l2_buf.index);
656} 710}
657 711
658#define frames_to_ms(frames) \ 712#define frames_to_ms(dev, frames) \
659 ((frames * WAKE_NUMERATOR * 1000) / WAKE_DENOMINATOR) 713 ((frames * dev->timeperframe.numerator * 1000) / dev->timeperframe.denominator)
660 714
661static void vivi_sleep(struct vivi_dev *dev) 715static void vivi_sleep(struct vivi_dev *dev)
662{ 716{
@@ -672,7 +726,7 @@ static void vivi_sleep(struct vivi_dev *dev)
672 goto stop_task; 726 goto stop_task;
673 727
674 /* Calculate time to wake up */ 728 /* Calculate time to wake up */
675 timeout = msecs_to_jiffies(frames_to_ms(1)); 729 timeout = msecs_to_jiffies(frames_to_ms(dev, 1));
676 730
677 vivi_thread_tick(dev); 731 vivi_thread_tick(dev);
678 732
@@ -872,7 +926,7 @@ static void vivi_unlock(struct vb2_queue *vq)
872} 926}
873 927
874 928
875static struct vb2_ops vivi_video_qops = { 929static const struct vb2_ops vivi_video_qops = {
876 .queue_setup = queue_setup, 930 .queue_setup = queue_setup,
877 .buf_prepare = buffer_prepare, 931 .buf_prepare = buffer_prepare,
878 .buf_queue = buffer_queue, 932 .buf_queue = buffer_queue,
@@ -903,7 +957,7 @@ static int vidioc_querycap(struct file *file, void *priv,
903static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv, 957static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
904 struct v4l2_fmtdesc *f) 958 struct v4l2_fmtdesc *f)
905{ 959{
906 struct vivi_fmt *fmt; 960 const struct vivi_fmt *fmt;
907 961
908 if (f->index >= ARRAY_SIZE(formats)) 962 if (f->index >= ARRAY_SIZE(formats))
909 return -EINVAL; 963 return -EINVAL;
@@ -939,7 +993,7 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
939 struct v4l2_format *f) 993 struct v4l2_format *f)
940{ 994{
941 struct vivi_dev *dev = video_drvdata(file); 995 struct vivi_dev *dev = video_drvdata(file);
942 struct vivi_fmt *fmt; 996 const struct vivi_fmt *fmt;
943 997
944 fmt = get_format(f); 998 fmt = get_format(f);
945 if (!fmt) { 999 if (!fmt) {
@@ -1044,6 +1098,70 @@ static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
1044 return 0; 1098 return 0;
1045} 1099}
1046 1100
1101/* timeperframe is arbitrary and continous */
1102static int vidioc_enum_frameintervals(struct file *file, void *priv,
1103 struct v4l2_frmivalenum *fival)
1104{
1105 const struct vivi_fmt *fmt;
1106
1107 if (fival->index)
1108 return -EINVAL;
1109
1110 fmt = __get_format(fival->pixel_format);
1111 if (!fmt)
1112 return -EINVAL;
1113
1114 /* regarding width & height - we support any */
1115
1116 fival->type = V4L2_FRMIVAL_TYPE_CONTINUOUS;
1117
1118 /* fill in stepwise (step=1.0 is requred by V4L2 spec) */
1119 fival->stepwise.min = tpf_min;
1120 fival->stepwise.max = tpf_max;
1121 fival->stepwise.step = (struct v4l2_fract) {1, 1};
1122
1123 return 0;
1124}
1125
1126static int vidioc_g_parm(struct file *file, void *priv,
1127 struct v4l2_streamparm *parm)
1128{
1129 struct vivi_dev *dev = video_drvdata(file);
1130
1131 if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1132 return -EINVAL;
1133
1134 parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
1135 parm->parm.capture.timeperframe = dev->timeperframe;
1136 parm->parm.capture.readbuffers = 1;
1137 return 0;
1138}
1139
1140#define FRACT_CMP(a, OP, b) \
1141 ((u64)(a).numerator * (b).denominator OP (u64)(b).numerator * (a).denominator)
1142
1143static int vidioc_s_parm(struct file *file, void *priv,
1144 struct v4l2_streamparm *parm)
1145{
1146 struct vivi_dev *dev = video_drvdata(file);
1147 struct v4l2_fract tpf;
1148
1149 if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1150 return -EINVAL;
1151
1152 tpf = parm->parm.capture.timeperframe;
1153
1154 /* tpf: {*, 0} resets timing; clip to [min, max]*/
1155 tpf = tpf.denominator ? tpf : tpf_default;
1156 tpf = FRACT_CMP(tpf, <, tpf_min) ? tpf_min : tpf;
1157 tpf = FRACT_CMP(tpf, >, tpf_max) ? tpf_max : tpf;
1158
1159 dev->timeperframe = tpf;
1160 parm->parm.capture.timeperframe = tpf;
1161 parm->parm.capture.readbuffers = 1;
1162 return 0;
1163}
1164
1047/* --- controls ---------------------------------------------- */ 1165/* --- controls ---------------------------------------------- */
1048 1166
1049static int vivi_g_volatile_ctrl(struct v4l2_ctrl *ctrl) 1167static int vivi_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
@@ -1202,6 +1320,9 @@ static const struct v4l2_ioctl_ops vivi_ioctl_ops = {
1202 .vidioc_enum_input = vidioc_enum_input, 1320 .vidioc_enum_input = vidioc_enum_input,
1203 .vidioc_g_input = vidioc_g_input, 1321 .vidioc_g_input = vidioc_g_input,
1204 .vidioc_s_input = vidioc_s_input, 1322 .vidioc_s_input = vidioc_s_input,
1323 .vidioc_enum_frameintervals = vidioc_enum_frameintervals,
1324 .vidioc_g_parm = vidioc_g_parm,
1325 .vidioc_s_parm = vidioc_s_parm,
1205 .vidioc_streamon = vb2_ioctl_streamon, 1326 .vidioc_streamon = vb2_ioctl_streamon,
1206 .vidioc_streamoff = vb2_ioctl_streamoff, 1327 .vidioc_streamoff = vb2_ioctl_streamoff,
1207 .vidioc_log_status = v4l2_ctrl_log_status, 1328 .vidioc_log_status = v4l2_ctrl_log_status,
@@ -1209,7 +1330,7 @@ static const struct v4l2_ioctl_ops vivi_ioctl_ops = {
1209 .vidioc_unsubscribe_event = v4l2_event_unsubscribe, 1330 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1210}; 1331};
1211 1332
1212static struct video_device vivi_template = { 1333static const struct video_device vivi_template = {
1213 .name = "vivi", 1334 .name = "vivi",
1214 .fops = &vivi_fops, 1335 .fops = &vivi_fops,
1215 .ioctl_ops = &vivi_ioctl_ops, 1336 .ioctl_ops = &vivi_ioctl_ops,
@@ -1260,6 +1381,7 @@ static int __init vivi_create_instance(int inst)
1260 goto free_dev; 1381 goto free_dev;
1261 1382
1262 dev->fmt = &formats[0]; 1383 dev->fmt = &formats[0];
1384 dev->timeperframe = tpf_default;
1263 dev->width = 640; 1385 dev->width = 640;
1264 dev->height = 480; 1386 dev->height = 480;
1265 dev->pixelsize = dev->fmt->depth / 8; 1387 dev->pixelsize = dev->fmt->depth / 8;
diff --git a/drivers/media/radio/Kconfig b/drivers/media/radio/Kconfig
index 9e580166161a..24e64a09884c 100644
--- a/drivers/media/radio/Kconfig
+++ b/drivers/media/radio/Kconfig
@@ -124,6 +124,18 @@ config USB_KEENE
124 To compile this driver as a module, choose M here: the 124 To compile this driver as a module, choose M here: the
125 module will be called radio-keene. 125 module will be called radio-keene.
126 126
127config USB_MA901
128 tristate "Masterkit MA901 USB FM radio support"
129 depends on USB && VIDEO_V4L2
130 ---help---
131 Say Y here if you want to connect this type of radio to your
132 computer's USB port. Note that the audio is not digital, and
133 you must connect the line out connector to a sound card or a
134 set of speakers or headphones.
135
136 To compile this driver as a module, choose M here: the
137 module will be called radio-ma901.
138
127config RADIO_TEA5764 139config RADIO_TEA5764
128 tristate "TEA5764 I2C FM radio support" 140 tristate "TEA5764 I2C FM radio support"
129 depends on I2C && VIDEO_V4L2 141 depends on I2C && VIDEO_V4L2
diff --git a/drivers/media/radio/Makefile b/drivers/media/radio/Makefile
index c03ce4fe74e9..303eaebdb85a 100644
--- a/drivers/media/radio/Makefile
+++ b/drivers/media/radio/Makefile
@@ -24,6 +24,7 @@ obj-$(CONFIG_USB_DSBR) += dsbr100.o
24obj-$(CONFIG_RADIO_SI470X) += si470x/ 24obj-$(CONFIG_RADIO_SI470X) += si470x/
25obj-$(CONFIG_USB_MR800) += radio-mr800.o 25obj-$(CONFIG_USB_MR800) += radio-mr800.o
26obj-$(CONFIG_USB_KEENE) += radio-keene.o 26obj-$(CONFIG_USB_KEENE) += radio-keene.o
27obj-$(CONFIG_USB_MA901) += radio-ma901.o
27obj-$(CONFIG_RADIO_TEA5764) += radio-tea5764.o 28obj-$(CONFIG_RADIO_TEA5764) += radio-tea5764.o
28obj-$(CONFIG_RADIO_SAA7706H) += saa7706h.o 29obj-$(CONFIG_RADIO_SAA7706H) += saa7706h.o
29obj-$(CONFIG_RADIO_TEF6862) += tef6862.o 30obj-$(CONFIG_RADIO_TEF6862) += tef6862.o
diff --git a/drivers/media/radio/radio-ma901.c b/drivers/media/radio/radio-ma901.c
new file mode 100644
index 000000000000..c61f590029ad
--- /dev/null
+++ b/drivers/media/radio/radio-ma901.c
@@ -0,0 +1,460 @@
1/*
2 * Driver for the MasterKit MA901 USB FM radio. This device plugs
3 * into the USB port and an analog audio input or headphones, so this thing
4 * only deals with initialization, frequency setting, volume.
5 *
6 * Copyright (c) 2012 Alexey Klimov <klimov.linux@gmail.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#include <linux/kernel.h>
24#include <linux/module.h>
25#include <linux/init.h>
26#include <linux/slab.h>
27#include <linux/input.h>
28#include <linux/videodev2.h>
29#include <media/v4l2-device.h>
30#include <media/v4l2-ioctl.h>
31#include <media/v4l2-ctrls.h>
32#include <media/v4l2-event.h>
33#include <linux/usb.h>
34#include <linux/mutex.h>
35
36#define DRIVER_AUTHOR "Alexey Klimov <klimov.linux@gmail.com>"
37#define DRIVER_DESC "Masterkit MA901 USB FM radio driver"
38#define DRIVER_VERSION "0.0.1"
39
40MODULE_AUTHOR(DRIVER_AUTHOR);
41MODULE_DESCRIPTION(DRIVER_DESC);
42MODULE_LICENSE("GPL");
43MODULE_VERSION(DRIVER_VERSION);
44
45#define USB_MA901_VENDOR 0x16c0
46#define USB_MA901_PRODUCT 0x05df
47
48/* dev_warn macro with driver name */
49#define MA901_DRIVER_NAME "radio-ma901"
50#define ma901radio_dev_warn(dev, fmt, arg...) \
51 dev_warn(dev, MA901_DRIVER_NAME " - " fmt, ##arg)
52
53#define ma901radio_dev_err(dev, fmt, arg...) \
54 dev_err(dev, MA901_DRIVER_NAME " - " fmt, ##arg)
55
56/* Probably USB_TIMEOUT should be modified in module parameter */
57#define BUFFER_LENGTH 8
58#define USB_TIMEOUT 500
59
60#define FREQ_MIN 87.5
61#define FREQ_MAX 108.0
62#define FREQ_MUL 16000
63
64#define MA901_VOLUME_MAX 16
65#define MA901_VOLUME_MIN 0
66
67/* Commands that device should understand
68 * List isn't full and will be updated with implementation of new functions
69 */
70#define MA901_RADIO_SET_FREQ 0x03
71#define MA901_RADIO_SET_VOLUME 0x04
72#define MA901_RADIO_SET_MONO_STEREO 0x05
73
74/* Comfortable defines for ma901radio_set_stereo */
75#define MA901_WANT_STEREO 0x50
76#define MA901_WANT_MONO 0xd0
77
78/* module parameter */
79static int radio_nr = -1;
80module_param(radio_nr, int, 0);
81MODULE_PARM_DESC(radio_nr, "Radio file number");
82
83/* Data for one (physical) device */
84struct ma901radio_device {
85 /* reference to USB and video device */
86 struct usb_device *usbdev;
87 struct usb_interface *intf;
88 struct video_device vdev;
89 struct v4l2_device v4l2_dev;
90 struct v4l2_ctrl_handler hdl;
91
92 u8 *buffer;
93 struct mutex lock; /* buffer locking */
94 int curfreq;
95 u16 volume;
96 int stereo;
97 bool muted;
98};
99
100static inline struct ma901radio_device *to_ma901radio_dev(struct v4l2_device *v4l2_dev)
101{
102 return container_of(v4l2_dev, struct ma901radio_device, v4l2_dev);
103}
104
105/* set a frequency, freq is defined by v4l's TUNER_LOW, i.e. 1/16th kHz */
106static int ma901radio_set_freq(struct ma901radio_device *radio, int freq)
107{
108 unsigned int freq_send = 0x300 + (freq >> 5) / 25;
109 int retval;
110
111 radio->buffer[0] = 0x0a;
112 radio->buffer[1] = MA901_RADIO_SET_FREQ;
113 radio->buffer[2] = ((freq_send >> 8) & 0xff) + 0x80;
114 radio->buffer[3] = freq_send & 0xff;
115 radio->buffer[4] = 0x00;
116 radio->buffer[5] = 0x00;
117 radio->buffer[6] = 0x00;
118 radio->buffer[7] = 0x00;
119
120 retval = usb_control_msg(radio->usbdev, usb_sndctrlpipe(radio->usbdev, 0),
121 9, 0x21, 0x0300, 0,
122 radio->buffer, BUFFER_LENGTH, USB_TIMEOUT);
123 if (retval < 0)
124 return retval;
125
126 radio->curfreq = freq;
127 return 0;
128}
129
130static int ma901radio_set_volume(struct ma901radio_device *radio, u16 vol_to_set)
131{
132 int retval;
133
134 radio->buffer[0] = 0x0a;
135 radio->buffer[1] = MA901_RADIO_SET_VOLUME;
136 radio->buffer[2] = 0xc2;
137 radio->buffer[3] = vol_to_set + 0x20;
138 radio->buffer[4] = 0x00;
139 radio->buffer[5] = 0x00;
140 radio->buffer[6] = 0x00;
141 radio->buffer[7] = 0x00;
142
143 retval = usb_control_msg(radio->usbdev, usb_sndctrlpipe(radio->usbdev, 0),
144 9, 0x21, 0x0300, 0,
145 radio->buffer, BUFFER_LENGTH, USB_TIMEOUT);
146 if (retval < 0)
147 return retval;
148
149 radio->volume = vol_to_set;
150 return retval;
151}
152
153static int ma901_set_stereo(struct ma901radio_device *radio, u8 stereo)
154{
155 int retval;
156
157 radio->buffer[0] = 0x0a;
158 radio->buffer[1] = MA901_RADIO_SET_MONO_STEREO;
159 radio->buffer[2] = stereo;
160 radio->buffer[3] = 0x00;
161 radio->buffer[4] = 0x00;
162 radio->buffer[5] = 0x00;
163 radio->buffer[6] = 0x00;
164 radio->buffer[7] = 0x00;
165
166 retval = usb_control_msg(radio->usbdev, usb_sndctrlpipe(radio->usbdev, 0),
167 9, 0x21, 0x0300, 0,
168 radio->buffer, BUFFER_LENGTH, USB_TIMEOUT);
169
170 if (retval < 0)
171 return retval;
172
173 if (stereo == MA901_WANT_STEREO)
174 radio->stereo = V4L2_TUNER_MODE_STEREO;
175 else
176 radio->stereo = V4L2_TUNER_MODE_MONO;
177
178 return retval;
179}
180
181/* Handle unplugging the device.
182 * We call video_unregister_device in any case.
183 * The last function called in this procedure is
184 * usb_ma901radio_device_release.
185 */
186static void usb_ma901radio_disconnect(struct usb_interface *intf)
187{
188 struct ma901radio_device *radio = to_ma901radio_dev(usb_get_intfdata(intf));
189
190 mutex_lock(&radio->lock);
191 video_unregister_device(&radio->vdev);
192 usb_set_intfdata(intf, NULL);
193 v4l2_device_disconnect(&radio->v4l2_dev);
194 mutex_unlock(&radio->lock);
195 v4l2_device_put(&radio->v4l2_dev);
196}
197
198/* vidioc_querycap - query device capabilities */
199static int vidioc_querycap(struct file *file, void *priv,
200 struct v4l2_capability *v)
201{
202 struct ma901radio_device *radio = video_drvdata(file);
203
204 strlcpy(v->driver, "radio-ma901", sizeof(v->driver));
205 strlcpy(v->card, "Masterkit MA901 USB FM Radio", sizeof(v->card));
206 usb_make_path(radio->usbdev, v->bus_info, sizeof(v->bus_info));
207 v->device_caps = V4L2_CAP_RADIO | V4L2_CAP_TUNER;
208 v->capabilities = v->device_caps | V4L2_CAP_DEVICE_CAPS;
209 return 0;
210}
211
212/* vidioc_g_tuner - get tuner attributes */
213static int vidioc_g_tuner(struct file *file, void *priv,
214 struct v4l2_tuner *v)
215{
216 struct ma901radio_device *radio = video_drvdata(file);
217
218 if (v->index > 0)
219 return -EINVAL;
220
221 v->signal = 0;
222
223 /* TODO: the same words like in _probe() goes here.
224 * When receiving of stats will be implemented then we can call
225 * ma901radio_get_stat().
226 * retval = ma901radio_get_stat(radio, &is_stereo, &v->signal);
227 */
228
229 strcpy(v->name, "FM");
230 v->type = V4L2_TUNER_RADIO;
231 v->rangelow = FREQ_MIN * FREQ_MUL;
232 v->rangehigh = FREQ_MAX * FREQ_MUL;
233 v->capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO;
234 /* v->rxsubchans = is_stereo ? V4L2_TUNER_SUB_STEREO : V4L2_TUNER_SUB_MONO; */
235 v->audmode = radio->stereo ?
236 V4L2_TUNER_MODE_STEREO : V4L2_TUNER_MODE_MONO;
237 return 0;
238}
239
240/* vidioc_s_tuner - set tuner attributes */
241static int vidioc_s_tuner(struct file *file, void *priv,
242 struct v4l2_tuner *v)
243{
244 struct ma901radio_device *radio = video_drvdata(file);
245
246 if (v->index > 0)
247 return -EINVAL;
248
249 /* mono/stereo selector */
250 switch (v->audmode) {
251 case V4L2_TUNER_MODE_MONO:
252 return ma901_set_stereo(radio, MA901_WANT_MONO);
253 default:
254 return ma901_set_stereo(radio, MA901_WANT_STEREO);
255 }
256}
257
258/* vidioc_s_frequency - set tuner radio frequency */
259static int vidioc_s_frequency(struct file *file, void *priv,
260 struct v4l2_frequency *f)
261{
262 struct ma901radio_device *radio = video_drvdata(file);
263
264 if (f->tuner != 0)
265 return -EINVAL;
266
267 return ma901radio_set_freq(radio, clamp_t(unsigned, f->frequency,
268 FREQ_MIN * FREQ_MUL, FREQ_MAX * FREQ_MUL));
269}
270
271/* vidioc_g_frequency - get tuner radio frequency */
272static int vidioc_g_frequency(struct file *file, void *priv,
273 struct v4l2_frequency *f)
274{
275 struct ma901radio_device *radio = video_drvdata(file);
276
277 if (f->tuner != 0)
278 return -EINVAL;
279 f->frequency = radio->curfreq;
280
281 return 0;
282}
283
284static int usb_ma901radio_s_ctrl(struct v4l2_ctrl *ctrl)
285{
286 struct ma901radio_device *radio =
287 container_of(ctrl->handler, struct ma901radio_device, hdl);
288
289 switch (ctrl->id) {
290 case V4L2_CID_AUDIO_VOLUME: /* set volume */
291 return ma901radio_set_volume(radio, (u16)ctrl->val);
292 }
293
294 return -EINVAL;
295}
296
297/* TODO: Should we really need to implement suspend and resume functions?
298 * Radio has it's own memory and will continue playing if power is present
299 * on usb port and on resume it will start to play again based on freq, volume
300 * values in device memory.
301 */
302static int usb_ma901radio_suspend(struct usb_interface *intf, pm_message_t message)
303{
304 return 0;
305}
306
307static int usb_ma901radio_resume(struct usb_interface *intf)
308{
309 return 0;
310}
311
312static const struct v4l2_ctrl_ops usb_ma901radio_ctrl_ops = {
313 .s_ctrl = usb_ma901radio_s_ctrl,
314};
315
316/* File system interface */
317static const struct v4l2_file_operations usb_ma901radio_fops = {
318 .owner = THIS_MODULE,
319 .open = v4l2_fh_open,
320 .release = v4l2_fh_release,
321 .poll = v4l2_ctrl_poll,
322 .unlocked_ioctl = video_ioctl2,
323};
324
325static const struct v4l2_ioctl_ops usb_ma901radio_ioctl_ops = {
326 .vidioc_querycap = vidioc_querycap,
327 .vidioc_g_tuner = vidioc_g_tuner,
328 .vidioc_s_tuner = vidioc_s_tuner,
329 .vidioc_g_frequency = vidioc_g_frequency,
330 .vidioc_s_frequency = vidioc_s_frequency,
331 .vidioc_log_status = v4l2_ctrl_log_status,
332 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
333 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
334};
335
336static void usb_ma901radio_release(struct v4l2_device *v4l2_dev)
337{
338 struct ma901radio_device *radio = to_ma901radio_dev(v4l2_dev);
339
340 v4l2_ctrl_handler_free(&radio->hdl);
341 v4l2_device_unregister(&radio->v4l2_dev);
342 kfree(radio->buffer);
343 kfree(radio);
344}
345
346/* check if the device is present and register with v4l and usb if it is */
347static int usb_ma901radio_probe(struct usb_interface *intf,
348 const struct usb_device_id *id)
349{
350 struct ma901radio_device *radio;
351 int retval = 0;
352
353 radio = kzalloc(sizeof(struct ma901radio_device), GFP_KERNEL);
354 if (!radio) {
355 dev_err(&intf->dev, "kzalloc for ma901radio_device failed\n");
356 retval = -ENOMEM;
357 goto err;
358 }
359
360 radio->buffer = kmalloc(BUFFER_LENGTH, GFP_KERNEL);
361 if (!radio->buffer) {
362 dev_err(&intf->dev, "kmalloc for radio->buffer failed\n");
363 retval = -ENOMEM;
364 goto err_nobuf;
365 }
366
367 retval = v4l2_device_register(&intf->dev, &radio->v4l2_dev);
368 if (retval < 0) {
369 dev_err(&intf->dev, "couldn't register v4l2_device\n");
370 goto err_v4l2;
371 }
372
373 v4l2_ctrl_handler_init(&radio->hdl, 1);
374
375 /* TODO:It looks like this radio doesn't have mute/unmute control
376 * and windows program just emulate it using volume control.
377 * Let's plan to do the same in this driver.
378 *
379 * v4l2_ctrl_new_std(&radio->hdl, &usb_ma901radio_ctrl_ops,
380 * V4L2_CID_AUDIO_MUTE, 0, 1, 1, 1);
381 */
382
383 v4l2_ctrl_new_std(&radio->hdl, &usb_ma901radio_ctrl_ops,
384 V4L2_CID_AUDIO_VOLUME, MA901_VOLUME_MIN,
385 MA901_VOLUME_MAX, 1, MA901_VOLUME_MAX);
386
387 if (radio->hdl.error) {
388 retval = radio->hdl.error;
389 dev_err(&intf->dev, "couldn't register control\n");
390 goto err_ctrl;
391 }
392 mutex_init(&radio->lock);
393
394 radio->v4l2_dev.ctrl_handler = &radio->hdl;
395 radio->v4l2_dev.release = usb_ma901radio_release;
396 strlcpy(radio->vdev.name, radio->v4l2_dev.name,
397 sizeof(radio->vdev.name));
398 radio->vdev.v4l2_dev = &radio->v4l2_dev;
399 radio->vdev.fops = &usb_ma901radio_fops;
400 radio->vdev.ioctl_ops = &usb_ma901radio_ioctl_ops;
401 radio->vdev.release = video_device_release_empty;
402 radio->vdev.lock = &radio->lock;
403 set_bit(V4L2_FL_USE_FH_PRIO, &radio->vdev.flags);
404
405 radio->usbdev = interface_to_usbdev(intf);
406 radio->intf = intf;
407 usb_set_intfdata(intf, &radio->v4l2_dev);
408 radio->curfreq = 95.21 * FREQ_MUL;
409
410 video_set_drvdata(&radio->vdev, radio);
411
412 /* TODO: we can get some statistics (freq, volume) from device
413 * but it's not implemented yet. After insertion in usb-port radio
414 * setups frequency and starts playing without any initialization.
415 * So we don't call usb_ma901radio_init/get_stat() here.
416 * retval = usb_ma901radio_init(radio);
417 */
418
419 retval = video_register_device(&radio->vdev, VFL_TYPE_RADIO,
420 radio_nr);
421 if (retval < 0) {
422 dev_err(&intf->dev, "could not register video device\n");
423 goto err_vdev;
424 }
425
426 return 0;
427
428err_vdev:
429 v4l2_ctrl_handler_free(&radio->hdl);
430err_ctrl:
431 v4l2_device_unregister(&radio->v4l2_dev);
432err_v4l2:
433 kfree(radio->buffer);
434err_nobuf:
435 kfree(radio);
436err:
437 return retval;
438}
439
440/* USB Device ID List */
441static struct usb_device_id usb_ma901radio_device_table[] = {
442 { USB_DEVICE_AND_INTERFACE_INFO(USB_MA901_VENDOR, USB_MA901_PRODUCT,
443 USB_CLASS_HID, 0, 0) },
444 { } /* Terminating entry */
445};
446
447MODULE_DEVICE_TABLE(usb, usb_ma901radio_device_table);
448
449/* USB subsystem interface */
450static struct usb_driver usb_ma901radio_driver = {
451 .name = MA901_DRIVER_NAME,
452 .probe = usb_ma901radio_probe,
453 .disconnect = usb_ma901radio_disconnect,
454 .suspend = usb_ma901radio_suspend,
455 .resume = usb_ma901radio_resume,
456 .reset_resume = usb_ma901radio_resume,
457 .id_table = usb_ma901radio_device_table,
458};
459
460module_usb_driver(usb_ma901radio_driver);
diff --git a/drivers/media/radio/radio-miropcm20.c b/drivers/media/radio/radio-miropcm20.c
index 11f76ed4c6fb..3d0ff4404d12 100644
--- a/drivers/media/radio/radio-miropcm20.c
+++ b/drivers/media/radio/radio-miropcm20.c
@@ -17,49 +17,36 @@
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-ctrls.h>
21#include <media/v4l2-fh.h>
22#include <media/v4l2-event.h>
20#include <sound/aci.h> 23#include <sound/aci.h>
21 24
22static int radio_nr = -1; 25static int radio_nr = -1;
23module_param(radio_nr, int, 0); 26module_param(radio_nr, int, 0);
24MODULE_PARM_DESC(radio_nr, "Set radio device number (/dev/radioX). Default: -1 (autodetect)"); 27MODULE_PARM_DESC(radio_nr, "Set radio device number (/dev/radioX). Default: -1 (autodetect)");
25 28
26static bool mono;
27module_param(mono, bool, 0);
28MODULE_PARM_DESC(mono, "Force tuner into mono mode.");
29
30struct pcm20 { 29struct pcm20 {
31 struct v4l2_device v4l2_dev; 30 struct v4l2_device v4l2_dev;
32 struct video_device vdev; 31 struct video_device vdev;
32 struct v4l2_ctrl_handler ctrl_handler;
33 unsigned long freq; 33 unsigned long freq;
34 int muted; 34 u32 audmode;
35 struct snd_miro_aci *aci; 35 struct snd_miro_aci *aci;
36 struct mutex lock; 36 struct mutex lock;
37}; 37};
38 38
39static struct pcm20 pcm20_card = { 39static struct pcm20 pcm20_card = {
40 .freq = 87*16000, 40 .freq = 87 * 16000,
41 .muted = 1, 41 .audmode = V4L2_TUNER_MODE_STEREO,
42}; 42};
43 43
44static int pcm20_mute(struct pcm20 *dev, unsigned char mute)
45{
46 dev->muted = mute;
47 return snd_aci_cmd(dev->aci, ACI_SET_TUNERMUTE, mute, -1);
48}
49
50static int pcm20_stereo(struct pcm20 *dev, unsigned char stereo)
51{
52 return snd_aci_cmd(dev->aci, ACI_SET_TUNERMONO, !stereo, -1);
53}
54
55static int pcm20_setfreq(struct pcm20 *dev, unsigned long freq) 44static int pcm20_setfreq(struct pcm20 *dev, unsigned long freq)
56{ 45{
57 unsigned char freql; 46 unsigned char freql;
58 unsigned char freqh; 47 unsigned char freqh;
59 struct snd_miro_aci *aci = dev->aci; 48 struct snd_miro_aci *aci = dev->aci;
60 49
61 dev->freq = freq;
62
63 freq /= 160; 50 freq /= 160;
64 if (!(aci->aci_version == 0x07 || aci->aci_version >= 0xb0)) 51 if (!(aci->aci_version == 0x07 || aci->aci_version >= 0xb0))
65 freq /= 10; /* I don't know exactly which version 52 freq /= 10; /* I don't know exactly which version
@@ -67,46 +54,66 @@ static int pcm20_setfreq(struct pcm20 *dev, unsigned long freq)
67 freql = freq & 0xff; 54 freql = freq & 0xff;
68 freqh = freq >> 8; 55 freqh = freq >> 8;
69 56
70 pcm20_stereo(dev, !mono);
71 return snd_aci_cmd(aci, ACI_WRITE_TUNE, freql, freqh); 57 return snd_aci_cmd(aci, ACI_WRITE_TUNE, freql, freqh);
72} 58}
73 59
74static const struct v4l2_file_operations pcm20_fops = { 60static const struct v4l2_file_operations pcm20_fops = {
75 .owner = THIS_MODULE, 61 .owner = THIS_MODULE,
62 .open = v4l2_fh_open,
63 .poll = v4l2_ctrl_poll,
64 .release = v4l2_fh_release,
76 .unlocked_ioctl = video_ioctl2, 65 .unlocked_ioctl = video_ioctl2,
77}; 66};
78 67
79static int vidioc_querycap(struct file *file, void *priv, 68static int vidioc_querycap(struct file *file, void *priv,
80 struct v4l2_capability *v) 69 struct v4l2_capability *v)
81{ 70{
71 struct pcm20 *dev = video_drvdata(file);
72
82 strlcpy(v->driver, "Miro PCM20", sizeof(v->driver)); 73 strlcpy(v->driver, "Miro PCM20", sizeof(v->driver));
83 strlcpy(v->card, "Miro PCM20", sizeof(v->card)); 74 strlcpy(v->card, "Miro PCM20", sizeof(v->card));
84 strlcpy(v->bus_info, "ISA", sizeof(v->bus_info)); 75 snprintf(v->bus_info, sizeof(v->bus_info), "ISA:%s", dev->v4l2_dev.name);
85 v->version = 0x1; 76 v->device_caps = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
86 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO; 77 v->capabilities = v->device_caps | V4L2_CAP_DEVICE_CAPS;
87 return 0; 78 return 0;
88} 79}
89 80
90static int vidioc_g_tuner(struct file *file, void *priv, 81static int vidioc_g_tuner(struct file *file, void *priv,
91 struct v4l2_tuner *v) 82 struct v4l2_tuner *v)
92{ 83{
93 if (v->index) /* Only 1 tuner */ 84 struct pcm20 *dev = video_drvdata(file);
85 int res;
86
87 if (v->index)
94 return -EINVAL; 88 return -EINVAL;
95 strlcpy(v->name, "FM", sizeof(v->name)); 89 strlcpy(v->name, "FM", sizeof(v->name));
96 v->type = V4L2_TUNER_RADIO; 90 v->type = V4L2_TUNER_RADIO;
97 v->rangelow = 87*16000; 91 v->rangelow = 87*16000;
98 v->rangehigh = 108*16000; 92 v->rangehigh = 108*16000;
99 v->signal = 0xffff; 93 res = snd_aci_cmd(dev->aci, ACI_READ_TUNERSTATION, -1, -1);
100 v->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO; 94 v->signal = (res & 0x80) ? 0 : 0xffff;
101 v->capability = V4L2_TUNER_CAP_LOW; 95 /* Note: stereo detection does not work if the audio is muted,
102 v->audmode = V4L2_TUNER_MODE_MONO; 96 it will default to mono in that case. */
97 res = snd_aci_cmd(dev->aci, ACI_READ_TUNERSTEREO, -1, -1);
98 v->rxsubchans = (res & 0x40) ? V4L2_TUNER_SUB_MONO :
99 V4L2_TUNER_SUB_STEREO;
100 v->capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO;
101 v->audmode = dev->audmode;
103 return 0; 102 return 0;
104} 103}
105 104
106static int vidioc_s_tuner(struct file *file, void *priv, 105static int vidioc_s_tuner(struct file *file, void *priv,
107 struct v4l2_tuner *v) 106 struct v4l2_tuner *v)
108{ 107{
109 return v->index ? -EINVAL : 0; 108 struct pcm20 *dev = video_drvdata(file);
109
110 if (v->index)
111 return -EINVAL;
112 if (v->audmode > V4L2_TUNER_MODE_STEREO)
113 v->audmode = V4L2_TUNER_MODE_STEREO;
114 snd_aci_cmd(dev->aci, ACI_SET_TUNERMONO,
115 v->audmode == V4L2_TUNER_MODE_MONO, -1);
116 return 0;
110} 117}
111 118
112static int vidioc_g_frequency(struct file *file, void *priv, 119static int vidioc_g_frequency(struct file *file, void *priv,
@@ -131,75 +138,21 @@ static int vidioc_s_frequency(struct file *file, void *priv,
131 if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO) 138 if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
132 return -EINVAL; 139 return -EINVAL;
133 140
134 dev->freq = f->frequency; 141 dev->freq = clamp(f->frequency, 87 * 16000U, 108 * 16000U);
135 pcm20_setfreq(dev, f->frequency); 142 pcm20_setfreq(dev, dev->freq);
136 return 0;
137}
138
139static int vidioc_queryctrl(struct file *file, void *priv,
140 struct v4l2_queryctrl *qc)
141{
142 switch (qc->id) {
143 case V4L2_CID_AUDIO_MUTE:
144 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
145 }
146 return -EINVAL;
147}
148
149static int vidioc_g_ctrl(struct file *file, void *priv,
150 struct v4l2_control *ctrl)
151{
152 struct pcm20 *dev = video_drvdata(file);
153
154 switch (ctrl->id) {
155 case V4L2_CID_AUDIO_MUTE:
156 ctrl->value = dev->muted;
157 break;
158 default:
159 return -EINVAL;
160 }
161 return 0; 143 return 0;
162} 144}
163 145
164static int vidioc_s_ctrl(struct file *file, void *priv, 146static int pcm20_s_ctrl(struct v4l2_ctrl *ctrl)
165 struct v4l2_control *ctrl)
166{ 147{
167 struct pcm20 *dev = video_drvdata(file); 148 struct pcm20 *dev = container_of(ctrl->handler, struct pcm20, ctrl_handler);
168 149
169 switch (ctrl->id) { 150 switch (ctrl->id) {
170 case V4L2_CID_AUDIO_MUTE: 151 case V4L2_CID_AUDIO_MUTE:
171 pcm20_mute(dev, ctrl->value); 152 snd_aci_cmd(dev->aci, ACI_SET_TUNERMUTE, ctrl->val, -1);
172 break; 153 return 0;
173 default:
174 return -EINVAL;
175 } 154 }
176 return 0; 155 return -EINVAL;
177}
178
179static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
180{
181 *i = 0;
182 return 0;
183}
184
185static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
186{
187 return i ? -EINVAL : 0;
188}
189
190static int vidioc_g_audio(struct file *file, void *priv,
191 struct v4l2_audio *a)
192{
193 a->index = 0;
194 strlcpy(a->name, "Radio", sizeof(a->name));
195 a->capability = V4L2_AUDCAP_STEREO;
196 return 0;
197}
198
199static int vidioc_s_audio(struct file *file, void *priv,
200 const struct v4l2_audio *a)
201{
202 return a->index ? -EINVAL : 0;
203} 156}
204 157
205static const struct v4l2_ioctl_ops pcm20_ioctl_ops = { 158static const struct v4l2_ioctl_ops pcm20_ioctl_ops = {
@@ -208,19 +161,20 @@ static const struct v4l2_ioctl_ops pcm20_ioctl_ops = {
208 .vidioc_s_tuner = vidioc_s_tuner, 161 .vidioc_s_tuner = vidioc_s_tuner,
209 .vidioc_g_frequency = vidioc_g_frequency, 162 .vidioc_g_frequency = vidioc_g_frequency,
210 .vidioc_s_frequency = vidioc_s_frequency, 163 .vidioc_s_frequency = vidioc_s_frequency,
211 .vidioc_queryctrl = vidioc_queryctrl, 164 .vidioc_log_status = v4l2_ctrl_log_status,
212 .vidioc_g_ctrl = vidioc_g_ctrl, 165 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
213 .vidioc_s_ctrl = vidioc_s_ctrl, 166 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
214 .vidioc_g_audio = vidioc_g_audio, 167};
215 .vidioc_s_audio = vidioc_s_audio, 168
216 .vidioc_g_input = vidioc_g_input, 169static const struct v4l2_ctrl_ops pcm20_ctrl_ops = {
217 .vidioc_s_input = vidioc_s_input, 170 .s_ctrl = pcm20_s_ctrl,
218}; 171};
219 172
220static int __init pcm20_init(void) 173static int __init pcm20_init(void)
221{ 174{
222 struct pcm20 *dev = &pcm20_card; 175 struct pcm20 *dev = &pcm20_card;
223 struct v4l2_device *v4l2_dev = &dev->v4l2_dev; 176 struct v4l2_device *v4l2_dev = &dev->v4l2_dev;
177 struct v4l2_ctrl_handler *hdl;
224 int res; 178 int res;
225 179
226 dev->aci = snd_aci_get_aci(); 180 dev->aci = snd_aci_get_aci();
@@ -229,7 +183,7 @@ static int __init pcm20_init(void)
229 "you must load the snd-miro driver first!\n"); 183 "you must load the snd-miro driver first!\n");
230 return -ENODEV; 184 return -ENODEV;
231 } 185 }
232 strlcpy(v4l2_dev->name, "miropcm20", sizeof(v4l2_dev->name)); 186 strlcpy(v4l2_dev->name, "radio-miropcm20", sizeof(v4l2_dev->name));
233 mutex_init(&dev->lock); 187 mutex_init(&dev->lock);
234 188
235 res = v4l2_device_register(NULL, v4l2_dev); 189 res = v4l2_device_register(NULL, v4l2_dev);
@@ -238,20 +192,35 @@ static int __init pcm20_init(void)
238 return -EINVAL; 192 return -EINVAL;
239 } 193 }
240 194
195 hdl = &dev->ctrl_handler;
196 v4l2_ctrl_handler_init(hdl, 1);
197 v4l2_ctrl_new_std(hdl, &pcm20_ctrl_ops,
198 V4L2_CID_AUDIO_MUTE, 0, 1, 1, 1);
199 v4l2_dev->ctrl_handler = hdl;
200 if (hdl->error) {
201 res = hdl->error;
202 v4l2_err(v4l2_dev, "Could not register control\n");
203 goto err_hdl;
204 }
241 strlcpy(dev->vdev.name, v4l2_dev->name, sizeof(dev->vdev.name)); 205 strlcpy(dev->vdev.name, v4l2_dev->name, sizeof(dev->vdev.name));
242 dev->vdev.v4l2_dev = v4l2_dev; 206 dev->vdev.v4l2_dev = v4l2_dev;
243 dev->vdev.fops = &pcm20_fops; 207 dev->vdev.fops = &pcm20_fops;
244 dev->vdev.ioctl_ops = &pcm20_ioctl_ops; 208 dev->vdev.ioctl_ops = &pcm20_ioctl_ops;
245 dev->vdev.release = video_device_release_empty; 209 dev->vdev.release = video_device_release_empty;
246 dev->vdev.lock = &dev->lock; 210 dev->vdev.lock = &dev->lock;
211 set_bit(V4L2_FL_USE_FH_PRIO, &dev->vdev.flags);
247 video_set_drvdata(&dev->vdev, dev); 212 video_set_drvdata(&dev->vdev, dev);
213 snd_aci_cmd(dev->aci, ACI_SET_TUNERMONO,
214 dev->audmode == V4L2_TUNER_MODE_MONO, -1);
215 pcm20_setfreq(dev, dev->freq);
248 216
249 if (video_register_device(&dev->vdev, VFL_TYPE_RADIO, radio_nr) < 0) 217 if (video_register_device(&dev->vdev, VFL_TYPE_RADIO, radio_nr) < 0)
250 goto fail; 218 goto err_hdl;
251 219
252 v4l2_info(v4l2_dev, "Mirosound PCM20 Radio tuner\n"); 220 v4l2_info(v4l2_dev, "Mirosound PCM20 Radio tuner\n");
253 return 0; 221 return 0;
254fail: 222err_hdl:
223 v4l2_ctrl_handler_free(hdl);
255 v4l2_device_unregister(v4l2_dev); 224 v4l2_device_unregister(v4l2_dev);
256 return -EINVAL; 225 return -EINVAL;
257} 226}
@@ -265,6 +234,8 @@ static void __exit pcm20_cleanup(void)
265 struct pcm20 *dev = &pcm20_card; 234 struct pcm20 *dev = &pcm20_card;
266 235
267 video_unregister_device(&dev->vdev); 236 video_unregister_device(&dev->vdev);
237 snd_aci_cmd(dev->aci, ACI_SET_TUNERMUTE, 1, -1);
238 v4l2_ctrl_handler_free(&dev->ctrl_handler);
268 v4l2_device_unregister(&dev->v4l2_dev); 239 v4l2_device_unregister(&dev->v4l2_dev);
269} 240}
270 241
diff --git a/drivers/media/radio/radio-wl1273.c b/drivers/media/radio/radio-wl1273.c
index cabbe3adf435..02151e0e6e63 100644
--- a/drivers/media/radio/radio-wl1273.c
+++ b/drivers/media/radio/radio-wl1273.c
@@ -2085,8 +2085,7 @@ static int wl1273_fm_radio_probe(struct platform_device *pdev)
2085 } 2085 }
2086 2086
2087 /* V4L2 configuration */ 2087 /* V4L2 configuration */
2088 memcpy(&radio->videodev, &wl1273_viddev_template, 2088 radio->videodev = wl1273_viddev_template;
2089 sizeof(wl1273_viddev_template));
2090 2089
2091 radio->videodev.v4l2_dev = &radio->v4l2dev; 2090 radio->videodev.v4l2_dev = &radio->v4l2dev;
2092 2091
diff --git a/drivers/media/radio/si470x/radio-si470x.h b/drivers/media/radio/si470x/radio-si470x.h
index 2f089b4252df..467e95575488 100644
--- a/drivers/media/radio/si470x/radio-si470x.h
+++ b/drivers/media/radio/si470x/radio-si470x.h
@@ -163,7 +163,7 @@ struct si470x_device {
163 struct completion completion; 163 struct completion completion;
164 bool status_rssi_auto_update; /* Does RSSI get updated automatic? */ 164 bool status_rssi_auto_update; /* Does RSSI get updated automatic? */
165 165
166#if defined(CONFIG_USB_SI470X) || defined(CONFIG_USB_SI470X_MODULE) 166#if IS_ENABLED(CONFIG_USB_SI470X)
167 /* reference to USB and video device */ 167 /* reference to USB and video device */
168 struct usb_device *usbdev; 168 struct usb_device *usbdev;
169 struct usb_interface *intf; 169 struct usb_interface *intf;
@@ -179,7 +179,7 @@ struct si470x_device {
179 unsigned char hardware_version; 179 unsigned char hardware_version;
180#endif 180#endif
181 181
182#if defined(CONFIG_I2C_SI470X) || defined(CONFIG_I2C_SI470X_MODULE) 182#if IS_ENABLED(CONFIG_I2C_SI470X)
183 struct i2c_client *client; 183 struct i2c_client *client;
184#endif 184#endif
185}; 185};
diff --git a/drivers/media/radio/wl128x/fmdrv_common.c b/drivers/media/radio/wl128x/fmdrv_common.c
index 602ef7ac8c24..a002234ed5de 100644
--- a/drivers/media/radio/wl128x/fmdrv_common.c
+++ b/drivers/media/radio/wl128x/fmdrv_common.c
@@ -1563,8 +1563,7 @@ int fmc_prepare(struct fmdev *fmdev)
1563 fmdev->irq_info.mask = FM_MAL_EVENT; 1563 fmdev->irq_info.mask = FM_MAL_EVENT;
1564 1564
1565 /* Region info */ 1565 /* Region info */
1566 memcpy(&fmdev->rx.region, &region_configs[default_radio_region], 1566 fmdev->rx.region = region_configs[default_radio_region];
1567 sizeof(struct region_info));
1568 1567
1569 fmdev->rx.mute_mode = FM_MUTE_OFF; 1568 fmdev->rx.mute_mode = FM_MUTE_OFF;
1570 fmdev->rx.rf_depend_mute = FM_RX_RF_DEPENDENT_MUTE_OFF; 1569 fmdev->rx.rf_depend_mute = FM_RX_RF_DEPENDENT_MUTE_OFF;
diff --git a/drivers/media/rc/ati_remote.c b/drivers/media/rc/ati_remote.c
index 2d6fb26a0170..4d6a63fe6c5e 100644
--- a/drivers/media/rc/ati_remote.c
+++ b/drivers/media/rc/ati_remote.c
@@ -872,11 +872,11 @@ static int ati_remote_probe(struct usb_interface *interface,
872 ati_remote = kzalloc(sizeof (struct ati_remote), GFP_KERNEL); 872 ati_remote = kzalloc(sizeof (struct ati_remote), GFP_KERNEL);
873 rc_dev = rc_allocate_device(); 873 rc_dev = rc_allocate_device();
874 if (!ati_remote || !rc_dev) 874 if (!ati_remote || !rc_dev)
875 goto fail1; 875 goto exit_free_dev_rdev;
876 876
877 /* Allocate URB buffers, URBs */ 877 /* Allocate URB buffers, URBs */
878 if (ati_remote_alloc_buffers(udev, ati_remote)) 878 if (ati_remote_alloc_buffers(udev, ati_remote))
879 goto fail2; 879 goto exit_free_buffers;
880 880
881 ati_remote->endpoint_in = endpoint_in; 881 ati_remote->endpoint_in = endpoint_in;
882 ati_remote->endpoint_out = endpoint_out; 882 ati_remote->endpoint_out = endpoint_out;
@@ -924,12 +924,12 @@ static int ati_remote_probe(struct usb_interface *interface,
924 /* Device Hardware Initialization - fills in ati_remote->idev from udev. */ 924 /* Device Hardware Initialization - fills in ati_remote->idev from udev. */
925 err = ati_remote_initialize(ati_remote); 925 err = ati_remote_initialize(ati_remote);
926 if (err) 926 if (err)
927 goto fail3; 927 goto exit_kill_urbs;
928 928
929 /* Set up and register rc device */ 929 /* Set up and register rc device */
930 err = rc_register_device(ati_remote->rdev); 930 err = rc_register_device(ati_remote->rdev);
931 if (err) 931 if (err)
932 goto fail3; 932 goto exit_kill_urbs;
933 933
934 /* use our delay for rc_dev */ 934 /* use our delay for rc_dev */
935 ati_remote->rdev->input_dev->rep[REP_DELAY] = repeat_delay; 935 ati_remote->rdev->input_dev->rep[REP_DELAY] = repeat_delay;
@@ -939,7 +939,7 @@ static int ati_remote_probe(struct usb_interface *interface,
939 input_dev = input_allocate_device(); 939 input_dev = input_allocate_device();
940 if (!input_dev) { 940 if (!input_dev) {
941 err = -ENOMEM; 941 err = -ENOMEM;
942 goto fail4; 942 goto exit_unregister_device;
943 } 943 }
944 944
945 ati_remote->idev = input_dev; 945 ati_remote->idev = input_dev;
@@ -947,19 +947,24 @@ static int ati_remote_probe(struct usb_interface *interface,
947 err = input_register_device(input_dev); 947 err = input_register_device(input_dev);
948 948
949 if (err) 949 if (err)
950 goto fail5; 950 goto exit_free_input_device;
951 } 951 }
952 952
953 usb_set_intfdata(interface, ati_remote); 953 usb_set_intfdata(interface, ati_remote);
954 return 0; 954 return 0;
955 955
956 fail5: input_free_device(input_dev); 956 exit_free_input_device:
957 fail4: rc_unregister_device(rc_dev); 957 input_free_device(input_dev);
958 exit_unregister_device:
959 rc_unregister_device(rc_dev);
958 rc_dev = NULL; 960 rc_dev = NULL;
959 fail3: usb_kill_urb(ati_remote->irq_urb); 961 exit_kill_urbs:
962 usb_kill_urb(ati_remote->irq_urb);
960 usb_kill_urb(ati_remote->out_urb); 963 usb_kill_urb(ati_remote->out_urb);
961 fail2: ati_remote_free_buffers(ati_remote); 964 exit_free_buffers:
962 fail1: rc_free_device(rc_dev); 965 ati_remote_free_buffers(ati_remote);
966 exit_free_dev_rdev:
967 rc_free_device(rc_dev);
963 kfree(ati_remote); 968 kfree(ati_remote);
964 return err; 969 return err;
965} 970}
diff --git a/drivers/media/rc/ene_ir.c b/drivers/media/rc/ene_ir.c
index cef04786b52f..ee6c984cade2 100644
--- a/drivers/media/rc/ene_ir.c
+++ b/drivers/media/rc/ene_ir.c
@@ -1003,7 +1003,7 @@ static int ene_probe(struct pnp_dev *pnp_dev, const struct pnp_device_id *id)
1003 dev = kzalloc(sizeof(struct ene_device), GFP_KERNEL); 1003 dev = kzalloc(sizeof(struct ene_device), GFP_KERNEL);
1004 rdev = rc_allocate_device(); 1004 rdev = rc_allocate_device();
1005 if (!dev || !rdev) 1005 if (!dev || !rdev)
1006 goto failure; 1006 goto exit_free_dev_rdev;
1007 1007
1008 /* validate resources */ 1008 /* validate resources */
1009 error = -ENODEV; 1009 error = -ENODEV;
@@ -1014,10 +1014,10 @@ static int ene_probe(struct pnp_dev *pnp_dev, const struct pnp_device_id *id)
1014 1014
1015 if (!pnp_port_valid(pnp_dev, 0) || 1015 if (!pnp_port_valid(pnp_dev, 0) ||
1016 pnp_port_len(pnp_dev, 0) < ENE_IO_SIZE) 1016 pnp_port_len(pnp_dev, 0) < ENE_IO_SIZE)
1017 goto failure; 1017 goto exit_free_dev_rdev;
1018 1018
1019 if (!pnp_irq_valid(pnp_dev, 0)) 1019 if (!pnp_irq_valid(pnp_dev, 0))
1020 goto failure; 1020 goto exit_free_dev_rdev;
1021 1021
1022 spin_lock_init(&dev->hw_lock); 1022 spin_lock_init(&dev->hw_lock);
1023 1023
@@ -1033,7 +1033,7 @@ static int ene_probe(struct pnp_dev *pnp_dev, const struct pnp_device_id *id)
1033 /* detect hardware version and features */ 1033 /* detect hardware version and features */
1034 error = ene_hw_detect(dev); 1034 error = ene_hw_detect(dev);
1035 if (error) 1035 if (error)
1036 goto failure; 1036 goto exit_free_dev_rdev;
1037 1037
1038 if (!dev->hw_learning_and_tx_capable && txsim) { 1038 if (!dev->hw_learning_and_tx_capable && txsim) {
1039 dev->hw_learning_and_tx_capable = true; 1039 dev->hw_learning_and_tx_capable = true;
@@ -1075,30 +1075,30 @@ static int ene_probe(struct pnp_dev *pnp_dev, const struct pnp_device_id *id)
1075 device_set_wakeup_capable(&pnp_dev->dev, true); 1075 device_set_wakeup_capable(&pnp_dev->dev, true);
1076 device_set_wakeup_enable(&pnp_dev->dev, true); 1076 device_set_wakeup_enable(&pnp_dev->dev, true);
1077 1077
1078 error = rc_register_device(rdev);
1079 if (error < 0)
1080 goto exit_free_dev_rdev;
1081
1078 /* claim the resources */ 1082 /* claim the resources */
1079 error = -EBUSY; 1083 error = -EBUSY;
1080 if (!request_region(dev->hw_io, ENE_IO_SIZE, ENE_DRIVER_NAME)) { 1084 if (!request_region(dev->hw_io, ENE_IO_SIZE, ENE_DRIVER_NAME)) {
1081 goto failure; 1085 goto exit_unregister_device;
1082 } 1086 }
1083 1087
1084 dev->irq = pnp_irq(pnp_dev, 0); 1088 dev->irq = pnp_irq(pnp_dev, 0);
1085 if (request_irq(dev->irq, ene_isr, 1089 if (request_irq(dev->irq, ene_isr,
1086 IRQF_SHARED, ENE_DRIVER_NAME, (void *)dev)) { 1090 IRQF_SHARED, ENE_DRIVER_NAME, (void *)dev)) {
1087 goto failure2; 1091 goto exit_release_hw_io;
1088 } 1092 }
1089 1093
1090 error = rc_register_device(rdev);
1091 if (error < 0)
1092 goto failure3;
1093
1094 pr_notice("driver has been successfully loaded\n"); 1094 pr_notice("driver has been successfully loaded\n");
1095 return 0; 1095 return 0;
1096 1096
1097failure3: 1097exit_release_hw_io:
1098 free_irq(dev->irq, dev);
1099failure2:
1100 release_region(dev->hw_io, ENE_IO_SIZE); 1098 release_region(dev->hw_io, ENE_IO_SIZE);
1101failure: 1099exit_unregister_device:
1100 rc_unregister_device(rdev);
1101exit_free_dev_rdev:
1102 rc_free_device(rdev); 1102 rc_free_device(rdev);
1103 kfree(dev); 1103 kfree(dev);
1104 return error; 1104 return error;
diff --git a/drivers/media/rc/fintek-cir.c b/drivers/media/rc/fintek-cir.c
index 1df410e13688..d6fa441655d2 100644
--- a/drivers/media/rc/fintek-cir.c
+++ b/drivers/media/rc/fintek-cir.c
@@ -500,18 +500,18 @@ static int fintek_probe(struct pnp_dev *pdev, const struct pnp_device_id *dev_id
500 /* input device for IR remote (and tx) */ 500 /* input device for IR remote (and tx) */
501 rdev = rc_allocate_device(); 501 rdev = rc_allocate_device();
502 if (!rdev) 502 if (!rdev)
503 goto failure; 503 goto exit_free_dev_rdev;
504 504
505 ret = -ENODEV; 505 ret = -ENODEV;
506 /* validate pnp resources */ 506 /* validate pnp resources */
507 if (!pnp_port_valid(pdev, 0)) { 507 if (!pnp_port_valid(pdev, 0)) {
508 dev_err(&pdev->dev, "IR PNP Port not valid!\n"); 508 dev_err(&pdev->dev, "IR PNP Port not valid!\n");
509 goto failure; 509 goto exit_free_dev_rdev;
510 } 510 }
511 511
512 if (!pnp_irq_valid(pdev, 0)) { 512 if (!pnp_irq_valid(pdev, 0)) {
513 dev_err(&pdev->dev, "IR PNP IRQ not valid!\n"); 513 dev_err(&pdev->dev, "IR PNP IRQ not valid!\n");
514 goto failure; 514 goto exit_free_dev_rdev;
515 } 515 }
516 516
517 fintek->cir_addr = pnp_port_start(pdev, 0); 517 fintek->cir_addr = pnp_port_start(pdev, 0);
@@ -528,7 +528,7 @@ static int fintek_probe(struct pnp_dev *pdev, const struct pnp_device_id *dev_id
528 528
529 ret = fintek_hw_detect(fintek); 529 ret = fintek_hw_detect(fintek);
530 if (ret) 530 if (ret)
531 goto failure; 531 goto exit_free_dev_rdev;
532 532
533 /* Initialize CIR & CIR Wake Logical Devices */ 533 /* Initialize CIR & CIR Wake Logical Devices */
534 fintek_config_mode_enable(fintek); 534 fintek_config_mode_enable(fintek);
@@ -557,33 +557,35 @@ static int fintek_probe(struct pnp_dev *pdev, const struct pnp_device_id *dev_id
557 /* rx resolution is hardwired to 50us atm, 1, 25, 100 also possible */ 557 /* rx resolution is hardwired to 50us atm, 1, 25, 100 also possible */
558 rdev->rx_resolution = US_TO_NS(CIR_SAMPLE_PERIOD); 558 rdev->rx_resolution = US_TO_NS(CIR_SAMPLE_PERIOD);
559 559
560 fintek->rdev = rdev;
561
560 ret = -EBUSY; 562 ret = -EBUSY;
561 /* now claim resources */ 563 /* now claim resources */
562 if (!request_region(fintek->cir_addr, 564 if (!request_region(fintek->cir_addr,
563 fintek->cir_port_len, FINTEK_DRIVER_NAME)) 565 fintek->cir_port_len, FINTEK_DRIVER_NAME))
564 goto failure; 566 goto exit_free_dev_rdev;
565 567
566 if (request_irq(fintek->cir_irq, fintek_cir_isr, IRQF_SHARED, 568 if (request_irq(fintek->cir_irq, fintek_cir_isr, IRQF_SHARED,
567 FINTEK_DRIVER_NAME, (void *)fintek)) 569 FINTEK_DRIVER_NAME, (void *)fintek))
568 goto failure2; 570 goto exit_free_cir_addr;
569 571
570 ret = rc_register_device(rdev); 572 ret = rc_register_device(rdev);
571 if (ret) 573 if (ret)
572 goto failure3; 574 goto exit_free_irq;
573 575
574 device_init_wakeup(&pdev->dev, true); 576 device_init_wakeup(&pdev->dev, true);
575 fintek->rdev = rdev; 577
576 fit_pr(KERN_NOTICE, "driver has been successfully loaded\n"); 578 fit_pr(KERN_NOTICE, "driver has been successfully loaded\n");
577 if (debug) 579 if (debug)
578 cir_dump_regs(fintek); 580 cir_dump_regs(fintek);
579 581
580 return 0; 582 return 0;
581 583
582failure3: 584exit_free_irq:
583 free_irq(fintek->cir_irq, fintek); 585 free_irq(fintek->cir_irq, fintek);
584failure2: 586exit_free_cir_addr:
585 release_region(fintek->cir_addr, fintek->cir_port_len); 587 release_region(fintek->cir_addr, fintek->cir_port_len);
586failure: 588exit_free_dev_rdev:
587 rc_free_device(rdev); 589 rc_free_device(rdev);
588 kfree(fintek); 590 kfree(fintek);
589 591
diff --git a/drivers/media/rc/gpio-ir-recv.c b/drivers/media/rc/gpio-ir-recv.c
index 4f71a7d1f019..8b82ae9bd686 100644
--- a/drivers/media/rc/gpio-ir-recv.c
+++ b/drivers/media/rc/gpio-ir-recv.c
@@ -16,6 +16,7 @@
16#include <linux/interrupt.h> 16#include <linux/interrupt.h>
17#include <linux/gpio.h> 17#include <linux/gpio.h>
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/of_gpio.h>
19#include <linux/platform_device.h> 20#include <linux/platform_device.h>
20#include <linux/irq.h> 21#include <linux/irq.h>
21#include <media/rc-core.h> 22#include <media/rc-core.h>
@@ -30,6 +31,45 @@ struct gpio_rc_dev {
30 bool active_low; 31 bool active_low;
31}; 32};
32 33
34#ifdef CONFIG_OF
35/*
36 * Translate OpenFirmware node properties into platform_data
37 */
38static int gpio_ir_recv_get_devtree_pdata(struct device *dev,
39 struct gpio_ir_recv_platform_data *pdata)
40{
41 struct device_node *np = dev->of_node;
42 enum of_gpio_flags flags;
43 int gpio;
44
45 gpio = of_get_gpio_flags(np, 0, &flags);
46 if (gpio < 0) {
47 if (gpio != -EPROBE_DEFER)
48 dev_err(dev, "Failed to get gpio flags (%d)\n", gpio);
49 return gpio;
50 }
51
52 pdata->gpio_nr = gpio;
53 pdata->active_low = (flags & OF_GPIO_ACTIVE_LOW);
54 /* probe() takes care of map_name == NULL or allowed_protos == 0 */
55 pdata->map_name = of_get_property(np, "linux,rc-map-name", NULL);
56 pdata->allowed_protos = 0;
57
58 return 0;
59}
60
61static struct of_device_id gpio_ir_recv_of_match[] = {
62 { .compatible = "gpio-ir-receiver", },
63 { },
64};
65MODULE_DEVICE_TABLE(of, gpio_ir_recv_of_match);
66
67#else /* !CONFIG_OF */
68
69#define gpio_ir_recv_get_devtree_pdata(dev, pdata) (-ENOSYS)
70
71#endif
72
33static irqreturn_t gpio_ir_recv_irq(int irq, void *dev_id) 73static irqreturn_t gpio_ir_recv_irq(int irq, void *dev_id)
34{ 74{
35 struct gpio_rc_dev *gpio_dev = dev_id; 75 struct gpio_rc_dev *gpio_dev = dev_id;
@@ -66,6 +106,17 @@ static int gpio_ir_recv_probe(struct platform_device *pdev)
66 pdev->dev.platform_data; 106 pdev->dev.platform_data;
67 int rc; 107 int rc;
68 108
109 if (pdev->dev.of_node) {
110 struct gpio_ir_recv_platform_data *dtpdata =
111 devm_kzalloc(&pdev->dev, sizeof(*dtpdata), GFP_KERNEL);
112 if (!dtpdata)
113 return -ENOMEM;
114 rc = gpio_ir_recv_get_devtree_pdata(&pdev->dev, dtpdata);
115 if (rc)
116 return rc;
117 pdata = dtpdata;
118 }
119
69 if (!pdata) 120 if (!pdata)
70 return -EINVAL; 121 return -EINVAL;
71 122
@@ -129,12 +180,12 @@ static int gpio_ir_recv_probe(struct platform_device *pdev)
129err_request_irq: 180err_request_irq:
130 platform_set_drvdata(pdev, NULL); 181 platform_set_drvdata(pdev, NULL);
131 rc_unregister_device(rcdev); 182 rc_unregister_device(rcdev);
183 rcdev = NULL;
132err_register_rc_device: 184err_register_rc_device:
133err_gpio_direction_input: 185err_gpio_direction_input:
134 gpio_free(pdata->gpio_nr); 186 gpio_free(pdata->gpio_nr);
135err_gpio_request: 187err_gpio_request:
136 rc_free_device(rcdev); 188 rc_free_device(rcdev);
137 rcdev = NULL;
138err_allocate_device: 189err_allocate_device:
139 kfree(gpio_dev); 190 kfree(gpio_dev);
140 return rc; 191 return rc;
@@ -148,7 +199,6 @@ static int gpio_ir_recv_remove(struct platform_device *pdev)
148 platform_set_drvdata(pdev, NULL); 199 platform_set_drvdata(pdev, NULL);
149 rc_unregister_device(gpio_dev->rcdev); 200 rc_unregister_device(gpio_dev->rcdev);
150 gpio_free(gpio_dev->gpio_nr); 201 gpio_free(gpio_dev->gpio_nr);
151 rc_free_device(gpio_dev->rcdev);
152 kfree(gpio_dev); 202 kfree(gpio_dev);
153 return 0; 203 return 0;
154} 204}
@@ -192,6 +242,7 @@ static struct platform_driver gpio_ir_recv_driver = {
192 .driver = { 242 .driver = {
193 .name = GPIO_IR_DRIVER_NAME, 243 .name = GPIO_IR_DRIVER_NAME,
194 .owner = THIS_MODULE, 244 .owner = THIS_MODULE,
245 .of_match_table = of_match_ptr(gpio_ir_recv_of_match),
195#ifdef CONFIG_PM 246#ifdef CONFIG_PM
196 .pm = &gpio_ir_recv_pm_ops, 247 .pm = &gpio_ir_recv_pm_ops,
197#endif 248#endif
diff --git a/drivers/media/rc/iguanair.c b/drivers/media/rc/iguanair.c
index b99b096d8a8f..a4ab2e6b3f82 100644
--- a/drivers/media/rc/iguanair.c
+++ b/drivers/media/rc/iguanair.c
@@ -58,6 +58,7 @@ struct iguanair {
58 char phys[64]; 58 char phys[64];
59}; 59};
60 60
61#define CMD_NOP 0x00
61#define CMD_GET_VERSION 0x01 62#define CMD_GET_VERSION 0x01
62#define CMD_GET_BUFSIZE 0x11 63#define CMD_GET_BUFSIZE 0x11
63#define CMD_GET_FEATURES 0x10 64#define CMD_GET_FEATURES 0x10
@@ -196,6 +197,10 @@ static void iguanair_irq_out(struct urb *urb)
196 197
197 if (urb->status) 198 if (urb->status)
198 dev_dbg(ir->dev, "Error: out urb status = %d\n", urb->status); 199 dev_dbg(ir->dev, "Error: out urb status = %d\n", urb->status);
200
201 /* if we sent an nop packet, do not expect a response */
202 if (urb->status == 0 && ir->packet->header.cmd == CMD_NOP)
203 complete(&ir->completion);
199} 204}
200 205
201static int iguanair_send(struct iguanair *ir, unsigned size) 206static int iguanair_send(struct iguanair *ir, unsigned size)
@@ -219,10 +224,17 @@ static int iguanair_get_features(struct iguanair *ir)
219{ 224{
220 int rc; 225 int rc;
221 226
227 /*
228 * On cold boot, the iguanair initializes on the first packet
229 * received but does not process that packet. Send an empty
230 * packet.
231 */
222 ir->packet->header.start = 0; 232 ir->packet->header.start = 0;
223 ir->packet->header.direction = DIR_OUT; 233 ir->packet->header.direction = DIR_OUT;
224 ir->packet->header.cmd = CMD_GET_VERSION; 234 ir->packet->header.cmd = CMD_NOP;
235 iguanair_send(ir, sizeof(ir->packet->header));
225 236
237 ir->packet->header.cmd = CMD_GET_VERSION;
226 rc = iguanair_send(ir, sizeof(ir->packet->header)); 238 rc = iguanair_send(ir, sizeof(ir->packet->header));
227 if (rc) { 239 if (rc) {
228 dev_info(ir->dev, "failed to get version\n"); 240 dev_info(ir->dev, "failed to get version\n");
@@ -255,19 +267,14 @@ static int iguanair_get_features(struct iguanair *ir)
255 ir->packet->header.cmd = CMD_GET_FEATURES; 267 ir->packet->header.cmd = CMD_GET_FEATURES;
256 268
257 rc = iguanair_send(ir, sizeof(ir->packet->header)); 269 rc = iguanair_send(ir, sizeof(ir->packet->header));
258 if (rc) { 270 if (rc)
259 dev_info(ir->dev, "failed to get features\n"); 271 dev_info(ir->dev, "failed to get features\n");
260 goto out;
261 }
262
263out: 272out:
264 return rc; 273 return rc;
265} 274}
266 275
267static int iguanair_receiver(struct iguanair *ir, bool enable) 276static int iguanair_receiver(struct iguanair *ir, bool enable)
268{ 277{
269 int rc;
270
271 ir->packet->header.start = 0; 278 ir->packet->header.start = 0;
272 ir->packet->header.direction = DIR_OUT; 279 ir->packet->header.direction = DIR_OUT;
273 ir->packet->header.cmd = enable ? CMD_RECEIVER_ON : CMD_RECEIVER_OFF; 280 ir->packet->header.cmd = enable ? CMD_RECEIVER_ON : CMD_RECEIVER_OFF;
@@ -275,9 +282,7 @@ static int iguanair_receiver(struct iguanair *ir, bool enable)
275 if (enable) 282 if (enable)
276 ir_raw_event_reset(ir->rc); 283 ir_raw_event_reset(ir->rc);
277 284
278 rc = iguanair_send(ir, sizeof(ir->packet->header)); 285 return iguanair_send(ir, sizeof(ir->packet->header));
279
280 return rc;
281} 286}
282 287
283/* 288/*
@@ -512,6 +517,7 @@ static int iguanair_probe(struct usb_interface *intf,
512 rc->rx_resolution = RX_RESOLUTION; 517 rc->rx_resolution = RX_RESOLUTION;
513 518
514 iguanair_set_tx_carrier(rc, 38000); 519 iguanair_set_tx_carrier(rc, 38000);
520 iguanair_set_tx_mask(rc, 0);
515 521
516 ret = rc_register_device(rc); 522 ret = rc_register_device(rc);
517 if (ret < 0) { 523 if (ret < 0) {
diff --git a/drivers/media/rc/imon.c b/drivers/media/rc/imon.c
index 78d109b978dd..dec203bb06f6 100644
--- a/drivers/media/rc/imon.c
+++ b/drivers/media/rc/imon.c
@@ -1221,7 +1221,7 @@ static u32 imon_panel_key_lookup(u64 code)
1221static bool imon_mouse_event(struct imon_context *ictx, 1221static bool imon_mouse_event(struct imon_context *ictx,
1222 unsigned char *buf, int len) 1222 unsigned char *buf, int len)
1223{ 1223{
1224 char rel_x = 0x00, rel_y = 0x00; 1224 signed char rel_x = 0x00, rel_y = 0x00;
1225 u8 right_shift = 1; 1225 u8 right_shift = 1;
1226 bool mouse_input = true; 1226 bool mouse_input = true;
1227 int dir = 0; 1227 int dir = 0;
@@ -1297,7 +1297,7 @@ static void imon_touch_event(struct imon_context *ictx, unsigned char *buf)
1297static void imon_pad_to_keys(struct imon_context *ictx, unsigned char *buf) 1297static void imon_pad_to_keys(struct imon_context *ictx, unsigned char *buf)
1298{ 1298{
1299 int dir = 0; 1299 int dir = 0;
1300 char rel_x = 0x00, rel_y = 0x00; 1300 signed char rel_x = 0x00, rel_y = 0x00;
1301 u16 timeout, threshold; 1301 u16 timeout, threshold;
1302 u32 scancode = KEY_RESERVED; 1302 u32 scancode = KEY_RESERVED;
1303 unsigned long flags; 1303 unsigned long flags;
diff --git a/drivers/media/rc/ir-raw.c b/drivers/media/rc/ir-raw.c
index 97dc8d13b06b..17c94be9f24c 100644
--- a/drivers/media/rc/ir-raw.c
+++ b/drivers/media/rc/ir-raw.c
@@ -31,11 +31,6 @@ static DEFINE_MUTEX(ir_raw_handler_lock);
31static LIST_HEAD(ir_raw_handler_list); 31static LIST_HEAD(ir_raw_handler_list);
32static u64 available_protocols; 32static u64 available_protocols;
33 33
34#ifdef MODULE
35/* Used to load the decoders */
36static struct work_struct wq_load;
37#endif
38
39static int ir_raw_event_thread(void *data) 34static int ir_raw_event_thread(void *data)
40{ 35{
41 struct ir_raw_event ev; 36 struct ir_raw_event ev;
@@ -347,8 +342,7 @@ void ir_raw_handler_unregister(struct ir_raw_handler *ir_raw_handler)
347} 342}
348EXPORT_SYMBOL(ir_raw_handler_unregister); 343EXPORT_SYMBOL(ir_raw_handler_unregister);
349 344
350#ifdef MODULE 345void ir_raw_init(void)
351static void init_decoders(struct work_struct *work)
352{ 346{
353 /* Load the decoder modules */ 347 /* Load the decoder modules */
354 348
@@ -365,12 +359,3 @@ static void init_decoders(struct work_struct *work)
365 it is needed to change the CONFIG_MODULE test at rc-core.h 359 it is needed to change the CONFIG_MODULE test at rc-core.h
366 */ 360 */
367} 361}
368#endif
369
370void ir_raw_init(void)
371{
372#ifdef MODULE
373 INIT_WORK(&wq_load, init_decoders);
374 schedule_work(&wq_load);
375#endif
376}
diff --git a/drivers/media/rc/ite-cir.c b/drivers/media/rc/ite-cir.c
index 1b8669b6d042..dd8237324c09 100644
--- a/drivers/media/rc/ite-cir.c
+++ b/drivers/media/rc/ite-cir.c
@@ -1472,7 +1472,7 @@ static int ite_probe(struct pnp_dev *pdev, const struct pnp_device_id
1472 /* input device for IR remote (and tx) */ 1472 /* input device for IR remote (and tx) */
1473 rdev = rc_allocate_device(); 1473 rdev = rc_allocate_device();
1474 if (!rdev) 1474 if (!rdev)
1475 goto failure; 1475 goto exit_free_dev_rdev;
1476 itdev->rdev = rdev; 1476 itdev->rdev = rdev;
1477 1477
1478 ret = -ENODEV; 1478 ret = -ENODEV;
@@ -1498,12 +1498,12 @@ static int ite_probe(struct pnp_dev *pdev, const struct pnp_device_id
1498 if (!pnp_port_valid(pdev, io_rsrc_no) || 1498 if (!pnp_port_valid(pdev, io_rsrc_no) ||
1499 pnp_port_len(pdev, io_rsrc_no) != dev_desc->io_region_size) { 1499 pnp_port_len(pdev, io_rsrc_no) != dev_desc->io_region_size) {
1500 dev_err(&pdev->dev, "IR PNP Port not valid!\n"); 1500 dev_err(&pdev->dev, "IR PNP Port not valid!\n");
1501 goto failure; 1501 goto exit_free_dev_rdev;
1502 } 1502 }
1503 1503
1504 if (!pnp_irq_valid(pdev, 0)) { 1504 if (!pnp_irq_valid(pdev, 0)) {
1505 dev_err(&pdev->dev, "PNP IRQ not valid!\n"); 1505 dev_err(&pdev->dev, "PNP IRQ not valid!\n");
1506 goto failure; 1506 goto exit_free_dev_rdev;
1507 } 1507 }
1508 1508
1509 /* store resource values */ 1509 /* store resource values */
@@ -1591,29 +1591,29 @@ static int ite_probe(struct pnp_dev *pdev, const struct pnp_device_id
1591 rdev->driver_name = ITE_DRIVER_NAME; 1591 rdev->driver_name = ITE_DRIVER_NAME;
1592 rdev->map_name = RC_MAP_RC6_MCE; 1592 rdev->map_name = RC_MAP_RC6_MCE;
1593 1593
1594 ret = rc_register_device(rdev);
1595 if (ret)
1596 goto exit_free_dev_rdev;
1597
1594 ret = -EBUSY; 1598 ret = -EBUSY;
1595 /* now claim resources */ 1599 /* now claim resources */
1596 if (!request_region(itdev->cir_addr, 1600 if (!request_region(itdev->cir_addr,
1597 dev_desc->io_region_size, ITE_DRIVER_NAME)) 1601 dev_desc->io_region_size, ITE_DRIVER_NAME))
1598 goto failure; 1602 goto exit_unregister_device;
1599 1603
1600 if (request_irq(itdev->cir_irq, ite_cir_isr, IRQF_SHARED, 1604 if (request_irq(itdev->cir_irq, ite_cir_isr, IRQF_SHARED,
1601 ITE_DRIVER_NAME, (void *)itdev)) 1605 ITE_DRIVER_NAME, (void *)itdev))
1602 goto failure2; 1606 goto exit_release_cir_addr;
1603
1604 ret = rc_register_device(rdev);
1605 if (ret)
1606 goto failure3;
1607 1607
1608 ite_pr(KERN_NOTICE, "driver has been successfully loaded\n"); 1608 ite_pr(KERN_NOTICE, "driver has been successfully loaded\n");
1609 1609
1610 return 0; 1610 return 0;
1611 1611
1612failure3: 1612exit_release_cir_addr:
1613 free_irq(itdev->cir_irq, itdev);
1614failure2:
1615 release_region(itdev->cir_addr, itdev->params.io_region_size); 1613 release_region(itdev->cir_addr, itdev->params.io_region_size);
1616failure: 1614exit_unregister_device:
1615 rc_unregister_device(rdev);
1616exit_free_dev_rdev:
1617 rc_free_device(rdev); 1617 rc_free_device(rdev);
1618 kfree(itdev); 1618 kfree(itdev);
1619 1619
diff --git a/drivers/media/rc/keymaps/Makefile b/drivers/media/rc/keymaps/Makefile
index ab84d66c67c1..778661971aed 100644
--- a/drivers/media/rc/keymaps/Makefile
+++ b/drivers/media/rc/keymaps/Makefile
@@ -88,6 +88,7 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \
88 rc-tevii-nec.o \ 88 rc-tevii-nec.o \
89 rc-tivo.o \ 89 rc-tivo.o \
90 rc-total-media-in-hand.o \ 90 rc-total-media-in-hand.o \
91 rc-total-media-in-hand-02.o \
91 rc-trekstor.o \ 92 rc-trekstor.o \
92 rc-tt-1500.o \ 93 rc-tt-1500.o \
93 rc-twinhan1027.o \ 94 rc-twinhan1027.o \
diff --git a/drivers/media/rc/keymaps/rc-total-media-in-hand-02.c b/drivers/media/rc/keymaps/rc-total-media-in-hand-02.c
new file mode 100644
index 000000000000..47270f72ebf0
--- /dev/null
+++ b/drivers/media/rc/keymaps/rc-total-media-in-hand-02.c
@@ -0,0 +1,86 @@
1/*
2 * Total Media In Hand_02 remote controller keytable for Mygica X8507
3 *
4 * Copyright (C) 2012 Alfredo J. Delaiti <alfredodelaiti@netscape.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21#include <media/rc-map.h>
22#include <linux/module.h>
23
24
25static struct rc_map_table total_media_in_hand_02[] = {
26 { 0x0000, KEY_0 },
27 { 0x0001, KEY_1 },
28 { 0x0002, KEY_2 },
29 { 0x0003, KEY_3 },
30 { 0x0004, KEY_4 },
31 { 0x0005, KEY_5 },
32 { 0x0006, KEY_6 },
33 { 0x0007, KEY_7 },
34 { 0x0008, KEY_8 },
35 { 0x0009, KEY_9 },
36 { 0x000a, KEY_MUTE },
37 { 0x000b, KEY_STOP }, /* Stop */
38 { 0x000c, KEY_POWER2 }, /* Turn on/off application */
39 { 0x000d, KEY_OK }, /* OK */
40 { 0x000e, KEY_CAMERA }, /* Snapshot */
41 { 0x000f, KEY_ZOOM }, /* Full Screen/Restore */
42 { 0x0010, KEY_RIGHT }, /* Right arrow */
43 { 0x0011, KEY_LEFT }, /* Left arrow */
44 { 0x0012, KEY_CHANNELUP },
45 { 0x0013, KEY_CHANNELDOWN },
46 { 0x0014, KEY_SHUFFLE },
47 { 0x0016, KEY_PAUSE },
48 { 0x0017, KEY_PLAY }, /* Play */
49 { 0x001e, KEY_TIME }, /* Time Shift */
50 { 0x001f, KEY_RECORD },
51 { 0x0020, KEY_UP },
52 { 0x0021, KEY_DOWN },
53 { 0x0025, KEY_POWER }, /* Turn off computer */
54 { 0x0026, KEY_REWIND }, /* FR << */
55 { 0x0027, KEY_FASTFORWARD }, /* FF >> */
56 { 0x0029, KEY_ESC },
57 { 0x002b, KEY_VOLUMEUP },
58 { 0x002c, KEY_VOLUMEDOWN },
59 { 0x002d, KEY_CHANNEL }, /* CH Surfing */
60 { 0x0038, KEY_VIDEO }, /* TV/AV/S-Video/YPbPr */
61};
62
63static struct rc_map_list total_media_in_hand_02_map = {
64 .map = {
65 .scan = total_media_in_hand_02,
66 .size = ARRAY_SIZE(total_media_in_hand_02),
67 .rc_type = RC_TYPE_RC5,
68 .name = RC_MAP_TOTAL_MEDIA_IN_HAND_02,
69 }
70};
71
72static int __init init_rc_map_total_media_in_hand_02(void)
73{
74 return rc_map_register(&total_media_in_hand_02_map);
75}
76
77static void __exit exit_rc_map_total_media_in_hand_02(void)
78{
79 rc_map_unregister(&total_media_in_hand_02_map);
80}
81
82module_init(init_rc_map_total_media_in_hand_02)
83module_exit(exit_rc_map_total_media_in_hand_02)
84
85MODULE_LICENSE("GPL");
86MODULE_AUTHOR(" Alfredo J. Delaiti <alfredodelaiti@netscape.net>");
diff --git a/drivers/media/rc/mceusb.c b/drivers/media/rc/mceusb.c
index 9afb9331217d..5b5b6e6f79e8 100644
--- a/drivers/media/rc/mceusb.c
+++ b/drivers/media/rc/mceusb.c
@@ -62,7 +62,6 @@
62#define MCE_PACKET_SIZE 4 /* Normal length of packet (without header) */ 62#define MCE_PACKET_SIZE 4 /* Normal length of packet (without header) */
63#define MCE_IRDATA_HEADER 0x84 /* Actual header format is 0x80 + num_bytes */ 63#define MCE_IRDATA_HEADER 0x84 /* Actual header format is 0x80 + num_bytes */
64#define MCE_IRDATA_TRAILER 0x80 /* End of IR data */ 64#define MCE_IRDATA_TRAILER 0x80 /* End of IR data */
65#define MCE_TX_HEADER_LENGTH 3 /* # of bytes in the initializing tx header */
66#define MCE_MAX_CHANNELS 2 /* Two transmitters, hardware dependent? */ 65#define MCE_MAX_CHANNELS 2 /* Two transmitters, hardware dependent? */
67#define MCE_DEFAULT_TX_MASK 0x03 /* Vals: TX1=0x01, TX2=0x02, ALL=0x03 */ 66#define MCE_DEFAULT_TX_MASK 0x03 /* Vals: TX1=0x01, TX2=0x02, ALL=0x03 */
68#define MCE_PULSE_BIT 0x80 /* Pulse bit, MSB set == PULSE else SPACE */ 67#define MCE_PULSE_BIT 0x80 /* Pulse bit, MSB set == PULSE else SPACE */
@@ -291,7 +290,8 @@ static struct usb_device_id mceusb_dev_table[] = {
291 /* Philips/Spinel plus IR transceiver for ASUS */ 290 /* Philips/Spinel plus IR transceiver for ASUS */
292 { USB_DEVICE(VENDOR_PHILIPS, 0x2088) }, 291 { USB_DEVICE(VENDOR_PHILIPS, 0x2088) },
293 /* Philips IR transceiver (Dell branded) */ 292 /* Philips IR transceiver (Dell branded) */
294 { USB_DEVICE(VENDOR_PHILIPS, 0x2093) }, 293 { USB_DEVICE(VENDOR_PHILIPS, 0x2093),
294 .driver_info = MCE_GEN2_TX_INV },
295 /* Realtek MCE IR Receiver and card reader */ 295 /* Realtek MCE IR Receiver and card reader */
296 { USB_DEVICE(VENDOR_REALTEK, 0x0161), 296 { USB_DEVICE(VENDOR_REALTEK, 0x0161),
297 .driver_info = MULTIFUNCTION }, 297 .driver_info = MULTIFUNCTION },
@@ -365,7 +365,8 @@ static struct usb_device_id mceusb_dev_table[] = {
365 /* Formosa Industrial Computing */ 365 /* Formosa Industrial Computing */
366 { USB_DEVICE(VENDOR_FORMOSA, 0xe042) }, 366 { USB_DEVICE(VENDOR_FORMOSA, 0xe042) },
367 /* Fintek eHome Infrared Transceiver (HP branded) */ 367 /* Fintek eHome Infrared Transceiver (HP branded) */
368 { USB_DEVICE(VENDOR_FINTEK, 0x5168) }, 368 { USB_DEVICE(VENDOR_FINTEK, 0x5168),
369 .driver_info = MCE_GEN2_TX_INV },
369 /* Fintek eHome Infrared Transceiver */ 370 /* Fintek eHome Infrared Transceiver */
370 { USB_DEVICE(VENDOR_FINTEK, 0x0602) }, 371 { USB_DEVICE(VENDOR_FINTEK, 0x0602) },
371 /* Fintek eHome Infrared Transceiver (in the AOpen MP45) */ 372 /* Fintek eHome Infrared Transceiver (in the AOpen MP45) */
@@ -788,19 +789,19 @@ static void mce_flush_rx_buffer(struct mceusb_dev *ir, int size)
788static int mceusb_tx_ir(struct rc_dev *dev, unsigned *txbuf, unsigned count) 789static int mceusb_tx_ir(struct rc_dev *dev, unsigned *txbuf, unsigned count)
789{ 790{
790 struct mceusb_dev *ir = dev->priv; 791 struct mceusb_dev *ir = dev->priv;
791 int i, ret = 0; 792 int i, length, ret = 0;
792 int cmdcount = 0; 793 int cmdcount = 0;
793 unsigned char *cmdbuf; /* MCE command buffer */ 794 unsigned char cmdbuf[MCE_CMDBUF_SIZE];
794
795 cmdbuf = kzalloc(sizeof(unsigned) * MCE_CMDBUF_SIZE, GFP_KERNEL);
796 if (!cmdbuf)
797 return -ENOMEM;
798 795
799 /* MCE tx init header */ 796 /* MCE tx init header */
800 cmdbuf[cmdcount++] = MCE_CMD_PORT_IR; 797 cmdbuf[cmdcount++] = MCE_CMD_PORT_IR;
801 cmdbuf[cmdcount++] = MCE_CMD_SETIRTXPORTS; 798 cmdbuf[cmdcount++] = MCE_CMD_SETIRTXPORTS;
802 cmdbuf[cmdcount++] = ir->tx_mask; 799 cmdbuf[cmdcount++] = ir->tx_mask;
803 800
801 /* Send the set TX ports command */
802 mce_async_out(ir, cmdbuf, cmdcount);
803 cmdcount = 0;
804
804 /* Generate mce packet data */ 805 /* Generate mce packet data */
805 for (i = 0; (i < count) && (cmdcount < MCE_CMDBUF_SIZE); i++) { 806 for (i = 0; (i < count) && (cmdcount < MCE_CMDBUF_SIZE); i++) {
806 txbuf[i] = txbuf[i] / MCE_TIME_UNIT; 807 txbuf[i] = txbuf[i] / MCE_TIME_UNIT;
@@ -809,8 +810,7 @@ static int mceusb_tx_ir(struct rc_dev *dev, unsigned *txbuf, unsigned count)
809 810
810 /* Insert mce packet header every 4th entry */ 811 /* Insert mce packet header every 4th entry */
811 if ((cmdcount < MCE_CMDBUF_SIZE) && 812 if ((cmdcount < MCE_CMDBUF_SIZE) &&
812 (cmdcount - MCE_TX_HEADER_LENGTH) % 813 (cmdcount % MCE_CODE_LENGTH) == 0)
813 MCE_CODE_LENGTH == 0)
814 cmdbuf[cmdcount++] = MCE_IRDATA_HEADER; 814 cmdbuf[cmdcount++] = MCE_IRDATA_HEADER;
815 815
816 /* Insert mce packet data */ 816 /* Insert mce packet data */
@@ -828,17 +828,16 @@ static int mceusb_tx_ir(struct rc_dev *dev, unsigned *txbuf, unsigned count)
828 (txbuf[i] -= MCE_MAX_PULSE_LENGTH)); 828 (txbuf[i] -= MCE_MAX_PULSE_LENGTH));
829 } 829 }
830 830
831 /* Fix packet length in last header */
832 cmdbuf[cmdcount - (cmdcount - MCE_TX_HEADER_LENGTH) % MCE_CODE_LENGTH] =
833 MCE_COMMAND_IRDATA + (cmdcount - MCE_TX_HEADER_LENGTH) %
834 MCE_CODE_LENGTH - 1;
835
836 /* Check if we have room for the empty packet at the end */ 831 /* Check if we have room for the empty packet at the end */
837 if (cmdcount >= MCE_CMDBUF_SIZE) { 832 if (cmdcount >= MCE_CMDBUF_SIZE) {
838 ret = -EINVAL; 833 ret = -EINVAL;
839 goto out; 834 goto out;
840 } 835 }
841 836
837 /* Fix packet length in last header */
838 length = cmdcount % MCE_CODE_LENGTH;
839 cmdbuf[cmdcount - length] -= MCE_CODE_LENGTH - length;
840
842 /* All mce commands end with an empty packet (0x80) */ 841 /* All mce commands end with an empty packet (0x80) */
843 cmdbuf[cmdcount++] = MCE_IRDATA_TRAILER; 842 cmdbuf[cmdcount++] = MCE_IRDATA_TRAILER;
844 843
@@ -846,7 +845,6 @@ static int mceusb_tx_ir(struct rc_dev *dev, unsigned *txbuf, unsigned count)
846 mce_async_out(ir, cmdbuf, cmdcount); 845 mce_async_out(ir, cmdbuf, cmdcount);
847 846
848out: 847out:
849 kfree(cmdbuf);
850 return ret ? ret : count; 848 return ret ? ret : count;
851} 849}
852 850
@@ -1121,16 +1119,13 @@ static void mceusb_gen1_init(struct mceusb_dev *ir)
1121 mce_async_out(ir, GET_REVISION, sizeof(GET_REVISION)); 1119 mce_async_out(ir, GET_REVISION, sizeof(GET_REVISION));
1122 1120
1123 kfree(data); 1121 kfree(data);
1124}; 1122}
1125 1123
1126static void mceusb_gen2_init(struct mceusb_dev *ir) 1124static void mceusb_gen2_init(struct mceusb_dev *ir)
1127{ 1125{
1128 /* device resume */ 1126 /* device resume */
1129 mce_async_out(ir, DEVICE_RESUME, sizeof(DEVICE_RESUME)); 1127 mce_async_out(ir, DEVICE_RESUME, sizeof(DEVICE_RESUME));
1130 1128
1131 /* get hw/sw revision? */
1132 mce_async_out(ir, GET_REVISION, sizeof(GET_REVISION));
1133
1134 /* get wake version (protocol, key, address) */ 1129 /* get wake version (protocol, key, address) */
1135 mce_async_out(ir, GET_WAKEVERSION, sizeof(GET_WAKEVERSION)); 1130 mce_async_out(ir, GET_WAKEVERSION, sizeof(GET_WAKEVERSION));
1136 1131
diff --git a/drivers/media/rc/nuvoton-cir.c b/drivers/media/rc/nuvoton-cir.c
index b8aa9abb31ff..40125d779049 100644
--- a/drivers/media/rc/nuvoton-cir.c
+++ b/drivers/media/rc/nuvoton-cir.c
@@ -986,25 +986,25 @@ static int nvt_probe(struct pnp_dev *pdev, const struct pnp_device_id *dev_id)
986 /* input device for IR remote (and tx) */ 986 /* input device for IR remote (and tx) */
987 rdev = rc_allocate_device(); 987 rdev = rc_allocate_device();
988 if (!rdev) 988 if (!rdev)
989 goto failure; 989 goto exit_free_dev_rdev;
990 990
991 ret = -ENODEV; 991 ret = -ENODEV;
992 /* validate pnp resources */ 992 /* validate pnp resources */
993 if (!pnp_port_valid(pdev, 0) || 993 if (!pnp_port_valid(pdev, 0) ||
994 pnp_port_len(pdev, 0) < CIR_IOREG_LENGTH) { 994 pnp_port_len(pdev, 0) < CIR_IOREG_LENGTH) {
995 dev_err(&pdev->dev, "IR PNP Port not valid!\n"); 995 dev_err(&pdev->dev, "IR PNP Port not valid!\n");
996 goto failure; 996 goto exit_free_dev_rdev;
997 } 997 }
998 998
999 if (!pnp_irq_valid(pdev, 0)) { 999 if (!pnp_irq_valid(pdev, 0)) {
1000 dev_err(&pdev->dev, "PNP IRQ not valid!\n"); 1000 dev_err(&pdev->dev, "PNP IRQ not valid!\n");
1001 goto failure; 1001 goto exit_free_dev_rdev;
1002 } 1002 }
1003 1003
1004 if (!pnp_port_valid(pdev, 1) || 1004 if (!pnp_port_valid(pdev, 1) ||
1005 pnp_port_len(pdev, 1) < CIR_IOREG_LENGTH) { 1005 pnp_port_len(pdev, 1) < CIR_IOREG_LENGTH) {
1006 dev_err(&pdev->dev, "Wake PNP Port not valid!\n"); 1006 dev_err(&pdev->dev, "Wake PNP Port not valid!\n");
1007 goto failure; 1007 goto exit_free_dev_rdev;
1008 } 1008 }
1009 1009
1010 nvt->cir_addr = pnp_port_start(pdev, 0); 1010 nvt->cir_addr = pnp_port_start(pdev, 0);
@@ -1027,7 +1027,7 @@ static int nvt_probe(struct pnp_dev *pdev, const struct pnp_device_id *dev_id)
1027 1027
1028 ret = nvt_hw_detect(nvt); 1028 ret = nvt_hw_detect(nvt);
1029 if (ret) 1029 if (ret)
1030 goto failure; 1030 goto exit_free_dev_rdev;
1031 1031
1032 /* Initialize CIR & CIR Wake Logical Devices */ 1032 /* Initialize CIR & CIR Wake Logical Devices */
1033 nvt_efm_enable(nvt); 1033 nvt_efm_enable(nvt);
@@ -1065,31 +1065,32 @@ static int nvt_probe(struct pnp_dev *pdev, const struct pnp_device_id *dev_id)
1065 /* tx bits */ 1065 /* tx bits */
1066 rdev->tx_resolution = XYZ; 1066 rdev->tx_resolution = XYZ;
1067#endif 1067#endif
1068 nvt->rdev = rdev;
1069
1070 ret = rc_register_device(rdev);
1071 if (ret)
1072 goto exit_free_dev_rdev;
1068 1073
1069 ret = -EBUSY; 1074 ret = -EBUSY;
1070 /* now claim resources */ 1075 /* now claim resources */
1071 if (!request_region(nvt->cir_addr, 1076 if (!request_region(nvt->cir_addr,
1072 CIR_IOREG_LENGTH, NVT_DRIVER_NAME)) 1077 CIR_IOREG_LENGTH, NVT_DRIVER_NAME))
1073 goto failure; 1078 goto exit_unregister_device;
1074 1079
1075 if (request_irq(nvt->cir_irq, nvt_cir_isr, IRQF_SHARED, 1080 if (request_irq(nvt->cir_irq, nvt_cir_isr, IRQF_SHARED,
1076 NVT_DRIVER_NAME, (void *)nvt)) 1081 NVT_DRIVER_NAME, (void *)nvt))
1077 goto failure2; 1082 goto exit_release_cir_addr;
1078 1083
1079 if (!request_region(nvt->cir_wake_addr, 1084 if (!request_region(nvt->cir_wake_addr,
1080 CIR_IOREG_LENGTH, NVT_DRIVER_NAME)) 1085 CIR_IOREG_LENGTH, NVT_DRIVER_NAME))
1081 goto failure3; 1086 goto exit_free_irq;
1082 1087
1083 if (request_irq(nvt->cir_wake_irq, nvt_cir_wake_isr, IRQF_SHARED, 1088 if (request_irq(nvt->cir_wake_irq, nvt_cir_wake_isr, IRQF_SHARED,
1084 NVT_DRIVER_NAME, (void *)nvt)) 1089 NVT_DRIVER_NAME, (void *)nvt))
1085 goto failure4; 1090 goto exit_release_cir_wake_addr;
1086
1087 ret = rc_register_device(rdev);
1088 if (ret)
1089 goto failure5;
1090 1091
1091 device_init_wakeup(&pdev->dev, true); 1092 device_init_wakeup(&pdev->dev, true);
1092 nvt->rdev = rdev; 1093
1093 nvt_pr(KERN_NOTICE, "driver has been successfully loaded\n"); 1094 nvt_pr(KERN_NOTICE, "driver has been successfully loaded\n");
1094 if (debug) { 1095 if (debug) {
1095 cir_dump_regs(nvt); 1096 cir_dump_regs(nvt);
@@ -1098,15 +1099,15 @@ static int nvt_probe(struct pnp_dev *pdev, const struct pnp_device_id *dev_id)
1098 1099
1099 return 0; 1100 return 0;
1100 1101
1101failure5: 1102exit_release_cir_wake_addr:
1102 free_irq(nvt->cir_wake_irq, nvt);
1103failure4:
1104 release_region(nvt->cir_wake_addr, CIR_IOREG_LENGTH); 1103 release_region(nvt->cir_wake_addr, CIR_IOREG_LENGTH);
1105failure3: 1104exit_free_irq:
1106 free_irq(nvt->cir_irq, nvt); 1105 free_irq(nvt->cir_irq, nvt);
1107failure2: 1106exit_release_cir_addr:
1108 release_region(nvt->cir_addr, CIR_IOREG_LENGTH); 1107 release_region(nvt->cir_addr, CIR_IOREG_LENGTH);
1109failure: 1108exit_unregister_device:
1109 rc_unregister_device(rdev);
1110exit_free_dev_rdev:
1110 rc_free_device(rdev); 1111 rc_free_device(rdev);
1111 kfree(nvt); 1112 kfree(nvt);
1112 1113
diff --git a/drivers/media/rc/rc-core-priv.h b/drivers/media/rc/rc-core-priv.h
index 96f0a8bb39ea..5d87287ed372 100644
--- a/drivers/media/rc/rc-core-priv.h
+++ b/drivers/media/rc/rc-core-priv.h
@@ -165,56 +165,56 @@ void ir_raw_init(void);
165 165
166/* from ir-nec-decoder.c */ 166/* from ir-nec-decoder.c */
167#ifdef CONFIG_IR_NEC_DECODER_MODULE 167#ifdef CONFIG_IR_NEC_DECODER_MODULE
168#define load_nec_decode() request_module("ir-nec-decoder") 168#define load_nec_decode() request_module_nowait("ir-nec-decoder")
169#else 169#else
170static inline void load_nec_decode(void) { } 170static inline void load_nec_decode(void) { }
171#endif 171#endif
172 172
173/* from ir-rc5-decoder.c */ 173/* from ir-rc5-decoder.c */
174#ifdef CONFIG_IR_RC5_DECODER_MODULE 174#ifdef CONFIG_IR_RC5_DECODER_MODULE
175#define load_rc5_decode() request_module("ir-rc5-decoder") 175#define load_rc5_decode() request_module_nowait("ir-rc5-decoder")
176#else 176#else
177static inline void load_rc5_decode(void) { } 177static inline void load_rc5_decode(void) { }
178#endif 178#endif
179 179
180/* from ir-rc6-decoder.c */ 180/* from ir-rc6-decoder.c */
181#ifdef CONFIG_IR_RC6_DECODER_MODULE 181#ifdef CONFIG_IR_RC6_DECODER_MODULE
182#define load_rc6_decode() request_module("ir-rc6-decoder") 182#define load_rc6_decode() request_module_nowait("ir-rc6-decoder")
183#else 183#else
184static inline void load_rc6_decode(void) { } 184static inline void load_rc6_decode(void) { }
185#endif 185#endif
186 186
187/* from ir-jvc-decoder.c */ 187/* from ir-jvc-decoder.c */
188#ifdef CONFIG_IR_JVC_DECODER_MODULE 188#ifdef CONFIG_IR_JVC_DECODER_MODULE
189#define load_jvc_decode() request_module("ir-jvc-decoder") 189#define load_jvc_decode() request_module_nowait("ir-jvc-decoder")
190#else 190#else
191static inline void load_jvc_decode(void) { } 191static inline void load_jvc_decode(void) { }
192#endif 192#endif
193 193
194/* from ir-sony-decoder.c */ 194/* from ir-sony-decoder.c */
195#ifdef CONFIG_IR_SONY_DECODER_MODULE 195#ifdef CONFIG_IR_SONY_DECODER_MODULE
196#define load_sony_decode() request_module("ir-sony-decoder") 196#define load_sony_decode() request_module_nowait("ir-sony-decoder")
197#else 197#else
198static inline void load_sony_decode(void) { } 198static inline void load_sony_decode(void) { }
199#endif 199#endif
200 200
201/* from ir-sanyo-decoder.c */ 201/* from ir-sanyo-decoder.c */
202#ifdef CONFIG_IR_SANYO_DECODER_MODULE 202#ifdef CONFIG_IR_SANYO_DECODER_MODULE
203#define load_sanyo_decode() request_module("ir-sanyo-decoder") 203#define load_sanyo_decode() request_module_nowait("ir-sanyo-decoder")
204#else 204#else
205static inline void load_sanyo_decode(void) { } 205static inline void load_sanyo_decode(void) { }
206#endif 206#endif
207 207
208/* from ir-mce_kbd-decoder.c */ 208/* from ir-mce_kbd-decoder.c */
209#ifdef CONFIG_IR_MCE_KBD_DECODER_MODULE 209#ifdef CONFIG_IR_MCE_KBD_DECODER_MODULE
210#define load_mce_kbd_decode() request_module("ir-mce_kbd-decoder") 210#define load_mce_kbd_decode() request_module_nowait("ir-mce_kbd-decoder")
211#else 211#else
212static inline void load_mce_kbd_decode(void) { } 212static inline void load_mce_kbd_decode(void) { }
213#endif 213#endif
214 214
215/* from ir-lirc-codec.c */ 215/* from ir-lirc-codec.c */
216#ifdef CONFIG_IR_LIRC_CODEC_MODULE 216#ifdef CONFIG_IR_LIRC_CODEC_MODULE
217#define load_lirc_codec() request_module("ir-lirc-codec") 217#define load_lirc_codec() request_module_nowait("ir-lirc-codec")
218#else 218#else
219static inline void load_lirc_codec(void) { } 219static inline void load_lirc_codec(void) { }
220#endif 220#endif
diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
index 601d1ac1c688..759a40a42eaa 100644
--- a/drivers/media/rc/rc-main.c
+++ b/drivers/media/rc/rc-main.c
@@ -789,8 +789,10 @@ static ssize_t show_protocols(struct device *device,
789 } else if (dev->raw) { 789 } else if (dev->raw) {
790 enabled = dev->raw->enabled_protocols; 790 enabled = dev->raw->enabled_protocols;
791 allowed = ir_raw_get_allowed_protocols(); 791 allowed = ir_raw_get_allowed_protocols();
792 } else 792 } else {
793 mutex_unlock(&dev->lock);
793 return -ENODEV; 794 return -ENODEV;
795 }
794 796
795 IR_dprintk(1, "allowed - 0x%llx, enabled - 0x%llx\n", 797 IR_dprintk(1, "allowed - 0x%llx, enabled - 0x%llx\n",
796 (long long)allowed, 798 (long long)allowed,
@@ -890,7 +892,8 @@ static ssize_t store_protocols(struct device *device,
890 892
891 if (i == ARRAY_SIZE(proto_names)) { 893 if (i == ARRAY_SIZE(proto_names)) {
892 IR_dprintk(1, "Unknown protocol: '%s'\n", tmp); 894 IR_dprintk(1, "Unknown protocol: '%s'\n", tmp);
893 return -EINVAL; 895 ret = -EINVAL;
896 goto out;
894 } 897 }
895 898
896 count++; 899 count++;
diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
index 1800326f93e6..1b37fe2779f8 100644
--- a/drivers/media/rc/redrat3.c
+++ b/drivers/media/rc/redrat3.c
@@ -195,9 +195,6 @@ struct redrat3_dev {
195 dma_addr_t dma_in; 195 dma_addr_t dma_in;
196 dma_addr_t dma_out; 196 dma_addr_t dma_out;
197 197
198 /* locks this structure */
199 struct mutex lock;
200
201 /* rx signal timeout timer */ 198 /* rx signal timeout timer */
202 struct timer_list rx_timeout; 199 struct timer_list rx_timeout;
203 u32 hw_timeout; 200 u32 hw_timeout;
@@ -922,8 +919,7 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf,
922 return -EAGAIN; 919 return -EAGAIN;
923 } 920 }
924 921
925 if (count > (RR3_DRIVER_MAXLENS * 2)) 922 count = min_t(unsigned, count, RR3_MAX_SIG_SIZE - RR3_TX_TRAILER_LEN);
926 return -EINVAL;
927 923
928 /* rr3 will disable rc detector on transmit */ 924 /* rr3 will disable rc detector on transmit */
929 rr3->det_enabled = false; 925 rr3->det_enabled = false;
@@ -936,24 +932,22 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf,
936 } 932 }
937 933
938 for (i = 0; i < count; i++) { 934 for (i = 0; i < count; i++) {
935 cur_sample_len = redrat3_us_to_len(txbuf[i]);
939 for (lencheck = 0; lencheck < curlencheck; lencheck++) { 936 for (lencheck = 0; lencheck < curlencheck; lencheck++) {
940 cur_sample_len = redrat3_us_to_len(txbuf[i]);
941 if (sample_lens[lencheck] == cur_sample_len) 937 if (sample_lens[lencheck] == cur_sample_len)
942 break; 938 break;
943 } 939 }
944 if (lencheck == curlencheck) { 940 if (lencheck == curlencheck) {
945 cur_sample_len = redrat3_us_to_len(txbuf[i]);
946 rr3_dbg(dev, "txbuf[%d]=%u, pos %d, enc %u\n", 941 rr3_dbg(dev, "txbuf[%d]=%u, pos %d, enc %u\n",
947 i, txbuf[i], curlencheck, cur_sample_len); 942 i, txbuf[i], curlencheck, cur_sample_len);
948 if (curlencheck < 255) { 943 if (curlencheck < RR3_DRIVER_MAXLENS) {
949 /* now convert the value to a proper 944 /* now convert the value to a proper
950 * rr3 value.. */ 945 * rr3 value.. */
951 sample_lens[curlencheck] = cur_sample_len; 946 sample_lens[curlencheck] = cur_sample_len;
952 curlencheck++; 947 curlencheck++;
953 } else { 948 } else {
954 dev_err(dev, "signal too long\n"); 949 count = i - 1;
955 ret = -EINVAL; 950 break;
956 goto out;
957 } 951 }
958 } 952 }
959 } 953 }
@@ -1087,6 +1081,7 @@ static struct rc_dev *redrat3_init_rc_dev(struct redrat3_dev *rr3)
1087 rc->tx_ir = redrat3_transmit_ir; 1081 rc->tx_ir = redrat3_transmit_ir;
1088 rc->s_tx_carrier = redrat3_set_tx_carrier; 1082 rc->s_tx_carrier = redrat3_set_tx_carrier;
1089 rc->driver_name = DRIVER_NAME; 1083 rc->driver_name = DRIVER_NAME;
1084 rc->rx_resolution = US_TO_NS(2);
1090 rc->map_name = RC_MAP_HAUPPAUGE; 1085 rc->map_name = RC_MAP_HAUPPAUGE;
1091 1086
1092 ret = rc_register_device(rc); 1087 ret = rc_register_device(rc);
@@ -1202,7 +1197,6 @@ static int redrat3_dev_probe(struct usb_interface *intf,
1202 rr3->bulk_out_buf, ep_out->wMaxPacketSize, 1197 rr3->bulk_out_buf, ep_out->wMaxPacketSize,
1203 (usb_complete_t)redrat3_write_bulk_callback, rr3); 1198 (usb_complete_t)redrat3_write_bulk_callback, rr3);
1204 1199
1205 mutex_init(&rr3->lock);
1206 rr3->udev = udev; 1200 rr3->udev = udev;
1207 1201
1208 redrat3_reset(rr3); 1202 redrat3_reset(rr3);
diff --git a/drivers/media/rc/ttusbir.c b/drivers/media/rc/ttusbir.c
index 78be8a914225..cf0d47f57fb2 100644
--- a/drivers/media/rc/ttusbir.c
+++ b/drivers/media/rc/ttusbir.c
@@ -213,19 +213,20 @@ static int ttusbir_probe(struct usb_interface *intf,
213 213
214 /* find the correct alt setting */ 214 /* find the correct alt setting */
215 for (i = 0; i < intf->num_altsetting && altsetting == -1; i++) { 215 for (i = 0; i < intf->num_altsetting && altsetting == -1; i++) {
216 int bulk_out_endp = -1, iso_in_endp = -1; 216 int max_packet, bulk_out_endp = -1, iso_in_endp = -1;
217 217
218 idesc = &intf->altsetting[i].desc; 218 idesc = &intf->altsetting[i].desc;
219 219
220 for (j = 0; j < idesc->bNumEndpoints; j++) { 220 for (j = 0; j < idesc->bNumEndpoints; j++) {
221 desc = &intf->altsetting[i].endpoint[j].desc; 221 desc = &intf->altsetting[i].endpoint[j].desc;
222 max_packet = le16_to_cpu(desc->wMaxPacketSize);
222 if (usb_endpoint_dir_in(desc) && 223 if (usb_endpoint_dir_in(desc) &&
223 usb_endpoint_xfer_isoc(desc) && 224 usb_endpoint_xfer_isoc(desc) &&
224 desc->wMaxPacketSize == 0x10) 225 max_packet == 0x10)
225 iso_in_endp = j; 226 iso_in_endp = j;
226 else if (usb_endpoint_dir_out(desc) && 227 else if (usb_endpoint_dir_out(desc) &&
227 usb_endpoint_xfer_bulk(desc) && 228 usb_endpoint_xfer_bulk(desc) &&
228 desc->wMaxPacketSize == 0x20) 229 max_packet == 0x20)
229 bulk_out_endp = j; 230 bulk_out_endp = j;
230 231
231 if (bulk_out_endp != -1 && iso_in_endp != -1) { 232 if (bulk_out_endp != -1 && iso_in_endp != -1) {
@@ -408,9 +409,8 @@ static int ttusbir_resume(struct usb_interface *intf)
408 struct ttusbir *tt = usb_get_intfdata(intf); 409 struct ttusbir *tt = usb_get_intfdata(intf);
409 int i, rc; 410 int i, rc;
410 411
411 led_classdev_resume(&tt->led);
412 tt->is_led_on = true; 412 tt->is_led_on = true;
413 ttusbir_set_led(tt); 413 led_classdev_resume(&tt->led);
414 414
415 for (i = 0; i < NUM_URBS; i++) { 415 for (i = 0; i < NUM_URBS; i++) {
416 rc = usb_submit_urb(tt->urb[i], GFP_KERNEL); 416 rc = usb_submit_urb(tt->urb[i], GFP_KERNEL);
diff --git a/drivers/media/rc/winbond-cir.c b/drivers/media/rc/winbond-cir.c
index 930c61499037..535a18dccbd0 100644
--- a/drivers/media/rc/winbond-cir.c
+++ b/drivers/media/rc/winbond-cir.c
@@ -154,6 +154,8 @@
154#define WBCIR_CNTR_R 0x02 154#define WBCIR_CNTR_R 0x02
155/* Invert TX */ 155/* Invert TX */
156#define WBCIR_IRTX_INV 0x04 156#define WBCIR_IRTX_INV 0x04
157/* Receiver oversampling */
158#define WBCIR_RX_T_OV 0x40
157 159
158/* Valid banks for the SP3 UART */ 160/* Valid banks for the SP3 UART */
159enum wbcir_bank { 161enum wbcir_bank {
@@ -394,7 +396,8 @@ wbcir_irq_rx(struct wbcir_data *data, struct pnp_dev *device)
394 if (data->rxstate == WBCIR_RXSTATE_ERROR) 396 if (data->rxstate == WBCIR_RXSTATE_ERROR)
395 continue; 397 continue;
396 398
397 duration = ((irdata & 0x7F) + 1) * 2; 399 duration = ((irdata & 0x7F) + 1) *
400 (data->carrier_report_enabled ? 2 : 10);
398 rawir.pulse = irdata & 0x80 ? false : true; 401 rawir.pulse = irdata & 0x80 ? false : true;
399 rawir.duration = US_TO_NS(duration); 402 rawir.duration = US_TO_NS(duration);
400 403
@@ -550,6 +553,17 @@ wbcir_set_carrier_report(struct rc_dev *dev, int enable)
550 wbcir_set_bits(data->ebase + WBCIR_REG_ECEIR_CCTL, 553 wbcir_set_bits(data->ebase + WBCIR_REG_ECEIR_CCTL,
551 WBCIR_CNTR_EN, WBCIR_CNTR_EN | WBCIR_CNTR_R); 554 WBCIR_CNTR_EN, WBCIR_CNTR_EN | WBCIR_CNTR_R);
552 555
556 /* Set a higher sampling resolution if carrier reports are enabled */
557 wbcir_select_bank(data, WBCIR_BANK_2);
558 data->dev->rx_resolution = US_TO_NS(enable ? 2 : 10);
559 outb(enable ? 0x03 : 0x0f, data->sbase + WBCIR_REG_SP3_BGDL);
560 outb(0x00, data->sbase + WBCIR_REG_SP3_BGDH);
561
562 /* Enable oversampling if carrier reports are enabled */
563 wbcir_select_bank(data, WBCIR_BANK_7);
564 wbcir_set_bits(data->sbase + WBCIR_REG_SP3_RCCFG,
565 enable ? WBCIR_RX_T_OV : 0, WBCIR_RX_T_OV);
566
553 data->carrier_report_enabled = enable; 567 data->carrier_report_enabled = enable;
554 spin_unlock_irqrestore(&data->spinlock, flags); 568 spin_unlock_irqrestore(&data->spinlock, flags);
555 569
@@ -931,8 +945,8 @@ wbcir_init_hw(struct wbcir_data *data)
931 /* prescaler 1.0, tx/rx fifo lvl 16 */ 945 /* prescaler 1.0, tx/rx fifo lvl 16 */
932 outb(0x30, data->sbase + WBCIR_REG_SP3_EXCR2); 946 outb(0x30, data->sbase + WBCIR_REG_SP3_EXCR2);
933 947
934 /* Set baud divisor to sample every 2 ns */ 948 /* Set baud divisor to sample every 10 us */
935 outb(0x03, data->sbase + WBCIR_REG_SP3_BGDL); 949 outb(0x0f, data->sbase + WBCIR_REG_SP3_BGDL);
936 outb(0x00, data->sbase + WBCIR_REG_SP3_BGDH); 950 outb(0x00, data->sbase + WBCIR_REG_SP3_BGDH);
937 951
938 /* Set CEIR mode */ 952 /* Set CEIR mode */
@@ -941,12 +955,9 @@ wbcir_init_hw(struct wbcir_data *data)
941 inb(data->sbase + WBCIR_REG_SP3_LSR); /* Clear LSR */ 955 inb(data->sbase + WBCIR_REG_SP3_LSR); /* Clear LSR */
942 inb(data->sbase + WBCIR_REG_SP3_MSR); /* Clear MSR */ 956 inb(data->sbase + WBCIR_REG_SP3_MSR); /* Clear MSR */
943 957
944 /* 958 /* Disable RX demod, enable run-length enc/dec, set freq span */
945 * Disable RX demod, enable run-length enc/dec, set freq span and
946 * enable over-sampling
947 */
948 wbcir_select_bank(data, WBCIR_BANK_7); 959 wbcir_select_bank(data, WBCIR_BANK_7);
949 outb(0xd0, data->sbase + WBCIR_REG_SP3_RCCFG); 960 outb(0x90, data->sbase + WBCIR_REG_SP3_RCCFG);
950 961
951 /* Disable timer */ 962 /* Disable timer */
952 wbcir_select_bank(data, WBCIR_BANK_4); 963 wbcir_select_bank(data, WBCIR_BANK_4);
@@ -1093,11 +1104,15 @@ wbcir_probe(struct pnp_dev *device, const struct pnp_device_id *dev_id)
1093 data->dev->rx_resolution = US_TO_NS(2); 1104 data->dev->rx_resolution = US_TO_NS(2);
1094 data->dev->allowed_protos = RC_BIT_ALL; 1105 data->dev->allowed_protos = RC_BIT_ALL;
1095 1106
1107 err = rc_register_device(data->dev);
1108 if (err)
1109 goto exit_free_rc;
1110
1096 if (!request_region(data->wbase, WAKEUP_IOMEM_LEN, DRVNAME)) { 1111 if (!request_region(data->wbase, WAKEUP_IOMEM_LEN, DRVNAME)) {
1097 dev_err(dev, "Region 0x%lx-0x%lx already in use!\n", 1112 dev_err(dev, "Region 0x%lx-0x%lx already in use!\n",
1098 data->wbase, data->wbase + WAKEUP_IOMEM_LEN - 1); 1113 data->wbase, data->wbase + WAKEUP_IOMEM_LEN - 1);
1099 err = -EBUSY; 1114 err = -EBUSY;
1100 goto exit_free_rc; 1115 goto exit_unregister_device;
1101 } 1116 }
1102 1117
1103 if (!request_region(data->ebase, EHFUNC_IOMEM_LEN, DRVNAME)) { 1118 if (!request_region(data->ebase, EHFUNC_IOMEM_LEN, DRVNAME)) {
@@ -1122,24 +1137,20 @@ wbcir_probe(struct pnp_dev *device, const struct pnp_device_id *dev_id)
1122 goto exit_release_sbase; 1137 goto exit_release_sbase;
1123 } 1138 }
1124 1139
1125 err = rc_register_device(data->dev);
1126 if (err)
1127 goto exit_free_irq;
1128
1129 device_init_wakeup(&device->dev, 1); 1140 device_init_wakeup(&device->dev, 1);
1130 1141
1131 wbcir_init_hw(data); 1142 wbcir_init_hw(data);
1132 1143
1133 return 0; 1144 return 0;
1134 1145
1135exit_free_irq:
1136 free_irq(data->irq, device);
1137exit_release_sbase: 1146exit_release_sbase:
1138 release_region(data->sbase, SP_IOMEM_LEN); 1147 release_region(data->sbase, SP_IOMEM_LEN);
1139exit_release_ebase: 1148exit_release_ebase:
1140 release_region(data->ebase, EHFUNC_IOMEM_LEN); 1149 release_region(data->ebase, EHFUNC_IOMEM_LEN);
1141exit_release_wbase: 1150exit_release_wbase:
1142 release_region(data->wbase, WAKEUP_IOMEM_LEN); 1151 release_region(data->wbase, WAKEUP_IOMEM_LEN);
1152exit_unregister_device:
1153 rc_unregister_device(data->dev);
1143exit_free_rc: 1154exit_free_rc:
1144 rc_free_device(data->dev); 1155 rc_free_device(data->dev);
1145exit_unregister_led: 1156exit_unregister_led:
diff --git a/drivers/media/tuners/fc0011.c b/drivers/media/tuners/fc0011.c
index e4882546c283..3932aa81e18c 100644
--- a/drivers/media/tuners/fc0011.c
+++ b/drivers/media/tuners/fc0011.c
@@ -183,8 +183,7 @@ static int fc0011_set_params(struct dvb_frontend *fe)
183 unsigned int i, vco_retries; 183 unsigned int i, vco_retries;
184 u32 freq = p->frequency / 1000; 184 u32 freq = p->frequency / 1000;
185 u32 bandwidth = p->bandwidth_hz / 1000; 185 u32 bandwidth = p->bandwidth_hz / 1000;
186 u32 fvco, xin, xdiv, xdivr; 186 u32 fvco, xin, frac, xdiv, xdivr;
187 u16 frac;
188 u8 fa, fp, vco_sel, vco_cal; 187 u8 fa, fp, vco_sel, vco_cal;
189 u8 regs[FC11_NR_REGS] = { }; 188 u8 regs[FC11_NR_REGS] = { };
190 189
@@ -221,18 +220,15 @@ static int fc0011_set_params(struct dvb_frontend *fe)
221 220
222 /* Calc XIN. The PLL reference frequency is 18 MHz. */ 221 /* Calc XIN. The PLL reference frequency is 18 MHz. */
223 xdiv = fvco / 18000; 222 xdiv = fvco / 18000;
223 WARN_ON(xdiv > 0xFF);
224 frac = fvco - xdiv * 18000; 224 frac = fvco - xdiv * 18000;
225 frac = (frac << 15) / 18000; 225 frac = (frac << 15) / 18000;
226 if (frac >= 16384) 226 if (frac >= 16384)
227 frac += 32786; 227 frac += 32786;
228 if (!frac) 228 if (!frac)
229 xin = 0; 229 xin = 0;
230 else if (frac < 511)
231 xin = 512;
232 else if (frac < 65026)
233 xin = frac;
234 else 230 else
235 xin = 65024; 231 xin = clamp_t(u32, frac, 512, 65024);
236 regs[FC11_REG_XINHI] = xin >> 8; 232 regs[FC11_REG_XINHI] = xin >> 8;
237 regs[FC11_REG_XINLO] = xin; 233 regs[FC11_REG_XINLO] = xin;
238 234
@@ -247,8 +243,8 @@ static int fc0011_set_params(struct dvb_frontend *fe)
247 fa += 8; 243 fa += 8;
248 } 244 }
249 if (fp > 0x1F) { 245 if (fp > 0x1F) {
250 fp &= 0x1F; 246 fp = 0x1F;
251 fa &= 0xF; 247 fa = 0xF;
252 } 248 }
253 if (fa >= fp) { 249 if (fa >= fp) {
254 dev_warn(&priv->i2c->dev, 250 dev_warn(&priv->i2c->dev,
@@ -351,6 +347,8 @@ static int fc0011_set_params(struct dvb_frontend *fe)
351 vco_cal &= FC11_VCOCAL_VALUEMASK; 347 vco_cal &= FC11_VCOCAL_VALUEMASK;
352 348
353 switch (vco_sel) { 349 switch (vco_sel) {
350 default:
351 WARN_ON(1);
354 case 0: 352 case 0:
355 if (vco_cal < 8) { 353 if (vco_cal < 8) {
356 regs[FC11_REG_VCOSEL] &= ~(FC11_VCOSEL_1 | FC11_VCOSEL_2); 354 regs[FC11_REG_VCOSEL] &= ~(FC11_VCOSEL_1 | FC11_VCOSEL_2);
@@ -432,7 +430,8 @@ static int fc0011_set_params(struct dvb_frontend *fe)
432 err = fc0011_writereg(priv, FC11_REG_RCCAL, regs[FC11_REG_RCCAL]); 430 err = fc0011_writereg(priv, FC11_REG_RCCAL, regs[FC11_REG_RCCAL]);
433 if (err) 431 if (err)
434 return err; 432 return err;
435 err = fc0011_writereg(priv, FC11_REG_16, 0xB); 433 regs[FC11_REG_16] = 0xB;
434 err = fc0011_writereg(priv, FC11_REG_16, regs[FC11_REG_16]);
436 if (err) 435 if (err)
437 return err; 436 return err;
438 437
diff --git a/drivers/media/tuners/fc0012-priv.h b/drivers/media/tuners/fc0012-priv.h
index 4577c917e616..1a86ce1d3fcf 100644
--- a/drivers/media/tuners/fc0012-priv.h
+++ b/drivers/media/tuners/fc0012-priv.h
@@ -21,20 +21,9 @@
21#ifndef _FC0012_PRIV_H_ 21#ifndef _FC0012_PRIV_H_
22#define _FC0012_PRIV_H_ 22#define _FC0012_PRIV_H_
23 23
24#define LOG_PREFIX "fc0012"
25
26#undef err
27#define err(f, arg...) printk(KERN_ERR LOG_PREFIX": " f "\n" , ## arg)
28#undef info
29#define info(f, arg...) printk(KERN_INFO LOG_PREFIX": " f "\n" , ## arg)
30#undef warn
31#define warn(f, arg...) printk(KERN_WARNING LOG_PREFIX": " f "\n" , ## arg)
32
33struct fc0012_priv { 24struct fc0012_priv {
34 struct i2c_adapter *i2c; 25 struct i2c_adapter *i2c;
35 u8 addr; 26 const struct fc0012_config *cfg;
36 u8 dual_master;
37 u8 xtal_freq;
38 27
39 u32 frequency; 28 u32 frequency;
40 u32 bandwidth; 29 u32 bandwidth;
diff --git a/drivers/media/tuners/fc0012.c b/drivers/media/tuners/fc0012.c
index 308135abd54c..f4d0e797a6cc 100644
--- a/drivers/media/tuners/fc0012.c
+++ b/drivers/media/tuners/fc0012.c
@@ -25,11 +25,13 @@ static int fc0012_writereg(struct fc0012_priv *priv, u8 reg, u8 val)
25{ 25{
26 u8 buf[2] = {reg, val}; 26 u8 buf[2] = {reg, val};
27 struct i2c_msg msg = { 27 struct i2c_msg msg = {
28 .addr = priv->addr, .flags = 0, .buf = buf, .len = 2 28 .addr = priv->cfg->i2c_address, .flags = 0, .buf = buf, .len = 2
29 }; 29 };
30 30
31 if (i2c_transfer(priv->i2c, &msg, 1) != 1) { 31 if (i2c_transfer(priv->i2c, &msg, 1) != 1) {
32 err("I2C write reg failed, reg: %02x, val: %02x", reg, val); 32 dev_err(&priv->i2c->dev,
33 "%s: I2C write reg failed, reg: %02x, val: %02x\n",
34 KBUILD_MODNAME, reg, val);
33 return -EREMOTEIO; 35 return -EREMOTEIO;
34 } 36 }
35 return 0; 37 return 0;
@@ -38,12 +40,16 @@ static int fc0012_writereg(struct fc0012_priv *priv, u8 reg, u8 val)
38static int fc0012_readreg(struct fc0012_priv *priv, u8 reg, u8 *val) 40static int fc0012_readreg(struct fc0012_priv *priv, u8 reg, u8 *val)
39{ 41{
40 struct i2c_msg msg[2] = { 42 struct i2c_msg msg[2] = {
41 { .addr = priv->addr, .flags = 0, .buf = &reg, .len = 1 }, 43 { .addr = priv->cfg->i2c_address, .flags = 0,
42 { .addr = priv->addr, .flags = I2C_M_RD, .buf = val, .len = 1 }, 44 .buf = &reg, .len = 1 },
45 { .addr = priv->cfg->i2c_address, .flags = I2C_M_RD,
46 .buf = val, .len = 1 },
43 }; 47 };
44 48
45 if (i2c_transfer(priv->i2c, msg, 2) != 2) { 49 if (i2c_transfer(priv->i2c, msg, 2) != 2) {
46 err("I2C read reg failed, reg: %02x", reg); 50 dev_err(&priv->i2c->dev,
51 "%s: I2C read reg failed, reg: %02x\n",
52 KBUILD_MODNAME, reg);
47 return -EREMOTEIO; 53 return -EREMOTEIO;
48 } 54 }
49 return 0; 55 return 0;
@@ -88,7 +94,7 @@ static int fc0012_init(struct dvb_frontend *fe)
88 0x04, /* reg. 0x15: Enable LNA COMPS */ 94 0x04, /* reg. 0x15: Enable LNA COMPS */
89 }; 95 };
90 96
91 switch (priv->xtal_freq) { 97 switch (priv->cfg->xtal_freq) {
92 case FC_XTAL_27_MHZ: 98 case FC_XTAL_27_MHZ:
93 case FC_XTAL_28_8_MHZ: 99 case FC_XTAL_28_8_MHZ:
94 reg[0x07] |= 0x20; 100 reg[0x07] |= 0x20;
@@ -98,9 +104,12 @@ static int fc0012_init(struct dvb_frontend *fe)
98 break; 104 break;
99 } 105 }
100 106
101 if (priv->dual_master) 107 if (priv->cfg->dual_master)
102 reg[0x0c] |= 0x02; 108 reg[0x0c] |= 0x02;
103 109
110 if (priv->cfg->loop_through)
111 reg[0x09] |= 0x01;
112
104 if (fe->ops.i2c_gate_ctrl) 113 if (fe->ops.i2c_gate_ctrl)
105 fe->ops.i2c_gate_ctrl(fe, 1); /* open I2C-gate */ 114 fe->ops.i2c_gate_ctrl(fe, 1); /* open I2C-gate */
106 115
@@ -114,17 +123,12 @@ static int fc0012_init(struct dvb_frontend *fe)
114 fe->ops.i2c_gate_ctrl(fe, 0); /* close I2C-gate */ 123 fe->ops.i2c_gate_ctrl(fe, 0); /* close I2C-gate */
115 124
116 if (ret) 125 if (ret)
117 err("fc0012_writereg failed: %d", ret); 126 dev_err(&priv->i2c->dev, "%s: fc0012_writereg failed: %d\n",
127 KBUILD_MODNAME, ret);
118 128
119 return ret; 129 return ret;
120} 130}
121 131
122static int fc0012_sleep(struct dvb_frontend *fe)
123{
124 /* nothing to do here */
125 return 0;
126}
127
128static int fc0012_set_params(struct dvb_frontend *fe) 132static int fc0012_set_params(struct dvb_frontend *fe)
129{ 133{
130 struct fc0012_priv *priv = fe->tuner_priv; 134 struct fc0012_priv *priv = fe->tuner_priv;
@@ -144,7 +148,7 @@ static int fc0012_set_params(struct dvb_frontend *fe)
144 goto exit; 148 goto exit;
145 } 149 }
146 150
147 switch (priv->xtal_freq) { 151 switch (priv->cfg->xtal_freq) {
148 case FC_XTAL_27_MHZ: 152 case FC_XTAL_27_MHZ:
149 xtal_freq_khz_2 = 27000 / 2; 153 xtal_freq_khz_2 = 27000 / 2;
150 break; 154 break;
@@ -256,7 +260,8 @@ static int fc0012_set_params(struct dvb_frontend *fe)
256 break; 260 break;
257 } 261 }
258 } else { 262 } else {
259 err("%s: modulation type not supported!", __func__); 263 dev_err(&priv->i2c->dev, "%s: modulation type not supported!\n",
264 KBUILD_MODNAME);
260 return -EINVAL; 265 return -EINVAL;
261 } 266 }
262 267
@@ -318,7 +323,8 @@ exit:
318 if (fe->ops.i2c_gate_ctrl) 323 if (fe->ops.i2c_gate_ctrl)
319 fe->ops.i2c_gate_ctrl(fe, 0); /* close I2C-gate */ 324 fe->ops.i2c_gate_ctrl(fe, 0); /* close I2C-gate */
320 if (ret) 325 if (ret)
321 warn("%s: failed: %d", __func__, ret); 326 dev_warn(&priv->i2c->dev, "%s: %s failed: %d\n",
327 KBUILD_MODNAME, __func__, ret);
322 return ret; 328 return ret;
323} 329}
324 330
@@ -331,8 +337,7 @@ static int fc0012_get_frequency(struct dvb_frontend *fe, u32 *frequency)
331 337
332static int fc0012_get_if_frequency(struct dvb_frontend *fe, u32 *frequency) 338static int fc0012_get_if_frequency(struct dvb_frontend *fe, u32 *frequency)
333{ 339{
334 /* CHECK: always ? */ 340 *frequency = 0; /* Zero-IF */
335 *frequency = 0;
336 return 0; 341 return 0;
337} 342}
338 343
@@ -408,7 +413,8 @@ err:
408 fe->ops.i2c_gate_ctrl(fe, 0); /* close I2C-gate */ 413 fe->ops.i2c_gate_ctrl(fe, 0); /* close I2C-gate */
409exit: 414exit:
410 if (ret) 415 if (ret)
411 warn("%s: failed: %d", __func__, ret); 416 dev_warn(&priv->i2c->dev, "%s: %s failed: %d\n",
417 KBUILD_MODNAME, __func__, ret);
412 return ret; 418 return ret;
413} 419}
414 420
@@ -424,7 +430,6 @@ static const struct dvb_tuner_ops fc0012_tuner_ops = {
424 .release = fc0012_release, 430 .release = fc0012_release,
425 431
426 .init = fc0012_init, 432 .init = fc0012_init,
427 .sleep = fc0012_sleep,
428 433
429 .set_params = fc0012_set_params, 434 .set_params = fc0012_set_params,
430 435
@@ -436,27 +441,73 @@ static const struct dvb_tuner_ops fc0012_tuner_ops = {
436}; 441};
437 442
438struct dvb_frontend *fc0012_attach(struct dvb_frontend *fe, 443struct dvb_frontend *fc0012_attach(struct dvb_frontend *fe,
439 struct i2c_adapter *i2c, u8 i2c_address, int dual_master, 444 struct i2c_adapter *i2c, const struct fc0012_config *cfg)
440 enum fc001x_xtal_freq xtal_freq)
441{ 445{
442 struct fc0012_priv *priv = NULL; 446 struct fc0012_priv *priv;
447 int ret;
448 u8 chip_id;
449
450 if (fe->ops.i2c_gate_ctrl)
451 fe->ops.i2c_gate_ctrl(fe, 1);
443 452
444 priv = kzalloc(sizeof(struct fc0012_priv), GFP_KERNEL); 453 priv = kzalloc(sizeof(struct fc0012_priv), GFP_KERNEL);
445 if (priv == NULL) 454 if (!priv) {
446 return NULL; 455 ret = -ENOMEM;
456 dev_err(&i2c->dev, "%s: kzalloc() failed\n", KBUILD_MODNAME);
457 goto err;
458 }
447 459
460 priv->cfg = cfg;
448 priv->i2c = i2c; 461 priv->i2c = i2c;
449 priv->dual_master = dual_master;
450 priv->addr = i2c_address;
451 priv->xtal_freq = xtal_freq;
452 462
453 info("Fitipower FC0012 successfully attached."); 463 /* check if the tuner is there */
464 ret = fc0012_readreg(priv, 0x00, &chip_id);
465 if (ret < 0)
466 goto err;
454 467
455 fe->tuner_priv = priv; 468 dev_dbg(&i2c->dev, "%s: chip_id=%02x\n", __func__, chip_id);
469
470 switch (chip_id) {
471 case 0xa1:
472 break;
473 default:
474 ret = -ENODEV;
475 goto err;
476 }
477
478 dev_info(&i2c->dev, "%s: Fitipower FC0012 successfully identified\n",
479 KBUILD_MODNAME);
480
481 if (priv->cfg->loop_through) {
482 ret = fc0012_writereg(priv, 0x09, 0x6f);
483 if (ret < 0)
484 goto err;
485 }
486
487 /*
488 * TODO: Clock out en or div?
489 * For dual tuner configuration clearing bit [0] is required.
490 */
491 if (priv->cfg->clock_out) {
492 ret = fc0012_writereg(priv, 0x0b, 0x82);
493 if (ret < 0)
494 goto err;
495 }
456 496
497 fe->tuner_priv = priv;
457 memcpy(&fe->ops.tuner_ops, &fc0012_tuner_ops, 498 memcpy(&fe->ops.tuner_ops, &fc0012_tuner_ops,
458 sizeof(struct dvb_tuner_ops)); 499 sizeof(struct dvb_tuner_ops));
459 500
501err:
502 if (fe->ops.i2c_gate_ctrl)
503 fe->ops.i2c_gate_ctrl(fe, 0);
504
505 if (ret) {
506 dev_dbg(&i2c->dev, "%s: failed: %d\n", __func__, ret);
507 kfree(priv);
508 return NULL;
509 }
510
460 return fe; 511 return fe;
461} 512}
462EXPORT_SYMBOL(fc0012_attach); 513EXPORT_SYMBOL(fc0012_attach);
diff --git a/drivers/media/tuners/fc0012.h b/drivers/media/tuners/fc0012.h
index 4dbd5efe8845..54508fcc3469 100644
--- a/drivers/media/tuners/fc0012.h
+++ b/drivers/media/tuners/fc0012.h
@@ -24,19 +24,41 @@
24#include "dvb_frontend.h" 24#include "dvb_frontend.h"
25#include "fc001x-common.h" 25#include "fc001x-common.h"
26 26
27struct fc0012_config {
28 /*
29 * I2C address
30 */
31 u8 i2c_address;
32
33 /*
34 * clock
35 */
36 enum fc001x_xtal_freq xtal_freq;
37
38 bool dual_master;
39
40 /*
41 * RF loop-through
42 */
43 bool loop_through;
44
45 /*
46 * clock output
47 */
48 bool clock_out;
49};
50
27#if defined(CONFIG_MEDIA_TUNER_FC0012) || \ 51#if defined(CONFIG_MEDIA_TUNER_FC0012) || \
28 (defined(CONFIG_MEDIA_TUNER_FC0012_MODULE) && defined(MODULE)) 52 (defined(CONFIG_MEDIA_TUNER_FC0012_MODULE) && defined(MODULE))
29extern struct dvb_frontend *fc0012_attach(struct dvb_frontend *fe, 53extern struct dvb_frontend *fc0012_attach(struct dvb_frontend *fe,
30 struct i2c_adapter *i2c, 54 struct i2c_adapter *i2c,
31 u8 i2c_address, int dual_master, 55 const struct fc0012_config *cfg);
32 enum fc001x_xtal_freq xtal_freq);
33#else 56#else
34static inline struct dvb_frontend *fc0012_attach(struct dvb_frontend *fe, 57static inline struct dvb_frontend *fc0012_attach(struct dvb_frontend *fe,
35 struct i2c_adapter *i2c, 58 struct i2c_adapter *i2c,
36 u8 i2c_address, int dual_master, 59 const struct fc0012_config *cfg)
37 enum fc001x_xtal_freq xtal_freq)
38{ 60{
39 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 61 pr_warn("%s: driver disabled by Kconfig\n", __func__);
40 return NULL; 62 return NULL;
41} 63}
42#endif 64#endif
diff --git a/drivers/media/tuners/mt2060.h b/drivers/media/tuners/mt2060.h
index cb60caffb6b6..c64fc19cb278 100644
--- a/drivers/media/tuners/mt2060.h
+++ b/drivers/media/tuners/mt2060.h
@@ -30,7 +30,7 @@ struct mt2060_config {
30 u8 clock_out; /* 0 = off, 1 = CLK/4, 2 = CLK/2, 3 = CLK/1 */ 30 u8 clock_out; /* 0 = off, 1 = CLK/4, 2 = CLK/2, 3 = CLK/1 */
31}; 31};
32 32
33#if defined(CONFIG_MEDIA_TUNER_MT2060) || (defined(CONFIG_MEDIA_TUNER_MT2060_MODULE) && defined(MODULE)) 33#if IS_ENABLED(CONFIG_MEDIA_TUNER_MT2060)
34extern struct dvb_frontend * mt2060_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, struct mt2060_config *cfg, u16 if1); 34extern struct dvb_frontend * mt2060_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, struct mt2060_config *cfg, u16 if1);
35#else 35#else
36static inline struct dvb_frontend * mt2060_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, struct mt2060_config *cfg, u16 if1) 36static inline struct dvb_frontend * mt2060_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, struct mt2060_config *cfg, u16 if1)
diff --git a/drivers/media/tuners/mt2063.h b/drivers/media/tuners/mt2063.h
index ab24170c1571..e1acfc8e7ae3 100644
--- a/drivers/media/tuners/mt2063.h
+++ b/drivers/media/tuners/mt2063.h
@@ -8,7 +8,7 @@ struct mt2063_config {
8 u32 refclock; 8 u32 refclock;
9}; 9};
10 10
11#if defined(CONFIG_MEDIA_TUNER_MT2063) || (defined(CONFIG_MEDIA_TUNER_MT2063_MODULE) && defined(MODULE)) 11#if IS_ENABLED(CONFIG_MEDIA_TUNER_MT2063)
12struct dvb_frontend *mt2063_attach(struct dvb_frontend *fe, 12struct dvb_frontend *mt2063_attach(struct dvb_frontend *fe,
13 struct mt2063_config *config, 13 struct mt2063_config *config,
14 struct i2c_adapter *i2c); 14 struct i2c_adapter *i2c);
diff --git a/drivers/media/tuners/mt20xx.h b/drivers/media/tuners/mt20xx.h
index 259553a24903..f56241ccaa00 100644
--- a/drivers/media/tuners/mt20xx.h
+++ b/drivers/media/tuners/mt20xx.h
@@ -20,7 +20,7 @@
20#include <linux/i2c.h> 20#include <linux/i2c.h>
21#include "dvb_frontend.h" 21#include "dvb_frontend.h"
22 22
23#if defined(CONFIG_MEDIA_TUNER_MT20XX) || (defined(CONFIG_MEDIA_TUNER_MT20XX_MODULE) && defined(MODULE)) 23#if IS_ENABLED(CONFIG_MEDIA_TUNER_MT20XX)
24extern struct dvb_frontend *microtune_attach(struct dvb_frontend *fe, 24extern struct dvb_frontend *microtune_attach(struct dvb_frontend *fe,
25 struct i2c_adapter* i2c_adap, 25 struct i2c_adapter* i2c_adap,
26 u8 i2c_addr); 26 u8 i2c_addr);
diff --git a/drivers/media/tuners/mt2131.h b/drivers/media/tuners/mt2131.h
index 6632de640df0..09ceaf68e47c 100644
--- a/drivers/media/tuners/mt2131.h
+++ b/drivers/media/tuners/mt2131.h
@@ -30,7 +30,7 @@ struct mt2131_config {
30 u8 clock_out; /* 0 = off, 1 = CLK/4, 2 = CLK/2, 3 = CLK/1 */ 30 u8 clock_out; /* 0 = off, 1 = CLK/4, 2 = CLK/2, 3 = CLK/1 */
31}; 31};
32 32
33#if defined(CONFIG_MEDIA_TUNER_MT2131) || (defined(CONFIG_MEDIA_TUNER_MT2131_MODULE) && defined(MODULE)) 33#if IS_ENABLED(CONFIG_MEDIA_TUNER_MT2131)
34extern struct dvb_frontend* mt2131_attach(struct dvb_frontend *fe, 34extern struct dvb_frontend* mt2131_attach(struct dvb_frontend *fe,
35 struct i2c_adapter *i2c, 35 struct i2c_adapter *i2c,
36 struct mt2131_config *cfg, 36 struct mt2131_config *cfg,
diff --git a/drivers/media/tuners/mt2266.h b/drivers/media/tuners/mt2266.h
index 4d083882d044..fad6dd657d77 100644
--- a/drivers/media/tuners/mt2266.h
+++ b/drivers/media/tuners/mt2266.h
@@ -24,7 +24,7 @@ struct mt2266_config {
24 u8 i2c_address; 24 u8 i2c_address;
25}; 25};
26 26
27#if defined(CONFIG_MEDIA_TUNER_MT2266) || (defined(CONFIG_MEDIA_TUNER_MT2266_MODULE) && defined(MODULE)) 27#if IS_ENABLED(CONFIG_MEDIA_TUNER_MT2266)
28extern struct dvb_frontend * mt2266_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, struct mt2266_config *cfg); 28extern struct dvb_frontend * mt2266_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, struct mt2266_config *cfg);
29#else 29#else
30static inline struct dvb_frontend * mt2266_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, struct mt2266_config *cfg) 30static inline struct dvb_frontend * mt2266_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, struct mt2266_config *cfg)
diff --git a/drivers/media/tuners/mxl5007t.h b/drivers/media/tuners/mxl5007t.h
index aa3eea0b5262..37b0942e2385 100644
--- a/drivers/media/tuners/mxl5007t.h
+++ b/drivers/media/tuners/mxl5007t.h
@@ -77,7 +77,7 @@ struct mxl5007t_config {
77 unsigned int clk_out_enable:1; 77 unsigned int clk_out_enable:1;
78}; 78};
79 79
80#if defined(CONFIG_MEDIA_TUNER_MXL5007T) || (defined(CONFIG_MEDIA_TUNER_MXL5007T_MODULE) && defined(MODULE)) 80#if IS_ENABLED(CONFIG_MEDIA_TUNER_MXL5007T)
81extern struct dvb_frontend *mxl5007t_attach(struct dvb_frontend *fe, 81extern struct dvb_frontend *mxl5007t_attach(struct dvb_frontend *fe,
82 struct i2c_adapter *i2c, u8 addr, 82 struct i2c_adapter *i2c, u8 addr,
83 struct mxl5007t_config *cfg); 83 struct mxl5007t_config *cfg);
diff --git a/drivers/media/tuners/qt1010.h b/drivers/media/tuners/qt1010.h
index 807fb7b6146b..8ab5d479749f 100644
--- a/drivers/media/tuners/qt1010.h
+++ b/drivers/media/tuners/qt1010.h
@@ -36,7 +36,7 @@ struct qt1010_config {
36 * @param cfg tuner hw based configuration 36 * @param cfg tuner hw based configuration
37 * @return fe pointer on success, NULL on failure 37 * @return fe pointer on success, NULL on failure
38 */ 38 */
39#if defined(CONFIG_MEDIA_TUNER_QT1010) || (defined(CONFIG_MEDIA_TUNER_QT1010_MODULE) && defined(MODULE)) 39#if IS_ENABLED(CONFIG_MEDIA_TUNER_QT1010)
40extern struct dvb_frontend *qt1010_attach(struct dvb_frontend *fe, 40extern struct dvb_frontend *qt1010_attach(struct dvb_frontend *fe,
41 struct i2c_adapter *i2c, 41 struct i2c_adapter *i2c,
42 struct qt1010_config *cfg); 42 struct qt1010_config *cfg);
diff --git a/drivers/media/tuners/tda18212.c b/drivers/media/tuners/tda18212.c
index 5d9f02842501..e4a84ee231cf 100644
--- a/drivers/media/tuners/tda18212.c
+++ b/drivers/media/tuners/tda18212.c
@@ -277,7 +277,7 @@ struct dvb_frontend *tda18212_attach(struct dvb_frontend *fe,
277{ 277{
278 struct tda18212_priv *priv = NULL; 278 struct tda18212_priv *priv = NULL;
279 int ret; 279 int ret;
280 u8 uninitialized_var(val); 280 u8 val;
281 281
282 priv = kzalloc(sizeof(struct tda18212_priv), GFP_KERNEL); 282 priv = kzalloc(sizeof(struct tda18212_priv), GFP_KERNEL);
283 if (priv == NULL) 283 if (priv == NULL)
@@ -296,8 +296,8 @@ struct dvb_frontend *tda18212_attach(struct dvb_frontend *fe,
296 if (fe->ops.i2c_gate_ctrl) 296 if (fe->ops.i2c_gate_ctrl)
297 fe->ops.i2c_gate_ctrl(fe, 0); /* close I2C-gate */ 297 fe->ops.i2c_gate_ctrl(fe, 0); /* close I2C-gate */
298 298
299 dev_dbg(&priv->i2c->dev, "%s: ret=%d chip id=%02x\n", __func__, ret, 299 if (!ret)
300 val); 300 dev_dbg(&priv->i2c->dev, "%s: chip id=%02x\n", __func__, val);
301 if (ret || val != 0xc7) { 301 if (ret || val != 0xc7) {
302 kfree(priv); 302 kfree(priv);
303 return NULL; 303 return NULL;
diff --git a/drivers/media/tuners/tda18218.c b/drivers/media/tuners/tda18218.c
index 18198537be9f..2d31aeb6b088 100644
--- a/drivers/media/tuners/tda18218.c
+++ b/drivers/media/tuners/tda18218.c
@@ -277,7 +277,7 @@ struct dvb_frontend *tda18218_attach(struct dvb_frontend *fe,
277 struct i2c_adapter *i2c, struct tda18218_config *cfg) 277 struct i2c_adapter *i2c, struct tda18218_config *cfg)
278{ 278{
279 struct tda18218_priv *priv = NULL; 279 struct tda18218_priv *priv = NULL;
280 u8 uninitialized_var(val); 280 u8 val;
281 int ret; 281 int ret;
282 /* chip default registers values */ 282 /* chip default registers values */
283 static u8 def_regs[] = { 283 static u8 def_regs[] = {
@@ -302,8 +302,8 @@ struct dvb_frontend *tda18218_attach(struct dvb_frontend *fe,
302 302
303 /* check if the tuner is there */ 303 /* check if the tuner is there */
304 ret = tda18218_rd_reg(priv, R00_ID, &val); 304 ret = tda18218_rd_reg(priv, R00_ID, &val);
305 dev_dbg(&priv->i2c->dev, "%s: ret=%d chip id=%02x\n", __func__, ret, 305 if (!ret)
306 val); 306 dev_dbg(&priv->i2c->dev, "%s: chip id=%02x\n", __func__, val);
307 if (ret || val != def_regs[R00_ID]) { 307 if (ret || val != def_regs[R00_ID]) {
308 kfree(priv); 308 kfree(priv);
309 return NULL; 309 return NULL;
diff --git a/drivers/media/tuners/tda18271-fe.c b/drivers/media/tuners/tda18271-fe.c
index 72c26fd77922..e7786862dab2 100644
--- a/drivers/media/tuners/tda18271-fe.c
+++ b/drivers/media/tuners/tda18271-fe.c
@@ -1122,6 +1122,7 @@ static int tda18271_dump_std_map(struct dvb_frontend *fe)
1122 tda18271_dump_std_item(dvbt_7, "dvbt 7"); 1122 tda18271_dump_std_item(dvbt_7, "dvbt 7");
1123 tda18271_dump_std_item(dvbt_8, "dvbt 8"); 1123 tda18271_dump_std_item(dvbt_8, "dvbt 8");
1124 tda18271_dump_std_item(qam_6, "qam 6 "); 1124 tda18271_dump_std_item(qam_6, "qam 6 ");
1125 tda18271_dump_std_item(qam_7, "qam 7 ");
1125 tda18271_dump_std_item(qam_8, "qam 8 "); 1126 tda18271_dump_std_item(qam_8, "qam 8 ");
1126 1127
1127 return 0; 1128 return 0;
@@ -1149,6 +1150,7 @@ static int tda18271_update_std_map(struct dvb_frontend *fe,
1149 tda18271_update_std(dvbt_7, "dvbt 7"); 1150 tda18271_update_std(dvbt_7, "dvbt 7");
1150 tda18271_update_std(dvbt_8, "dvbt 8"); 1151 tda18271_update_std(dvbt_8, "dvbt 8");
1151 tda18271_update_std(qam_6, "qam 6"); 1152 tda18271_update_std(qam_6, "qam 6");
1153 tda18271_update_std(qam_7, "qam 7");
1152 tda18271_update_std(qam_8, "qam 8"); 1154 tda18271_update_std(qam_8, "qam 8");
1153 1155
1154 return 0; 1156 return 0;
diff --git a/drivers/media/tuners/tda18271-maps.c b/drivers/media/tuners/tda18271-maps.c
index fb881c667c94..b62e925f643f 100644
--- a/drivers/media/tuners/tda18271-maps.c
+++ b/drivers/media/tuners/tda18271-maps.c
@@ -1290,13 +1290,11 @@ int tda18271_assign_map_layout(struct dvb_frontend *fe)
1290 switch (priv->id) { 1290 switch (priv->id) {
1291 case TDA18271HDC1: 1291 case TDA18271HDC1:
1292 priv->maps = &tda18271c1_map_layout; 1292 priv->maps = &tda18271c1_map_layout;
1293 memcpy(&priv->std, &tda18271c1_std_map, 1293 priv->std = tda18271c1_std_map;
1294 sizeof(struct tda18271_std_map));
1295 break; 1294 break;
1296 case TDA18271HDC2: 1295 case TDA18271HDC2:
1297 priv->maps = &tda18271c2_map_layout; 1296 priv->maps = &tda18271c2_map_layout;
1298 memcpy(&priv->std, &tda18271c2_std_map, 1297 priv->std = tda18271c2_std_map;
1299 sizeof(struct tda18271_std_map));
1300 break; 1298 break;
1301 default: 1299 default:
1302 ret = -EINVAL; 1300 ret = -EINVAL;
diff --git a/drivers/media/tuners/tda18271.h b/drivers/media/tuners/tda18271.h
index 89b6c6d93fec..4c418d63f540 100644
--- a/drivers/media/tuners/tda18271.h
+++ b/drivers/media/tuners/tda18271.h
@@ -121,7 +121,7 @@ enum tda18271_mode {
121 TDA18271_DIGITAL, 121 TDA18271_DIGITAL,
122}; 122};
123 123
124#if defined(CONFIG_MEDIA_TUNER_TDA18271) || (defined(CONFIG_MEDIA_TUNER_TDA18271_MODULE) && defined(MODULE)) 124#if IS_ENABLED(CONFIG_MEDIA_TUNER_TDA18271)
125extern struct dvb_frontend *tda18271_attach(struct dvb_frontend *fe, u8 addr, 125extern struct dvb_frontend *tda18271_attach(struct dvb_frontend *fe, u8 addr,
126 struct i2c_adapter *i2c, 126 struct i2c_adapter *i2c,
127 struct tda18271_config *cfg); 127 struct tda18271_config *cfg);
diff --git a/drivers/media/tuners/tda827x.h b/drivers/media/tuners/tda827x.h
index 7d72ce0a0c2d..9432b5b6121b 100644
--- a/drivers/media/tuners/tda827x.h
+++ b/drivers/media/tuners/tda827x.h
@@ -50,7 +50,7 @@ struct tda827x_config
50 * @param cfg optional callback function pointers. 50 * @param cfg optional callback function pointers.
51 * @return FE pointer on success, NULL on failure. 51 * @return FE pointer on success, NULL on failure.
52 */ 52 */
53#if defined(CONFIG_MEDIA_TUNER_TDA827X) || (defined(CONFIG_MEDIA_TUNER_TDA827X_MODULE) && defined(MODULE)) 53#if IS_ENABLED(CONFIG_MEDIA_TUNER_TDA827X)
54extern struct dvb_frontend* tda827x_attach(struct dvb_frontend *fe, int addr, 54extern struct dvb_frontend* tda827x_attach(struct dvb_frontend *fe, int addr,
55 struct i2c_adapter *i2c, 55 struct i2c_adapter *i2c,
56 struct tda827x_config *cfg); 56 struct tda827x_config *cfg);
diff --git a/drivers/media/tuners/tda8290.h b/drivers/media/tuners/tda8290.h
index 7e288b26fcc3..e12ecbaa35a4 100644
--- a/drivers/media/tuners/tda8290.h
+++ b/drivers/media/tuners/tda8290.h
@@ -28,7 +28,7 @@ struct tda829x_config {
28#define TDA829X_DONT_PROBE 1 28#define TDA829X_DONT_PROBE 1
29}; 29};
30 30
31#if defined(CONFIG_MEDIA_TUNER_TDA8290) || (defined(CONFIG_MEDIA_TUNER_TDA8290_MODULE) && defined(MODULE)) 31#if IS_ENABLED(CONFIG_MEDIA_TUNER_TDA8290)
32extern int tda829x_probe(struct i2c_adapter *i2c_adap, u8 i2c_addr); 32extern int tda829x_probe(struct i2c_adapter *i2c_adap, u8 i2c_addr);
33 33
34extern struct dvb_frontend *tda829x_attach(struct dvb_frontend *fe, 34extern struct dvb_frontend *tda829x_attach(struct dvb_frontend *fe,
diff --git a/drivers/media/tuners/tda9887.h b/drivers/media/tuners/tda9887.h
index acc419e8c4fc..37a4a1123e0c 100644
--- a/drivers/media/tuners/tda9887.h
+++ b/drivers/media/tuners/tda9887.h
@@ -21,7 +21,7 @@
21#include "dvb_frontend.h" 21#include "dvb_frontend.h"
22 22
23/* ------------------------------------------------------------------------ */ 23/* ------------------------------------------------------------------------ */
24#if defined(CONFIG_MEDIA_TUNER_TDA9887) || (defined(CONFIG_MEDIA_TUNER_TDA9887_MODULE) && defined(MODULE)) 24#if IS_ENABLED(CONFIG_MEDIA_TUNER_TDA9887)
25extern struct dvb_frontend *tda9887_attach(struct dvb_frontend *fe, 25extern struct dvb_frontend *tda9887_attach(struct dvb_frontend *fe,
26 struct i2c_adapter *i2c_adap, 26 struct i2c_adapter *i2c_adap,
27 u8 i2c_addr); 27 u8 i2c_addr);
diff --git a/drivers/media/tuners/tea5761.h b/drivers/media/tuners/tea5761.h
index 2e2ff82c95a4..933228ffb509 100644
--- a/drivers/media/tuners/tea5761.h
+++ b/drivers/media/tuners/tea5761.h
@@ -20,7 +20,7 @@
20#include <linux/i2c.h> 20#include <linux/i2c.h>
21#include "dvb_frontend.h" 21#include "dvb_frontend.h"
22 22
23#if defined(CONFIG_MEDIA_TUNER_TEA5761) || (defined(CONFIG_MEDIA_TUNER_TEA5761_MODULE) && defined(MODULE)) 23#if IS_ENABLED(CONFIG_MEDIA_TUNER_TEA5761)
24extern int tea5761_autodetection(struct i2c_adapter* i2c_adap, u8 i2c_addr); 24extern int tea5761_autodetection(struct i2c_adapter* i2c_adap, u8 i2c_addr);
25 25
26extern struct dvb_frontend *tea5761_attach(struct dvb_frontend *fe, 26extern struct dvb_frontend *tea5761_attach(struct dvb_frontend *fe,
diff --git a/drivers/media/tuners/tea5767.h b/drivers/media/tuners/tea5767.h
index d30ab1b483de..c39101199383 100644
--- a/drivers/media/tuners/tea5767.h
+++ b/drivers/media/tuners/tea5767.h
@@ -39,7 +39,7 @@ struct tea5767_ctrl {
39 enum tea5767_xtal xtal_freq; 39 enum tea5767_xtal xtal_freq;
40}; 40};
41 41
42#if defined(CONFIG_MEDIA_TUNER_TEA5767) || (defined(CONFIG_MEDIA_TUNER_TEA5767_MODULE) && defined(MODULE)) 42#if IS_ENABLED(CONFIG_MEDIA_TUNER_TEA5767)
43extern int tea5767_autodetection(struct i2c_adapter* i2c_adap, u8 i2c_addr); 43extern int tea5767_autodetection(struct i2c_adapter* i2c_adap, u8 i2c_addr);
44 44
45extern struct dvb_frontend *tea5767_attach(struct dvb_frontend *fe, 45extern struct dvb_frontend *tea5767_attach(struct dvb_frontend *fe,
diff --git a/drivers/media/tuners/tuner-simple.h b/drivers/media/tuners/tuner-simple.h
index 381fa5d35a9b..ffd12cfe650b 100644
--- a/drivers/media/tuners/tuner-simple.h
+++ b/drivers/media/tuners/tuner-simple.h
@@ -20,7 +20,7 @@
20#include <linux/i2c.h> 20#include <linux/i2c.h>
21#include "dvb_frontend.h" 21#include "dvb_frontend.h"
22 22
23#if defined(CONFIG_MEDIA_TUNER_SIMPLE) || (defined(CONFIG_MEDIA_TUNER_SIMPLE_MODULE) && defined(MODULE)) 23#if IS_ENABLED(CONFIG_MEDIA_TUNER_SIMPLE)
24extern struct dvb_frontend *simple_tuner_attach(struct dvb_frontend *fe, 24extern struct dvb_frontend *simple_tuner_attach(struct dvb_frontend *fe,
25 struct i2c_adapter *i2c_adap, 25 struct i2c_adapter *i2c_adap,
26 u8 i2c_addr, 26 u8 i2c_addr,
diff --git a/drivers/media/tuners/tuner-xc2028.c b/drivers/media/tuners/tuner-xc2028.c
index 7bcb6b0ff1df..09451737c77e 100644
--- a/drivers/media/tuners/tuner-xc2028.c
+++ b/drivers/media/tuners/tuner-xc2028.c
@@ -870,7 +870,7 @@ check_device:
870 } 870 }
871 871
872read_not_reliable: 872read_not_reliable:
873 memcpy(&priv->cur_fw, &new_fw, sizeof(priv->cur_fw)); 873 priv->cur_fw = new_fw;
874 874
875 /* 875 /*
876 * By setting BASE in cur_fw.type only after successfully loading all 876 * By setting BASE in cur_fw.type only after successfully loading all
diff --git a/drivers/media/tuners/tuner-xc2028.h b/drivers/media/tuners/tuner-xc2028.h
index 9ebfb2d0ff14..181d087faec4 100644
--- a/drivers/media/tuners/tuner-xc2028.h
+++ b/drivers/media/tuners/tuner-xc2028.h
@@ -56,7 +56,7 @@ struct xc2028_config {
56#define XC2028_RESET_CLK 1 56#define XC2028_RESET_CLK 1
57#define XC2028_I2C_FLUSH 2 57#define XC2028_I2C_FLUSH 2
58 58
59#if defined(CONFIG_MEDIA_TUNER_XC2028) || (defined(CONFIG_MEDIA_TUNER_XC2028_MODULE) && defined(MODULE)) 59#if IS_ENABLED(CONFIG_MEDIA_TUNER_XC2028)
60extern struct dvb_frontend *xc2028_attach(struct dvb_frontend *fe, 60extern struct dvb_frontend *xc2028_attach(struct dvb_frontend *fe,
61 struct xc2028_config *cfg); 61 struct xc2028_config *cfg);
62#else 62#else
diff --git a/drivers/media/tuners/xc4000.c b/drivers/media/tuners/xc4000.c
index 5c0fd787cc8f..2018befabb5a 100644
--- a/drivers/media/tuners/xc4000.c
+++ b/drivers/media/tuners/xc4000.c
@@ -1066,7 +1066,7 @@ check_device:
1066 goto fail; 1066 goto fail;
1067 } 1067 }
1068 1068
1069 memcpy(&priv->cur_fw, &new_fw, sizeof(priv->cur_fw)); 1069 priv->cur_fw = new_fw;
1070 1070
1071 /* 1071 /*
1072 * By setting BASE in cur_fw.type only after successfully loading all 1072 * By setting BASE in cur_fw.type only after successfully loading all
diff --git a/drivers/media/tuners/xc4000.h b/drivers/media/tuners/xc4000.h
index e6a44d151cbd..97c23de5296c 100644
--- a/drivers/media/tuners/xc4000.h
+++ b/drivers/media/tuners/xc4000.h
@@ -50,7 +50,7 @@ struct xc4000_config {
50 * it's passed back to a bridge during tuner_callback(). 50 * it's passed back to a bridge during tuner_callback().
51 */ 51 */
52 52
53#if defined(CONFIG_MEDIA_TUNER_XC4000) || (defined(CONFIG_MEDIA_TUNER_XC4000_MODULE) && defined(MODULE)) 53#if IS_ENABLED(CONFIG_MEDIA_TUNER_XC4000)
54extern struct dvb_frontend *xc4000_attach(struct dvb_frontend *fe, 54extern struct dvb_frontend *xc4000_attach(struct dvb_frontend *fe,
55 struct i2c_adapter *i2c, 55 struct i2c_adapter *i2c,
56 struct xc4000_config *cfg); 56 struct xc4000_config *cfg);
diff --git a/drivers/media/tuners/xc5000.c b/drivers/media/tuners/xc5000.c
index dc93cf338f36..d6be1b613c52 100644
--- a/drivers/media/tuners/xc5000.c
+++ b/drivers/media/tuners/xc5000.c
@@ -785,6 +785,7 @@ static int xc5000_set_params(struct dvb_frontend *fe)
785 return -EINVAL; 785 return -EINVAL;
786 } 786 }
787 priv->rf_mode = XC_RF_MODE_AIR; 787 priv->rf_mode = XC_RF_MODE_AIR;
788 break;
788 case SYS_DVBC_ANNEX_A: 789 case SYS_DVBC_ANNEX_A:
789 case SYS_DVBC_ANNEX_C: 790 case SYS_DVBC_ANNEX_C:
790 dprintk(1, "%s() QAM modulation\n", __func__); 791 dprintk(1, "%s() QAM modulation\n", __func__);
diff --git a/drivers/media/usb/Kconfig b/drivers/media/usb/Kconfig
index 6746994d03fe..0a7d520636a9 100644
--- a/drivers/media/usb/Kconfig
+++ b/drivers/media/usb/Kconfig
@@ -21,7 +21,6 @@ endif
21 21
22if MEDIA_ANALOG_TV_SUPPORT 22if MEDIA_ANALOG_TV_SUPPORT
23 comment "Analog TV USB devices" 23 comment "Analog TV USB devices"
24source "drivers/media/usb/au0828/Kconfig"
25source "drivers/media/usb/pvrusb2/Kconfig" 24source "drivers/media/usb/pvrusb2/Kconfig"
26source "drivers/media/usb/hdpvr/Kconfig" 25source "drivers/media/usb/hdpvr/Kconfig"
27source "drivers/media/usb/tlg2300/Kconfig" 26source "drivers/media/usb/tlg2300/Kconfig"
@@ -31,6 +30,7 @@ endif
31 30
32if (MEDIA_ANALOG_TV_SUPPORT || MEDIA_DIGITAL_TV_SUPPORT) 31if (MEDIA_ANALOG_TV_SUPPORT || MEDIA_DIGITAL_TV_SUPPORT)
33 comment "Analog/digital TV USB devices" 32 comment "Analog/digital TV USB devices"
33source "drivers/media/usb/au0828/Kconfig"
34source "drivers/media/usb/cx231xx/Kconfig" 34source "drivers/media/usb/cx231xx/Kconfig"
35source "drivers/media/usb/tm6000/Kconfig" 35source "drivers/media/usb/tm6000/Kconfig"
36endif 36endif
diff --git a/drivers/media/usb/au0828/Kconfig b/drivers/media/usb/au0828/Kconfig
index 1766c0ce93be..953a37c613b1 100644
--- a/drivers/media/usb/au0828/Kconfig
+++ b/drivers/media/usb/au0828/Kconfig
@@ -1,17 +1,28 @@
1 1
2config VIDEO_AU0828 2config VIDEO_AU0828
3 tristate "Auvitek AU0828 support" 3 tristate "Auvitek AU0828 support"
4 depends on I2C && INPUT && DVB_CORE && USB && VIDEO_V4L2 4 depends on I2C && INPUT && DVB_CORE && USB
5 select I2C_ALGOBIT 5 select I2C_ALGOBIT
6 select VIDEO_TVEEPROM 6 select VIDEO_TVEEPROM
7 select VIDEOBUF_VMALLOC 7 select VIDEOBUF_VMALLOC
8 select DVB_AU8522_DTV if MEDIA_SUBDRV_AUTOSELECT 8 select DVB_AU8522_DTV if MEDIA_SUBDRV_AUTOSELECT
9 select DVB_AU8522_V4L if MEDIA_SUBDRV_AUTOSELECT
10 select MEDIA_TUNER_XC5000 if MEDIA_SUBDRV_AUTOSELECT 9 select MEDIA_TUNER_XC5000 if MEDIA_SUBDRV_AUTOSELECT
11 select MEDIA_TUNER_MXL5007T if MEDIA_SUBDRV_AUTOSELECT 10 select MEDIA_TUNER_MXL5007T if MEDIA_SUBDRV_AUTOSELECT
12 select MEDIA_TUNER_TDA18271 if MEDIA_SUBDRV_AUTOSELECT 11 select MEDIA_TUNER_TDA18271 if MEDIA_SUBDRV_AUTOSELECT
13 ---help--- 12 ---help---
14 This is a video4linux driver for Auvitek's USB device. 13 This is a hybrid analog/digital tv capture driver for
14 Auvitek's AU0828 USB device.
15 15
16 To compile this driver as a module, choose M here: the 16 To compile this driver as a module, choose M here: the
17 module will be called au0828 17 module will be called au0828
18
19config VIDEO_AU0828_V4L2
20 bool "Auvitek AU0828 v4l2 analog video support"
21 depends on VIDEO_AU0828 && VIDEO_V4L2
22 select DVB_AU8522_V4L if MEDIA_SUBDRV_AUTOSELECT
23 default y
24 ---help---
25 This is a video4linux driver for Auvitek's USB device.
26
27 Choose Y here to include support for v4l2 analog video
28 capture within the au0828 driver.
diff --git a/drivers/media/usb/au0828/Makefile b/drivers/media/usb/au0828/Makefile
index 98cc20cc0ffb..be3bdf698022 100644
--- a/drivers/media/usb/au0828/Makefile
+++ b/drivers/media/usb/au0828/Makefile
@@ -1,4 +1,8 @@
1au0828-objs := au0828-core.o au0828-i2c.o au0828-cards.o au0828-dvb.o au0828-video.o au0828-vbi.o 1au0828-objs := au0828-core.o au0828-i2c.o au0828-cards.o au0828-dvb.o
2
3ifeq ($(CONFIG_VIDEO_AU0828_V4L2),y)
4 au0828-objs += au0828-video.o au0828-vbi.o
5endif
2 6
3obj-$(CONFIG_VIDEO_AU0828) += au0828.o 7obj-$(CONFIG_VIDEO_AU0828) += au0828.o
4 8
diff --git a/drivers/media/usb/au0828/au0828-cards.c b/drivers/media/usb/au0828/au0828-cards.c
index 0cb7c28dcb17..dd32decb237d 100644
--- a/drivers/media/usb/au0828/au0828-cards.c
+++ b/drivers/media/usb/au0828/au0828-cards.c
@@ -169,7 +169,9 @@ static void hauppauge_eeprom(struct au0828_dev *dev, u8 *eeprom_data)
169 case 72231: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and analog video */ 169 case 72231: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and analog video */
170 case 72241: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM and analog video */ 170 case 72241: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM and analog video */
171 case 72251: /* WinTV-HVR950q (Retail, IR, ATSC/QAM and analog video */ 171 case 72251: /* WinTV-HVR950q (Retail, IR, ATSC/QAM and analog video */
172 case 72261: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and analog video */ 172 case 72261: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM and analog video */
173 case 72271: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM and analog video */
174 case 72281: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM and analog video */
173 case 72301: /* WinTV-HVR850 (Retail, IR, ATSC and analog video */ 175 case 72301: /* WinTV-HVR850 (Retail, IR, ATSC and analog video */
174 case 72500: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM */ 176 case 72500: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM */
175 break; 177 break;
@@ -183,16 +185,15 @@ static void hauppauge_eeprom(struct au0828_dev *dev, u8 *eeprom_data)
183 __func__, tv.model); 185 __func__, tv.model);
184} 186}
185 187
188void au0828_card_analog_fe_setup(struct au0828_dev *dev);
189
186void au0828_card_setup(struct au0828_dev *dev) 190void au0828_card_setup(struct au0828_dev *dev)
187{ 191{
188 static u8 eeprom[256]; 192 static u8 eeprom[256];
189 struct tuner_setup tun_setup;
190 struct v4l2_subdev *sd;
191 unsigned int mode_mask = T_ANALOG_TV;
192 193
193 dprintk(1, "%s()\n", __func__); 194 dprintk(1, "%s()\n", __func__);
194 195
195 memcpy(&dev->board, &au0828_boards[dev->boardnr], sizeof(dev->board)); 196 dev->board = au0828_boards[dev->boardnr];
196 197
197 if (dev->i2c_rc == 0) { 198 if (dev->i2c_rc == 0) {
198 dev->i2c_client.addr = 0xa0 >> 1; 199 dev->i2c_client.addr = 0xa0 >> 1;
@@ -209,6 +210,16 @@ void au0828_card_setup(struct au0828_dev *dev)
209 break; 210 break;
210 } 211 }
211 212
213 au0828_card_analog_fe_setup(dev);
214}
215
216void au0828_card_analog_fe_setup(struct au0828_dev *dev)
217{
218#ifdef CONFIG_VIDEO_AU0828_V4L2
219 struct tuner_setup tun_setup;
220 struct v4l2_subdev *sd;
221 unsigned int mode_mask = T_ANALOG_TV;
222
212 if (AUVI_INPUT(0).type != AU0828_VMUX_UNDEFINED) { 223 if (AUVI_INPUT(0).type != AU0828_VMUX_UNDEFINED) {
213 /* Load the analog demodulator driver (note this would need to 224 /* Load the analog demodulator driver (note this would need to
214 be abstracted out if we ever need to support a different 225 be abstracted out if we ever need to support a different
@@ -234,6 +245,7 @@ void au0828_card_setup(struct au0828_dev *dev)
234 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_type_addr, 245 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_type_addr,
235 &tun_setup); 246 &tun_setup);
236 } 247 }
248#endif
237} 249}
238 250
239/* 251/*
@@ -333,6 +345,8 @@ struct usb_device_id au0828_usb_id_table[] = {
333 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q }, 345 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
334 { USB_DEVICE(0x2040, 0x7213), 346 { USB_DEVICE(0x2040, 0x7213),
335 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q }, 347 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
348 { USB_DEVICE(0x2040, 0x7270),
349 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
336 { }, 350 { },
337}; 351};
338 352
diff --git a/drivers/media/usb/au0828/au0828-core.c b/drivers/media/usb/au0828/au0828-core.c
index 745a80a798c8..1e6f40ef1c6b 100644
--- a/drivers/media/usb/au0828/au0828-core.c
+++ b/drivers/media/usb/au0828/au0828-core.c
@@ -134,13 +134,17 @@ static void au0828_usb_disconnect(struct usb_interface *interface)
134 /* Digital TV */ 134 /* Digital TV */
135 au0828_dvb_unregister(dev); 135 au0828_dvb_unregister(dev);
136 136
137#ifdef CONFIG_VIDEO_AU0828_V4L2
137 if (AUVI_INPUT(0).type != AU0828_VMUX_UNDEFINED) 138 if (AUVI_INPUT(0).type != AU0828_VMUX_UNDEFINED)
138 au0828_analog_unregister(dev); 139 au0828_analog_unregister(dev);
140#endif
139 141
140 /* I2C */ 142 /* I2C */
141 au0828_i2c_unregister(dev); 143 au0828_i2c_unregister(dev);
142 144
145#ifdef CONFIG_VIDEO_AU0828_V4L2
143 v4l2_device_unregister(&dev->v4l2_dev); 146 v4l2_device_unregister(&dev->v4l2_dev);
147#endif
144 148
145 usb_set_intfdata(interface, NULL); 149 usb_set_intfdata(interface, NULL);
146 150
@@ -155,7 +159,10 @@ static void au0828_usb_disconnect(struct usb_interface *interface)
155static int au0828_usb_probe(struct usb_interface *interface, 159static int au0828_usb_probe(struct usb_interface *interface,
156 const struct usb_device_id *id) 160 const struct usb_device_id *id)
157{ 161{
158 int ifnum, retval; 162 int ifnum;
163#ifdef CONFIG_VIDEO_AU0828_V4L2
164 int retval;
165#endif
159 struct au0828_dev *dev; 166 struct au0828_dev *dev;
160 struct usb_device *usbdev = interface_to_usbdev(interface); 167 struct usb_device *usbdev = interface_to_usbdev(interface);
161 168
@@ -194,6 +201,7 @@ static int au0828_usb_probe(struct usb_interface *interface,
194 dev->usbdev = usbdev; 201 dev->usbdev = usbdev;
195 dev->boardnr = id->driver_info; 202 dev->boardnr = id->driver_info;
196 203
204#ifdef CONFIG_VIDEO_AU0828_V4L2
197 /* Create the v4l2_device */ 205 /* Create the v4l2_device */
198 retval = v4l2_device_register(&interface->dev, &dev->v4l2_dev); 206 retval = v4l2_device_register(&interface->dev, &dev->v4l2_dev);
199 if (retval) { 207 if (retval) {
@@ -203,6 +211,7 @@ static int au0828_usb_probe(struct usb_interface *interface,
203 kfree(dev); 211 kfree(dev);
204 return -EIO; 212 return -EIO;
205 } 213 }
214#endif
206 215
207 /* Power Up the bridge */ 216 /* Power Up the bridge */
208 au0828_write(dev, REG_600, 1 << 4); 217 au0828_write(dev, REG_600, 1 << 4);
@@ -216,9 +225,11 @@ static int au0828_usb_probe(struct usb_interface *interface,
216 /* Setup */ 225 /* Setup */
217 au0828_card_setup(dev); 226 au0828_card_setup(dev);
218 227
228#ifdef CONFIG_VIDEO_AU0828_V4L2
219 /* Analog TV */ 229 /* Analog TV */
220 if (AUVI_INPUT(0).type != AU0828_VMUX_UNDEFINED) 230 if (AUVI_INPUT(0).type != AU0828_VMUX_UNDEFINED)
221 au0828_analog_register(dev, interface); 231 au0828_analog_register(dev, interface);
232#endif
222 233
223 /* Digital TV */ 234 /* Digital TV */
224 au0828_dvb_register(dev); 235 au0828_dvb_register(dev);
diff --git a/drivers/media/usb/au0828/au0828-i2c.c b/drivers/media/usb/au0828/au0828-i2c.c
index 4ded17fe1957..17ec3651b10e 100644
--- a/drivers/media/usb/au0828/au0828-i2c.c
+++ b/drivers/media/usb/au0828/au0828-i2c.c
@@ -364,12 +364,9 @@ int au0828_i2c_register(struct au0828_dev *dev)
364{ 364{
365 dprintk(1, "%s()\n", __func__); 365 dprintk(1, "%s()\n", __func__);
366 366
367 memcpy(&dev->i2c_adap, &au0828_i2c_adap_template, 367 dev->i2c_adap = au0828_i2c_adap_template;
368 sizeof(dev->i2c_adap)); 368 dev->i2c_algo = au0828_i2c_algo_template;
369 memcpy(&dev->i2c_algo, &au0828_i2c_algo_template, 369 dev->i2c_client = au0828_i2c_client_template;
370 sizeof(dev->i2c_algo));
371 memcpy(&dev->i2c_client, &au0828_i2c_client_template,
372 sizeof(dev->i2c_client));
373 370
374 dev->i2c_adap.dev.parent = &dev->usbdev->dev; 371 dev->i2c_adap.dev.parent = &dev->usbdev->dev;
375 372
@@ -378,7 +375,11 @@ int au0828_i2c_register(struct au0828_dev *dev)
378 375
379 dev->i2c_adap.algo = &dev->i2c_algo; 376 dev->i2c_adap.algo = &dev->i2c_algo;
380 dev->i2c_adap.algo_data = dev; 377 dev->i2c_adap.algo_data = dev;
378#ifdef CONFIG_VIDEO_AU0828_V4L2
381 i2c_set_adapdata(&dev->i2c_adap, &dev->v4l2_dev); 379 i2c_set_adapdata(&dev->i2c_adap, &dev->v4l2_dev);
380#else
381 i2c_set_adapdata(&dev->i2c_adap, dev);
382#endif
382 i2c_add_adapter(&dev->i2c_adap); 383 i2c_add_adapter(&dev->i2c_adap);
383 384
384 dev->i2c_client.adapter = &dev->i2c_adap; 385 dev->i2c_client.adapter = &dev->i2c_adap;
diff --git a/drivers/media/usb/au0828/au0828-video.c b/drivers/media/usb/au0828/au0828-video.c
index 45387aab10c7..8b9e8268e911 100644
--- a/drivers/media/usb/au0828/au0828-video.c
+++ b/drivers/media/usb/au0828/au0828-video.c
@@ -304,7 +304,7 @@ static inline void buffer_filled(struct au0828_dev *dev,
304 304
305 buf->vb.state = VIDEOBUF_DONE; 305 buf->vb.state = VIDEOBUF_DONE;
306 buf->vb.field_count++; 306 buf->vb.field_count++;
307 do_gettimeofday(&buf->vb.ts); 307 v4l2_get_timestamp(&buf->vb.ts);
308 308
309 dev->isoc_ctl.buf = NULL; 309 dev->isoc_ctl.buf = NULL;
310 310
@@ -321,7 +321,7 @@ static inline void vbi_buffer_filled(struct au0828_dev *dev,
321 321
322 buf->vb.state = VIDEOBUF_DONE; 322 buf->vb.state = VIDEOBUF_DONE;
323 buf->vb.field_count++; 323 buf->vb.field_count++;
324 do_gettimeofday(&buf->vb.ts); 324 v4l2_get_timestamp(&buf->vb.ts);
325 325
326 dev->isoc_ctl.vbi_buf = NULL; 326 dev->isoc_ctl.vbi_buf = NULL;
327 327
diff --git a/drivers/media/usb/au0828/au0828.h b/drivers/media/usb/au0828/au0828.h
index 66a56ef7bbe4..e579ff69ca4a 100644
--- a/drivers/media/usb/au0828/au0828.h
+++ b/drivers/media/usb/au0828/au0828.h
@@ -199,8 +199,10 @@ struct au0828_dev {
199 struct au0828_dvb dvb; 199 struct au0828_dvb dvb;
200 struct work_struct restart_streaming; 200 struct work_struct restart_streaming;
201 201
202#ifdef CONFIG_VIDEO_AU0828_V4L2
202 /* Analog */ 203 /* Analog */
203 struct v4l2_device v4l2_dev; 204 struct v4l2_device v4l2_dev;
205#endif
204 int users; 206 int users;
205 unsigned int resources; /* resources in use */ 207 unsigned int resources; /* resources in use */
206 struct video_device *vdev; 208 struct video_device *vdev;
diff --git a/drivers/media/usb/cpia2/cpia2_usb.c b/drivers/media/usb/cpia2/cpia2_usb.c
index 95b5d6e7cdc4..be1719283609 100644
--- a/drivers/media/usb/cpia2/cpia2_usb.c
+++ b/drivers/media/usb/cpia2/cpia2_usb.c
@@ -328,7 +328,7 @@ static void cpia2_usb_complete(struct urb *urb)
328 continue; 328 continue;
329 } 329 }
330 DBG("Start of frame pattern found\n"); 330 DBG("Start of frame pattern found\n");
331 do_gettimeofday(&cam->workbuff->timestamp); 331 v4l2_get_timestamp(&cam->workbuff->timestamp);
332 cam->workbuff->seq = cam->frame_count++; 332 cam->workbuff->seq = cam->frame_count++;
333 cam->workbuff->data[0] = 0xFF; 333 cam->workbuff->data[0] = 0xFF;
334 cam->workbuff->data[1] = 0xD8; 334 cam->workbuff->data[1] = 0xD8;
diff --git a/drivers/media/usb/cpia2/cpia2_v4l.c b/drivers/media/usb/cpia2/cpia2_v4l.c
index aeb9d2275725..d5d42b6e94be 100644
--- a/drivers/media/usb/cpia2/cpia2_v4l.c
+++ b/drivers/media/usb/cpia2/cpia2_v4l.c
@@ -825,6 +825,8 @@ static int cpia2_querybuf(struct file *file, void *fh, struct v4l2_buffer *buf)
825 else 825 else
826 buf->flags = 0; 826 buf->flags = 0;
827 827
828 buf->flags |= V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
829
828 switch (cam->buffers[buf->index].status) { 830 switch (cam->buffers[buf->index].status) {
829 case FRAME_EMPTY: 831 case FRAME_EMPTY:
830 case FRAME_ERROR: 832 case FRAME_ERROR:
@@ -943,7 +945,8 @@ static int cpia2_dqbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
943 945
944 buf->index = frame; 946 buf->index = frame;
945 buf->bytesused = cam->buffers[buf->index].length; 947 buf->bytesused = cam->buffers[buf->index].length;
946 buf->flags = V4L2_BUF_FLAG_MAPPED | V4L2_BUF_FLAG_DONE; 948 buf->flags = V4L2_BUF_FLAG_MAPPED | V4L2_BUF_FLAG_DONE
949 | V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
947 buf->field = V4L2_FIELD_NONE; 950 buf->field = V4L2_FIELD_NONE;
948 buf->timestamp = cam->buffers[buf->index].timestamp; 951 buf->timestamp = cam->buffers[buf->index].timestamp;
949 buf->sequence = cam->buffers[buf->index].seq; 952 buf->sequence = cam->buffers[buf->index].seq;
diff --git a/drivers/media/usb/cx231xx/cx231xx-417.c b/drivers/media/usb/cx231xx/cx231xx-417.c
index b024e5197a75..28688dbcb609 100644
--- a/drivers/media/usb/cx231xx/cx231xx-417.c
+++ b/drivers/media/usb/cx231xx/cx231xx-417.c
@@ -1291,7 +1291,7 @@ static void buffer_copy(struct cx231xx *dev, char *data, int len, struct urb *ur
1291 1291
1292 buf->vb.state = VIDEOBUF_DONE; 1292 buf->vb.state = VIDEOBUF_DONE;
1293 buf->vb.field_count++; 1293 buf->vb.field_count++;
1294 do_gettimeofday(&buf->vb.ts); 1294 v4l2_get_timestamp(&buf->vb.ts);
1295 list_del(&buf->vb.queue); 1295 list_del(&buf->vb.queue);
1296 wake_up(&buf->vb.done); 1296 wake_up(&buf->vb.done);
1297 dma_q->mpeg_buffer_completed = 0; 1297 dma_q->mpeg_buffer_completed = 0;
@@ -1327,7 +1327,7 @@ static void buffer_filled(char *data, int len, struct urb *urb,
1327 memcpy(vbuf, data, len); 1327 memcpy(vbuf, data, len);
1328 buf->vb.state = VIDEOBUF_DONE; 1328 buf->vb.state = VIDEOBUF_DONE;
1329 buf->vb.field_count++; 1329 buf->vb.field_count++;
1330 do_gettimeofday(&buf->vb.ts); 1330 v4l2_get_timestamp(&buf->vb.ts);
1331 list_del(&buf->vb.queue); 1331 list_del(&buf->vb.queue);
1332 wake_up(&buf->vb.done); 1332 wake_up(&buf->vb.done);
1333 1333
diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c b/drivers/media/usb/cx231xx/cx231xx-cards.c
index bbed1e40eeda..8d529565f163 100644
--- a/drivers/media/usb/cx231xx/cx231xx-cards.c
+++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
@@ -603,6 +603,33 @@ struct cx231xx_board cx231xx_boards[] = {
603 .gpio = NULL, 603 .gpio = NULL,
604 } }, 604 } },
605 }, 605 },
606 [CX231XX_BOARD_ELGATO_VIDEO_CAPTURE_V2] = {
607 .name = "Elgato Video Capture V2",
608 .tuner_type = TUNER_ABSENT,
609 .decoder = CX231XX_AVDECODER,
610 .output_mode = OUT_MODE_VIP11,
611 .demod_xfer_mode = 0,
612 .ctl_pin_status_mask = 0xFFFFFFC4,
613 .agc_analog_digital_select_gpio = 0x0c,
614 .gpio_pin_status_mask = 0x4001000,
615 .norm = V4L2_STD_NTSC,
616 .no_alt_vanc = 1,
617 .external_av = 1,
618 .dont_use_port_3 = 1,
619 .input = {{
620 .type = CX231XX_VMUX_COMPOSITE1,
621 .vmux = CX231XX_VIN_2_1,
622 .amux = CX231XX_AMUX_LINE_IN,
623 .gpio = NULL,
624 }, {
625 .type = CX231XX_VMUX_SVIDEO,
626 .vmux = CX231XX_VIN_1_1 |
627 (CX231XX_VIN_1_2 << 8) |
628 CX25840_SVIDEO_ON,
629 .amux = CX231XX_AMUX_LINE_IN,
630 .gpio = NULL,
631 } },
632 },
606}; 633};
607const unsigned int cx231xx_bcount = ARRAY_SIZE(cx231xx_boards); 634const unsigned int cx231xx_bcount = ARRAY_SIZE(cx231xx_boards);
608 635
@@ -642,6 +669,8 @@ struct usb_device_id cx231xx_id_table[] = {
642 .driver_info = CX231XX_BOARD_KWORLD_UB430_USB_HYBRID}, 669 .driver_info = CX231XX_BOARD_KWORLD_UB430_USB_HYBRID},
643 {USB_DEVICE(0x1f4d, 0x0237), 670 {USB_DEVICE(0x1f4d, 0x0237),
644 .driver_info = CX231XX_BOARD_ICONBIT_U100}, 671 .driver_info = CX231XX_BOARD_ICONBIT_U100},
672 {USB_DEVICE(0x0fd9, 0x0037),
673 .driver_info = CX231XX_BOARD_ELGATO_VIDEO_CAPTURE_V2},
645 {}, 674 {},
646}; 675};
647 676
@@ -707,7 +736,7 @@ static void cx231xx_sleep_s5h1432(struct cx231xx *dev)
707 736
708static inline void cx231xx_set_model(struct cx231xx *dev) 737static inline void cx231xx_set_model(struct cx231xx *dev)
709{ 738{
710 memcpy(&dev->board, &cx231xx_boards[dev->model], sizeof(dev->board)); 739 dev->board = cx231xx_boards[dev->model];
711} 740}
712 741
713/* Since cx231xx_pre_card_setup() requires a proper dev->model, 742/* Since cx231xx_pre_card_setup() requires a proper dev->model,
diff --git a/drivers/media/usb/cx231xx/cx231xx-vbi.c b/drivers/media/usb/cx231xx/cx231xx-vbi.c
index ac7db52f404f..46e3892557c2 100644
--- a/drivers/media/usb/cx231xx/cx231xx-vbi.c
+++ b/drivers/media/usb/cx231xx/cx231xx-vbi.c
@@ -530,7 +530,7 @@ static inline void vbi_buffer_filled(struct cx231xx *dev,
530 530
531 buf->vb.state = VIDEOBUF_DONE; 531 buf->vb.state = VIDEOBUF_DONE;
532 buf->vb.field_count++; 532 buf->vb.field_count++;
533 do_gettimeofday(&buf->vb.ts); 533 v4l2_get_timestamp(&buf->vb.ts);
534 534
535 dev->vbi_mode.bulk_ctl.buf = NULL; 535 dev->vbi_mode.bulk_ctl.buf = NULL;
536 536
diff --git a/drivers/media/usb/cx231xx/cx231xx-video.c b/drivers/media/usb/cx231xx/cx231xx-video.c
index fedf7852a355..06376d904c9f 100644
--- a/drivers/media/usb/cx231xx/cx231xx-video.c
+++ b/drivers/media/usb/cx231xx/cx231xx-video.c
@@ -235,7 +235,7 @@ static inline void buffer_filled(struct cx231xx *dev,
235 cx231xx_isocdbg("[%p/%d] wakeup\n", buf, buf->vb.i); 235 cx231xx_isocdbg("[%p/%d] wakeup\n", buf, buf->vb.i);
236 buf->vb.state = VIDEOBUF_DONE; 236 buf->vb.state = VIDEOBUF_DONE;
237 buf->vb.field_count++; 237 buf->vb.field_count++;
238 do_gettimeofday(&buf->vb.ts); 238 v4l2_get_timestamp(&buf->vb.ts);
239 239
240 if (dev->USE_ISO) 240 if (dev->USE_ISO)
241 dev->video_mode.isoc_ctl.buf = NULL; 241 dev->video_mode.isoc_ctl.buf = NULL;
@@ -1751,6 +1751,7 @@ static int vidioc_s_register(struct file *file, void *priv,
1751 0x02, 1751 0x02,
1752 (u16)reg->reg, 1, 1752 (u16)reg->reg, 1,
1753 value, 1, 2); 1753 value, 1, 2);
1754 break;
1754 case 0x322: 1755 case 0x322:
1755 ret = 1756 ret =
1756 cx231xx_write_i2c_master(dev, 1757 cx231xx_write_i2c_master(dev,
@@ -2627,8 +2628,7 @@ int cx231xx_register_analog_devices(struct cx231xx *dev)
2627 dev->name, video_device_node_name(dev->vdev)); 2628 dev->name, video_device_node_name(dev->vdev));
2628 2629
2629 /* Initialize VBI template */ 2630 /* Initialize VBI template */
2630 memcpy(&cx231xx_vbi_template, &cx231xx_video_template, 2631 cx231xx_vbi_template = cx231xx_video_template;
2631 sizeof(cx231xx_vbi_template));
2632 strcpy(cx231xx_vbi_template.name, "cx231xx-vbi"); 2632 strcpy(cx231xx_vbi_template.name, "cx231xx-vbi");
2633 2633
2634 /* Allocate and fill vbi video_device struct */ 2634 /* Allocate and fill vbi video_device struct */
diff --git a/drivers/media/usb/cx231xx/cx231xx.h b/drivers/media/usb/cx231xx/cx231xx.h
index a89d020de948..3e11462be0d0 100644
--- a/drivers/media/usb/cx231xx/cx231xx.h
+++ b/drivers/media/usb/cx231xx/cx231xx.h
@@ -68,6 +68,7 @@
68#define CX231XX_BOARD_ICONBIT_U100 13 68#define CX231XX_BOARD_ICONBIT_U100 13
69#define CX231XX_BOARD_HAUPPAUGE_USB2_FM_PAL 14 69#define CX231XX_BOARD_HAUPPAUGE_USB2_FM_PAL 14
70#define CX231XX_BOARD_HAUPPAUGE_USB2_FM_NTSC 15 70#define CX231XX_BOARD_HAUPPAUGE_USB2_FM_NTSC 15
71#define CX231XX_BOARD_ELGATO_VIDEO_CAPTURE_V2 16
71 72
72/* Limits minimum and default number of buffers */ 73/* Limits minimum and default number of buffers */
73#define CX231XX_MIN_BUF 4 74#define CX231XX_MIN_BUF 4
diff --git a/drivers/media/usb/dvb-usb-v2/Kconfig b/drivers/media/usb/dvb-usb-v2/Kconfig
index 7a622dbe9b6d..692224d97d06 100644
--- a/drivers/media/usb/dvb-usb-v2/Kconfig
+++ b/drivers/media/usb/dvb-usb-v2/Kconfig
@@ -1,6 +1,6 @@
1config DVB_USB_V2 1config DVB_USB_V2
2 tristate "Support for various USB DVB devices v2" 2 tristate "Support for various USB DVB devices v2"
3 depends on DVB_CORE && USB && I2C && RC_CORE 3 depends on DVB_CORE && USB && I2C
4 help 4 help
5 By enabling this you will be able to choose the various supported 5 By enabling this you will be able to choose the various supported
6 USB1.1 and USB2.0 DVB devices. 6 USB1.1 and USB2.0 DVB devices.
@@ -113,6 +113,7 @@ config DVB_USB_IT913X
113config DVB_USB_LME2510 113config DVB_USB_LME2510
114 tristate "LME DM04/QQBOX DVB-S USB2.0 support" 114 tristate "LME DM04/QQBOX DVB-S USB2.0 support"
115 depends on DVB_USB_V2 115 depends on DVB_USB_V2
116 depends on RC_CORE
116 select DVB_TDA10086 if MEDIA_SUBDRV_AUTOSELECT 117 select DVB_TDA10086 if MEDIA_SUBDRV_AUTOSELECT
117 select DVB_TDA826X if MEDIA_SUBDRV_AUTOSELECT 118 select DVB_TDA826X if MEDIA_SUBDRV_AUTOSELECT
118 select DVB_STV0288 if MEDIA_SUBDRV_AUTOSELECT 119 select DVB_STV0288 if MEDIA_SUBDRV_AUTOSELECT
@@ -120,6 +121,7 @@ config DVB_USB_LME2510
120 select DVB_STV0299 if MEDIA_SUBDRV_AUTOSELECT 121 select DVB_STV0299 if MEDIA_SUBDRV_AUTOSELECT
121 select DVB_PLL if MEDIA_SUBDRV_AUTOSELECT 122 select DVB_PLL if MEDIA_SUBDRV_AUTOSELECT
122 select DVB_M88RS2000 if MEDIA_SUBDRV_AUTOSELECT 123 select DVB_M88RS2000 if MEDIA_SUBDRV_AUTOSELECT
124 select DVB_TS2020 if MEDIA_SUBDRV_AUTOSELECT
123 help 125 help
124 Say Y here to support the LME DM04/QQBOX DVB-S USB2.0 126 Say Y here to support the LME DM04/QQBOX DVB-S USB2.0
125 127
diff --git a/drivers/media/usb/dvb-usb-v2/af9015.c b/drivers/media/usb/dvb-usb-v2/af9015.c
index 943d93423705..b86d0f27a398 100644
--- a/drivers/media/usb/dvb-usb-v2/af9015.c
+++ b/drivers/media/usb/dvb-usb-v2/af9015.c
@@ -1156,6 +1156,7 @@ error:
1156 return ret; 1156 return ret;
1157} 1157}
1158 1158
1159#if IS_ENABLED(CONFIG_RC_CORE)
1159struct af9015_rc_setup { 1160struct af9015_rc_setup {
1160 unsigned int id; 1161 unsigned int id;
1161 char *rc_codes; 1162 char *rc_codes;
@@ -1312,6 +1313,9 @@ static int af9015_get_rc_config(struct dvb_usb_device *d, struct dvb_usb_rc *rc)
1312 1313
1313 return 0; 1314 return 0;
1314} 1315}
1316#else
1317 #define af9015_get_rc_config NULL
1318#endif
1315 1319
1316/* interface 0 is used by DVB-T receiver and 1320/* interface 0 is used by DVB-T receiver and
1317 interface 1 is for remote controller (HID) */ 1321 interface 1 is for remote controller (HID) */
diff --git a/drivers/media/usb/dvb-usb-v2/af9035.c b/drivers/media/usb/dvb-usb-v2/af9035.c
index 61ae7f9d0b27..f11cc42454f0 100644
--- a/drivers/media/usb/dvb-usb-v2/af9035.c
+++ b/drivers/media/usb/dvb-usb-v2/af9035.c
@@ -209,10 +209,15 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap,
209 if (msg[0].len > 40 || msg[1].len > 40) { 209 if (msg[0].len > 40 || msg[1].len > 40) {
210 /* TODO: correct limits > 40 */ 210 /* TODO: correct limits > 40 */
211 ret = -EOPNOTSUPP; 211 ret = -EOPNOTSUPP;
212 } else if (msg[0].addr == state->af9033_config[0].i2c_addr) { 212 } else if ((msg[0].addr == state->af9033_config[0].i2c_addr) ||
213 /* integrated demod */ 213 (msg[0].addr == state->af9033_config[1].i2c_addr)) {
214 /* demod access via firmware interface */
214 u32 reg = msg[0].buf[0] << 16 | msg[0].buf[1] << 8 | 215 u32 reg = msg[0].buf[0] << 16 | msg[0].buf[1] << 8 |
215 msg[0].buf[2]; 216 msg[0].buf[2];
217
218 if (msg[0].addr == state->af9033_config[1].i2c_addr)
219 reg |= 0x100000;
220
216 ret = af9035_rd_regs(d, reg, &msg[1].buf[0], 221 ret = af9035_rd_regs(d, reg, &msg[1].buf[0],
217 msg[1].len); 222 msg[1].len);
218 } else { 223 } else {
@@ -220,6 +225,7 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap,
220 u8 buf[5 + msg[0].len]; 225 u8 buf[5 + msg[0].len];
221 struct usb_req req = { CMD_I2C_RD, 0, sizeof(buf), 226 struct usb_req req = { CMD_I2C_RD, 0, sizeof(buf),
222 buf, msg[1].len, msg[1].buf }; 227 buf, msg[1].len, msg[1].buf };
228 req.mbox |= ((msg[0].addr & 0x80) >> 3);
223 buf[0] = msg[1].len; 229 buf[0] = msg[1].len;
224 buf[1] = msg[0].addr << 1; 230 buf[1] = msg[0].addr << 1;
225 buf[2] = 0x00; /* reg addr len */ 231 buf[2] = 0x00; /* reg addr len */
@@ -232,10 +238,15 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap,
232 if (msg[0].len > 40) { 238 if (msg[0].len > 40) {
233 /* TODO: correct limits > 40 */ 239 /* TODO: correct limits > 40 */
234 ret = -EOPNOTSUPP; 240 ret = -EOPNOTSUPP;
235 } else if (msg[0].addr == state->af9033_config[0].i2c_addr) { 241 } else if ((msg[0].addr == state->af9033_config[0].i2c_addr) ||
236 /* integrated demod */ 242 (msg[0].addr == state->af9033_config[1].i2c_addr)) {
243 /* demod access via firmware interface */
237 u32 reg = msg[0].buf[0] << 16 | msg[0].buf[1] << 8 | 244 u32 reg = msg[0].buf[0] << 16 | msg[0].buf[1] << 8 |
238 msg[0].buf[2]; 245 msg[0].buf[2];
246
247 if (msg[0].addr == state->af9033_config[1].i2c_addr)
248 reg |= 0x100000;
249
239 ret = af9035_wr_regs(d, reg, &msg[0].buf[3], 250 ret = af9035_wr_regs(d, reg, &msg[0].buf[3],
240 msg[0].len - 3); 251 msg[0].len - 3);
241 } else { 252 } else {
@@ -243,6 +254,7 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap,
243 u8 buf[5 + msg[0].len]; 254 u8 buf[5 + msg[0].len];
244 struct usb_req req = { CMD_I2C_WR, 0, sizeof(buf), buf, 255 struct usb_req req = { CMD_I2C_WR, 0, sizeof(buf), buf,
245 0, NULL }; 256 0, NULL };
257 req.mbox |= ((msg[0].addr & 0x80) >> 3);
246 buf[0] = msg[0].len; 258 buf[0] = msg[0].len;
247 buf[1] = msg[0].addr << 1; 259 buf[1] = msg[0].addr << 1;
248 buf[2] = 0x00; /* reg addr len */ 260 buf[2] = 0x00; /* reg addr len */
@@ -313,12 +325,57 @@ static int af9035_download_firmware(struct dvb_usb_device *d,
313 struct usb_req req = { 0, 0, 0, NULL, 0, NULL }; 325 struct usb_req req = { 0, 0, 0, NULL, 0, NULL };
314 struct usb_req req_fw_dl = { CMD_FW_DL, 0, 0, wbuf, 0, NULL }; 326 struct usb_req req_fw_dl = { CMD_FW_DL, 0, 0, wbuf, 0, NULL };
315 struct usb_req req_fw_ver = { CMD_FW_QUERYINFO, 0, 1, wbuf, 4, rbuf } ; 327 struct usb_req req_fw_ver = { CMD_FW_QUERYINFO, 0, 1, wbuf, 4, rbuf } ;
316 u8 hdr_core; 328 u8 hdr_core, tmp;
317 u16 hdr_addr, hdr_data_len, hdr_checksum; 329 u16 hdr_addr, hdr_data_len, hdr_checksum;
318 #define MAX_DATA 58 330 #define MAX_DATA 58
319 #define HDR_SIZE 7 331 #define HDR_SIZE 7
320 332
321 /* 333 /*
334 * In case of dual tuner configuration we need to do some extra
335 * initialization in order to download firmware to slave demod too,
336 * which is done by master demod.
337 * Master feeds also clock and controls power via GPIO.
338 */
339 ret = af9035_rd_reg(d, EEPROM_DUAL_MODE, &tmp);
340 if (ret < 0)
341 goto err;
342
343 if (tmp) {
344 /* configure gpioh1, reset & power slave demod */
345 ret = af9035_wr_reg_mask(d, 0x00d8b0, 0x01, 0x01);
346 if (ret < 0)
347 goto err;
348
349 ret = af9035_wr_reg_mask(d, 0x00d8b1, 0x01, 0x01);
350 if (ret < 0)
351 goto err;
352
353 ret = af9035_wr_reg_mask(d, 0x00d8af, 0x00, 0x01);
354 if (ret < 0)
355 goto err;
356
357 usleep_range(10000, 50000);
358
359 ret = af9035_wr_reg_mask(d, 0x00d8af, 0x01, 0x01);
360 if (ret < 0)
361 goto err;
362
363 /* tell the slave I2C address */
364 ret = af9035_rd_reg(d, EEPROM_2ND_DEMOD_ADDR, &tmp);
365 if (ret < 0)
366 goto err;
367
368 ret = af9035_wr_reg(d, 0x00417f, tmp);
369 if (ret < 0)
370 goto err;
371
372 /* enable clock out */
373 ret = af9035_wr_reg_mask(d, 0x00d81a, 0x01, 0x01);
374 if (ret < 0)
375 goto err;
376 }
377
378 /*
322 * Thanks to Daniel Glöckner <daniel-gl@gmx.net> about that info! 379 * Thanks to Daniel Glöckner <daniel-gl@gmx.net> about that info!
323 * 380 *
324 * byte 0: MCS 51 core 381 * byte 0: MCS 51 core
@@ -380,6 +437,10 @@ static int af9035_download_firmware(struct dvb_usb_device *d,
380 __func__, fw->size - i); 437 __func__, fw->size - i);
381 } 438 }
382 439
440 /* print warn if firmware is bad, continue and see what happens */
441 if (i)
442 dev_warn(&d->udev->dev, "%s: bad firmware\n", KBUILD_MODNAME);
443
383 /* firmware loaded, request boot */ 444 /* firmware loaded, request boot */
384 req.cmd = CMD_FW_BOOT; 445 req.cmd = CMD_FW_BOOT;
385 ret = af9035_ctrl_msg(d, &req); 446 ret = af9035_ctrl_msg(d, &req);
@@ -489,14 +550,28 @@ static int af9035_read_config(struct dvb_usb_device *d)
489 u8 tmp; 550 u8 tmp;
490 u16 tmp16; 551 u16 tmp16;
491 552
553 /* demod I2C "address" */
554 state->af9033_config[0].i2c_addr = 0x38;
555
492 /* check if there is dual tuners */ 556 /* check if there is dual tuners */
493 ret = af9035_rd_reg(d, EEPROM_DUAL_MODE, &tmp); 557 ret = af9035_rd_reg(d, EEPROM_DUAL_MODE, &tmp);
494 if (ret < 0) 558 if (ret < 0)
495 goto err; 559 goto err;
496 560
497 state->dual_mode = tmp; 561 state->dual_mode = tmp;
498 dev_dbg(&d->udev->dev, "%s: dual mode=%d\n", 562 dev_dbg(&d->udev->dev, "%s: dual mode=%d\n", __func__,
499 __func__, state->dual_mode); 563 state->dual_mode);
564
565 if (state->dual_mode) {
566 /* read 2nd demodulator I2C address */
567 ret = af9035_rd_reg(d, EEPROM_2ND_DEMOD_ADDR, &tmp);
568 if (ret < 0)
569 goto err;
570
571 state->af9033_config[1].i2c_addr = tmp;
572 dev_dbg(&d->udev->dev, "%s: 2nd demod I2C addr=%02x\n",
573 __func__, tmp);
574 }
500 575
501 for (i = 0; i < state->dual_mode + 1; i++) { 576 for (i = 0; i < state->dual_mode + 1; i++) {
502 /* tuner */ 577 /* tuner */
@@ -514,6 +589,7 @@ static int af9035_read_config(struct dvb_usb_device *d)
514 case AF9033_TUNER_MXL5007T: 589 case AF9033_TUNER_MXL5007T:
515 case AF9033_TUNER_TDA18218: 590 case AF9033_TUNER_TDA18218:
516 case AF9033_TUNER_FC2580: 591 case AF9033_TUNER_FC2580:
592 case AF9033_TUNER_FC0012:
517 state->af9033_config[i].spec_inv = 1; 593 state->af9033_config[i].spec_inv = 1;
518 break; 594 break;
519 default: 595 default:
@@ -522,6 +598,18 @@ static int af9035_read_config(struct dvb_usb_device *d)
522 KBUILD_MODNAME, tmp); 598 KBUILD_MODNAME, tmp);
523 } 599 }
524 600
601 /* disable dual mode if driver does not support it */
602 if (i == 1)
603 switch (tmp) {
604 case AF9033_TUNER_FC0012:
605 break;
606 default:
607 state->dual_mode = false;
608 dev_info(&d->udev->dev, "%s: driver does not " \
609 "support 2nd tuner and will " \
610 "disable it", KBUILD_MODNAME);
611 }
612
525 /* tuner IF frequency */ 613 /* tuner IF frequency */
526 ret = af9035_rd_reg(d, EEPROM_1_IFFREQ_L + eeprom_shift, &tmp); 614 ret = af9035_rd_reg(d, EEPROM_1_IFFREQ_L + eeprom_shift, &tmp);
527 if (ret < 0) 615 if (ret < 0)
@@ -730,6 +818,12 @@ static int af9035_frontend_callback(void *adapter_priv, int component,
730 return 0; 818 return 0;
731} 819}
732 820
821static int af9035_get_adapter_count(struct dvb_usb_device *d)
822{
823 struct state *state = d_to_priv(d);
824 return state->dual_mode + 1;
825}
826
733static int af9035_frontend_attach(struct dvb_usb_adapter *adap) 827static int af9035_frontend_attach(struct dvb_usb_adapter *adap)
734{ 828{
735 struct state *state = adap_to_priv(adap); 829 struct state *state = adap_to_priv(adap);
@@ -751,15 +845,14 @@ static int af9035_frontend_attach(struct dvb_usb_adapter *adap)
751 if (ret < 0) 845 if (ret < 0)
752 goto err; 846 goto err;
753 847
754 ret = af9035_wr_reg(d, 0x00d81a, 848 ret = af9035_wr_reg(d, 0x00d81a, state->dual_mode);
755 state->dual_mode);
756 if (ret < 0) 849 if (ret < 0)
757 goto err; 850 goto err;
758 } 851 }
759 852
760 /* attach demodulator */ 853 /* attach demodulator */
761 adap->fe[0] = dvb_attach(af9033_attach, 854 adap->fe[0] = dvb_attach(af9033_attach, &state->af9033_config[adap->id],
762 &state->af9033_config[adap->id], &d->i2c_adap); 855 &d->i2c_adap);
763 if (adap->fe[0] == NULL) { 856 if (adap->fe[0] == NULL) {
764 ret = -ENODEV; 857 ret = -ENODEV;
765 goto err; 858 goto err;
@@ -785,13 +878,22 @@ static const struct fc0011_config af9035_fc0011_config = {
785 .i2c_address = 0x60, 878 .i2c_address = 0x60,
786}; 879};
787 880
788static struct mxl5007t_config af9035_mxl5007t_config = { 881static struct mxl5007t_config af9035_mxl5007t_config[] = {
789 .xtal_freq_hz = MxL_XTAL_24_MHZ, 882 {
790 .if_freq_hz = MxL_IF_4_57_MHZ, 883 .xtal_freq_hz = MxL_XTAL_24_MHZ,
791 .invert_if = 0, 884 .if_freq_hz = MxL_IF_4_57_MHZ,
792 .loop_thru_enable = 0, 885 .invert_if = 0,
793 .clk_out_enable = 0, 886 .loop_thru_enable = 0,
794 .clk_out_amp = MxL_CLKOUT_AMP_0_94V, 887 .clk_out_enable = 0,
888 .clk_out_amp = MxL_CLKOUT_AMP_0_94V,
889 }, {
890 .xtal_freq_hz = MxL_XTAL_24_MHZ,
891 .if_freq_hz = MxL_IF_4_57_MHZ,
892 .invert_if = 0,
893 .loop_thru_enable = 1,
894 .clk_out_enable = 1,
895 .clk_out_amp = MxL_CLKOUT_AMP_0_94V,
896 }
795}; 897};
796 898
797static struct tda18218_config af9035_tda18218_config = { 899static struct tda18218_config af9035_tda18218_config = {
@@ -804,12 +906,32 @@ static const struct fc2580_config af9035_fc2580_config = {
804 .clock = 16384000, 906 .clock = 16384000,
805}; 907};
806 908
909static const struct fc0012_config af9035_fc0012_config[] = {
910 {
911 .i2c_address = 0x63,
912 .xtal_freq = FC_XTAL_36_MHZ,
913 .dual_master = true,
914 .loop_through = true,
915 .clock_out = true,
916 }, {
917 .i2c_address = 0x63 | 0x80, /* I2C bus select hack */
918 .xtal_freq = FC_XTAL_36_MHZ,
919 .dual_master = true,
920 }
921};
922
807static int af9035_tuner_attach(struct dvb_usb_adapter *adap) 923static int af9035_tuner_attach(struct dvb_usb_adapter *adap)
808{ 924{
809 struct state *state = adap_to_priv(adap); 925 struct state *state = adap_to_priv(adap);
810 struct dvb_usb_device *d = adap_to_d(adap); 926 struct dvb_usb_device *d = adap_to_d(adap);
811 int ret; 927 int ret;
812 struct dvb_frontend *fe; 928 struct dvb_frontend *fe;
929 struct i2c_msg msg[1];
930 u8 tuner_addr;
931 /*
932 * XXX: Hack used in that function: we abuse unused I2C address bit [7]
933 * to carry info about used I2C bus for dual tuner configuration.
934 */
813 935
814 switch (state->af9033_config[adap->id].tuner) { 936 switch (state->af9033_config[adap->id].tuner) {
815 case AF9033_TUNER_TUA9001: 937 case AF9033_TUNER_TUA9001:
@@ -842,46 +964,59 @@ static int af9035_tuner_attach(struct dvb_usb_adapter *adap)
842 &d->i2c_adap, &af9035_fc0011_config); 964 &d->i2c_adap, &af9035_fc0011_config);
843 break; 965 break;
844 case AF9033_TUNER_MXL5007T: 966 case AF9033_TUNER_MXL5007T:
845 ret = af9035_wr_reg(d, 0x00d8e0, 1); 967 if (adap->id == 0) {
846 if (ret < 0) 968 ret = af9035_wr_reg(d, 0x00d8e0, 1);
847 goto err; 969 if (ret < 0)
848 ret = af9035_wr_reg(d, 0x00d8e1, 1); 970 goto err;
849 if (ret < 0)
850 goto err;
851 ret = af9035_wr_reg(d, 0x00d8df, 0);
852 if (ret < 0)
853 goto err;
854 971
855 msleep(30); 972 ret = af9035_wr_reg(d, 0x00d8e1, 1);
973 if (ret < 0)
974 goto err;
856 975
857 ret = af9035_wr_reg(d, 0x00d8df, 1); 976 ret = af9035_wr_reg(d, 0x00d8df, 0);
858 if (ret < 0) 977 if (ret < 0)
859 goto err; 978 goto err;
860 979
861 msleep(300); 980 msleep(30);
862 981
863 ret = af9035_wr_reg(d, 0x00d8c0, 1); 982 ret = af9035_wr_reg(d, 0x00d8df, 1);
864 if (ret < 0) 983 if (ret < 0)
865 goto err; 984 goto err;
866 ret = af9035_wr_reg(d, 0x00d8c1, 1); 985
867 if (ret < 0) 986 msleep(300);
868 goto err; 987
869 ret = af9035_wr_reg(d, 0x00d8bf, 0); 988 ret = af9035_wr_reg(d, 0x00d8c0, 1);
870 if (ret < 0) 989 if (ret < 0)
871 goto err; 990 goto err;
872 ret = af9035_wr_reg(d, 0x00d8b4, 1); 991
873 if (ret < 0) 992 ret = af9035_wr_reg(d, 0x00d8c1, 1);
874 goto err; 993 if (ret < 0)
875 ret = af9035_wr_reg(d, 0x00d8b5, 1); 994 goto err;
876 if (ret < 0) 995
877 goto err; 996 ret = af9035_wr_reg(d, 0x00d8bf, 0);
878 ret = af9035_wr_reg(d, 0x00d8b3, 1); 997 if (ret < 0)
879 if (ret < 0) 998 goto err;
880 goto err; 999
1000 ret = af9035_wr_reg(d, 0x00d8b4, 1);
1001 if (ret < 0)
1002 goto err;
1003
1004 ret = af9035_wr_reg(d, 0x00d8b5, 1);
1005 if (ret < 0)
1006 goto err;
1007
1008 ret = af9035_wr_reg(d, 0x00d8b3, 1);
1009 if (ret < 0)
1010 goto err;
1011
1012 tuner_addr = 0x60;
1013 } else {
1014 tuner_addr = 0x60 | 0x80; /* I2C bus hack */
1015 }
881 1016
882 /* attach tuner */ 1017 /* attach tuner */
883 fe = dvb_attach(mxl5007t_attach, adap->fe[0], 1018 fe = dvb_attach(mxl5007t_attach, adap->fe[0], &d->i2c_adap,
884 &d->i2c_adap, 0x60, &af9035_mxl5007t_config); 1019 tuner_addr, &af9035_mxl5007t_config[adap->id]);
885 break; 1020 break;
886 case AF9033_TUNER_TDA18218: 1021 case AF9033_TUNER_TDA18218:
887 /* attach tuner */ 1022 /* attach tuner */
@@ -907,6 +1042,46 @@ static int af9035_tuner_attach(struct dvb_usb_adapter *adap)
907 fe = dvb_attach(fc2580_attach, adap->fe[0], 1042 fe = dvb_attach(fc2580_attach, adap->fe[0],
908 &d->i2c_adap, &af9035_fc2580_config); 1043 &d->i2c_adap, &af9035_fc2580_config);
909 break; 1044 break;
1045 case AF9033_TUNER_FC0012:
1046 /*
1047 * AF9035 gpiot2 = FC0012 enable
1048 * XXX: there seems to be something on gpioh8 too, but on my
1049 * my test I didn't find any difference.
1050 */
1051
1052 if (adap->id == 0) {
1053 /* configure gpiot2 as output and high */
1054 ret = af9035_wr_reg_mask(d, 0xd8eb, 0x01, 0x01);
1055 if (ret < 0)
1056 goto err;
1057
1058 ret = af9035_wr_reg_mask(d, 0xd8ec, 0x01, 0x01);
1059 if (ret < 0)
1060 goto err;
1061
1062 ret = af9035_wr_reg_mask(d, 0xd8ed, 0x01, 0x01);
1063 if (ret < 0)
1064 goto err;
1065 } else {
1066 /*
1067 * FIXME: That belongs for the FC0012 driver.
1068 * Write 02 to FC0012 master tuner register 0d directly
1069 * in order to make slave tuner working.
1070 */
1071 msg[0].addr = 0x63;
1072 msg[0].flags = 0;
1073 msg[0].len = 2;
1074 msg[0].buf = "\x0d\x02";
1075 ret = i2c_transfer(&d->i2c_adap, msg, 1);
1076 if (ret < 0)
1077 goto err;
1078 }
1079
1080 usleep_range(10000, 50000);
1081
1082 fe = dvb_attach(fc0012_attach, adap->fe[0], &d->i2c_adap,
1083 &af9035_fc0012_config[adap->id]);
1084 break;
910 default: 1085 default:
911 fe = NULL; 1086 fe = NULL;
912 } 1087 }
@@ -945,8 +1120,8 @@ static int af9035_init(struct dvb_usb_device *d)
945 { 0x00dd8a, (frame_size >> 0) & 0xff, 0xff}, 1120 { 0x00dd8a, (frame_size >> 0) & 0xff, 0xff},
946 { 0x00dd8b, (frame_size >> 8) & 0xff, 0xff}, 1121 { 0x00dd8b, (frame_size >> 8) & 0xff, 0xff},
947 { 0x00dd0d, packet_size, 0xff }, 1122 { 0x00dd0d, packet_size, 0xff },
948 { 0x80f9a3, 0x00, 0x01 }, 1123 { 0x80f9a3, state->dual_mode, 0x01 },
949 { 0x80f9cd, 0x00, 0x01 }, 1124 { 0x80f9cd, state->dual_mode, 0x01 },
950 { 0x80f99d, 0x00, 0x01 }, 1125 { 0x80f99d, 0x00, 0x01 },
951 { 0x80f9a4, 0x00, 0x01 }, 1126 { 0x80f9a4, 0x00, 0x01 },
952 }; 1127 };
@@ -971,6 +1146,7 @@ err:
971 return ret; 1146 return ret;
972} 1147}
973 1148
1149#if IS_ENABLED(CONFIG_RC_CORE)
974static int af9035_rc_query(struct dvb_usb_device *d) 1150static int af9035_rc_query(struct dvb_usb_device *d)
975{ 1151{
976 unsigned int key; 1152 unsigned int key;
@@ -1045,6 +1221,9 @@ err:
1045 1221
1046 return ret; 1222 return ret;
1047} 1223}
1224#else
1225 #define af9035_get_rc_config NULL
1226#endif
1048 1227
1049/* interface 0 is used by DVB-T receiver and 1228/* interface 0 is used by DVB-T receiver and
1050 interface 1 is for remote controller (HID) */ 1229 interface 1 is for remote controller (HID) */
@@ -1068,7 +1247,7 @@ static const struct dvb_usb_device_properties af9035_props = {
1068 .init = af9035_init, 1247 .init = af9035_init,
1069 .get_rc_config = af9035_get_rc_config, 1248 .get_rc_config = af9035_get_rc_config,
1070 1249
1071 .num_adapters = 1, 1250 .get_adapter_count = af9035_get_adapter_count,
1072 .adapter = { 1251 .adapter = {
1073 { 1252 {
1074 .stream = DVB_USB_STREAM_BULK(0x84, 6, 87 * 188), 1253 .stream = DVB_USB_STREAM_BULK(0x84, 6, 87 * 188),
diff --git a/drivers/media/usb/dvb-usb-v2/af9035.h b/drivers/media/usb/dvb-usb-v2/af9035.h
index 75ef1ec13fbf..29f3eec22c2c 100644
--- a/drivers/media/usb/dvb-usb-v2/af9035.h
+++ b/drivers/media/usb/dvb-usb-v2/af9035.h
@@ -26,6 +26,7 @@
26#include "af9033.h" 26#include "af9033.h"
27#include "tua9001.h" 27#include "tua9001.h"
28#include "fc0011.h" 28#include "fc0011.h"
29#include "fc0012.h"
29#include "mxl5007t.h" 30#include "mxl5007t.h"
30#include "tda18218.h" 31#include "tda18218.h"
31#include "fc2580.h" 32#include "fc2580.h"
@@ -53,7 +54,6 @@ struct usb_req {
53struct state { 54struct state {
54 u8 seq; /* packet sequence number */ 55 u8 seq; /* packet sequence number */
55 bool dual_mode; 56 bool dual_mode;
56
57 struct af9033_config af9033_config[2]; 57 struct af9033_config af9033_config[2];
58}; 58};
59 59
@@ -91,6 +91,7 @@ u32 clock_lut_it9135[] = {
91/* EEPROM locations */ 91/* EEPROM locations */
92#define EEPROM_IR_MODE 0x430d 92#define EEPROM_IR_MODE 0x430d
93#define EEPROM_DUAL_MODE 0x4326 93#define EEPROM_DUAL_MODE 0x4326
94#define EEPROM_2ND_DEMOD_ADDR 0x4327
94#define EEPROM_IR_TYPE 0x4329 95#define EEPROM_IR_TYPE 0x4329
95#define EEPROM_1_IFFREQ_L 0x432d 96#define EEPROM_1_IFFREQ_L 0x432d
96#define EEPROM_1_IFFREQ_H 0x432e 97#define EEPROM_1_IFFREQ_H 0x432e
diff --git a/drivers/media/usb/dvb-usb-v2/anysee.c b/drivers/media/usb/dvb-usb-v2/anysee.c
index d05c5b563dac..a20d691d0b63 100644
--- a/drivers/media/usb/dvb-usb-v2/anysee.c
+++ b/drivers/media/usb/dvb-usb-v2/anysee.c
@@ -1019,6 +1019,7 @@ static int anysee_tuner_attach(struct dvb_usb_adapter *adap)
1019 return ret; 1019 return ret;
1020} 1020}
1021 1021
1022#if IS_ENABLED(CONFIG_RC_CORE)
1022static int anysee_rc_query(struct dvb_usb_device *d) 1023static int anysee_rc_query(struct dvb_usb_device *d)
1023{ 1024{
1024 u8 buf[] = {CMD_GET_IR_CODE}; 1025 u8 buf[] = {CMD_GET_IR_CODE};
@@ -1054,6 +1055,9 @@ static int anysee_get_rc_config(struct dvb_usb_device *d, struct dvb_usb_rc *rc)
1054 1055
1055 return 0; 1056 return 0;
1056} 1057}
1058#else
1059 #define anysee_get_rc_config NULL
1060#endif
1057 1061
1058static int anysee_ci_read_attribute_mem(struct dvb_ca_en50221 *ci, int slot, 1062static int anysee_ci_read_attribute_mem(struct dvb_ca_en50221 *ci, int slot,
1059 int addr) 1063 int addr)
diff --git a/drivers/media/usb/dvb-usb-v2/az6007.c b/drivers/media/usb/dvb-usb-v2/az6007.c
index d75dbf27e99e..70ec80d8be71 100644
--- a/drivers/media/usb/dvb-usb-v2/az6007.c
+++ b/drivers/media/usb/dvb-usb-v2/az6007.c
@@ -189,6 +189,7 @@ static int az6007_streaming_ctrl(struct dvb_frontend *fe, int onoff)
189 return az6007_write(d, 0xbc, onoff, 0, NULL, 0); 189 return az6007_write(d, 0xbc, onoff, 0, NULL, 0);
190} 190}
191 191
192#if IS_ENABLED(CONFIG_RC_CORE)
192/* remote control stuff (does not work with my box) */ 193/* remote control stuff (does not work with my box) */
193static int az6007_rc_query(struct dvb_usb_device *d) 194static int az6007_rc_query(struct dvb_usb_device *d)
194{ 195{
@@ -215,6 +216,20 @@ static int az6007_rc_query(struct dvb_usb_device *d)
215 return 0; 216 return 0;
216} 217}
217 218
219static int az6007_get_rc_config(struct dvb_usb_device *d, struct dvb_usb_rc *rc)
220{
221 pr_debug("Getting az6007 Remote Control properties\n");
222
223 rc->allowed_protos = RC_BIT_NEC;
224 rc->query = az6007_rc_query;
225 rc->interval = 400;
226
227 return 0;
228}
229#else
230 #define az6007_get_rc_config NULL
231#endif
232
218static int az6007_ci_read_attribute_mem(struct dvb_ca_en50221 *ca, 233static int az6007_ci_read_attribute_mem(struct dvb_ca_en50221 *ca,
219 int slot, 234 int slot,
220 int address) 235 int address)
@@ -822,17 +837,6 @@ static void az6007_usb_disconnect(struct usb_interface *intf)
822 dvb_usbv2_disconnect(intf); 837 dvb_usbv2_disconnect(intf);
823} 838}
824 839
825static int az6007_get_rc_config(struct dvb_usb_device *d, struct dvb_usb_rc *rc)
826{
827 pr_debug("Getting az6007 Remote Control properties\n");
828
829 rc->allowed_protos = RC_BIT_NEC;
830 rc->query = az6007_rc_query;
831 rc->interval = 400;
832
833 return 0;
834}
835
836static int az6007_download_firmware(struct dvb_usb_device *d, 840static int az6007_download_firmware(struct dvb_usb_device *d,
837 const struct firmware *fw) 841 const struct firmware *fw)
838{ 842{
diff --git a/drivers/media/usb/dvb-usb-v2/dvb_usb.h b/drivers/media/usb/dvb-usb-v2/dvb_usb.h
index 059291b892b8..3cac8bd0b116 100644
--- a/drivers/media/usb/dvb-usb-v2/dvb_usb.h
+++ b/drivers/media/usb/dvb-usb-v2/dvb_usb.h
@@ -347,6 +347,7 @@ struct dvb_usb_adapter {
347 * @props: device properties 347 * @props: device properties
348 * @name: device name 348 * @name: device name
349 * @rc_map: name of rc codes table 349 * @rc_map: name of rc codes table
350 * @rc_polling_active: set when RC polling is active
350 * @udev: pointer to the device's struct usb_device 351 * @udev: pointer to the device's struct usb_device
351 * @intf: pointer to the device's usb interface 352 * @intf: pointer to the device's usb interface
352 * @rc: remote controller configuration 353 * @rc: remote controller configuration
@@ -364,7 +365,7 @@ struct dvb_usb_device {
364 const struct dvb_usb_device_properties *props; 365 const struct dvb_usb_device_properties *props;
365 const char *name; 366 const char *name;
366 const char *rc_map; 367 const char *rc_map;
367 368 bool rc_polling_active;
368 struct usb_device *udev; 369 struct usb_device *udev;
369 struct usb_interface *intf; 370 struct usb_interface *intf;
370 struct dvb_usb_rc rc; 371 struct dvb_usb_rc rc;
diff --git a/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c b/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c
index 671b4fa232b4..086792055912 100644
--- a/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c
+++ b/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c
@@ -102,6 +102,7 @@ static int dvb_usbv2_i2c_exit(struct dvb_usb_device *d)
102 return 0; 102 return 0;
103} 103}
104 104
105#if IS_ENABLED(CONFIG_RC_CORE)
105static void dvb_usb_read_remote_control(struct work_struct *work) 106static void dvb_usb_read_remote_control(struct work_struct *work)
106{ 107{
107 struct dvb_usb_device *d = container_of(work, 108 struct dvb_usb_device *d = container_of(work,
@@ -112,13 +113,16 @@ static void dvb_usb_read_remote_control(struct work_struct *work)
112 * When the parameter has been set to 1 via sysfs while the 113 * When the parameter has been set to 1 via sysfs while the
113 * driver was running, or when bulk mode is enabled after IR init. 114 * driver was running, or when bulk mode is enabled after IR init.
114 */ 115 */
115 if (dvb_usbv2_disable_rc_polling || d->rc.bulk_mode) 116 if (dvb_usbv2_disable_rc_polling || d->rc.bulk_mode) {
117 d->rc_polling_active = false;
116 return; 118 return;
119 }
117 120
118 ret = d->rc.query(d); 121 ret = d->rc.query(d);
119 if (ret < 0) { 122 if (ret < 0) {
120 dev_err(&d->udev->dev, "%s: rc.query() failed=%d\n", 123 dev_err(&d->udev->dev, "%s: rc.query() failed=%d\n",
121 KBUILD_MODNAME, ret); 124 KBUILD_MODNAME, ret);
125 d->rc_polling_active = false;
122 return; /* stop polling */ 126 return; /* stop polling */
123 } 127 }
124 128
@@ -182,6 +186,7 @@ static int dvb_usbv2_remote_init(struct dvb_usb_device *d)
182 d->rc.interval); 186 d->rc.interval);
183 schedule_delayed_work(&d->rc_query_work, 187 schedule_delayed_work(&d->rc_query_work,
184 msecs_to_jiffies(d->rc.interval)); 188 msecs_to_jiffies(d->rc.interval));
189 d->rc_polling_active = true;
185 } 190 }
186 191
187 return 0; 192 return 0;
@@ -202,6 +207,10 @@ static int dvb_usbv2_remote_exit(struct dvb_usb_device *d)
202 207
203 return 0; 208 return 0;
204} 209}
210#else
211 #define dvb_usbv2_remote_init(args...) 0
212 #define dvb_usbv2_remote_exit(args...)
213#endif
205 214
206static void dvb_usb_data_complete(struct usb_data_stream *stream, u8 *buf, 215static void dvb_usb_data_complete(struct usb_data_stream *stream, u8 *buf,
207 size_t len) 216 size_t len)
@@ -959,7 +968,7 @@ int dvb_usbv2_suspend(struct usb_interface *intf, pm_message_t msg)
959 dev_dbg(&d->udev->dev, "%s:\n", __func__); 968 dev_dbg(&d->udev->dev, "%s:\n", __func__);
960 969
961 /* stop remote controller poll */ 970 /* stop remote controller poll */
962 if (d->rc.query && !d->rc.bulk_mode) 971 if (d->rc_polling_active)
963 cancel_delayed_work_sync(&d->rc_query_work); 972 cancel_delayed_work_sync(&d->rc_query_work);
964 973
965 for (i = MAX_NO_OF_ADAPTER_PER_DEVICE - 1; i >= 0; i--) { 974 for (i = MAX_NO_OF_ADAPTER_PER_DEVICE - 1; i >= 0; i--) {
@@ -1006,7 +1015,7 @@ static int dvb_usbv2_resume_common(struct dvb_usb_device *d)
1006 } 1015 }
1007 1016
1008 /* start remote controller poll */ 1017 /* start remote controller poll */
1009 if (d->rc.query && !d->rc.bulk_mode) 1018 if (d->rc_polling_active)
1010 schedule_delayed_work(&d->rc_query_work, 1019 schedule_delayed_work(&d->rc_query_work,
1011 msecs_to_jiffies(d->rc.interval)); 1020 msecs_to_jiffies(d->rc.interval));
1012 1021
diff --git a/drivers/media/usb/dvb-usb-v2/it913x.c b/drivers/media/usb/dvb-usb-v2/it913x.c
index 47204280b8b3..833847995c65 100644
--- a/drivers/media/usb/dvb-usb-v2/it913x.c
+++ b/drivers/media/usb/dvb-usb-v2/it913x.c
@@ -308,7 +308,7 @@ static struct i2c_algorithm it913x_i2c_algo = {
308}; 308};
309 309
310/* Callbacks for DVB USB */ 310/* Callbacks for DVB USB */
311#define IT913X_POLL 250 311#if IS_ENABLED(CONFIG_RC_CORE)
312static int it913x_rc_query(struct dvb_usb_device *d) 312static int it913x_rc_query(struct dvb_usb_device *d)
313{ 313{
314 u8 ibuf[4]; 314 u8 ibuf[4];
@@ -334,6 +334,25 @@ static int it913x_rc_query(struct dvb_usb_device *d)
334 return ret; 334 return ret;
335} 335}
336 336
337static int it913x_get_rc_config(struct dvb_usb_device *d, struct dvb_usb_rc *rc)
338{
339 struct it913x_state *st = d->priv;
340
341 if (st->proprietary_ir == false) {
342 rc->map_name = NULL;
343 return 0;
344 }
345
346 rc->allowed_protos = RC_BIT_NEC;
347 rc->query = it913x_rc_query;
348 rc->interval = 250;
349
350 return 0;
351}
352#else
353 #define it913x_get_rc_config NULL
354#endif
355
337/* Firmware sets raw */ 356/* Firmware sets raw */
338static const char fw_it9135_v1[] = FW_IT9135_V1; 357static const char fw_it9135_v1[] = FW_IT9135_V1;
339static const char fw_it9135_v2[] = FW_IT9135_V2; 358static const char fw_it9135_v2[] = FW_IT9135_V2;
@@ -643,7 +662,8 @@ static int it913x_frontend_attach(struct dvb_usb_adapter *adap)
643 struct it913x_state *st = d->priv; 662 struct it913x_state *st = d->priv;
644 int ret = 0; 663 int ret = 0;
645 u8 adap_addr = I2C_BASE_ADDR + (adap->id << 5); 664 u8 adap_addr = I2C_BASE_ADDR + (adap->id << 5);
646 u16 ep_size = adap->stream.buf_size / 4; 665 u16 ep_size = (adap->pid_filtering) ? TS_BUFFER_SIZE_PID / 4 :
666 TS_BUFFER_SIZE_MAX / 4;
647 u8 pkt_size = 0x80; 667 u8 pkt_size = 0x80;
648 668
649 if (d->udev->speed != USB_SPEED_HIGH) 669 if (d->udev->speed != USB_SPEED_HIGH)
@@ -695,22 +715,6 @@ static int it913x_frontend_attach(struct dvb_usb_adapter *adap)
695} 715}
696 716
697/* DVB USB Driver */ 717/* DVB USB Driver */
698static int it913x_get_rc_config(struct dvb_usb_device *d, struct dvb_usb_rc *rc)
699{
700 struct it913x_state *st = d->priv;
701
702 if (st->proprietary_ir == false) {
703 rc->map_name = NULL;
704 return 0;
705 }
706
707 rc->allowed_protos = RC_BIT_NEC;
708 rc->query = it913x_rc_query;
709 rc->interval = 250;
710
711 return 0;
712}
713
714static int it913x_get_adapter_count(struct dvb_usb_device *d) 718static int it913x_get_adapter_count(struct dvb_usb_device *d)
715{ 719{
716 struct it913x_state *st = d->priv; 720 struct it913x_state *st = d->priv;
@@ -779,6 +783,18 @@ static const struct usb_device_id it913x_id_table[] = {
779 { DVB_USB_DEVICE(USB_VID_ITETECH, USB_PID_ITETECH_IT9135_9006, 783 { DVB_USB_DEVICE(USB_VID_ITETECH, USB_PID_ITETECH_IT9135_9006,
780 &it913x_properties, "ITE 9135(9006) Generic", 784 &it913x_properties, "ITE 9135(9006) Generic",
781 RC_MAP_IT913X_V1) }, 785 RC_MAP_IT913X_V1) },
786 { DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A835B_1835,
787 &it913x_properties, "Avermedia A835B(1835)",
788 RC_MAP_IT913X_V2) },
789 { DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A835B_2835,
790 &it913x_properties, "Avermedia A835B(2835)",
791 RC_MAP_IT913X_V2) },
792 { DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A835B_3835,
793 &it913x_properties, "Avermedia A835B(3835)",
794 RC_MAP_IT913X_V2) },
795 { DVB_USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A835B_4835,
796 &it913x_properties, "Avermedia A835B(4835)",
797 RC_MAP_IT913X_V2) },
782 {} /* Terminating entry */ 798 {} /* Terminating entry */
783}; 799};
784 800
@@ -797,7 +813,7 @@ module_usb_driver(it913x_driver);
797 813
798MODULE_AUTHOR("Malcolm Priestley <tvboxspy@gmail.com>"); 814MODULE_AUTHOR("Malcolm Priestley <tvboxspy@gmail.com>");
799MODULE_DESCRIPTION("it913x USB 2 Driver"); 815MODULE_DESCRIPTION("it913x USB 2 Driver");
800MODULE_VERSION("1.32"); 816MODULE_VERSION("1.33");
801MODULE_LICENSE("GPL"); 817MODULE_LICENSE("GPL");
802MODULE_FIRMWARE(FW_IT9135_V1); 818MODULE_FIRMWARE(FW_IT9135_V1);
803MODULE_FIRMWARE(FW_IT9135_V2); 819MODULE_FIRMWARE(FW_IT9135_V2);
diff --git a/drivers/media/usb/dvb-usb-v2/lmedm04.c b/drivers/media/usb/dvb-usb-v2/lmedm04.c
index 6427ac359f21..f30c58cecbba 100644
--- a/drivers/media/usb/dvb-usb-v2/lmedm04.c
+++ b/drivers/media/usb/dvb-usb-v2/lmedm04.c
@@ -81,6 +81,7 @@
81#include "dvb-pll.h" 81#include "dvb-pll.h"
82#include "z0194a.h" 82#include "z0194a.h"
83#include "m88rs2000.h" 83#include "m88rs2000.h"
84#include "ts2020.h"
84 85
85 86
86#define LME2510_C_S7395 "dvb-usb-lme2510c-s7395.fw"; 87#define LME2510_C_S7395 "dvb-usb-lme2510c-s7395.fw";
@@ -626,8 +627,8 @@ static int lme2510_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
626 gate = 5; 627 gate = 5;
627 628
628 for (i = 0; i < num; i++) { 629 for (i = 0; i < num; i++) {
629 read_o = 1 & (msg[i].flags & I2C_M_RD); 630 read_o = msg[i].flags & I2C_M_RD;
630 read = i+1 < num && (msg[i+1].flags & I2C_M_RD); 631 read = i + 1 < num && msg[i + 1].flags & I2C_M_RD;
631 read |= read_o; 632 read |= read_o;
632 gate = (msg[i].addr == st->i2c_tuner_addr) 633 gate = (msg[i].addr == st->i2c_tuner_addr)
633 ? (read) ? st->i2c_tuner_gate_r 634 ? (read) ? st->i2c_tuner_gate_r
@@ -640,7 +641,8 @@ static int lme2510_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
640 else 641 else
641 obuf[1] = msg[i].len + read + 1; 642 obuf[1] = msg[i].len + read + 1;
642 643
643 obuf[2] = msg[i].addr; 644 obuf[2] = msg[i].addr << 1;
645
644 if (read) { 646 if (read) {
645 if (read_o) 647 if (read_o)
646 len = 3; 648 len = 3;
@@ -894,27 +896,27 @@ static int lme2510_kill_urb(struct usb_data_stream *stream)
894} 896}
895 897
896static struct tda10086_config tda10086_config = { 898static struct tda10086_config tda10086_config = {
897 .demod_address = 0x1c, 899 .demod_address = 0x0e,
898 .invert = 0, 900 .invert = 0,
899 .diseqc_tone = 1, 901 .diseqc_tone = 1,
900 .xtal_freq = TDA10086_XTAL_16M, 902 .xtal_freq = TDA10086_XTAL_16M,
901}; 903};
902 904
903static struct stv0288_config lme_config = { 905static struct stv0288_config lme_config = {
904 .demod_address = 0xd0, 906 .demod_address = 0x68,
905 .min_delay_ms = 15, 907 .min_delay_ms = 15,
906 .inittab = s7395_inittab, 908 .inittab = s7395_inittab,
907}; 909};
908 910
909static struct ix2505v_config lme_tuner = { 911static struct ix2505v_config lme_tuner = {
910 .tuner_address = 0xc0, 912 .tuner_address = 0x60,
911 .min_delay_ms = 100, 913 .min_delay_ms = 100,
912 .tuner_gain = 0x0, 914 .tuner_gain = 0x0,
913 .tuner_chargepump = 0x3, 915 .tuner_chargepump = 0x3,
914}; 916};
915 917
916static struct stv0299_config sharp_z0194_config = { 918static struct stv0299_config sharp_z0194_config = {
917 .demod_address = 0xd0, 919 .demod_address = 0x68,
918 .inittab = sharp_z0194a_inittab, 920 .inittab = sharp_z0194a_inittab,
919 .mclk = 88000000UL, 921 .mclk = 88000000UL,
920 .invert = 0, 922 .invert = 0,
@@ -943,11 +945,15 @@ static int dm04_rs2000_set_ts_param(struct dvb_frontend *fe,
943} 945}
944 946
945static struct m88rs2000_config m88rs2000_config = { 947static struct m88rs2000_config m88rs2000_config = {
946 .demod_addr = 0xd0, 948 .demod_addr = 0x68,
947 .tuner_addr = 0xc0,
948 .set_ts_params = dm04_rs2000_set_ts_param, 949 .set_ts_params = dm04_rs2000_set_ts_param,
949}; 950};
950 951
952static struct ts2020_config ts2020_config = {
953 .tuner_address = 0x60,
954 .clk_out_div = 7,
955};
956
951static int dm04_lme2510_set_voltage(struct dvb_frontend *fe, 957static int dm04_lme2510_set_voltage(struct dvb_frontend *fe,
952 fe_sec_voltage_t voltage) 958 fe_sec_voltage_t voltage)
953{ 959{
@@ -1049,7 +1055,7 @@ static int dm04_lme2510_frontend_attach(struct dvb_usb_adapter *adap)
1049 info("TUN Found Frontend TDA10086"); 1055 info("TUN Found Frontend TDA10086");
1050 st->i2c_tuner_gate_w = 4; 1056 st->i2c_tuner_gate_w = 4;
1051 st->i2c_tuner_gate_r = 4; 1057 st->i2c_tuner_gate_r = 4;
1052 st->i2c_tuner_addr = 0xc0; 1058 st->i2c_tuner_addr = 0x60;
1053 st->tuner_config = TUNER_LG; 1059 st->tuner_config = TUNER_LG;
1054 if (st->dvb_usb_lme2510_firmware != TUNER_LG) { 1060 if (st->dvb_usb_lme2510_firmware != TUNER_LG) {
1055 st->dvb_usb_lme2510_firmware = TUNER_LG; 1061 st->dvb_usb_lme2510_firmware = TUNER_LG;
@@ -1065,7 +1071,7 @@ static int dm04_lme2510_frontend_attach(struct dvb_usb_adapter *adap)
1065 info("FE Found Stv0299"); 1071 info("FE Found Stv0299");
1066 st->i2c_tuner_gate_w = 4; 1072 st->i2c_tuner_gate_w = 4;
1067 st->i2c_tuner_gate_r = 5; 1073 st->i2c_tuner_gate_r = 5;
1068 st->i2c_tuner_addr = 0xc0; 1074 st->i2c_tuner_addr = 0x60;
1069 st->tuner_config = TUNER_S0194; 1075 st->tuner_config = TUNER_S0194;
1070 if (st->dvb_usb_lme2510_firmware != TUNER_S0194) { 1076 if (st->dvb_usb_lme2510_firmware != TUNER_S0194) {
1071 st->dvb_usb_lme2510_firmware = TUNER_S0194; 1077 st->dvb_usb_lme2510_firmware = TUNER_S0194;
@@ -1082,7 +1088,7 @@ static int dm04_lme2510_frontend_attach(struct dvb_usb_adapter *adap)
1082 info("FE Found Stv0288"); 1088 info("FE Found Stv0288");
1083 st->i2c_tuner_gate_w = 4; 1089 st->i2c_tuner_gate_w = 4;
1084 st->i2c_tuner_gate_r = 5; 1090 st->i2c_tuner_gate_r = 5;
1085 st->i2c_tuner_addr = 0xc0; 1091 st->i2c_tuner_addr = 0x60;
1086 st->tuner_config = TUNER_S7395; 1092 st->tuner_config = TUNER_S7395;
1087 if (st->dvb_usb_lme2510_firmware != TUNER_S7395) { 1093 if (st->dvb_usb_lme2510_firmware != TUNER_S7395) {
1088 st->dvb_usb_lme2510_firmware = TUNER_S7395; 1094 st->dvb_usb_lme2510_firmware = TUNER_S7395;
@@ -1097,9 +1103,11 @@ static int dm04_lme2510_frontend_attach(struct dvb_usb_adapter *adap)
1097 1103
1098 if (adap->fe[0]) { 1104 if (adap->fe[0]) {
1099 info("FE Found M88RS2000"); 1105 info("FE Found M88RS2000");
1106 dvb_attach(ts2020_attach, adap->fe[0], &ts2020_config,
1107 &d->i2c_adap);
1100 st->i2c_tuner_gate_w = 5; 1108 st->i2c_tuner_gate_w = 5;
1101 st->i2c_tuner_gate_r = 5; 1109 st->i2c_tuner_gate_r = 5;
1102 st->i2c_tuner_addr = 0xc0; 1110 st->i2c_tuner_addr = 0x60;
1103 st->tuner_config = TUNER_RS2000; 1111 st->tuner_config = TUNER_RS2000;
1104 st->fe_set_voltage = 1112 st->fe_set_voltage =
1105 adap->fe[0]->ops.set_voltage; 1113 adap->fe[0]->ops.set_voltage;
@@ -1144,7 +1152,7 @@ static int dm04_lme2510_tuner(struct dvb_usb_adapter *adap)
1144 1152
1145 switch (st->tuner_config) { 1153 switch (st->tuner_config) {
1146 case TUNER_LG: 1154 case TUNER_LG:
1147 if (dvb_attach(tda826x_attach, adap->fe[0], 0xc0, 1155 if (dvb_attach(tda826x_attach, adap->fe[0], 0x60,
1148 &d->i2c_adap, 1)) 1156 &d->i2c_adap, 1))
1149 ret = st->tuner_config; 1157 ret = st->tuner_config;
1150 break; 1158 break;
@@ -1154,7 +1162,7 @@ static int dm04_lme2510_tuner(struct dvb_usb_adapter *adap)
1154 ret = st->tuner_config; 1162 ret = st->tuner_config;
1155 break; 1163 break;
1156 case TUNER_S0194: 1164 case TUNER_S0194:
1157 if (dvb_attach(dvb_pll_attach , adap->fe[0], 0xc0, 1165 if (dvb_attach(dvb_pll_attach , adap->fe[0], 0x60,
1158 &d->i2c_adap, DVB_PLL_OPERA1)) 1166 &d->i2c_adap, DVB_PLL_OPERA1))
1159 ret = st->tuner_config; 1167 ret = st->tuner_config;
1160 break; 1168 break;
diff --git a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
index a4c302d0aa37..d98387a3c95e 100644
--- a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
+++ b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
@@ -835,6 +835,11 @@ static struct tua9001_config rtl2832u_tua9001_config = {
835 .i2c_addr = 0x60, 835 .i2c_addr = 0x60,
836}; 836};
837 837
838static const struct fc0012_config rtl2832u_fc0012_config = {
839 .i2c_address = 0x63, /* 0xc6 >> 1 */
840 .xtal_freq = FC_XTAL_28_8_MHZ,
841};
842
838static int rtl2832u_tuner_attach(struct dvb_usb_adapter *adap) 843static int rtl2832u_tuner_attach(struct dvb_usb_adapter *adap)
839{ 844{
840 int ret; 845 int ret;
@@ -847,7 +852,7 @@ static int rtl2832u_tuner_attach(struct dvb_usb_adapter *adap)
847 switch (priv->tuner) { 852 switch (priv->tuner) {
848 case TUNER_RTL2832_FC0012: 853 case TUNER_RTL2832_FC0012:
849 fe = dvb_attach(fc0012_attach, adap->fe[0], 854 fe = dvb_attach(fc0012_attach, adap->fe[0],
850 &d->i2c_adap, 0xc6>>1, 0, FC_XTAL_28_8_MHZ); 855 &d->i2c_adap, &rtl2832u_fc0012_config);
851 856
852 /* since fc0012 includs reading the signal strength delegate 857 /* since fc0012 includs reading the signal strength delegate
853 * that to the tuner driver */ 858 * that to the tuner driver */
@@ -1120,7 +1125,7 @@ err:
1120 return ret; 1125 return ret;
1121} 1126}
1122 1127
1123 1128#if IS_ENABLED(CONFIG_RC_CORE)
1124static int rtl2831u_rc_query(struct dvb_usb_device *d) 1129static int rtl2831u_rc_query(struct dvb_usb_device *d)
1125{ 1130{
1126 int ret, i; 1131 int ret, i;
@@ -1203,7 +1208,11 @@ static int rtl2831u_get_rc_config(struct dvb_usb_device *d,
1203 1208
1204 return 0; 1209 return 0;
1205} 1210}
1211#else
1212 #define rtl2831u_get_rc_config NULL
1213#endif
1206 1214
1215#if IS_ENABLED(CONFIG_RC_CORE)
1207static int rtl2832u_rc_query(struct dvb_usb_device *d) 1216static int rtl2832u_rc_query(struct dvb_usb_device *d)
1208{ 1217{
1209 int ret, i; 1218 int ret, i;
@@ -1275,6 +1284,9 @@ static int rtl2832u_get_rc_config(struct dvb_usb_device *d,
1275 1284
1276 return 0; 1285 return 0;
1277} 1286}
1287#else
1288 #define rtl2832u_get_rc_config NULL
1289#endif
1278 1290
1279static const struct dvb_usb_device_properties rtl2831u_props = { 1291static const struct dvb_usb_device_properties rtl2831u_props = {
1280 .driver_name = KBUILD_MODNAME, 1292 .driver_name = KBUILD_MODNAME,
@@ -1333,13 +1345,13 @@ static const struct usb_device_id rtl28xxu_id_table[] = {
1333 { DVB_USB_DEVICE(USB_VID_REALTEK, 0x2838, 1345 { DVB_USB_DEVICE(USB_VID_REALTEK, 0x2838,
1334 &rtl2832u_props, "Realtek RTL2832U reference design", NULL) }, 1346 &rtl2832u_props, "Realtek RTL2832U reference design", NULL) },
1335 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK_BLACK_REV1, 1347 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK_BLACK_REV1,
1336 &rtl2832u_props, "Terratec Cinergy T Stick Black", NULL) }, 1348 &rtl2832u_props, "TerraTec Cinergy T Stick Black", NULL) },
1337 { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_DELOCK_USB2_DVBT, 1349 { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_DELOCK_USB2_DVBT,
1338 &rtl2832u_props, "G-Tek Electronics Group Lifeview LV5TDLX DVB-T", NULL) }, 1350 &rtl2832u_props, "G-Tek Electronics Group Lifeview LV5TDLX DVB-T", NULL) },
1339 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK, 1351 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK,
1340 &rtl2832u_props, "NOXON DAB/DAB+ USB dongle", NULL) }, 1352 &rtl2832u_props, "TerraTec NOXON DAB Stick", NULL) },
1341 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK_REV2, 1353 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK_REV2,
1342 &rtl2832u_props, "NOXON DAB/DAB+ USB dongle (rev 2)", NULL) }, 1354 &rtl2832u_props, "TerraTec NOXON DAB Stick (rev 2)", NULL) },
1343 { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_TREKSTOR_TERRES_2_0, 1355 { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_TREKSTOR_TERRES_2_0,
1344 &rtl2832u_props, "Trekstor DVB-T Stick Terres 2.0", NULL) }, 1356 &rtl2832u_props, "Trekstor DVB-T Stick Terres 2.0", NULL) },
1345 { DVB_USB_DEVICE(USB_VID_DEXATEK, 0x1101, 1357 { DVB_USB_DEVICE(USB_VID_DEXATEK, 0x1101,
@@ -1352,6 +1364,14 @@ static const struct usb_device_id rtl28xxu_id_table[] = {
1352 &rtl2832u_props, "Dexatek DK mini DVB-T Dongle", NULL) }, 1364 &rtl2832u_props, "Dexatek DK mini DVB-T Dongle", NULL) },
1353 { DVB_USB_DEVICE(USB_VID_TERRATEC, 0x00d7, 1365 { DVB_USB_DEVICE(USB_VID_TERRATEC, 0x00d7,
1354 &rtl2832u_props, "TerraTec Cinergy T Stick+", NULL) }, 1366 &rtl2832u_props, "TerraTec Cinergy T Stick+", NULL) },
1367 { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd3a8,
1368 &rtl2832u_props, "ASUS My Cinema-U3100Mini Plus V2", NULL) },
1369 { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd393,
1370 &rtl2832u_props, "GIGABYTE U7300", NULL) },
1371 { DVB_USB_DEVICE(USB_VID_DEXATEK, 0x1104,
1372 &rtl2832u_props, "Digivox Micro Hd", NULL) },
1373 { DVB_USB_DEVICE(USB_VID_COMPRO, 0x0620,
1374 &rtl2832u_props, "Compro VideoMate U620F", NULL) },
1355 { } 1375 { }
1356}; 1376};
1357MODULE_DEVICE_TABLE(usb, rtl28xxu_id_table); 1377MODULE_DEVICE_TABLE(usb, rtl28xxu_id_table);
diff --git a/drivers/media/usb/dvb-usb/Kconfig b/drivers/media/usb/dvb-usb/Kconfig
index fa0b2931d305..c5d95662e2e1 100644
--- a/drivers/media/usb/dvb-usb/Kconfig
+++ b/drivers/media/usb/dvb-usb/Kconfig
@@ -202,8 +202,12 @@ config DVB_USB_TTUSB2
202 select DVB_TDA10086 if MEDIA_SUBDRV_AUTOSELECT 202 select DVB_TDA10086 if MEDIA_SUBDRV_AUTOSELECT
203 select DVB_LNBP21 if MEDIA_SUBDRV_AUTOSELECT 203 select DVB_LNBP21 if MEDIA_SUBDRV_AUTOSELECT
204 select DVB_TDA826X if MEDIA_SUBDRV_AUTOSELECT 204 select DVB_TDA826X if MEDIA_SUBDRV_AUTOSELECT
205 select DVB_TDA10023 if MEDIA_SUBDRV_AUTOSELECT
206 select DVB_TDA10048 if MEDIA_SUBDRV_AUTOSELECT
207 select MEDIA_TUNER_TDA827X if MEDIA_SUBDRV_AUTOSELECT
205 help 208 help
206 Say Y here to support the Pinnacle 400e DVB-S USB2.0 receiver. The 209 Say Y here to support the Pinnacle 400e DVB-S USB2.0 receiver and
210 the TechnoTrend CT-3650 CI DVB-C/T USB2.0 receiver. The
207 firmware protocol used by this module is similar to the one used by the 211 firmware protocol used by this module is similar to the one used by the
208 old ttusb-driver - that's why the module is called dvb-usb-ttusb2. 212 old ttusb-driver - that's why the module is called dvb-usb-ttusb2.
209 213
@@ -267,9 +271,11 @@ config DVB_USB_DW2102
267 select DVB_MT312 if MEDIA_SUBDRV_AUTOSELECT 271 select DVB_MT312 if MEDIA_SUBDRV_AUTOSELECT
268 select DVB_ZL10039 if MEDIA_SUBDRV_AUTOSELECT 272 select DVB_ZL10039 if MEDIA_SUBDRV_AUTOSELECT
269 select DVB_DS3000 if MEDIA_SUBDRV_AUTOSELECT 273 select DVB_DS3000 if MEDIA_SUBDRV_AUTOSELECT
274 select DVB_TS2020 if MEDIA_SUBDRV_AUTOSELECT
270 select DVB_STB6100 if MEDIA_SUBDRV_AUTOSELECT 275 select DVB_STB6100 if MEDIA_SUBDRV_AUTOSELECT
271 select DVB_STV6110 if MEDIA_SUBDRV_AUTOSELECT 276 select DVB_STV6110 if MEDIA_SUBDRV_AUTOSELECT
272 select DVB_STV0900 if MEDIA_SUBDRV_AUTOSELECT 277 select DVB_STV0900 if MEDIA_SUBDRV_AUTOSELECT
278 select DVB_M88RS2000 if MEDIA_SUBDRV_AUTOSELECT
273 help 279 help
274 Say Y here to support the DvbWorld, TeVii, Prof DVB-S/S2 USB2.0 280 Say Y here to support the DvbWorld, TeVii, Prof DVB-S/S2 USB2.0
275 receivers. 281 receivers.
diff --git a/drivers/media/usb/dvb-usb/dib0700_core.c b/drivers/media/usb/dvb-usb/dib0700_core.c
index 19b5ed2825d7..bf2a908d74cf 100644
--- a/drivers/media/usb/dvb-usb/dib0700_core.c
+++ b/drivers/media/usb/dvb-usb/dib0700_core.c
@@ -561,10 +561,7 @@ int dib0700_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
561 } 561 }
562 } 562 }
563 563
564 if (mutex_lock_interruptible(&adap->dev->usb_mutex) < 0) { 564 mutex_lock(&adap->dev->usb_mutex);
565 err("could not acquire lock");
566 return -EINTR;
567 }
568 565
569 st->buf[0] = REQUEST_ENABLE_VIDEO; 566 st->buf[0] = REQUEST_ENABLE_VIDEO;
570 /* this bit gives a kind of command, 567 /* this bit gives a kind of command,
diff --git a/drivers/media/usb/dvb-usb/dvb-usb-init.c b/drivers/media/usb/dvb-usb/dvb-usb-init.c
index 169196ec2d4e..1adf325012f7 100644
--- a/drivers/media/usb/dvb-usb/dvb-usb-init.c
+++ b/drivers/media/usb/dvb-usb/dvb-usb-init.c
@@ -38,41 +38,41 @@ static int dvb_usb_adapter_init(struct dvb_usb_device *d, short *adapter_nrs)
38 38
39 memcpy(&adap->props, &d->props.adapter[n], sizeof(struct dvb_usb_adapter_properties)); 39 memcpy(&adap->props, &d->props.adapter[n], sizeof(struct dvb_usb_adapter_properties));
40 40
41 for (o = 0; o < adap->props.num_frontends; o++) { 41 for (o = 0; o < adap->props.num_frontends; o++) {
42 struct dvb_usb_adapter_fe_properties *props = &adap->props.fe[o]; 42 struct dvb_usb_adapter_fe_properties *props = &adap->props.fe[o];
43 /* speed - when running at FULL speed we need a HW PID filter */ 43 /* speed - when running at FULL speed we need a HW PID filter */
44 if (d->udev->speed == USB_SPEED_FULL && !(props->caps & DVB_USB_ADAP_HAS_PID_FILTER)) { 44 if (d->udev->speed == USB_SPEED_FULL && !(props->caps & DVB_USB_ADAP_HAS_PID_FILTER)) {
45 err("This USB2.0 device cannot be run on a USB1.1 port. (it lacks a hardware PID filter)"); 45 err("This USB2.0 device cannot be run on a USB1.1 port. (it lacks a hardware PID filter)");
46 return -ENODEV; 46 return -ENODEV;
47 } 47 }
48 48
49 if ((d->udev->speed == USB_SPEED_FULL && props->caps & DVB_USB_ADAP_HAS_PID_FILTER) || 49 if ((d->udev->speed == USB_SPEED_FULL && props->caps & DVB_USB_ADAP_HAS_PID_FILTER) ||
50 (props->caps & DVB_USB_ADAP_NEED_PID_FILTERING)) { 50 (props->caps & DVB_USB_ADAP_NEED_PID_FILTERING)) {
51 info("will use the device's hardware PID filter (table count: %d).", props->pid_filter_count); 51 info("will use the device's hardware PID filter (table count: %d).", props->pid_filter_count);
52 adap->fe_adap[o].pid_filtering = 1; 52 adap->fe_adap[o].pid_filtering = 1;
53 adap->fe_adap[o].max_feed_count = props->pid_filter_count; 53 adap->fe_adap[o].max_feed_count = props->pid_filter_count;
54 } else { 54 } else {
55 info("will pass the complete MPEG2 transport stream to the software demuxer."); 55 info("will pass the complete MPEG2 transport stream to the software demuxer.");
56 adap->fe_adap[o].pid_filtering = 0; 56 adap->fe_adap[o].pid_filtering = 0;
57 adap->fe_adap[o].max_feed_count = 255; 57 adap->fe_adap[o].max_feed_count = 255;
58 } 58 }
59 59
60 if (!adap->fe_adap[o].pid_filtering && 60 if (!adap->fe_adap[o].pid_filtering &&
61 dvb_usb_force_pid_filter_usage && 61 dvb_usb_force_pid_filter_usage &&
62 props->caps & DVB_USB_ADAP_HAS_PID_FILTER) { 62 props->caps & DVB_USB_ADAP_HAS_PID_FILTER) {
63 info("pid filter enabled by module option."); 63 info("pid filter enabled by module option.");
64 adap->fe_adap[o].pid_filtering = 1; 64 adap->fe_adap[o].pid_filtering = 1;
65 adap->fe_adap[o].max_feed_count = props->pid_filter_count; 65 adap->fe_adap[o].max_feed_count = props->pid_filter_count;
66 } 66 }
67 67
68 if (props->size_of_priv > 0) { 68 if (props->size_of_priv > 0) {
69 adap->fe_adap[o].priv = kzalloc(props->size_of_priv, GFP_KERNEL); 69 adap->fe_adap[o].priv = kzalloc(props->size_of_priv, GFP_KERNEL);
70 if (adap->fe_adap[o].priv == NULL) { 70 if (adap->fe_adap[o].priv == NULL) {
71 err("no memory for priv for adapter %d fe %d.", n, o); 71 err("no memory for priv for adapter %d fe %d.", n, o);
72 return -ENOMEM; 72 return -ENOMEM;
73 }
73 } 74 }
74 } 75 }
75 }
76 76
77 if (adap->props.size_of_priv > 0) { 77 if (adap->props.size_of_priv > 0) {
78 adap->priv = kzalloc(adap->props.size_of_priv, GFP_KERNEL); 78 adap->priv = kzalloc(adap->props.size_of_priv, GFP_KERNEL);
diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
index 9382895b1b88..9578a6761f1b 100644
--- a/drivers/media/usb/dvb-usb/dw2102.c
+++ b/drivers/media/usb/dvb-usb/dw2102.c
@@ -1,9 +1,9 @@
1/* DVB USB framework compliant Linux driver for the 1/* DVB USB framework compliant Linux driver for the
2 * DVBWorld DVB-S 2101, 2102, DVB-S2 2104, DVB-C 3101, 2 * DVBWorld DVB-S 2101, 2102, DVB-S2 2104, DVB-C 3101,
3 * TeVii S600, S630, S650, S660, S480, 3 * TeVii S600, S630, S650, S660, S480, S421, S632
4 * Prof 1100, 7500, 4 * Prof 1100, 7500,
5 * Geniatech SU3000 Cards 5 * Geniatech SU3000 Cards
6 * Copyright (C) 2008-2011 Igor M. Liplianin (liplianin@me.by) 6 * Copyright (C) 2008-2012 Igor M. Liplianin (liplianin@me.by)
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify it 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 9 * under the terms of the GNU General Public License as published by the
@@ -22,11 +22,14 @@
22#include "tda1002x.h" 22#include "tda1002x.h"
23#include "mt312.h" 23#include "mt312.h"
24#include "zl10039.h" 24#include "zl10039.h"
25#include "ts2020.h"
25#include "ds3000.h" 26#include "ds3000.h"
26#include "stv0900.h" 27#include "stv0900.h"
27#include "stv6110.h" 28#include "stv6110.h"
28#include "stb6100.h" 29#include "stb6100.h"
29#include "stb6100_proc.h" 30#include "stb6100_proc.h"
31#include "m88rs2000.h"
32#include "ts2020.h"
30 33
31#ifndef USB_PID_DW2102 34#ifndef USB_PID_DW2102
32#define USB_PID_DW2102 0x2102 35#define USB_PID_DW2102 0x2102
@@ -68,6 +71,14 @@
68#define USB_PID_PROF_1100 0xb012 71#define USB_PID_PROF_1100 0xb012
69#endif 72#endif
70 73
74#ifndef USB_PID_TEVII_S421
75#define USB_PID_TEVII_S421 0xd421
76#endif
77
78#ifndef USB_PID_TEVII_S632
79#define USB_PID_TEVII_S632 0xd632
80#endif
81
71#define DW210X_READ_MSG 0 82#define DW210X_READ_MSG 0
72#define DW210X_WRITE_MSG 1 83#define DW210X_WRITE_MSG 1
73 84
@@ -80,6 +91,15 @@
80#define DW2102_RC_QUERY (0x1a00) 91#define DW2102_RC_QUERY (0x1a00)
81#define DW2102_LED_CTRL (0x1b00) 92#define DW2102_LED_CTRL (0x1b00)
82 93
94#define DW2101_FIRMWARE "dvb-usb-dw2101.fw"
95#define DW2102_FIRMWARE "dvb-usb-dw2102.fw"
96#define DW2104_FIRMWARE "dvb-usb-dw2104.fw"
97#define DW3101_FIRMWARE "dvb-usb-dw3101.fw"
98#define S630_FIRMWARE "dvb-usb-s630.fw"
99#define S660_FIRMWARE "dvb-usb-s660.fw"
100#define P1100_FIRMWARE "dvb-usb-p1100.fw"
101#define P7500_FIRMWARE "dvb-usb-p7500.fw"
102
83#define err_str "did not find the firmware file. (%s) " \ 103#define err_str "did not find the firmware file. (%s) " \
84 "Please see linux/Documentation/dvb/ for more details " \ 104 "Please see linux/Documentation/dvb/ for more details " \
85 "on firmware-problems." 105 "on firmware-problems."
@@ -534,7 +554,7 @@ static int s6x0_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
534 } 554 }
535 /*case 0x55: cx24116 555 /*case 0x55: cx24116
536 case 0x6a: stv0903 556 case 0x6a: stv0903
537 case 0x68: ds3000, stv0903 557 case 0x68: ds3000, stv0903, rs2000
538 case 0x60: ts2020, stv6110, stb6100 558 case 0x60: ts2020, stv6110, stb6100
539 case 0xa0: eeprom */ 559 case 0xa0: eeprom */
540 default: { 560 default: {
@@ -932,6 +952,17 @@ static struct ds3000_config dw2104_ds3000_config = {
932 .demod_address = 0x68, 952 .demod_address = 0x68,
933}; 953};
934 954
955static struct ts2020_config dw2104_ts2020_config = {
956 .tuner_address = 0x60,
957 .clk_out_div = 1,
958};
959
960static struct ds3000_config s660_ds3000_config = {
961 .demod_address = 0x68,
962 .ci_mode = 1,
963 .set_lock_led = dw210x_led_ctrl,
964};
965
935static struct stv0900_config dw2104a_stv0900_config = { 966static struct stv0900_config dw2104a_stv0900_config = {
936 .demod_address = 0x6a, 967 .demod_address = 0x6a,
937 .demod_mode = 0, 968 .demod_mode = 0,
@@ -981,6 +1012,30 @@ static struct stv0900_config prof_7500_stv0900_config = {
981static struct ds3000_config su3000_ds3000_config = { 1012static struct ds3000_config su3000_ds3000_config = {
982 .demod_address = 0x68, 1013 .demod_address = 0x68,
983 .ci_mode = 1, 1014 .ci_mode = 1,
1015 .set_lock_led = dw210x_led_ctrl,
1016};
1017
1018static u8 m88rs2000_inittab[] = {
1019 DEMOD_WRITE, 0x9a, 0x30,
1020 DEMOD_WRITE, 0x00, 0x01,
1021 WRITE_DELAY, 0x19, 0x00,
1022 DEMOD_WRITE, 0x00, 0x00,
1023 DEMOD_WRITE, 0x9a, 0xb0,
1024 DEMOD_WRITE, 0x81, 0xc1,
1025 DEMOD_WRITE, 0x81, 0x81,
1026 DEMOD_WRITE, 0x86, 0xc6,
1027 DEMOD_WRITE, 0x9a, 0x30,
1028 DEMOD_WRITE, 0xf0, 0x80,
1029 DEMOD_WRITE, 0xf1, 0xbf,
1030 DEMOD_WRITE, 0xb0, 0x45,
1031 DEMOD_WRITE, 0xb2, 0x01,
1032 DEMOD_WRITE, 0x9a, 0xb0,
1033 0xff, 0xaa, 0xff
1034};
1035
1036static struct m88rs2000_config s421_m88rs2000_config = {
1037 .demod_addr = 0x68,
1038 .inittab = m88rs2000_inittab,
984}; 1039};
985 1040
986static int dw2104_frontend_attach(struct dvb_usb_adapter *d) 1041static int dw2104_frontend_attach(struct dvb_usb_adapter *d)
@@ -1033,6 +1088,8 @@ static int dw2104_frontend_attach(struct dvb_usb_adapter *d)
1033 d->fe_adap[0].fe = dvb_attach(ds3000_attach, &dw2104_ds3000_config, 1088 d->fe_adap[0].fe = dvb_attach(ds3000_attach, &dw2104_ds3000_config,
1034 &d->dev->i2c_adap); 1089 &d->dev->i2c_adap);
1035 if (d->fe_adap[0].fe != NULL) { 1090 if (d->fe_adap[0].fe != NULL) {
1091 dvb_attach(ts2020_attach, d->fe_adap[0].fe,
1092 &dw2104_ts2020_config, &d->dev->i2c_adap);
1036 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage; 1093 d->fe_adap[0].fe->ops.set_voltage = dw210x_set_voltage;
1037 info("Attached DS3000!\n"); 1094 info("Attached DS3000!\n");
1038 return 0; 1095 return 0;
@@ -1139,12 +1196,15 @@ static int ds3000_frontend_attach(struct dvb_usb_adapter *d)
1139 struct s6x0_state *st = (struct s6x0_state *)d->dev->priv; 1196 struct s6x0_state *st = (struct s6x0_state *)d->dev->priv;
1140 u8 obuf[] = {7, 1}; 1197 u8 obuf[] = {7, 1};
1141 1198
1142 d->fe_adap[0].fe = dvb_attach(ds3000_attach, &dw2104_ds3000_config, 1199 d->fe_adap[0].fe = dvb_attach(ds3000_attach, &s660_ds3000_config,
1143 &d->dev->i2c_adap); 1200 &d->dev->i2c_adap);
1144 1201
1145 if (d->fe_adap[0].fe == NULL) 1202 if (d->fe_adap[0].fe == NULL)
1146 return -EIO; 1203 return -EIO;
1147 1204
1205 dvb_attach(ts2020_attach, d->fe_adap[0].fe, &dw2104_ts2020_config,
1206 &d->dev->i2c_adap);
1207
1148 st->old_set_voltage = d->fe_adap[0].fe->ops.set_voltage; 1208 st->old_set_voltage = d->fe_adap[0].fe->ops.set_voltage;
1149 d->fe_adap[0].fe->ops.set_voltage = s660_set_voltage; 1209 d->fe_adap[0].fe->ops.set_voltage = s660_set_voltage;
1150 1210
@@ -1182,6 +1242,14 @@ static int su3000_frontend_attach(struct dvb_usb_adapter *d)
1182 err("command 0x0e transfer failed."); 1242 err("command 0x0e transfer failed.");
1183 1243
1184 obuf[0] = 0xe; 1244 obuf[0] = 0xe;
1245 obuf[1] = 0x02;
1246 obuf[2] = 1;
1247
1248 if (dvb_usb_generic_rw(d->dev, obuf, 3, ibuf, 1, 0) < 0)
1249 err("command 0x0e transfer failed.");
1250 msleep(300);
1251
1252 obuf[0] = 0xe;
1185 obuf[1] = 0x83; 1253 obuf[1] = 0x83;
1186 obuf[2] = 0; 1254 obuf[2] = 0;
1187 1255
@@ -1205,9 +1273,40 @@ static int su3000_frontend_attach(struct dvb_usb_adapter *d)
1205 if (d->fe_adap[0].fe == NULL) 1273 if (d->fe_adap[0].fe == NULL)
1206 return -EIO; 1274 return -EIO;
1207 1275
1208 info("Attached DS3000!\n"); 1276 if (dvb_attach(ts2020_attach, d->fe_adap[0].fe,
1277 &dw2104_ts2020_config,
1278 &d->dev->i2c_adap)) {
1279 info("Attached DS3000/TS2020!\n");
1280 return 0;
1281 }
1209 1282
1210 return 0; 1283 info("Failed to attach DS3000/TS2020!\n");
1284 return -EIO;
1285}
1286
1287static int m88rs2000_frontend_attach(struct dvb_usb_adapter *d)
1288{
1289 u8 obuf[] = { 0x51 };
1290 u8 ibuf[] = { 0 };
1291
1292 if (dvb_usb_generic_rw(d->dev, obuf, 1, ibuf, 1, 0) < 0)
1293 err("command 0x51 transfer failed.");
1294
1295 d->fe_adap[0].fe = dvb_attach(m88rs2000_attach, &s421_m88rs2000_config,
1296 &d->dev->i2c_adap);
1297
1298 if (d->fe_adap[0].fe == NULL)
1299 return -EIO;
1300
1301 if (dvb_attach(ts2020_attach, d->fe_adap[0].fe,
1302 &dw2104_ts2020_config,
1303 &d->dev->i2c_adap)) {
1304 info("Attached RS2000/TS2020!\n");
1305 return 0;
1306 }
1307
1308 info("Failed to attach RS2000/TS2020!\n");
1309 return -EIO;
1211} 1310}
1212 1311
1213static int dw2102_tuner_attach(struct dvb_usb_adapter *adap) 1312static int dw2102_tuner_attach(struct dvb_usb_adapter *adap)
@@ -1447,6 +1546,8 @@ enum dw2102_table_entry {
1447 TEVII_S480_1, 1546 TEVII_S480_1,
1448 TEVII_S480_2, 1547 TEVII_S480_2,
1449 X3M_SPC1400HD, 1548 X3M_SPC1400HD,
1549 TEVII_S421,
1550 TEVII_S632,
1450}; 1551};
1451 1552
1452static struct usb_device_id dw2102_table[] = { 1553static struct usb_device_id dw2102_table[] = {
@@ -1465,6 +1566,8 @@ static struct usb_device_id dw2102_table[] = {
1465 [TEVII_S480_1] = {USB_DEVICE(0x9022, USB_PID_TEVII_S480_1)}, 1566 [TEVII_S480_1] = {USB_DEVICE(0x9022, USB_PID_TEVII_S480_1)},
1466 [TEVII_S480_2] = {USB_DEVICE(0x9022, USB_PID_TEVII_S480_2)}, 1567 [TEVII_S480_2] = {USB_DEVICE(0x9022, USB_PID_TEVII_S480_2)},
1467 [X3M_SPC1400HD] = {USB_DEVICE(0x1f4d, 0x3100)}, 1568 [X3M_SPC1400HD] = {USB_DEVICE(0x1f4d, 0x3100)},
1569 [TEVII_S421] = {USB_DEVICE(0x9022, USB_PID_TEVII_S421)},
1570 [TEVII_S632] = {USB_DEVICE(0x9022, USB_PID_TEVII_S632)},
1468 { } 1571 { }
1469}; 1572};
1470 1573
@@ -1478,13 +1581,12 @@ static int dw2102_load_firmware(struct usb_device *dev,
1478 u8 reset; 1581 u8 reset;
1479 u8 reset16[] = {0, 0, 0, 0, 0, 0, 0}; 1582 u8 reset16[] = {0, 0, 0, 0, 0, 0, 0};
1480 const struct firmware *fw; 1583 const struct firmware *fw;
1481 const char *fw_2101 = "dvb-usb-dw2101.fw";
1482 1584
1483 switch (dev->descriptor.idProduct) { 1585 switch (dev->descriptor.idProduct) {
1484 case 0x2101: 1586 case 0x2101:
1485 ret = request_firmware(&fw, fw_2101, &dev->dev); 1587 ret = request_firmware(&fw, DW2101_FIRMWARE, &dev->dev);
1486 if (ret != 0) { 1588 if (ret != 0) {
1487 err(err_str, fw_2101); 1589 err(err_str, DW2101_FIRMWARE);
1488 return ret; 1590 return ret;
1489 } 1591 }
1490 break; 1592 break;
@@ -1586,7 +1688,7 @@ static int dw2102_load_firmware(struct usb_device *dev,
1586static struct dvb_usb_device_properties dw2102_properties = { 1688static struct dvb_usb_device_properties dw2102_properties = {
1587 .caps = DVB_USB_IS_AN_I2C_ADAPTER, 1689 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1588 .usb_ctrl = DEVICE_SPECIFIC, 1690 .usb_ctrl = DEVICE_SPECIFIC,
1589 .firmware = "dvb-usb-dw2102.fw", 1691 .firmware = DW2102_FIRMWARE,
1590 .no_reconnect = 1, 1692 .no_reconnect = 1,
1591 1693
1592 .i2c_algo = &dw2102_serit_i2c_algo, 1694 .i2c_algo = &dw2102_serit_i2c_algo,
@@ -1641,7 +1743,7 @@ static struct dvb_usb_device_properties dw2102_properties = {
1641static struct dvb_usb_device_properties dw2104_properties = { 1743static struct dvb_usb_device_properties dw2104_properties = {
1642 .caps = DVB_USB_IS_AN_I2C_ADAPTER, 1744 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1643 .usb_ctrl = DEVICE_SPECIFIC, 1745 .usb_ctrl = DEVICE_SPECIFIC,
1644 .firmware = "dvb-usb-dw2104.fw", 1746 .firmware = DW2104_FIRMWARE,
1645 .no_reconnect = 1, 1747 .no_reconnect = 1,
1646 1748
1647 .i2c_algo = &dw2104_i2c_algo, 1749 .i2c_algo = &dw2104_i2c_algo,
@@ -1691,7 +1793,7 @@ static struct dvb_usb_device_properties dw2104_properties = {
1691static struct dvb_usb_device_properties dw3101_properties = { 1793static struct dvb_usb_device_properties dw3101_properties = {
1692 .caps = DVB_USB_IS_AN_I2C_ADAPTER, 1794 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1693 .usb_ctrl = DEVICE_SPECIFIC, 1795 .usb_ctrl = DEVICE_SPECIFIC,
1694 .firmware = "dvb-usb-dw3101.fw", 1796 .firmware = DW3101_FIRMWARE,
1695 .no_reconnect = 1, 1797 .no_reconnect = 1,
1696 1798
1697 .i2c_algo = &dw3101_i2c_algo, 1799 .i2c_algo = &dw3101_i2c_algo,
@@ -1739,7 +1841,7 @@ static struct dvb_usb_device_properties s6x0_properties = {
1739 .caps = DVB_USB_IS_AN_I2C_ADAPTER, 1841 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1740 .usb_ctrl = DEVICE_SPECIFIC, 1842 .usb_ctrl = DEVICE_SPECIFIC,
1741 .size_of_priv = sizeof(struct s6x0_state), 1843 .size_of_priv = sizeof(struct s6x0_state),
1742 .firmware = "dvb-usb-s630.fw", 1844 .firmware = S630_FIRMWARE,
1743 .no_reconnect = 1, 1845 .no_reconnect = 1,
1744 1846
1745 .i2c_algo = &s6x0_i2c_algo, 1847 .i2c_algo = &s6x0_i2c_algo,
@@ -1814,6 +1916,19 @@ static struct dvb_usb_device_description d7500 = {
1814 {NULL}, 1916 {NULL},
1815}; 1917};
1816 1918
1919struct dvb_usb_device_properties *s421;
1920static struct dvb_usb_device_description d421 = {
1921 "TeVii S421 PCI",
1922 {&dw2102_table[TEVII_S421], NULL},
1923 {NULL},
1924};
1925
1926static struct dvb_usb_device_description d632 = {
1927 "TeVii S632 USB",
1928 {&dw2102_table[TEVII_S632], NULL},
1929 {NULL},
1930};
1931
1817static struct dvb_usb_device_properties su3000_properties = { 1932static struct dvb_usb_device_properties su3000_properties = {
1818 .caps = DVB_USB_IS_AN_I2C_ADAPTER, 1933 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1819 .usb_ctrl = DEVICE_SPECIFIC, 1934 .usb_ctrl = DEVICE_SPECIFIC,
@@ -1879,7 +1994,7 @@ static int dw2102_probe(struct usb_interface *intf,
1879 return -ENOMEM; 1994 return -ENOMEM;
1880 /* copy default structure */ 1995 /* copy default structure */
1881 /* fill only different fields */ 1996 /* fill only different fields */
1882 p1100->firmware = "dvb-usb-p1100.fw"; 1997 p1100->firmware = P1100_FIRMWARE;
1883 p1100->devices[0] = d1100; 1998 p1100->devices[0] = d1100;
1884 p1100->rc.legacy.rc_map_table = rc_map_tbs_table; 1999 p1100->rc.legacy.rc_map_table = rc_map_tbs_table;
1885 p1100->rc.legacy.rc_map_size = ARRAY_SIZE(rc_map_tbs_table); 2000 p1100->rc.legacy.rc_map_size = ARRAY_SIZE(rc_map_tbs_table);
@@ -1891,7 +2006,7 @@ static int dw2102_probe(struct usb_interface *intf,
1891 kfree(p1100); 2006 kfree(p1100);
1892 return -ENOMEM; 2007 return -ENOMEM;
1893 } 2008 }
1894 s660->firmware = "dvb-usb-s660.fw"; 2009 s660->firmware = S660_FIRMWARE;
1895 s660->num_device_descs = 3; 2010 s660->num_device_descs = 3;
1896 s660->devices[0] = d660; 2011 s660->devices[0] = d660;
1897 s660->devices[1] = d480_1; 2012 s660->devices[1] = d480_1;
@@ -1905,12 +2020,26 @@ static int dw2102_probe(struct usb_interface *intf,
1905 kfree(s660); 2020 kfree(s660);
1906 return -ENOMEM; 2021 return -ENOMEM;
1907 } 2022 }
1908 p7500->firmware = "dvb-usb-p7500.fw"; 2023 p7500->firmware = P7500_FIRMWARE;
1909 p7500->devices[0] = d7500; 2024 p7500->devices[0] = d7500;
1910 p7500->rc.legacy.rc_map_table = rc_map_tbs_table; 2025 p7500->rc.legacy.rc_map_table = rc_map_tbs_table;
1911 p7500->rc.legacy.rc_map_size = ARRAY_SIZE(rc_map_tbs_table); 2026 p7500->rc.legacy.rc_map_size = ARRAY_SIZE(rc_map_tbs_table);
1912 p7500->adapter->fe[0].frontend_attach = prof_7500_frontend_attach; 2027 p7500->adapter->fe[0].frontend_attach = prof_7500_frontend_attach;
1913 2028
2029
2030 s421 = kmemdup(&su3000_properties,
2031 sizeof(struct dvb_usb_device_properties), GFP_KERNEL);
2032 if (!s421) {
2033 kfree(p1100);
2034 kfree(s660);
2035 kfree(p7500);
2036 return -ENOMEM;
2037 }
2038 s421->num_device_descs = 2;
2039 s421->devices[0] = d421;
2040 s421->devices[1] = d632;
2041 s421->adapter->fe[0].frontend_attach = m88rs2000_frontend_attach;
2042
1914 if (0 == dvb_usb_device_init(intf, &dw2102_properties, 2043 if (0 == dvb_usb_device_init(intf, &dw2102_properties,
1915 THIS_MODULE, NULL, adapter_nr) || 2044 THIS_MODULE, NULL, adapter_nr) ||
1916 0 == dvb_usb_device_init(intf, &dw2104_properties, 2045 0 == dvb_usb_device_init(intf, &dw2104_properties,
@@ -1925,6 +2054,8 @@ static int dw2102_probe(struct usb_interface *intf,
1925 THIS_MODULE, NULL, adapter_nr) || 2054 THIS_MODULE, NULL, adapter_nr) ||
1926 0 == dvb_usb_device_init(intf, p7500, 2055 0 == dvb_usb_device_init(intf, p7500,
1927 THIS_MODULE, NULL, adapter_nr) || 2056 THIS_MODULE, NULL, adapter_nr) ||
2057 0 == dvb_usb_device_init(intf, s421,
2058 THIS_MODULE, NULL, adapter_nr) ||
1928 0 == dvb_usb_device_init(intf, &su3000_properties, 2059 0 == dvb_usb_device_init(intf, &su3000_properties,
1929 THIS_MODULE, NULL, adapter_nr)) 2060 THIS_MODULE, NULL, adapter_nr))
1930 return 0; 2061 return 0;
@@ -1943,9 +2074,17 @@ module_usb_driver(dw2102_driver);
1943 2074
1944MODULE_AUTHOR("Igor M. Liplianin (c) liplianin@me.by"); 2075MODULE_AUTHOR("Igor M. Liplianin (c) liplianin@me.by");
1945MODULE_DESCRIPTION("Driver for DVBWorld DVB-S 2101, 2102, DVB-S2 2104," 2076MODULE_DESCRIPTION("Driver for DVBWorld DVB-S 2101, 2102, DVB-S2 2104,"
1946 " DVB-C 3101 USB2.0," 2077 " DVB-C 3101 USB2.0,"
1947 " TeVii S600, S630, S650, S660, S480," 2078 " TeVii S600, S630, S650, S660, S480, S421, S632"
1948 " Prof 1100, 7500 USB2.0," 2079 " Prof 1100, 7500 USB2.0,"
1949 " Geniatech SU3000 devices"); 2080 " Geniatech SU3000 devices");
1950MODULE_VERSION("0.1"); 2081MODULE_VERSION("0.1");
1951MODULE_LICENSE("GPL"); 2082MODULE_LICENSE("GPL");
2083MODULE_FIRMWARE(DW2101_FIRMWARE);
2084MODULE_FIRMWARE(DW2102_FIRMWARE);
2085MODULE_FIRMWARE(DW2104_FIRMWARE);
2086MODULE_FIRMWARE(DW3101_FIRMWARE);
2087MODULE_FIRMWARE(S630_FIRMWARE);
2088MODULE_FIRMWARE(S660_FIRMWARE);
2089MODULE_FIRMWARE(P1100_FIRMWARE);
2090MODULE_FIRMWARE(P7500_FIRMWARE);
diff --git a/drivers/media/usb/dvb-usb/friio-fe.c b/drivers/media/usb/dvb-usb/friio-fe.c
index 90a70c66a96e..d56f927fc31a 100644
--- a/drivers/media/usb/dvb-usb/friio-fe.c
+++ b/drivers/media/usb/dvb-usb/friio-fe.c
@@ -421,11 +421,10 @@ struct dvb_frontend *jdvbt90502_attach(struct dvb_usb_device *d)
421 421
422 /* setup the state */ 422 /* setup the state */
423 state->i2c = &d->i2c_adap; 423 state->i2c = &d->i2c_adap;
424 memcpy(&state->config, &friio_fe_config, sizeof(friio_fe_config)); 424 state->config = friio_fe_config;
425 425
426 /* create dvb_frontend */ 426 /* create dvb_frontend */
427 memcpy(&state->frontend.ops, &jdvbt90502_ops, 427 state->frontend.ops = jdvbt90502_ops;
428 sizeof(jdvbt90502_ops));
429 state->frontend.demodulator_priv = state; 428 state->frontend.demodulator_priv = state;
430 429
431 if (jdvbt90502_init(&state->frontend) < 0) 430 if (jdvbt90502_init(&state->frontend) < 0)
diff --git a/drivers/media/usb/dvb-usb/m920x.c b/drivers/media/usb/dvb-usb/m920x.c
index 661bb75be955..92afeb20650f 100644
--- a/drivers/media/usb/dvb-usb/m920x.c
+++ b/drivers/media/usb/dvb-usb/m920x.c
@@ -16,6 +16,7 @@
16#include "qt1010.h" 16#include "qt1010.h"
17#include "tda1004x.h" 17#include "tda1004x.h"
18#include "tda827x.h" 18#include "tda827x.h"
19#include "mt2060.h"
19 20
20#include <media/tuner.h> 21#include <media/tuner.h>
21#include "tuner-simple.h" 22#include "tuner-simple.h"
@@ -63,23 +64,33 @@ static inline int m920x_write(struct usb_device *udev, u8 request,
63 return ret; 64 return ret;
64} 65}
65 66
67static inline int m920x_write_seq(struct usb_device *udev, u8 request,
68 struct m920x_inits *seq)
69{
70 int ret;
71 while (seq->address) {
72 ret = m920x_write(udev, request, seq->data, seq->address);
73 if (ret != 0)
74 return ret;
75
76 seq++;
77 }
78
79 return ret;
80}
81
66static int m920x_init(struct dvb_usb_device *d, struct m920x_inits *rc_seq) 82static int m920x_init(struct dvb_usb_device *d, struct m920x_inits *rc_seq)
67{ 83{
68 int ret = 0, i, epi, flags = 0; 84 int ret = 0, i, epi, flags = 0;
69 int adap_enabled[M9206_MAX_ADAPTERS] = { 0 }; 85 int adap_enabled[M9206_MAX_ADAPTERS] = { 0 };
70 86
71 /* Remote controller init. */ 87 /* Remote controller init. */
72 if (d->props.rc.legacy.rc_query) { 88 if (d->props.rc.legacy.rc_query || d->props.rc.core.rc_query) {
73 deb("Initialising remote control\n"); 89 deb("Initialising remote control\n");
74 while (rc_seq->address) { 90 ret = m920x_write_seq(d->udev, M9206_CORE, rc_seq);
75 if ((ret = m920x_write(d->udev, M9206_CORE, 91 if (ret != 0) {
76 rc_seq->data, 92 deb("Initialising remote control failed\n");
77 rc_seq->address)) != 0) { 93 return ret;
78 deb("Initialising remote control failed\n");
79 return ret;
80 }
81
82 rc_seq++;
83 } 94 }
84 95
85 deb("Initialising remote control success\n"); 96 deb("Initialising remote control success\n");
@@ -130,9 +141,50 @@ static int m920x_init_ep(struct usb_interface *intf)
130 alt->desc.bAlternateSetting); 141 alt->desc.bAlternateSetting);
131} 142}
132 143
133static int m920x_rc_query(struct dvb_usb_device *d, u32 *event, int *state) 144static inline void m920x_parse_rc_state(struct dvb_usb_device *d, u8 rc_state,
145 int *state)
134{ 146{
135 struct m920x_state *m = d->priv; 147 struct m920x_state *m = d->priv;
148
149 switch (rc_state) {
150 case 0x80:
151 *state = REMOTE_NO_KEY_PRESSED;
152 break;
153
154 case 0x88: /* framing error or "invalid code" */
155 case 0x99:
156 case 0xc0:
157 case 0xd8:
158 *state = REMOTE_NO_KEY_PRESSED;
159 m->rep_count = 0;
160 break;
161
162 case 0x93:
163 case 0x92:
164 case 0x83: /* pinnacle PCTV310e */
165 case 0x82:
166 m->rep_count = 0;
167 *state = REMOTE_KEY_PRESSED;
168 break;
169
170 case 0x91:
171 case 0x81: /* pinnacle PCTV310e */
172 /* prevent immediate auto-repeat */
173 if (++m->rep_count > 2)
174 *state = REMOTE_KEY_REPEAT;
175 else
176 *state = REMOTE_NO_KEY_PRESSED;
177 break;
178
179 default:
180 deb("Unexpected rc state %02x\n", rc_state);
181 *state = REMOTE_NO_KEY_PRESSED;
182 break;
183 }
184}
185
186static int m920x_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
187{
136 int i, ret = 0; 188 int i, ret = 0;
137 u8 *rc_state; 189 u8 *rc_state;
138 190
@@ -140,51 +192,22 @@ static int m920x_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
140 if (!rc_state) 192 if (!rc_state)
141 return -ENOMEM; 193 return -ENOMEM;
142 194
143 if ((ret = m920x_read(d->udev, M9206_CORE, 0x0, M9206_RC_STATE, rc_state, 1)) != 0) 195 ret = m920x_read(d->udev, M9206_CORE, 0x0, M9206_RC_STATE,
196 rc_state, 1);
197 if (ret != 0)
144 goto out; 198 goto out;
145 199
146 if ((ret = m920x_read(d->udev, M9206_CORE, 0x0, M9206_RC_KEY, rc_state + 1, 1)) != 0) 200 ret = m920x_read(d->udev, M9206_CORE, 0x0, M9206_RC_KEY,
201 rc_state + 1, 1);
202 if (ret != 0)
147 goto out; 203 goto out;
148 204
205 m920x_parse_rc_state(d, rc_state[0], state);
206
149 for (i = 0; i < d->props.rc.legacy.rc_map_size; i++) 207 for (i = 0; i < d->props.rc.legacy.rc_map_size; i++)
150 if (rc5_data(&d->props.rc.legacy.rc_map_table[i]) == rc_state[1]) { 208 if (rc5_data(&d->props.rc.legacy.rc_map_table[i]) == rc_state[1]) {
151 *event = d->props.rc.legacy.rc_map_table[i].keycode; 209 *event = d->props.rc.legacy.rc_map_table[i].keycode;
152 210 goto out;
153 switch(rc_state[0]) {
154 case 0x80:
155 *state = REMOTE_NO_KEY_PRESSED;
156 goto out;
157
158 case 0x88: /* framing error or "invalid code" */
159 case 0x99:
160 case 0xc0:
161 case 0xd8:
162 *state = REMOTE_NO_KEY_PRESSED;
163 m->rep_count = 0;
164 goto out;
165
166 case 0x93:
167 case 0x92:
168 case 0x83: /* pinnacle PCTV310e */
169 case 0x82:
170 m->rep_count = 0;
171 *state = REMOTE_KEY_PRESSED;
172 goto out;
173
174 case 0x91:
175 case 0x81: /* pinnacle PCTV310e */
176 /* prevent immediate auto-repeat */
177 if (++m->rep_count > 2)
178 *state = REMOTE_KEY_REPEAT;
179 else
180 *state = REMOTE_NO_KEY_PRESSED;
181 goto out;
182
183 default:
184 deb("Unexpected rc state %02x\n", rc_state[0]);
185 *state = REMOTE_NO_KEY_PRESSED;
186 goto out;
187 }
188 } 211 }
189 212
190 if (rc_state[1] != 0) 213 if (rc_state[1] != 0)
@@ -197,6 +220,38 @@ static int m920x_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
197 return ret; 220 return ret;
198} 221}
199 222
223static int m920x_rc_core_query(struct dvb_usb_device *d)
224{
225 int ret = 0;
226 u8 *rc_state;
227 int state;
228
229 rc_state = kmalloc(2, GFP_KERNEL);
230 if (!rc_state)
231 return -ENOMEM;
232
233 if ((ret = m920x_read(d->udev, M9206_CORE, 0x0, M9206_RC_STATE, &rc_state[0], 1)) != 0)
234 goto out;
235
236 if ((ret = m920x_read(d->udev, M9206_CORE, 0x0, M9206_RC_KEY, &rc_state[1], 1)) != 0)
237 goto out;
238
239 deb("state=0x%02x keycode=0x%02x\n", rc_state[0], rc_state[1]);
240
241 m920x_parse_rc_state(d, rc_state[0], &state);
242
243 if (state == REMOTE_NO_KEY_PRESSED)
244 rc_keyup(d->rc_dev);
245 else if (state == REMOTE_KEY_REPEAT)
246 rc_repeat(d->rc_dev);
247 else
248 rc_keydown(d->rc_dev, rc_state[1], 0);
249
250out:
251 kfree(rc_state);
252 return ret;
253}
254
200/* I2C */ 255/* I2C */
201static int m920x_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num) 256static int m920x_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
202{ 257{
@@ -496,6 +551,12 @@ static struct qt1010_config m920x_qt1010_config = {
496 .i2c_address = 0x62 551 .i2c_address = 0x62
497}; 552};
498 553
554static struct mt2060_config m920x_mt2060_config = {
555 .i2c_address = 0x60, /* 0xc0 */
556 .clock_out = 0,
557};
558
559
499/* Callbacks for DVB USB */ 560/* Callbacks for DVB USB */
500static int m920x_mt352_frontend_attach(struct dvb_usb_adapter *adap) 561static int m920x_mt352_frontend_attach(struct dvb_usb_adapter *adap)
501{ 562{
@@ -510,6 +571,37 @@ static int m920x_mt352_frontend_attach(struct dvb_usb_adapter *adap)
510 return 0; 571 return 0;
511} 572}
512 573
574static int m920x_mt352_frontend_attach_vp7049(struct dvb_usb_adapter *adap)
575{
576 struct m920x_inits vp7049_fe_init_seq[] = {
577 /* XXX without these commands the frontend cannot be detected,
578 * they must be sent BEFORE the frontend is attached */
579 { 0xff28, 0x00 },
580 { 0xff23, 0x00 },
581 { 0xff28, 0x00 },
582 { 0xff23, 0x00 },
583 { 0xff21, 0x20 },
584 { 0xff21, 0x60 },
585 { 0xff28, 0x00 },
586 { 0xff22, 0x00 },
587 { 0xff20, 0x30 },
588 { 0xff20, 0x20 },
589 { 0xff20, 0x30 },
590 { } /* terminating entry */
591 };
592 int ret;
593
594 deb("%s\n", __func__);
595
596 ret = m920x_write_seq(adap->dev->udev, M9206_CORE, vp7049_fe_init_seq);
597 if (ret != 0) {
598 deb("Initialization of vp7049 frontend failed.");
599 return ret;
600 }
601
602 return m920x_mt352_frontend_attach(adap);
603}
604
513static int m920x_tda10046_08_frontend_attach(struct dvb_usb_adapter *adap) 605static int m920x_tda10046_08_frontend_attach(struct dvb_usb_adapter *adap)
514{ 606{
515 deb("%s\n",__func__); 607 deb("%s\n",__func__);
@@ -574,6 +666,18 @@ static int m920x_fmd1216me_tuner_attach(struct dvb_usb_adapter *adap)
574 return 0; 666 return 0;
575} 667}
576 668
669static int m920x_mt2060_tuner_attach(struct dvb_usb_adapter *adap)
670{
671 deb("%s\n", __func__);
672
673 if (dvb_attach(mt2060_attach, adap->fe_adap[0].fe, &adap->dev->i2c_adap,
674 &m920x_mt2060_config, 1220) == NULL)
675 return -ENODEV;
676
677 return 0;
678}
679
680
577/* device-specific initialization */ 681/* device-specific initialization */
578static struct m920x_inits megasky_rc_init [] = { 682static struct m920x_inits megasky_rc_init [] = {
579 { M9206_RC_INIT2, 0xa8 }, 683 { M9206_RC_INIT2, 0xa8 },
@@ -591,7 +695,7 @@ static struct m920x_inits tvwalkertwin_rc_init [] = {
591}; 695};
592 696
593static struct m920x_inits pinnacle310e_init[] = { 697static struct m920x_inits pinnacle310e_init[] = {
594 /* without these the tuner don't work */ 698 /* without these the tuner doesn't work */
595 { 0xff20, 0x9b }, 699 { 0xff20, 0x9b },
596 { 0xff22, 0x70 }, 700 { 0xff22, 0x70 },
597 701
@@ -602,6 +706,15 @@ static struct m920x_inits pinnacle310e_init[] = {
602 { } /* terminating entry */ 706 { } /* terminating entry */
603}; 707};
604 708
709static struct m920x_inits vp7049_rc_init[] = {
710 { 0xff28, 0x00 },
711 { 0xff23, 0x00 },
712 { 0xff21, 0x70 },
713 { M9206_RC_INIT2, 0x00 },
714 { M9206_RC_INIT1, 0xff },
715 { } /* terminating entry */
716};
717
605/* ir keymaps */ 718/* ir keymaps */
606static struct rc_map_table rc_map_megasky_table[] = { 719static struct rc_map_table rc_map_megasky_table[] = {
607 { 0x0012, KEY_POWER }, 720 { 0x0012, KEY_POWER },
@@ -704,6 +817,7 @@ static struct dvb_usb_device_properties digivox_mini_ii_properties;
704static struct dvb_usb_device_properties tvwalkertwin_properties; 817static struct dvb_usb_device_properties tvwalkertwin_properties;
705static struct dvb_usb_device_properties dposh_properties; 818static struct dvb_usb_device_properties dposh_properties;
706static struct dvb_usb_device_properties pinnacle_pctv310e_properties; 819static struct dvb_usb_device_properties pinnacle_pctv310e_properties;
820static struct dvb_usb_device_properties vp7049_properties;
707 821
708static int m920x_probe(struct usb_interface *intf, 822static int m920x_probe(struct usb_interface *intf,
709 const struct usb_device_id *id) 823 const struct usb_device_id *id)
@@ -756,6 +870,13 @@ static int m920x_probe(struct usb_interface *intf,
756 goto found; 870 goto found;
757 } 871 }
758 872
873 ret = dvb_usb_device_init(intf, &vp7049_properties,
874 THIS_MODULE, &d, adapter_nr);
875 if (ret == 0) {
876 rc_init_seq = vp7049_rc_init;
877 goto found;
878 }
879
759 return ret; 880 return ret;
760 } else { 881 } else {
761 /* Another interface on a multi-tuner device */ 882 /* Another interface on a multi-tuner device */
@@ -787,6 +908,7 @@ static struct usb_device_id m920x_table [] = {
787 { USB_DEVICE(USB_VID_DPOSH, USB_PID_DPOSH_M9206_COLD) }, 908 { USB_DEVICE(USB_VID_DPOSH, USB_PID_DPOSH_M9206_COLD) },
788 { USB_DEVICE(USB_VID_DPOSH, USB_PID_DPOSH_M9206_WARM) }, 909 { USB_DEVICE(USB_VID_DPOSH, USB_PID_DPOSH_M9206_WARM) },
789 { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_PINNACLE_PCTV310E) }, 910 { USB_DEVICE(USB_VID_VISIONPLUS, USB_PID_PINNACLE_PCTV310E) },
911 { USB_DEVICE(USB_VID_AZUREWAVE, USB_PID_TWINHAN_VP7049) },
790 { } /* Terminating entry */ 912 { } /* Terminating entry */
791}; 913};
792MODULE_DEVICE_TABLE (usb, m920x_table); 914MODULE_DEVICE_TABLE (usb, m920x_table);
@@ -1079,6 +1201,61 @@ static struct dvb_usb_device_properties pinnacle_pctv310e_properties = {
1079 } 1201 }
1080}; 1202};
1081 1203
1204static struct dvb_usb_device_properties vp7049_properties = {
1205 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1206
1207 .usb_ctrl = DEVICE_SPECIFIC,
1208 .firmware = "dvb-usb-vp7049-0.95.fw",
1209 .download_firmware = m920x_firmware_download,
1210
1211 .rc.core = {
1212 .rc_interval = 150,
1213 .rc_codes = RC_MAP_TWINHAN_VP1027_DVBS,
1214 .rc_query = m920x_rc_core_query,
1215 .allowed_protos = RC_TYPE_UNKNOWN,
1216 },
1217
1218 .size_of_priv = sizeof(struct m920x_state),
1219
1220 .identify_state = m920x_identify_state,
1221 .num_adapters = 1,
1222 .adapter = {{
1223 .num_frontends = 1,
1224 .fe = {{
1225
1226 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
1227 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
1228
1229 .pid_filter_count = 8,
1230 .pid_filter = m920x_pid_filter,
1231 .pid_filter_ctrl = m920x_pid_filter_ctrl,
1232
1233 .frontend_attach = m920x_mt352_frontend_attach_vp7049,
1234 .tuner_attach = m920x_mt2060_tuner_attach,
1235
1236 .stream = {
1237 .type = USB_BULK,
1238 .count = 8,
1239 .endpoint = 0x81,
1240 .u = {
1241 .bulk = {
1242 .buffersize = 512,
1243 }
1244 }
1245 },
1246 } },
1247 } },
1248 .i2c_algo = &m920x_i2c_algo,
1249
1250 .num_device_descs = 1,
1251 .devices = {
1252 { "DTV-DVB UDTT7049",
1253 { &m920x_table[7], NULL },
1254 { NULL },
1255 }
1256 }
1257};
1258
1082static struct usb_driver m920x_driver = { 1259static struct usb_driver m920x_driver = {
1083 .name = "dvb_usb_m920x", 1260 .name = "dvb_usb_m920x",
1084 .probe = m920x_probe, 1261 .probe = m920x_probe,
diff --git a/drivers/media/usb/dvb-usb/ttusb2.c b/drivers/media/usb/dvb-usb/ttusb2.c
index bcdac225ebe1..2ce3d19c58ef 100644
--- a/drivers/media/usb/dvb-usb/ttusb2.c
+++ b/drivers/media/usb/dvb-usb/ttusb2.c
@@ -620,6 +620,8 @@ static struct usb_device_id ttusb2_table [] = {
620 USB_PID_TECHNOTREND_CONNECT_S2400) }, 620 USB_PID_TECHNOTREND_CONNECT_S2400) },
621 { USB_DEVICE(USB_VID_TECHNOTREND, 621 { USB_DEVICE(USB_VID_TECHNOTREND,
622 USB_PID_TECHNOTREND_CONNECT_CT3650) }, 622 USB_PID_TECHNOTREND_CONNECT_CT3650) },
623 { USB_DEVICE(USB_VID_TECHNOTREND,
624 USB_PID_TECHNOTREND_CONNECT_S2400_8KEEPROM) },
623 {} /* Terminating entry */ 625 {} /* Terminating entry */
624}; 626};
625MODULE_DEVICE_TABLE (usb, ttusb2_table); 627MODULE_DEVICE_TABLE (usb, ttusb2_table);
@@ -721,12 +723,16 @@ static struct dvb_usb_device_properties ttusb2_properties_s2400 = {
721 723
722 .generic_bulk_ctrl_endpoint = 0x01, 724 .generic_bulk_ctrl_endpoint = 0x01,
723 725
724 .num_device_descs = 1, 726 .num_device_descs = 2,
725 .devices = { 727 .devices = {
726 { "Technotrend TT-connect S-2400", 728 { "Technotrend TT-connect S-2400",
727 { &ttusb2_table[2], NULL }, 729 { &ttusb2_table[2], NULL },
728 { NULL }, 730 { NULL },
729 }, 731 },
732 { "Technotrend TT-connect S-2400 (8kB EEPROM)",
733 { &ttusb2_table[4], NULL },
734 { NULL },
735 },
730 } 736 }
731}; 737};
732 738
diff --git a/drivers/media/usb/em28xx/Kconfig b/drivers/media/usb/em28xx/Kconfig
index 7a5bd61bd3bb..c754a80a8d8b 100644
--- a/drivers/media/usb/em28xx/Kconfig
+++ b/drivers/media/usb/em28xx/Kconfig
@@ -3,7 +3,7 @@ config VIDEO_EM28XX
3 depends on VIDEO_DEV && I2C 3 depends on VIDEO_DEV && I2C
4 select VIDEO_TUNER 4 select VIDEO_TUNER
5 select VIDEO_TVEEPROM 5 select VIDEO_TVEEPROM
6 select VIDEOBUF_VMALLOC 6 select VIDEOBUF2_VMALLOC
7 select VIDEO_SAA711X if MEDIA_SUBDRV_AUTOSELECT 7 select VIDEO_SAA711X if MEDIA_SUBDRV_AUTOSELECT
8 select VIDEO_TVP5150 if MEDIA_SUBDRV_AUTOSELECT 8 select VIDEO_TVP5150 if MEDIA_SUBDRV_AUTOSELECT
9 select VIDEO_MSP3400 if MEDIA_SUBDRV_AUTOSELECT 9 select VIDEO_MSP3400 if MEDIA_SUBDRV_AUTOSELECT
@@ -34,6 +34,7 @@ config VIDEO_EM28XX_DVB
34 tristate "DVB/ATSC Support for em28xx based TV cards" 34 tristate "DVB/ATSC Support for em28xx based TV cards"
35 depends on VIDEO_EM28XX && DVB_CORE 35 depends on VIDEO_EM28XX && DVB_CORE
36 select DVB_LGDT330X if MEDIA_SUBDRV_AUTOSELECT 36 select DVB_LGDT330X if MEDIA_SUBDRV_AUTOSELECT
37 select DVB_LGDT3305 if MEDIA_SUBDRV_AUTOSELECT
37 select DVB_ZL10353 if MEDIA_SUBDRV_AUTOSELECT 38 select DVB_ZL10353 if MEDIA_SUBDRV_AUTOSELECT
38 select DVB_TDA10023 if MEDIA_SUBDRV_AUTOSELECT 39 select DVB_TDA10023 if MEDIA_SUBDRV_AUTOSELECT
39 select DVB_S921 if MEDIA_SUBDRV_AUTOSELECT 40 select DVB_S921 if MEDIA_SUBDRV_AUTOSELECT
@@ -43,7 +44,10 @@ config VIDEO_EM28XX_DVB
43 select DVB_TDA18271C2DD if MEDIA_SUBDRV_AUTOSELECT 44 select DVB_TDA18271C2DD if MEDIA_SUBDRV_AUTOSELECT
44 select DVB_TDA10071 if MEDIA_SUBDRV_AUTOSELECT 45 select DVB_TDA10071 if MEDIA_SUBDRV_AUTOSELECT
45 select DVB_A8293 if MEDIA_SUBDRV_AUTOSELECT 46 select DVB_A8293 if MEDIA_SUBDRV_AUTOSELECT
46 select VIDEOBUF_DVB 47 select DVB_MT352 if MEDIA_SUBDRV_AUTOSELECT
48 select DVB_S5H1409 if MEDIA_SUBDRV_AUTOSELECT
49 select MEDIA_TUNER_QT1010 if MEDIA_SUBDRV_AUTOSELECT
50 select MEDIA_TUNER_TDA18271 if MEDIA_SUBDRV_AUTOSELECT
47 ---help--- 51 ---help---
48 This adds support for DVB cards based on the 52 This adds support for DVB cards based on the
49 Empiatech em28xx chips. 53 Empiatech em28xx chips.
diff --git a/drivers/media/usb/em28xx/em28xx-cards.c b/drivers/media/usb/em28xx/em28xx-cards.c
index 619bffbab3bc..54a03b20de6e 100644
--- a/drivers/media/usb/em28xx/em28xx-cards.c
+++ b/drivers/media/usb/em28xx/em28xx-cards.c
@@ -6,6 +6,7 @@
6 Markus Rechberger <mrechberger@gmail.com> 6 Markus Rechberger <mrechberger@gmail.com>
7 Mauro Carvalho Chehab <mchehab@infradead.org> 7 Mauro Carvalho Chehab <mchehab@infradead.org>
8 Sascha Sommer <saschasommer@freenet.de> 8 Sascha Sommer <saschasommer@freenet.de>
9 Copyright (C) 2012 Frank Schäfer <fschaefer.oss@googlemail.com>
9 10
10 This program is free software; you can redistribute it and/or modify 11 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by 12 it under the terms of the GNU General Public License as published by
@@ -56,10 +57,16 @@ module_param(disable_usb_speed_check, int, 0444);
56MODULE_PARM_DESC(disable_usb_speed_check, 57MODULE_PARM_DESC(disable_usb_speed_check,
57 "override min bandwidth requirement of 480M bps"); 58 "override min bandwidth requirement of 480M bps");
58 59
59static unsigned int card[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET }; 60static unsigned int card[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = -1U };
60module_param_array(card, int, NULL, 0444); 61module_param_array(card, int, NULL, 0444);
61MODULE_PARM_DESC(card, "card type"); 62MODULE_PARM_DESC(card, "card type");
62 63
64static int usb_xfer_mode = -1;
65module_param(usb_xfer_mode, int, 0444);
66MODULE_PARM_DESC(usb_xfer_mode,
67 "USB transfer mode for frame data (-1 = auto, 0 = prefer isoc, 1 = prefer bulk)");
68
69
63/* Bitmask marking allocated devices from 0 to EM28XX_MAXBOARDS - 1 */ 70/* Bitmask marking allocated devices from 0 to EM28XX_MAXBOARDS - 1 */
64static unsigned long em28xx_devused; 71static unsigned long em28xx_devused;
65 72
@@ -486,7 +493,7 @@ struct em28xx_board em28xx_boards[] = {
486 .input = { { 493 .input = { {
487 .type = EM28XX_VMUX_TELEVISION, 494 .type = EM28XX_VMUX_TELEVISION,
488 .vmux = SAA7115_COMPOSITE2, 495 .vmux = SAA7115_COMPOSITE2,
489 .amux = EM28XX_AMUX_LINE_IN, 496 .amux = EM28XX_AMUX_VIDEO,
490 }, { 497 }, {
491 .type = EM28XX_VMUX_COMPOSITE1, 498 .type = EM28XX_VMUX_COMPOSITE1,
492 .vmux = SAA7115_COMPOSITE0, 499 .vmux = SAA7115_COMPOSITE0,
@@ -2073,6 +2080,8 @@ struct usb_device_id em28xx_id_table[] = {
2073 .driver_info = EM2884_BOARD_TERRATEC_H5 }, 2080 .driver_info = EM2884_BOARD_TERRATEC_H5 },
2074 { USB_DEVICE(0x0ccd, 0x10ad), /* H5 Rev. 2 */ 2081 { USB_DEVICE(0x0ccd, 0x10ad), /* H5 Rev. 2 */
2075 .driver_info = EM2884_BOARD_TERRATEC_H5 }, 2082 .driver_info = EM2884_BOARD_TERRATEC_H5 },
2083 { USB_DEVICE(0x0ccd, 0x10b6), /* H5 Rev. 3 */
2084 .driver_info = EM2884_BOARD_TERRATEC_H5 },
2076 { USB_DEVICE(0x0ccd, 0x0084), 2085 { USB_DEVICE(0x0ccd, 0x0084),
2077 .driver_info = EM2860_BOARD_TERRATEC_AV350 }, 2086 .driver_info = EM2860_BOARD_TERRATEC_AV350 },
2078 { USB_DEVICE(0x0ccd, 0x0096), 2087 { USB_DEVICE(0x0ccd, 0x0096),
@@ -2905,7 +2914,7 @@ static void request_module_async(struct work_struct *work)
2905 2914
2906 if (dev->board.has_dvb) 2915 if (dev->board.has_dvb)
2907 request_module("em28xx-dvb"); 2916 request_module("em28xx-dvb");
2908 if (dev->board.ir_codes && !disable_ir) 2917 if ((dev->board.ir_codes || dev->board.has_ir_i2c) && !disable_ir)
2909 request_module("em28xx-rc"); 2918 request_module("em28xx-rc");
2910#endif /* CONFIG_MODULES */ 2919#endif /* CONFIG_MODULES */
2911} 2920}
@@ -2934,6 +2943,8 @@ void em28xx_release_resources(struct em28xx *dev)
2934 2943
2935 em28xx_i2c_unregister(dev); 2944 em28xx_i2c_unregister(dev);
2936 2945
2946 v4l2_ctrl_handler_free(&dev->ctrl_handler);
2947
2937 v4l2_device_unregister(&dev->v4l2_dev); 2948 v4l2_device_unregister(&dev->v4l2_dev);
2938 2949
2939 usb_put_dev(dev->udev); 2950 usb_put_dev(dev->udev);
@@ -2950,9 +2961,14 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev,
2950 struct usb_interface *interface, 2961 struct usb_interface *interface,
2951 int minor) 2962 int minor)
2952{ 2963{
2964 struct v4l2_ctrl_handler *hdl = &dev->ctrl_handler;
2953 int retval; 2965 int retval;
2966 static const char *default_chip_name = "em28xx";
2967 const char *chip_name = default_chip_name;
2954 2968
2955 dev->udev = udev; 2969 dev->udev = udev;
2970 mutex_init(&dev->vb_queue_lock);
2971 mutex_init(&dev->vb_vbi_queue_lock);
2956 mutex_init(&dev->ctrl_urb_lock); 2972 mutex_init(&dev->ctrl_urb_lock);
2957 spin_lock_init(&dev->slock); 2973 spin_lock_init(&dev->slock);
2958 2974
@@ -2978,51 +2994,62 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev,
2978 2994
2979 switch (dev->chip_id) { 2995 switch (dev->chip_id) {
2980 case CHIP_ID_EM2800: 2996 case CHIP_ID_EM2800:
2981 em28xx_info("chip ID is em2800\n"); 2997 chip_name = "em2800";
2982 break; 2998 break;
2983 case CHIP_ID_EM2710: 2999 case CHIP_ID_EM2710:
2984 em28xx_info("chip ID is em2710\n"); 3000 chip_name = "em2710";
2985 break; 3001 break;
2986 case CHIP_ID_EM2750: 3002 case CHIP_ID_EM2750:
2987 em28xx_info("chip ID is em2750\n"); 3003 chip_name = "em2750";
2988 break; 3004 break;
2989 case CHIP_ID_EM2820: 3005 case CHIP_ID_EM2820:
2990 em28xx_info("chip ID is em2820 (or em2710)\n"); 3006 chip_name = "em2710/2820";
2991 break; 3007 break;
2992 case CHIP_ID_EM2840: 3008 case CHIP_ID_EM2840:
2993 em28xx_info("chip ID is em2840\n"); 3009 chip_name = "em2840";
2994 break; 3010 break;
2995 case CHIP_ID_EM2860: 3011 case CHIP_ID_EM2860:
2996 em28xx_info("chip ID is em2860\n"); 3012 chip_name = "em2860";
2997 break; 3013 break;
2998 case CHIP_ID_EM2870: 3014 case CHIP_ID_EM2870:
2999 em28xx_info("chip ID is em2870\n"); 3015 chip_name = "em2870";
3000 dev->wait_after_write = 0; 3016 dev->wait_after_write = 0;
3001 break; 3017 break;
3002 case CHIP_ID_EM2874: 3018 case CHIP_ID_EM2874:
3003 em28xx_info("chip ID is em2874\n"); 3019 chip_name = "em2874";
3004 dev->reg_gpio_num = EM2874_R80_GPIO; 3020 dev->reg_gpio_num = EM2874_R80_GPIO;
3005 dev->wait_after_write = 0; 3021 dev->wait_after_write = 0;
3006 break; 3022 break;
3007 case CHIP_ID_EM28174: 3023 case CHIP_ID_EM28174:
3008 em28xx_info("chip ID is em28174\n"); 3024 chip_name = "em28174";
3009 dev->reg_gpio_num = EM2874_R80_GPIO; 3025 dev->reg_gpio_num = EM2874_R80_GPIO;
3010 dev->wait_after_write = 0; 3026 dev->wait_after_write = 0;
3011 break; 3027 break;
3012 case CHIP_ID_EM2883: 3028 case CHIP_ID_EM2883:
3013 em28xx_info("chip ID is em2882/em2883\n"); 3029 chip_name = "em2882/3";
3014 dev->wait_after_write = 0; 3030 dev->wait_after_write = 0;
3015 break; 3031 break;
3016 case CHIP_ID_EM2884: 3032 case CHIP_ID_EM2884:
3017 em28xx_info("chip ID is em2884\n"); 3033 chip_name = "em2884";
3018 dev->reg_gpio_num = EM2874_R80_GPIO; 3034 dev->reg_gpio_num = EM2874_R80_GPIO;
3019 dev->wait_after_write = 0; 3035 dev->wait_after_write = 0;
3020 break; 3036 break;
3021 default: 3037 default:
3022 em28xx_info("em28xx chip ID = %d\n", dev->chip_id); 3038 printk(KERN_INFO DRIVER_NAME
3039 ": unknown em28xx chip ID (%d)\n", dev->chip_id);
3023 } 3040 }
3024 } 3041 }
3025 3042
3043 if (chip_name != default_chip_name)
3044 printk(KERN_INFO DRIVER_NAME
3045 ": chip ID is %s\n", chip_name);
3046
3047 /*
3048 * For em2820/em2710, the name may change latter, after checking
3049 * if the device has a sensor (so, it is em2710) or not.
3050 */
3051 snprintf(dev->name, sizeof(dev->name), "%s #%d", chip_name, dev->devno);
3052
3026 if (dev->is_audio_only) { 3053 if (dev->is_audio_only) {
3027 retval = em28xx_audio_setup(dev); 3054 retval = em28xx_audio_setup(dev);
3028 if (retval) 3055 if (retval)
@@ -3039,6 +3066,14 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev,
3039 3066
3040 em28xx_pre_card_setup(dev); 3067 em28xx_pre_card_setup(dev);
3041 3068
3069 if (dev->chip_id == CHIP_ID_EM2820) {
3070 if (dev->board.is_webcam)
3071 chip_name = "em2710";
3072 else
3073 chip_name = "em2820";
3074 snprintf(dev->name, sizeof(dev->name), "%s #%d", chip_name, dev->devno);
3075 }
3076
3042 if (!dev->board.is_em2800) { 3077 if (!dev->board.is_em2800) {
3043 /* Resets I2C speed */ 3078 /* Resets I2C speed */
3044 retval = em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, dev->board.i2c_speed); 3079 retval = em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, dev->board.i2c_speed);
@@ -3056,6 +3091,9 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev,
3056 return retval; 3091 return retval;
3057 } 3092 }
3058 3093
3094 v4l2_ctrl_handler_init(hdl, 4);
3095 dev->v4l2_dev.ctrl_handler = hdl;
3096
3059 /* register i2c bus */ 3097 /* register i2c bus */
3060 retval = em28xx_i2c_register(dev); 3098 retval = em28xx_i2c_register(dev);
3061 if (retval < 0) { 3099 if (retval < 0) {
@@ -3081,6 +3119,18 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev,
3081 __func__, retval); 3119 __func__, retval);
3082 goto fail; 3120 goto fail;
3083 } 3121 }
3122 if (dev->audio_mode.ac97 != EM28XX_NO_AC97) {
3123 v4l2_ctrl_new_std(hdl, &em28xx_ctrl_ops,
3124 V4L2_CID_AUDIO_MUTE, 0, 1, 1, 1);
3125 v4l2_ctrl_new_std(hdl, &em28xx_ctrl_ops,
3126 V4L2_CID_AUDIO_VOLUME, 0, 0x1f, 1, 0x1f);
3127 } else {
3128 /* install the em28xx notify callback */
3129 v4l2_ctrl_notify(v4l2_ctrl_find(hdl, V4L2_CID_AUDIO_MUTE),
3130 em28xx_ctrl_notify, dev);
3131 v4l2_ctrl_notify(v4l2_ctrl_find(hdl, V4L2_CID_AUDIO_VOLUME),
3132 em28xx_ctrl_notify, dev);
3133 }
3084 3134
3085 /* wake i2c devices */ 3135 /* wake i2c devices */
3086 em28xx_wake_i2c(dev); 3136 em28xx_wake_i2c(dev);
@@ -3110,6 +3160,11 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev,
3110 msleep(3); 3160 msleep(3);
3111 } 3161 }
3112 3162
3163 v4l2_ctrl_handler_setup(&dev->ctrl_handler);
3164 retval = dev->ctrl_handler.error;
3165 if (retval)
3166 goto fail;
3167
3113 retval = em28xx_register_analog_devices(dev); 3168 retval = em28xx_register_analog_devices(dev);
3114 if (retval < 0) { 3169 if (retval < 0) {
3115 goto fail; 3170 goto fail;
@@ -3122,6 +3177,7 @@ static int em28xx_init_dev(struct em28xx *dev, struct usb_device *udev,
3122 3177
3123fail: 3178fail:
3124 em28xx_i2c_unregister(dev); 3179 em28xx_i2c_unregister(dev);
3180 v4l2_ctrl_handler_free(&dev->ctrl_handler);
3125 3181
3126unregister_dev: 3182unregister_dev:
3127 v4l2_device_unregister(&dev->v4l2_dev); 3183 v4l2_device_unregister(&dev->v4l2_dev);
@@ -3143,7 +3199,7 @@ static int em28xx_usb_probe(struct usb_interface *interface,
3143 struct em28xx *dev = NULL; 3199 struct em28xx *dev = NULL;
3144 int retval; 3200 int retval;
3145 bool has_audio = false, has_video = false, has_dvb = false; 3201 bool has_audio = false, has_video = false, has_dvb = false;
3146 int i, nr; 3202 int i, nr, try_bulk;
3147 const int ifnum = interface->altsetting[0].desc.bInterfaceNumber; 3203 const int ifnum = interface->altsetting[0].desc.bInterfaceNumber;
3148 char *speed; 3204 char *speed;
3149 3205
@@ -3183,9 +3239,10 @@ static int em28xx_usb_probe(struct usb_interface *interface,
3183 } 3239 }
3184 3240
3185 /* compute alternate max packet sizes */ 3241 /* compute alternate max packet sizes */
3186 dev->alt_max_pkt_size = kmalloc(sizeof(dev->alt_max_pkt_size[0]) * 3242 dev->alt_max_pkt_size_isoc =
3243 kmalloc(sizeof(dev->alt_max_pkt_size_isoc[0]) *
3187 interface->num_altsetting, GFP_KERNEL); 3244 interface->num_altsetting, GFP_KERNEL);
3188 if (dev->alt_max_pkt_size == NULL) { 3245 if (dev->alt_max_pkt_size_isoc == NULL) {
3189 em28xx_errdev("out of memory!\n"); 3246 em28xx_errdev("out of memory!\n");
3190 kfree(dev); 3247 kfree(dev);
3191 retval = -ENOMEM; 3248 retval = -ENOMEM;
@@ -3208,25 +3265,67 @@ static int em28xx_usb_probe(struct usb_interface *interface,
3208 if (udev->speed == USB_SPEED_HIGH) 3265 if (udev->speed == USB_SPEED_HIGH)
3209 size = size * hb_mult(sizedescr); 3266 size = size * hb_mult(sizedescr);
3210 3267
3211 if (usb_endpoint_xfer_isoc(e) && 3268 if (usb_endpoint_dir_in(e)) {
3212 usb_endpoint_dir_in(e)) {
3213 switch (e->bEndpointAddress) { 3269 switch (e->bEndpointAddress) {
3214 case EM28XX_EP_AUDIO: 3270 case 0x82:
3215 has_audio = true;
3216 break;
3217 case EM28XX_EP_ANALOG:
3218 has_video = true; 3271 has_video = true;
3219 dev->alt_max_pkt_size[i] = size; 3272 if (usb_endpoint_xfer_isoc(e)) {
3273 dev->analog_ep_isoc =
3274 e->bEndpointAddress;
3275 dev->alt_max_pkt_size_isoc[i] = size;
3276 } else if (usb_endpoint_xfer_bulk(e)) {
3277 dev->analog_ep_bulk =
3278 e->bEndpointAddress;
3279 }
3220 break; 3280 break;
3221 case EM28XX_EP_DIGITAL: 3281 case 0x83:
3222 has_dvb = true; 3282 if (usb_endpoint_xfer_isoc(e)) {
3223 if (size > dev->dvb_max_pkt_size) { 3283 has_audio = true;
3224 dev->dvb_max_pkt_size = size; 3284 } else {
3225 dev->dvb_alt = i; 3285 printk(KERN_INFO DRIVER_NAME
3286 ": error: skipping audio endpoint 0x83, because it uses bulk transfers !\n");
3287 }
3288 break;
3289 case 0x84:
3290 if (has_video &&
3291 (usb_endpoint_xfer_bulk(e))) {
3292 dev->analog_ep_bulk =
3293 e->bEndpointAddress;
3294 } else {
3295 has_dvb = true;
3296 if (usb_endpoint_xfer_isoc(e)) {
3297 dev->dvb_ep_isoc = e->bEndpointAddress;
3298 if (size > dev->dvb_max_pkt_size_isoc) {
3299 dev->dvb_max_pkt_size_isoc = size;
3300 dev->dvb_alt_isoc = i;
3301 }
3302 } else {
3303 dev->dvb_ep_bulk = e->bEndpointAddress;
3304 }
3226 } 3305 }
3227 break; 3306 break;
3228 } 3307 }
3229 } 3308 }
3309 /* NOTE:
3310 * Old logic with support for isoc transfers only was:
3311 * 0x82 isoc => analog
3312 * 0x83 isoc => audio
3313 * 0x84 isoc => digital
3314 *
3315 * New logic with support for bulk transfers
3316 * 0x82 isoc => analog
3317 * 0x82 bulk => analog
3318 * 0x83 isoc* => audio
3319 * 0x84 isoc => digital
3320 * 0x84 bulk => analog or digital**
3321 * (*: audio should always be isoc)
3322 * (**: analog, if ep 0x82 is isoc, otherwise digital)
3323 *
3324 * The new logic preserves backwards compatibility and
3325 * reflects the endpoint configurations we have seen
3326 * so far. But there might be devices for which this
3327 * logic is not sufficient...
3328 */
3230 } 3329 }
3231 } 3330 }
3232 3331
@@ -3261,19 +3360,6 @@ static int em28xx_usb_probe(struct usb_interface *interface,
3261 ifnum, 3360 ifnum,
3262 interface->altsetting->desc.bInterfaceNumber); 3361 interface->altsetting->desc.bInterfaceNumber);
3263 3362
3264 if (has_audio)
3265 printk(KERN_INFO DRIVER_NAME
3266 ": Audio Vendor Class interface %i found\n",
3267 ifnum);
3268 if (has_video)
3269 printk(KERN_INFO DRIVER_NAME
3270 ": Video interface %i found\n",
3271 ifnum);
3272 if (has_dvb)
3273 printk(KERN_INFO DRIVER_NAME
3274 ": DVB interface %i found\n",
3275 ifnum);
3276
3277 /* 3363 /*
3278 * Make sure we have 480 Mbps of bandwidth, otherwise things like 3364 * Make sure we have 480 Mbps of bandwidth, otherwise things like
3279 * video stream wouldn't likely work, since 12 Mbps is generally 3365 * video stream wouldn't likely work, since 12 Mbps is generally
@@ -3287,7 +3373,6 @@ static int em28xx_usb_probe(struct usb_interface *interface,
3287 goto err_free; 3373 goto err_free;
3288 } 3374 }
3289 3375
3290 snprintf(dev->name, sizeof(dev->name), "em28xx #%d", nr);
3291 dev->devno = nr; 3376 dev->devno = nr;
3292 dev->model = id->driver_info; 3377 dev->model = id->driver_info;
3293 dev->alt = -1; 3378 dev->alt = -1;
@@ -3304,6 +3389,24 @@ static int em28xx_usb_probe(struct usb_interface *interface,
3304 } 3389 }
3305 } 3390 }
3306 3391
3392 if (has_audio)
3393 printk(KERN_INFO DRIVER_NAME
3394 ": Audio interface %i found %s\n",
3395 ifnum,
3396 dev->has_audio_class ? "(USB Audio Class)" : "(Vendor Class)");
3397 if (has_video)
3398 printk(KERN_INFO DRIVER_NAME
3399 ": Video interface %i found:%s%s\n",
3400 ifnum,
3401 dev->analog_ep_bulk ? " bulk" : "",
3402 dev->analog_ep_isoc ? " isoc" : "");
3403 if (has_dvb)
3404 printk(KERN_INFO DRIVER_NAME
3405 ": DVB interface %i found:%s%s\n",
3406 ifnum,
3407 dev->dvb_ep_bulk ? " bulk" : "",
3408 dev->dvb_ep_isoc ? " isoc" : "");
3409
3307 dev->num_alt = interface->num_altsetting; 3410 dev->num_alt = interface->num_altsetting;
3308 3411
3309 if ((unsigned)card[nr] < em28xx_bcount) 3412 if ((unsigned)card[nr] < em28xx_bcount)
@@ -3312,6 +3415,9 @@ static int em28xx_usb_probe(struct usb_interface *interface,
3312 /* save our data pointer in this interface device */ 3415 /* save our data pointer in this interface device */
3313 usb_set_intfdata(interface, dev); 3416 usb_set_intfdata(interface, dev);
3314 3417
3418 /* initialize videobuf2 stuff */
3419 em28xx_vb2_setup(dev);
3420
3315 /* allocate device struct */ 3421 /* allocate device struct */
3316 mutex_init(&dev->lock); 3422 mutex_init(&dev->lock);
3317 mutex_lock(&dev->lock); 3423 mutex_lock(&dev->lock);
@@ -3320,13 +3426,46 @@ static int em28xx_usb_probe(struct usb_interface *interface,
3320 goto unlock_and_free; 3426 goto unlock_and_free;
3321 } 3427 }
3322 3428
3429 if (usb_xfer_mode < 0) {
3430 if (dev->board.is_webcam)
3431 try_bulk = 1;
3432 else
3433 try_bulk = 0;
3434 } else {
3435 try_bulk = usb_xfer_mode > 0;
3436 }
3437
3438 /* Select USB transfer types to use */
3439 if (has_video) {
3440 if (!dev->analog_ep_isoc || (try_bulk && dev->analog_ep_bulk))
3441 dev->analog_xfer_bulk = 1;
3442 em28xx_info("analog set to %s mode.\n",
3443 dev->analog_xfer_bulk ? "bulk" : "isoc");
3444 }
3323 if (has_dvb) { 3445 if (has_dvb) {
3324 /* pre-allocate DVB isoc transfer buffers */ 3446 if (!dev->dvb_ep_isoc || (try_bulk && dev->dvb_ep_bulk))
3325 retval = em28xx_alloc_isoc(dev, EM28XX_DIGITAL_MODE, 3447 dev->dvb_xfer_bulk = 1;
3326 EM28XX_DVB_MAX_PACKETS, 3448
3327 EM28XX_DVB_NUM_BUFS, 3449 em28xx_info("dvb set to %s mode.\n",
3328 dev->dvb_max_pkt_size); 3450 dev->dvb_xfer_bulk ? "bulk" : "isoc");
3451
3452 /* pre-allocate DVB usb transfer buffers */
3453 if (dev->dvb_xfer_bulk) {
3454 retval = em28xx_alloc_urbs(dev, EM28XX_DIGITAL_MODE,
3455 dev->dvb_xfer_bulk,
3456 EM28XX_DVB_NUM_BUFS,
3457 512,
3458 EM28XX_DVB_BULK_PACKET_MULTIPLIER);
3459 } else {
3460 retval = em28xx_alloc_urbs(dev, EM28XX_DIGITAL_MODE,
3461 dev->dvb_xfer_bulk,
3462 EM28XX_DVB_NUM_BUFS,
3463 dev->dvb_max_pkt_size_isoc,
3464 EM28XX_DVB_NUM_ISOC_PACKETS);
3465 }
3329 if (retval) { 3466 if (retval) {
3467 printk(DRIVER_NAME
3468 ": Failed to pre-allocate USB transfer buffers for DVB.\n");
3330 goto unlock_and_free; 3469 goto unlock_and_free;
3331 } 3470 }
3332 } 3471 }
@@ -3344,7 +3483,7 @@ unlock_and_free:
3344 mutex_unlock(&dev->lock); 3483 mutex_unlock(&dev->lock);
3345 3484
3346err_free: 3485err_free:
3347 kfree(dev->alt_max_pkt_size); 3486 kfree(dev->alt_max_pkt_size_isoc);
3348 kfree(dev); 3487 kfree(dev);
3349 3488
3350err: 3489err:
@@ -3370,6 +3509,8 @@ static void em28xx_usb_disconnect(struct usb_interface *interface)
3370 if (!dev) 3509 if (!dev)
3371 return; 3510 return;
3372 3511
3512 dev->disconnected = 1;
3513
3373 if (dev->is_audio_only) { 3514 if (dev->is_audio_only) {
3374 mutex_lock(&dev->lock); 3515 mutex_lock(&dev->lock);
3375 em28xx_close_extension(dev); 3516 em28xx_close_extension(dev);
@@ -3381,35 +3522,28 @@ static void em28xx_usb_disconnect(struct usb_interface *interface)
3381 3522
3382 flush_request_modules(dev); 3523 flush_request_modules(dev);
3383 3524
3384 /* wait until all current v4l2 io is finished then deallocate
3385 resources */
3386 mutex_lock(&dev->lock); 3525 mutex_lock(&dev->lock);
3387 3526
3388 v4l2_device_disconnect(&dev->v4l2_dev); 3527 v4l2_device_disconnect(&dev->v4l2_dev);
3389 3528
3390 if (dev->users) { 3529 if (dev->users) {
3391 em28xx_warn 3530 em28xx_warn("device %s is open! Deregistration and memory deallocation are deferred on close.\n",
3392 ("device %s is open! Deregistration and memory " 3531 video_device_node_name(dev->vdev));
3393 "deallocation are deferred on close.\n", 3532
3394 video_device_node_name(dev->vdev)); 3533 em28xx_uninit_usb_xfer(dev, EM28XX_ANALOG_MODE);
3395 3534 em28xx_uninit_usb_xfer(dev, EM28XX_DIGITAL_MODE);
3396 dev->state |= DEV_MISCONFIGURED;
3397 em28xx_uninit_isoc(dev, dev->mode);
3398 dev->state |= DEV_DISCONNECTED;
3399 } else {
3400 dev->state |= DEV_DISCONNECTED;
3401 em28xx_release_resources(dev);
3402 } 3535 }
3403 3536
3404 /* free DVB isoc buffers */ 3537 em28xx_close_extension(dev);
3405 em28xx_uninit_isoc(dev, EM28XX_DIGITAL_MODE); 3538 /* NOTE: must be called BEFORE the resources are released */
3406 3539
3407 mutex_unlock(&dev->lock); 3540 if (!dev->users)
3541 em28xx_release_resources(dev);
3408 3542
3409 em28xx_close_extension(dev); 3543 mutex_unlock(&dev->lock);
3410 3544
3411 if (!dev->users) { 3545 if (!dev->users) {
3412 kfree(dev->alt_max_pkt_size); 3546 kfree(dev->alt_max_pkt_size_isoc);
3413 kfree(dev); 3547 kfree(dev);
3414 } 3548 }
3415} 3549}
diff --git a/drivers/media/usb/em28xx/em28xx-core.c b/drivers/media/usb/em28xx/em28xx-core.c
index bed07a6c33f8..aaedd11791f2 100644
--- a/drivers/media/usb/em28xx/em28xx-core.c
+++ b/drivers/media/usb/em28xx/em28xx-core.c
@@ -5,6 +5,7 @@
5 Markus Rechberger <mrechberger@gmail.com> 5 Markus Rechberger <mrechberger@gmail.com>
6 Mauro Carvalho Chehab <mchehab@infradead.org> 6 Mauro Carvalho Chehab <mchehab@infradead.org>
7 Sascha Sommer <saschasommer@freenet.de> 7 Sascha Sommer <saschasommer@freenet.de>
8 Copyright (C) 2012 Frank Schäfer <fschaefer.oss@googlemail.com>
8 9
9 This program is free software; you can redistribute it and/or modify 10 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 it under the terms of the GNU General Public License as published by
@@ -76,7 +77,7 @@ int em28xx_read_reg_req_len(struct em28xx *dev, u8 req, u16 reg,
76 int ret; 77 int ret;
77 int pipe = usb_rcvctrlpipe(dev->udev, 0); 78 int pipe = usb_rcvctrlpipe(dev->udev, 0);
78 79
79 if (dev->state & DEV_DISCONNECTED) 80 if (dev->disconnected)
80 return -ENODEV; 81 return -ENODEV;
81 82
82 if (len > URB_MAX_CTRL_SIZE) 83 if (len > URB_MAX_CTRL_SIZE)
@@ -100,7 +101,7 @@ int em28xx_read_reg_req_len(struct em28xx *dev, u8 req, u16 reg,
100 if (reg_debug) 101 if (reg_debug)
101 printk(" failed!\n"); 102 printk(" failed!\n");
102 mutex_unlock(&dev->ctrl_urb_lock); 103 mutex_unlock(&dev->ctrl_urb_lock);
103 return ret; 104 return usb_translate_errors(ret);
104 } 105 }
105 106
106 if (len) 107 if (len)
@@ -152,7 +153,7 @@ int em28xx_write_regs_req(struct em28xx *dev, u8 req, u16 reg, char *buf,
152 int ret; 153 int ret;
153 int pipe = usb_sndctrlpipe(dev->udev, 0); 154 int pipe = usb_sndctrlpipe(dev->udev, 0);
154 155
155 if (dev->state & DEV_DISCONNECTED) 156 if (dev->disconnected)
156 return -ENODEV; 157 return -ENODEV;
157 158
158 if ((len < 1) || (len > URB_MAX_CTRL_SIZE)) 159 if ((len < 1) || (len > URB_MAX_CTRL_SIZE))
@@ -181,6 +182,9 @@ int em28xx_write_regs_req(struct em28xx *dev, u8 req, u16 reg, char *buf,
181 0x0000, reg, dev->urb_buf, len, HZ); 182 0x0000, reg, dev->urb_buf, len, HZ);
182 mutex_unlock(&dev->ctrl_urb_lock); 183 mutex_unlock(&dev->ctrl_urb_lock);
183 184
185 if (ret < 0)
186 return usb_translate_errors(ret);
187
184 if (dev->wait_after_write) 188 if (dev->wait_after_write)
185 msleep(dev->wait_after_write); 189 msleep(dev->wait_after_write);
186 190
@@ -729,22 +733,24 @@ static int em28xx_accumulator_set(struct em28xx *dev, u8 xmin, u8 xmax,
729 return em28xx_write_regs(dev, EM28XX_R2B_YMAX, &ymax, 1); 733 return em28xx_write_regs(dev, EM28XX_R2B_YMAX, &ymax, 1);
730} 734}
731 735
732static int em28xx_capture_area_set(struct em28xx *dev, u8 hstart, u8 vstart, 736static void em28xx_capture_area_set(struct em28xx *dev, u8 hstart, u8 vstart,
733 u16 width, u16 height) 737 u16 width, u16 height)
734{ 738{
735 u8 cwidth = width; 739 u8 cwidth = width >> 2;
736 u8 cheight = height; 740 u8 cheight = height >> 2;
737 u8 overflow = (height >> 7 & 0x02) | (width >> 8 & 0x01); 741 u8 overflow = (height >> 9 & 0x02) | (width >> 10 & 0x01);
742 /* NOTE: size limit: 2047x1023 = 2MPix */
738 743
739 em28xx_coredbg("em28xx Area Set: (%d,%d)\n", 744 em28xx_coredbg("capture area set to (%d,%d): %dx%d\n",
740 (width | (overflow & 2) << 7), 745 hstart, vstart,
741 (height | (overflow & 1) << 8)); 746 ((overflow & 2) << 9 | cwidth << 2),
747 ((overflow & 1) << 10 | cheight << 2));
742 748
743 em28xx_write_regs(dev, EM28XX_R1C_HSTART, &hstart, 1); 749 em28xx_write_regs(dev, EM28XX_R1C_HSTART, &hstart, 1);
744 em28xx_write_regs(dev, EM28XX_R1D_VSTART, &vstart, 1); 750 em28xx_write_regs(dev, EM28XX_R1D_VSTART, &vstart, 1);
745 em28xx_write_regs(dev, EM28XX_R1E_CWIDTH, &cwidth, 1); 751 em28xx_write_regs(dev, EM28XX_R1E_CWIDTH, &cwidth, 1);
746 em28xx_write_regs(dev, EM28XX_R1F_CHEIGHT, &cheight, 1); 752 em28xx_write_regs(dev, EM28XX_R1F_CHEIGHT, &cheight, 1);
747 return em28xx_write_regs(dev, EM28XX_R1B_OFLOW, &overflow, 1); 753 em28xx_write_regs(dev, EM28XX_R1B_OFLOW, &overflow, 1);
748} 754}
749 755
750static int em28xx_scaler_set(struct em28xx *dev, u16 h, u16 v) 756static int em28xx_scaler_set(struct em28xx *dev, u16 h, u16 v)
@@ -797,28 +803,30 @@ int em28xx_resolution_set(struct em28xx *dev)
797 it out, we end up with the same format as the rest of the VBI 803 it out, we end up with the same format as the rest of the VBI
798 region */ 804 region */
799 if (em28xx_vbi_supported(dev) == 1) 805 if (em28xx_vbi_supported(dev) == 1)
800 em28xx_capture_area_set(dev, 0, 2, width >> 2, height >> 2); 806 em28xx_capture_area_set(dev, 0, 2, width, height);
801 else 807 else
802 em28xx_capture_area_set(dev, 0, 0, width >> 2, height >> 2); 808 em28xx_capture_area_set(dev, 0, 0, width, height);
803 809
804 return em28xx_scaler_set(dev, dev->hscale, dev->vscale); 810 return em28xx_scaler_set(dev, dev->hscale, dev->vscale);
805} 811}
806 812
813/* Set USB alternate setting for analog video */
807int em28xx_set_alternate(struct em28xx *dev) 814int em28xx_set_alternate(struct em28xx *dev)
808{ 815{
809 int errCode, prev_alt = dev->alt; 816 int errCode;
810 int i; 817 int i;
811 unsigned int min_pkt_size = dev->width * 2 + 4; 818 unsigned int min_pkt_size = dev->width * 2 + 4;
812 819
813 /* 820 /* NOTE: for isoc transfers, only alt settings > 0 are allowed
814 * alt = 0 is used only for control messages, so, only values 821 bulk transfers seem to work only with alt=0 ! */
815 * greater than 0 can be used for streaming. 822 dev->alt = 0;
816 */ 823 if ((alt > 0) && (alt < dev->num_alt)) {
817 if (alt && alt < dev->num_alt) {
818 em28xx_coredbg("alternate forced to %d\n", dev->alt); 824 em28xx_coredbg("alternate forced to %d\n", dev->alt);
819 dev->alt = alt; 825 dev->alt = alt;
820 goto set_alt; 826 goto set_alt;
821 } 827 }
828 if (dev->analog_xfer_bulk)
829 goto set_alt;
822 830
823 /* When image size is bigger than a certain value, 831 /* When image size is bigger than a certain value,
824 the frame size should be increased, otherwise, only 832 the frame size should be increased, otherwise, only
@@ -829,30 +837,38 @@ int em28xx_set_alternate(struct em28xx *dev)
829 837
830 for (i = 0; i < dev->num_alt; i++) { 838 for (i = 0; i < dev->num_alt; i++) {
831 /* stop when the selected alt setting offers enough bandwidth */ 839 /* stop when the selected alt setting offers enough bandwidth */
832 if (dev->alt_max_pkt_size[i] >= min_pkt_size) { 840 if (dev->alt_max_pkt_size_isoc[i] >= min_pkt_size) {
833 dev->alt = i; 841 dev->alt = i;
834 break; 842 break;
835 /* otherwise make sure that we end up with the maximum bandwidth 843 /* otherwise make sure that we end up with the maximum bandwidth
836 because the min_pkt_size equation might be wrong... 844 because the min_pkt_size equation might be wrong...
837 */ 845 */
838 } else if (dev->alt_max_pkt_size[i] > 846 } else if (dev->alt_max_pkt_size_isoc[i] >
839 dev->alt_max_pkt_size[dev->alt]) 847 dev->alt_max_pkt_size_isoc[dev->alt])
840 dev->alt = i; 848 dev->alt = i;
841 } 849 }
842 850
843set_alt: 851set_alt:
844 if (dev->alt != prev_alt) { 852 /* NOTE: for bulk transfers, we need to call usb_set_interface()
853 * even if the previous settings were the same. Otherwise streaming
854 * fails with all urbs having status = -EOVERFLOW ! */
855 if (dev->analog_xfer_bulk) {
856 dev->max_pkt_size = 512; /* USB 2.0 spec */
857 dev->packet_multiplier = EM28XX_BULK_PACKET_MULTIPLIER;
858 } else { /* isoc */
845 em28xx_coredbg("minimum isoc packet size: %u (alt=%d)\n", 859 em28xx_coredbg("minimum isoc packet size: %u (alt=%d)\n",
846 min_pkt_size, dev->alt); 860 min_pkt_size, dev->alt);
847 dev->max_pkt_size = dev->alt_max_pkt_size[dev->alt]; 861 dev->max_pkt_size =
848 em28xx_coredbg("setting alternate %d with wMaxPacketSize=%u\n", 862 dev->alt_max_pkt_size_isoc[dev->alt];
849 dev->alt, dev->max_pkt_size); 863 dev->packet_multiplier = EM28XX_NUM_ISOC_PACKETS;
850 errCode = usb_set_interface(dev->udev, 0, dev->alt); 864 }
851 if (errCode < 0) { 865 em28xx_coredbg("setting alternate %d with wMaxPacketSize=%u\n",
852 em28xx_errdev("cannot change alternate number to %d (error=%i)\n", 866 dev->alt, dev->max_pkt_size);
853 dev->alt, errCode); 867 errCode = usb_set_interface(dev->udev, 0, dev->alt);
854 return errCode; 868 if (errCode < 0) {
855 } 869 em28xx_errdev("cannot change alternate number to %d (error=%i)\n",
870 dev->alt, errCode);
871 return errCode;
856 } 872 }
857 return 0; 873 return 0;
858} 874}
@@ -919,7 +935,7 @@ EXPORT_SYMBOL_GPL(em28xx_set_mode);
919 ------------------------------------------------------------------*/ 935 ------------------------------------------------------------------*/
920 936
921/* 937/*
922 * IRQ callback, called by URB callback 938 * URB completion handler for isoc/bulk transfers
923 */ 939 */
924static void em28xx_irq_callback(struct urb *urb) 940static void em28xx_irq_callback(struct urb *urb)
925{ 941{
@@ -941,11 +957,12 @@ static void em28xx_irq_callback(struct urb *urb)
941 957
942 /* Copy data from URB */ 958 /* Copy data from URB */
943 spin_lock(&dev->slock); 959 spin_lock(&dev->slock);
944 dev->isoc_ctl.isoc_copy(dev, urb); 960 dev->usb_ctl.urb_data_copy(dev, urb);
945 spin_unlock(&dev->slock); 961 spin_unlock(&dev->slock);
946 962
947 /* Reset urb buffers */ 963 /* Reset urb buffers */
948 for (i = 0; i < urb->number_of_packets; i++) { 964 for (i = 0; i < urb->number_of_packets; i++) {
965 /* isoc only (bulk: number_of_packets = 0) */
949 urb->iso_frame_desc[i].status = 0; 966 urb->iso_frame_desc[i].status = 0;
950 urb->iso_frame_desc[i].actual_length = 0; 967 urb->iso_frame_desc[i].actual_length = 0;
951 } 968 }
@@ -961,49 +978,50 @@ static void em28xx_irq_callback(struct urb *urb)
961/* 978/*
962 * Stop and Deallocate URBs 979 * Stop and Deallocate URBs
963 */ 980 */
964void em28xx_uninit_isoc(struct em28xx *dev, enum em28xx_mode mode) 981void em28xx_uninit_usb_xfer(struct em28xx *dev, enum em28xx_mode mode)
965{ 982{
966 struct urb *urb; 983 struct urb *urb;
967 struct em28xx_usb_isoc_bufs *isoc_bufs; 984 struct em28xx_usb_bufs *usb_bufs;
968 int i; 985 int i;
969 986
970 em28xx_isocdbg("em28xx: called em28xx_uninit_isoc in mode %d\n", mode); 987 em28xx_isocdbg("em28xx: called em28xx_uninit_usb_xfer in mode %d\n",
988 mode);
971 989
972 if (mode == EM28XX_DIGITAL_MODE) 990 if (mode == EM28XX_DIGITAL_MODE)
973 isoc_bufs = &dev->isoc_ctl.digital_bufs; 991 usb_bufs = &dev->usb_ctl.digital_bufs;
974 else 992 else
975 isoc_bufs = &dev->isoc_ctl.analog_bufs; 993 usb_bufs = &dev->usb_ctl.analog_bufs;
976 994
977 for (i = 0; i < isoc_bufs->num_bufs; i++) { 995 for (i = 0; i < usb_bufs->num_bufs; i++) {
978 urb = isoc_bufs->urb[i]; 996 urb = usb_bufs->urb[i];
979 if (urb) { 997 if (urb) {
980 if (!irqs_disabled()) 998 if (!irqs_disabled())
981 usb_kill_urb(urb); 999 usb_kill_urb(urb);
982 else 1000 else
983 usb_unlink_urb(urb); 1001 usb_unlink_urb(urb);
984 1002
985 if (isoc_bufs->transfer_buffer[i]) { 1003 if (usb_bufs->transfer_buffer[i]) {
986 usb_free_coherent(dev->udev, 1004 usb_free_coherent(dev->udev,
987 urb->transfer_buffer_length, 1005 urb->transfer_buffer_length,
988 isoc_bufs->transfer_buffer[i], 1006 usb_bufs->transfer_buffer[i],
989 urb->transfer_dma); 1007 urb->transfer_dma);
990 } 1008 }
991 usb_free_urb(urb); 1009 usb_free_urb(urb);
992 isoc_bufs->urb[i] = NULL; 1010 usb_bufs->urb[i] = NULL;
993 } 1011 }
994 isoc_bufs->transfer_buffer[i] = NULL; 1012 usb_bufs->transfer_buffer[i] = NULL;
995 } 1013 }
996 1014
997 kfree(isoc_bufs->urb); 1015 kfree(usb_bufs->urb);
998 kfree(isoc_bufs->transfer_buffer); 1016 kfree(usb_bufs->transfer_buffer);
999 1017
1000 isoc_bufs->urb = NULL; 1018 usb_bufs->urb = NULL;
1001 isoc_bufs->transfer_buffer = NULL; 1019 usb_bufs->transfer_buffer = NULL;
1002 isoc_bufs->num_bufs = 0; 1020 usb_bufs->num_bufs = 0;
1003 1021
1004 em28xx_capture_start(dev, 0); 1022 em28xx_capture_start(dev, 0);
1005} 1023}
1006EXPORT_SYMBOL_GPL(em28xx_uninit_isoc); 1024EXPORT_SYMBOL_GPL(em28xx_uninit_usb_xfer);
1007 1025
1008/* 1026/*
1009 * Stop URBs 1027 * Stop URBs
@@ -1012,7 +1030,7 @@ void em28xx_stop_urbs(struct em28xx *dev)
1012{ 1030{
1013 int i; 1031 int i;
1014 struct urb *urb; 1032 struct urb *urb;
1015 struct em28xx_usb_isoc_bufs *isoc_bufs = &dev->isoc_ctl.digital_bufs; 1033 struct em28xx_usb_bufs *isoc_bufs = &dev->usb_ctl.digital_bufs;
1016 1034
1017 em28xx_isocdbg("em28xx: called em28xx_stop_urbs\n"); 1035 em28xx_isocdbg("em28xx: called em28xx_stop_urbs\n");
1018 1036
@@ -1033,10 +1051,10 @@ EXPORT_SYMBOL_GPL(em28xx_stop_urbs);
1033/* 1051/*
1034 * Allocate URBs 1052 * Allocate URBs
1035 */ 1053 */
1036int em28xx_alloc_isoc(struct em28xx *dev, enum em28xx_mode mode, 1054int em28xx_alloc_urbs(struct em28xx *dev, enum em28xx_mode mode, int xfer_bulk,
1037 int max_packets, int num_bufs, int max_pkt_size) 1055 int num_bufs, int max_pkt_size, int packet_multiplier)
1038{ 1056{
1039 struct em28xx_usb_isoc_bufs *isoc_bufs; 1057 struct em28xx_usb_bufs *usb_bufs;
1040 int i; 1058 int i;
1041 int sb_size, pipe; 1059 int sb_size, pipe;
1042 struct urb *urb; 1060 struct urb *urb;
@@ -1044,140 +1062,180 @@ int em28xx_alloc_isoc(struct em28xx *dev, enum em28xx_mode mode,
1044 1062
1045 em28xx_isocdbg("em28xx: called em28xx_alloc_isoc in mode %d\n", mode); 1063 em28xx_isocdbg("em28xx: called em28xx_alloc_isoc in mode %d\n", mode);
1046 1064
1047 if (mode == EM28XX_DIGITAL_MODE) 1065 /* Check mode and if we have an endpoint for the selected
1048 isoc_bufs = &dev->isoc_ctl.digital_bufs; 1066 transfer type, select buffer */
1049 else 1067 if (mode == EM28XX_DIGITAL_MODE) {
1050 isoc_bufs = &dev->isoc_ctl.analog_bufs; 1068 if ((xfer_bulk && !dev->dvb_ep_bulk) ||
1069 (!xfer_bulk && !dev->dvb_ep_isoc)) {
1070 em28xx_errdev("no endpoint for DVB mode and transfer type %d\n",
1071 xfer_bulk > 0);
1072 return -EINVAL;
1073 }
1074 usb_bufs = &dev->usb_ctl.digital_bufs;
1075 } else if (mode == EM28XX_ANALOG_MODE) {
1076 if ((xfer_bulk && !dev->analog_ep_bulk) ||
1077 (!xfer_bulk && !dev->analog_ep_isoc)) {
1078 em28xx_errdev("no endpoint for analog mode and transfer type %d\n",
1079 xfer_bulk > 0);
1080 return -EINVAL;
1081 }
1082 usb_bufs = &dev->usb_ctl.analog_bufs;
1083 } else {
1084 em28xx_errdev("invalid mode selected\n");
1085 return -EINVAL;
1086 }
1051 1087
1052 /* De-allocates all pending stuff */ 1088 /* De-allocates all pending stuff */
1053 em28xx_uninit_isoc(dev, mode); 1089 em28xx_uninit_usb_xfer(dev, mode);
1054 1090
1055 isoc_bufs->num_bufs = num_bufs; 1091 usb_bufs->num_bufs = num_bufs;
1056 1092
1057 isoc_bufs->urb = kzalloc(sizeof(void *)*num_bufs, GFP_KERNEL); 1093 usb_bufs->urb = kzalloc(sizeof(void *)*num_bufs, GFP_KERNEL);
1058 if (!isoc_bufs->urb) { 1094 if (!usb_bufs->urb) {
1059 em28xx_errdev("cannot alloc memory for usb buffers\n"); 1095 em28xx_errdev("cannot alloc memory for usb buffers\n");
1060 return -ENOMEM; 1096 return -ENOMEM;
1061 } 1097 }
1062 1098
1063 isoc_bufs->transfer_buffer = kzalloc(sizeof(void *)*num_bufs, 1099 usb_bufs->transfer_buffer = kzalloc(sizeof(void *)*num_bufs,
1064 GFP_KERNEL); 1100 GFP_KERNEL);
1065 if (!isoc_bufs->transfer_buffer) { 1101 if (!usb_bufs->transfer_buffer) {
1066 em28xx_errdev("cannot allocate memory for usb transfer\n"); 1102 em28xx_errdev("cannot allocate memory for usb transfer\n");
1067 kfree(isoc_bufs->urb); 1103 kfree(usb_bufs->urb);
1068 return -ENOMEM; 1104 return -ENOMEM;
1069 } 1105 }
1070 1106
1071 isoc_bufs->max_pkt_size = max_pkt_size; 1107 usb_bufs->max_pkt_size = max_pkt_size;
1072 isoc_bufs->num_packets = max_packets; 1108 if (xfer_bulk)
1073 dev->isoc_ctl.vid_buf = NULL; 1109 usb_bufs->num_packets = 0;
1074 dev->isoc_ctl.vbi_buf = NULL; 1110 else
1111 usb_bufs->num_packets = packet_multiplier;
1112 dev->usb_ctl.vid_buf = NULL;
1113 dev->usb_ctl.vbi_buf = NULL;
1075 1114
1076 sb_size = isoc_bufs->num_packets * isoc_bufs->max_pkt_size; 1115 sb_size = packet_multiplier * usb_bufs->max_pkt_size;
1077 1116
1078 /* allocate urbs and transfer buffers */ 1117 /* allocate urbs and transfer buffers */
1079 for (i = 0; i < isoc_bufs->num_bufs; i++) { 1118 for (i = 0; i < usb_bufs->num_bufs; i++) {
1080 urb = usb_alloc_urb(isoc_bufs->num_packets, GFP_KERNEL); 1119 urb = usb_alloc_urb(usb_bufs->num_packets, GFP_KERNEL);
1081 if (!urb) { 1120 if (!urb) {
1082 em28xx_err("cannot alloc isoc_ctl.urb %i\n", i); 1121 em28xx_err("cannot alloc usb_ctl.urb %i\n", i);
1083 em28xx_uninit_isoc(dev, mode); 1122 em28xx_uninit_usb_xfer(dev, mode);
1084 return -ENOMEM; 1123 return -ENOMEM;
1085 } 1124 }
1086 isoc_bufs->urb[i] = urb; 1125 usb_bufs->urb[i] = urb;
1087 1126
1088 isoc_bufs->transfer_buffer[i] = usb_alloc_coherent(dev->udev, 1127 usb_bufs->transfer_buffer[i] = usb_alloc_coherent(dev->udev,
1089 sb_size, GFP_KERNEL, &urb->transfer_dma); 1128 sb_size, GFP_KERNEL, &urb->transfer_dma);
1090 if (!isoc_bufs->transfer_buffer[i]) { 1129 if (!usb_bufs->transfer_buffer[i]) {
1091 em28xx_err("unable to allocate %i bytes for transfer" 1130 em28xx_err("unable to allocate %i bytes for transfer"
1092 " buffer %i%s\n", 1131 " buffer %i%s\n",
1093 sb_size, i, 1132 sb_size, i,
1094 in_interrupt() ? " while in int" : ""); 1133 in_interrupt() ? " while in int" : "");
1095 em28xx_uninit_isoc(dev, mode); 1134 em28xx_uninit_usb_xfer(dev, mode);
1096 return -ENOMEM; 1135 return -ENOMEM;
1097 } 1136 }
1098 memset(isoc_bufs->transfer_buffer[i], 0, sb_size); 1137 memset(usb_bufs->transfer_buffer[i], 0, sb_size);
1099 1138
1100 /* FIXME: this is a hack - should be 1139 if (xfer_bulk) { /* bulk */
1101 'desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK' 1140 pipe = usb_rcvbulkpipe(dev->udev,
1102 should also be using 'desc.bInterval' 1141 mode == EM28XX_ANALOG_MODE ?
1103 */ 1142 dev->analog_ep_bulk :
1104 pipe = usb_rcvisocpipe(dev->udev, 1143 dev->dvb_ep_bulk);
1105 mode == EM28XX_ANALOG_MODE ? 1144 usb_fill_bulk_urb(urb, dev->udev, pipe,
1106 EM28XX_EP_ANALOG : EM28XX_EP_DIGITAL); 1145 usb_bufs->transfer_buffer[i], sb_size,
1107 1146 em28xx_irq_callback, dev);
1108 usb_fill_int_urb(urb, dev->udev, pipe, 1147 urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
1109 isoc_bufs->transfer_buffer[i], sb_size, 1148 } else { /* isoc */
1110 em28xx_irq_callback, dev, 1); 1149 pipe = usb_rcvisocpipe(dev->udev,
1111 1150 mode == EM28XX_ANALOG_MODE ?
1112 urb->number_of_packets = isoc_bufs->num_packets; 1151 dev->analog_ep_isoc :
1113 urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; 1152 dev->dvb_ep_isoc);
1114 1153 usb_fill_int_urb(urb, dev->udev, pipe,
1115 k = 0; 1154 usb_bufs->transfer_buffer[i], sb_size,
1116 for (j = 0; j < isoc_bufs->num_packets; j++) { 1155 em28xx_irq_callback, dev, 1);
1117 urb->iso_frame_desc[j].offset = k; 1156 urb->transfer_flags = URB_ISO_ASAP |
1118 urb->iso_frame_desc[j].length = 1157 URB_NO_TRANSFER_DMA_MAP;
1119 isoc_bufs->max_pkt_size; 1158 k = 0;
1120 k += isoc_bufs->max_pkt_size; 1159 for (j = 0; j < usb_bufs->num_packets; j++) {
1160 urb->iso_frame_desc[j].offset = k;
1161 urb->iso_frame_desc[j].length =
1162 usb_bufs->max_pkt_size;
1163 k += usb_bufs->max_pkt_size;
1164 }
1121 } 1165 }
1166
1167 urb->number_of_packets = usb_bufs->num_packets;
1122 } 1168 }
1123 1169
1124 return 0; 1170 return 0;
1125} 1171}
1126EXPORT_SYMBOL_GPL(em28xx_alloc_isoc); 1172EXPORT_SYMBOL_GPL(em28xx_alloc_urbs);
1127 1173
1128/* 1174/*
1129 * Allocate URBs and start IRQ 1175 * Allocate URBs and start IRQ
1130 */ 1176 */
1131int em28xx_init_isoc(struct em28xx *dev, enum em28xx_mode mode, 1177int em28xx_init_usb_xfer(struct em28xx *dev, enum em28xx_mode mode,
1132 int max_packets, int num_bufs, int max_pkt_size, 1178 int xfer_bulk, int num_bufs, int max_pkt_size,
1133 int (*isoc_copy) (struct em28xx *dev, struct urb *urb)) 1179 int packet_multiplier,
1180 int (*urb_data_copy) (struct em28xx *dev, struct urb *urb))
1134{ 1181{
1135 struct em28xx_dmaqueue *dma_q = &dev->vidq; 1182 struct em28xx_dmaqueue *dma_q = &dev->vidq;
1136 struct em28xx_dmaqueue *vbi_dma_q = &dev->vbiq; 1183 struct em28xx_dmaqueue *vbi_dma_q = &dev->vbiq;
1137 struct em28xx_usb_isoc_bufs *isoc_bufs; 1184 struct em28xx_usb_bufs *usb_bufs;
1138 int i; 1185 int i;
1139 int rc; 1186 int rc;
1140 int alloc; 1187 int alloc;
1141 1188
1142 em28xx_isocdbg("em28xx: called em28xx_init_isoc in mode %d\n", mode); 1189 em28xx_isocdbg("em28xx: called em28xx_init_usb_xfer in mode %d\n",
1190 mode);
1143 1191
1144 dev->isoc_ctl.isoc_copy = isoc_copy; 1192 dev->usb_ctl.urb_data_copy = urb_data_copy;
1145 1193
1146 if (mode == EM28XX_DIGITAL_MODE) { 1194 if (mode == EM28XX_DIGITAL_MODE) {
1147 isoc_bufs = &dev->isoc_ctl.digital_bufs; 1195 usb_bufs = &dev->usb_ctl.digital_bufs;
1148 /* no need to free/alloc isoc buffers in digital mode */ 1196 /* no need to free/alloc usb buffers in digital mode */
1149 alloc = 0; 1197 alloc = 0;
1150 } else { 1198 } else {
1151 isoc_bufs = &dev->isoc_ctl.analog_bufs; 1199 usb_bufs = &dev->usb_ctl.analog_bufs;
1152 alloc = 1; 1200 alloc = 1;
1153 } 1201 }
1154 1202
1155 if (alloc) { 1203 if (alloc) {
1156 rc = em28xx_alloc_isoc(dev, mode, max_packets, 1204 rc = em28xx_alloc_urbs(dev, mode, xfer_bulk, num_bufs,
1157 num_bufs, max_pkt_size); 1205 max_pkt_size, packet_multiplier);
1158 if (rc) 1206 if (rc)
1159 return rc; 1207 return rc;
1160 } 1208 }
1161 1209
1210 if (xfer_bulk) {
1211 rc = usb_clear_halt(dev->udev, usb_bufs->urb[0]->pipe);
1212 if (rc < 0) {
1213 em28xx_err("failed to clear USB bulk endpoint stall/halt condition (error=%i)\n",
1214 rc);
1215 em28xx_uninit_usb_xfer(dev, mode);
1216 return rc;
1217 }
1218 }
1219
1162 init_waitqueue_head(&dma_q->wq); 1220 init_waitqueue_head(&dma_q->wq);
1163 init_waitqueue_head(&vbi_dma_q->wq); 1221 init_waitqueue_head(&vbi_dma_q->wq);
1164 1222
1165 em28xx_capture_start(dev, 1); 1223 em28xx_capture_start(dev, 1);
1166 1224
1167 /* submit urbs and enables IRQ */ 1225 /* submit urbs and enables IRQ */
1168 for (i = 0; i < isoc_bufs->num_bufs; i++) { 1226 for (i = 0; i < usb_bufs->num_bufs; i++) {
1169 rc = usb_submit_urb(isoc_bufs->urb[i], GFP_ATOMIC); 1227 rc = usb_submit_urb(usb_bufs->urb[i], GFP_ATOMIC);
1170 if (rc) { 1228 if (rc) {
1171 em28xx_err("submit of urb %i failed (error=%i)\n", i, 1229 em28xx_err("submit of urb %i failed (error=%i)\n", i,
1172 rc); 1230 rc);
1173 em28xx_uninit_isoc(dev, mode); 1231 em28xx_uninit_usb_xfer(dev, mode);
1174 return rc; 1232 return rc;
1175 } 1233 }
1176 } 1234 }
1177 1235
1178 return 0; 1236 return 0;
1179} 1237}
1180EXPORT_SYMBOL_GPL(em28xx_init_isoc); 1238EXPORT_SYMBOL_GPL(em28xx_init_usb_xfer);
1181 1239
1182/* 1240/*
1183 * em28xx_wake_i2c() 1241 * em28xx_wake_i2c()
diff --git a/drivers/media/usb/em28xx/em28xx-dvb.c b/drivers/media/usb/em28xx/em28xx-dvb.c
index 63f2e7070c00..a81ec2e8cc9b 100644
--- a/drivers/media/usb/em28xx/em28xx-dvb.c
+++ b/drivers/media/usb/em28xx/em28xx-dvb.c
@@ -10,6 +10,8 @@
10 10
11 (c) 2008 Aidan Thornton <makosoft@googlemail.com> 11 (c) 2008 Aidan Thornton <makosoft@googlemail.com>
12 12
13 (c) 2012 Frank Schäfer <fschaefer.oss@googlemail.com>
14
13 Based on cx88-dvb, saa7134-dvb and videobuf-dvb originally written by: 15 Based on cx88-dvb, saa7134-dvb and videobuf-dvb originally written by:
14 (c) 2004, 2005 Chris Pascoe <c.pascoe@itee.uq.edu.au> 16 (c) 2004, 2005 Chris Pascoe <c.pascoe@itee.uq.edu.au>
15 (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs] 17 (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
@@ -25,7 +27,9 @@
25 27
26#include "em28xx.h" 28#include "em28xx.h"
27#include <media/v4l2-common.h> 29#include <media/v4l2-common.h>
28#include <media/videobuf-vmalloc.h> 30#include <dvb_demux.h>
31#include <dvb_net.h>
32#include <dmxdev.h>
29#include <media/tuner.h> 33#include <media/tuner.h>
30#include "tuner-simple.h" 34#include "tuner-simple.h"
31#include <linux/gpio.h> 35#include <linux/gpio.h>
@@ -124,34 +128,47 @@ static inline void print_err_status(struct em28xx *dev,
124 } 128 }
125} 129}
126 130
127static inline int em28xx_dvb_isoc_copy(struct em28xx *dev, struct urb *urb) 131static inline int em28xx_dvb_urb_data_copy(struct em28xx *dev, struct urb *urb)
128{ 132{
129 int i; 133 int xfer_bulk, num_packets, i;
130 134
131 if (!dev) 135 if (!dev)
132 return 0; 136 return 0;
133 137
134 if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED)) 138 if (dev->disconnected)
135 return 0; 139 return 0;
136 140
137 if (urb->status < 0) { 141 if (urb->status < 0)
138 print_err_status(dev, -1, urb->status); 142 print_err_status(dev, -1, urb->status);
139 if (urb->status == -ENOENT)
140 return 0;
141 }
142 143
143 for (i = 0; i < urb->number_of_packets; i++) { 144 xfer_bulk = usb_pipebulk(urb->pipe);
144 int status = urb->iso_frame_desc[i].status;
145 145
146 if (status < 0) { 146 if (xfer_bulk) /* bulk */
147 print_err_status(dev, i, status); 147 num_packets = 1;
148 if (urb->iso_frame_desc[i].status != -EPROTO) 148 else /* isoc */
149 continue; 149 num_packets = urb->number_of_packets;
150 }
151 150
152 dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer + 151 for (i = 0; i < num_packets; i++) {
153 urb->iso_frame_desc[i].offset, 152 if (xfer_bulk) {
154 urb->iso_frame_desc[i].actual_length); 153 if (urb->status < 0) {
154 print_err_status(dev, i, urb->status);
155 if (urb->status != -EPROTO)
156 continue;
157 }
158 dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer,
159 urb->actual_length);
160 } else {
161 if (urb->iso_frame_desc[i].status < 0) {
162 print_err_status(dev, i,
163 urb->iso_frame_desc[i].status);
164 if (urb->iso_frame_desc[i].status != -EPROTO)
165 continue;
166 }
167 dvb_dmx_swfilter(&dev->dvb->demux,
168 urb->transfer_buffer +
169 urb->iso_frame_desc[i].offset,
170 urb->iso_frame_desc[i].actual_length);
171 }
155 } 172 }
156 173
157 return 0; 174 return 0;
@@ -161,24 +178,40 @@ static int em28xx_start_streaming(struct em28xx_dvb *dvb)
161{ 178{
162 int rc; 179 int rc;
163 struct em28xx *dev = dvb->adapter.priv; 180 struct em28xx *dev = dvb->adapter.priv;
164 int max_dvb_packet_size; 181 int dvb_max_packet_size, packet_multiplier, dvb_alt;
182
183 if (dev->dvb_xfer_bulk) {
184 if (!dev->dvb_ep_bulk)
185 return -ENODEV;
186 dvb_max_packet_size = 512; /* USB 2.0 spec */
187 packet_multiplier = EM28XX_DVB_BULK_PACKET_MULTIPLIER;
188 dvb_alt = 0;
189 } else { /* isoc */
190 if (!dev->dvb_ep_isoc)
191 return -ENODEV;
192 dvb_max_packet_size = dev->dvb_max_pkt_size_isoc;
193 if (dvb_max_packet_size < 0)
194 return dvb_max_packet_size;
195 packet_multiplier = EM28XX_DVB_NUM_ISOC_PACKETS;
196 dvb_alt = dev->dvb_alt_isoc;
197 }
165 198
166 usb_set_interface(dev->udev, 0, dev->dvb_alt); 199 usb_set_interface(dev->udev, 0, dvb_alt);
167 rc = em28xx_set_mode(dev, EM28XX_DIGITAL_MODE); 200 rc = em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
168 if (rc < 0) 201 if (rc < 0)
169 return rc; 202 return rc;
170 203
171 max_dvb_packet_size = dev->dvb_max_pkt_size;
172 if (max_dvb_packet_size < 0)
173 return max_dvb_packet_size;
174 dprintk(1, "Using %d buffers each with %d x %d bytes\n", 204 dprintk(1, "Using %d buffers each with %d x %d bytes\n",
175 EM28XX_DVB_NUM_BUFS, 205 EM28XX_DVB_NUM_BUFS,
176 EM28XX_DVB_MAX_PACKETS, 206 packet_multiplier,
177 max_dvb_packet_size); 207 dvb_max_packet_size);
178 208
179 return em28xx_init_isoc(dev, EM28XX_DIGITAL_MODE, 209 return em28xx_init_usb_xfer(dev, EM28XX_DIGITAL_MODE,
180 EM28XX_DVB_MAX_PACKETS, EM28XX_DVB_NUM_BUFS, 210 dev->dvb_xfer_bulk,
181 max_dvb_packet_size, em28xx_dvb_isoc_copy); 211 EM28XX_DVB_NUM_BUFS,
212 dvb_max_packet_size,
213 packet_multiplier,
214 em28xx_dvb_urb_data_copy);
182} 215}
183 216
184static int em28xx_stop_streaming(struct em28xx_dvb *dvb) 217static int em28xx_stop_streaming(struct em28xx_dvb *dvb)
@@ -714,7 +747,8 @@ static struct tda18271_config em28xx_cxd2820r_tda18271_config = {
714}; 747};
715 748
716static const struct tda10071_config em28xx_tda10071_config = { 749static const struct tda10071_config em28xx_tda10071_config = {
717 .i2c_address = 0x55, /* (0xaa >> 1) */ 750 .demod_i2c_addr = 0x55, /* (0xaa >> 1) */
751 .tuner_i2c_addr = 0x14,
718 .i2c_wr_max = 64, 752 .i2c_wr_max = 64,
719 .ts_mode = TDA10071_TS_SERIAL, 753 .ts_mode = TDA10071_TS_SERIAL,
720 .spec_inv = 0, 754 .spec_inv = 0,
@@ -1288,7 +1322,7 @@ static int em28xx_dvb_fini(struct em28xx *dev)
1288 if (dev->dvb) { 1322 if (dev->dvb) {
1289 struct em28xx_dvb *dvb = dev->dvb; 1323 struct em28xx_dvb *dvb = dev->dvb;
1290 1324
1291 if (dev->state & DEV_DISCONNECTED) { 1325 if (dev->disconnected) {
1292 /* We cannot tell the device to sleep 1326 /* We cannot tell the device to sleep
1293 * once it has been unplugged. */ 1327 * once it has been unplugged. */
1294 if (dvb->fe[0]) 1328 if (dvb->fe[0])
diff --git a/drivers/media/usb/em28xx/em28xx-i2c.c b/drivers/media/usb/em28xx/em28xx-i2c.c
index 1683bd9d51ee..8532c1d4fd46 100644
--- a/drivers/media/usb/em28xx/em28xx-i2c.c
+++ b/drivers/media/usb/em28xx/em28xx-i2c.c
@@ -50,15 +50,18 @@ do { \
50} while (0) 50} while (0)
51 51
52/* 52/*
53 * em2800_i2c_send_max4() 53 * em2800_i2c_send_bytes()
54 * send up to 4 bytes to the i2c device 54 * send up to 4 bytes to the em2800 i2c device
55 */ 55 */
56static int em2800_i2c_send_max4(struct em28xx *dev, unsigned char addr, 56static int em2800_i2c_send_bytes(struct em28xx *dev, u8 addr, u8 *buf, u16 len)
57 char *buf, int len)
58{ 57{
59 int ret; 58 int ret;
60 int write_timeout; 59 int write_timeout;
61 unsigned char b2[6]; 60 u8 b2[6];
61
62 if (len < 1 || len > 4)
63 return -EOPNOTSUPP;
64
62 BUG_ON(len < 1 || len > 4); 65 BUG_ON(len < 1 || len > 4);
63 b2[5] = 0x80 + len - 1; 66 b2[5] = 0x80 + len - 1;
64 b2[4] = addr; 67 b2[4] = addr;
@@ -70,165 +73,212 @@ static int em2800_i2c_send_max4(struct em28xx *dev, unsigned char addr,
70 if (len > 3) 73 if (len > 3)
71 b2[0] = buf[3]; 74 b2[0] = buf[3];
72 75
76 /* trigger write */
73 ret = dev->em28xx_write_regs(dev, 4 - len, &b2[4 - len], 2 + len); 77 ret = dev->em28xx_write_regs(dev, 4 - len, &b2[4 - len], 2 + len);
74 if (ret != 2 + len) { 78 if (ret != 2 + len) {
75 em28xx_warn("writing to i2c device failed (error=%i)\n", ret); 79 em28xx_warn("failed to trigger write to i2c address 0x%x "
76 return -EIO; 80 "(error=%i)\n", addr, ret);
81 return (ret < 0) ? ret : -EIO;
77 } 82 }
78 for (write_timeout = EM2800_I2C_WRITE_TIMEOUT; write_timeout > 0; 83 /* wait for completion */
84 for (write_timeout = EM2800_I2C_XFER_TIMEOUT; write_timeout > 0;
79 write_timeout -= 5) { 85 write_timeout -= 5) {
80 ret = dev->em28xx_read_reg(dev, 0x05); 86 ret = dev->em28xx_read_reg(dev, 0x05);
81 if (ret == 0x80 + len - 1) 87 if (ret == 0x80 + len - 1) {
82 return len; 88 return len;
89 } else if (ret == 0x94 + len - 1) {
90 return -ENODEV;
91 } else if (ret < 0) {
92 em28xx_warn("failed to get i2c transfer status from "
93 "bridge register (error=%i)\n", ret);
94 return ret;
95 }
83 msleep(5); 96 msleep(5);
84 } 97 }
85 em28xx_warn("i2c write timed out\n"); 98 em28xx_warn("write to i2c device at 0x%x timed out\n", addr);
86 return -EIO; 99 return -EIO;
87} 100}
88 101
89/* 102/*
90 * em2800_i2c_send_bytes() 103 * em2800_i2c_recv_bytes()
91 */ 104 * read up to 4 bytes from the em2800 i2c device
92static int em2800_i2c_send_bytes(void *data, unsigned char addr, char *buf,
93 short len)
94{
95 char *bufPtr = buf;
96 int ret;
97 int wrcount = 0;
98 int count;
99 int maxLen = 4;
100 struct em28xx *dev = (struct em28xx *)data;
101 while (len > 0) {
102 count = (len > maxLen) ? maxLen : len;
103 ret = em2800_i2c_send_max4(dev, addr, bufPtr, count);
104 if (ret > 0) {
105 len -= count;
106 bufPtr += count;
107 wrcount += count;
108 } else
109 return (ret < 0) ? ret : -EFAULT;
110 }
111 return wrcount;
112}
113
114/*
115 * em2800_i2c_check_for_device()
116 * check if there is a i2c_device at the supplied address
117 */ 105 */
118static int em2800_i2c_check_for_device(struct em28xx *dev, unsigned char addr) 106static int em2800_i2c_recv_bytes(struct em28xx *dev, u8 addr, u8 *buf, u16 len)
119{ 107{
120 char msg; 108 u8 buf2[4];
121 int ret; 109 int ret;
122 int write_timeout; 110 int read_timeout;
123 msg = addr; 111 int i;
124 ret = dev->em28xx_write_regs(dev, 0x04, &msg, 1); 112
125 if (ret < 0) { 113 if (len < 1 || len > 4)
126 em28xx_warn("setting i2c device address failed (error=%i)\n", 114 return -EOPNOTSUPP;
127 ret); 115
128 return ret; 116 /* trigger read */
129 } 117 buf2[1] = 0x84 + len - 1;
130 msg = 0x84; 118 buf2[0] = addr;
131 ret = dev->em28xx_write_regs(dev, 0x05, &msg, 1); 119 ret = dev->em28xx_write_regs(dev, 0x04, buf2, 2);
132 if (ret < 0) { 120 if (ret != 2) {
133 em28xx_warn("preparing i2c read failed (error=%i)\n", ret); 121 em28xx_warn("failed to trigger read from i2c address 0x%x "
134 return ret; 122 "(error=%i)\n", addr, ret);
123 return (ret < 0) ? ret : -EIO;
135 } 124 }
136 for (write_timeout = EM2800_I2C_WRITE_TIMEOUT; write_timeout > 0;
137 write_timeout -= 5) {
138 unsigned reg = dev->em28xx_read_reg(dev, 0x5);
139 125
140 if (reg == 0x94) 126 /* wait for completion */
127 for (read_timeout = EM2800_I2C_XFER_TIMEOUT; read_timeout > 0;
128 read_timeout -= 5) {
129 ret = dev->em28xx_read_reg(dev, 0x05);
130 if (ret == 0x84 + len - 1) {
131 break;
132 } else if (ret == 0x94 + len - 1) {
141 return -ENODEV; 133 return -ENODEV;
142 else if (reg == 0x84) 134 } else if (ret < 0) {
143 return 0; 135 em28xx_warn("failed to get i2c transfer status from "
136 "bridge register (error=%i)\n", ret);
137 return ret;
138 }
144 msleep(5); 139 msleep(5);
145 } 140 }
146 return -ENODEV; 141 if (ret != 0x84 + len - 1)
142 em28xx_warn("read from i2c device at 0x%x timed out\n", addr);
143
144 /* get the received message */
145 ret = dev->em28xx_read_reg_req_len(dev, 0x00, 4-len, buf2, len);
146 if (ret != len) {
147 em28xx_warn("reading from i2c device at 0x%x failed: "
148 "couldn't get the received message from the bridge "
149 "(error=%i)\n", addr, ret);
150 return (ret < 0) ? ret : -EIO;
151 }
152 for (i = 0; i < len; i++)
153 buf[i] = buf2[len - 1 - i];
154
155 return ret;
147} 156}
148 157
149/* 158/*
150 * em2800_i2c_recv_bytes() 159 * em2800_i2c_check_for_device()
151 * read from the i2c device 160 * check if there is an i2c device at the supplied address
152 */ 161 */
153static int em2800_i2c_recv_bytes(struct em28xx *dev, unsigned char addr, 162static int em2800_i2c_check_for_device(struct em28xx *dev, u8 addr)
154 char *buf, int len)
155{ 163{
164 u8 buf;
156 int ret; 165 int ret;
157 /* check for the device and set i2c read address */ 166
158 ret = em2800_i2c_check_for_device(dev, addr); 167 ret = em2800_i2c_recv_bytes(dev, addr, &buf, 1);
159 if (ret) { 168 if (ret == 1)
160 em28xx_warn 169 return 0;
161 ("preparing read at i2c address 0x%x failed (error=%i)\n", 170 return (ret < 0) ? ret : -EIO;
162 addr, ret);
163 return ret;
164 }
165 ret = dev->em28xx_read_reg_req_len(dev, 0x0, 0x3, buf, len);
166 if (ret < 0) {
167 em28xx_warn("reading from i2c device at 0x%x failed (error=%i)",
168 addr, ret);
169 return ret;
170 }
171 return ret;
172} 171}
173 172
174/* 173/*
175 * em28xx_i2c_send_bytes() 174 * em28xx_i2c_send_bytes()
176 */ 175 */
177static int em28xx_i2c_send_bytes(void *data, unsigned char addr, char *buf, 176static int em28xx_i2c_send_bytes(struct em28xx *dev, u16 addr, u8 *buf,
178 short len, int stop) 177 u16 len, int stop)
179{ 178{
180 int wrcount = 0;
181 struct em28xx *dev = (struct em28xx *)data;
182 int write_timeout, ret; 179 int write_timeout, ret;
183 180
184 wrcount = dev->em28xx_write_regs_req(dev, stop ? 2 : 3, addr, buf, len); 181 if (len < 1 || len > 64)
182 return -EOPNOTSUPP;
183 /* NOTE: limited by the USB ctrl message constraints
184 * Zero length reads always succeed, even if no device is connected */
185
186 /* Write to i2c device */
187 ret = dev->em28xx_write_regs_req(dev, stop ? 2 : 3, addr, buf, len);
188 if (ret != len) {
189 if (ret < 0) {
190 em28xx_warn("writing to i2c device at 0x%x failed "
191 "(error=%i)\n", addr, ret);
192 return ret;
193 } else {
194 em28xx_warn("%i bytes write to i2c device at 0x%x "
195 "requested, but %i bytes written\n",
196 len, addr, ret);
197 return -EIO;
198 }
199 }
185 200
186 /* Seems to be required after a write */ 201 /* Check success of the i2c operation */
187 for (write_timeout = EM2800_I2C_WRITE_TIMEOUT; write_timeout > 0; 202 for (write_timeout = EM2800_I2C_XFER_TIMEOUT; write_timeout > 0;
188 write_timeout -= 5) { 203 write_timeout -= 5) {
189 ret = dev->em28xx_read_reg(dev, 0x05); 204 ret = dev->em28xx_read_reg(dev, 0x05);
190 if (!ret) 205 if (ret == 0) { /* success */
191 break; 206 return len;
207 } else if (ret == 0x10) {
208 return -ENODEV;
209 } else if (ret < 0) {
210 em28xx_warn("failed to read i2c transfer status from "
211 "bridge (error=%i)\n", ret);
212 return ret;
213 }
192 msleep(5); 214 msleep(5);
215 /* NOTE: do we really have to wait for success ?
216 Never seen anything else than 0x00 or 0x10
217 (even with high payload) ... */
193 } 218 }
194 219 em28xx_warn("write to i2c device at 0x%x timed out\n", addr);
195 return wrcount; 220 return -EIO;
196} 221}
197 222
198/* 223/*
199 * em28xx_i2c_recv_bytes() 224 * em28xx_i2c_recv_bytes()
200 * read a byte from the i2c device 225 * read a byte from the i2c device
201 */ 226 */
202static int em28xx_i2c_recv_bytes(struct em28xx *dev, unsigned char addr, 227static int em28xx_i2c_recv_bytes(struct em28xx *dev, u16 addr, u8 *buf, u16 len)
203 char *buf, int len)
204{ 228{
205 int ret; 229 int ret;
230
231 if (len < 1 || len > 64)
232 return -EOPNOTSUPP;
233 /* NOTE: limited by the USB ctrl message constraints
234 * Zero length reads always succeed, even if no device is connected */
235
236 /* Read data from i2c device */
206 ret = dev->em28xx_read_reg_req_len(dev, 2, addr, buf, len); 237 ret = dev->em28xx_read_reg_req_len(dev, 2, addr, buf, len);
238 if (ret != len) {
239 if (ret < 0) {
240 em28xx_warn("reading from i2c device at 0x%x failed "
241 "(error=%i)\n", addr, ret);
242 return ret;
243 } else {
244 em28xx_warn("%i bytes requested from i2c device at "
245 "0x%x, but %i bytes received\n",
246 len, addr, ret);
247 return -EIO;
248 }
249 }
250
251 /* Check success of the i2c operation */
252 ret = dev->em28xx_read_reg(dev, 0x05);
207 if (ret < 0) { 253 if (ret < 0) {
208 em28xx_warn("reading i2c device failed (error=%i)\n", ret); 254 em28xx_warn("failed to read i2c transfer status from "
255 "bridge (error=%i)\n", ret);
209 return ret; 256 return ret;
210 } 257 }
211 if (dev->em28xx_read_reg(dev, 0x5) != 0) 258 if (ret > 0) {
212 return -ENODEV; 259 if (ret == 0x10) {
213 return ret; 260 return -ENODEV;
261 } else {
262 em28xx_warn("unknown i2c error (status=%i)\n", ret);
263 return -EIO;
264 }
265 }
266 return len;
214} 267}
215 268
216/* 269/*
217 * em28xx_i2c_check_for_device() 270 * em28xx_i2c_check_for_device()
218 * check if there is a i2c_device at the supplied address 271 * check if there is a i2c_device at the supplied address
219 */ 272 */
220static int em28xx_i2c_check_for_device(struct em28xx *dev, unsigned char addr) 273static int em28xx_i2c_check_for_device(struct em28xx *dev, u16 addr)
221{ 274{
222 int ret; 275 int ret;
276 u8 buf;
223 277
224 ret = dev->em28xx_read_reg_req(dev, 2, addr); 278 ret = em28xx_i2c_recv_bytes(dev, addr, &buf, 1);
225 if (ret < 0) { 279 if (ret == 1)
226 em28xx_warn("reading from i2c device failed (error=%i)\n", ret); 280 return 0;
227 return ret; 281 return (ret < 0) ? ret : -EIO;
228 }
229 if (dev->em28xx_read_reg(dev, 0x5) != 0)
230 return -ENODEV;
231 return 0;
232} 282}
233 283
234/* 284/*
@@ -253,11 +303,11 @@ static int em28xx_i2c_xfer(struct i2c_adapter *i2c_adap,
253 rc = em2800_i2c_check_for_device(dev, addr); 303 rc = em2800_i2c_check_for_device(dev, addr);
254 else 304 else
255 rc = em28xx_i2c_check_for_device(dev, addr); 305 rc = em28xx_i2c_check_for_device(dev, addr);
256 if (rc < 0) { 306 if (rc == -ENODEV) {
257 dprintk2(2, " no device\n"); 307 if (i2c_debug >= 2)
308 printk(" no device\n");
258 return rc; 309 return rc;
259 } 310 }
260
261 } else if (msgs[i].flags & I2C_M_RD) { 311 } else if (msgs[i].flags & I2C_M_RD) {
262 /* read bytes */ 312 /* read bytes */
263 if (dev->board.is_em2800) 313 if (dev->board.is_em2800)
@@ -288,16 +338,16 @@ static int em28xx_i2c_xfer(struct i2c_adapter *i2c_adap,
288 msgs[i].len, 338 msgs[i].len,
289 i == num - 1); 339 i == num - 1);
290 } 340 }
291 if (rc < 0) 341 if (rc < 0) {
292 goto err; 342 if (i2c_debug >= 2)
343 printk(" ERROR: %i\n", rc);
344 return rc;
345 }
293 if (i2c_debug >= 2) 346 if (i2c_debug >= 2)
294 printk("\n"); 347 printk("\n");
295 } 348 }
296 349
297 return num; 350 return num;
298err:
299 dprintk2(2, " ERROR: %i\n", rc);
300 return rc;
301} 351}
302 352
303/* based on linux/sunrpc/svcauth.h and linux/hash.h 353/* based on linux/sunrpc/svcauth.h and linux/hash.h
@@ -329,7 +379,7 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char *eedata, int len)
329{ 379{
330 unsigned char buf, *p = eedata; 380 unsigned char buf, *p = eedata;
331 struct em28xx_eeprom *em_eeprom = (void *)eedata; 381 struct em28xx_eeprom *em_eeprom = (void *)eedata;
332 int i, err, size = len, block; 382 int i, err, size = len, block, block_max;
333 383
334 if (dev->chip_id == CHIP_ID_EM2874 || 384 if (dev->chip_id == CHIP_ID_EM2874 ||
335 dev->chip_id == CHIP_ID_EM28174 || 385 dev->chip_id == CHIP_ID_EM28174 ||
@@ -362,9 +412,15 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char *eedata, int len)
362 dev->name, err); 412 dev->name, err);
363 return err; 413 return err;
364 } 414 }
415
416 if (dev->board.is_em2800)
417 block_max = 4;
418 else
419 block_max = 64;
420
365 while (size > 0) { 421 while (size > 0) {
366 if (size > 16) 422 if (size > block_max)
367 block = 16; 423 block = block_max;
368 else 424 else
369 block = size; 425 block = size;
370 426
@@ -449,7 +505,11 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char *eedata, int len)
449 */ 505 */
450static u32 functionality(struct i2c_adapter *adap) 506static u32 functionality(struct i2c_adapter *adap)
451{ 507{
452 return I2C_FUNC_SMBUS_EMUL; 508 struct em28xx *dev = adap->algo_data;
509 u32 func_flags = I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
510 if (dev->board.is_em2800)
511 func_flags &= ~I2C_FUNC_SMBUS_WRITE_BLOCK_DATA;
512 return func_flags;
453} 513}
454 514
455static struct i2c_algorithm em28xx_algo = { 515static struct i2c_algorithm em28xx_algo = {
@@ -474,6 +534,7 @@ static struct i2c_client em28xx_client_template = {
474 * incomplete list of known devices 534 * incomplete list of known devices
475 */ 535 */
476static char *i2c_devs[128] = { 536static char *i2c_devs[128] = {
537 [0x3e >> 1] = "remote IR sensor",
477 [0x4a >> 1] = "saa7113h", 538 [0x4a >> 1] = "saa7113h",
478 [0x52 >> 1] = "drxk", 539 [0x52 >> 1] = "drxk",
479 [0x60 >> 1] = "remote IR sensor", 540 [0x60 >> 1] = "remote IR sensor",
diff --git a/drivers/media/usb/em28xx/em28xx-input.c b/drivers/media/usb/em28xx/em28xx-input.c
index 660bf803c9e4..1bef990b3f18 100644
--- a/drivers/media/usb/em28xx/em28xx-input.c
+++ b/drivers/media/usb/em28xx/em28xx-input.c
@@ -40,11 +40,6 @@ MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]");
40 40
41#define MODULE_NAME "em28xx" 41#define MODULE_NAME "em28xx"
42 42
43#define i2cdprintk(fmt, arg...) \
44 if (ir_debug) { \
45 printk(KERN_DEBUG "%s/ir: " fmt, ir->name , ## arg); \
46 }
47
48#define dprintk(fmt, arg...) \ 43#define dprintk(fmt, arg...) \
49 if (ir_debug) { \ 44 if (ir_debug) { \
50 printk(KERN_DEBUG "%s/ir: " fmt, ir->name , ## arg); \ 45 printk(KERN_DEBUG "%s/ir: " fmt, ir->name , ## arg); \
@@ -57,8 +52,8 @@ MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]");
57struct em28xx_ir_poll_result { 52struct em28xx_ir_poll_result {
58 unsigned int toggle_bit:1; 53 unsigned int toggle_bit:1;
59 unsigned int read_count:7; 54 unsigned int read_count:7;
60 u8 rc_address; 55
61 u8 rc_data[4]; /* 1 byte on em2860/2880, 4 on em2874 */ 56 u32 scancode;
62}; 57};
63 58
64struct em28xx_IR { 59struct em28xx_IR {
@@ -67,12 +62,17 @@ struct em28xx_IR {
67 char name[32]; 62 char name[32];
68 char phys[32]; 63 char phys[32];
69 64
70 /* poll external decoder */ 65 /* poll decoder */
71 int polling; 66 int polling;
72 struct delayed_work work; 67 struct delayed_work work;
73 unsigned int full_code:1; 68 unsigned int full_code:1;
74 unsigned int last_readcount; 69 unsigned int last_readcount;
70 u64 rc_type;
75 71
72 /* i2c slave address of external device (if used) */
73 u16 i2c_dev_addr;
74
75 int (*get_key_i2c)(struct i2c_client *, u32 *);
76 int (*get_key)(struct em28xx_IR *, struct em28xx_ir_poll_result *); 76 int (*get_key)(struct em28xx_IR *, struct em28xx_ir_poll_result *);
77}; 77};
78 78
@@ -80,21 +80,16 @@ struct em28xx_IR {
80 I2C IR based get keycodes - should be used with ir-kbd-i2c 80 I2C IR based get keycodes - should be used with ir-kbd-i2c
81 **********************************************************/ 81 **********************************************************/
82 82
83static int em28xx_get_key_terratec(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) 83static int em28xx_get_key_terratec(struct i2c_client *i2c_dev, u32 *ir_key)
84{ 84{
85 unsigned char b; 85 unsigned char b;
86 86
87 /* poll IR chip */ 87 /* poll IR chip */
88 if (1 != i2c_master_recv(ir->c, &b, 1)) { 88 if (1 != i2c_master_recv(i2c_dev, &b, 1))
89 i2cdprintk("read error\n");
90 return -EIO; 89 return -EIO;
91 }
92 90
93 /* it seems that 0xFE indicates that a button is still hold 91 /* it seems that 0xFE indicates that a button is still hold
94 down, while 0xff indicates that no button is hold 92 down, while 0xff indicates that no button is hold down. */
95 down. 0xfe sequences are sometimes interrupted by 0xFF */
96
97 i2cdprintk("key %02x\n", b);
98 93
99 if (b == 0xff) 94 if (b == 0xff)
100 return 0; 95 return 0;
@@ -104,18 +99,17 @@ static int em28xx_get_key_terratec(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
104 return 1; 99 return 1;
105 100
106 *ir_key = b; 101 *ir_key = b;
107 *ir_raw = b;
108 return 1; 102 return 1;
109} 103}
110 104
111static int em28xx_get_key_em_haup(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) 105static int em28xx_get_key_em_haup(struct i2c_client *i2c_dev, u32 *ir_key)
112{ 106{
113 unsigned char buf[2]; 107 unsigned char buf[2];
114 u16 code; 108 u16 code;
115 int size; 109 int size;
116 110
117 /* poll IR chip */ 111 /* poll IR chip */
118 size = i2c_master_recv(ir->c, buf, sizeof(buf)); 112 size = i2c_master_recv(i2c_dev, buf, sizeof(buf));
119 113
120 if (size != 2) 114 if (size != 2)
121 return -EIO; 115 return -EIO;
@@ -124,8 +118,6 @@ static int em28xx_get_key_em_haup(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
124 if (buf[1] == 0xff) 118 if (buf[1] == 0xff)
125 return 0; 119 return 0;
126 120
127 ir->old = buf[1];
128
129 /* 121 /*
130 * Rearranges bits to the right order. 122 * Rearranges bits to the right order.
131 * The bit order were determined experimentally by using 123 * The bit order were determined experimentally by using
@@ -148,65 +140,51 @@ static int em28xx_get_key_em_haup(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
148 ((buf[1] & 0x40) ? 0x0200 : 0) | /* 0000 0010 */ 140 ((buf[1] & 0x40) ? 0x0200 : 0) | /* 0000 0010 */
149 ((buf[1] & 0x80) ? 0x0100 : 0); /* 0000 0001 */ 141 ((buf[1] & 0x80) ? 0x0100 : 0); /* 0000 0001 */
150 142
151 i2cdprintk("ir hauppauge (em2840): code=0x%02x (rcv=0x%02x%02x)\n",
152 code, buf[1], buf[0]);
153
154 /* return key */ 143 /* return key */
155 *ir_key = code; 144 *ir_key = code;
156 *ir_raw = code;
157 return 1; 145 return 1;
158} 146}
159 147
160static int em28xx_get_key_pinnacle_usb_grey(struct IR_i2c *ir, u32 *ir_key, 148static int em28xx_get_key_pinnacle_usb_grey(struct i2c_client *i2c_dev,
161 u32 *ir_raw) 149 u32 *ir_key)
162{ 150{
163 unsigned char buf[3]; 151 unsigned char buf[3];
164 152
165 /* poll IR chip */ 153 /* poll IR chip */
166 154
167 if (3 != i2c_master_recv(ir->c, buf, 3)) { 155 if (3 != i2c_master_recv(i2c_dev, buf, 3))
168 i2cdprintk("read error\n");
169 return -EIO; 156 return -EIO;
170 }
171 157
172 i2cdprintk("key %02x\n", buf[2]&0x3f);
173 if (buf[0] != 0x00) 158 if (buf[0] != 0x00)
174 return 0; 159 return 0;
175 160
176 *ir_key = buf[2]&0x3f; 161 *ir_key = buf[2]&0x3f;
177 *ir_raw = buf[2]&0x3f;
178 162
179 return 1; 163 return 1;
180} 164}
181 165
182static int em28xx_get_key_winfast_usbii_deluxe(struct IR_i2c *ir, u32 *ir_key, 166static int em28xx_get_key_winfast_usbii_deluxe(struct i2c_client *i2c_dev,
183 u32 *ir_raw) 167 u32 *ir_key)
184{ 168{
185 unsigned char subaddr, keydetect, key; 169 unsigned char subaddr, keydetect, key;
186 170
187 struct i2c_msg msg[] = { { .addr = ir->c->addr, .flags = 0, .buf = &subaddr, .len = 1}, 171 struct i2c_msg msg[] = { { .addr = i2c_dev->addr, .flags = 0, .buf = &subaddr, .len = 1},
188 172 { .addr = i2c_dev->addr, .flags = I2C_M_RD, .buf = &keydetect, .len = 1} };
189 { .addr = ir->c->addr, .flags = I2C_M_RD, .buf = &keydetect, .len = 1} };
190 173
191 subaddr = 0x10; 174 subaddr = 0x10;
192 if (2 != i2c_transfer(ir->c->adapter, msg, 2)) { 175 if (2 != i2c_transfer(i2c_dev->adapter, msg, 2))
193 i2cdprintk("read error\n");
194 return -EIO; 176 return -EIO;
195 }
196 if (keydetect == 0x00) 177 if (keydetect == 0x00)
197 return 0; 178 return 0;
198 179
199 subaddr = 0x00; 180 subaddr = 0x00;
200 msg[1].buf = &key; 181 msg[1].buf = &key;
201 if (2 != i2c_transfer(ir->c->adapter, msg, 2)) { 182 if (2 != i2c_transfer(i2c_dev->adapter, msg, 2))
202 i2cdprintk("read error\n"); 183 return -EIO;
203 return -EIO;
204 }
205 if (key == 0x00) 184 if (key == 0x00)
206 return 0; 185 return 0;
207 186
208 *ir_key = key; 187 *ir_key = key;
209 *ir_raw = key;
210 return 1; 188 return 1;
211} 189}
212 190
@@ -236,11 +214,8 @@ static int default_polling_getkey(struct em28xx_IR *ir,
236 /* Infrared read count (Reg 0x45[6:0] */ 214 /* Infrared read count (Reg 0x45[6:0] */
237 poll_result->read_count = (msg[0] & 0x7f); 215 poll_result->read_count = (msg[0] & 0x7f);
238 216
239 /* Remote Control Address (Reg 0x46) */ 217 /* Remote Control Address/Data (Regs 0x46/0x47) */
240 poll_result->rc_address = msg[1]; 218 poll_result->scancode = msg[1] << 8 | msg[2];
241
242 /* Remote Control Data (Reg 0x47) */
243 poll_result->rc_data[0] = msg[2];
244 219
245 return 0; 220 return 0;
246} 221}
@@ -266,13 +241,35 @@ static int em2874_polling_getkey(struct em28xx_IR *ir,
266 /* Infrared read count (Reg 0x51[6:0] */ 241 /* Infrared read count (Reg 0x51[6:0] */
267 poll_result->read_count = (msg[0] & 0x7f); 242 poll_result->read_count = (msg[0] & 0x7f);
268 243
269 /* Remote Control Address (Reg 0x52) */ 244 /*
270 poll_result->rc_address = msg[1]; 245 * Remote Control Address (Reg 0x52)
271 246 * Remote Control Data (Reg 0x53-0x55)
272 /* Remote Control Data (Reg 0x53-55) */ 247 */
273 poll_result->rc_data[0] = msg[2]; 248 switch (ir->rc_type) {
274 poll_result->rc_data[1] = msg[3]; 249 case RC_BIT_RC5:
275 poll_result->rc_data[2] = msg[4]; 250 poll_result->scancode = msg[1] << 8 | msg[2];
251 break;
252 case RC_BIT_NEC:
253 if ((msg[3] ^ msg[4]) != 0xff) /* 32 bits NEC */
254 poll_result->scancode = (msg[1] << 24) |
255 (msg[2] << 16) |
256 (msg[3] << 8) |
257 msg[4];
258 else if ((msg[1] ^ msg[2]) != 0xff) /* 24 bits NEC */
259 poll_result->scancode = (msg[1] << 16) |
260 (msg[2] << 8) |
261 msg[3];
262 else /* Normal NEC */
263 poll_result->scancode = msg[1] << 8 | msg[3];
264 break;
265 case RC_BIT_RC6_0:
266 poll_result->scancode = msg[1] << 8 | msg[2];
267 break;
268 default:
269 poll_result->scancode = (msg[1] << 24) | (msg[2] << 16) |
270 (msg[3] << 8) | msg[4];
271 break;
272 }
276 273
277 return 0; 274 return 0;
278} 275}
@@ -281,6 +278,28 @@ static int em2874_polling_getkey(struct em28xx_IR *ir,
281 Polling code for em28xx 278 Polling code for em28xx
282 **********************************************************/ 279 **********************************************************/
283 280
281static int em28xx_i2c_ir_handle_key(struct em28xx_IR *ir)
282{
283 static u32 ir_key;
284 int rc;
285 struct i2c_client client;
286
287 client.adapter = &ir->dev->i2c_adap;
288 client.addr = ir->i2c_dev_addr;
289
290 rc = ir->get_key_i2c(&client, &ir_key);
291 if (rc < 0) {
292 dprintk("ir->get_key_i2c() failed: %d\n", rc);
293 return rc;
294 }
295
296 if (rc) {
297 dprintk("%s: keycode = 0x%04x\n", __func__, ir_key);
298 rc_keydown(ir->rc, ir_key, 0);
299 }
300 return 0;
301}
302
284static void em28xx_ir_handle_key(struct em28xx_IR *ir) 303static void em28xx_ir_handle_key(struct em28xx_IR *ir)
285{ 304{
286 int result; 305 int result;
@@ -289,22 +308,21 @@ static void em28xx_ir_handle_key(struct em28xx_IR *ir)
289 /* read the registers containing the IR status */ 308 /* read the registers containing the IR status */
290 result = ir->get_key(ir, &poll_result); 309 result = ir->get_key(ir, &poll_result);
291 if (unlikely(result < 0)) { 310 if (unlikely(result < 0)) {
292 dprintk("ir->get_key() failed %d\n", result); 311 dprintk("ir->get_key() failed: %d\n", result);
293 return; 312 return;
294 } 313 }
295 314
296 if (unlikely(poll_result.read_count != ir->last_readcount)) { 315 if (unlikely(poll_result.read_count != ir->last_readcount)) {
297 dprintk("%s: toggle: %d, count: %d, key 0x%02x%02x\n", __func__, 316 dprintk("%s: toggle: %d, count: %d, key 0x%04x\n", __func__,
298 poll_result.toggle_bit, poll_result.read_count, 317 poll_result.toggle_bit, poll_result.read_count,
299 poll_result.rc_address, poll_result.rc_data[0]); 318 poll_result.scancode);
300 if (ir->full_code) 319 if (ir->full_code)
301 rc_keydown(ir->rc, 320 rc_keydown(ir->rc,
302 poll_result.rc_address << 8 | 321 poll_result.scancode,
303 poll_result.rc_data[0],
304 poll_result.toggle_bit); 322 poll_result.toggle_bit);
305 else 323 else
306 rc_keydown(ir->rc, 324 rc_keydown(ir->rc,
307 poll_result.rc_data[0], 325 poll_result.scancode & 0xff,
308 poll_result.toggle_bit); 326 poll_result.toggle_bit);
309 327
310 if (ir->dev->chip_id == CHIP_ID_EM2874 || 328 if (ir->dev->chip_id == CHIP_ID_EM2874 ||
@@ -324,7 +342,10 @@ static void em28xx_ir_work(struct work_struct *work)
324{ 342{
325 struct em28xx_IR *ir = container_of(work, struct em28xx_IR, work.work); 343 struct em28xx_IR *ir = container_of(work, struct em28xx_IR, work.work);
326 344
327 em28xx_ir_handle_key(ir); 345 if (ir->i2c_dev_addr) /* external i2c device */
346 em28xx_i2c_ir_handle_key(ir);
347 else /* internal device */
348 em28xx_ir_handle_key(ir);
328 schedule_delayed_work(&ir->work, msecs_to_jiffies(ir->polling)); 349 schedule_delayed_work(&ir->work, msecs_to_jiffies(ir->polling));
329} 350}
330 351
@@ -345,93 +366,107 @@ static void em28xx_ir_stop(struct rc_dev *rc)
345 cancel_delayed_work_sync(&ir->work); 366 cancel_delayed_work_sync(&ir->work);
346} 367}
347 368
348static int em28xx_ir_change_protocol(struct rc_dev *rc_dev, u64 *rc_type) 369static int em2860_ir_change_protocol(struct rc_dev *rc_dev, u64 *rc_type)
349{ 370{
350 int rc = 0;
351 struct em28xx_IR *ir = rc_dev->priv; 371 struct em28xx_IR *ir = rc_dev->priv;
352 struct em28xx *dev = ir->dev; 372 struct em28xx *dev = ir->dev;
353 u8 ir_config = EM2874_IR_RC5;
354
355 /* Adjust xclk based o IR table for RC5/NEC tables */
356 373
374 /* Adjust xclk based on IR table for RC5/NEC tables */
357 if (*rc_type & RC_BIT_RC5) { 375 if (*rc_type & RC_BIT_RC5) {
358 dev->board.xclk |= EM28XX_XCLK_IR_RC5_MODE; 376 dev->board.xclk |= EM28XX_XCLK_IR_RC5_MODE;
359 ir->full_code = 1; 377 ir->full_code = 1;
360 *rc_type = RC_BIT_RC5; 378 *rc_type = RC_BIT_RC5;
361 } else if (*rc_type & RC_BIT_NEC) { 379 } else if (*rc_type & RC_BIT_NEC) {
362 dev->board.xclk &= ~EM28XX_XCLK_IR_RC5_MODE; 380 dev->board.xclk &= ~EM28XX_XCLK_IR_RC5_MODE;
363 ir_config = EM2874_IR_NEC;
364 ir->full_code = 1; 381 ir->full_code = 1;
365 *rc_type = RC_BIT_NEC; 382 *rc_type = RC_BIT_NEC;
366 } else if (*rc_type != RC_BIT_UNKNOWN) 383 } else if (*rc_type & RC_BIT_UNKNOWN) {
367 rc = -EINVAL; 384 *rc_type = RC_BIT_UNKNOWN;
385 } else {
386 *rc_type = ir->rc_type;
387 return -EINVAL;
388 }
389 em28xx_write_reg_bits(dev, EM28XX_R0F_XCLK, dev->board.xclk,
390 EM28XX_XCLK_IR_RC5_MODE);
391
392 ir->rc_type = *rc_type;
368 393
394 return 0;
395}
396
397static int em2874_ir_change_protocol(struct rc_dev *rc_dev, u64 *rc_type)
398{
399 struct em28xx_IR *ir = rc_dev->priv;
400 struct em28xx *dev = ir->dev;
401 u8 ir_config = EM2874_IR_RC5;
402
403 /* Adjust xclk and set type based on IR table for RC5/NEC/RC6 tables */
404 if (*rc_type & RC_BIT_RC5) {
405 dev->board.xclk |= EM28XX_XCLK_IR_RC5_MODE;
406 ir->full_code = 1;
407 *rc_type = RC_BIT_RC5;
408 } else if (*rc_type & RC_BIT_NEC) {
409 dev->board.xclk &= ~EM28XX_XCLK_IR_RC5_MODE;
410 ir_config = EM2874_IR_NEC | EM2874_IR_NEC_NO_PARITY;
411 ir->full_code = 1;
412 *rc_type = RC_BIT_NEC;
413 } else if (*rc_type & RC_BIT_RC6_0) {
414 dev->board.xclk |= EM28XX_XCLK_IR_RC5_MODE;
415 ir_config = EM2874_IR_RC6_MODE_0;
416 ir->full_code = 1;
417 *rc_type = RC_BIT_RC6_0;
418 } else if (*rc_type & RC_BIT_UNKNOWN) {
419 *rc_type = RC_BIT_UNKNOWN;
420 } else {
421 *rc_type = ir->rc_type;
422 return -EINVAL;
423 }
424 em28xx_write_regs(dev, EM2874_R50_IR_CONFIG, &ir_config, 1);
369 em28xx_write_reg_bits(dev, EM28XX_R0F_XCLK, dev->board.xclk, 425 em28xx_write_reg_bits(dev, EM28XX_R0F_XCLK, dev->board.xclk,
370 EM28XX_XCLK_IR_RC5_MODE); 426 EM28XX_XCLK_IR_RC5_MODE);
371 427
428 ir->rc_type = *rc_type;
429
430 return 0;
431}
432static int em28xx_ir_change_protocol(struct rc_dev *rc_dev, u64 *rc_type)
433{
434 struct em28xx_IR *ir = rc_dev->priv;
435 struct em28xx *dev = ir->dev;
436
372 /* Setup the proper handler based on the chip */ 437 /* Setup the proper handler based on the chip */
373 switch (dev->chip_id) { 438 switch (dev->chip_id) {
374 case CHIP_ID_EM2860: 439 case CHIP_ID_EM2860:
375 case CHIP_ID_EM2883: 440 case CHIP_ID_EM2883:
376 ir->get_key = default_polling_getkey; 441 return em2860_ir_change_protocol(rc_dev, rc_type);
377 break;
378 case CHIP_ID_EM2884: 442 case CHIP_ID_EM2884:
379 case CHIP_ID_EM2874: 443 case CHIP_ID_EM2874:
380 case CHIP_ID_EM28174: 444 case CHIP_ID_EM28174:
381 ir->get_key = em2874_polling_getkey; 445 return em2874_ir_change_protocol(rc_dev, rc_type);
382 em28xx_write_regs(dev, EM2874_R50_IR_CONFIG, &ir_config, 1);
383 break;
384 default: 446 default:
385 printk("Unrecognized em28xx chip id 0x%02x: IR not supported\n", 447 printk("Unrecognized em28xx chip id 0x%02x: IR not supported\n",
386 dev->chip_id); 448 dev->chip_id);
387 rc = -EINVAL; 449 return -EINVAL;
388 } 450 }
389
390 return rc;
391} 451}
392 452
393static void em28xx_register_i2c_ir(struct em28xx *dev) 453static int em28xx_probe_i2c_ir(struct em28xx *dev)
394{ 454{
455 int i = 0;
395 /* Leadtek winfast tv USBII deluxe can find a non working IR-device */ 456 /* Leadtek winfast tv USBII deluxe can find a non working IR-device */
396 /* at address 0x18, so if that address is needed for another board in */ 457 /* at address 0x18, so if that address is needed for another board in */
397 /* the future, please put it after 0x1f. */ 458 /* the future, please put it after 0x1f. */
398 struct i2c_board_info info;
399 const unsigned short addr_list[] = { 459 const unsigned short addr_list[] = {
400 0x1f, 0x30, 0x47, I2C_CLIENT_END 460 0x1f, 0x30, 0x47, I2C_CLIENT_END
401 }; 461 };
402 462
403 memset(&info, 0, sizeof(struct i2c_board_info)); 463 while (addr_list[i] != I2C_CLIENT_END) {
404 memset(&dev->init_data, 0, sizeof(dev->init_data)); 464 if (i2c_probe_func_quick_read(&dev->i2c_adap, addr_list[i]) == 1)
405 strlcpy(info.type, "ir_video", I2C_NAME_SIZE); 465 return addr_list[i];
406 466 i++;
407 /* detect & configure */
408 switch (dev->model) {
409 case EM2800_BOARD_TERRATEC_CINERGY_200:
410 case EM2820_BOARD_TERRATEC_CINERGY_250:
411 dev->init_data.ir_codes = RC_MAP_EM_TERRATEC;
412 dev->init_data.get_key = em28xx_get_key_terratec;
413 dev->init_data.name = "i2c IR (EM28XX Terratec)";
414 break;
415 case EM2820_BOARD_PINNACLE_USB_2:
416 dev->init_data.ir_codes = RC_MAP_PINNACLE_GREY;
417 dev->init_data.get_key = em28xx_get_key_pinnacle_usb_grey;
418 dev->init_data.name = "i2c IR (EM28XX Pinnacle PCTV)";
419 break;
420 case EM2820_BOARD_HAUPPAUGE_WINTV_USB_2:
421 dev->init_data.ir_codes = RC_MAP_HAUPPAUGE;
422 dev->init_data.get_key = em28xx_get_key_em_haup;
423 dev->init_data.name = "i2c IR (EM2840 Hauppauge)";
424 break;
425 case EM2820_BOARD_LEADTEK_WINFAST_USBII_DELUXE:
426 dev->init_data.ir_codes = RC_MAP_WINFAST_USBII_DELUXE;
427 dev->init_data.get_key = em28xx_get_key_winfast_usbii_deluxe;
428 dev->init_data.name = "i2c IR (EM2820 Winfast TV USBII Deluxe)";
429 break;
430 } 467 }
431 468
432 if (dev->init_data.name) 469 return -ENODEV;
433 info.platform_data = &dev->init_data;
434 i2c_new_probed_device(&dev->i2c_adap, &info, addr_list, NULL);
435} 470}
436 471
437/********************************************************** 472/**********************************************************
@@ -527,8 +562,21 @@ static int em28xx_ir_init(struct em28xx *dev)
527 struct rc_dev *rc; 562 struct rc_dev *rc;
528 int err = -ENOMEM; 563 int err = -ENOMEM;
529 u64 rc_type; 564 u64 rc_type;
565 u16 i2c_rc_dev_addr = 0;
566
567 if (dev->board.has_snapshot_button)
568 em28xx_register_snapshot_button(dev);
569
570 if (dev->board.has_ir_i2c) {
571 i2c_rc_dev_addr = em28xx_probe_i2c_ir(dev);
572 if (!i2c_rc_dev_addr) {
573 dev->board.has_ir_i2c = 0;
574 em28xx_warn("No i2c IR remote control device found.\n");
575 return -ENODEV;
576 }
577 }
530 578
531 if (dev->board.ir_codes == NULL) { 579 if (dev->board.ir_codes == NULL && !dev->board.has_ir_i2c) {
532 /* No remote control support */ 580 /* No remote control support */
533 em28xx_warn("Remote control support is not available for " 581 em28xx_warn("Remote control support is not available for "
534 "this card.\n"); 582 "this card.\n");
@@ -538,35 +586,77 @@ static int em28xx_ir_init(struct em28xx *dev)
538 ir = kzalloc(sizeof(*ir), GFP_KERNEL); 586 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
539 rc = rc_allocate_device(); 587 rc = rc_allocate_device();
540 if (!ir || !rc) 588 if (!ir || !rc)
541 goto err_out_free; 589 goto error;
542 590
543 /* record handles to ourself */ 591 /* record handles to ourself */
544 ir->dev = dev; 592 ir->dev = dev;
545 dev->ir = ir; 593 dev->ir = ir;
546 ir->rc = rc; 594 ir->rc = rc;
547 595
548 /*
549 * em2874 supports more protocols. For now, let's just announce
550 * the two protocols that were already tested
551 */
552 rc->allowed_protos = RC_BIT_RC5 | RC_BIT_NEC;
553 rc->priv = ir; 596 rc->priv = ir;
554 rc->change_protocol = em28xx_ir_change_protocol;
555 rc->open = em28xx_ir_start; 597 rc->open = em28xx_ir_start;
556 rc->close = em28xx_ir_stop; 598 rc->close = em28xx_ir_stop;
557 599
558 /* By default, keep protocol field untouched */ 600 if (dev->board.has_ir_i2c) { /* external i2c device */
559 rc_type = RC_BIT_UNKNOWN; 601 switch (dev->model) {
560 err = em28xx_ir_change_protocol(rc, &rc_type); 602 case EM2800_BOARD_TERRATEC_CINERGY_200:
561 if (err) 603 case EM2820_BOARD_TERRATEC_CINERGY_250:
562 goto err_out_free; 604 rc->map_name = RC_MAP_EM_TERRATEC;
605 ir->get_key_i2c = em28xx_get_key_terratec;
606 break;
607 case EM2820_BOARD_PINNACLE_USB_2:
608 rc->map_name = RC_MAP_PINNACLE_GREY;
609 ir->get_key_i2c = em28xx_get_key_pinnacle_usb_grey;
610 break;
611 case EM2820_BOARD_HAUPPAUGE_WINTV_USB_2:
612 rc->map_name = RC_MAP_HAUPPAUGE;
613 ir->get_key_i2c = em28xx_get_key_em_haup;
614 rc->allowed_protos = RC_BIT_RC5;
615 break;
616 case EM2820_BOARD_LEADTEK_WINFAST_USBII_DELUXE:
617 rc->map_name = RC_MAP_WINFAST_USBII_DELUXE;
618 ir->get_key_i2c = em28xx_get_key_winfast_usbii_deluxe;
619 break;
620 default:
621 err = -ENODEV;
622 goto error;
623 }
624
625 ir->i2c_dev_addr = i2c_rc_dev_addr;
626 } else { /* internal device */
627 switch (dev->chip_id) {
628 case CHIP_ID_EM2860:
629 case CHIP_ID_EM2883:
630 rc->allowed_protos = RC_BIT_RC5 | RC_BIT_NEC;
631 ir->get_key = default_polling_getkey;
632 break;
633 case CHIP_ID_EM2884:
634 case CHIP_ID_EM2874:
635 case CHIP_ID_EM28174:
636 ir->get_key = em2874_polling_getkey;
637 rc->allowed_protos = RC_BIT_RC5 | RC_BIT_NEC |
638 RC_BIT_RC6_0;
639 break;
640 default:
641 err = -ENODEV;
642 goto error;
643 }
644
645 rc->change_protocol = em28xx_ir_change_protocol;
646 rc->map_name = dev->board.ir_codes;
647
648 /* By default, keep protocol field untouched */
649 rc_type = RC_BIT_UNKNOWN;
650 err = em28xx_ir_change_protocol(rc, &rc_type);
651 if (err)
652 goto error;
653 }
563 654
564 /* This is how often we ask the chip for IR information */ 655 /* This is how often we ask the chip for IR information */
565 ir->polling = 100; /* ms */ 656 ir->polling = 100; /* ms */
566 657
567 /* init input device */ 658 /* init input device */
568 snprintf(ir->name, sizeof(ir->name), "em28xx IR (%s)", 659 snprintf(ir->name, sizeof(ir->name), "em28xx IR (%s)", dev->name);
569 dev->name);
570 660
571 usb_make_path(dev->udev, ir->phys, sizeof(ir->phys)); 661 usb_make_path(dev->udev, ir->phys, sizeof(ir->phys));
572 strlcat(ir->phys, "/input0", sizeof(ir->phys)); 662 strlcat(ir->phys, "/input0", sizeof(ir->phys));
@@ -578,28 +668,17 @@ static int em28xx_ir_init(struct em28xx *dev)
578 rc->input_id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor); 668 rc->input_id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor);
579 rc->input_id.product = le16_to_cpu(dev->udev->descriptor.idProduct); 669 rc->input_id.product = le16_to_cpu(dev->udev->descriptor.idProduct);
580 rc->dev.parent = &dev->udev->dev; 670 rc->dev.parent = &dev->udev->dev;
581 rc->map_name = dev->board.ir_codes;
582 rc->driver_name = MODULE_NAME; 671 rc->driver_name = MODULE_NAME;
583 672
584 /* all done */ 673 /* all done */
585 err = rc_register_device(rc); 674 err = rc_register_device(rc);
586 if (err) 675 if (err)
587 goto err_out_stop; 676 goto error;
588
589 em28xx_register_i2c_ir(dev);
590
591#if defined(CONFIG_MODULES) && defined(MODULE)
592 if (dev->board.has_ir_i2c)
593 request_module("ir-kbd-i2c");
594#endif
595 if (dev->board.has_snapshot_button)
596 em28xx_register_snapshot_button(dev);
597 677
598 return 0; 678 return 0;
599 679
600 err_out_stop: 680error:
601 dev->ir = NULL; 681 dev->ir = NULL;
602 err_out_free:
603 rc_free_device(rc); 682 rc_free_device(rc);
604 kfree(ir); 683 kfree(ir);
605 return err; 684 return err;
diff --git a/drivers/media/usb/em28xx/em28xx-reg.h b/drivers/media/usb/em28xx/em28xx-reg.h
index 6ff368297f6e..885089e22bcd 100644
--- a/drivers/media/usb/em28xx/em28xx-reg.h
+++ b/drivers/media/usb/em28xx/em28xx-reg.h
@@ -13,9 +13,9 @@
13#define EM_GPO_3 (1 << 3) 13#define EM_GPO_3 (1 << 3)
14 14
15/* em28xx endpoints */ 15/* em28xx endpoints */
16#define EM28XX_EP_ANALOG 0x82 16/* 0x82: (always ?) analog */
17#define EM28XX_EP_AUDIO 0x83 17#define EM28XX_EP_AUDIO 0x83
18#define EM28XX_EP_DIGITAL 0x84 18/* 0x84: digital or analog */
19 19
20/* em2800 registers */ 20/* em2800 registers */
21#define EM2800_R08_AUDIOSRC 0x08 21#define EM2800_R08_AUDIOSRC 0x08
@@ -177,6 +177,7 @@
177 177
178/* em2874 IR config register (0x50) */ 178/* em2874 IR config register (0x50) */
179#define EM2874_IR_NEC 0x00 179#define EM2874_IR_NEC 0x00
180#define EM2874_IR_NEC_NO_PARITY 0x01
180#define EM2874_IR_RC5 0x04 181#define EM2874_IR_RC5 0x04
181#define EM2874_IR_RC6_MODE_0 0x08 182#define EM2874_IR_RC6_MODE_0 0x08
182#define EM2874_IR_RC6_MODE_6A 0x0b 183#define EM2874_IR_RC6_MODE_6A 0x0b
diff --git a/drivers/media/usb/em28xx/em28xx-vbi.c b/drivers/media/usb/em28xx/em28xx-vbi.c
index 2b4c9cba2d67..39f39c527c13 100644
--- a/drivers/media/usb/em28xx/em28xx-vbi.c
+++ b/drivers/media/usb/em28xx/em28xx-vbi.c
@@ -41,105 +41,72 @@ MODULE_PARM_DESC(vbi_debug, "enable debug messages [vbi]");
41 41
42/* ------------------------------------------------------------------ */ 42/* ------------------------------------------------------------------ */
43 43
44static void 44static int vbi_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
45free_buffer(struct videobuf_queue *vq, struct em28xx_buffer *buf) 45 unsigned int *nbuffers, unsigned int *nplanes,
46 unsigned int sizes[], void *alloc_ctxs[])
46{ 47{
47 struct em28xx_fh *fh = vq->priv_data; 48 struct em28xx *dev = vb2_get_drv_priv(vq);
48 struct em28xx *dev = fh->dev; 49 unsigned long size;
49 unsigned long flags = 0;
50 if (in_interrupt())
51 BUG();
52
53 /* We used to wait for the buffer to finish here, but this didn't work
54 because, as we were keeping the state as VIDEOBUF_QUEUED,
55 videobuf_queue_cancel marked it as finished for us.
56 (Also, it could wedge forever if the hardware was misconfigured.)
57
58 This should be safe; by the time we get here, the buffer isn't
59 queued anymore. If we ever start marking the buffers as
60 VIDEOBUF_ACTIVE, it won't be, though.
61 */
62 spin_lock_irqsave(&dev->slock, flags);
63 if (dev->isoc_ctl.vbi_buf == buf)
64 dev->isoc_ctl.vbi_buf = NULL;
65 spin_unlock_irqrestore(&dev->slock, flags);
66 50
67 videobuf_vmalloc_free(&buf->vb); 51 if (fmt)
68 buf->vb.state = VIDEOBUF_NEEDS_INIT; 52 size = fmt->fmt.pix.sizeimage;
69} 53 else
54 size = dev->vbi_width * dev->vbi_height * 2;
70 55
71static int 56 if (0 == *nbuffers)
72vbi_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size) 57 *nbuffers = 32;
73{ 58 if (*nbuffers < 2)
74 struct em28xx_fh *fh = q->priv_data; 59 *nbuffers = 2;
75 struct em28xx *dev = fh->dev; 60 if (*nbuffers > 32)
61 *nbuffers = 32;
76 62
77 *size = dev->vbi_width * dev->vbi_height * 2; 63 *nplanes = 1;
64 sizes[0] = size;
78 65
79 if (0 == *count)
80 *count = vbibufs;
81 if (*count < 2)
82 *count = 2;
83 if (*count > 32)
84 *count = 32;
85 return 0; 66 return 0;
86} 67}
87 68
88static int 69static int vbi_buffer_prepare(struct vb2_buffer *vb)
89vbi_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
90 enum v4l2_field field)
91{ 70{
92 struct em28xx_fh *fh = q->priv_data; 71 struct em28xx *dev = vb2_get_drv_priv(vb->vb2_queue);
93 struct em28xx *dev = fh->dev;
94 struct em28xx_buffer *buf = container_of(vb, struct em28xx_buffer, vb); 72 struct em28xx_buffer *buf = container_of(vb, struct em28xx_buffer, vb);
95 int rc = 0; 73 unsigned long size;
96 74
97 buf->vb.size = dev->vbi_width * dev->vbi_height * 2; 75 size = dev->vbi_width * dev->vbi_height * 2;
98 76
99 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) 77 if (vb2_plane_size(vb, 0) < size) {
78 printk(KERN_INFO "%s data will not fit into plane (%lu < %lu)\n",
79 __func__, vb2_plane_size(vb, 0), size);
100 return -EINVAL; 80 return -EINVAL;
101
102 buf->vb.width = dev->vbi_width;
103 buf->vb.height = dev->vbi_height;
104 buf->vb.field = field;
105
106 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
107 rc = videobuf_iolock(q, &buf->vb, NULL);
108 if (rc < 0)
109 goto fail;
110 } 81 }
82 vb2_set_plane_payload(&buf->vb, 0, size);
111 83
112 buf->vb.state = VIDEOBUF_PREPARED;
113 return 0; 84 return 0;
114
115fail:
116 free_buffer(q, buf);
117 return rc;
118} 85}
119 86
120static void 87static void
121vbi_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) 88vbi_buffer_queue(struct vb2_buffer *vb)
122{
123 struct em28xx_buffer *buf = container_of(vb,
124 struct em28xx_buffer,
125 vb);
126 struct em28xx_fh *fh = vq->priv_data;
127 struct em28xx *dev = fh->dev;
128 struct em28xx_dmaqueue *vbiq = &dev->vbiq;
129
130 buf->vb.state = VIDEOBUF_QUEUED;
131 list_add_tail(&buf->vb.queue, &vbiq->active);
132}
133
134static void vbi_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
135{ 89{
90 struct em28xx *dev = vb2_get_drv_priv(vb->vb2_queue);
136 struct em28xx_buffer *buf = container_of(vb, struct em28xx_buffer, vb); 91 struct em28xx_buffer *buf = container_of(vb, struct em28xx_buffer, vb);
137 free_buffer(q, buf); 92 struct em28xx_dmaqueue *vbiq = &dev->vbiq;
93 unsigned long flags = 0;
94
95 buf->mem = vb2_plane_vaddr(vb, 0);
96 buf->length = vb2_plane_size(vb, 0);
97
98 spin_lock_irqsave(&dev->slock, flags);
99 list_add_tail(&buf->list, &vbiq->active);
100 spin_unlock_irqrestore(&dev->slock, flags);
138} 101}
139 102
140struct videobuf_queue_ops em28xx_vbi_qops = { 103
141 .buf_setup = vbi_setup, 104struct vb2_ops em28xx_vbi_qops = {
142 .buf_prepare = vbi_prepare, 105 .queue_setup = vbi_queue_setup,
143 .buf_queue = vbi_queue, 106 .buf_prepare = vbi_buffer_prepare,
144 .buf_release = vbi_release, 107 .buf_queue = vbi_buffer_queue,
108 .start_streaming = em28xx_start_analog_streaming,
109 .stop_streaming = em28xx_stop_vbi_streaming,
110 .wait_prepare = vb2_ops_wait_prepare,
111 .wait_finish = vb2_ops_wait_finish,
145}; 112};
diff --git a/drivers/media/usb/em28xx/em28xx-video.c b/drivers/media/usb/em28xx/em28xx-video.c
index 1e553d357380..32bd7de5dec1 100644
--- a/drivers/media/usb/em28xx/em28xx-video.c
+++ b/drivers/media/usb/em28xx/em28xx-video.c
@@ -6,6 +6,7 @@
6 Markus Rechberger <mrechberger@gmail.com> 6 Markus Rechberger <mrechberger@gmail.com>
7 Mauro Carvalho Chehab <mchehab@infradead.org> 7 Mauro Carvalho Chehab <mchehab@infradead.org>
8 Sascha Sommer <saschasommer@freenet.de> 8 Sascha Sommer <saschasommer@freenet.de>
9 Copyright (C) 2012 Frank Schäfer <fschaefer.oss@googlemail.com>
9 10
10 Some parts based on SN9C10x PC Camera Controllers GPL driver made 11 Some parts based on SN9C10x PC Camera Controllers GPL driver made
11 by Luca Risolia <luca.risolia@studio.unibo.it> 12 by Luca Risolia <luca.risolia@studio.unibo.it>
@@ -39,6 +40,7 @@
39#include "em28xx.h" 40#include "em28xx.h"
40#include <media/v4l2-common.h> 41#include <media/v4l2-common.h>
41#include <media/v4l2-ioctl.h> 42#include <media/v4l2-ioctl.h>
43#include <media/v4l2-event.h>
42#include <media/v4l2-chip-ident.h> 44#include <media/v4l2-chip-ident.h>
43#include <media/msp3400.h> 45#include <media/msp3400.h>
44#include <media/tuner.h> 46#include <media/tuner.h>
@@ -74,9 +76,9 @@ MODULE_DESCRIPTION(DRIVER_DESC);
74MODULE_LICENSE("GPL"); 76MODULE_LICENSE("GPL");
75MODULE_VERSION(EM28XX_VERSION); 77MODULE_VERSION(EM28XX_VERSION);
76 78
77static unsigned int video_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET }; 79static unsigned int video_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = -1U };
78static unsigned int vbi_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET }; 80static unsigned int vbi_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = -1U };
79static unsigned int radio_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = UNSET }; 81static unsigned int radio_nr[] = {[0 ... (EM28XX_MAXBOARDS - 1)] = -1U };
80 82
81module_param_array(video_nr, int, NULL, 0444); 83module_param_array(video_nr, int, NULL, 0444);
82module_param_array(vbi_nr, int, NULL, 0444); 84module_param_array(vbi_nr, int, NULL, 0444);
@@ -124,101 +126,50 @@ static struct em28xx_fmt format[] = {
124 }, 126 },
125}; 127};
126 128
127/* supported controls */
128/* Common to all boards */
129static struct v4l2_queryctrl ac97_qctrl[] = {
130 {
131 .id = V4L2_CID_AUDIO_VOLUME,
132 .type = V4L2_CTRL_TYPE_INTEGER,
133 .name = "Volume",
134 .minimum = 0x0,
135 .maximum = 0x1f,
136 .step = 0x1,
137 .default_value = 0x1f,
138 .flags = V4L2_CTRL_FLAG_SLIDER,
139 }, {
140 .id = V4L2_CID_AUDIO_MUTE,
141 .type = V4L2_CTRL_TYPE_BOOLEAN,
142 .name = "Mute",
143 .minimum = 0,
144 .maximum = 1,
145 .step = 1,
146 .default_value = 1,
147 .flags = 0,
148 }
149};
150
151/* ------------------------------------------------------------------ 129/* ------------------------------------------------------------------
152 DMA and thread functions 130 DMA and thread functions
153 ------------------------------------------------------------------*/ 131 ------------------------------------------------------------------*/
154 132
155/* 133/*
156 * Announces that a buffer were filled and request the next 134 * Finish the current buffer
157 */ 135 */
158static inline void buffer_filled(struct em28xx *dev, 136static inline void finish_buffer(struct em28xx *dev,
159 struct em28xx_dmaqueue *dma_q, 137 struct em28xx_buffer *buf)
160 struct em28xx_buffer *buf)
161{ 138{
162 /* Advice that buffer was filled */ 139 em28xx_isocdbg("[%p/%d] wakeup\n", buf, buf->top_field);
163 em28xx_isocdbg("[%p/%d] wakeup\n", buf, buf->vb.i);
164 buf->vb.state = VIDEOBUF_DONE;
165 buf->vb.field_count++;
166 do_gettimeofday(&buf->vb.ts);
167 140
168 dev->isoc_ctl.vid_buf = NULL; 141 buf->vb.v4l2_buf.sequence = dev->field_count++;
142 buf->vb.v4l2_buf.field = V4L2_FIELD_INTERLACED;
143 v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp);
169 144
170 list_del(&buf->vb.queue); 145 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_DONE);
171 wake_up(&buf->vb.done);
172}
173
174static inline void vbi_buffer_filled(struct em28xx *dev,
175 struct em28xx_dmaqueue *dma_q,
176 struct em28xx_buffer *buf)
177{
178 /* Advice that buffer was filled */
179 em28xx_isocdbg("[%p/%d] wakeup\n", buf, buf->vb.i);
180
181 buf->vb.state = VIDEOBUF_DONE;
182 buf->vb.field_count++;
183 do_gettimeofday(&buf->vb.ts);
184
185 dev->isoc_ctl.vbi_buf = NULL;
186
187 list_del(&buf->vb.queue);
188 wake_up(&buf->vb.done);
189} 146}
190 147
191/* 148/*
192 * Identify the buffer header type and properly handles 149 * Copy picture data from USB buffer to videobuf buffer
193 */ 150 */
194static void em28xx_copy_video(struct em28xx *dev, 151static void em28xx_copy_video(struct em28xx *dev,
195 struct em28xx_dmaqueue *dma_q,
196 struct em28xx_buffer *buf, 152 struct em28xx_buffer *buf,
197 unsigned char *p, 153 unsigned char *usb_buf,
198 unsigned char *outp, unsigned long len) 154 unsigned long len)
199{ 155{
200 void *fieldstart, *startwrite, *startread; 156 void *fieldstart, *startwrite, *startread;
201 int linesdone, currlinedone, offset, lencopy, remain; 157 int linesdone, currlinedone, offset, lencopy, remain;
202 int bytesperline = dev->width << 1; 158 int bytesperline = dev->width << 1;
203 159
204 if (dma_q->pos + len > buf->vb.size) 160 if (buf->pos + len > buf->length)
205 len = buf->vb.size - dma_q->pos; 161 len = buf->length - buf->pos;
206 162
207 startread = p; 163 startread = usb_buf;
208 remain = len; 164 remain = len;
209 165
210 if (dev->progressive) 166 if (dev->progressive || buf->top_field)
211 fieldstart = outp; 167 fieldstart = buf->vb_buf;
212 else { 168 else /* interlaced mode, even nr. of lines */
213 /* Interlaces two half frames */ 169 fieldstart = buf->vb_buf + bytesperline;
214 if (buf->top_field)
215 fieldstart = outp;
216 else
217 fieldstart = outp + bytesperline;
218 }
219 170
220 linesdone = dma_q->pos / bytesperline; 171 linesdone = buf->pos / bytesperline;
221 currlinedone = dma_q->pos % bytesperline; 172 currlinedone = buf->pos % bytesperline;
222 173
223 if (dev->progressive) 174 if (dev->progressive)
224 offset = linesdone * bytesperline + currlinedone; 175 offset = linesdone * bytesperline + currlinedone;
@@ -229,11 +180,12 @@ static void em28xx_copy_video(struct em28xx *dev,
229 lencopy = bytesperline - currlinedone; 180 lencopy = bytesperline - currlinedone;
230 lencopy = lencopy > remain ? remain : lencopy; 181 lencopy = lencopy > remain ? remain : lencopy;
231 182
232 if ((char *)startwrite + lencopy > (char *)outp + buf->vb.size) { 183 if ((char *)startwrite + lencopy > (char *)buf->vb_buf + buf->length) {
233 em28xx_isocdbg("Overflow of %zi bytes past buffer end (1)\n", 184 em28xx_isocdbg("Overflow of %zi bytes past buffer end (1)\n",
234 ((char *)startwrite + lencopy) - 185 ((char *)startwrite + lencopy) -
235 ((char *)outp + buf->vb.size)); 186 ((char *)buf->vb_buf + buf->length));
236 remain = (char *)outp + buf->vb.size - (char *)startwrite; 187 remain = (char *)buf->vb_buf + buf->length -
188 (char *)startwrite;
237 lencopy = remain; 189 lencopy = remain;
238 } 190 }
239 if (lencopy <= 0) 191 if (lencopy <= 0)
@@ -243,21 +195,24 @@ static void em28xx_copy_video(struct em28xx *dev,
243 remain -= lencopy; 195 remain -= lencopy;
244 196
245 while (remain > 0) { 197 while (remain > 0) {
246 startwrite += lencopy + bytesperline; 198 if (dev->progressive)
199 startwrite += lencopy;
200 else
201 startwrite += lencopy + bytesperline;
247 startread += lencopy; 202 startread += lencopy;
248 if (bytesperline > remain) 203 if (bytesperline > remain)
249 lencopy = remain; 204 lencopy = remain;
250 else 205 else
251 lencopy = bytesperline; 206 lencopy = bytesperline;
252 207
253 if ((char *)startwrite + lencopy > (char *)outp + 208 if ((char *)startwrite + lencopy > (char *)buf->vb_buf +
254 buf->vb.size) { 209 buf->length) {
255 em28xx_isocdbg("Overflow of %zi bytes past buffer end" 210 em28xx_isocdbg("Overflow of %zi bytes past buffer end"
256 "(2)\n", 211 "(2)\n",
257 ((char *)startwrite + lencopy) - 212 ((char *)startwrite + lencopy) -
258 ((char *)outp + buf->vb.size)); 213 ((char *)buf->vb_buf + buf->length));
259 lencopy = remain = (char *)outp + buf->vb.size - 214 lencopy = remain = (char *)buf->vb_buf + buf->length -
260 (char *)startwrite; 215 (char *)startwrite;
261 } 216 }
262 if (lencopy <= 0) 217 if (lencopy <= 0)
263 break; 218 break;
@@ -267,57 +222,29 @@ static void em28xx_copy_video(struct em28xx *dev,
267 remain -= lencopy; 222 remain -= lencopy;
268 } 223 }
269 224
270 dma_q->pos += len; 225 buf->pos += len;
271} 226}
272 227
228/*
229 * Copy VBI data from USB buffer to videobuf buffer
230 */
273static void em28xx_copy_vbi(struct em28xx *dev, 231static void em28xx_copy_vbi(struct em28xx *dev,
274 struct em28xx_dmaqueue *dma_q, 232 struct em28xx_buffer *buf,
275 struct em28xx_buffer *buf, 233 unsigned char *usb_buf,
276 unsigned char *p, 234 unsigned long len)
277 unsigned char *outp, unsigned long len)
278{ 235{
279 void *startwrite, *startread; 236 unsigned int offset;
280 int offset;
281 int bytesperline;
282
283 if (dev == NULL) {
284 em28xx_isocdbg("dev is null\n");
285 return;
286 }
287 bytesperline = dev->vbi_width;
288 237
289 if (dma_q == NULL) { 238 if (buf->pos + len > buf->length)
290 em28xx_isocdbg("dma_q is null\n"); 239 len = buf->length - buf->pos;
291 return;
292 }
293 if (buf == NULL) {
294 return;
295 }
296 if (p == NULL) {
297 em28xx_isocdbg("p is null\n");
298 return;
299 }
300 if (outp == NULL) {
301 em28xx_isocdbg("outp is null\n");
302 return;
303 }
304
305 if (dma_q->pos + len > buf->vb.size)
306 len = buf->vb.size - dma_q->pos;
307
308 startread = p;
309
310 startwrite = outp + dma_q->pos;
311 offset = dma_q->pos;
312 240
241 offset = buf->pos;
313 /* Make sure the bottom field populates the second half of the frame */ 242 /* Make sure the bottom field populates the second half of the frame */
314 if (buf->top_field == 0) { 243 if (buf->top_field == 0)
315 startwrite += bytesperline * dev->vbi_height; 244 offset += dev->vbi_width * dev->vbi_height;
316 offset += bytesperline * dev->vbi_height;
317 }
318 245
319 memcpy(startwrite, startread, len); 246 memcpy(buf->vb_buf + offset, usb_buf, len);
320 dma_q->pos += len; 247 buf->pos += len;
321} 248}
322 249
323static inline void print_err_status(struct em28xx *dev, 250static inline void print_err_status(struct em28xx *dev,
@@ -360,470 +287,444 @@ static inline void print_err_status(struct em28xx *dev,
360} 287}
361 288
362/* 289/*
363 * video-buf generic routine to get the next available buffer 290 * get the next available buffer from dma queue
364 */ 291 */
365static inline void get_next_buf(struct em28xx_dmaqueue *dma_q, 292static inline struct em28xx_buffer *get_next_buf(struct em28xx *dev,
366 struct em28xx_buffer **buf) 293 struct em28xx_dmaqueue *dma_q)
367{ 294{
368 struct em28xx *dev = container_of(dma_q, struct em28xx, vidq); 295 struct em28xx_buffer *buf;
369 char *outp;
370 296
371 if (list_empty(&dma_q->active)) { 297 if (list_empty(&dma_q->active)) {
372 em28xx_isocdbg("No active queue to serve\n"); 298 em28xx_isocdbg("No active queue to serve\n");
373 dev->isoc_ctl.vid_buf = NULL; 299 return NULL;
374 *buf = NULL;
375 return;
376 } 300 }
377 301
378 /* Get the next buffer */ 302 /* Get the next buffer */
379 *buf = list_entry(dma_q->active.next, struct em28xx_buffer, vb.queue); 303 buf = list_entry(dma_q->active.next, struct em28xx_buffer, list);
380
381 /* Cleans up buffer - Useful for testing for frame/URB loss */ 304 /* Cleans up buffer - Useful for testing for frame/URB loss */
382 outp = videobuf_to_vmalloc(&(*buf)->vb); 305 list_del(&buf->list);
383 memset(outp, 0, (*buf)->vb.size); 306 buf->pos = 0;
307 buf->vb_buf = buf->mem;
384 308
385 dev->isoc_ctl.vid_buf = *buf; 309 return buf;
386
387 return;
388} 310}
389 311
390/* 312/*
391 * video-buf generic routine to get the next available VBI buffer 313 * Finish the current buffer if completed and prepare for the next field
392 */ 314 */
393static inline void vbi_get_next_buf(struct em28xx_dmaqueue *dma_q, 315static struct em28xx_buffer *
394 struct em28xx_buffer **buf) 316finish_field_prepare_next(struct em28xx *dev,
395{ 317 struct em28xx_buffer *buf,
396 struct em28xx *dev = container_of(dma_q, struct em28xx, vbiq); 318 struct em28xx_dmaqueue *dma_q)
397 char *outp; 319{
398 320 if (dev->progressive || dev->top_field) { /* Brand new frame */
399 if (list_empty(&dma_q->active)) { 321 if (buf != NULL)
400 em28xx_isocdbg("No active queue to serve\n"); 322 finish_buffer(dev, buf);
401 dev->isoc_ctl.vbi_buf = NULL; 323 buf = get_next_buf(dev, dma_q);
402 *buf = NULL; 324 }
403 return; 325 if (buf != NULL) {
326 buf->top_field = dev->top_field;
327 buf->pos = 0;
404 } 328 }
405 329
406 /* Get the next buffer */ 330 return buf;
407 *buf = list_entry(dma_q->active.next, struct em28xx_buffer, vb.queue);
408 /* Cleans up buffer - Useful for testing for frame/URB loss */
409 outp = videobuf_to_vmalloc(&(*buf)->vb);
410 memset(outp, 0x00, (*buf)->vb.size);
411
412 dev->isoc_ctl.vbi_buf = *buf;
413
414 return;
415} 331}
416 332
417/* 333/*
418 * Controls the isoc copy of each urb packet 334 * Process data packet according to the em2710/em2750/em28xx frame data format
419 */ 335 */
420static inline int em28xx_isoc_copy(struct em28xx *dev, struct urb *urb) 336static inline void process_frame_data_em28xx(struct em28xx *dev,
337 unsigned char *data_pkt,
338 unsigned int data_len)
421{ 339{
422 struct em28xx_buffer *buf; 340 struct em28xx_buffer *buf = dev->usb_ctl.vid_buf;
341 struct em28xx_buffer *vbi_buf = dev->usb_ctl.vbi_buf;
423 struct em28xx_dmaqueue *dma_q = &dev->vidq; 342 struct em28xx_dmaqueue *dma_q = &dev->vidq;
424 unsigned char *outp = NULL; 343 struct em28xx_dmaqueue *vbi_dma_q = &dev->vbiq;
425 int i, len = 0, rc = 1;
426 unsigned char *p;
427
428 if (!dev)
429 return 0;
430
431 if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED))
432 return 0;
433
434 if (urb->status < 0) {
435 print_err_status(dev, -1, urb->status);
436 if (urb->status == -ENOENT)
437 return 0;
438 }
439
440 buf = dev->isoc_ctl.vid_buf;
441 if (buf != NULL)
442 outp = videobuf_to_vmalloc(&buf->vb);
443
444 for (i = 0; i < urb->number_of_packets; i++) {
445 int status = urb->iso_frame_desc[i].status;
446 344
447 if (status < 0) { 345 /* capture type 0 = vbi start
448 print_err_status(dev, i, status); 346 capture type 1 = vbi in progress
449 if (urb->iso_frame_desc[i].status != -EPROTO) 347 capture type 2 = video start
450 continue; 348 capture type 3 = video in progress */
349 if (data_len >= 4) {
350 /* NOTE: Headers are always 4 bytes and
351 * never split across packets */
352 if (data_pkt[0] == 0x88 && data_pkt[1] == 0x88 &&
353 data_pkt[2] == 0x88 && data_pkt[3] == 0x88) {
354 /* Continuation */
355 data_pkt += 4;
356 data_len -= 4;
357 } else if (data_pkt[0] == 0x33 && data_pkt[1] == 0x95) {
358 /* Field start (VBI mode) */
359 dev->capture_type = 0;
360 dev->vbi_read = 0;
361 em28xx_isocdbg("VBI START HEADER !!!\n");
362 dev->top_field = !(data_pkt[2] & 1);
363 data_pkt += 4;
364 data_len -= 4;
365 } else if (data_pkt[0] == 0x22 && data_pkt[1] == 0x5a) {
366 /* Field start (VBI disabled) */
367 dev->capture_type = 2;
368 em28xx_isocdbg("VIDEO START HEADER !!!\n");
369 dev->top_field = !(data_pkt[2] & 1);
370 data_pkt += 4;
371 data_len -= 4;
451 } 372 }
373 }
374 /* NOTE: With bulk transfers, intermediate data packets
375 * have no continuation header */
452 376
453 len = urb->iso_frame_desc[i].actual_length - 4; 377 if (dev->capture_type == 0) {
378 vbi_buf = finish_field_prepare_next(dev, vbi_buf, vbi_dma_q);
379 dev->usb_ctl.vbi_buf = vbi_buf;
380 dev->capture_type = 1;
381 }
454 382
455 if (urb->iso_frame_desc[i].actual_length <= 0) { 383 if (dev->capture_type == 1) {
456 /* em28xx_isocdbg("packet %d is empty",i); - spammy */ 384 int vbi_size = dev->vbi_width * dev->vbi_height;
457 continue; 385 int vbi_data_len = ((dev->vbi_read + data_len) > vbi_size) ?
458 } 386 (vbi_size - dev->vbi_read) : data_len;
459 if (urb->iso_frame_desc[i].actual_length >
460 dev->max_pkt_size) {
461 em28xx_isocdbg("packet bigger than packet size");
462 continue;
463 }
464 387
465 p = urb->transfer_buffer + urb->iso_frame_desc[i].offset; 388 /* Copy VBI data */
389 if (vbi_buf != NULL)
390 em28xx_copy_vbi(dev, vbi_buf, data_pkt, vbi_data_len);
391 dev->vbi_read += vbi_data_len;
466 392
467 /* FIXME: incomplete buffer checks where removed to make 393 if (vbi_data_len < data_len) {
468 logic simpler. Impacts of those changes should be evaluated 394 /* Continue with copying video data */
469 */ 395 dev->capture_type = 2;
470 if (p[0] == 0x33 && p[1] == 0x95 && p[2] == 0x00) { 396 data_pkt += vbi_data_len;
471 em28xx_isocdbg("VBI HEADER!!!\n"); 397 data_len -= vbi_data_len;
472 /* FIXME: Should add vbi copy */
473 continue;
474 } 398 }
475 if (p[0] == 0x22 && p[1] == 0x5a) { 399 }
476 em28xx_isocdbg("Video frame %d, length=%i, %s\n", p[2],
477 len, (p[2] & 1) ? "odd" : "even");
478
479 if (dev->progressive || !(p[2] & 1)) {
480 if (buf != NULL)
481 buffer_filled(dev, dma_q, buf);
482 get_next_buf(dma_q, &buf);
483 if (buf == NULL)
484 outp = NULL;
485 else
486 outp = videobuf_to_vmalloc(&buf->vb);
487 }
488
489 if (buf != NULL) {
490 if (p[2] & 1)
491 buf->top_field = 0;
492 else
493 buf->top_field = 1;
494 }
495 400
496 dma_q->pos = 0; 401 if (dev->capture_type == 2) {
497 } 402 buf = finish_field_prepare_next(dev, buf, dma_q);
498 if (buf != NULL) { 403 dev->usb_ctl.vid_buf = buf;
499 if (p[0] != 0x88 && p[0] != 0x22) { 404 dev->capture_type = 3;
500 em28xx_isocdbg("frame is not complete\n");
501 len += 4;
502 } else {
503 p += 4;
504 }
505 em28xx_copy_video(dev, dma_q, buf, p, outp, len);
506 }
507 } 405 }
508 return rc; 406
407 if (dev->capture_type == 3 && buf != NULL && data_len > 0)
408 em28xx_copy_video(dev, buf, data_pkt, data_len);
509} 409}
510 410
511/* Version of isoc handler that takes into account a mixture of video and 411/* Processes and copies the URB data content (video and VBI data) */
512 VBI data */ 412static inline int em28xx_urb_data_copy(struct em28xx *dev, struct urb *urb)
513static inline int em28xx_isoc_copy_vbi(struct em28xx *dev, struct urb *urb)
514{ 413{
515 struct em28xx_buffer *buf, *vbi_buf; 414 int xfer_bulk, num_packets, i;
516 struct em28xx_dmaqueue *dma_q = &dev->vidq; 415 unsigned char *usb_data_pkt;
517 struct em28xx_dmaqueue *vbi_dma_q = &dev->vbiq; 416 unsigned int usb_data_len;
518 unsigned char *outp = NULL;
519 unsigned char *vbioutp = NULL;
520 int i, len = 0, rc = 1;
521 unsigned char *p;
522 int vbi_size;
523 417
524 if (!dev) 418 if (!dev)
525 return 0; 419 return 0;
526 420
527 if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED)) 421 if (dev->disconnected)
528 return 0; 422 return 0;
529 423
530 if (urb->status < 0) { 424 if (urb->status < 0)
531 print_err_status(dev, -1, urb->status); 425 print_err_status(dev, -1, urb->status);
532 if (urb->status == -ENOENT)
533 return 0;
534 }
535 426
536 buf = dev->isoc_ctl.vid_buf; 427 xfer_bulk = usb_pipebulk(urb->pipe);
537 if (buf != NULL)
538 outp = videobuf_to_vmalloc(&buf->vb);
539 428
540 vbi_buf = dev->isoc_ctl.vbi_buf; 429 if (xfer_bulk) /* bulk */
541 if (vbi_buf != NULL) 430 num_packets = 1;
542 vbioutp = videobuf_to_vmalloc(&vbi_buf->vb); 431 else /* isoc */
432 num_packets = urb->number_of_packets;
543 433
544 for (i = 0; i < urb->number_of_packets; i++) { 434 for (i = 0; i < num_packets; i++) {
545 int status = urb->iso_frame_desc[i].status; 435 if (xfer_bulk) { /* bulk */
436 usb_data_len = urb->actual_length;
546 437
547 if (status < 0) { 438 usb_data_pkt = urb->transfer_buffer;
548 print_err_status(dev, i, status); 439 } else { /* isoc */
549 if (urb->iso_frame_desc[i].status != -EPROTO) 440 if (urb->iso_frame_desc[i].status < 0) {
441 print_err_status(dev, i,
442 urb->iso_frame_desc[i].status);
443 if (urb->iso_frame_desc[i].status != -EPROTO)
444 continue;
445 }
446
447 usb_data_len = urb->iso_frame_desc[i].actual_length;
448 if (usb_data_len > dev->max_pkt_size) {
449 em28xx_isocdbg("packet bigger than packet size");
550 continue; 450 continue;
551 } 451 }
552 452
553 len = urb->iso_frame_desc[i].actual_length; 453 usb_data_pkt = urb->transfer_buffer +
554 if (urb->iso_frame_desc[i].actual_length <= 0) { 454 urb->iso_frame_desc[i].offset;
555 /* em28xx_isocdbg("packet %d is empty",i); - spammy */
556 continue;
557 }
558 if (urb->iso_frame_desc[i].actual_length >
559 dev->max_pkt_size) {
560 em28xx_isocdbg("packet bigger than packet size");
561 continue;
562 } 455 }
563 456
564 p = urb->transfer_buffer + urb->iso_frame_desc[i].offset; 457 if (usb_data_len == 0) {
565 458 /* NOTE: happens very often with isoc transfers */
566 /* capture type 0 = vbi start 459 /* em28xx_usbdbg("packet %d is empty",i); - spammy */
567 capture type 1 = video start 460 continue;
568 capture type 2 = video in progress */
569 if (p[0] == 0x33 && p[1] == 0x95) {
570 dev->capture_type = 0;
571 dev->vbi_read = 0;
572 em28xx_isocdbg("VBI START HEADER!!!\n");
573 dev->cur_field = p[2];
574 p += 4;
575 len -= 4;
576 } else if (p[0] == 0x88 && p[1] == 0x88 &&
577 p[2] == 0x88 && p[3] == 0x88) {
578 /* continuation */
579 p += 4;
580 len -= 4;
581 } else if (p[0] == 0x22 && p[1] == 0x5a) {
582 /* start video */
583 p += 4;
584 len -= 4;
585 } 461 }
586 462
587 vbi_size = dev->vbi_width * dev->vbi_height; 463 process_frame_data_em28xx(dev, usb_data_pkt, usb_data_len);
588 464 }
589 if (dev->capture_type == 0) { 465 return 1;
590 if (dev->vbi_read >= vbi_size) { 466}
591 /* We've already read all the VBI data, so
592 treat the rest as video */
593 em28xx_isocdbg("dev->vbi_read > vbi_size\n");
594 } else if ((dev->vbi_read + len) < vbi_size) {
595 /* This entire frame is VBI data */
596 if (dev->vbi_read == 0 &&
597 (!(dev->cur_field & 1))) {
598 /* Brand new frame */
599 if (vbi_buf != NULL)
600 vbi_buffer_filled(dev,
601 vbi_dma_q,
602 vbi_buf);
603 vbi_get_next_buf(vbi_dma_q, &vbi_buf);
604 if (vbi_buf == NULL)
605 vbioutp = NULL;
606 else
607 vbioutp = videobuf_to_vmalloc(
608 &vbi_buf->vb);
609 }
610
611 if (dev->vbi_read == 0) {
612 vbi_dma_q->pos = 0;
613 if (vbi_buf != NULL) {
614 if (dev->cur_field & 1)
615 vbi_buf->top_field = 0;
616 else
617 vbi_buf->top_field = 1;
618 }
619 }
620
621 dev->vbi_read += len;
622 em28xx_copy_vbi(dev, vbi_dma_q, vbi_buf, p,
623 vbioutp, len);
624 } else {
625 /* Some of this frame is VBI data and some is
626 video data */
627 int vbi_data_len = vbi_size - dev->vbi_read;
628 dev->vbi_read += vbi_data_len;
629 em28xx_copy_vbi(dev, vbi_dma_q, vbi_buf, p,
630 vbioutp, vbi_data_len);
631 dev->capture_type = 1;
632 p += vbi_data_len;
633 len -= vbi_data_len;
634 }
635 }
636 467
637 if (dev->capture_type == 1) {
638 dev->capture_type = 2;
639 if (dev->progressive || !(dev->cur_field & 1)) {
640 if (buf != NULL)
641 buffer_filled(dev, dma_q, buf);
642 get_next_buf(dma_q, &buf);
643 if (buf == NULL)
644 outp = NULL;
645 else
646 outp = videobuf_to_vmalloc(&buf->vb);
647 }
648 if (buf != NULL) {
649 if (dev->cur_field & 1)
650 buf->top_field = 0;
651 else
652 buf->top_field = 1;
653 }
654 468
655 dma_q->pos = 0; 469static int get_ressource(enum v4l2_buf_type f_type)
656 } 470{
471 switch (f_type) {
472 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
473 return EM28XX_RESOURCE_VIDEO;
474 case V4L2_BUF_TYPE_VBI_CAPTURE:
475 return EM28XX_RESOURCE_VBI;
476 default:
477 BUG();
478 return 0;
479 }
480}
657 481
658 if (buf != NULL && dev->capture_type == 2) { 482/* Usage lock check functions */
659 if (len >= 4 && p[0] == 0x88 && p[1] == 0x88 && 483static int res_get(struct em28xx *dev, enum v4l2_buf_type f_type)
660 p[2] == 0x88 && p[3] == 0x88) { 484{
661 p += 4; 485 int res_type = get_ressource(f_type);
662 len -= 4;
663 }
664 if (len >= 4 && p[0] == 0x22 && p[1] == 0x5a) {
665 em28xx_isocdbg("Video frame %d, len=%i, %s\n",
666 p[2], len, (p[2] & 1) ?
667 "odd" : "even");
668 p += 4;
669 len -= 4;
670 }
671 486
672 if (len > 0) 487 /* is it free? */
673 em28xx_copy_video(dev, dma_q, buf, p, outp, 488 if (dev->resources & res_type) {
674 len); 489 /* no, someone else uses it */
675 } 490 return -EBUSY;
676 } 491 }
677 return rc; 492
493 /* it's free, grab it */
494 dev->resources |= res_type;
495 em28xx_videodbg("res: get %d\n", res_type);
496 return 0;
678} 497}
679 498
499static void res_free(struct em28xx *dev, enum v4l2_buf_type f_type)
500{
501 int res_type = get_ressource(f_type);
502
503 dev->resources &= ~res_type;
504 em28xx_videodbg("res: put %d\n", res_type);
505}
680 506
681/* ------------------------------------------------------------------ 507/* ------------------------------------------------------------------
682 Videobuf operations 508 Videobuf2 operations
683 ------------------------------------------------------------------*/ 509 ------------------------------------------------------------------*/
684 510
685static int 511static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
686buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size) 512 unsigned int *nbuffers, unsigned int *nplanes,
513 unsigned int sizes[], void *alloc_ctxs[])
687{ 514{
688 struct em28xx_fh *fh = vq->priv_data; 515 struct em28xx *dev = vb2_get_drv_priv(vq);
689 struct em28xx *dev = fh->dev; 516 unsigned long size;
690 struct v4l2_frequency f;
691 517
692 *size = (fh->dev->width * fh->dev->height * dev->format->depth + 7) 518 if (fmt)
693 >> 3; 519 size = fmt->fmt.pix.sizeimage;
694 520 else
695 if (0 == *count) 521 size = (dev->width * dev->height * dev->format->depth + 7) >> 3;
696 *count = EM28XX_DEF_BUF;
697 522
698 if (*count < EM28XX_MIN_BUF) 523 if (size == 0)
699 *count = EM28XX_MIN_BUF; 524 return -EINVAL;
700 525
701 /* Ask tuner to go to analog or radio mode */ 526 if (0 == *nbuffers)
702 memset(&f, 0, sizeof(f)); 527 *nbuffers = 32;
703 f.frequency = dev->ctl_freq;
704 f.type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
705 528
706 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, &f); 529 *nplanes = 1;
530 sizes[0] = size;
707 531
708 return 0; 532 return 0;
709} 533}
710 534
711/* This is called *without* dev->slock held; please keep it that way */ 535static int
712static void free_buffer(struct videobuf_queue *vq, struct em28xx_buffer *buf) 536buffer_prepare(struct vb2_buffer *vb)
713{ 537{
714 struct em28xx_fh *fh = vq->priv_data; 538 struct em28xx *dev = vb2_get_drv_priv(vb->vb2_queue);
715 struct em28xx *dev = fh->dev; 539 struct em28xx_buffer *buf = container_of(vb, struct em28xx_buffer, vb);
716 unsigned long flags = 0; 540 unsigned long size;
717 if (in_interrupt())
718 BUG();
719 541
720 /* We used to wait for the buffer to finish here, but this didn't work 542 em28xx_videodbg("%s, field=%d\n", __func__, vb->v4l2_buf.field);
721 because, as we were keeping the state as VIDEOBUF_QUEUED,
722 videobuf_queue_cancel marked it as finished for us.
723 (Also, it could wedge forever if the hardware was misconfigured.)
724 543
725 This should be safe; by the time we get here, the buffer isn't 544 size = (dev->width * dev->height * dev->format->depth + 7) >> 3;
726 queued anymore. If we ever start marking the buffers as
727 VIDEOBUF_ACTIVE, it won't be, though.
728 */
729 spin_lock_irqsave(&dev->slock, flags);
730 if (dev->isoc_ctl.vid_buf == buf)
731 dev->isoc_ctl.vid_buf = NULL;
732 spin_unlock_irqrestore(&dev->slock, flags);
733 545
734 videobuf_vmalloc_free(&buf->vb); 546 if (vb2_plane_size(vb, 0) < size) {
735 buf->vb.state = VIDEOBUF_NEEDS_INIT; 547 em28xx_videodbg("%s data will not fit into plane (%lu < %lu)\n",
548 __func__, vb2_plane_size(vb, 0), size);
549 return -EINVAL;
550 }
551 vb2_set_plane_payload(&buf->vb, 0, size);
552
553 return 0;
736} 554}
737 555
738static int 556int em28xx_start_analog_streaming(struct vb2_queue *vq, unsigned int count)
739buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
740 enum v4l2_field field)
741{ 557{
742 struct em28xx_fh *fh = vq->priv_data; 558 struct em28xx *dev = vb2_get_drv_priv(vq);
743 struct em28xx_buffer *buf = container_of(vb, struct em28xx_buffer, vb); 559 struct v4l2_frequency f;
744 struct em28xx *dev = fh->dev; 560 int rc = 0;
745 int rc = 0, urb_init = 0;
746 561
747 buf->vb.size = (fh->dev->width * fh->dev->height * dev->format->depth 562 em28xx_videodbg("%s\n", __func__);
748 + 7) >> 3;
749 563
750 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) 564 /* Make sure streaming is not already in progress for this type
751 return -EINVAL; 565 of filehandle (e.g. video, vbi) */
566 rc = res_get(dev, vq->type);
567 if (rc)
568 return rc;
569
570 if (dev->streaming_users++ == 0) {
571 /* First active streaming user, so allocate all the URBs */
752 572
753 buf->vb.width = dev->width; 573 /* Allocate the USB bandwidth */
754 buf->vb.height = dev->height; 574 em28xx_set_alternate(dev);
755 buf->vb.field = field; 575
576 /* Needed, since GPIO might have disabled power of
577 some i2c device
578 */
579 em28xx_wake_i2c(dev);
756 580
757 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { 581 dev->capture_type = -1;
758 rc = videobuf_iolock(vq, &buf->vb, NULL); 582 rc = em28xx_init_usb_xfer(dev, EM28XX_ANALOG_MODE,
583 dev->analog_xfer_bulk,
584 EM28XX_NUM_BUFS,
585 dev->max_pkt_size,
586 dev->packet_multiplier,
587 em28xx_urb_data_copy);
759 if (rc < 0) 588 if (rc < 0)
760 goto fail; 589 goto fail;
761 }
762 590
763 if (!dev->isoc_ctl.analog_bufs.num_bufs) 591 /*
764 urb_init = 1; 592 * djh: it's not clear whether this code is still needed. I'm
593 * leaving it in here for now entirely out of concern for
594 * backward compatibility (the old code did it)
595 */
765 596
766 if (urb_init) { 597 /* Ask tuner to go to analog or radio mode */
767 if (em28xx_vbi_supported(dev) == 1) 598 memset(&f, 0, sizeof(f));
768 rc = em28xx_init_isoc(dev, EM28XX_ANALOG_MODE, 599 f.frequency = dev->ctl_freq;
769 EM28XX_NUM_PACKETS, 600 if (vq->owner && vq->owner->vdev->vfl_type == VFL_TYPE_RADIO)
770 EM28XX_NUM_BUFS, 601 f.type = V4L2_TUNER_RADIO;
771 dev->max_pkt_size,
772 em28xx_isoc_copy_vbi);
773 else 602 else
774 rc = em28xx_init_isoc(dev, EM28XX_ANALOG_MODE, 603 f.type = V4L2_TUNER_ANALOG_TV;
775 EM28XX_NUM_PACKETS, 604 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, &f);
776 EM28XX_NUM_BUFS,
777 dev->max_pkt_size,
778 em28xx_isoc_copy);
779 if (rc < 0)
780 goto fail;
781 } 605 }
782 606
783 buf->vb.state = VIDEOBUF_PREPARED;
784 return 0;
785
786fail: 607fail:
787 free_buffer(vq, buf);
788 return rc; 608 return rc;
789} 609}
790 610
791static void 611static int em28xx_stop_streaming(struct vb2_queue *vq)
792buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
793{ 612{
794 struct em28xx_buffer *buf = container_of(vb, 613 struct em28xx *dev = vb2_get_drv_priv(vq);
795 struct em28xx_buffer, 614 struct em28xx_dmaqueue *vidq = &dev->vidq;
796 vb); 615 unsigned long flags = 0;
797 struct em28xx_fh *fh = vq->priv_data; 616
798 struct em28xx *dev = fh->dev; 617 em28xx_videodbg("%s\n", __func__);
799 struct em28xx_dmaqueue *vidq = &dev->vidq; 618
619 res_free(dev, vq->type);
620
621 if (dev->streaming_users-- == 1) {
622 /* Last active user, so shutdown all the URBS */
623 em28xx_uninit_usb_xfer(dev, EM28XX_ANALOG_MODE);
624 }
800 625
801 buf->vb.state = VIDEOBUF_QUEUED; 626 spin_lock_irqsave(&dev->slock, flags);
802 list_add_tail(&buf->vb.queue, &vidq->active); 627 while (!list_empty(&vidq->active)) {
628 struct em28xx_buffer *buf;
629 buf = list_entry(vidq->active.next, struct em28xx_buffer, list);
630 list_del(&buf->list);
631 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
632 }
633 dev->usb_ctl.vid_buf = NULL;
634 spin_unlock_irqrestore(&dev->slock, flags);
803 635
636 return 0;
804} 637}
805 638
806static void buffer_release(struct videobuf_queue *vq, 639int em28xx_stop_vbi_streaming(struct vb2_queue *vq)
807 struct videobuf_buffer *vb)
808{ 640{
809 struct em28xx_buffer *buf = container_of(vb, 641 struct em28xx *dev = vb2_get_drv_priv(vq);
810 struct em28xx_buffer, 642 struct em28xx_dmaqueue *vbiq = &dev->vbiq;
811 vb); 643 unsigned long flags = 0;
812 struct em28xx_fh *fh = vq->priv_data; 644
813 struct em28xx *dev = (struct em28xx *)fh->dev; 645 em28xx_videodbg("%s\n", __func__);
814 646
815 em28xx_isocdbg("em28xx: called buffer_release\n"); 647 res_free(dev, vq->type);
816 648
817 free_buffer(vq, buf); 649 if (dev->streaming_users-- == 1) {
650 /* Last active user, so shutdown all the URBS */
651 em28xx_uninit_usb_xfer(dev, EM28XX_ANALOG_MODE);
652 }
653
654 spin_lock_irqsave(&dev->slock, flags);
655 while (!list_empty(&vbiq->active)) {
656 struct em28xx_buffer *buf;
657 buf = list_entry(vbiq->active.next, struct em28xx_buffer, list);
658 list_del(&buf->list);
659 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
660 }
661 dev->usb_ctl.vbi_buf = NULL;
662 spin_unlock_irqrestore(&dev->slock, flags);
663
664 return 0;
818} 665}
819 666
820static struct videobuf_queue_ops em28xx_video_qops = { 667static void
821 .buf_setup = buffer_setup, 668buffer_queue(struct vb2_buffer *vb)
669{
670 struct em28xx *dev = vb2_get_drv_priv(vb->vb2_queue);
671 struct em28xx_buffer *buf = container_of(vb, struct em28xx_buffer, vb);
672 struct em28xx_dmaqueue *vidq = &dev->vidq;
673 unsigned long flags = 0;
674
675 em28xx_videodbg("%s\n", __func__);
676 buf->mem = vb2_plane_vaddr(vb, 0);
677 buf->length = vb2_plane_size(vb, 0);
678
679 spin_lock_irqsave(&dev->slock, flags);
680 list_add_tail(&buf->list, &vidq->active);
681 spin_unlock_irqrestore(&dev->slock, flags);
682}
683
684static struct vb2_ops em28xx_video_qops = {
685 .queue_setup = queue_setup,
822 .buf_prepare = buffer_prepare, 686 .buf_prepare = buffer_prepare,
823 .buf_queue = buffer_queue, 687 .buf_queue = buffer_queue,
824 .buf_release = buffer_release, 688 .start_streaming = em28xx_start_analog_streaming,
689 .stop_streaming = em28xx_stop_streaming,
690 .wait_prepare = vb2_ops_wait_prepare,
691 .wait_finish = vb2_ops_wait_finish,
825}; 692};
826 693
694int em28xx_vb2_setup(struct em28xx *dev)
695{
696 int rc;
697 struct vb2_queue *q;
698
699 /* Setup Videobuf2 for Video capture */
700 q = &dev->vb_vidq;
701 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
702 q->io_modes = VB2_READ | VB2_MMAP | VB2_USERPTR | VB2_DMABUF;
703 q->drv_priv = dev;
704 q->buf_struct_size = sizeof(struct em28xx_buffer);
705 q->ops = &em28xx_video_qops;
706 q->mem_ops = &vb2_vmalloc_memops;
707
708 rc = vb2_queue_init(q);
709 if (rc < 0)
710 return rc;
711
712 /* Setup Videobuf2 for VBI capture */
713 q = &dev->vb_vbiq;
714 q->type = V4L2_BUF_TYPE_VBI_CAPTURE;
715 q->io_modes = VB2_READ | VB2_MMAP | VB2_USERPTR;
716 q->drv_priv = dev;
717 q->buf_struct_size = sizeof(struct em28xx_buffer);
718 q->ops = &em28xx_vbi_qops;
719 q->mem_ops = &vb2_vmalloc_memops;
720
721 rc = vb2_queue_init(q);
722 if (rc < 0)
723 return rc;
724
725 return 0;
726}
727
827/********************* v4l2 interface **************************************/ 728/********************* v4l2 interface **************************************/
828 729
829static void video_mux(struct em28xx *dev, int index) 730static void video_mux(struct em28xx *dev, int index)
@@ -856,143 +757,54 @@ static void video_mux(struct em28xx *dev, int index)
856 em28xx_audio_analog_set(dev); 757 em28xx_audio_analog_set(dev);
857} 758}
858 759
859/* Usage lock check functions */ 760void em28xx_ctrl_notify(struct v4l2_ctrl *ctrl, void *priv)
860static int res_get(struct em28xx_fh *fh, unsigned int bit)
861{
862 struct em28xx *dev = fh->dev;
863
864 if (fh->resources & bit)
865 /* have it already allocated */
866 return 1;
867
868 /* is it free? */
869 if (dev->resources & bit) {
870 /* no, someone else uses it */
871 return 0;
872 }
873 /* it's free, grab it */
874 fh->resources |= bit;
875 dev->resources |= bit;
876 em28xx_videodbg("res: get %d\n", bit);
877 return 1;
878}
879
880static int res_check(struct em28xx_fh *fh, unsigned int bit)
881{
882 return fh->resources & bit;
883}
884
885static int res_locked(struct em28xx *dev, unsigned int bit)
886{
887 return dev->resources & bit;
888}
889
890static void res_free(struct em28xx_fh *fh, unsigned int bits)
891{ 761{
892 struct em28xx *dev = fh->dev; 762 struct em28xx *dev = priv;
893
894 BUG_ON((fh->resources & bits) != bits);
895
896 fh->resources &= ~bits;
897 dev->resources &= ~bits;
898 em28xx_videodbg("res: put %d\n", bits);
899}
900
901static int get_ressource(struct em28xx_fh *fh)
902{
903 switch (fh->type) {
904 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
905 return EM28XX_RESOURCE_VIDEO;
906 case V4L2_BUF_TYPE_VBI_CAPTURE:
907 return EM28XX_RESOURCE_VBI;
908 default:
909 BUG();
910 return 0;
911 }
912}
913
914/*
915 * ac97_queryctrl()
916 * return the ac97 supported controls
917 */
918static int ac97_queryctrl(struct v4l2_queryctrl *qc)
919{
920 int i;
921 763
922 for (i = 0; i < ARRAY_SIZE(ac97_qctrl); i++) { 764 /*
923 if (qc->id && qc->id == ac97_qctrl[i].id) { 765 * In the case of non-AC97 volume controls, we still need
924 memcpy(qc, &(ac97_qctrl[i]), sizeof(*qc)); 766 * to do some setups at em28xx, in order to mute/unmute
925 return 0; 767 * and to adjust audio volume. However, the value ranges
926 } 768 * should be checked by the corresponding V4L subdriver.
927 } 769 */
928
929 /* Control is not ac97 related */
930 return 1;
931}
932
933/*
934 * ac97_get_ctrl()
935 * return the current values for ac97 mute and volume
936 */
937static int ac97_get_ctrl(struct em28xx *dev, struct v4l2_control *ctrl)
938{
939 switch (ctrl->id) { 770 switch (ctrl->id) {
940 case V4L2_CID_AUDIO_MUTE: 771 case V4L2_CID_AUDIO_MUTE:
941 ctrl->value = dev->mute; 772 dev->mute = ctrl->val;
942 return 0; 773 em28xx_audio_analog_set(dev);
774 break;
943 case V4L2_CID_AUDIO_VOLUME: 775 case V4L2_CID_AUDIO_VOLUME:
944 ctrl->value = dev->volume; 776 dev->volume = ctrl->val;
945 return 0; 777 em28xx_audio_analog_set(dev);
946 default: 778 break;
947 /* Control is not ac97 related */
948 return 1;
949 } 779 }
950} 780}
951 781
952/* 782static int em28xx_s_ctrl(struct v4l2_ctrl *ctrl)
953 * ac97_set_ctrl()
954 * set values for ac97 mute and volume
955 */
956static int ac97_set_ctrl(struct em28xx *dev, const struct v4l2_control *ctrl)
957{ 783{
958 int i; 784 struct em28xx *dev = container_of(ctrl->handler, struct em28xx, ctrl_handler);
959
960 for (i = 0; i < ARRAY_SIZE(ac97_qctrl); i++)
961 if (ctrl->id == ac97_qctrl[i].id)
962 goto handle;
963
964 /* Announce that hasn't handle it */
965 return 1;
966
967handle:
968 if (ctrl->value < ac97_qctrl[i].minimum ||
969 ctrl->value > ac97_qctrl[i].maximum)
970 return -ERANGE;
971 785
972 switch (ctrl->id) { 786 switch (ctrl->id) {
973 case V4L2_CID_AUDIO_MUTE: 787 case V4L2_CID_AUDIO_MUTE:
974 dev->mute = ctrl->value; 788 dev->mute = ctrl->val;
975 break; 789 break;
976 case V4L2_CID_AUDIO_VOLUME: 790 case V4L2_CID_AUDIO_VOLUME:
977 dev->volume = ctrl->value; 791 dev->volume = ctrl->val;
978 break; 792 break;
979 } 793 }
980 794
981 return em28xx_audio_analog_set(dev); 795 return em28xx_audio_analog_set(dev);
982} 796}
983 797
798const struct v4l2_ctrl_ops em28xx_ctrl_ops = {
799 .s_ctrl = em28xx_s_ctrl,
800};
801
984static int check_dev(struct em28xx *dev) 802static int check_dev(struct em28xx *dev)
985{ 803{
986 if (dev->state & DEV_DISCONNECTED) { 804 if (dev->disconnected) {
987 em28xx_errdev("v4l2 ioctl: device not present\n"); 805 em28xx_errdev("v4l2 ioctl: device not present\n");
988 return -ENODEV; 806 return -ENODEV;
989 } 807 }
990
991 if (dev->state & DEV_MISCONFIGURED) {
992 em28xx_errdev("v4l2 ioctl: device is misconfigured; "
993 "close and open it again\n");
994 return -EIO;
995 }
996 return 0; 808 return 0;
997} 809}
998 810
@@ -1072,8 +884,11 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
1072 /* the em2800 can only scale down to 50% */ 884 /* the em2800 can only scale down to 50% */
1073 height = height > (3 * maxh / 4) ? maxh : maxh / 2; 885 height = height > (3 * maxh / 4) ? maxh : maxh / 2;
1074 width = width > (3 * maxw / 4) ? maxw : maxw / 2; 886 width = width > (3 * maxw / 4) ? maxw : maxw / 2;
1075 /* MaxPacketSize for em2800 is too small to capture at full resolution 887 /*
1076 * use half of maxw as the scaler can only scale to 50% */ 888 * MaxPacketSize for em2800 is too small to capture at full
889 * resolution use half of maxw as the scaler can only scale
890 * to 50%
891 */
1077 if (width == maxw && height == maxh) 892 if (width == maxw && height == maxh)
1078 width /= 2; 893 width /= 2;
1079 } else { 894 } else {
@@ -1091,7 +906,7 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
1091 f->fmt.pix.width = width; 906 f->fmt.pix.width = width;
1092 f->fmt.pix.height = height; 907 f->fmt.pix.height = height;
1093 f->fmt.pix.pixelformat = fmt->fourcc; 908 f->fmt.pix.pixelformat = fmt->fourcc;
1094 f->fmt.pix.bytesperline = (dev->width * fmt->depth + 7) >> 3; 909 f->fmt.pix.bytesperline = (width * fmt->depth + 7) >> 3;
1095 f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * height; 910 f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * height;
1096 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; 911 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
1097 if (dev->progressive) 912 if (dev->progressive)
@@ -1119,7 +934,6 @@ static int em28xx_set_video_format(struct em28xx *dev, unsigned int fourcc,
1119 /* set new image size */ 934 /* set new image size */
1120 get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale); 935 get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale);
1121 936
1122 em28xx_set_alternate(dev);
1123 em28xx_resolution_set(dev); 937 em28xx_resolution_set(dev);
1124 938
1125 return 0; 939 return 0;
@@ -1128,21 +942,13 @@ static int em28xx_set_video_format(struct em28xx *dev, unsigned int fourcc,
1128static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, 942static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
1129 struct v4l2_format *f) 943 struct v4l2_format *f)
1130{ 944{
1131 struct em28xx_fh *fh = priv; 945 struct em28xx *dev = video_drvdata(file);
1132 struct em28xx *dev = fh->dev;
1133 int rc;
1134 946
1135 rc = check_dev(dev); 947 if (dev->streaming_users > 0)
1136 if (rc < 0) 948 return -EBUSY;
1137 return rc;
1138 949
1139 vidioc_try_fmt_vid_cap(file, priv, f); 950 vidioc_try_fmt_vid_cap(file, priv, f);
1140 951
1141 if (videobuf_queue_is_busy(&fh->vb_vidq)) {
1142 em28xx_errdev("%s queue busy\n", __func__);
1143 return -EBUSY;
1144 }
1145
1146 return em28xx_set_video_format(dev, f->fmt.pix.pixelformat, 952 return em28xx_set_video_format(dev, f->fmt.pix.pixelformat,
1147 f->fmt.pix.width, f->fmt.pix.height); 953 f->fmt.pix.width, f->fmt.pix.height);
1148} 954}
@@ -1153,6 +959,8 @@ static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *norm)
1153 struct em28xx *dev = fh->dev; 959 struct em28xx *dev = fh->dev;
1154 int rc; 960 int rc;
1155 961
962 if (dev->board.is_webcam)
963 return -ENOTTY;
1156 rc = check_dev(dev); 964 rc = check_dev(dev);
1157 if (rc < 0) 965 if (rc < 0)
1158 return rc; 966 return rc;
@@ -1168,6 +976,8 @@ static int vidioc_querystd(struct file *file, void *priv, v4l2_std_id *norm)
1168 struct em28xx *dev = fh->dev; 976 struct em28xx *dev = fh->dev;
1169 int rc; 977 int rc;
1170 978
979 if (dev->board.is_webcam)
980 return -ENOTTY;
1171 rc = check_dev(dev); 981 rc = check_dev(dev);
1172 if (rc < 0) 982 if (rc < 0)
1173 return rc; 983 return rc;
@@ -1184,15 +994,22 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *norm)
1184 struct v4l2_format f; 994 struct v4l2_format f;
1185 int rc; 995 int rc;
1186 996
997 if (dev->board.is_webcam)
998 return -ENOTTY;
999 if (*norm == dev->norm)
1000 return 0;
1187 rc = check_dev(dev); 1001 rc = check_dev(dev);
1188 if (rc < 0) 1002 if (rc < 0)
1189 return rc; 1003 return rc;
1190 1004
1005 if (dev->streaming_users > 0)
1006 return -EBUSY;
1007
1191 dev->norm = *norm; 1008 dev->norm = *norm;
1192 1009
1193 /* Adjusts width/height, if needed */ 1010 /* Adjusts width/height, if needed */
1194 f.fmt.pix.width = dev->width; 1011 f.fmt.pix.width = 720;
1195 f.fmt.pix.height = dev->height; 1012 f.fmt.pix.height = (*norm & V4L2_STD_525_60) ? 480 : 576;
1196 vidioc_try_fmt_vid_cap(file, priv, &f); 1013 vidioc_try_fmt_vid_cap(file, priv, &f);
1197 1014
1198 /* set new image size */ 1015 /* set new image size */
@@ -1216,6 +1033,7 @@ static int vidioc_g_parm(struct file *file, void *priv,
1216 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 1033 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1217 return -EINVAL; 1034 return -EINVAL;
1218 1035
1036 p->parm.capture.readbuffers = EM28XX_MIN_BUF;
1219 if (dev->board.is_webcam) 1037 if (dev->board.is_webcam)
1220 rc = v4l2_device_call_until_err(&dev->v4l2_dev, 0, 1038 rc = v4l2_device_call_until_err(&dev->v4l2_dev, 0,
1221 video, g_parm, p); 1039 video, g_parm, p);
@@ -1233,11 +1051,12 @@ static int vidioc_s_parm(struct file *file, void *priv,
1233 struct em28xx *dev = fh->dev; 1051 struct em28xx *dev = fh->dev;
1234 1052
1235 if (!dev->board.is_webcam) 1053 if (!dev->board.is_webcam)
1236 return -EINVAL; 1054 return -ENOTTY;
1237 1055
1238 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 1056 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1239 return -EINVAL; 1057 return -EINVAL;
1240 1058
1059 p->parm.capture.readbuffers = EM28XX_MIN_BUF;
1241 return v4l2_device_call_until_err(&dev->v4l2_dev, 0, video, s_parm, p); 1060 return v4l2_device_call_until_err(&dev->v4l2_dev, 0, video, s_parm, p);
1242} 1061}
1243 1062
@@ -1276,6 +1095,9 @@ static int vidioc_enum_input(struct file *file, void *priv,
1276 i->type = V4L2_INPUT_TYPE_TUNER; 1095 i->type = V4L2_INPUT_TYPE_TUNER;
1277 1096
1278 i->std = dev->vdev->tvnorms; 1097 i->std = dev->vdev->tvnorms;
1098 /* webcams do not have the STD API */
1099 if (dev->board.is_webcam)
1100 i->capabilities = 0;
1279 1101
1280 return 0; 1102 return 0;
1281} 1103}
@@ -1375,131 +1197,6 @@ static int vidioc_s_audio(struct file *file, void *priv, const struct v4l2_audio
1375 return 0; 1197 return 0;
1376} 1198}
1377 1199
1378static int vidioc_queryctrl(struct file *file, void *priv,
1379 struct v4l2_queryctrl *qc)
1380{
1381 struct em28xx_fh *fh = priv;
1382 struct em28xx *dev = fh->dev;
1383 int id = qc->id;
1384 int rc;
1385
1386 rc = check_dev(dev);
1387 if (rc < 0)
1388 return rc;
1389
1390 memset(qc, 0, sizeof(*qc));
1391
1392 qc->id = id;
1393
1394 /* enumerate AC97 controls */
1395 if (dev->audio_mode.ac97 != EM28XX_NO_AC97) {
1396 rc = ac97_queryctrl(qc);
1397 if (!rc)
1398 return 0;
1399 }
1400
1401 /* enumerate V4L2 device controls */
1402 v4l2_device_call_all(&dev->v4l2_dev, 0, core, queryctrl, qc);
1403
1404 if (qc->type)
1405 return 0;
1406 else
1407 return -EINVAL;
1408}
1409
1410/*
1411 * FIXME: This is an indirect way to check if a control exists at a
1412 * subdev. Instead of that hack, maybe the better would be to change all
1413 * subdevs to return -ENOIOCTLCMD, if an ioctl is not supported.
1414 */
1415static int check_subdev_ctrl(struct em28xx *dev, int id)
1416{
1417 struct v4l2_queryctrl qc;
1418
1419 memset(&qc, 0, sizeof(qc));
1420 qc.id = id;
1421
1422 /* enumerate V4L2 device controls */
1423 v4l2_device_call_all(&dev->v4l2_dev, 0, core, queryctrl, &qc);
1424
1425 if (qc.type)
1426 return 0;
1427 else
1428 return -EINVAL;
1429}
1430
1431static int vidioc_g_ctrl(struct file *file, void *priv,
1432 struct v4l2_control *ctrl)
1433{
1434 struct em28xx_fh *fh = priv;
1435 struct em28xx *dev = fh->dev;
1436 int rc;
1437
1438 rc = check_dev(dev);
1439 if (rc < 0)
1440 return rc;
1441 rc = 0;
1442
1443 /* Set an AC97 control */
1444 if (dev->audio_mode.ac97 != EM28XX_NO_AC97)
1445 rc = ac97_get_ctrl(dev, ctrl);
1446 else
1447 rc = 1;
1448
1449 /* It were not an AC97 control. Sends it to the v4l2 dev interface */
1450 if (rc == 1) {
1451 if (check_subdev_ctrl(dev, ctrl->id))
1452 return -EINVAL;
1453
1454 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_ctrl, ctrl);
1455 rc = 0;
1456 }
1457
1458 return rc;
1459}
1460
1461static int vidioc_s_ctrl(struct file *file, void *priv,
1462 struct v4l2_control *ctrl)
1463{
1464 struct em28xx_fh *fh = priv;
1465 struct em28xx *dev = fh->dev;
1466 int rc;
1467
1468 rc = check_dev(dev);
1469 if (rc < 0)
1470 return rc;
1471
1472 /* Set an AC97 control */
1473 if (dev->audio_mode.ac97 != EM28XX_NO_AC97)
1474 rc = ac97_set_ctrl(dev, ctrl);
1475 else
1476 rc = 1;
1477
1478 /* It isn't an AC97 control. Sends it to the v4l2 dev interface */
1479 if (rc == 1) {
1480 rc = check_subdev_ctrl(dev, ctrl->id);
1481 if (!rc)
1482 v4l2_device_call_all(&dev->v4l2_dev, 0,
1483 core, s_ctrl, ctrl);
1484 /*
1485 * In the case of non-AC97 volume controls, we still need
1486 * to do some setups at em28xx, in order to mute/unmute
1487 * and to adjust audio volume. However, the value ranges
1488 * should be checked by the corresponding V4L subdriver.
1489 */
1490 switch (ctrl->id) {
1491 case V4L2_CID_AUDIO_MUTE:
1492 dev->mute = ctrl->value;
1493 rc = em28xx_audio_analog_set(dev);
1494 break;
1495 case V4L2_CID_AUDIO_VOLUME:
1496 dev->volume = ctrl->value;
1497 rc = em28xx_audio_analog_set(dev);
1498 }
1499 }
1500 return (rc < 0) ? rc : 0;
1501}
1502
1503static int vidioc_g_tuner(struct file *file, void *priv, 1200static int vidioc_g_tuner(struct file *file, void *priv,
1504 struct v4l2_tuner *t) 1201 struct v4l2_tuner *t)
1505{ 1202{
@@ -1515,7 +1212,6 @@ static int vidioc_g_tuner(struct file *file, void *priv,
1515 return -EINVAL; 1212 return -EINVAL;
1516 1213
1517 strcpy(t->name, "Tuner"); 1214 strcpy(t->name, "Tuner");
1518 t->type = V4L2_TUNER_ANALOG_TV;
1519 1215
1520 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t); 1216 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t);
1521 return 0; 1217 return 0;
@@ -1545,7 +1241,9 @@ static int vidioc_g_frequency(struct file *file, void *priv,
1545 struct em28xx_fh *fh = priv; 1241 struct em28xx_fh *fh = priv;
1546 struct em28xx *dev = fh->dev; 1242 struct em28xx *dev = fh->dev;
1547 1243
1548 f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; 1244 if (0 != f->tuner)
1245 return -EINVAL;
1246
1549 f->frequency = dev->ctl_freq; 1247 f->frequency = dev->ctl_freq;
1550 return 0; 1248 return 0;
1551} 1249}
@@ -1564,13 +1262,9 @@ static int vidioc_s_frequency(struct file *file, void *priv,
1564 if (0 != f->tuner) 1262 if (0 != f->tuner)
1565 return -EINVAL; 1263 return -EINVAL;
1566 1264
1567 if (unlikely(0 == fh->radio && f->type != V4L2_TUNER_ANALOG_TV))
1568 return -EINVAL;
1569 if (unlikely(1 == fh->radio && f->type != V4L2_TUNER_RADIO))
1570 return -EINVAL;
1571
1572 dev->ctl_freq = f->frequency;
1573 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, f); 1265 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, f);
1266 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_frequency, f);
1267 dev->ctl_freq = f->frequency;
1574 1268
1575 return 0; 1269 return 0;
1576} 1270}
@@ -1596,6 +1290,14 @@ static int vidioc_g_chip_ident(struct file *file, void *priv,
1596 1290
1597 chip->ident = V4L2_IDENT_NONE; 1291 chip->ident = V4L2_IDENT_NONE;
1598 chip->revision = 0; 1292 chip->revision = 0;
1293 if (chip->match.type == V4L2_CHIP_MATCH_HOST) {
1294 if (v4l2_chip_match_host(&chip->match))
1295 chip->ident = V4L2_IDENT_NONE;
1296 return 0;
1297 }
1298 if (chip->match.type != V4L2_CHIP_MATCH_I2C_DRIVER &&
1299 chip->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
1300 return -EINVAL;
1599 1301
1600 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_chip_ident, chip); 1302 v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_chip_ident, chip);
1601 1303
@@ -1704,72 +1406,10 @@ static int vidioc_cropcap(struct file *file, void *priv,
1704 return 0; 1406 return 0;
1705} 1407}
1706 1408
1707static int vidioc_streamon(struct file *file, void *priv,
1708 enum v4l2_buf_type type)
1709{
1710 struct em28xx_fh *fh = priv;
1711 struct em28xx *dev = fh->dev;
1712 int rc = -EINVAL;
1713
1714 rc = check_dev(dev);
1715 if (rc < 0)
1716 return rc;
1717
1718 if (unlikely(type != fh->type))
1719 return -EINVAL;
1720
1721 em28xx_videodbg("vidioc_streamon fh=%p t=%d fh->res=%d dev->res=%d\n",
1722 fh, type, fh->resources, dev->resources);
1723
1724 if (unlikely(!res_get(fh, get_ressource(fh))))
1725 return -EBUSY;
1726
1727 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1728 rc = videobuf_streamon(&fh->vb_vidq);
1729 else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE)
1730 rc = videobuf_streamon(&fh->vb_vbiq);
1731
1732 return rc;
1733}
1734
1735static int vidioc_streamoff(struct file *file, void *priv,
1736 enum v4l2_buf_type type)
1737{
1738 struct em28xx_fh *fh = priv;
1739 struct em28xx *dev = fh->dev;
1740 int rc;
1741
1742 rc = check_dev(dev);
1743 if (rc < 0)
1744 return rc;
1745
1746 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
1747 fh->type != V4L2_BUF_TYPE_VBI_CAPTURE)
1748 return -EINVAL;
1749 if (type != fh->type)
1750 return -EINVAL;
1751
1752 em28xx_videodbg("vidioc_streamoff fh=%p t=%d fh->res=%d dev->res=%d\n",
1753 fh, type, fh->resources, dev->resources);
1754
1755 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1756 if (res_check(fh, EM28XX_RESOURCE_VIDEO)) {
1757 videobuf_streamoff(&fh->vb_vidq);
1758 res_free(fh, EM28XX_RESOURCE_VIDEO);
1759 }
1760 } else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
1761 if (res_check(fh, EM28XX_RESOURCE_VBI)) {
1762 videobuf_streamoff(&fh->vb_vbiq);
1763 res_free(fh, EM28XX_RESOURCE_VBI);
1764 }
1765 }
1766
1767 return 0;
1768}
1769
1770static int vidioc_querycap(struct file *file, void *priv, 1409static int vidioc_querycap(struct file *file, void *priv,
1771 struct v4l2_capability *cap) 1410 struct v4l2_capability *cap)
1772{ 1411{
1412 struct video_device *vdev = video_devdata(file);
1773 struct em28xx_fh *fh = priv; 1413 struct em28xx_fh *fh = priv;
1774 struct em28xx *dev = fh->dev; 1414 struct em28xx *dev = fh->dev;
1775 1415
@@ -1777,20 +1417,26 @@ static int vidioc_querycap(struct file *file, void *priv,
1777 strlcpy(cap->card, em28xx_boards[dev->model].name, sizeof(cap->card)); 1417 strlcpy(cap->card, em28xx_boards[dev->model].name, sizeof(cap->card));
1778 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info)); 1418 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info));
1779 1419
1780 cap->capabilities = 1420 if (vdev->vfl_type == VFL_TYPE_GRABBER)
1781 V4L2_CAP_SLICED_VBI_CAPTURE | 1421 cap->device_caps = V4L2_CAP_READWRITE |
1782 V4L2_CAP_VIDEO_CAPTURE | 1422 V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
1783 V4L2_CAP_READWRITE | V4L2_CAP_STREAMING; 1423 else if (vdev->vfl_type == VFL_TYPE_RADIO)
1784 1424 cap->device_caps = V4L2_CAP_RADIO;
1785 if (dev->vbi_dev) 1425 else
1786 cap->capabilities |= V4L2_CAP_VBI_CAPTURE; 1426 cap->device_caps = V4L2_CAP_READWRITE | V4L2_CAP_VBI_CAPTURE;
1787 1427
1788 if (dev->audio_mode.has_audio) 1428 if (dev->audio_mode.has_audio)
1789 cap->capabilities |= V4L2_CAP_AUDIO; 1429 cap->device_caps |= V4L2_CAP_AUDIO;
1790 1430
1791 if (dev->tuner_type != TUNER_ABSENT) 1431 if (dev->tuner_type != TUNER_ABSENT)
1792 cap->capabilities |= V4L2_CAP_TUNER; 1432 cap->device_caps |= V4L2_CAP_TUNER;
1793 1433
1434 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS |
1435 V4L2_CAP_READWRITE | V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
1436 if (dev->vbi_dev)
1437 cap->capabilities |= V4L2_CAP_VBI_CAPTURE;
1438 if (dev->radio_dev)
1439 cap->capabilities |= V4L2_CAP_RADIO;
1794 return 0; 1440 return 0;
1795} 1441}
1796 1442
@@ -1845,46 +1491,6 @@ static int vidioc_enum_framesizes(struct file *file, void *priv,
1845 return 0; 1491 return 0;
1846} 1492}
1847 1493
1848/* Sliced VBI ioctls */
1849static int vidioc_g_fmt_sliced_vbi_cap(struct file *file, void *priv,
1850 struct v4l2_format *f)
1851{
1852 struct em28xx_fh *fh = priv;
1853 struct em28xx *dev = fh->dev;
1854 int rc;
1855
1856 rc = check_dev(dev);
1857 if (rc < 0)
1858 return rc;
1859
1860 f->fmt.sliced.service_set = 0;
1861 v4l2_device_call_all(&dev->v4l2_dev, 0, vbi, g_sliced_fmt, &f->fmt.sliced);
1862
1863 if (f->fmt.sliced.service_set == 0)
1864 rc = -EINVAL;
1865
1866 return rc;
1867}
1868
1869static int vidioc_try_set_sliced_vbi_cap(struct file *file, void *priv,
1870 struct v4l2_format *f)
1871{
1872 struct em28xx_fh *fh = priv;
1873 struct em28xx *dev = fh->dev;
1874 int rc;
1875
1876 rc = check_dev(dev);
1877 if (rc < 0)
1878 return rc;
1879
1880 v4l2_device_call_all(&dev->v4l2_dev, 0, vbi, g_sliced_fmt, &f->fmt.sliced);
1881
1882 if (f->fmt.sliced.service_set == 0)
1883 return -EINVAL;
1884
1885 return 0;
1886}
1887
1888/* RAW VBI ioctls */ 1494/* RAW VBI ioctls */
1889 1495
1890static int vidioc_g_fmt_vbi_cap(struct file *file, void *priv, 1496static int vidioc_g_fmt_vbi_cap(struct file *file, void *priv,
@@ -1900,6 +1506,7 @@ static int vidioc_g_fmt_vbi_cap(struct file *file, void *priv,
1900 format->fmt.vbi.sampling_rate = 6750000 * 4 / 2; 1506 format->fmt.vbi.sampling_rate = 6750000 * 4 / 2;
1901 format->fmt.vbi.count[0] = dev->vbi_height; 1507 format->fmt.vbi.count[0] = dev->vbi_height;
1902 format->fmt.vbi.count[1] = dev->vbi_height; 1508 format->fmt.vbi.count[1] = dev->vbi_height;
1509 memset(format->fmt.vbi.reserved, 0, sizeof(format->fmt.vbi.reserved));
1903 1510
1904 /* Varies by video standard (NTSC, PAL, etc.) */ 1511 /* Varies by video standard (NTSC, PAL, etc.) */
1905 if (dev->norm & V4L2_STD_525_60) { 1512 if (dev->norm & V4L2_STD_525_60) {
@@ -1928,6 +1535,7 @@ static int vidioc_s_fmt_vbi_cap(struct file *file, void *priv,
1928 format->fmt.vbi.sampling_rate = 6750000 * 4 / 2; 1535 format->fmt.vbi.sampling_rate = 6750000 * 4 / 2;
1929 format->fmt.vbi.count[0] = dev->vbi_height; 1536 format->fmt.vbi.count[0] = dev->vbi_height;
1930 format->fmt.vbi.count[1] = dev->vbi_height; 1537 format->fmt.vbi.count[1] = dev->vbi_height;
1538 memset(format->fmt.vbi.reserved, 0, sizeof(format->fmt.vbi.reserved));
1931 1539
1932 /* Varies by video standard (NTSC, PAL, etc.) */ 1540 /* Varies by video standard (NTSC, PAL, etc.) */
1933 if (dev->norm & V4L2_STD_525_60) { 1541 if (dev->norm & V4L2_STD_525_60) {
@@ -1943,100 +1551,10 @@ static int vidioc_s_fmt_vbi_cap(struct file *file, void *priv,
1943 return 0; 1551 return 0;
1944} 1552}
1945 1553
1946static int vidioc_reqbufs(struct file *file, void *priv,
1947 struct v4l2_requestbuffers *rb)
1948{
1949 struct em28xx_fh *fh = priv;
1950 struct em28xx *dev = fh->dev;
1951 int rc;
1952
1953 rc = check_dev(dev);
1954 if (rc < 0)
1955 return rc;
1956
1957 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1958 return videobuf_reqbufs(&fh->vb_vidq, rb);
1959 else
1960 return videobuf_reqbufs(&fh->vb_vbiq, rb);
1961}
1962
1963static int vidioc_querybuf(struct file *file, void *priv,
1964 struct v4l2_buffer *b)
1965{
1966 struct em28xx_fh *fh = priv;
1967 struct em28xx *dev = fh->dev;
1968 int rc;
1969
1970 rc = check_dev(dev);
1971 if (rc < 0)
1972 return rc;
1973
1974 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1975 return videobuf_querybuf(&fh->vb_vidq, b);
1976 else {
1977 /* FIXME: I'm not sure yet whether this is a bug in zvbi or
1978 the videobuf framework, but we probably shouldn't be
1979 returning a buffer larger than that which was asked for.
1980 At a minimum, it causes a crash in zvbi since it does
1981 a memcpy based on the source buffer length */
1982 int result = videobuf_querybuf(&fh->vb_vbiq, b);
1983 b->length = dev->vbi_width * dev->vbi_height * 2;
1984
1985 return result;
1986 }
1987}
1988
1989static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *b)
1990{
1991 struct em28xx_fh *fh = priv;
1992 struct em28xx *dev = fh->dev;
1993 int rc;
1994
1995 rc = check_dev(dev);
1996 if (rc < 0)
1997 return rc;
1998
1999 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
2000 return videobuf_qbuf(&fh->vb_vidq, b);
2001 else
2002 return videobuf_qbuf(&fh->vb_vbiq, b);
2003}
2004
2005static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b)
2006{
2007 struct em28xx_fh *fh = priv;
2008 struct em28xx *dev = fh->dev;
2009 int rc;
2010
2011 rc = check_dev(dev);
2012 if (rc < 0)
2013 return rc;
2014
2015 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
2016 return videobuf_dqbuf(&fh->vb_vidq, b, file->f_flags &
2017 O_NONBLOCK);
2018 else
2019 return videobuf_dqbuf(&fh->vb_vbiq, b, file->f_flags &
2020 O_NONBLOCK);
2021}
2022
2023/* ----------------------------------------------------------- */ 1554/* ----------------------------------------------------------- */
2024/* RADIO ESPECIFIC IOCTLS */ 1555/* RADIO ESPECIFIC IOCTLS */
2025/* ----------------------------------------------------------- */ 1556/* ----------------------------------------------------------- */
2026 1557
2027static int radio_querycap(struct file *file, void *priv,
2028 struct v4l2_capability *cap)
2029{
2030 struct em28xx *dev = ((struct em28xx_fh *)priv)->dev;
2031
2032 strlcpy(cap->driver, "em28xx", sizeof(cap->driver));
2033 strlcpy(cap->card, em28xx_boards[dev->model].name, sizeof(cap->card));
2034 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info));
2035
2036 cap->capabilities = V4L2_CAP_TUNER;
2037 return 0;
2038}
2039
2040static int radio_g_tuner(struct file *file, void *priv, 1558static int radio_g_tuner(struct file *file, void *priv,
2041 struct v4l2_tuner *t) 1559 struct v4l2_tuner *t)
2042{ 1560{
@@ -2053,26 +1571,6 @@ static int radio_g_tuner(struct file *file, void *priv,
2053 return 0; 1571 return 0;
2054} 1572}
2055 1573
2056static int radio_enum_input(struct file *file, void *priv,
2057 struct v4l2_input *i)
2058{
2059 if (i->index != 0)
2060 return -EINVAL;
2061 strcpy(i->name, "Radio");
2062 i->type = V4L2_INPUT_TYPE_TUNER;
2063
2064 return 0;
2065}
2066
2067static int radio_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
2068{
2069 if (unlikely(a->index))
2070 return -EINVAL;
2071
2072 strcpy(a->name, "Radio");
2073 return 0;
2074}
2075
2076static int radio_s_tuner(struct file *file, void *priv, 1574static int radio_s_tuner(struct file *file, void *priv,
2077 struct v4l2_tuner *t) 1575 struct v4l2_tuner *t)
2078{ 1576{
@@ -2086,48 +1584,16 @@ static int radio_s_tuner(struct file *file, void *priv,
2086 return 0; 1584 return 0;
2087} 1585}
2088 1586
2089static int radio_s_audio(struct file *file, void *fh,
2090 const struct v4l2_audio *a)
2091{
2092 return 0;
2093}
2094
2095static int radio_s_input(struct file *file, void *fh, unsigned int i)
2096{
2097 return 0;
2098}
2099
2100static int radio_queryctrl(struct file *file, void *priv,
2101 struct v4l2_queryctrl *qc)
2102{
2103 int i;
2104
2105 if (qc->id < V4L2_CID_BASE ||
2106 qc->id >= V4L2_CID_LASTP1)
2107 return -EINVAL;
2108
2109 for (i = 0; i < ARRAY_SIZE(ac97_qctrl); i++) {
2110 if (qc->id && qc->id == ac97_qctrl[i].id) {
2111 memcpy(qc, &(ac97_qctrl[i]), sizeof(*qc));
2112 return 0;
2113 }
2114 }
2115
2116 return -EINVAL;
2117}
2118
2119/* 1587/*
2120 * em28xx_v4l2_open() 1588 * em28xx_v4l2_open()
2121 * inits the device and starts isoc transfer 1589 * inits the device and starts isoc transfer
2122 */ 1590 */
2123static int em28xx_v4l2_open(struct file *filp) 1591static int em28xx_v4l2_open(struct file *filp)
2124{ 1592{
2125 int errCode = 0, radio = 0;
2126 struct video_device *vdev = video_devdata(filp); 1593 struct video_device *vdev = video_devdata(filp);
2127 struct em28xx *dev = video_drvdata(filp); 1594 struct em28xx *dev = video_drvdata(filp);
2128 enum v4l2_buf_type fh_type = 0; 1595 enum v4l2_buf_type fh_type = 0;
2129 struct em28xx_fh *fh; 1596 struct em28xx_fh *fh;
2130 enum v4l2_field field;
2131 1597
2132 switch (vdev->vfl_type) { 1598 switch (vdev->vfl_type) {
2133 case VFL_TYPE_GRABBER: 1599 case VFL_TYPE_GRABBER:
@@ -2136,9 +1602,6 @@ static int em28xx_v4l2_open(struct file *filp)
2136 case VFL_TYPE_VBI: 1602 case VFL_TYPE_VBI:
2137 fh_type = V4L2_BUF_TYPE_VBI_CAPTURE; 1603 fh_type = V4L2_BUF_TYPE_VBI_CAPTURE;
2138 break; 1604 break;
2139 case VFL_TYPE_RADIO:
2140 radio = 1;
2141 break;
2142 } 1605 }
2143 1606
2144 em28xx_videodbg("open dev=%s type=%s users=%d\n", 1607 em28xx_videodbg("open dev=%s type=%s users=%d\n",
@@ -2154,14 +1617,13 @@ static int em28xx_v4l2_open(struct file *filp)
2154 mutex_unlock(&dev->lock); 1617 mutex_unlock(&dev->lock);
2155 return -ENOMEM; 1618 return -ENOMEM;
2156 } 1619 }
1620 v4l2_fh_init(&fh->fh, vdev);
2157 fh->dev = dev; 1621 fh->dev = dev;
2158 fh->radio = radio;
2159 fh->type = fh_type; 1622 fh->type = fh_type;
2160 filp->private_data = fh; 1623 filp->private_data = fh;
2161 1624
2162 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && dev->users == 0) { 1625 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && dev->users == 0) {
2163 em28xx_set_mode(dev, EM28XX_ANALOG_MODE); 1626 em28xx_set_mode(dev, EM28XX_ANALOG_MODE);
2164 em28xx_set_alternate(dev);
2165 em28xx_resolution_set(dev); 1627 em28xx_resolution_set(dev);
2166 1628
2167 /* Needed, since GPIO might have disabled power of 1629 /* Needed, since GPIO might have disabled power of
@@ -2170,31 +1632,18 @@ static int em28xx_v4l2_open(struct file *filp)
2170 em28xx_wake_i2c(dev); 1632 em28xx_wake_i2c(dev);
2171 1633
2172 } 1634 }
2173 if (fh->radio) { 1635
1636 if (vdev->vfl_type == VFL_TYPE_RADIO) {
2174 em28xx_videodbg("video_open: setting radio device\n"); 1637 em28xx_videodbg("video_open: setting radio device\n");
2175 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_radio); 1638 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_radio);
2176 } 1639 }
2177 1640
2178 dev->users++; 1641 dev->users++;
2179 1642
2180 if (dev->progressive)
2181 field = V4L2_FIELD_NONE;
2182 else
2183 field = V4L2_FIELD_INTERLACED;
2184
2185 videobuf_queue_vmalloc_init(&fh->vb_vidq, &em28xx_video_qops,
2186 NULL, &dev->slock,
2187 V4L2_BUF_TYPE_VIDEO_CAPTURE, field,
2188 sizeof(struct em28xx_buffer), fh, &dev->lock);
2189
2190 videobuf_queue_vmalloc_init(&fh->vb_vbiq, &em28xx_vbi_qops,
2191 NULL, &dev->slock,
2192 V4L2_BUF_TYPE_VBI_CAPTURE,
2193 V4L2_FIELD_SEQ_TB,
2194 sizeof(struct em28xx_buffer), fh, &dev->lock);
2195 mutex_unlock(&dev->lock); 1643 mutex_unlock(&dev->lock);
1644 v4l2_fh_add(&fh->fh);
2196 1645
2197 return errCode; 1646 return 0;
2198} 1647}
2199 1648
2200/* 1649/*
@@ -2248,25 +1697,16 @@ static int em28xx_v4l2_close(struct file *filp)
2248 em28xx_videodbg("users=%d\n", dev->users); 1697 em28xx_videodbg("users=%d\n", dev->users);
2249 1698
2250 mutex_lock(&dev->lock); 1699 mutex_lock(&dev->lock);
2251 if (res_check(fh, EM28XX_RESOURCE_VIDEO)) { 1700 vb2_fop_release(filp);
2252 videobuf_stop(&fh->vb_vidq);
2253 res_free(fh, EM28XX_RESOURCE_VIDEO);
2254 }
2255
2256 if (res_check(fh, EM28XX_RESOURCE_VBI)) {
2257 videobuf_stop(&fh->vb_vbiq);
2258 res_free(fh, EM28XX_RESOURCE_VBI);
2259 }
2260 1701
2261 if (dev->users == 1) { 1702 if (dev->users == 1) {
2262 /* the device is already disconnect, 1703 /* the device is already disconnect,
2263 free the remaining resources */ 1704 free the remaining resources */
2264 if (dev->state & DEV_DISCONNECTED) { 1705 if (dev->disconnected) {
2265 em28xx_release_resources(dev); 1706 em28xx_release_resources(dev);
2266 kfree(dev->alt_max_pkt_size); 1707 kfree(dev->alt_max_pkt_size_isoc);
2267 mutex_unlock(&dev->lock); 1708 mutex_unlock(&dev->lock);
2268 kfree(dev); 1709 kfree(dev);
2269 kfree(fh);
2270 return 0; 1710 return 0;
2271 } 1711 }
2272 1712
@@ -2274,7 +1714,6 @@ static int em28xx_v4l2_close(struct file *filp)
2274 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_power, 0); 1714 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_power, 0);
2275 1715
2276 /* do this before setting alternate! */ 1716 /* do this before setting alternate! */
2277 em28xx_uninit_isoc(dev, EM28XX_ANALOG_MODE);
2278 em28xx_set_mode(dev, EM28XX_SUSPEND); 1717 em28xx_set_mode(dev, EM28XX_SUSPEND);
2279 1718
2280 /* set alternate 0 */ 1719 /* set alternate 0 */
@@ -2287,129 +1726,18 @@ static int em28xx_v4l2_close(struct file *filp)
2287 } 1726 }
2288 } 1727 }
2289 1728
2290 videobuf_mmap_free(&fh->vb_vidq);
2291 videobuf_mmap_free(&fh->vb_vbiq);
2292 kfree(fh);
2293 dev->users--; 1729 dev->users--;
2294 mutex_unlock(&dev->lock); 1730 mutex_unlock(&dev->lock);
2295 return 0; 1731 return 0;
2296} 1732}
2297 1733
2298/*
2299 * em28xx_v4l2_read()
2300 * will allocate buffers when called for the first time
2301 */
2302static ssize_t
2303em28xx_v4l2_read(struct file *filp, char __user *buf, size_t count,
2304 loff_t *pos)
2305{
2306 struct em28xx_fh *fh = filp->private_data;
2307 struct em28xx *dev = fh->dev;
2308 int rc;
2309
2310 rc = check_dev(dev);
2311 if (rc < 0)
2312 return rc;
2313
2314 if (mutex_lock_interruptible(&dev->lock))
2315 return -ERESTARTSYS;
2316 /* FIXME: read() is not prepared to allow changing the video
2317 resolution while streaming. Seems a bug at em28xx_set_fmt
2318 */
2319
2320 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
2321 if (res_locked(dev, EM28XX_RESOURCE_VIDEO))
2322 rc = -EBUSY;
2323 else
2324 rc = videobuf_read_stream(&fh->vb_vidq, buf, count, pos, 0,
2325 filp->f_flags & O_NONBLOCK);
2326 } else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
2327 if (!res_get(fh, EM28XX_RESOURCE_VBI))
2328 rc = -EBUSY;
2329 else
2330 rc = videobuf_read_stream(&fh->vb_vbiq, buf, count, pos, 0,
2331 filp->f_flags & O_NONBLOCK);
2332 }
2333 mutex_unlock(&dev->lock);
2334
2335 return rc;
2336}
2337
2338/*
2339 * em28xx_poll()
2340 * will allocate buffers when called for the first time
2341 */
2342static unsigned int em28xx_poll(struct file *filp, poll_table *wait)
2343{
2344 struct em28xx_fh *fh = filp->private_data;
2345 struct em28xx *dev = fh->dev;
2346 int rc;
2347
2348 rc = check_dev(dev);
2349 if (rc < 0)
2350 return rc;
2351
2352 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
2353 if (!res_get(fh, EM28XX_RESOURCE_VIDEO))
2354 return POLLERR;
2355 return videobuf_poll_stream(filp, &fh->vb_vidq, wait);
2356 } else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
2357 if (!res_get(fh, EM28XX_RESOURCE_VBI))
2358 return POLLERR;
2359 return videobuf_poll_stream(filp, &fh->vb_vbiq, wait);
2360 } else {
2361 return POLLERR;
2362 }
2363}
2364
2365static unsigned int em28xx_v4l2_poll(struct file *filp, poll_table *wait)
2366{
2367 struct em28xx_fh *fh = filp->private_data;
2368 struct em28xx *dev = fh->dev;
2369 unsigned int res;
2370
2371 mutex_lock(&dev->lock);
2372 res = em28xx_poll(filp, wait);
2373 mutex_unlock(&dev->lock);
2374 return res;
2375}
2376
2377/*
2378 * em28xx_v4l2_mmap()
2379 */
2380static int em28xx_v4l2_mmap(struct file *filp, struct vm_area_struct *vma)
2381{
2382 struct em28xx_fh *fh = filp->private_data;
2383 struct em28xx *dev = fh->dev;
2384 int rc;
2385
2386 rc = check_dev(dev);
2387 if (rc < 0)
2388 return rc;
2389
2390 if (mutex_lock_interruptible(&dev->lock))
2391 return -ERESTARTSYS;
2392 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
2393 rc = videobuf_mmap_mapper(&fh->vb_vidq, vma);
2394 else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE)
2395 rc = videobuf_mmap_mapper(&fh->vb_vbiq, vma);
2396 mutex_unlock(&dev->lock);
2397
2398 em28xx_videodbg("vma start=0x%08lx, size=%ld, ret=%d\n",
2399 (unsigned long)vma->vm_start,
2400 (unsigned long)vma->vm_end-(unsigned long)vma->vm_start,
2401 rc);
2402
2403 return rc;
2404}
2405
2406static const struct v4l2_file_operations em28xx_v4l_fops = { 1734static const struct v4l2_file_operations em28xx_v4l_fops = {
2407 .owner = THIS_MODULE, 1735 .owner = THIS_MODULE,
2408 .open = em28xx_v4l2_open, 1736 .open = em28xx_v4l2_open,
2409 .release = em28xx_v4l2_close, 1737 .release = em28xx_v4l2_close,
2410 .read = em28xx_v4l2_read, 1738 .read = vb2_fop_read,
2411 .poll = em28xx_v4l2_poll, 1739 .poll = vb2_fop_poll,
2412 .mmap = em28xx_v4l2_mmap, 1740 .mmap = vb2_fop_mmap,
2413 .unlocked_ioctl = video_ioctl2, 1741 .unlocked_ioctl = video_ioctl2,
2414}; 1742};
2415 1743
@@ -2420,19 +1748,20 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
2420 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap, 1748 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
2421 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, 1749 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
2422 .vidioc_g_fmt_vbi_cap = vidioc_g_fmt_vbi_cap, 1750 .vidioc_g_fmt_vbi_cap = vidioc_g_fmt_vbi_cap,
1751 .vidioc_try_fmt_vbi_cap = vidioc_g_fmt_vbi_cap,
2423 .vidioc_s_fmt_vbi_cap = vidioc_s_fmt_vbi_cap, 1752 .vidioc_s_fmt_vbi_cap = vidioc_s_fmt_vbi_cap,
2424 .vidioc_enum_framesizes = vidioc_enum_framesizes, 1753 .vidioc_enum_framesizes = vidioc_enum_framesizes,
2425 .vidioc_g_audio = vidioc_g_audio, 1754 .vidioc_g_audio = vidioc_g_audio,
2426 .vidioc_s_audio = vidioc_s_audio, 1755 .vidioc_s_audio = vidioc_s_audio,
2427 .vidioc_cropcap = vidioc_cropcap, 1756 .vidioc_cropcap = vidioc_cropcap,
2428 .vidioc_g_fmt_sliced_vbi_cap = vidioc_g_fmt_sliced_vbi_cap, 1757
2429 .vidioc_try_fmt_sliced_vbi_cap = vidioc_try_set_sliced_vbi_cap, 1758 .vidioc_reqbufs = vb2_ioctl_reqbufs,
2430 .vidioc_s_fmt_sliced_vbi_cap = vidioc_try_set_sliced_vbi_cap, 1759 .vidioc_create_bufs = vb2_ioctl_create_bufs,
2431 1760 .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
2432 .vidioc_reqbufs = vidioc_reqbufs, 1761 .vidioc_querybuf = vb2_ioctl_querybuf,
2433 .vidioc_querybuf = vidioc_querybuf, 1762 .vidioc_qbuf = vb2_ioctl_qbuf,
2434 .vidioc_qbuf = vidioc_qbuf, 1763 .vidioc_dqbuf = vb2_ioctl_dqbuf,
2435 .vidioc_dqbuf = vidioc_dqbuf, 1764
2436 .vidioc_g_std = vidioc_g_std, 1765 .vidioc_g_std = vidioc_g_std,
2437 .vidioc_querystd = vidioc_querystd, 1766 .vidioc_querystd = vidioc_querystd,
2438 .vidioc_s_std = vidioc_s_std, 1767 .vidioc_s_std = vidioc_s_std,
@@ -2441,15 +1770,14 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
2441 .vidioc_enum_input = vidioc_enum_input, 1770 .vidioc_enum_input = vidioc_enum_input,
2442 .vidioc_g_input = vidioc_g_input, 1771 .vidioc_g_input = vidioc_g_input,
2443 .vidioc_s_input = vidioc_s_input, 1772 .vidioc_s_input = vidioc_s_input,
2444 .vidioc_queryctrl = vidioc_queryctrl, 1773 .vidioc_streamon = vb2_ioctl_streamon,
2445 .vidioc_g_ctrl = vidioc_g_ctrl, 1774 .vidioc_streamoff = vb2_ioctl_streamoff,
2446 .vidioc_s_ctrl = vidioc_s_ctrl,
2447 .vidioc_streamon = vidioc_streamon,
2448 .vidioc_streamoff = vidioc_streamoff,
2449 .vidioc_g_tuner = vidioc_g_tuner, 1775 .vidioc_g_tuner = vidioc_g_tuner,
2450 .vidioc_s_tuner = vidioc_s_tuner, 1776 .vidioc_s_tuner = vidioc_s_tuner,
2451 .vidioc_g_frequency = vidioc_g_frequency, 1777 .vidioc_g_frequency = vidioc_g_frequency,
2452 .vidioc_s_frequency = vidioc_s_frequency, 1778 .vidioc_s_frequency = vidioc_s_frequency,
1779 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1780 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
2453#ifdef CONFIG_VIDEO_ADV_DEBUG 1781#ifdef CONFIG_VIDEO_ADV_DEBUG
2454 .vidioc_g_register = vidioc_g_register, 1782 .vidioc_g_register = vidioc_g_register,
2455 .vidioc_s_register = vidioc_s_register, 1783 .vidioc_s_register = vidioc_s_register,
@@ -2459,11 +1787,10 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
2459 1787
2460static const struct video_device em28xx_video_template = { 1788static const struct video_device em28xx_video_template = {
2461 .fops = &em28xx_v4l_fops, 1789 .fops = &em28xx_v4l_fops,
2462 .release = video_device_release, 1790 .release = video_device_release_empty,
2463 .ioctl_ops = &video_ioctl_ops, 1791 .ioctl_ops = &video_ioctl_ops,
2464 1792
2465 .tvnorms = V4L2_STD_ALL, 1793 .tvnorms = V4L2_STD_ALL,
2466 .current_norm = V4L2_STD_PAL,
2467}; 1794};
2468 1795
2469static const struct v4l2_file_operations radio_fops = { 1796static const struct v4l2_file_operations radio_fops = {
@@ -2474,18 +1801,13 @@ static const struct v4l2_file_operations radio_fops = {
2474}; 1801};
2475 1802
2476static const struct v4l2_ioctl_ops radio_ioctl_ops = { 1803static const struct v4l2_ioctl_ops radio_ioctl_ops = {
2477 .vidioc_querycap = radio_querycap, 1804 .vidioc_querycap = vidioc_querycap,
2478 .vidioc_g_tuner = radio_g_tuner, 1805 .vidioc_g_tuner = radio_g_tuner,
2479 .vidioc_enum_input = radio_enum_input,
2480 .vidioc_g_audio = radio_g_audio,
2481 .vidioc_s_tuner = radio_s_tuner, 1806 .vidioc_s_tuner = radio_s_tuner,
2482 .vidioc_s_audio = radio_s_audio,
2483 .vidioc_s_input = radio_s_input,
2484 .vidioc_queryctrl = radio_queryctrl,
2485 .vidioc_g_ctrl = vidioc_g_ctrl,
2486 .vidioc_s_ctrl = vidioc_s_ctrl,
2487 .vidioc_g_frequency = vidioc_g_frequency, 1807 .vidioc_g_frequency = vidioc_g_frequency,
2488 .vidioc_s_frequency = vidioc_s_frequency, 1808 .vidioc_s_frequency = vidioc_s_frequency,
1809 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1810 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
2489#ifdef CONFIG_VIDEO_ADV_DEBUG 1811#ifdef CONFIG_VIDEO_ADV_DEBUG
2490 .vidioc_g_register = vidioc_g_register, 1812 .vidioc_g_register = vidioc_g_register,
2491 .vidioc_s_register = vidioc_s_register, 1813 .vidioc_s_register = vidioc_s_register,
@@ -2514,9 +1836,11 @@ static struct video_device *em28xx_vdev_init(struct em28xx *dev,
2514 1836
2515 *vfd = *template; 1837 *vfd = *template;
2516 vfd->v4l2_dev = &dev->v4l2_dev; 1838 vfd->v4l2_dev = &dev->v4l2_dev;
2517 vfd->release = video_device_release;
2518 vfd->debug = video_debug; 1839 vfd->debug = video_debug;
2519 vfd->lock = &dev->lock; 1840 vfd->lock = &dev->lock;
1841 set_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
1842 if (dev->board.is_webcam)
1843 vfd->tvnorms = 0;
2520 1844
2521 snprintf(vfd->name, sizeof(vfd->name), "%s %s", 1845 snprintf(vfd->name, sizeof(vfd->name), "%s %s",
2522 dev->name, type_name); 1846 dev->name, type_name);
@@ -2527,7 +1851,7 @@ static struct video_device *em28xx_vdev_init(struct em28xx *dev,
2527 1851
2528int em28xx_register_analog_devices(struct em28xx *dev) 1852int em28xx_register_analog_devices(struct em28xx *dev)
2529{ 1853{
2530 u8 val; 1854 u8 val;
2531 int ret; 1855 int ret;
2532 unsigned int maxw; 1856 unsigned int maxw;
2533 1857
@@ -2535,7 +1859,7 @@ int em28xx_register_analog_devices(struct em28xx *dev)
2535 dev->name, EM28XX_VERSION); 1859 dev->name, EM28XX_VERSION);
2536 1860
2537 /* set default norm */ 1861 /* set default norm */
2538 dev->norm = em28xx_video_template.current_norm; 1862 dev->norm = V4L2_STD_PAL;
2539 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_std, dev->norm); 1863 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_std, dev->norm);
2540 dev->interlaced = EM28XX_INTERLACED_DEFAULT; 1864 dev->interlaced = EM28XX_INTERLACED_DEFAULT;
2541 1865
@@ -2543,10 +1867,10 @@ int em28xx_register_analog_devices(struct em28xx *dev)
2543 dev->format = &format[0]; 1867 dev->format = &format[0];
2544 1868
2545 maxw = norm_maxw(dev); 1869 maxw = norm_maxw(dev);
2546 /* MaxPacketSize for em2800 is too small to capture at full resolution 1870 /* MaxPacketSize for em2800 is too small to capture at full resolution
2547 * use half of maxw as the scaler can only scale to 50% */ 1871 * use half of maxw as the scaler can only scale to 50% */
2548 if (dev->board.is_em2800) 1872 if (dev->board.is_em2800)
2549 maxw /= 2; 1873 maxw /= 2;
2550 1874
2551 em28xx_set_video_format(dev, format[0].fourcc, 1875 em28xx_set_video_format(dev, format[0].fourcc,
2552 maxw, norm_maxh(dev)); 1876 maxw, norm_maxh(dev));
@@ -2572,6 +1896,8 @@ int em28xx_register_analog_devices(struct em28xx *dev)
2572 em28xx_errdev("cannot allocate video_device.\n"); 1896 em28xx_errdev("cannot allocate video_device.\n");
2573 return -ENODEV; 1897 return -ENODEV;
2574 } 1898 }
1899 dev->vdev->queue = &dev->vb_vidq;
1900 dev->vdev->queue->lock = &dev->vb_queue_lock;
2575 1901
2576 /* register v4l2 video video_device */ 1902 /* register v4l2 video video_device */
2577 ret = video_register_device(dev->vdev, VFL_TYPE_GRABBER, 1903 ret = video_register_device(dev->vdev, VFL_TYPE_GRABBER,
@@ -2587,6 +1913,9 @@ int em28xx_register_analog_devices(struct em28xx *dev)
2587 dev->vbi_dev = em28xx_vdev_init(dev, &em28xx_video_template, 1913 dev->vbi_dev = em28xx_vdev_init(dev, &em28xx_video_template,
2588 "vbi"); 1914 "vbi");
2589 1915
1916 dev->vbi_dev->queue = &dev->vb_vbiq;
1917 dev->vbi_dev->queue->lock = &dev->vb_vbi_queue_lock;
1918
2590 /* register v4l2 vbi video_device */ 1919 /* register v4l2 vbi video_device */
2591 ret = video_register_device(dev->vbi_dev, VFL_TYPE_VBI, 1920 ret = video_register_device(dev->vbi_dev, VFL_TYPE_VBI,
2592 vbi_nr[dev->devno]); 1921 vbi_nr[dev->devno]);
diff --git a/drivers/media/usb/em28xx/em28xx.h b/drivers/media/usb/em28xx/em28xx.h
index 86e90d86da6d..5f0b2c59e846 100644
--- a/drivers/media/usb/em28xx/em28xx.h
+++ b/drivers/media/usb/em28xx/em28xx.h
@@ -4,6 +4,7 @@
4 Copyright (C) 2005 Markus Rechberger <mrechberger@gmail.com> 4 Copyright (C) 2005 Markus Rechberger <mrechberger@gmail.com>
5 Ludovico Cavedon <cavedon@sssup.it> 5 Ludovico Cavedon <cavedon@sssup.it>
6 Mauro Carvalho Chehab <mchehab@infradead.org> 6 Mauro Carvalho Chehab <mchehab@infradead.org>
7 Copyright (C) 2012 Frank Schäfer <fschaefer.oss@googlemail.com>
7 8
8 Based on the em2800 driver from Sascha Sommer <saschasommer@freenet.de> 9 Based on the em2800 driver from Sascha Sommer <saschasommer@freenet.de>
9 10
@@ -30,13 +31,12 @@
30#include <linux/mutex.h> 31#include <linux/mutex.h>
31#include <linux/videodev2.h> 32#include <linux/videodev2.h>
32 33
33#include <media/videobuf-vmalloc.h> 34#include <media/videobuf2-vmalloc.h>
34#include <media/v4l2-device.h> 35#include <media/v4l2-device.h>
36#include <media/v4l2-ctrls.h>
37#include <media/v4l2-fh.h>
35#include <media/ir-kbd-i2c.h> 38#include <media/ir-kbd-i2c.h>
36#include <media/rc-core.h> 39#include <media/rc-core.h>
37#if defined(CONFIG_VIDEO_EM28XX_DVB) || defined(CONFIG_VIDEO_EM28XX_DVB_MODULE)
38#include <media/videobuf-dvb.h>
39#endif
40#include "tuner-xc2028.h" 40#include "tuner-xc2028.h"
41#include "xc5000.h" 41#include "xc5000.h"
42#include "em28xx-reg.h" 42#include "em28xx-reg.h"
@@ -157,12 +157,18 @@
157#define EM28XX_NUM_BUFS 5 157#define EM28XX_NUM_BUFS 5
158#define EM28XX_DVB_NUM_BUFS 5 158#define EM28XX_DVB_NUM_BUFS 5
159 159
160/* number of packets for each buffer 160/* isoc transfers: number of packets for each buffer
161 windows requests only 64 packets .. so we better do the same 161 windows requests only 64 packets .. so we better do the same
162 this is what I found out for all alternate numbers there! 162 this is what I found out for all alternate numbers there!
163 */ 163 */
164#define EM28XX_NUM_PACKETS 64 164#define EM28XX_NUM_ISOC_PACKETS 64
165#define EM28XX_DVB_MAX_PACKETS 64 165#define EM28XX_DVB_NUM_ISOC_PACKETS 64
166
167/* bulk transfers: transfer buffer size = packet size * packet multiplier
168 USB 2.0 spec says bulk packet size is always 512 bytes
169 */
170#define EM28XX_BULK_PACKET_MULTIPLIER 384
171#define EM28XX_DVB_BULK_PACKET_MULTIPLIER 384
166 172
167#define EM28XX_INTERLACED_DEFAULT 1 173#define EM28XX_INTERLACED_DEFAULT 1
168 174
@@ -187,12 +193,8 @@
187 Interval: 125us 193 Interval: 125us
188*/ 194*/
189 195
190/* time to wait when stopping the isoc transfer */
191#define EM28XX_URB_TIMEOUT \
192 msecs_to_jiffies(EM28XX_NUM_BUFS * EM28XX_NUM_PACKETS)
193
194/* time in msecs to wait for i2c writes to finish */ 196/* time in msecs to wait for i2c writes to finish */
195#define EM2800_I2C_WRITE_TIMEOUT 20 197#define EM2800_I2C_XFER_TIMEOUT 20
196 198
197enum em28xx_mode { 199enum em28xx_mode {
198 EM28XX_SUSPEND, 200 EM28XX_SUSPEND,
@@ -203,7 +205,7 @@ enum em28xx_mode {
203 205
204struct em28xx; 206struct em28xx;
205 207
206struct em28xx_usb_isoc_bufs { 208struct em28xx_usb_bufs {
207 /* max packet size of isoc transaction */ 209 /* max packet size of isoc transaction */
208 int max_pkt_size; 210 int max_pkt_size;
209 211
@@ -213,26 +215,26 @@ struct em28xx_usb_isoc_bufs {
213 /* number of allocated urbs */ 215 /* number of allocated urbs */
214 int num_bufs; 216 int num_bufs;
215 217
216 /* urb for isoc transfers */ 218 /* urb for isoc/bulk transfers */
217 struct urb **urb; 219 struct urb **urb;
218 220
219 /* transfer buffers for isoc transfer */ 221 /* transfer buffers for isoc/bulk transfer */
220 char **transfer_buffer; 222 char **transfer_buffer;
221}; 223};
222 224
223struct em28xx_usb_isoc_ctl { 225struct em28xx_usb_ctl {
224 /* isoc transfer buffers for analog mode */ 226 /* isoc/bulk transfer buffers for analog mode */
225 struct em28xx_usb_isoc_bufs analog_bufs; 227 struct em28xx_usb_bufs analog_bufs;
226 228
227 /* isoc transfer buffers for digital mode */ 229 /* isoc/bulk transfer buffers for digital mode */
228 struct em28xx_usb_isoc_bufs digital_bufs; 230 struct em28xx_usb_bufs digital_bufs;
229 231
230 /* Stores already requested buffers */ 232 /* Stores already requested buffers */
231 struct em28xx_buffer *vid_buf; 233 struct em28xx_buffer *vid_buf;
232 struct em28xx_buffer *vbi_buf; 234 struct em28xx_buffer *vbi_buf;
233 235
234 /* isoc urb callback */ 236 /* copy data from URB */
235 int (*isoc_copy) (struct em28xx *dev, struct urb *urb); 237 int (*urb_data_copy) (struct em28xx *dev, struct urb *urb);
236 238
237}; 239};
238 240
@@ -247,19 +249,26 @@ struct em28xx_fmt {
247/* buffer for one video frame */ 249/* buffer for one video frame */
248struct em28xx_buffer { 250struct em28xx_buffer {
249 /* common v4l buffer stuff -- must be first */ 251 /* common v4l buffer stuff -- must be first */
250 struct videobuf_buffer vb; 252 struct vb2_buffer vb;
253 struct list_head list;
251 254
252 struct list_head frame; 255 void *mem;
256 unsigned int length;
253 int top_field; 257 int top_field;
258
259 /* counter to control buffer fill */
260 unsigned int pos;
261 /* NOTE; in interlaced mode, this value is reset to zero at
262 * the start of each new field (not frame !) */
263
264 /* pointer to vmalloc memory address in vb */
265 char *vb_buf;
254}; 266};
255 267
256struct em28xx_dmaqueue { 268struct em28xx_dmaqueue {
257 struct list_head active; 269 struct list_head active;
258 270
259 wait_queue_head_t wq; 271 wait_queue_head_t wq;
260
261 /* Counters to control buffer fill */
262 int pos;
263}; 272};
264 273
265/* inputs */ 274/* inputs */
@@ -430,13 +439,6 @@ struct em28xx_eeprom {
430 u8 string_idx_table; 439 u8 string_idx_table;
431}; 440};
432 441
433/* device states */
434enum em28xx_dev_state {
435 DEV_INITIALIZED = 0x01,
436 DEV_DISCONNECTED = 0x02,
437 DEV_MISCONFIGURED = 0x04,
438};
439
440#define EM28XX_AUDIO_BUFS 5 442#define EM28XX_AUDIO_BUFS 5
441#define EM28XX_NUM_AUDIO_PACKETS 64 443#define EM28XX_NUM_AUDIO_PACKETS 64
442#define EM28XX_AUDIO_MAX_PACKET_SIZE 196 /* static value */ 444#define EM28XX_AUDIO_MAX_PACKET_SIZE 196 /* static value */
@@ -469,12 +471,8 @@ struct em28xx_audio {
469struct em28xx; 471struct em28xx;
470 472
471struct em28xx_fh { 473struct em28xx_fh {
474 struct v4l2_fh fh;
472 struct em28xx *dev; 475 struct em28xx *dev;
473 int radio;
474 unsigned int resources;
475
476 struct videobuf_queue vb_vidq;
477 struct videobuf_queue vb_vbiq;
478 476
479 enum v4l2_buf_type type; 477 enum v4l2_buf_type type;
480}; 478};
@@ -487,9 +485,14 @@ struct em28xx {
487 int devno; /* marks the number of this device */ 485 int devno; /* marks the number of this device */
488 enum em28xx_chip_id chip_id; 486 enum em28xx_chip_id chip_id;
489 487
488 unsigned char disconnected:1; /* device has been diconnected */
489
490 int audio_ifnum; 490 int audio_ifnum;
491 491
492 struct v4l2_device v4l2_dev; 492 struct v4l2_device v4l2_dev;
493 struct v4l2_ctrl_handler ctrl_handler;
494 /* provides ac97 mute and volume overrides */
495 struct v4l2_ctrl_handler ac97_ctrl_handler;
493 struct em28xx_board board; 496 struct em28xx_board board;
494 497
495 /* Webcam specific fields */ 498 /* Webcam specific fields */
@@ -497,7 +500,7 @@ struct em28xx {
497 int sensor_xres, sensor_yres; 500 int sensor_xres, sensor_yres;
498 int sensor_xtal; 501 int sensor_xtal;
499 502
500 /* Allows progressive (e. g. non-interlaced) mode */ 503 /* Progressive (non-interlaced) mode */
501 int progressive; 504 int progressive;
502 505
503 /* Vinmode/Vinctl used at the driver */ 506 /* Vinmode/Vinctl used at the driver */
@@ -532,6 +535,7 @@ struct em28xx {
532 struct i2c_client i2c_client; 535 struct i2c_client i2c_client;
533 /* video for linux */ 536 /* video for linux */
534 int users; /* user count for exclusive use */ 537 int users; /* user count for exclusive use */
538 int streaming_users; /* Number of actively streaming users */
535 struct video_device *vdev; /* video for linux device struct */ 539 struct video_device *vdev; /* video for linux device struct */
536 v4l2_std_id norm; /* selected tv norm */ 540 v4l2_std_id norm; /* selected tv norm */
537 int ctl_freq; /* selected frequency */ 541 int ctl_freq; /* selected frequency */
@@ -554,13 +558,10 @@ struct em28xx {
554 558
555 struct em28xx_audio adev; 559 struct em28xx_audio adev;
556 560
557 /* states */ 561 /* capture state tracking */
558 enum em28xx_dev_state state;
559
560 /* vbi related state tracking */
561 int capture_type; 562 int capture_type;
563 unsigned char top_field:1;
562 int vbi_read; 564 int vbi_read;
563 unsigned char cur_field;
564 unsigned int vbi_width; 565 unsigned int vbi_width;
565 unsigned int vbi_height; /* lines per field */ 566 unsigned int vbi_height; /* lines per field */
566 567
@@ -574,6 +575,12 @@ struct em28xx {
574 struct video_device *vbi_dev; 575 struct video_device *vbi_dev;
575 struct video_device *radio_dev; 576 struct video_device *radio_dev;
576 577
578 /* Videobuf2 */
579 struct vb2_queue vb_vidq;
580 struct vb2_queue vb_vbiq;
581 struct mutex vb_queue_lock;
582 struct mutex vb_vbi_queue_lock;
583
577 /* resources in use */ 584 /* resources in use */
578 unsigned int resources; 585 unsigned int resources;
579 586
@@ -582,17 +589,31 @@ struct em28xx {
582 /* Isoc control struct */ 589 /* Isoc control struct */
583 struct em28xx_dmaqueue vidq; 590 struct em28xx_dmaqueue vidq;
584 struct em28xx_dmaqueue vbiq; 591 struct em28xx_dmaqueue vbiq;
585 struct em28xx_usb_isoc_ctl isoc_ctl; 592 struct em28xx_usb_ctl usb_ctl;
586 spinlock_t slock; 593 spinlock_t slock;
587 594
595 unsigned int field_count;
596 unsigned int vbi_field_count;
597
588 /* usb transfer */ 598 /* usb transfer */
589 struct usb_device *udev; /* the usb device */ 599 struct usb_device *udev; /* the usb device */
590 int alt; /* alternate */ 600 u8 analog_ep_isoc; /* address of isoc endpoint for analog */
591 int max_pkt_size; /* max packet size of isoc transaction */ 601 u8 analog_ep_bulk; /* address of bulk endpoint for analog */
592 int num_alt; /* Number of alternative settings */ 602 u8 dvb_ep_isoc; /* address of isoc endpoint for DVB */
593 unsigned int *alt_max_pkt_size; /* array of wMaxPacketSize */ 603 u8 dvb_ep_bulk; /* address of bulk endpoint for DVC */
594 int dvb_alt; /* alternate for DVB */ 604 int alt; /* alternate setting */
595 unsigned int dvb_max_pkt_size; /* wMaxPacketSize for DVB */ 605 int max_pkt_size; /* max packet size of the selected ep at alt */
606 int packet_multiplier; /* multiplier for wMaxPacketSize, used for
607 URB buffer size definition */
608 int num_alt; /* number of alternative settings */
609 unsigned int *alt_max_pkt_size_isoc; /* array of isoc wMaxPacketSize */
610 unsigned int analog_xfer_bulk:1; /* use bulk instead of isoc
611 transfers for analog */
612 int dvb_alt_isoc; /* alternate setting for DVB isoc transfers */
613 unsigned int dvb_max_pkt_size_isoc; /* isoc max packet size of the
614 selected DVB ep at dvb_alt */
615 unsigned int dvb_xfer_bulk:1; /* use bulk instead of isoc
616 transfers for DVB */
596 char urb_buf[URB_MAX_CTRL_SIZE]; /* urb control msg buffer */ 617 char urb_buf[URB_MAX_CTRL_SIZE]; /* urb control msg buffer */
597 618
598 /* helper funcs that call usb_control_msg */ 619 /* helper funcs that call usb_control_msg */
@@ -619,9 +640,6 @@ struct em28xx {
619 struct delayed_work sbutton_query_work; 640 struct delayed_work sbutton_query_work;
620 641
621 struct em28xx_dvb *dvb; 642 struct em28xx_dvb *dvb;
622
623 /* I2C keyboard data */
624 struct IR_i2c_init_data init_data;
625}; 643};
626 644
627struct em28xx_ops { 645struct em28xx_ops {
@@ -666,12 +684,14 @@ int em28xx_vbi_supported(struct em28xx *dev);
666int em28xx_set_outfmt(struct em28xx *dev); 684int em28xx_set_outfmt(struct em28xx *dev);
667int em28xx_resolution_set(struct em28xx *dev); 685int em28xx_resolution_set(struct em28xx *dev);
668int em28xx_set_alternate(struct em28xx *dev); 686int em28xx_set_alternate(struct em28xx *dev);
669int em28xx_alloc_isoc(struct em28xx *dev, enum em28xx_mode mode, 687int em28xx_alloc_urbs(struct em28xx *dev, enum em28xx_mode mode, int xfer_bulk,
670 int max_packets, int num_bufs, int max_pkt_size); 688 int num_bufs, int max_pkt_size, int packet_multiplier);
671int em28xx_init_isoc(struct em28xx *dev, enum em28xx_mode mode, 689int em28xx_init_usb_xfer(struct em28xx *dev, enum em28xx_mode mode,
672 int max_packets, int num_bufs, int max_pkt_size, 690 int xfer_bulk,
673 int (*isoc_copy) (struct em28xx *dev, struct urb *urb)); 691 int num_bufs, int max_pkt_size, int packet_multiplier,
674void em28xx_uninit_isoc(struct em28xx *dev, enum em28xx_mode mode); 692 int (*urb_data_copy)
693 (struct em28xx *dev, struct urb *urb));
694void em28xx_uninit_usb_xfer(struct em28xx *dev, enum em28xx_mode mode);
675void em28xx_stop_urbs(struct em28xx *dev); 695void em28xx_stop_urbs(struct em28xx *dev);
676int em28xx_isoc_dvb_max_packetsize(struct em28xx *dev); 696int em28xx_isoc_dvb_max_packetsize(struct em28xx *dev);
677int em28xx_set_mode(struct em28xx *dev, enum em28xx_mode set_mode); 697int em28xx_set_mode(struct em28xx *dev, enum em28xx_mode set_mode);
@@ -683,8 +703,13 @@ void em28xx_init_extension(struct em28xx *dev);
683void em28xx_close_extension(struct em28xx *dev); 703void em28xx_close_extension(struct em28xx *dev);
684 704
685/* Provided by em28xx-video.c */ 705/* Provided by em28xx-video.c */
706int em28xx_vb2_setup(struct em28xx *dev);
686int em28xx_register_analog_devices(struct em28xx *dev); 707int em28xx_register_analog_devices(struct em28xx *dev);
687void em28xx_release_analog_resources(struct em28xx *dev); 708void em28xx_release_analog_resources(struct em28xx *dev);
709void em28xx_ctrl_notify(struct v4l2_ctrl *ctrl, void *priv);
710int em28xx_start_analog_streaming(struct vb2_queue *vq, unsigned int count);
711int em28xx_stop_vbi_streaming(struct vb2_queue *vq);
712extern const struct v4l2_ctrl_ops em28xx_ctrl_ops;
688 713
689/* Provided by em28xx-cards.c */ 714/* Provided by em28xx-cards.c */
690extern int em2800_variant_detect(struct usb_device *udev, int model); 715extern int em2800_variant_detect(struct usb_device *udev, int model);
@@ -695,7 +720,7 @@ int em28xx_tuner_callback(void *ptr, int component, int command, int arg);
695void em28xx_release_resources(struct em28xx *dev); 720void em28xx_release_resources(struct em28xx *dev);
696 721
697/* Provided by em28xx-vbi.c */ 722/* Provided by em28xx-vbi.c */
698extern struct videobuf_queue_ops em28xx_vbi_qops; 723extern struct vb2_ops em28xx_vbi_qops;
699 724
700/* printk macros */ 725/* printk macros */
701 726
diff --git a/drivers/media/usb/gspca/cpia1.c b/drivers/media/usb/gspca/cpia1.c
index b3ba47d4d6a2..1dcdd9f95f1c 100644
--- a/drivers/media/usb/gspca/cpia1.c
+++ b/drivers/media/usb/gspca/cpia1.c
@@ -541,7 +541,7 @@ static int do_command(struct gspca_dev *gspca_dev, u16 command,
541 /* test button press */ 541 /* test button press */
542 a = ((gspca_dev->usb_buf[1] & 0x02) == 0); 542 a = ((gspca_dev->usb_buf[1] & 0x02) == 0);
543 if (a != sd->params.qx3.button) { 543 if (a != sd->params.qx3.button) {
544#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 544#if IS_ENABLED(CONFIG_INPUT)
545 input_report_key(gspca_dev->input_dev, KEY_CAMERA, a); 545 input_report_key(gspca_dev->input_dev, KEY_CAMERA, a);
546 input_sync(gspca_dev->input_dev); 546 input_sync(gspca_dev->input_dev);
547#endif 547#endif
@@ -1640,7 +1640,7 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
1640 /* Update the camera status */ 1640 /* Update the camera status */
1641 do_command(gspca_dev, CPIA_COMMAND_GetCameraStatus, 0, 0, 0, 0); 1641 do_command(gspca_dev, CPIA_COMMAND_GetCameraStatus, 0, 0, 0, 0);
1642 1642
1643#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 1643#if IS_ENABLED(CONFIG_INPUT)
1644 /* If the last button state is pressed, release it now! */ 1644 /* If the last button state is pressed, release it now! */
1645 if (sd->params.qx3.button) { 1645 if (sd->params.qx3.button) {
1646 /* The camera latch will hold the pressed state until we reset 1646 /* The camera latch will hold the pressed state until we reset
@@ -1869,7 +1869,7 @@ static const struct sd_desc sd_desc = {
1869 .stopN = sd_stopN, 1869 .stopN = sd_stopN,
1870 .dq_callback = sd_dq_callback, 1870 .dq_callback = sd_dq_callback,
1871 .pkt_scan = sd_pkt_scan, 1871 .pkt_scan = sd_pkt_scan,
1872#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 1872#if IS_ENABLED(CONFIG_INPUT)
1873 .other_input = 1, 1873 .other_input = 1,
1874#endif 1874#endif
1875}; 1875};
diff --git a/drivers/media/usb/gspca/gspca.c b/drivers/media/usb/gspca/gspca.c
index e0a431bb0d42..3564bdbb2ea3 100644
--- a/drivers/media/usb/gspca/gspca.c
+++ b/drivers/media/usb/gspca/gspca.c
@@ -44,7 +44,7 @@
44 44
45#include "gspca.h" 45#include "gspca.h"
46 46
47#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 47#if IS_ENABLED(CONFIG_INPUT)
48#include <linux/input.h> 48#include <linux/input.h>
49#include <linux/usb/input.h> 49#include <linux/usb/input.h>
50#endif 50#endif
@@ -118,7 +118,7 @@ static const struct vm_operations_struct gspca_vm_ops = {
118/* 118/*
119 * Input and interrupt endpoint handling functions 119 * Input and interrupt endpoint handling functions
120 */ 120 */
121#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 121#if IS_ENABLED(CONFIG_INPUT)
122static void int_irq(struct urb *urb) 122static void int_irq(struct urb *urb)
123{ 123{
124 struct gspca_dev *gspca_dev = (struct gspca_dev *) urb->context; 124 struct gspca_dev *gspca_dev = (struct gspca_dev *) urb->context;
@@ -2303,7 +2303,7 @@ int gspca_dev_probe2(struct usb_interface *intf,
2303 2303
2304 return 0; 2304 return 0;
2305out: 2305out:
2306#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 2306#if IS_ENABLED(CONFIG_INPUT)
2307 if (gspca_dev->input_dev) 2307 if (gspca_dev->input_dev)
2308 input_unregister_device(gspca_dev->input_dev); 2308 input_unregister_device(gspca_dev->input_dev);
2309#endif 2309#endif
@@ -2348,7 +2348,7 @@ EXPORT_SYMBOL(gspca_dev_probe);
2348void gspca_disconnect(struct usb_interface *intf) 2348void gspca_disconnect(struct usb_interface *intf)
2349{ 2349{
2350 struct gspca_dev *gspca_dev = usb_get_intfdata(intf); 2350 struct gspca_dev *gspca_dev = usb_get_intfdata(intf);
2351#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 2351#if IS_ENABLED(CONFIG_INPUT)
2352 struct input_dev *input_dev; 2352 struct input_dev *input_dev;
2353#endif 2353#endif
2354 2354
@@ -2360,7 +2360,7 @@ void gspca_disconnect(struct usb_interface *intf)
2360 gspca_dev->present = 0; 2360 gspca_dev->present = 0;
2361 destroy_urbs(gspca_dev); 2361 destroy_urbs(gspca_dev);
2362 2362
2363#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 2363#if IS_ENABLED(CONFIG_INPUT)
2364 gspca_input_destroy_urb(gspca_dev); 2364 gspca_input_destroy_urb(gspca_dev);
2365 input_dev = gspca_dev->input_dev; 2365 input_dev = gspca_dev->input_dev;
2366 if (input_dev) { 2366 if (input_dev) {
diff --git a/drivers/media/usb/gspca/gspca.h b/drivers/media/usb/gspca/gspca.h
index 352317d7acdb..5559932bf2f5 100644
--- a/drivers/media/usb/gspca/gspca.h
+++ b/drivers/media/usb/gspca/gspca.h
@@ -138,7 +138,7 @@ struct sd_desc {
138 cam_reg_op get_register; 138 cam_reg_op get_register;
139#endif 139#endif
140 cam_ident_op get_chip_ident; 140 cam_ident_op get_chip_ident;
141#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 141#if IS_ENABLED(CONFIG_INPUT)
142 cam_int_pkt_op int_pkt_scan; 142 cam_int_pkt_op int_pkt_scan;
143 /* other_input makes the gspca core create gspca_dev->input even when 143 /* other_input makes the gspca core create gspca_dev->input even when
144 int_pkt_scan is NULL, for cams with non interrupt driven buttons */ 144 int_pkt_scan is NULL, for cams with non interrupt driven buttons */
@@ -167,7 +167,7 @@ struct gspca_dev {
167 struct usb_device *dev; 167 struct usb_device *dev;
168 struct file *capt_file; /* file doing video capture */ 168 struct file *capt_file; /* file doing video capture */
169 /* protected by queue_lock */ 169 /* protected by queue_lock */
170#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 170#if IS_ENABLED(CONFIG_INPUT)
171 struct input_dev *input_dev; 171 struct input_dev *input_dev;
172 char phys[64]; /* physical device path */ 172 char phys[64]; /* physical device path */
173#endif 173#endif
@@ -190,7 +190,7 @@ struct gspca_dev {
190#define USB_BUF_SZ 64 190#define USB_BUF_SZ 64
191 __u8 *usb_buf; /* buffer for USB exchanges */ 191 __u8 *usb_buf; /* buffer for USB exchanges */
192 struct urb *urb[MAX_NURBS]; 192 struct urb *urb[MAX_NURBS];
193#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 193#if IS_ENABLED(CONFIG_INPUT)
194 struct urb *int_urb; 194 struct urb *int_urb;
195#endif 195#endif
196 196
diff --git a/drivers/media/usb/gspca/jl2005bcd.c b/drivers/media/usb/gspca/jl2005bcd.c
index 62ba80d9b998..fdaeeb14453f 100644
--- a/drivers/media/usb/gspca/jl2005bcd.c
+++ b/drivers/media/usb/gspca/jl2005bcd.c
@@ -536,20 +536,4 @@ static struct usb_driver sd_driver = {
536#endif 536#endif
537}; 537};
538 538
539/* -- module insert / remove -- */ 539module_usb_driver(sd_driver);
540static int __init sd_mod_init(void)
541{
542 int ret;
543
544 ret = usb_register(&sd_driver);
545 if (ret < 0)
546 return ret;
547 return 0;
548}
549static void __exit sd_mod_exit(void)
550{
551 usb_deregister(&sd_driver);
552}
553
554module_init(sd_mod_init);
555module_exit(sd_mod_exit);
diff --git a/drivers/media/usb/gspca/konica.c b/drivers/media/usb/gspca/konica.c
index bbf91e07e38b..61e25dbf2447 100644
--- a/drivers/media/usb/gspca/konica.c
+++ b/drivers/media/usb/gspca/konica.c
@@ -246,7 +246,7 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
246 struct sd *sd = (struct sd *) gspca_dev; 246 struct sd *sd = (struct sd *) gspca_dev;
247 247
248 konica_stream_off(gspca_dev); 248 konica_stream_off(gspca_dev);
249#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 249#if IS_ENABLED(CONFIG_INPUT)
250 /* Don't keep the button in the pressed state "forever" if it was 250 /* Don't keep the button in the pressed state "forever" if it was
251 pressed when streaming is stopped */ 251 pressed when streaming is stopped */
252 if (sd->snapshot_pressed) { 252 if (sd->snapshot_pressed) {
@@ -345,7 +345,7 @@ static void sd_isoc_irq(struct urb *urb)
345 gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0); 345 gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
346 gspca_frame_add(gspca_dev, FIRST_PACKET, NULL, 0); 346 gspca_frame_add(gspca_dev, FIRST_PACKET, NULL, 0);
347 } else { 347 } else {
348#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 348#if IS_ENABLED(CONFIG_INPUT)
349 u8 button_state = st & 0x40 ? 1 : 0; 349 u8 button_state = st & 0x40 ? 1 : 0;
350 if (sd->snapshot_pressed != button_state) { 350 if (sd->snapshot_pressed != button_state) {
351 input_report_key(gspca_dev->input_dev, 351 input_report_key(gspca_dev->input_dev,
@@ -452,7 +452,7 @@ static const struct sd_desc sd_desc = {
452 .init_controls = sd_init_controls, 452 .init_controls = sd_init_controls,
453 .start = sd_start, 453 .start = sd_start,
454 .stopN = sd_stopN, 454 .stopN = sd_stopN,
455#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 455#if IS_ENABLED(CONFIG_INPUT)
456 .other_input = 1, 456 .other_input = 1,
457#endif 457#endif
458}; 458};
diff --git a/drivers/media/usb/gspca/ov519.c b/drivers/media/usb/gspca/ov519.c
index 9aa09f845ce4..9ad19a7ef81b 100644
--- a/drivers/media/usb/gspca/ov519.c
+++ b/drivers/media/usb/gspca/ov519.c
@@ -4238,7 +4238,7 @@ static void sd_stop0(struct gspca_dev *gspca_dev)
4238 if (sd->bridge == BRIDGE_W9968CF) 4238 if (sd->bridge == BRIDGE_W9968CF)
4239 w9968cf_stop0(sd); 4239 w9968cf_stop0(sd);
4240 4240
4241#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 4241#if IS_ENABLED(CONFIG_INPUT)
4242 /* If the last button state is pressed, release it now! */ 4242 /* If the last button state is pressed, release it now! */
4243 if (sd->snapshot_pressed) { 4243 if (sd->snapshot_pressed) {
4244 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0); 4244 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
@@ -4255,7 +4255,7 @@ static void ov51x_handle_button(struct gspca_dev *gspca_dev, u8 state)
4255 struct sd *sd = (struct sd *) gspca_dev; 4255 struct sd *sd = (struct sd *) gspca_dev;
4256 4256
4257 if (sd->snapshot_pressed != state) { 4257 if (sd->snapshot_pressed != state) {
4258#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 4258#if IS_ENABLED(CONFIG_INPUT)
4259 input_report_key(gspca_dev->input_dev, KEY_CAMERA, state); 4259 input_report_key(gspca_dev->input_dev, KEY_CAMERA, state);
4260 input_sync(gspca_dev->input_dev); 4260 input_sync(gspca_dev->input_dev);
4261#endif 4261#endif
@@ -4924,7 +4924,7 @@ static const struct sd_desc sd_desc = {
4924 .dq_callback = sd_reset_snapshot, 4924 .dq_callback = sd_reset_snapshot,
4925 .get_jcomp = sd_get_jcomp, 4925 .get_jcomp = sd_get_jcomp,
4926 .set_jcomp = sd_set_jcomp, 4926 .set_jcomp = sd_set_jcomp,
4927#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 4927#if IS_ENABLED(CONFIG_INPUT)
4928 .other_input = 1, 4928 .other_input = 1,
4929#endif 4929#endif
4930}; 4930};
diff --git a/drivers/media/usb/gspca/pac207.c b/drivers/media/usb/gspca/pac207.c
index d236d1791f78..3b75097dd34e 100644
--- a/drivers/media/usb/gspca/pac207.c
+++ b/drivers/media/usb/gspca/pac207.c
@@ -55,6 +55,11 @@ MODULE_LICENSE("GPL");
55 55
56#define PAC207_AUTOGAIN_DEADZONE 30 56#define PAC207_AUTOGAIN_DEADZONE 30
57 57
58/* global parameters */
59static int led_invert;
60module_param(led_invert, int, 0644);
61MODULE_PARM_DESC(led_invert, "Invert led");
62
58/* specific webcam descriptor */ 63/* specific webcam descriptor */
59struct sd { 64struct sd {
60 struct gspca_dev gspca_dev; /* !! must be the first item */ 65 struct gspca_dev gspca_dev; /* !! must be the first item */
@@ -187,10 +192,14 @@ static int sd_config(struct gspca_dev *gspca_dev,
187/* this function is called at probe and resume time */ 192/* this function is called at probe and resume time */
188static int sd_init(struct gspca_dev *gspca_dev) 193static int sd_init(struct gspca_dev *gspca_dev)
189{ 194{
190 pac207_write_reg(gspca_dev, 0x41, 0x00); 195 u8 mode;
191 /* Bit_0=Image Format, 196
192 * Bit_1=LED, 197 /* mode: Image Format (Bit 0), LED (1), Compr. test mode (2) */
193 * Bit_2=Compression test mode enable */ 198 if (led_invert)
199 mode = 0x02;
200 else
201 mode = 0x00;
202 pac207_write_reg(gspca_dev, 0x41, mode);
194 pac207_write_reg(gspca_dev, 0x0f, 0x00); /* Power Control */ 203 pac207_write_reg(gspca_dev, 0x0f, 0x00); /* Power Control */
195 204
196 return gspca_dev->usb_err; 205 return gspca_dev->usb_err;
@@ -303,7 +312,11 @@ static int sd_start(struct gspca_dev *gspca_dev)
303 pac207_write_reg(gspca_dev, 0x02, 312 pac207_write_reg(gspca_dev, 0x02,
304 v4l2_ctrl_g_ctrl(gspca_dev->exposure)); /* PXCK = 12MHz /n */ 313 v4l2_ctrl_g_ctrl(gspca_dev->exposure)); /* PXCK = 12MHz /n */
305 314
306 mode = 0x02; /* Image Format (Bit 0), LED (1), Compr. test mode (2) */ 315 /* mode: Image Format (Bit 0), LED (1), Compr. test mode (2) */
316 if (led_invert)
317 mode = 0x00;
318 else
319 mode = 0x02;
307 if (gspca_dev->width == 176) { /* 176x144 */ 320 if (gspca_dev->width == 176) { /* 176x144 */
308 mode |= 0x01; 321 mode |= 0x01;
309 PDEBUG(D_STREAM, "pac207_start mode 176x144"); 322 PDEBUG(D_STREAM, "pac207_start mode 176x144");
@@ -325,8 +338,15 @@ static int sd_start(struct gspca_dev *gspca_dev)
325 338
326static void sd_stopN(struct gspca_dev *gspca_dev) 339static void sd_stopN(struct gspca_dev *gspca_dev)
327{ 340{
341 u8 mode;
342
343 /* mode: Image Format (Bit 0), LED (1), Compr. test mode (2) */
344 if (led_invert)
345 mode = 0x02;
346 else
347 mode = 0x00;
328 pac207_write_reg(gspca_dev, 0x40, 0x00); /* Stop ISO pipe */ 348 pac207_write_reg(gspca_dev, 0x40, 0x00); /* Stop ISO pipe */
329 pac207_write_reg(gspca_dev, 0x41, 0x00); /* Turn of LED */ 349 pac207_write_reg(gspca_dev, 0x41, mode); /* Turn off LED */
330 pac207_write_reg(gspca_dev, 0x0f, 0x00); /* Power Control */ 350 pac207_write_reg(gspca_dev, 0x0f, 0x00); /* Power Control */
331} 351}
332 352
@@ -393,7 +413,7 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
393 gspca_frame_add(gspca_dev, INTER_PACKET, data, len); 413 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
394} 414}
395 415
396#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 416#if IS_ENABLED(CONFIG_INPUT)
397static int sd_int_pkt_scan(struct gspca_dev *gspca_dev, 417static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
398 u8 *data, /* interrupt packet data */ 418 u8 *data, /* interrupt packet data */
399 int len) /* interrput packet length */ 419 int len) /* interrput packet length */
@@ -422,7 +442,7 @@ static const struct sd_desc sd_desc = {
422 .stopN = sd_stopN, 442 .stopN = sd_stopN,
423 .dq_callback = pac207_do_auto_gain, 443 .dq_callback = pac207_do_auto_gain,
424 .pkt_scan = sd_pkt_scan, 444 .pkt_scan = sd_pkt_scan,
425#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 445#if IS_ENABLED(CONFIG_INPUT)
426 .int_pkt_scan = sd_int_pkt_scan, 446 .int_pkt_scan = sd_int_pkt_scan,
427#endif 447#endif
428}; 448};
diff --git a/drivers/media/usb/gspca/pac7302.c b/drivers/media/usb/gspca/pac7302.c
index 4f5869a98082..add6f725ba50 100644
--- a/drivers/media/usb/gspca/pac7302.c
+++ b/drivers/media/usb/gspca/pac7302.c
@@ -890,7 +890,7 @@ static int sd_chip_ident(struct gspca_dev *gspca_dev,
890} 890}
891#endif 891#endif
892 892
893#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 893#if IS_ENABLED(CONFIG_INPUT)
894static int sd_int_pkt_scan(struct gspca_dev *gspca_dev, 894static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
895 u8 *data, /* interrupt packet data */ 895 u8 *data, /* interrupt packet data */
896 int len) /* interrput packet length */ 896 int len) /* interrput packet length */
@@ -936,7 +936,7 @@ static const struct sd_desc sd_desc = {
936 .set_register = sd_dbg_s_register, 936 .set_register = sd_dbg_s_register,
937 .get_chip_ident = sd_chip_ident, 937 .get_chip_ident = sd_chip_ident,
938#endif 938#endif
939#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 939#if IS_ENABLED(CONFIG_INPUT)
940 .int_pkt_scan = sd_int_pkt_scan, 940 .int_pkt_scan = sd_int_pkt_scan,
941#endif 941#endif
942}; 942};
diff --git a/drivers/media/usb/gspca/pac7311.c b/drivers/media/usb/gspca/pac7311.c
index ba3558d3f017..a12dfbf6e051 100644
--- a/drivers/media/usb/gspca/pac7311.c
+++ b/drivers/media/usb/gspca/pac7311.c
@@ -621,7 +621,7 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
621 gspca_frame_add(gspca_dev, INTER_PACKET, data, len); 621 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
622} 622}
623 623
624#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 624#if IS_ENABLED(CONFIG_INPUT)
625static int sd_int_pkt_scan(struct gspca_dev *gspca_dev, 625static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
626 u8 *data, /* interrupt packet data */ 626 u8 *data, /* interrupt packet data */
627 int len) /* interrupt packet length */ 627 int len) /* interrupt packet length */
@@ -661,7 +661,7 @@ static const struct sd_desc sd_desc = {
661 .stopN = sd_stopN, 661 .stopN = sd_stopN,
662 .pkt_scan = sd_pkt_scan, 662 .pkt_scan = sd_pkt_scan,
663 .dq_callback = do_autogain, 663 .dq_callback = do_autogain,
664#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 664#if IS_ENABLED(CONFIG_INPUT)
665 .int_pkt_scan = sd_int_pkt_scan, 665 .int_pkt_scan = sd_int_pkt_scan,
666#endif 666#endif
667}; 667};
diff --git a/drivers/media/usb/gspca/se401.c b/drivers/media/usb/gspca/se401.c
index a33cb78a839c..5f729b8aa2bd 100644
--- a/drivers/media/usb/gspca/se401.c
+++ b/drivers/media/usb/gspca/se401.c
@@ -594,7 +594,7 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev, u8 *data, int len)
594 sd_pkt_scan_janggu(gspca_dev, data, len); 594 sd_pkt_scan_janggu(gspca_dev, data, len);
595} 595}
596 596
597#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 597#if IS_ENABLED(CONFIG_INPUT)
598static int sd_int_pkt_scan(struct gspca_dev *gspca_dev, u8 *data, int len) 598static int sd_int_pkt_scan(struct gspca_dev *gspca_dev, u8 *data, int len)
599{ 599{
600 struct sd *sd = (struct sd *)gspca_dev; 600 struct sd *sd = (struct sd *)gspca_dev;
@@ -688,7 +688,7 @@ static const struct sd_desc sd_desc = {
688 .stopN = sd_stopN, 688 .stopN = sd_stopN,
689 .dq_callback = sd_dq_callback, 689 .dq_callback = sd_dq_callback,
690 .pkt_scan = sd_pkt_scan, 690 .pkt_scan = sd_pkt_scan,
691#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 691#if IS_ENABLED(CONFIG_INPUT)
692 .int_pkt_scan = sd_int_pkt_scan, 692 .int_pkt_scan = sd_int_pkt_scan,
693#endif 693#endif
694}; 694};
diff --git a/drivers/media/usb/gspca/sn9c20x.c b/drivers/media/usb/gspca/sn9c20x.c
index 41f769fe340c..4ec544f4a845 100644
--- a/drivers/media/usb/gspca/sn9c20x.c
+++ b/drivers/media/usb/gspca/sn9c20x.c
@@ -2205,7 +2205,7 @@ static void qual_upd(struct work_struct *work)
2205 mutex_unlock(&gspca_dev->usb_lock); 2205 mutex_unlock(&gspca_dev->usb_lock);
2206} 2206}
2207 2207
2208#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 2208#if IS_ENABLED(CONFIG_INPUT)
2209static int sd_int_pkt_scan(struct gspca_dev *gspca_dev, 2209static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
2210 u8 *data, /* interrupt packet */ 2210 u8 *data, /* interrupt packet */
2211 int len) /* interrupt packet length */ 2211 int len) /* interrupt packet length */
@@ -2349,7 +2349,7 @@ static const struct sd_desc sd_desc = {
2349 .stopN = sd_stopN, 2349 .stopN = sd_stopN,
2350 .stop0 = sd_stop0, 2350 .stop0 = sd_stop0,
2351 .pkt_scan = sd_pkt_scan, 2351 .pkt_scan = sd_pkt_scan,
2352#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 2352#if IS_ENABLED(CONFIG_INPUT)
2353 .int_pkt_scan = sd_int_pkt_scan, 2353 .int_pkt_scan = sd_int_pkt_scan,
2354#endif 2354#endif
2355 .dq_callback = sd_dqcallback, 2355 .dq_callback = sd_dqcallback,
diff --git a/drivers/media/usb/gspca/sonixb.c b/drivers/media/usb/gspca/sonixb.c
index 1220340e7602..104ae25275b4 100644
--- a/drivers/media/usb/gspca/sonixb.c
+++ b/drivers/media/usb/gspca/sonixb.c
@@ -1400,7 +1400,7 @@ static int sd_querymenu(struct gspca_dev *gspca_dev,
1400 return -EINVAL; 1400 return -EINVAL;
1401} 1401}
1402 1402
1403#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 1403#if IS_ENABLED(CONFIG_INPUT)
1404static int sd_int_pkt_scan(struct gspca_dev *gspca_dev, 1404static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
1405 u8 *data, /* interrupt packet data */ 1405 u8 *data, /* interrupt packet data */
1406 int len) /* interrupt packet length */ 1406 int len) /* interrupt packet length */
@@ -1430,7 +1430,7 @@ static const struct sd_desc sd_desc = {
1430 .pkt_scan = sd_pkt_scan, 1430 .pkt_scan = sd_pkt_scan,
1431 .querymenu = sd_querymenu, 1431 .querymenu = sd_querymenu,
1432 .dq_callback = do_autogain, 1432 .dq_callback = do_autogain,
1433#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 1433#if IS_ENABLED(CONFIG_INPUT)
1434 .int_pkt_scan = sd_int_pkt_scan, 1434 .int_pkt_scan = sd_int_pkt_scan,
1435#endif 1435#endif
1436}; 1436};
@@ -1448,7 +1448,7 @@ static const struct usb_device_id device_table[] = {
1448 {USB_DEVICE(0x0c45, 0x600d), SB(PAS106, 101)}, 1448 {USB_DEVICE(0x0c45, 0x600d), SB(PAS106, 101)},
1449 {USB_DEVICE(0x0c45, 0x6011), SB(OV6650, 101)}, 1449 {USB_DEVICE(0x0c45, 0x6011), SB(OV6650, 101)},
1450 {USB_DEVICE(0x0c45, 0x6019), SB(OV7630, 101)}, 1450 {USB_DEVICE(0x0c45, 0x6019), SB(OV7630, 101)},
1451#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE 1451#if !IS_ENABLED(CONFIG_USB_SN9C102)
1452 {USB_DEVICE(0x0c45, 0x6024), SB(TAS5130CXX, 102)}, 1452 {USB_DEVICE(0x0c45, 0x6024), SB(TAS5130CXX, 102)},
1453 {USB_DEVICE(0x0c45, 0x6025), SB(TAS5130CXX, 102)}, 1453 {USB_DEVICE(0x0c45, 0x6025), SB(TAS5130CXX, 102)},
1454#endif 1454#endif
diff --git a/drivers/media/usb/gspca/sonixj.c b/drivers/media/usb/gspca/sonixj.c
index 36307a9028a9..671d0c6dece3 100644
--- a/drivers/media/usb/gspca/sonixj.c
+++ b/drivers/media/usb/gspca/sonixj.c
@@ -3077,7 +3077,7 @@ static int sd_querymenu(struct gspca_dev *gspca_dev,
3077 return -EINVAL; 3077 return -EINVAL;
3078} 3078}
3079 3079
3080#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 3080#if IS_ENABLED(CONFIG_INPUT)
3081static int sd_int_pkt_scan(struct gspca_dev *gspca_dev, 3081static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
3082 u8 *data, /* interrupt packet data */ 3082 u8 *data, /* interrupt packet data */
3083 int len) /* interrupt packet length */ 3083 int len) /* interrupt packet length */
@@ -3109,7 +3109,7 @@ static const struct sd_desc sd_desc = {
3109 .pkt_scan = sd_pkt_scan, 3109 .pkt_scan = sd_pkt_scan,
3110 .dq_callback = do_autogain, 3110 .dq_callback = do_autogain,
3111 .querymenu = sd_querymenu, 3111 .querymenu = sd_querymenu,
3112#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 3112#if IS_ENABLED(CONFIG_INPUT)
3113 .int_pkt_scan = sd_int_pkt_scan, 3113 .int_pkt_scan = sd_int_pkt_scan,
3114#endif 3114#endif
3115}; 3115};
diff --git a/drivers/media/usb/gspca/spca561.c b/drivers/media/usb/gspca/spca561.c
index cfe71dd6747d..d1db3d8f6522 100644
--- a/drivers/media/usb/gspca/spca561.c
+++ b/drivers/media/usb/gspca/spca561.c
@@ -741,7 +741,7 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
741 return; 741 return;
742 } 742 }
743 743
744#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 744#if IS_ENABLED(CONFIG_INPUT)
745 if (data[0] & 0x20) { 745 if (data[0] & 0x20) {
746 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1); 746 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1);
747 input_sync(gspca_dev->input_dev); 747 input_sync(gspca_dev->input_dev);
@@ -866,7 +866,7 @@ static const struct sd_desc sd_desc_12a = {
866 .start = sd_start_12a, 866 .start = sd_start_12a,
867 .stopN = sd_stopN, 867 .stopN = sd_stopN,
868 .pkt_scan = sd_pkt_scan, 868 .pkt_scan = sd_pkt_scan,
869#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 869#if IS_ENABLED(CONFIG_INPUT)
870 .other_input = 1, 870 .other_input = 1,
871#endif 871#endif
872}; 872};
@@ -879,7 +879,7 @@ static const struct sd_desc sd_desc_72a = {
879 .stopN = sd_stopN, 879 .stopN = sd_stopN,
880 .pkt_scan = sd_pkt_scan, 880 .pkt_scan = sd_pkt_scan,
881 .dq_callback = do_autogain, 881 .dq_callback = do_autogain,
882#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 882#if IS_ENABLED(CONFIG_INPUT)
883 .other_input = 1, 883 .other_input = 1,
884#endif 884#endif
885}; 885};
diff --git a/drivers/media/usb/gspca/stv06xx/stv06xx.c b/drivers/media/usb/gspca/stv06xx/stv06xx.c
index 999ec7764449..657160b4a1f7 100644
--- a/drivers/media/usb/gspca/stv06xx/stv06xx.c
+++ b/drivers/media/usb/gspca/stv06xx/stv06xx.c
@@ -492,7 +492,7 @@ frame_data:
492 } 492 }
493} 493}
494 494
495#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 495#if IS_ENABLED(CONFIG_INPUT)
496static int sd_int_pkt_scan(struct gspca_dev *gspca_dev, 496static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
497 u8 *data, /* interrupt packet data */ 497 u8 *data, /* interrupt packet data */
498 int len) /* interrupt packet length */ 498 int len) /* interrupt packet length */
@@ -529,7 +529,7 @@ static const struct sd_desc sd_desc = {
529 .pkt_scan = stv06xx_pkt_scan, 529 .pkt_scan = stv06xx_pkt_scan,
530 .isoc_init = stv06xx_isoc_init, 530 .isoc_init = stv06xx_isoc_init,
531 .isoc_nego = stv06xx_isoc_nego, 531 .isoc_nego = stv06xx_isoc_nego,
532#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 532#if IS_ENABLED(CONFIG_INPUT)
533 .int_pkt_scan = sd_int_pkt_scan, 533 .int_pkt_scan = sd_int_pkt_scan,
534#endif 534#endif
535}; 535};
diff --git a/drivers/media/usb/gspca/stv06xx/stv06xx_vv6410.c b/drivers/media/usb/gspca/stv06xx/stv06xx_vv6410.c
index 748e1421d6d8..e95fa8997d22 100644
--- a/drivers/media/usb/gspca/stv06xx/stv06xx_vv6410.c
+++ b/drivers/media/usb/gspca/stv06xx/stv06xx_vv6410.c
@@ -52,9 +52,13 @@ static int vv6410_s_ctrl(struct v4l2_ctrl *ctrl)
52 52
53 switch (ctrl->id) { 53 switch (ctrl->id) {
54 case V4L2_CID_HFLIP: 54 case V4L2_CID_HFLIP:
55 if (!gspca_dev->streaming)
56 return 0;
55 err = vv6410_set_hflip(gspca_dev, ctrl->val); 57 err = vv6410_set_hflip(gspca_dev, ctrl->val);
56 break; 58 break;
57 case V4L2_CID_VFLIP: 59 case V4L2_CID_VFLIP:
60 if (!gspca_dev->streaming)
61 return 0;
58 err = vv6410_set_vflip(gspca_dev, ctrl->val); 62 err = vv6410_set_vflip(gspca_dev, ctrl->val);
59 break; 63 break;
60 case V4L2_CID_GAIN: 64 case V4L2_CID_GAIN:
@@ -94,11 +98,14 @@ static int vv6410_init_controls(struct sd *sd)
94{ 98{
95 struct v4l2_ctrl_handler *hdl = &sd->gspca_dev.ctrl_handler; 99 struct v4l2_ctrl_handler *hdl = &sd->gspca_dev.ctrl_handler;
96 100
97 v4l2_ctrl_handler_init(hdl, 4); 101 v4l2_ctrl_handler_init(hdl, 2);
98 v4l2_ctrl_new_std(hdl, &vv6410_ctrl_ops, 102 /* Disable the hardware VFLIP and HFLIP as we currently lack a
99 V4L2_CID_HFLIP, 0, 1, 1, 0); 103 mechanism to adjust the image offset in such a way that
100 v4l2_ctrl_new_std(hdl, &vv6410_ctrl_ops, 104 we don't need to renegotiate the announced format */
101 V4L2_CID_VFLIP, 0, 1, 1, 0); 105 /* v4l2_ctrl_new_std(hdl, &vv6410_ctrl_ops, */
106 /* V4L2_CID_HFLIP, 0, 1, 1, 0); */
107 /* v4l2_ctrl_new_std(hdl, &vv6410_ctrl_ops, */
108 /* V4L2_CID_VFLIP, 0, 1, 1, 0); */
102 v4l2_ctrl_new_std(hdl, &vv6410_ctrl_ops, 109 v4l2_ctrl_new_std(hdl, &vv6410_ctrl_ops,
103 V4L2_CID_EXPOSURE, 0, 32768, 1, 20000); 110 V4L2_CID_EXPOSURE, 0, 32768, 1, 20000);
104 v4l2_ctrl_new_std(hdl, &vv6410_ctrl_ops, 111 v4l2_ctrl_new_std(hdl, &vv6410_ctrl_ops,
diff --git a/drivers/media/usb/gspca/t613.c b/drivers/media/usb/gspca/t613.c
index 8bc6c3ceec2c..e2cc4e5a0ccb 100644
--- a/drivers/media/usb/gspca/t613.c
+++ b/drivers/media/usb/gspca/t613.c
@@ -494,7 +494,7 @@ static void setcolors(struct gspca_dev *gspca_dev, s32 val)
494 494
495static void setgamma(struct gspca_dev *gspca_dev, s32 val) 495static void setgamma(struct gspca_dev *gspca_dev, s32 val)
496{ 496{
497 PDEBUG(D_CONF, "Gamma: %d", sd->gamma); 497 PDEBUG(D_CONF, "Gamma: %d", val);
498 reg_w_ixbuf(gspca_dev, 0x90, 498 reg_w_ixbuf(gspca_dev, 0x90,
499 gamma_table[val], sizeof gamma_table[0]); 499 gamma_table[val], sizeof gamma_table[0]);
500} 500}
@@ -823,7 +823,7 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
823 msleep(20); 823 msleep(20);
824 reg_w(gspca_dev, 0x0309); 824 reg_w(gspca_dev, 0x0309);
825 } 825 }
826#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 826#if IS_ENABLED(CONFIG_INPUT)
827 /* If the last button state is pressed, release it now! */ 827 /* If the last button state is pressed, release it now! */
828 if (sd->button_pressed) { 828 if (sd->button_pressed) {
829 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0); 829 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
@@ -841,7 +841,7 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
841 int pkt_type; 841 int pkt_type;
842 842
843 if (data[0] == 0x5a) { 843 if (data[0] == 0x5a) {
844#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 844#if IS_ENABLED(CONFIG_INPUT)
845 if (len > 20) { 845 if (len > 20) {
846 u8 state = (data[20] & 0x80) ? 1 : 0; 846 u8 state = (data[20] & 0x80) ? 1 : 0;
847 if (sd->button_pressed != state) { 847 if (sd->button_pressed != state) {
@@ -1019,7 +1019,7 @@ static const struct sd_desc sd_desc = {
1019 .start = sd_start, 1019 .start = sd_start,
1020 .stopN = sd_stopN, 1020 .stopN = sd_stopN,
1021 .pkt_scan = sd_pkt_scan, 1021 .pkt_scan = sd_pkt_scan,
1022#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 1022#if IS_ENABLED(CONFIG_INPUT)
1023 .other_input = 1, 1023 .other_input = 1,
1024#endif 1024#endif
1025}; 1025};
diff --git a/drivers/media/usb/gspca/xirlink_cit.c b/drivers/media/usb/gspca/xirlink_cit.c
index d4b23c9bf90c..7eaf64eb867c 100644
--- a/drivers/media/usb/gspca/xirlink_cit.c
+++ b/drivers/media/usb/gspca/xirlink_cit.c
@@ -2759,7 +2759,7 @@ static void sd_stop0(struct gspca_dev *gspca_dev)
2759 break; 2759 break;
2760 } 2760 }
2761 2761
2762#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 2762#if IS_ENABLED(CONFIG_INPUT)
2763 /* If the last button state is pressed, release it now! */ 2763 /* If the last button state is pressed, release it now! */
2764 if (sd->button_state) { 2764 if (sd->button_state) {
2765 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0); 2765 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
@@ -2914,7 +2914,7 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
2914 gspca_frame_add(gspca_dev, INTER_PACKET, data, len); 2914 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
2915} 2915}
2916 2916
2917#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 2917#if IS_ENABLED(CONFIG_INPUT)
2918static void cit_check_button(struct gspca_dev *gspca_dev) 2918static void cit_check_button(struct gspca_dev *gspca_dev)
2919{ 2919{
2920 int new_button_state; 2920 int new_button_state;
@@ -3062,7 +3062,7 @@ static const struct sd_desc sd_desc = {
3062 .stopN = sd_stopN, 3062 .stopN = sd_stopN,
3063 .stop0 = sd_stop0, 3063 .stop0 = sd_stop0,
3064 .pkt_scan = sd_pkt_scan, 3064 .pkt_scan = sd_pkt_scan,
3065#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 3065#if IS_ENABLED(CONFIG_INPUT)
3066 .dq_callback = cit_check_button, 3066 .dq_callback = cit_check_button,
3067 .other_input = 1, 3067 .other_input = 1,
3068#endif 3068#endif
@@ -3079,7 +3079,7 @@ static const struct sd_desc sd_desc_isoc_nego = {
3079 .stopN = sd_stopN, 3079 .stopN = sd_stopN,
3080 .stop0 = sd_stop0, 3080 .stop0 = sd_stop0,
3081 .pkt_scan = sd_pkt_scan, 3081 .pkt_scan = sd_pkt_scan,
3082#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 3082#if IS_ENABLED(CONFIG_INPUT)
3083 .dq_callback = cit_check_button, 3083 .dq_callback = cit_check_button,
3084 .other_input = 1, 3084 .other_input = 1,
3085#endif 3085#endif
diff --git a/drivers/media/usb/gspca/zc3xx.c b/drivers/media/usb/gspca/zc3xx.c
index 77c57755e7b4..a8dc421f9f1f 100644
--- a/drivers/media/usb/gspca/zc3xx.c
+++ b/drivers/media/usb/gspca/zc3xx.c
@@ -6902,7 +6902,7 @@ static int sd_get_jcomp(struct gspca_dev *gspca_dev,
6902 return 0; 6902 return 0;
6903} 6903}
6904 6904
6905#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 6905#if IS_ENABLED(CONFIG_INPUT)
6906static int sd_int_pkt_scan(struct gspca_dev *gspca_dev, 6906static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
6907 u8 *data, /* interrupt packet data */ 6907 u8 *data, /* interrupt packet data */
6908 int len) /* interrput packet length */ 6908 int len) /* interrput packet length */
@@ -6929,7 +6929,7 @@ static const struct sd_desc sd_desc = {
6929 .pkt_scan = sd_pkt_scan, 6929 .pkt_scan = sd_pkt_scan,
6930 .get_jcomp = sd_get_jcomp, 6930 .get_jcomp = sd_get_jcomp,
6931 .set_jcomp = sd_set_jcomp, 6931 .set_jcomp = sd_set_jcomp,
6932#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE) 6932#if IS_ENABLED(CONFIG_INPUT)
6933 .int_pkt_scan = sd_int_pkt_scan, 6933 .int_pkt_scan = sd_int_pkt_scan,
6934#endif 6934#endif
6935}; 6935};
diff --git a/drivers/media/usb/hdpvr/hdpvr-core.c b/drivers/media/usb/hdpvr/hdpvr-core.c
index 84dc26fe80ee..5c6193536399 100644
--- a/drivers/media/usb/hdpvr/hdpvr-core.c
+++ b/drivers/media/usb/hdpvr/hdpvr-core.c
@@ -391,7 +391,7 @@ static int hdpvr_probe(struct usb_interface *interface,
391 goto error; 391 goto error;
392 } 392 }
393 393
394#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 394#if IS_ENABLED(CONFIG_I2C)
395 retval = hdpvr_register_i2c_adapter(dev); 395 retval = hdpvr_register_i2c_adapter(dev);
396 if (retval < 0) { 396 if (retval < 0) {
397 v4l2_err(&dev->v4l2_dev, "i2c adapter register failed\n"); 397 v4l2_err(&dev->v4l2_dev, "i2c adapter register failed\n");
@@ -419,7 +419,7 @@ static int hdpvr_probe(struct usb_interface *interface,
419 return 0; 419 return 0;
420 420
421reg_fail: 421reg_fail:
422#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 422#if IS_ENABLED(CONFIG_I2C)
423 i2c_del_adapter(&dev->i2c_adapter); 423 i2c_del_adapter(&dev->i2c_adapter);
424#endif 424#endif
425error: 425error:
@@ -451,7 +451,7 @@ static void hdpvr_disconnect(struct usb_interface *interface)
451 mutex_lock(&dev->io_mutex); 451 mutex_lock(&dev->io_mutex);
452 hdpvr_cancel_queue(dev); 452 hdpvr_cancel_queue(dev);
453 mutex_unlock(&dev->io_mutex); 453 mutex_unlock(&dev->io_mutex);
454#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 454#if IS_ENABLED(CONFIG_I2C)
455 i2c_del_adapter(&dev->i2c_adapter); 455 i2c_del_adapter(&dev->i2c_adapter);
456#endif 456#endif
457 video_unregister_device(dev->video_dev); 457 video_unregister_device(dev->video_dev);
diff --git a/drivers/media/usb/hdpvr/hdpvr-i2c.c b/drivers/media/usb/hdpvr/hdpvr-i2c.c
index 031cf024304c..a38f58c4c6bf 100644
--- a/drivers/media/usb/hdpvr/hdpvr-i2c.c
+++ b/drivers/media/usb/hdpvr/hdpvr-i2c.c
@@ -13,7 +13,7 @@
13 * 13 *
14 */ 14 */
15 15
16#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 16#if IS_ENABLED(CONFIG_I2C)
17 17
18#include <linux/i2c.h> 18#include <linux/i2c.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
@@ -217,8 +217,7 @@ int hdpvr_register_i2c_adapter(struct hdpvr_device *dev)
217 217
218 hdpvr_activate_ir(dev); 218 hdpvr_activate_ir(dev);
219 219
220 memcpy(&dev->i2c_adapter, &hdpvr_i2c_adapter_template, 220 dev->i2c_adapter = hdpvr_i2c_adapter_template;
221 sizeof(struct i2c_adapter));
222 dev->i2c_adapter.dev.parent = &dev->udev->dev; 221 dev->i2c_adapter.dev.parent = &dev->udev->dev;
223 222
224 i2c_set_adapdata(&dev->i2c_adapter, dev); 223 i2c_set_adapdata(&dev->i2c_adapter, dev);
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-encoder.c b/drivers/media/usb/pvrusb2/pvrusb2-encoder.c
index e046fdaec5ae..f7702aeeda3f 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-encoder.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-encoder.c
@@ -422,8 +422,7 @@ int pvr2_encoder_adjust(struct pvr2_hdw *hdw)
422 pvr2_trace(PVR2_TRACE_ERROR_LEGS, 422 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
423 "Error from cx2341x module code=%d",ret); 423 "Error from cx2341x module code=%d",ret);
424 } else { 424 } else {
425 memcpy(&hdw->enc_cur_state,&hdw->enc_ctl_state, 425 hdw->enc_cur_state = hdw->enc_ctl_state;
426 sizeof(struct cx2341x_mpeg_params));
427 hdw->enc_cur_valid = !0; 426 hdw->enc_cur_valid = !0;
428 } 427 }
429 return ret; 428 return ret;
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-i2c-core.c b/drivers/media/usb/pvrusb2/pvrusb2-i2c-core.c
index 9ab596c78a4e..b5e929f1bf82 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-i2c-core.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-i2c-core.c
@@ -649,8 +649,8 @@ void pvr2_i2c_core_init(struct pvr2_hdw *hdw)
649 } 649 }
650 650
651 // Configure the adapter and set up everything else related to it. 651 // Configure the adapter and set up everything else related to it.
652 memcpy(&hdw->i2c_adap,&pvr2_i2c_adap_template,sizeof(hdw->i2c_adap)); 652 hdw->i2c_adap = pvr2_i2c_adap_template;
653 memcpy(&hdw->i2c_algo,&pvr2_i2c_algo_template,sizeof(hdw->i2c_algo)); 653 hdw->i2c_algo = pvr2_i2c_algo_template;
654 strlcpy(hdw->i2c_adap.name,hdw->name,sizeof(hdw->i2c_adap.name)); 654 strlcpy(hdw->i2c_adap.name,hdw->name,sizeof(hdw->i2c_adap.name));
655 hdw->i2c_adap.dev.parent = &hdw->usb_dev->dev; 655 hdw->i2c_adap.dev.parent = &hdw->usb_dev->dev;
656 hdw->i2c_adap.algo = &hdw->i2c_algo; 656 hdw->i2c_adap.algo = &hdw->i2c_algo;
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c b/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c
index 6930676051e7..34c3b6e80e86 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c
@@ -1339,7 +1339,7 @@ static void pvr2_v4l2_dev_init(struct pvr2_v4l2_dev *dip,
1339 return; 1339 return;
1340 } 1340 }
1341 1341
1342 memcpy(&dip->devbase,&vdev_template,sizeof(vdev_template)); 1342 dip->devbase = vdev_template;
1343 dip->devbase.release = pvr2_video_device_release; 1343 dip->devbase.release = pvr2_video_device_release;
1344 dip->devbase.ioctl_ops = &pvr2_ioctl_ops; 1344 dip->devbase.ioctl_ops = &pvr2_ioctl_ops;
1345 { 1345 {
diff --git a/drivers/media/usb/pwc/pwc-if.c b/drivers/media/usb/pwc/pwc-if.c
index 5210239cbaee..5ec15cb1ed26 100644
--- a/drivers/media/usb/pwc/pwc-if.c
+++ b/drivers/media/usb/pwc/pwc-if.c
@@ -316,7 +316,8 @@ static void pwc_isoc_handler(struct urb *urb)
316 struct pwc_frame_buf *fbuf = pdev->fill_buf; 316 struct pwc_frame_buf *fbuf = pdev->fill_buf;
317 317
318 if (pdev->vsync == 1) { 318 if (pdev->vsync == 1) {
319 do_gettimeofday(&fbuf->vb.v4l2_buf.timestamp); 319 v4l2_get_timestamp(
320 &fbuf->vb.v4l2_buf.timestamp);
320 pdev->vsync = 2; 321 pdev->vsync = 2;
321 } 322 }
322 323
@@ -1007,7 +1008,7 @@ static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id
1007 } 1008 }
1008 1009
1009 /* Init video_device structure */ 1010 /* Init video_device structure */
1010 memcpy(&pdev->vdev, &pwc_template, sizeof(pwc_template)); 1011 pdev->vdev = pwc_template;
1011 strcpy(pdev->vdev.name, name); 1012 strcpy(pdev->vdev.name, name);
1012 pdev->vdev.queue = &pdev->vb_queue; 1013 pdev->vdev.queue = &pdev->vb_queue;
1013 pdev->vdev.queue->lock = &pdev->vb_queue_lock; 1014 pdev->vdev.queue->lock = &pdev->vb_queue_lock;
diff --git a/drivers/media/usb/pwc/pwc-v4l.c b/drivers/media/usb/pwc/pwc-v4l.c
index 545e9bbdeede..aa7449eaca08 100644
--- a/drivers/media/usb/pwc/pwc-v4l.c
+++ b/drivers/media/usb/pwc/pwc-v4l.c
@@ -434,19 +434,18 @@ static int pwc_vidioc_try_fmt(struct pwc_device *pdev, struct v4l2_format *f)
434 case V4L2_PIX_FMT_PWC1: 434 case V4L2_PIX_FMT_PWC1:
435 if (DEVICE_USE_CODEC23(pdev->type)) { 435 if (DEVICE_USE_CODEC23(pdev->type)) {
436 PWC_DEBUG_IOCTL("codec1 is only supported for old pwc webcam\n"); 436 PWC_DEBUG_IOCTL("codec1 is only supported for old pwc webcam\n");
437 return -EINVAL; 437 f->fmt.pix.pixelformat = V4L2_PIX_FMT_YUV420;
438 } 438 }
439 break; 439 break;
440 case V4L2_PIX_FMT_PWC2: 440 case V4L2_PIX_FMT_PWC2:
441 if (DEVICE_USE_CODEC1(pdev->type)) { 441 if (DEVICE_USE_CODEC1(pdev->type)) {
442 PWC_DEBUG_IOCTL("codec23 is only supported for new pwc webcam\n"); 442 PWC_DEBUG_IOCTL("codec23 is only supported for new pwc webcam\n");
443 return -EINVAL; 443 f->fmt.pix.pixelformat = V4L2_PIX_FMT_YUV420;
444 } 444 }
445 break; 445 break;
446 default: 446 default:
447 PWC_DEBUG_IOCTL("Unsupported pixel format\n"); 447 PWC_DEBUG_IOCTL("Unsupported pixel format\n");
448 return -EINVAL; 448 f->fmt.pix.pixelformat = V4L2_PIX_FMT_YUV420;
449
450 } 449 }
451 450
452 size = pwc_get_size(pdev, f->fmt.pix.width, f->fmt.pix.height); 451 size = pwc_get_size(pdev, f->fmt.pix.width, f->fmt.pix.height);
diff --git a/drivers/media/usb/s2255/s2255drv.c b/drivers/media/usb/s2255/s2255drv.c
index 8ebec0d7bf59..498c57ea5d32 100644
--- a/drivers/media/usb/s2255/s2255drv.c
+++ b/drivers/media/usb/s2255/s2255drv.c
@@ -593,7 +593,7 @@ static int s2255_got_frame(struct s2255_channel *channel, int jpgsize)
593 buf = list_entry(dma_q->active.next, 593 buf = list_entry(dma_q->active.next,
594 struct s2255_buffer, vb.queue); 594 struct s2255_buffer, vb.queue);
595 list_del(&buf->vb.queue); 595 list_del(&buf->vb.queue);
596 do_gettimeofday(&buf->vb.ts); 596 v4l2_get_timestamp(&buf->vb.ts);
597 s2255_fillbuff(channel, buf, jpgsize); 597 s2255_fillbuff(channel, buf, jpgsize);
598 wake_up(&buf->vb.done); 598 wake_up(&buf->vb.done);
599 dprintk(2, "%s: [buf/i] [%p/%d]\n", __func__, buf, buf->vb.i); 599 dprintk(2, "%s: [buf/i] [%p/%d]\n", __func__, buf, buf->vb.i);
@@ -629,7 +629,6 @@ static void s2255_fillbuff(struct s2255_channel *channel,
629 struct s2255_buffer *buf, int jpgsize) 629 struct s2255_buffer *buf, int jpgsize)
630{ 630{
631 int pos = 0; 631 int pos = 0;
632 struct timeval ts;
633 const char *tmpbuf; 632 const char *tmpbuf;
634 char *vbuf = videobuf_to_vmalloc(&buf->vb); 633 char *vbuf = videobuf_to_vmalloc(&buf->vb);
635 unsigned long last_frame; 634 unsigned long last_frame;
@@ -674,8 +673,7 @@ static void s2255_fillbuff(struct s2255_channel *channel,
674 /* tell v4l buffer was filled */ 673 /* tell v4l buffer was filled */
675 674
676 buf->vb.field_count = channel->frame_count * 2; 675 buf->vb.field_count = channel->frame_count * 2;
677 do_gettimeofday(&ts); 676 v4l2_get_timestamp(&buf->vb.ts);
678 buf->vb.ts = ts;
679 buf->vb.state = VIDEOBUF_DONE; 677 buf->vb.state = VIDEOBUF_DONE;
680} 678}
681 679
diff --git a/drivers/media/usb/sn9c102/sn9c102_core.c b/drivers/media/usb/sn9c102/sn9c102_core.c
index 73605864fffa..c957e9aa6077 100644
--- a/drivers/media/usb/sn9c102/sn9c102_core.c
+++ b/drivers/media/usb/sn9c102/sn9c102_core.c
@@ -173,7 +173,7 @@ sn9c102_request_buffers(struct sn9c102_device* cam, u32 count,
173 cam->frame[i].buf.sequence = 0; 173 cam->frame[i].buf.sequence = 0;
174 cam->frame[i].buf.field = V4L2_FIELD_NONE; 174 cam->frame[i].buf.field = V4L2_FIELD_NONE;
175 cam->frame[i].buf.memory = V4L2_MEMORY_MMAP; 175 cam->frame[i].buf.memory = V4L2_MEMORY_MMAP;
176 cam->frame[i].buf.flags = 0; 176 cam->frame[i].buf.flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
177 } 177 }
178 178
179 return cam->nbuffers; 179 return cam->nbuffers;
@@ -773,7 +773,8 @@ end_of_frame:
773 img); 773 img);
774 774
775 if ((*f)->buf.bytesused == 0) 775 if ((*f)->buf.bytesused == 0)
776 do_gettimeofday(&(*f)->buf.timestamp); 776 v4l2_get_timestamp(
777 &(*f)->buf.timestamp);
777 778
778 (*f)->buf.bytesused += img; 779 (*f)->buf.bytesused += img;
779 780
@@ -2826,7 +2827,7 @@ sn9c102_vidioc_querybuf(struct sn9c102_device* cam, void __user * arg)
2826 b.index >= cam->nbuffers || cam->io != IO_MMAP) 2827 b.index >= cam->nbuffers || cam->io != IO_MMAP)
2827 return -EINVAL; 2828 return -EINVAL;
2828 2829
2829 memcpy(&b, &cam->frame[b.index].buf, sizeof(b)); 2830 b = cam->frame[b.index].buf;
2830 2831
2831 if (cam->frame[b.index].vma_use_count) 2832 if (cam->frame[b.index].vma_use_count)
2832 b.flags |= V4L2_BUF_FLAG_MAPPED; 2833 b.flags |= V4L2_BUF_FLAG_MAPPED;
@@ -2929,7 +2930,7 @@ sn9c102_vidioc_dqbuf(struct sn9c102_device* cam, struct file* filp,
2929 2930
2930 f->state = F_UNUSED; 2931 f->state = F_UNUSED;
2931 2932
2932 memcpy(&b, &f->buf, sizeof(b)); 2933 b = f->buf;
2933 if (f->vma_use_count) 2934 if (f->vma_use_count)
2934 b.flags |= V4L2_BUF_FLAG_MAPPED; 2935 b.flags |= V4L2_BUF_FLAG_MAPPED;
2935 2936
diff --git a/drivers/media/usb/stk1160/stk1160-video.c b/drivers/media/usb/stk1160/stk1160-video.c
index fa3671de02aa..39f1aae209bc 100644
--- a/drivers/media/usb/stk1160/stk1160-video.c
+++ b/drivers/media/usb/stk1160/stk1160-video.c
@@ -78,7 +78,7 @@ struct stk1160_buffer *stk1160_next_buffer(struct stk1160 *dev)
78 unsigned long flags = 0; 78 unsigned long flags = 0;
79 79
80 /* Current buffer must be NULL when this functions gets called */ 80 /* Current buffer must be NULL when this functions gets called */
81 BUG_ON(dev->isoc_ctl.buf); 81 WARN_ON(dev->isoc_ctl.buf);
82 82
83 spin_lock_irqsave(&dev->buf_lock, flags); 83 spin_lock_irqsave(&dev->buf_lock, flags);
84 if (!list_empty(&dev->avail_bufs)) { 84 if (!list_empty(&dev->avail_bufs)) {
@@ -101,7 +101,7 @@ void stk1160_buffer_done(struct stk1160 *dev)
101 buf->vb.v4l2_buf.sequence = dev->field_count >> 1; 101 buf->vb.v4l2_buf.sequence = dev->field_count >> 1;
102 buf->vb.v4l2_buf.field = V4L2_FIELD_INTERLACED; 102 buf->vb.v4l2_buf.field = V4L2_FIELD_INTERLACED;
103 buf->vb.v4l2_buf.bytesused = buf->bytesused; 103 buf->vb.v4l2_buf.bytesused = buf->bytesused;
104 do_gettimeofday(&buf->vb.v4l2_buf.timestamp); 104 v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp);
105 105
106 vb2_set_plane_payload(&buf->vb, 0, buf->bytesused); 106 vb2_set_plane_payload(&buf->vb, 0, buf->bytesused);
107 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_DONE); 107 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_DONE);
diff --git a/drivers/media/usb/stkwebcam/stk-webcam.c b/drivers/media/usb/stkwebcam/stk-webcam.c
index 5d3c032d733c..4cbab085e348 100644
--- a/drivers/media/usb/stkwebcam/stk-webcam.c
+++ b/drivers/media/usb/stkwebcam/stk-webcam.c
@@ -28,6 +28,7 @@
28#include <linux/errno.h> 28#include <linux/errno.h>
29#include <linux/slab.h> 29#include <linux/slab.h>
30 30
31#include <linux/dmi.h>
31#include <linux/usb.h> 32#include <linux/usb.h>
32#include <linux/mm.h> 33#include <linux/mm.h>
33#include <linux/vmalloc.h> 34#include <linux/vmalloc.h>
@@ -38,12 +39,12 @@
38#include "stk-webcam.h" 39#include "stk-webcam.h"
39 40
40 41
41static bool hflip; 42static int hflip = -1;
42module_param(hflip, bool, 0444); 43module_param(hflip, int, 0444);
43MODULE_PARM_DESC(hflip, "Horizontal image flip (mirror). Defaults to 0"); 44MODULE_PARM_DESC(hflip, "Horizontal image flip (mirror). Defaults to 0");
44 45
45static bool vflip; 46static int vflip = -1;
46module_param(vflip, bool, 0444); 47module_param(vflip, int, 0444);
47MODULE_PARM_DESC(vflip, "Vertical image flip. Defaults to 0"); 48MODULE_PARM_DESC(vflip, "Vertical image flip. Defaults to 0");
48 49
49static int debug; 50static int debug;
@@ -62,6 +63,19 @@ static struct usb_device_id stkwebcam_table[] = {
62}; 63};
63MODULE_DEVICE_TABLE(usb, stkwebcam_table); 64MODULE_DEVICE_TABLE(usb, stkwebcam_table);
64 65
66/* The stk webcam laptop module is mounted upside down in some laptops :( */
67static const struct dmi_system_id stk_upside_down_dmi_table[] = {
68 {
69 .ident = "ASUS G1",
70 .matches = {
71 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
72 DMI_MATCH(DMI_PRODUCT_NAME, "G1")
73 }
74 },
75 {}
76};
77
78
65/* 79/*
66 * Basic stuff 80 * Basic stuff
67 */ 81 */
@@ -466,6 +480,7 @@ static int stk_setup_siobuf(struct stk_camera *dev, int index)
466 buf->dev = dev; 480 buf->dev = dev;
467 buf->v4lbuf.index = index; 481 buf->v4lbuf.index = index;
468 buf->v4lbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 482 buf->v4lbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
483 buf->v4lbuf.flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
469 buf->v4lbuf.field = V4L2_FIELD_NONE; 484 buf->v4lbuf.field = V4L2_FIELD_NONE;
470 buf->v4lbuf.memory = V4L2_MEMORY_MMAP; 485 buf->v4lbuf.memory = V4L2_MEMORY_MMAP;
471 buf->v4lbuf.m.offset = 2*index*buf->v4lbuf.length; 486 buf->v4lbuf.m.offset = 2*index*buf->v4lbuf.length;
@@ -816,10 +831,16 @@ static int stk_vidioc_g_ctrl(struct file *filp,
816 c->value = dev->vsettings.brightness; 831 c->value = dev->vsettings.brightness;
817 break; 832 break;
818 case V4L2_CID_HFLIP: 833 case V4L2_CID_HFLIP:
819 c->value = dev->vsettings.hflip; 834 if (dmi_check_system(stk_upside_down_dmi_table))
835 c->value = !dev->vsettings.hflip;
836 else
837 c->value = dev->vsettings.hflip;
820 break; 838 break;
821 case V4L2_CID_VFLIP: 839 case V4L2_CID_VFLIP:
822 c->value = dev->vsettings.vflip; 840 if (dmi_check_system(stk_upside_down_dmi_table))
841 c->value = !dev->vsettings.vflip;
842 else
843 c->value = dev->vsettings.vflip;
823 break; 844 break;
824 default: 845 default:
825 return -EINVAL; 846 return -EINVAL;
@@ -836,10 +857,16 @@ static int stk_vidioc_s_ctrl(struct file *filp,
836 dev->vsettings.brightness = c->value; 857 dev->vsettings.brightness = c->value;
837 return stk_sensor_set_brightness(dev, c->value >> 8); 858 return stk_sensor_set_brightness(dev, c->value >> 8);
838 case V4L2_CID_HFLIP: 859 case V4L2_CID_HFLIP:
839 dev->vsettings.hflip = c->value; 860 if (dmi_check_system(stk_upside_down_dmi_table))
861 dev->vsettings.hflip = !c->value;
862 else
863 dev->vsettings.hflip = c->value;
840 return 0; 864 return 0;
841 case V4L2_CID_VFLIP: 865 case V4L2_CID_VFLIP:
842 dev->vsettings.vflip = c->value; 866 if (dmi_check_system(stk_upside_down_dmi_table))
867 dev->vsettings.vflip = !c->value;
868 else
869 dev->vsettings.vflip = c->value;
843 return 0; 870 return 0;
844 default: 871 default:
845 return -EINVAL; 872 return -EINVAL;
@@ -1113,7 +1140,7 @@ static int stk_vidioc_dqbuf(struct file *filp,
1113 sbuf->v4lbuf.flags &= ~V4L2_BUF_FLAG_QUEUED; 1140 sbuf->v4lbuf.flags &= ~V4L2_BUF_FLAG_QUEUED;
1114 sbuf->v4lbuf.flags |= V4L2_BUF_FLAG_DONE; 1141 sbuf->v4lbuf.flags |= V4L2_BUF_FLAG_DONE;
1115 sbuf->v4lbuf.sequence = ++dev->sequence; 1142 sbuf->v4lbuf.sequence = ++dev->sequence;
1116 do_gettimeofday(&sbuf->v4lbuf.timestamp); 1143 v4l2_get_timestamp(&sbuf->v4lbuf.timestamp);
1117 1144
1118 *buf = sbuf->v4lbuf; 1145 *buf = sbuf->v4lbuf;
1119 return 0; 1146 return 0;
@@ -1275,8 +1302,18 @@ static int stk_camera_probe(struct usb_interface *interface,
1275 dev->interface = interface; 1302 dev->interface = interface;
1276 usb_get_intf(interface); 1303 usb_get_intf(interface);
1277 1304
1278 dev->vsettings.vflip = vflip; 1305 if (hflip != -1)
1279 dev->vsettings.hflip = hflip; 1306 dev->vsettings.hflip = hflip;
1307 else if (dmi_check_system(stk_upside_down_dmi_table))
1308 dev->vsettings.hflip = 1;
1309 else
1310 dev->vsettings.hflip = 0;
1311 if (vflip != -1)
1312 dev->vsettings.vflip = vflip;
1313 else if (dmi_check_system(stk_upside_down_dmi_table))
1314 dev->vsettings.vflip = 1;
1315 else
1316 dev->vsettings.vflip = 0;
1280 dev->n_sbufs = 0; 1317 dev->n_sbufs = 0;
1281 set_present(dev); 1318 set_present(dev);
1282 1319
diff --git a/drivers/media/usb/tlg2300/pd-video.c b/drivers/media/usb/tlg2300/pd-video.c
index 3082bfa9b2c5..21723378bb8f 100644
--- a/drivers/media/usb/tlg2300/pd-video.c
+++ b/drivers/media/usb/tlg2300/pd-video.c
@@ -212,7 +212,7 @@ static void submit_frame(struct front_face *front)
212 front->curr_frame = NULL; 212 front->curr_frame = NULL;
213 vb->state = VIDEOBUF_DONE; 213 vb->state = VIDEOBUF_DONE;
214 vb->field_count++; 214 vb->field_count++;
215 do_gettimeofday(&vb->ts); 215 v4l2_get_timestamp(&vb->ts);
216 216
217 wake_up(&vb->done); 217 wake_up(&vb->done);
218} 218}
diff --git a/drivers/media/usb/tm6000/tm6000-core.c b/drivers/media/usb/tm6000/tm6000-core.c
index 22cc0116deb6..7c32353c59db 100644
--- a/drivers/media/usb/tm6000/tm6000-core.c
+++ b/drivers/media/usb/tm6000/tm6000-core.c
@@ -40,10 +40,13 @@ int tm6000_read_write_usb(struct tm6000_core *dev, u8 req_type, u8 req,
40 u8 *data = NULL; 40 u8 *data = NULL;
41 int delay = 5000; 41 int delay = 5000;
42 42
43 mutex_lock(&dev->usb_lock); 43 if (len) {
44
45 if (len)
46 data = kzalloc(len, GFP_KERNEL); 44 data = kzalloc(len, GFP_KERNEL);
45 if (!data)
46 return -ENOMEM;
47 }
48
49 mutex_lock(&dev->usb_lock);
47 50
48 if (req_type & USB_DIR_IN) 51 if (req_type & USB_DIR_IN)
49 pipe = usb_rcvctrlpipe(dev->udev, 0); 52 pipe = usb_rcvctrlpipe(dev->udev, 0);
diff --git a/drivers/media/usb/tm6000/tm6000-dvb.c b/drivers/media/usb/tm6000/tm6000-dvb.c
index e1f3f66e1e63..9fc1e940a82b 100644
--- a/drivers/media/usb/tm6000/tm6000-dvb.c
+++ b/drivers/media/usb/tm6000/tm6000-dvb.c
@@ -360,8 +360,8 @@ dvb_dmx_err:
360 dvb_dmx_release(&dvb->demux); 360 dvb_dmx_release(&dvb->demux);
361frontend_err: 361frontend_err:
362 if (dvb->frontend) { 362 if (dvb->frontend) {
363 dvb_frontend_detach(dvb->frontend);
364 dvb_unregister_frontend(dvb->frontend); 363 dvb_unregister_frontend(dvb->frontend);
364 dvb_frontend_detach(dvb->frontend);
365 } 365 }
366adapter_err: 366adapter_err:
367 dvb_unregister_adapter(&dvb->adapter); 367 dvb_unregister_adapter(&dvb->adapter);
@@ -384,8 +384,8 @@ static void unregister_dvb(struct tm6000_core *dev)
384 384
385/* mutex_lock(&tm6000_driver.open_close_mutex); */ 385/* mutex_lock(&tm6000_driver.open_close_mutex); */
386 if (dvb->frontend) { 386 if (dvb->frontend) {
387 dvb_frontend_detach(dvb->frontend);
388 dvb_unregister_frontend(dvb->frontend); 387 dvb_unregister_frontend(dvb->frontend);
388 dvb_frontend_detach(dvb->frontend);
389 } 389 }
390 390
391 dvb_dmxdev_release(&dvb->dmxdev); 391 dvb_dmxdev_release(&dvb->dmxdev);
diff --git a/drivers/media/usb/tm6000/tm6000-video.c b/drivers/media/usb/tm6000/tm6000-video.c
index f656fd7a39a2..1a6857929c15 100644
--- a/drivers/media/usb/tm6000/tm6000-video.c
+++ b/drivers/media/usb/tm6000/tm6000-video.c
@@ -34,6 +34,7 @@
34#include <linux/usb.h> 34#include <linux/usb.h>
35#include <linux/videodev2.h> 35#include <linux/videodev2.h>
36#include <media/v4l2-ioctl.h> 36#include <media/v4l2-ioctl.h>
37#include <media/v4l2-event.h>
37#include <media/tuner.h> 38#include <media/tuner.h>
38#include <linux/interrupt.h> 39#include <linux/interrupt.h>
39#include <linux/kthread.h> 40#include <linux/kthread.h>
@@ -49,82 +50,20 @@
49#define TM6000_MIN_BUF 4 50#define TM6000_MIN_BUF 4
50#define TM6000_DEF_BUF 8 51#define TM6000_DEF_BUF 8
51 52
53#define TM6000_NUM_URB_BUF 8
54
52#define TM6000_MAX_ISO_PACKETS 46 /* Max number of ISO packets */ 55#define TM6000_MAX_ISO_PACKETS 46 /* Max number of ISO packets */
53 56
54/* Declare static vars that will be used as parameters */ 57/* Declare static vars that will be used as parameters */
55static unsigned int vid_limit = 16; /* Video memory limit, in Mb */ 58static unsigned int vid_limit = 16; /* Video memory limit, in Mb */
56static int video_nr = -1; /* /dev/videoN, -1 for autodetect */ 59static int video_nr = -1; /* /dev/videoN, -1 for autodetect */
57static int radio_nr = -1; /* /dev/radioN, -1 for autodetect */ 60static int radio_nr = -1; /* /dev/radioN, -1 for autodetect */
61static bool keep_urb; /* keep urb buffers allocated */
58 62
59/* Debug level */ 63/* Debug level */
60int tm6000_debug; 64int tm6000_debug;
61EXPORT_SYMBOL_GPL(tm6000_debug); 65EXPORT_SYMBOL_GPL(tm6000_debug);
62 66
63static const struct v4l2_queryctrl no_ctrl = {
64 .name = "42",
65 .flags = V4L2_CTRL_FLAG_DISABLED,
66};
67
68/* supported controls */
69static struct v4l2_queryctrl tm6000_qctrl[] = {
70 {
71 .id = V4L2_CID_BRIGHTNESS,
72 .type = V4L2_CTRL_TYPE_INTEGER,
73 .name = "Brightness",
74 .minimum = 0,
75 .maximum = 255,
76 .step = 1,
77 .default_value = 54,
78 .flags = 0,
79 }, {
80 .id = V4L2_CID_CONTRAST,
81 .type = V4L2_CTRL_TYPE_INTEGER,
82 .name = "Contrast",
83 .minimum = 0,
84 .maximum = 255,
85 .step = 0x1,
86 .default_value = 119,
87 .flags = 0,
88 }, {
89 .id = V4L2_CID_SATURATION,
90 .type = V4L2_CTRL_TYPE_INTEGER,
91 .name = "Saturation",
92 .minimum = 0,
93 .maximum = 255,
94 .step = 0x1,
95 .default_value = 112,
96 .flags = 0,
97 }, {
98 .id = V4L2_CID_HUE,
99 .type = V4L2_CTRL_TYPE_INTEGER,
100 .name = "Hue",
101 .minimum = -128,
102 .maximum = 127,
103 .step = 0x1,
104 .default_value = 0,
105 .flags = 0,
106 },
107 /* --- audio --- */
108 {
109 .id = V4L2_CID_AUDIO_MUTE,
110 .name = "Mute",
111 .minimum = 0,
112 .maximum = 1,
113 .type = V4L2_CTRL_TYPE_BOOLEAN,
114 }, {
115 .id = V4L2_CID_AUDIO_VOLUME,
116 .name = "Volume",
117 .minimum = -15,
118 .maximum = 15,
119 .step = 1,
120 .default_value = 0,
121 .type = V4L2_CTRL_TYPE_INTEGER,
122 }
123};
124
125static const unsigned int CTRLS = ARRAY_SIZE(tm6000_qctrl);
126static int qctl_regs[ARRAY_SIZE(tm6000_qctrl)];
127
128static struct tm6000_fmt format[] = { 67static struct tm6000_fmt format[] = {
129 { 68 {
130 .name = "4:2:2, packed, YVY2", 69 .name = "4:2:2, packed, YVY2",
@@ -141,16 +80,6 @@ static struct tm6000_fmt format[] = {
141 } 80 }
142}; 81};
143 82
144static const struct v4l2_queryctrl *ctrl_by_id(unsigned int id)
145{
146 unsigned int i;
147
148 for (i = 0; i < CTRLS; i++)
149 if (tm6000_qctrl[i].id == id)
150 return tm6000_qctrl+i;
151 return NULL;
152}
153
154/* ------------------------------------------------------------------ 83/* ------------------------------------------------------------------
155 * DMA and thread functions 84 * DMA and thread functions
156 * ------------------------------------------------------------------ 85 * ------------------------------------------------------------------
@@ -191,7 +120,7 @@ static inline void buffer_filled(struct tm6000_core *dev,
191 dprintk(dev, V4L2_DEBUG_ISOC, "[%p/%d] wakeup\n", buf, buf->vb.i); 120 dprintk(dev, V4L2_DEBUG_ISOC, "[%p/%d] wakeup\n", buf, buf->vb.i);
192 buf->vb.state = VIDEOBUF_DONE; 121 buf->vb.state = VIDEOBUF_DONE;
193 buf->vb.field_count++; 122 buf->vb.field_count++;
194 do_gettimeofday(&buf->vb.ts); 123 v4l2_get_timestamp(&buf->vb.ts);
195 124
196 list_del(&buf->vb.queue); 125 list_del(&buf->vb.queue);
197 wake_up(&buf->vb.done); 126 wake_up(&buf->vb.done);
@@ -538,6 +467,71 @@ static void tm6000_irq_callback(struct urb *urb)
538} 467}
539 468
540/* 469/*
470 * Allocate URB buffers
471 */
472static int tm6000_alloc_urb_buffers(struct tm6000_core *dev)
473{
474 int num_bufs = TM6000_NUM_URB_BUF;
475 int i;
476
477 if (dev->urb_buffer != NULL)
478 return 0;
479
480 dev->urb_buffer = kmalloc(sizeof(void *)*num_bufs, GFP_KERNEL);
481 if (!dev->urb_buffer) {
482 tm6000_err("cannot allocate memory for urb buffers\n");
483 return -ENOMEM;
484 }
485
486 dev->urb_dma = kmalloc(sizeof(dma_addr_t *)*num_bufs, GFP_KERNEL);
487 if (!dev->urb_dma) {
488 tm6000_err("cannot allocate memory for urb dma pointers\n");
489 return -ENOMEM;
490 }
491
492 for (i = 0; i < num_bufs; i++) {
493 dev->urb_buffer[i] = usb_alloc_coherent(
494 dev->udev, dev->urb_size,
495 GFP_KERNEL, &dev->urb_dma[i]);
496 if (!dev->urb_buffer[i]) {
497 tm6000_err("unable to allocate %i bytes for transfer buffer %i\n",
498 dev->urb_size, i);
499 return -ENOMEM;
500 }
501 memset(dev->urb_buffer[i], 0, dev->urb_size);
502 }
503
504 return 0;
505}
506
507/*
508 * Free URB buffers
509 */
510static int tm6000_free_urb_buffers(struct tm6000_core *dev)
511{
512 int i;
513
514 if (dev->urb_buffer == NULL)
515 return 0;
516
517 for (i = 0; i < TM6000_NUM_URB_BUF; i++) {
518 if (dev->urb_buffer[i]) {
519 usb_free_coherent(dev->udev,
520 dev->urb_size,
521 dev->urb_buffer[i],
522 dev->urb_dma[i]);
523 dev->urb_buffer[i] = NULL;
524 }
525 }
526 kfree(dev->urb_buffer);
527 kfree(dev->urb_dma);
528 dev->urb_buffer = NULL;
529 dev->urb_dma = NULL;
530
531 return 0;
532}
533
534/*
541 * Stop and Deallocate URBs 535 * Stop and Deallocate URBs
542 */ 536 */
543static void tm6000_uninit_isoc(struct tm6000_core *dev) 537static void tm6000_uninit_isoc(struct tm6000_core *dev)
@@ -551,18 +545,15 @@ static void tm6000_uninit_isoc(struct tm6000_core *dev)
551 if (urb) { 545 if (urb) {
552 usb_kill_urb(urb); 546 usb_kill_urb(urb);
553 usb_unlink_urb(urb); 547 usb_unlink_urb(urb);
554 if (dev->isoc_ctl.transfer_buffer[i]) {
555 usb_free_coherent(dev->udev,
556 urb->transfer_buffer_length,
557 dev->isoc_ctl.transfer_buffer[i],
558 urb->transfer_dma);
559 }
560 usb_free_urb(urb); 548 usb_free_urb(urb);
561 dev->isoc_ctl.urb[i] = NULL; 549 dev->isoc_ctl.urb[i] = NULL;
562 } 550 }
563 dev->isoc_ctl.transfer_buffer[i] = NULL; 551 dev->isoc_ctl.transfer_buffer[i] = NULL;
564 } 552 }
565 553
554 if (!keep_urb)
555 tm6000_free_urb_buffers(dev);
556
566 kfree(dev->isoc_ctl.urb); 557 kfree(dev->isoc_ctl.urb);
567 kfree(dev->isoc_ctl.transfer_buffer); 558 kfree(dev->isoc_ctl.transfer_buffer);
568 559
@@ -572,12 +563,13 @@ static void tm6000_uninit_isoc(struct tm6000_core *dev)
572} 563}
573 564
574/* 565/*
575 * Allocate URBs and start IRQ 566 * Assign URBs and start IRQ
576 */ 567 */
577static int tm6000_prepare_isoc(struct tm6000_core *dev) 568static int tm6000_prepare_isoc(struct tm6000_core *dev)
578{ 569{
579 struct tm6000_dmaqueue *dma_q = &dev->vidq; 570 struct tm6000_dmaqueue *dma_q = &dev->vidq;
580 int i, j, sb_size, pipe, size, max_packets, num_bufs = 8; 571 int i, j, sb_size, pipe, size, max_packets;
572 int num_bufs = TM6000_NUM_URB_BUF;
581 struct urb *urb; 573 struct urb *urb;
582 574
583 /* De-allocates all pending stuff */ 575 /* De-allocates all pending stuff */
@@ -605,6 +597,7 @@ static int tm6000_prepare_isoc(struct tm6000_core *dev)
605 597
606 max_packets = TM6000_MAX_ISO_PACKETS; 598 max_packets = TM6000_MAX_ISO_PACKETS;
607 sb_size = max_packets * size; 599 sb_size = max_packets * size;
600 dev->urb_size = sb_size;
608 601
609 dev->isoc_ctl.num_bufs = num_bufs; 602 dev->isoc_ctl.num_bufs = num_bufs;
610 603
@@ -627,6 +620,17 @@ static int tm6000_prepare_isoc(struct tm6000_core *dev)
627 max_packets, num_bufs, sb_size, 620 max_packets, num_bufs, sb_size,
628 dev->isoc_in.maxsize, size); 621 dev->isoc_in.maxsize, size);
629 622
623
624 if (!dev->urb_buffer && tm6000_alloc_urb_buffers(dev) < 0) {
625 tm6000_err("cannot allocate memory for urb buffers\n");
626
627 /* call free, as some buffers might have been allocated */
628 tm6000_free_urb_buffers(dev);
629 kfree(dev->isoc_ctl.urb);
630 kfree(dev->isoc_ctl.transfer_buffer);
631 return -ENOMEM;
632 }
633
630 /* allocate urbs and transfer buffers */ 634 /* allocate urbs and transfer buffers */
631 for (i = 0; i < dev->isoc_ctl.num_bufs; i++) { 635 for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
632 urb = usb_alloc_urb(max_packets, GFP_KERNEL); 636 urb = usb_alloc_urb(max_packets, GFP_KERNEL);
@@ -638,17 +642,8 @@ static int tm6000_prepare_isoc(struct tm6000_core *dev)
638 } 642 }
639 dev->isoc_ctl.urb[i] = urb; 643 dev->isoc_ctl.urb[i] = urb;
640 644
641 dev->isoc_ctl.transfer_buffer[i] = usb_alloc_coherent(dev->udev, 645 urb->transfer_dma = dev->urb_dma[i];
642 sb_size, GFP_KERNEL, &urb->transfer_dma); 646 dev->isoc_ctl.transfer_buffer[i] = dev->urb_buffer[i];
643 if (!dev->isoc_ctl.transfer_buffer[i]) {
644 tm6000_err("unable to allocate %i bytes for transfer"
645 " buffer %i%s\n",
646 sb_size, i,
647 in_interrupt() ? " while in int" : "");
648 tm6000_uninit_isoc(dev);
649 return -ENOMEM;
650 }
651 memset(dev->isoc_ctl.transfer_buffer[i], 0, sb_size);
652 647
653 usb_fill_bulk_urb(urb, dev->udev, pipe, 648 usb_fill_bulk_urb(urb, dev->udev, pipe,
654 dev->isoc_ctl.transfer_buffer[i], sb_size, 649 dev->isoc_ctl.transfer_buffer[i], sb_size,
@@ -879,16 +874,21 @@ static int vidioc_querycap(struct file *file, void *priv,
879 struct v4l2_capability *cap) 874 struct v4l2_capability *cap)
880{ 875{
881 struct tm6000_core *dev = ((struct tm6000_fh *)priv)->dev; 876 struct tm6000_core *dev = ((struct tm6000_fh *)priv)->dev;
877 struct video_device *vdev = video_devdata(file);
882 878
883 strlcpy(cap->driver, "tm6000", sizeof(cap->driver)); 879 strlcpy(cap->driver, "tm6000", sizeof(cap->driver));
884 strlcpy(cap->card, "Trident TVMaster TM5600/6000/6010", sizeof(cap->card)); 880 strlcpy(cap->card, "Trident TVMaster TM5600/6000/6010", sizeof(cap->card));
885 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | 881 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info));
886 V4L2_CAP_STREAMING |
887 V4L2_CAP_AUDIO |
888 V4L2_CAP_READWRITE;
889
890 if (dev->tuner_type != TUNER_ABSENT) 882 if (dev->tuner_type != TUNER_ABSENT)
891 cap->capabilities |= V4L2_CAP_TUNER; 883 cap->device_caps |= V4L2_CAP_TUNER;
884 if (vdev->vfl_type == VFL_TYPE_GRABBER)
885 cap->device_caps |= V4L2_CAP_VIDEO_CAPTURE |
886 V4L2_CAP_STREAMING |
887 V4L2_CAP_READWRITE;
888 else
889 cap->device_caps |= V4L2_CAP_RADIO;
890 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS |
891 V4L2_CAP_RADIO | V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE;
892 892
893 return 0; 893 return 0;
894} 894}
@@ -896,7 +896,7 @@ static int vidioc_querycap(struct file *file, void *priv,
896static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv, 896static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
897 struct v4l2_fmtdesc *f) 897 struct v4l2_fmtdesc *f)
898{ 898{
899 if (unlikely(f->index >= ARRAY_SIZE(format))) 899 if (f->index >= ARRAY_SIZE(format))
900 return -EINVAL; 900 return -EINVAL;
901 901
902 strlcpy(f->description, format[f->index].name, sizeof(f->description)); 902 strlcpy(f->description, format[f->index].name, sizeof(f->description));
@@ -913,10 +913,12 @@ static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
913 f->fmt.pix.height = fh->height; 913 f->fmt.pix.height = fh->height;
914 f->fmt.pix.field = fh->vb_vidq.field; 914 f->fmt.pix.field = fh->vb_vidq.field;
915 f->fmt.pix.pixelformat = fh->fmt->fourcc; 915 f->fmt.pix.pixelformat = fh->fmt->fourcc;
916 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
916 f->fmt.pix.bytesperline = 917 f->fmt.pix.bytesperline =
917 (f->fmt.pix.width * fh->fmt->depth) >> 3; 918 (f->fmt.pix.width * fh->fmt->depth) >> 3;
918 f->fmt.pix.sizeimage = 919 f->fmt.pix.sizeimage =
919 f->fmt.pix.height * f->fmt.pix.bytesperline; 920 f->fmt.pix.height * f->fmt.pix.bytesperline;
921 f->fmt.pix.priv = 0;
920 922
921 return 0; 923 return 0;
922} 924}
@@ -947,12 +949,7 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
947 949
948 field = f->fmt.pix.field; 950 field = f->fmt.pix.field;
949 951
950 if (field == V4L2_FIELD_ANY) 952 field = V4L2_FIELD_INTERLACED;
951 field = V4L2_FIELD_SEQ_TB;
952 else if (V4L2_FIELD_INTERLACED != field) {
953 dprintk(dev, V4L2_DEBUG_IOCTL_ARG, "Field type invalid.\n");
954 return -EINVAL;
955 }
956 953
957 tm6000_get_std_res(dev); 954 tm6000_get_std_res(dev);
958 955
@@ -962,11 +959,13 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
962 f->fmt.pix.width &= ~0x01; 959 f->fmt.pix.width &= ~0x01;
963 960
964 f->fmt.pix.field = field; 961 f->fmt.pix.field = field;
962 f->fmt.pix.priv = 0;
965 963
966 f->fmt.pix.bytesperline = 964 f->fmt.pix.bytesperline =
967 (f->fmt.pix.width * fmt->depth) >> 3; 965 (f->fmt.pix.width * fmt->depth) >> 3;
968 f->fmt.pix.sizeimage = 966 f->fmt.pix.sizeimage =
969 f->fmt.pix.height * f->fmt.pix.bytesperline; 967 f->fmt.pix.height * f->fmt.pix.bytesperline;
968 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
970 969
971 return 0; 970 return 0;
972} 971}
@@ -1141,79 +1140,40 @@ static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
1141} 1140}
1142 1141
1143/* --- controls ---------------------------------------------- */ 1142/* --- controls ---------------------------------------------- */
1144static int vidioc_queryctrl(struct file *file, void *priv,
1145 struct v4l2_queryctrl *qc)
1146{
1147 int i;
1148
1149 for (i = 0; i < ARRAY_SIZE(tm6000_qctrl); i++)
1150 if (qc->id && qc->id == tm6000_qctrl[i].id) {
1151 memcpy(qc, &(tm6000_qctrl[i]),
1152 sizeof(*qc));
1153 return 0;
1154 }
1155 1143
1156 return -EINVAL; 1144static int tm6000_s_ctrl(struct v4l2_ctrl *ctrl)
1157}
1158
1159static int vidioc_g_ctrl(struct file *file, void *priv,
1160 struct v4l2_control *ctrl)
1161{ 1145{
1162 struct tm6000_fh *fh = priv; 1146 struct tm6000_core *dev = container_of(ctrl->handler, struct tm6000_core, ctrl_handler);
1163 struct tm6000_core *dev = fh->dev; 1147 u8 val = ctrl->val;
1164 int val;
1165 1148
1166 /* FIXME: Probably, those won't work! Maybe we need shadow regs */
1167 switch (ctrl->id) { 1149 switch (ctrl->id) {
1168 case V4L2_CID_CONTRAST: 1150 case V4L2_CID_CONTRAST:
1169 val = tm6000_get_reg(dev, TM6010_REQ07_R08_LUMA_CONTRAST_ADJ, 0); 1151 tm6000_set_reg(dev, TM6010_REQ07_R08_LUMA_CONTRAST_ADJ, val);
1170 break; 1152 return 0;
1171 case V4L2_CID_BRIGHTNESS: 1153 case V4L2_CID_BRIGHTNESS:
1172 val = tm6000_get_reg(dev, TM6010_REQ07_R09_LUMA_BRIGHTNESS_ADJ, 0); 1154 tm6000_set_reg(dev, TM6010_REQ07_R09_LUMA_BRIGHTNESS_ADJ, val);
1173 return 0; 1155 return 0;
1174 case V4L2_CID_SATURATION: 1156 case V4L2_CID_SATURATION:
1175 val = tm6000_get_reg(dev, TM6010_REQ07_R0A_CHROMA_SATURATION_ADJ, 0); 1157 tm6000_set_reg(dev, TM6010_REQ07_R0A_CHROMA_SATURATION_ADJ, val);
1176 return 0; 1158 return 0;
1177 case V4L2_CID_HUE: 1159 case V4L2_CID_HUE:
1178 val = tm6000_get_reg(dev, TM6010_REQ07_R0B_CHROMA_HUE_PHASE_ADJ, 0); 1160 tm6000_set_reg(dev, TM6010_REQ07_R0B_CHROMA_HUE_PHASE_ADJ, val);
1179 return 0;
1180 case V4L2_CID_AUDIO_MUTE:
1181 val = dev->ctl_mute;
1182 return 0;
1183 case V4L2_CID_AUDIO_VOLUME:
1184 val = dev->ctl_volume;
1185 return 0; 1161 return 0;
1186 default:
1187 return -EINVAL;
1188 } 1162 }
1163 return -EINVAL;
1164}
1189 1165
1190 if (val < 0) 1166static const struct v4l2_ctrl_ops tm6000_ctrl_ops = {
1191 return val; 1167 .s_ctrl = tm6000_s_ctrl,
1192 1168};
1193 ctrl->value = val;
1194 1169
1195 return 0; 1170static int tm6000_radio_s_ctrl(struct v4l2_ctrl *ctrl)
1196}
1197static int vidioc_s_ctrl(struct file *file, void *priv,
1198 struct v4l2_control *ctrl)
1199{ 1171{
1200 struct tm6000_fh *fh = priv; 1172 struct tm6000_core *dev = container_of(ctrl->handler,
1201 struct tm6000_core *dev = fh->dev; 1173 struct tm6000_core, radio_ctrl_handler);
1202 u8 val = ctrl->value; 1174 u8 val = ctrl->val;
1203 1175
1204 switch (ctrl->id) { 1176 switch (ctrl->id) {
1205 case V4L2_CID_CONTRAST:
1206 tm6000_set_reg(dev, TM6010_REQ07_R08_LUMA_CONTRAST_ADJ, val);
1207 return 0;
1208 case V4L2_CID_BRIGHTNESS:
1209 tm6000_set_reg(dev, TM6010_REQ07_R09_LUMA_BRIGHTNESS_ADJ, val);
1210 return 0;
1211 case V4L2_CID_SATURATION:
1212 tm6000_set_reg(dev, TM6010_REQ07_R0A_CHROMA_SATURATION_ADJ, val);
1213 return 0;
1214 case V4L2_CID_HUE:
1215 tm6000_set_reg(dev, TM6010_REQ07_R0B_CHROMA_HUE_PHASE_ADJ, val);
1216 return 0;
1217 case V4L2_CID_AUDIO_MUTE: 1177 case V4L2_CID_AUDIO_MUTE:
1218 dev->ctl_mute = val; 1178 dev->ctl_mute = val;
1219 tm6000_tvaudio_set_mute(dev, val); 1179 tm6000_tvaudio_set_mute(dev, val);
@@ -1226,20 +1186,24 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
1226 return -EINVAL; 1186 return -EINVAL;
1227} 1187}
1228 1188
1189static const struct v4l2_ctrl_ops tm6000_radio_ctrl_ops = {
1190 .s_ctrl = tm6000_radio_s_ctrl,
1191};
1192
1229static int vidioc_g_tuner(struct file *file, void *priv, 1193static int vidioc_g_tuner(struct file *file, void *priv,
1230 struct v4l2_tuner *t) 1194 struct v4l2_tuner *t)
1231{ 1195{
1232 struct tm6000_fh *fh = priv; 1196 struct tm6000_fh *fh = priv;
1233 struct tm6000_core *dev = fh->dev; 1197 struct tm6000_core *dev = fh->dev;
1234 1198
1235 if (unlikely(UNSET == dev->tuner_type)) 1199 if (UNSET == dev->tuner_type)
1236 return -EINVAL; 1200 return -ENOTTY;
1237 if (0 != t->index) 1201 if (0 != t->index)
1238 return -EINVAL; 1202 return -EINVAL;
1239 1203
1240 strcpy(t->name, "Television"); 1204 strcpy(t->name, "Television");
1241 t->type = V4L2_TUNER_ANALOG_TV; 1205 t->type = V4L2_TUNER_ANALOG_TV;
1242 t->capability = V4L2_TUNER_CAP_NORM; 1206 t->capability = V4L2_TUNER_CAP_NORM | V4L2_TUNER_CAP_STEREO;
1243 t->rangehigh = 0xffffffffUL; 1207 t->rangehigh = 0xffffffffUL;
1244 t->rxsubchans = V4L2_TUNER_SUB_STEREO; 1208 t->rxsubchans = V4L2_TUNER_SUB_STEREO;
1245 1209
@@ -1257,11 +1221,14 @@ static int vidioc_s_tuner(struct file *file, void *priv,
1257 struct tm6000_core *dev = fh->dev; 1221 struct tm6000_core *dev = fh->dev;
1258 1222
1259 if (UNSET == dev->tuner_type) 1223 if (UNSET == dev->tuner_type)
1260 return -EINVAL; 1224 return -ENOTTY;
1261 if (0 != t->index) 1225 if (0 != t->index)
1262 return -EINVAL; 1226 return -EINVAL;
1263 1227
1264 dev->amode = t->audmode; 1228 if (t->audmode > V4L2_TUNER_MODE_STEREO)
1229 dev->amode = V4L2_TUNER_MODE_STEREO;
1230 else
1231 dev->amode = t->audmode;
1265 dprintk(dev, 3, "audio mode: %x\n", t->audmode); 1232 dprintk(dev, 3, "audio mode: %x\n", t->audmode);
1266 1233
1267 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t); 1234 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t);
@@ -1275,10 +1242,11 @@ static int vidioc_g_frequency(struct file *file, void *priv,
1275 struct tm6000_fh *fh = priv; 1242 struct tm6000_fh *fh = priv;
1276 struct tm6000_core *dev = fh->dev; 1243 struct tm6000_core *dev = fh->dev;
1277 1244
1278 if (unlikely(UNSET == dev->tuner_type)) 1245 if (UNSET == dev->tuner_type)
1246 return -ENOTTY;
1247 if (f->tuner)
1279 return -EINVAL; 1248 return -EINVAL;
1280 1249
1281 f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1282 f->frequency = dev->freq; 1250 f->frequency = dev->freq;
1283 1251
1284 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_frequency, f); 1252 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_frequency, f);
@@ -1292,13 +1260,9 @@ static int vidioc_s_frequency(struct file *file, void *priv,
1292 struct tm6000_fh *fh = priv; 1260 struct tm6000_fh *fh = priv;
1293 struct tm6000_core *dev = fh->dev; 1261 struct tm6000_core *dev = fh->dev;
1294 1262
1295 if (unlikely(UNSET == dev->tuner_type)) 1263 if (UNSET == dev->tuner_type)
1296 return -EINVAL; 1264 return -ENOTTY;
1297 if (unlikely(f->tuner != 0)) 1265 if (f->tuner != 0)
1298 return -EINVAL;
1299 if (0 == fh->radio && V4L2_TUNER_ANALOG_TV != f->type)
1300 return -EINVAL;
1301 if (1 == fh->radio && V4L2_TUNER_RADIO != f->type)
1302 return -EINVAL; 1266 return -EINVAL;
1303 1267
1304 dev->freq = f->frequency; 1268 dev->freq = f->frequency;
@@ -1307,27 +1271,6 @@ static int vidioc_s_frequency(struct file *file, void *priv,
1307 return 0; 1271 return 0;
1308} 1272}
1309 1273
1310static int radio_querycap(struct file *file, void *priv,
1311 struct v4l2_capability *cap)
1312{
1313 struct tm6000_fh *fh = file->private_data;
1314 struct tm6000_core *dev = fh->dev;
1315
1316 strcpy(cap->driver, "tm6000");
1317 strlcpy(cap->card, dev->name, sizeof(dev->name));
1318 sprintf(cap->bus_info, "USB%04x:%04x",
1319 le16_to_cpu(dev->udev->descriptor.idVendor),
1320 le16_to_cpu(dev->udev->descriptor.idProduct));
1321 cap->version = dev->dev_type;
1322 cap->capabilities = V4L2_CAP_TUNER |
1323 V4L2_CAP_AUDIO |
1324 V4L2_CAP_RADIO |
1325 V4L2_CAP_READWRITE |
1326 V4L2_CAP_STREAMING;
1327
1328 return 0;
1329}
1330
1331static int radio_g_tuner(struct file *file, void *priv, 1274static int radio_g_tuner(struct file *file, void *priv,
1332 struct v4l2_tuner *t) 1275 struct v4l2_tuner *t)
1333{ 1276{
@@ -1340,7 +1283,9 @@ static int radio_g_tuner(struct file *file, void *priv,
1340 memset(t, 0, sizeof(*t)); 1283 memset(t, 0, sizeof(*t));
1341 strcpy(t->name, "Radio"); 1284 strcpy(t->name, "Radio");
1342 t->type = V4L2_TUNER_RADIO; 1285 t->type = V4L2_TUNER_RADIO;
1286 t->capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO;
1343 t->rxsubchans = V4L2_TUNER_SUB_STEREO; 1287 t->rxsubchans = V4L2_TUNER_SUB_STEREO;
1288 t->audmode = V4L2_TUNER_MODE_STEREO;
1344 1289
1345 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t); 1290 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t);
1346 1291
@@ -1355,95 +1300,14 @@ static int radio_s_tuner(struct file *file, void *priv,
1355 1300
1356 if (0 != t->index) 1301 if (0 != t->index)
1357 return -EINVAL; 1302 return -EINVAL;
1303 if (t->audmode > V4L2_TUNER_MODE_STEREO)
1304 t->audmode = V4L2_TUNER_MODE_STEREO;
1358 1305
1359 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t); 1306 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t);
1360 1307
1361 return 0; 1308 return 0;
1362} 1309}
1363 1310
1364static int radio_enum_input(struct file *file, void *priv,
1365 struct v4l2_input *i)
1366{
1367 struct tm6000_fh *fh = priv;
1368 struct tm6000_core *dev = fh->dev;
1369
1370 if (i->index != 0)
1371 return -EINVAL;
1372
1373 if (!dev->rinput.type)
1374 return -EINVAL;
1375
1376 strcpy(i->name, "Radio");
1377 i->type = V4L2_INPUT_TYPE_TUNER;
1378
1379 return 0;
1380}
1381
1382static int radio_g_input(struct file *filp, void *priv, unsigned int *i)
1383{
1384 struct tm6000_fh *fh = priv;
1385 struct tm6000_core *dev = fh->dev;
1386
1387 if (dev->input != 5)
1388 return -EINVAL;
1389
1390 *i = dev->input - 5;
1391
1392 return 0;
1393}
1394
1395static int radio_g_audio(struct file *file, void *priv,
1396 struct v4l2_audio *a)
1397{
1398 memset(a, 0, sizeof(*a));
1399 strcpy(a->name, "Radio");
1400 return 0;
1401}
1402
1403static int radio_s_audio(struct file *file, void *priv,
1404 const struct v4l2_audio *a)
1405{
1406 return 0;
1407}
1408
1409static int radio_s_input(struct file *filp, void *priv, unsigned int i)
1410{
1411 struct tm6000_fh *fh = priv;
1412 struct tm6000_core *dev = fh->dev;
1413
1414 if (i)
1415 return -EINVAL;
1416
1417 if (!dev->rinput.type)
1418 return -EINVAL;
1419
1420 dev->input = i + 5;
1421
1422 return 0;
1423}
1424
1425static int radio_s_std(struct file *file, void *fh, v4l2_std_id *norm)
1426{
1427 return 0;
1428}
1429
1430static int radio_queryctrl(struct file *file, void *priv,
1431 struct v4l2_queryctrl *c)
1432{
1433 const struct v4l2_queryctrl *ctrl;
1434
1435 if (c->id < V4L2_CID_BASE ||
1436 c->id >= V4L2_CID_LASTP1)
1437 return -EINVAL;
1438 if (c->id == V4L2_CID_AUDIO_MUTE) {
1439 ctrl = ctrl_by_id(c->id);
1440 *c = *ctrl;
1441 } else
1442 *c = no_ctrl;
1443
1444 return 0;
1445}
1446
1447/* ------------------------------------------------------------------ 1311/* ------------------------------------------------------------------
1448 File operations for the device 1312 File operations for the device
1449 ------------------------------------------------------------------*/ 1313 ------------------------------------------------------------------*/
@@ -1454,7 +1318,7 @@ static int __tm6000_open(struct file *file)
1454 struct tm6000_core *dev = video_drvdata(file); 1318 struct tm6000_core *dev = video_drvdata(file);
1455 struct tm6000_fh *fh; 1319 struct tm6000_fh *fh;
1456 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 1320 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1457 int i, rc; 1321 int rc;
1458 int radio = 0; 1322 int radio = 0;
1459 1323
1460 dprintk(dev, V4L2_DEBUG_OPEN, "tm6000: open called (dev=%s)\n", 1324 dprintk(dev, V4L2_DEBUG_OPEN, "tm6000: open called (dev=%s)\n",
@@ -1486,6 +1350,7 @@ static int __tm6000_open(struct file *file)
1486 return -ENOMEM; 1350 return -ENOMEM;
1487 } 1351 }
1488 1352
1353 v4l2_fh_init(&fh->fh, vdev);
1489 file->private_data = fh; 1354 file->private_data = fh;
1490 fh->dev = dev; 1355 fh->dev = dev;
1491 fh->radio = radio; 1356 fh->radio = radio;
@@ -1514,13 +1379,7 @@ static int __tm6000_open(struct file *file)
1514 if (rc < 0) 1379 if (rc < 0)
1515 return rc; 1380 return rc;
1516 1381
1517 if (dev->mode != TM6000_MODE_ANALOG) { 1382 dev->mode = TM6000_MODE_ANALOG;
1518 /* Put all controls at a sane state */
1519 for (i = 0; i < ARRAY_SIZE(tm6000_qctrl); i++)
1520 qctl_regs[i] = tm6000_qctrl[i].default_value;
1521
1522 dev->mode = TM6000_MODE_ANALOG;
1523 }
1524 1383
1525 if (!fh->radio) { 1384 if (!fh->radio) {
1526 videobuf_queue_vmalloc_init(&fh->vb_vidq, &tm6000_video_qops, 1385 videobuf_queue_vmalloc_init(&fh->vb_vidq, &tm6000_video_qops,
@@ -1530,12 +1389,12 @@ static int __tm6000_open(struct file *file)
1530 sizeof(struct tm6000_buffer), fh, &dev->lock); 1389 sizeof(struct tm6000_buffer), fh, &dev->lock);
1531 } else { 1390 } else {
1532 dprintk(dev, V4L2_DEBUG_OPEN, "video_open: setting radio device\n"); 1391 dprintk(dev, V4L2_DEBUG_OPEN, "video_open: setting radio device\n");
1533 dev->input = 5;
1534 tm6000_set_audio_rinput(dev); 1392 tm6000_set_audio_rinput(dev);
1535 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_radio); 1393 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_radio);
1536 tm6000_prepare_isoc(dev); 1394 tm6000_prepare_isoc(dev);
1537 tm6000_start_thread(dev); 1395 tm6000_start_thread(dev);
1538 } 1396 }
1397 v4l2_fh_add(&fh->fh);
1539 1398
1540 return 0; 1399 return 0;
1541} 1400}
@@ -1576,29 +1435,35 @@ tm6000_read(struct file *file, char __user *data, size_t count, loff_t *pos)
1576static unsigned int 1435static unsigned int
1577__tm6000_poll(struct file *file, struct poll_table_struct *wait) 1436__tm6000_poll(struct file *file, struct poll_table_struct *wait)
1578{ 1437{
1438 unsigned long req_events = poll_requested_events(wait);
1579 struct tm6000_fh *fh = file->private_data; 1439 struct tm6000_fh *fh = file->private_data;
1580 struct tm6000_buffer *buf; 1440 struct tm6000_buffer *buf;
1441 int res = 0;
1581 1442
1443 if (v4l2_event_pending(&fh->fh))
1444 res = POLLPRI;
1445 else if (req_events & POLLPRI)
1446 poll_wait(file, &fh->fh.wait, wait);
1582 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type) 1447 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type)
1583 return POLLERR; 1448 return res | POLLERR;
1584 1449
1585 if (!!is_res_streaming(fh->dev, fh)) 1450 if (!!is_res_streaming(fh->dev, fh))
1586 return POLLERR; 1451 return res | POLLERR;
1587 1452
1588 if (!is_res_read(fh->dev, fh)) { 1453 if (!is_res_read(fh->dev, fh)) {
1589 /* streaming capture */ 1454 /* streaming capture */
1590 if (list_empty(&fh->vb_vidq.stream)) 1455 if (list_empty(&fh->vb_vidq.stream))
1591 return POLLERR; 1456 return res | POLLERR;
1592 buf = list_entry(fh->vb_vidq.stream.next, struct tm6000_buffer, vb.stream); 1457 buf = list_entry(fh->vb_vidq.stream.next, struct tm6000_buffer, vb.stream);
1593 } else { 1458 poll_wait(file, &buf->vb.done, wait);
1459 if (buf->vb.state == VIDEOBUF_DONE ||
1460 buf->vb.state == VIDEOBUF_ERROR)
1461 return res | POLLIN | POLLRDNORM;
1462 } else if (req_events & (POLLIN | POLLRDNORM)) {
1594 /* read() capture */ 1463 /* read() capture */
1595 return videobuf_poll_stream(file, &fh->vb_vidq, wait); 1464 return res | videobuf_poll_stream(file, &fh->vb_vidq, wait);
1596 } 1465 }
1597 poll_wait(file, &buf->vb.done, wait); 1466 return res;
1598 if (buf->vb.state == VIDEOBUF_DONE ||
1599 buf->vb.state == VIDEOBUF_ERROR)
1600 return POLLIN | POLLRDNORM;
1601 return 0;
1602} 1467}
1603 1468
1604static unsigned int tm6000_poll(struct file *file, struct poll_table_struct *wait) 1469static unsigned int tm6000_poll(struct file *file, struct poll_table_struct *wait)
@@ -1648,7 +1513,8 @@ static int tm6000_release(struct file *file)
1648 if (!fh->radio) 1513 if (!fh->radio)
1649 videobuf_mmap_free(&fh->vb_vidq); 1514 videobuf_mmap_free(&fh->vb_vidq);
1650 } 1515 }
1651 1516 v4l2_fh_del(&fh->fh);
1517 v4l2_fh_exit(&fh->fh);
1652 kfree(fh); 1518 kfree(fh);
1653 mutex_unlock(&dev->lock); 1519 mutex_unlock(&dev->lock);
1654 1520
@@ -1688,9 +1554,6 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
1688 .vidioc_enum_input = vidioc_enum_input, 1554 .vidioc_enum_input = vidioc_enum_input,
1689 .vidioc_g_input = vidioc_g_input, 1555 .vidioc_g_input = vidioc_g_input,
1690 .vidioc_s_input = vidioc_s_input, 1556 .vidioc_s_input = vidioc_s_input,
1691 .vidioc_queryctrl = vidioc_queryctrl,
1692 .vidioc_g_ctrl = vidioc_g_ctrl,
1693 .vidioc_s_ctrl = vidioc_s_ctrl,
1694 .vidioc_g_tuner = vidioc_g_tuner, 1557 .vidioc_g_tuner = vidioc_g_tuner,
1695 .vidioc_s_tuner = vidioc_s_tuner, 1558 .vidioc_s_tuner = vidioc_s_tuner,
1696 .vidioc_g_frequency = vidioc_g_frequency, 1559 .vidioc_g_frequency = vidioc_g_frequency,
@@ -1701,6 +1564,8 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
1701 .vidioc_querybuf = vidioc_querybuf, 1564 .vidioc_querybuf = vidioc_querybuf,
1702 .vidioc_qbuf = vidioc_qbuf, 1565 .vidioc_qbuf = vidioc_qbuf,
1703 .vidioc_dqbuf = vidioc_dqbuf, 1566 .vidioc_dqbuf = vidioc_dqbuf,
1567 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1568 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1704}; 1569};
1705 1570
1706static struct video_device tm6000_template = { 1571static struct video_device tm6000_template = {
@@ -1715,25 +1580,19 @@ static struct video_device tm6000_template = {
1715static const struct v4l2_file_operations radio_fops = { 1580static const struct v4l2_file_operations radio_fops = {
1716 .owner = THIS_MODULE, 1581 .owner = THIS_MODULE,
1717 .open = tm6000_open, 1582 .open = tm6000_open,
1583 .poll = v4l2_ctrl_poll,
1718 .release = tm6000_release, 1584 .release = tm6000_release,
1719 .unlocked_ioctl = video_ioctl2, 1585 .unlocked_ioctl = video_ioctl2,
1720}; 1586};
1721 1587
1722static const struct v4l2_ioctl_ops radio_ioctl_ops = { 1588static const struct v4l2_ioctl_ops radio_ioctl_ops = {
1723 .vidioc_querycap = radio_querycap, 1589 .vidioc_querycap = vidioc_querycap,
1724 .vidioc_g_tuner = radio_g_tuner, 1590 .vidioc_g_tuner = radio_g_tuner,
1725 .vidioc_enum_input = radio_enum_input,
1726 .vidioc_g_audio = radio_g_audio,
1727 .vidioc_s_tuner = radio_s_tuner, 1591 .vidioc_s_tuner = radio_s_tuner,
1728 .vidioc_s_audio = radio_s_audio,
1729 .vidioc_s_input = radio_s_input,
1730 .vidioc_s_std = radio_s_std,
1731 .vidioc_queryctrl = radio_queryctrl,
1732 .vidioc_g_input = radio_g_input,
1733 .vidioc_g_ctrl = vidioc_g_ctrl,
1734 .vidioc_s_ctrl = vidioc_s_ctrl,
1735 .vidioc_g_frequency = vidioc_g_frequency, 1592 .vidioc_g_frequency = vidioc_g_frequency,
1736 .vidioc_s_frequency = vidioc_s_frequency, 1593 .vidioc_s_frequency = vidioc_s_frequency,
1594 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1595 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1737}; 1596};
1738 1597
1739static struct video_device tm6000_radio_template = { 1598static struct video_device tm6000_radio_template = {
@@ -1762,6 +1621,7 @@ static struct video_device *vdev_init(struct tm6000_core *dev,
1762 vfd->release = video_device_release; 1621 vfd->release = video_device_release;
1763 vfd->debug = tm6000_debug; 1622 vfd->debug = tm6000_debug;
1764 vfd->lock = &dev->lock; 1623 vfd->lock = &dev->lock;
1624 set_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
1765 1625
1766 snprintf(vfd->name, sizeof(vfd->name), "%s %s", dev->name, type_name); 1626 snprintf(vfd->name, sizeof(vfd->name), "%s %s", dev->name, type_name);
1767 1627
@@ -1771,15 +1631,41 @@ static struct video_device *vdev_init(struct tm6000_core *dev,
1771 1631
1772int tm6000_v4l2_register(struct tm6000_core *dev) 1632int tm6000_v4l2_register(struct tm6000_core *dev)
1773{ 1633{
1774 int ret = -1; 1634 int ret = 0;
1635
1636 v4l2_ctrl_handler_init(&dev->ctrl_handler, 6);
1637 v4l2_ctrl_handler_init(&dev->radio_ctrl_handler, 2);
1638 v4l2_ctrl_new_std(&dev->radio_ctrl_handler, &tm6000_radio_ctrl_ops,
1639 V4L2_CID_AUDIO_MUTE, 0, 1, 1, 0);
1640 v4l2_ctrl_new_std(&dev->radio_ctrl_handler, &tm6000_radio_ctrl_ops,
1641 V4L2_CID_AUDIO_VOLUME, -15, 15, 1, 0);
1642 v4l2_ctrl_new_std(&dev->ctrl_handler, &tm6000_ctrl_ops,
1643 V4L2_CID_BRIGHTNESS, 0, 255, 1, 54);
1644 v4l2_ctrl_new_std(&dev->ctrl_handler, &tm6000_ctrl_ops,
1645 V4L2_CID_CONTRAST, 0, 255, 1, 119);
1646 v4l2_ctrl_new_std(&dev->ctrl_handler, &tm6000_ctrl_ops,
1647 V4L2_CID_SATURATION, 0, 255, 1, 112);
1648 v4l2_ctrl_new_std(&dev->ctrl_handler, &tm6000_ctrl_ops,
1649 V4L2_CID_HUE, -128, 127, 1, 0);
1650 v4l2_ctrl_add_handler(&dev->ctrl_handler,
1651 &dev->radio_ctrl_handler, NULL);
1652
1653 if (dev->radio_ctrl_handler.error)
1654 ret = dev->radio_ctrl_handler.error;
1655 if (!ret && dev->ctrl_handler.error)
1656 ret = dev->ctrl_handler.error;
1657 if (ret)
1658 goto free_ctrl;
1775 1659
1776 dev->vfd = vdev_init(dev, &tm6000_template, "video"); 1660 dev->vfd = vdev_init(dev, &tm6000_template, "video");
1777 1661
1778 if (!dev->vfd) { 1662 if (!dev->vfd) {
1779 printk(KERN_INFO "%s: can't register video device\n", 1663 printk(KERN_INFO "%s: can't register video device\n",
1780 dev->name); 1664 dev->name);
1781 return -ENOMEM; 1665 ret = -ENOMEM;
1666 goto free_ctrl;
1782 } 1667 }
1668 dev->vfd->ctrl_handler = &dev->ctrl_handler;
1783 1669
1784 /* init video dma queues */ 1670 /* init video dma queues */
1785 INIT_LIST_HEAD(&dev->vidq.active); 1671 INIT_LIST_HEAD(&dev->vidq.active);
@@ -1790,7 +1676,9 @@ int tm6000_v4l2_register(struct tm6000_core *dev)
1790 if (ret < 0) { 1676 if (ret < 0) {
1791 printk(KERN_INFO "%s: can't register video device\n", 1677 printk(KERN_INFO "%s: can't register video device\n",
1792 dev->name); 1678 dev->name);
1793 return ret; 1679 video_device_release(dev->vfd);
1680 dev->vfd = NULL;
1681 goto free_ctrl;
1794 } 1682 }
1795 1683
1796 printk(KERN_INFO "%s: registered device %s\n", 1684 printk(KERN_INFO "%s: registered device %s\n",
@@ -1803,15 +1691,17 @@ int tm6000_v4l2_register(struct tm6000_core *dev)
1803 printk(KERN_INFO "%s: can't register radio device\n", 1691 printk(KERN_INFO "%s: can't register radio device\n",
1804 dev->name); 1692 dev->name);
1805 ret = -ENXIO; 1693 ret = -ENXIO;
1806 return ret; /* FIXME release resource */ 1694 goto unreg_video;
1807 } 1695 }
1808 1696
1697 dev->radio_dev->ctrl_handler = &dev->radio_ctrl_handler;
1809 ret = video_register_device(dev->radio_dev, VFL_TYPE_RADIO, 1698 ret = video_register_device(dev->radio_dev, VFL_TYPE_RADIO,
1810 radio_nr); 1699 radio_nr);
1811 if (ret < 0) { 1700 if (ret < 0) {
1812 printk(KERN_INFO "%s: can't register radio device\n", 1701 printk(KERN_INFO "%s: can't register radio device\n",
1813 dev->name); 1702 dev->name);
1814 return ret; /* FIXME release resource */ 1703 video_device_release(dev->radio_dev);
1704 goto unreg_video;
1815 } 1705 }
1816 1706
1817 printk(KERN_INFO "%s: registered device %s\n", 1707 printk(KERN_INFO "%s: registered device %s\n",
@@ -1820,12 +1710,22 @@ int tm6000_v4l2_register(struct tm6000_core *dev)
1820 1710
1821 printk(KERN_INFO "Trident TVMaster TM5600/TM6000/TM6010 USB2 board (Load status: %d)\n", ret); 1711 printk(KERN_INFO "Trident TVMaster TM5600/TM6000/TM6010 USB2 board (Load status: %d)\n", ret);
1822 return ret; 1712 return ret;
1713
1714unreg_video:
1715 video_unregister_device(dev->vfd);
1716free_ctrl:
1717 v4l2_ctrl_handler_free(&dev->ctrl_handler);
1718 v4l2_ctrl_handler_free(&dev->radio_ctrl_handler);
1719 return ret;
1823} 1720}
1824 1721
1825int tm6000_v4l2_unregister(struct tm6000_core *dev) 1722int tm6000_v4l2_unregister(struct tm6000_core *dev)
1826{ 1723{
1827 video_unregister_device(dev->vfd); 1724 video_unregister_device(dev->vfd);
1828 1725
1726 /* if URB buffers are still allocated free them now */
1727 tm6000_free_urb_buffers(dev);
1728
1829 if (dev->radio_dev) { 1729 if (dev->radio_dev) {
1830 if (video_is_registered(dev->radio_dev)) 1730 if (video_is_registered(dev->radio_dev))
1831 video_unregister_device(dev->radio_dev); 1731 video_unregister_device(dev->radio_dev);
@@ -1851,3 +1751,5 @@ MODULE_PARM_DESC(debug, "activates debug info");
1851module_param(vid_limit, int, 0644); 1751module_param(vid_limit, int, 0644);
1852MODULE_PARM_DESC(vid_limit, "capture memory limit in megabytes"); 1752MODULE_PARM_DESC(vid_limit, "capture memory limit in megabytes");
1853 1753
1754module_param(keep_urb, bool, 0);
1755MODULE_PARM_DESC(keep_urb, "Keep urb buffers allocated even when the device is closed by the user");
diff --git a/drivers/media/usb/tm6000/tm6000.h b/drivers/media/usb/tm6000/tm6000.h
index 6df418658c9c..08bd0740dd23 100644
--- a/drivers/media/usb/tm6000/tm6000.h
+++ b/drivers/media/usb/tm6000/tm6000.h
@@ -27,6 +27,8 @@
27#include <linux/i2c.h> 27#include <linux/i2c.h>
28#include <linux/mutex.h> 28#include <linux/mutex.h>
29#include <media/v4l2-device.h> 29#include <media/v4l2-device.h>
30#include <media/v4l2-ctrls.h>
31#include <media/v4l2-fh.h>
30 32
31#include <linux/dvb/frontend.h> 33#include <linux/dvb/frontend.h>
32#include "dvb_demux.h" 34#include "dvb_demux.h"
@@ -222,6 +224,8 @@ struct tm6000_core {
222 struct video_device *radio_dev; 224 struct video_device *radio_dev;
223 struct tm6000_dmaqueue vidq; 225 struct tm6000_dmaqueue vidq;
224 struct v4l2_device v4l2_dev; 226 struct v4l2_device v4l2_dev;
227 struct v4l2_ctrl_handler ctrl_handler;
228 struct v4l2_ctrl_handler radio_ctrl_handler;
225 229
226 int input; 230 int input;
227 struct tm6000_input vinput[3]; /* video input */ 231 struct tm6000_input vinput[3]; /* video input */
@@ -264,6 +268,11 @@ struct tm6000_core {
264 268
265 spinlock_t slock; 269 spinlock_t slock;
266 270
271 /* urb dma buffers */
272 char **urb_buffer;
273 dma_addr_t *urb_dma;
274 unsigned int urb_size;
275
267 unsigned long quirks; 276 unsigned long quirks;
268}; 277};
269 278
@@ -282,6 +291,7 @@ struct tm6000_ops {
282}; 291};
283 292
284struct tm6000_fh { 293struct tm6000_fh {
294 struct v4l2_fh fh;
285 struct tm6000_core *dev; 295 struct tm6000_core *dev;
286 unsigned int radio; 296 unsigned int radio;
287 297
diff --git a/drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c b/drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c
index 5b682cc4c814..e40718552850 100644
--- a/drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c
+++ b/drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c
@@ -561,6 +561,13 @@ static void ttusb_process_muxpack(struct ttusb *ttusb, const u8 * muxpack,
561{ 561{
562 u16 csum = 0, cc; 562 u16 csum = 0, cc;
563 int i; 563 int i;
564
565 if (len < 4 || len & 0x1) {
566 pr_warn("%s: muxpack has invalid len %d\n", __func__, len);
567 numinvalid++;
568 return;
569 }
570
564 for (i = 0; i < len; i += 2) 571 for (i = 0; i < len; i += 2)
565 csum ^= le16_to_cpup((__le16 *) (muxpack + i)); 572 csum ^= le16_to_cpup((__le16 *) (muxpack + i));
566 if (csum) { 573 if (csum) {
diff --git a/drivers/media/usb/usbvision/usbvision-core.c b/drivers/media/usb/usbvision/usbvision-core.c
index c9b2042f8bdf..816b1cffab7d 100644
--- a/drivers/media/usb/usbvision/usbvision-core.c
+++ b/drivers/media/usb/usbvision/usbvision-core.c
@@ -1169,7 +1169,7 @@ static void usbvision_parse_data(struct usb_usbvision *usbvision)
1169 1169
1170 if (newstate == parse_state_next_frame) { 1170 if (newstate == parse_state_next_frame) {
1171 frame->grabstate = frame_state_done; 1171 frame->grabstate = frame_state_done;
1172 do_gettimeofday(&(frame->timestamp)); 1172 v4l2_get_timestamp(&(frame->timestamp));
1173 frame->sequence = usbvision->frame_num; 1173 frame->sequence = usbvision->frame_num;
1174 1174
1175 spin_lock_irqsave(&usbvision->queue_lock, lock_flags); 1175 spin_lock_irqsave(&usbvision->queue_lock, lock_flags);
diff --git a/drivers/media/usb/usbvision/usbvision-i2c.c b/drivers/media/usb/usbvision/usbvision-i2c.c
index 89fec029e924..ba262a32bd3a 100644
--- a/drivers/media/usb/usbvision/usbvision-i2c.c
+++ b/drivers/media/usb/usbvision/usbvision-i2c.c
@@ -189,8 +189,7 @@ int usbvision_i2c_register(struct usb_usbvision *usbvision)
189 if (usbvision->registered_i2c) 189 if (usbvision->registered_i2c)
190 return 0; 190 return 0;
191 191
192 memcpy(&usbvision->i2c_adap, &i2c_adap_template, 192 usbvision->i2c_adap = i2c_adap_template;
193 sizeof(struct i2c_adapter));
194 193
195 sprintf(usbvision->i2c_adap.name, "%s-%d-%s", i2c_adap_template.name, 194 sprintf(usbvision->i2c_adap.name, "%s-%d-%s", i2c_adap_template.name,
196 usbvision->dev->bus->busnum, usbvision->dev->devpath); 195 usbvision->dev->bus->busnum, usbvision->dev->devpath);
diff --git a/drivers/media/usb/usbvision/usbvision-video.c b/drivers/media/usb/usbvision/usbvision-video.c
index ad7f7448072e..cd1fe78a5532 100644
--- a/drivers/media/usb/usbvision/usbvision-video.c
+++ b/drivers/media/usb/usbvision/usbvision-video.c
@@ -761,7 +761,7 @@ static int vidioc_querybuf(struct file *file,
761 if (vb->index >= usbvision->num_frames) 761 if (vb->index >= usbvision->num_frames)
762 return -EINVAL; 762 return -EINVAL;
763 /* Updating the corresponding frame state */ 763 /* Updating the corresponding frame state */
764 vb->flags = 0; 764 vb->flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
765 frame = &usbvision->frame[vb->index]; 765 frame = &usbvision->frame[vb->index];
766 if (frame->grabstate >= frame_state_ready) 766 if (frame->grabstate >= frame_state_ready)
767 vb->flags |= V4L2_BUF_FLAG_QUEUED; 767 vb->flags |= V4L2_BUF_FLAG_QUEUED;
@@ -843,7 +843,8 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *vb)
843 vb->memory = V4L2_MEMORY_MMAP; 843 vb->memory = V4L2_MEMORY_MMAP;
844 vb->flags = V4L2_BUF_FLAG_MAPPED | 844 vb->flags = V4L2_BUF_FLAG_MAPPED |
845 V4L2_BUF_FLAG_QUEUED | 845 V4L2_BUF_FLAG_QUEUED |
846 V4L2_BUF_FLAG_DONE; 846 V4L2_BUF_FLAG_DONE |
847 V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
847 vb->index = f->index; 848 vb->index = f->index;
848 vb->sequence = f->sequence; 849 vb->sequence = f->sequence;
849 vb->timestamp = f->timestamp; 850 vb->timestamp = f->timestamp;
diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c
index d5baab17a5ef..61e28dec991d 100644
--- a/drivers/media/usb/uvc/uvc_ctrl.c
+++ b/drivers/media/usb/uvc/uvc_ctrl.c
@@ -1838,7 +1838,7 @@ static int uvc_ctrl_add_info(struct uvc_device *dev, struct uvc_control *ctrl,
1838{ 1838{
1839 int ret = 0; 1839 int ret = 0;
1840 1840
1841 memcpy(&ctrl->info, info, sizeof(*info)); 1841 ctrl->info = *info;
1842 INIT_LIST_HEAD(&ctrl->info.mappings); 1842 INIT_LIST_HEAD(&ctrl->info.mappings);
1843 1843
1844 /* Allocate an array to save control values (cur, def, max, etc.) */ 1844 /* Allocate an array to save control values (cur, def, max, etc.) */
diff --git a/drivers/media/usb/uvc/uvc_queue.c b/drivers/media/usb/uvc/uvc_queue.c
index 778addc5caff..6c233a54ce40 100644
--- a/drivers/media/usb/uvc/uvc_queue.c
+++ b/drivers/media/usb/uvc/uvc_queue.c
@@ -115,11 +115,27 @@ static int uvc_buffer_finish(struct vb2_buffer *vb)
115 return 0; 115 return 0;
116} 116}
117 117
118static void uvc_wait_prepare(struct vb2_queue *vq)
119{
120 struct uvc_video_queue *queue = vb2_get_drv_priv(vq);
121
122 mutex_unlock(&queue->mutex);
123}
124
125static void uvc_wait_finish(struct vb2_queue *vq)
126{
127 struct uvc_video_queue *queue = vb2_get_drv_priv(vq);
128
129 mutex_lock(&queue->mutex);
130}
131
118static struct vb2_ops uvc_queue_qops = { 132static struct vb2_ops uvc_queue_qops = {
119 .queue_setup = uvc_queue_setup, 133 .queue_setup = uvc_queue_setup,
120 .buf_prepare = uvc_buffer_prepare, 134 .buf_prepare = uvc_buffer_prepare,
121 .buf_queue = uvc_buffer_queue, 135 .buf_queue = uvc_buffer_queue,
122 .buf_finish = uvc_buffer_finish, 136 .buf_finish = uvc_buffer_finish,
137 .wait_prepare = uvc_wait_prepare,
138 .wait_finish = uvc_wait_finish,
123}; 139};
124 140
125int uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type, 141int uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type,
diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c
index 68d59b527492..b2dc32623a71 100644
--- a/drivers/media/usb/uvc/uvc_v4l2.c
+++ b/drivers/media/usb/uvc/uvc_v4l2.c
@@ -315,7 +315,7 @@ static int uvc_v4l2_set_format(struct uvc_streaming *stream,
315 goto done; 315 goto done;
316 } 316 }
317 317
318 memcpy(&stream->ctrl, &probe, sizeof probe); 318 stream->ctrl = probe;
319 stream->cur_format = format; 319 stream->cur_format = format;
320 stream->cur_frame = frame; 320 stream->cur_frame = frame;
321 321
@@ -387,7 +387,7 @@ static int uvc_v4l2_set_streamparm(struct uvc_streaming *stream,
387 return -EBUSY; 387 return -EBUSY;
388 } 388 }
389 389
390 memcpy(&probe, &stream->ctrl, sizeof probe); 390 probe = stream->ctrl;
391 probe.dwFrameInterval = 391 probe.dwFrameInterval =
392 uvc_try_frame_interval(stream->cur_frame, interval); 392 uvc_try_frame_interval(stream->cur_frame, interval);
393 393
@@ -398,7 +398,7 @@ static int uvc_v4l2_set_streamparm(struct uvc_streaming *stream,
398 return ret; 398 return ret;
399 } 399 }
400 400
401 memcpy(&stream->ctrl, &probe, sizeof probe); 401 stream->ctrl = probe;
402 mutex_unlock(&stream->mutex); 402 mutex_unlock(&stream->mutex);
403 403
404 /* Return the actual frame period. */ 404 /* Return the actual frame period. */
@@ -501,8 +501,8 @@ static int uvc_v4l2_open(struct file *file)
501 if (atomic_inc_return(&stream->dev->users) == 1) { 501 if (atomic_inc_return(&stream->dev->users) == 1) {
502 ret = uvc_status_start(stream->dev); 502 ret = uvc_status_start(stream->dev);
503 if (ret < 0) { 503 if (ret < 0) {
504 usb_autopm_put_interface(stream->dev->intf);
505 atomic_dec(&stream->dev->users); 504 atomic_dec(&stream->dev->users);
505 usb_autopm_put_interface(stream->dev->intf);
506 kfree(handle); 506 kfree(handle);
507 return ret; 507 return ret;
508 } 508 }
diff --git a/drivers/media/usb/zr364xx/zr364xx.c b/drivers/media/usb/zr364xx/zr364xx.c
index 39edd4442932..74d56df3347f 100644
--- a/drivers/media/usb/zr364xx/zr364xx.c
+++ b/drivers/media/usb/zr364xx/zr364xx.c
@@ -501,7 +501,6 @@ static void zr364xx_fillbuff(struct zr364xx_camera *cam,
501 int jpgsize) 501 int jpgsize)
502{ 502{
503 int pos = 0; 503 int pos = 0;
504 struct timeval ts;
505 const char *tmpbuf; 504 const char *tmpbuf;
506 char *vbuf = videobuf_to_vmalloc(&buf->vb); 505 char *vbuf = videobuf_to_vmalloc(&buf->vb);
507 unsigned long last_frame; 506 unsigned long last_frame;
@@ -530,8 +529,7 @@ static void zr364xx_fillbuff(struct zr364xx_camera *cam,
530 /* tell v4l buffer was filled */ 529 /* tell v4l buffer was filled */
531 530
532 buf->vb.field_count = cam->frame_count * 2; 531 buf->vb.field_count = cam->frame_count * 2;
533 do_gettimeofday(&ts); 532 v4l2_get_timestamp(&buf->vb.ts);
534 buf->vb.ts = ts;
535 buf->vb.state = VIDEOBUF_DONE; 533 buf->vb.state = VIDEOBUF_DONE;
536} 534}
537 535
@@ -559,7 +557,7 @@ static int zr364xx_got_frame(struct zr364xx_camera *cam, int jpgsize)
559 goto unlock; 557 goto unlock;
560 } 558 }
561 list_del(&buf->vb.queue); 559 list_del(&buf->vb.queue);
562 do_gettimeofday(&buf->vb.ts); 560 v4l2_get_timestamp(&buf->vb.ts);
563 DBG("[%p/%d] wakeup\n", buf, buf->vb.i); 561 DBG("[%p/%d] wakeup\n", buf, buf->vb.i);
564 zr364xx_fillbuff(cam, buf, jpgsize); 562 zr364xx_fillbuff(cam, buf, jpgsize);
565 wake_up(&buf->vb.done); 563 wake_up(&buf->vb.done);
diff --git a/drivers/media/v4l2-core/Kconfig b/drivers/media/v4l2-core/Kconfig
index 65875c3aba1b..976d029e9925 100644
--- a/drivers/media/v4l2-core/Kconfig
+++ b/drivers/media/v4l2-core/Kconfig
@@ -82,3 +82,14 @@ config VIDEOBUF2_DMA_SG
82 #depends on HAS_DMA 82 #depends on HAS_DMA
83 select VIDEOBUF2_CORE 83 select VIDEOBUF2_CORE
84 select VIDEOBUF2_MEMOPS 84 select VIDEOBUF2_MEMOPS
85
86config VIDEO_V4L2_INT_DEVICE
87 tristate "V4L2 int device (DEPRECATED)"
88 depends on VIDEO_V4L2
89 ---help---
90 An early framework for a hardware-independent interface for
91 image sensors and bridges etc. Currently used by omap24xxcam and
92 tcm825x drivers that should be converted to V4L2 subdev.
93
94 Do not use for new developments.
95
diff --git a/drivers/media/v4l2-core/Makefile b/drivers/media/v4l2-core/Makefile
index c2d61d4f03d1..a9d355230e8e 100644
--- a/drivers/media/v4l2-core/Makefile
+++ b/drivers/media/v4l2-core/Makefile
@@ -10,7 +10,8 @@ ifeq ($(CONFIG_COMPAT),y)
10 videodev-objs += v4l2-compat-ioctl32.o 10 videodev-objs += v4l2-compat-ioctl32.o
11endif 11endif
12 12
13obj-$(CONFIG_VIDEO_DEV) += videodev.o v4l2-int-device.o 13obj-$(CONFIG_VIDEO_DEV) += videodev.o
14obj-$(CONFIG_VIDEO_V4L2_INT_DEVICE) += v4l2-int-device.o
14obj-$(CONFIG_VIDEO_V4L2) += v4l2-common.o 15obj-$(CONFIG_VIDEO_V4L2) += v4l2-common.o
15 16
16obj-$(CONFIG_VIDEO_TUNER) += tuner.o 17obj-$(CONFIG_VIDEO_TUNER) += tuner.o
diff --git a/drivers/media/v4l2-core/tuner-core.c b/drivers/media/v4l2-core/tuner-core.c
index b5a819af2b8c..b5a8aac2e126 100644
--- a/drivers/media/v4l2-core/tuner-core.c
+++ b/drivers/media/v4l2-core/tuner-core.c
@@ -1013,6 +1013,11 @@ static void set_radio_freq(struct i2c_client *c, unsigned int freq)
1013 t->standby = false; 1013 t->standby = false;
1014 1014
1015 analog_ops->set_params(&t->fe, &params); 1015 analog_ops->set_params(&t->fe, &params);
1016 /*
1017 * The tuner driver might decide to change the audmode if it only
1018 * supports stereo, so update t->audmode.
1019 */
1020 t->audmode = params.audmode;
1016} 1021}
1017 1022
1018/* 1023/*
@@ -1235,8 +1240,18 @@ static int tuner_s_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
1235 if (set_mode(t, vt->type)) 1240 if (set_mode(t, vt->type))
1236 return 0; 1241 return 0;
1237 1242
1238 if (t->mode == V4L2_TUNER_RADIO) 1243 if (t->mode == V4L2_TUNER_RADIO) {
1239 t->audmode = vt->audmode; 1244 t->audmode = vt->audmode;
1245 /*
1246 * For radio audmode can only be mono or stereo. Map any
1247 * other values to stereo. The actual tuner driver that is
1248 * called in set_radio_freq can decide to limit the audmode to
1249 * mono if only mono is supported.
1250 */
1251 if (t->audmode != V4L2_TUNER_MODE_MONO &&
1252 t->audmode != V4L2_TUNER_MODE_STEREO)
1253 t->audmode = V4L2_TUNER_MODE_STEREO;
1254 }
1240 set_freq(t, 0); 1255 set_freq(t, 0);
1241 1256
1242 return 0; 1257 return 0;
diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-core/v4l2-common.c
index 380ddd89fa4c..aa044f491666 100644
--- a/drivers/media/v4l2-core/v4l2-common.c
+++ b/drivers/media/v4l2-core/v4l2-common.c
@@ -238,7 +238,7 @@ int v4l2_chip_match_host(const struct v4l2_dbg_match *match)
238} 238}
239EXPORT_SYMBOL(v4l2_chip_match_host); 239EXPORT_SYMBOL(v4l2_chip_match_host);
240 240
241#if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE)) 241#if IS_ENABLED(CONFIG_I2C)
242int v4l2_chip_match_i2c_client(struct i2c_client *c, const struct v4l2_dbg_match *match) 242int v4l2_chip_match_i2c_client(struct i2c_client *c, const struct v4l2_dbg_match *match)
243{ 243{
244 int len; 244 int len;
@@ -384,7 +384,7 @@ EXPORT_SYMBOL_GPL(v4l2_i2c_subdev_addr);
384const unsigned short *v4l2_i2c_tuner_addrs(enum v4l2_i2c_tuner_type type) 384const unsigned short *v4l2_i2c_tuner_addrs(enum v4l2_i2c_tuner_type type)
385{ 385{
386 static const unsigned short radio_addrs[] = { 386 static const unsigned short radio_addrs[] = {
387#if defined(CONFIG_MEDIA_TUNER_TEA5761) || defined(CONFIG_MEDIA_TUNER_TEA5761_MODULE) 387#if IS_ENABLED(CONFIG_MEDIA_TUNER_TEA5761)
388 0x10, 388 0x10,
389#endif 389#endif
390 0x60, 390 0x60,
@@ -978,3 +978,13 @@ const struct v4l2_frmsize_discrete *v4l2_find_nearest_format(
978 return best; 978 return best;
979} 979}
980EXPORT_SYMBOL_GPL(v4l2_find_nearest_format); 980EXPORT_SYMBOL_GPL(v4l2_find_nearest_format);
981
982void v4l2_get_timestamp(struct timeval *tv)
983{
984 struct timespec ts;
985
986 ktime_get_ts(&ts);
987 tv->tv_sec = ts.tv_sec;
988 tv->tv_usec = ts.tv_nsec / NSEC_PER_USEC;
989}
990EXPORT_SYMBOL_GPL(v4l2_get_timestamp);
diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
index f6ee201d9347..6b28b5800500 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls.c
@@ -577,8 +577,6 @@ const char *v4l2_ctrl_get_name(u32 id)
577 case V4L2_CID_GAIN: return "Gain"; 577 case V4L2_CID_GAIN: return "Gain";
578 case V4L2_CID_HFLIP: return "Horizontal Flip"; 578 case V4L2_CID_HFLIP: return "Horizontal Flip";
579 case V4L2_CID_VFLIP: return "Vertical Flip"; 579 case V4L2_CID_VFLIP: return "Vertical Flip";
580 case V4L2_CID_HCENTER: return "Horizontal Center";
581 case V4L2_CID_VCENTER: return "Vertical Center";
582 case V4L2_CID_POWER_LINE_FREQUENCY: return "Power Line Frequency"; 580 case V4L2_CID_POWER_LINE_FREQUENCY: return "Power Line Frequency";
583 case V4L2_CID_HUE_AUTO: return "Hue, Automatic"; 581 case V4L2_CID_HUE_AUTO: return "Hue, Automatic";
584 case V4L2_CID_WHITE_BALANCE_TEMPERATURE: return "White Balance Temperature"; 582 case V4L2_CID_WHITE_BALANCE_TEMPERATURE: return "White Balance Temperature";
@@ -1160,8 +1158,7 @@ static int new_to_user(struct v4l2_ext_control *c,
1160} 1158}
1161 1159
1162/* Copy the new value to the current value. */ 1160/* Copy the new value to the current value. */
1163static void new_to_cur(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl, 1161static void new_to_cur(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl, u32 ch_flags)
1164 bool update_inactive)
1165{ 1162{
1166 bool changed = false; 1163 bool changed = false;
1167 1164
@@ -1185,8 +1182,8 @@ static void new_to_cur(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl,
1185 ctrl->cur.val = ctrl->val; 1182 ctrl->cur.val = ctrl->val;
1186 break; 1183 break;
1187 } 1184 }
1188 if (update_inactive) { 1185 if (ch_flags & V4L2_EVENT_CTRL_CH_FLAGS) {
1189 /* Note: update_inactive can only be true for auto clusters. */ 1186 /* Note: CH_FLAGS is only set for auto clusters. */
1190 ctrl->flags &= 1187 ctrl->flags &=
1191 ~(V4L2_CTRL_FLAG_INACTIVE | V4L2_CTRL_FLAG_VOLATILE); 1188 ~(V4L2_CTRL_FLAG_INACTIVE | V4L2_CTRL_FLAG_VOLATILE);
1192 if (!is_cur_manual(ctrl->cluster[0])) { 1189 if (!is_cur_manual(ctrl->cluster[0])) {
@@ -1196,14 +1193,15 @@ static void new_to_cur(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl,
1196 } 1193 }
1197 fh = NULL; 1194 fh = NULL;
1198 } 1195 }
1199 if (changed || update_inactive) { 1196 if (changed || ch_flags) {
1200 /* If a control was changed that was not one of the controls 1197 /* If a control was changed that was not one of the controls
1201 modified by the application, then send the event to all. */ 1198 modified by the application, then send the event to all. */
1202 if (!ctrl->is_new) 1199 if (!ctrl->is_new)
1203 fh = NULL; 1200 fh = NULL;
1204 send_event(fh, ctrl, 1201 send_event(fh, ctrl,
1205 (changed ? V4L2_EVENT_CTRL_CH_VALUE : 0) | 1202 (changed ? V4L2_EVENT_CTRL_CH_VALUE : 0) | ch_flags);
1206 (update_inactive ? V4L2_EVENT_CTRL_CH_FLAGS : 0)); 1203 if (ctrl->call_notify && changed && ctrl->handler->notify)
1204 ctrl->handler->notify(ctrl, ctrl->handler->notify_priv);
1207 } 1205 }
1208} 1206}
1209 1207
@@ -1257,6 +1255,41 @@ static int cluster_changed(struct v4l2_ctrl *master)
1257 return diff; 1255 return diff;
1258} 1256}
1259 1257
1258/* Control range checking */
1259static int check_range(enum v4l2_ctrl_type type,
1260 s32 min, s32 max, u32 step, s32 def)
1261{
1262 switch (type) {
1263 case V4L2_CTRL_TYPE_BOOLEAN:
1264 if (step != 1 || max > 1 || min < 0)
1265 return -ERANGE;
1266 /* fall through */
1267 case V4L2_CTRL_TYPE_INTEGER:
1268 if (step <= 0 || min > max || def < min || def > max)
1269 return -ERANGE;
1270 return 0;
1271 case V4L2_CTRL_TYPE_BITMASK:
1272 if (step || min || !max || (def & ~max))
1273 return -ERANGE;
1274 return 0;
1275 case V4L2_CTRL_TYPE_MENU:
1276 case V4L2_CTRL_TYPE_INTEGER_MENU:
1277 if (min > max || def < min || def > max)
1278 return -ERANGE;
1279 /* Note: step == menu_skip_mask for menu controls.
1280 So here we check if the default value is masked out. */
1281 if (step && ((1 << def) & step))
1282 return -EINVAL;
1283 return 0;
1284 case V4L2_CTRL_TYPE_STRING:
1285 if (min > max || min < 0 || step < 1 || def)
1286 return -ERANGE;
1287 return 0;
1288 default:
1289 return 0;
1290 }
1291}
1292
1260/* Validate a new control */ 1293/* Validate a new control */
1261static int validate_new(const struct v4l2_ctrl *ctrl, 1294static int validate_new(const struct v4l2_ctrl *ctrl,
1262 struct v4l2_ext_control *c) 1295 struct v4l2_ext_control *c)
@@ -1529,30 +1562,21 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
1529{ 1562{
1530 struct v4l2_ctrl *ctrl; 1563 struct v4l2_ctrl *ctrl;
1531 unsigned sz_extra = 0; 1564 unsigned sz_extra = 0;
1565 int err;
1532 1566
1533 if (hdl->error) 1567 if (hdl->error)
1534 return NULL; 1568 return NULL;
1535 1569
1536 /* Sanity checks */ 1570 /* Sanity checks */
1537 if (id == 0 || name == NULL || id >= V4L2_CID_PRIVATE_BASE || 1571 if (id == 0 || name == NULL || id >= V4L2_CID_PRIVATE_BASE ||
1538 (type == V4L2_CTRL_TYPE_INTEGER && step == 0) ||
1539 (type == V4L2_CTRL_TYPE_BITMASK && max == 0) ||
1540 (type == V4L2_CTRL_TYPE_MENU && qmenu == NULL) || 1572 (type == V4L2_CTRL_TYPE_MENU && qmenu == NULL) ||
1541 (type == V4L2_CTRL_TYPE_INTEGER_MENU && qmenu_int == NULL) || 1573 (type == V4L2_CTRL_TYPE_INTEGER_MENU && qmenu_int == NULL)) {
1542 (type == V4L2_CTRL_TYPE_STRING && max == 0)) {
1543 handler_set_err(hdl, -ERANGE);
1544 return NULL;
1545 }
1546 if (type != V4L2_CTRL_TYPE_BITMASK && max < min) {
1547 handler_set_err(hdl, -ERANGE); 1574 handler_set_err(hdl, -ERANGE);
1548 return NULL; 1575 return NULL;
1549 } 1576 }
1550 if ((type == V4L2_CTRL_TYPE_INTEGER || 1577 err = check_range(type, min, max, step, def);
1551 type == V4L2_CTRL_TYPE_MENU || 1578 if (err) {
1552 type == V4L2_CTRL_TYPE_INTEGER_MENU || 1579 handler_set_err(hdl, err);
1553 type == V4L2_CTRL_TYPE_BOOLEAN) &&
1554 (def < min || def > max)) {
1555 handler_set_err(hdl, -ERANGE);
1556 return NULL; 1580 return NULL;
1557 } 1581 }
1558 if (type == V4L2_CTRL_TYPE_BITMASK && ((def & ~max) || min || step)) { 1582 if (type == V4L2_CTRL_TYPE_BITMASK && ((def & ~max) || min || step)) {
@@ -1980,6 +2004,13 @@ void v4l2_ctrl_handler_log_status(struct v4l2_ctrl_handler *hdl,
1980} 2004}
1981EXPORT_SYMBOL(v4l2_ctrl_handler_log_status); 2005EXPORT_SYMBOL(v4l2_ctrl_handler_log_status);
1982 2006
2007int v4l2_ctrl_subdev_log_status(struct v4l2_subdev *sd)
2008{
2009 v4l2_ctrl_handler_log_status(sd->ctrl_handler, sd->name);
2010 return 0;
2011}
2012EXPORT_SYMBOL(v4l2_ctrl_subdev_log_status);
2013
1983/* Call s_ctrl for all controls owned by the handler */ 2014/* Call s_ctrl for all controls owned by the handler */
1984int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl) 2015int v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl)
1985{ 2016{
@@ -2426,8 +2457,8 @@ EXPORT_SYMBOL(v4l2_ctrl_g_ctrl_int64);
2426/* Core function that calls try/s_ctrl and ensures that the new value is 2457/* Core function that calls try/s_ctrl and ensures that the new value is
2427 copied to the current value on a set. 2458 copied to the current value on a set.
2428 Must be called with ctrl->handler->lock held. */ 2459 Must be called with ctrl->handler->lock held. */
2429static int try_or_set_cluster(struct v4l2_fh *fh, 2460static int try_or_set_cluster(struct v4l2_fh *fh, struct v4l2_ctrl *master,
2430 struct v4l2_ctrl *master, bool set) 2461 bool set, u32 ch_flags)
2431{ 2462{
2432 bool update_flag; 2463 bool update_flag;
2433 int ret; 2464 int ret;
@@ -2465,7 +2496,8 @@ static int try_or_set_cluster(struct v4l2_fh *fh,
2465 /* If OK, then make the new values permanent. */ 2496 /* If OK, then make the new values permanent. */
2466 update_flag = is_cur_manual(master) != is_new_manual(master); 2497 update_flag = is_cur_manual(master) != is_new_manual(master);
2467 for (i = 0; i < master->ncontrols; i++) 2498 for (i = 0; i < master->ncontrols; i++)
2468 new_to_cur(fh, master->cluster[i], update_flag && i > 0); 2499 new_to_cur(fh, master->cluster[i], ch_flags |
2500 ((update_flag && i > 0) ? V4L2_EVENT_CTRL_CH_FLAGS : 0));
2469 return 0; 2501 return 0;
2470} 2502}
2471 2503
@@ -2592,7 +2624,7 @@ static int try_set_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
2592 } while (!ret && idx); 2624 } while (!ret && idx);
2593 2625
2594 if (!ret) 2626 if (!ret)
2595 ret = try_or_set_cluster(fh, master, set); 2627 ret = try_or_set_cluster(fh, master, set, 0);
2596 2628
2597 /* Copy the new values back to userspace. */ 2629 /* Copy the new values back to userspace. */
2598 if (!ret) { 2630 if (!ret) {
@@ -2638,10 +2670,9 @@ EXPORT_SYMBOL(v4l2_subdev_s_ext_ctrls);
2638 2670
2639/* Helper function for VIDIOC_S_CTRL compatibility */ 2671/* Helper function for VIDIOC_S_CTRL compatibility */
2640static int set_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl, 2672static int set_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl,
2641 struct v4l2_ext_control *c) 2673 struct v4l2_ext_control *c, u32 ch_flags)
2642{ 2674{
2643 struct v4l2_ctrl *master = ctrl->cluster[0]; 2675 struct v4l2_ctrl *master = ctrl->cluster[0];
2644 int ret;
2645 int i; 2676 int i;
2646 2677
2647 /* String controls are not supported. The user_to_new() and 2678 /* String controls are not supported. The user_to_new() and
@@ -2651,12 +2682,6 @@ static int set_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl,
2651 if (ctrl->type == V4L2_CTRL_TYPE_STRING) 2682 if (ctrl->type == V4L2_CTRL_TYPE_STRING)
2652 return -EINVAL; 2683 return -EINVAL;
2653 2684
2654 ret = validate_new(ctrl, c);
2655 if (ret)
2656 return ret;
2657
2658 v4l2_ctrl_lock(ctrl);
2659
2660 /* Reset the 'is_new' flags of the cluster */ 2685 /* Reset the 'is_new' flags of the cluster */
2661 for (i = 0; i < master->ncontrols; i++) 2686 for (i = 0; i < master->ncontrols; i++)
2662 if (master->cluster[i]) 2687 if (master->cluster[i])
@@ -2670,10 +2695,22 @@ static int set_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl,
2670 update_from_auto_cluster(master); 2695 update_from_auto_cluster(master);
2671 2696
2672 user_to_new(c, ctrl); 2697 user_to_new(c, ctrl);
2673 ret = try_or_set_cluster(fh, master, true); 2698 return try_or_set_cluster(fh, master, true, ch_flags);
2674 cur_to_user(c, ctrl); 2699}
2675 2700
2676 v4l2_ctrl_unlock(ctrl); 2701/* Helper function for VIDIOC_S_CTRL compatibility */
2702static int set_ctrl_lock(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl,
2703 struct v4l2_ext_control *c)
2704{
2705 int ret = validate_new(ctrl, c);
2706
2707 if (!ret) {
2708 v4l2_ctrl_lock(ctrl);
2709 ret = set_ctrl(fh, ctrl, c, 0);
2710 if (!ret)
2711 cur_to_user(c, ctrl);
2712 v4l2_ctrl_unlock(ctrl);
2713 }
2677 return ret; 2714 return ret;
2678} 2715}
2679 2716
@@ -2691,7 +2728,7 @@ int v4l2_s_ctrl(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
2691 return -EACCES; 2728 return -EACCES;
2692 2729
2693 c.value = control->value; 2730 c.value = control->value;
2694 ret = set_ctrl(fh, ctrl, &c); 2731 ret = set_ctrl_lock(fh, ctrl, &c);
2695 control->value = c.value; 2732 control->value = c.value;
2696 return ret; 2733 return ret;
2697} 2734}
@@ -2710,7 +2747,7 @@ int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val)
2710 /* It's a driver bug if this happens. */ 2747 /* It's a driver bug if this happens. */
2711 WARN_ON(!type_is_int(ctrl)); 2748 WARN_ON(!type_is_int(ctrl));
2712 c.value = val; 2749 c.value = val;
2713 return set_ctrl(NULL, ctrl, &c); 2750 return set_ctrl_lock(NULL, ctrl, &c);
2714} 2751}
2715EXPORT_SYMBOL(v4l2_ctrl_s_ctrl); 2752EXPORT_SYMBOL(v4l2_ctrl_s_ctrl);
2716 2753
@@ -2721,10 +2758,61 @@ int v4l2_ctrl_s_ctrl_int64(struct v4l2_ctrl *ctrl, s64 val)
2721 /* It's a driver bug if this happens. */ 2758 /* It's a driver bug if this happens. */
2722 WARN_ON(ctrl->type != V4L2_CTRL_TYPE_INTEGER64); 2759 WARN_ON(ctrl->type != V4L2_CTRL_TYPE_INTEGER64);
2723 c.value64 = val; 2760 c.value64 = val;
2724 return set_ctrl(NULL, ctrl, &c); 2761 return set_ctrl_lock(NULL, ctrl, &c);
2725} 2762}
2726EXPORT_SYMBOL(v4l2_ctrl_s_ctrl_int64); 2763EXPORT_SYMBOL(v4l2_ctrl_s_ctrl_int64);
2727 2764
2765void v4l2_ctrl_notify(struct v4l2_ctrl *ctrl, v4l2_ctrl_notify_fnc notify, void *priv)
2766{
2767 if (ctrl == NULL)
2768 return;
2769 if (notify == NULL) {
2770 ctrl->call_notify = 0;
2771 return;
2772 }
2773 if (WARN_ON(ctrl->handler->notify && ctrl->handler->notify != notify))
2774 return;
2775 ctrl->handler->notify = notify;
2776 ctrl->handler->notify_priv = priv;
2777 ctrl->call_notify = 1;
2778}
2779EXPORT_SYMBOL(v4l2_ctrl_notify);
2780
2781int v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
2782 s32 min, s32 max, u32 step, s32 def)
2783{
2784 int ret = check_range(ctrl->type, min, max, step, def);
2785 struct v4l2_ext_control c;
2786
2787 switch (ctrl->type) {
2788 case V4L2_CTRL_TYPE_INTEGER:
2789 case V4L2_CTRL_TYPE_BOOLEAN:
2790 case V4L2_CTRL_TYPE_MENU:
2791 case V4L2_CTRL_TYPE_INTEGER_MENU:
2792 case V4L2_CTRL_TYPE_BITMASK:
2793 if (ret)
2794 return ret;
2795 break;
2796 default:
2797 return -EINVAL;
2798 }
2799 v4l2_ctrl_lock(ctrl);
2800 ctrl->minimum = min;
2801 ctrl->maximum = max;
2802 ctrl->step = step;
2803 ctrl->default_value = def;
2804 c.value = ctrl->cur.val;
2805 if (validate_new(ctrl, &c))
2806 c.value = def;
2807 if (c.value != ctrl->cur.val)
2808 ret = set_ctrl(NULL, ctrl, &c, V4L2_EVENT_CTRL_CH_RANGE);
2809 else
2810 send_event(NULL, ctrl, V4L2_EVENT_CTRL_CH_RANGE);
2811 v4l2_ctrl_unlock(ctrl);
2812 return ret;
2813}
2814EXPORT_SYMBOL(v4l2_ctrl_modify_range);
2815
2728static int v4l2_ctrl_add_event(struct v4l2_subscribed_event *sev, unsigned elems) 2816static int v4l2_ctrl_add_event(struct v4l2_subscribed_event *sev, unsigned elems)
2729{ 2817{
2730 struct v4l2_ctrl *ctrl = v4l2_ctrl_find(sev->fh->ctrl_handler, sev->id); 2818 struct v4l2_ctrl *ctrl = v4l2_ctrl_find(sev->fh->ctrl_handler, sev->id);
@@ -2804,6 +2892,15 @@ int v4l2_ctrl_subscribe_event(struct v4l2_fh *fh,
2804} 2892}
2805EXPORT_SYMBOL(v4l2_ctrl_subscribe_event); 2893EXPORT_SYMBOL(v4l2_ctrl_subscribe_event);
2806 2894
2895int v4l2_ctrl_subdev_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh,
2896 struct v4l2_event_subscription *sub)
2897{
2898 if (!sd->ctrl_handler)
2899 return -EINVAL;
2900 return v4l2_ctrl_subscribe_event(fh, sub);
2901}
2902EXPORT_SYMBOL(v4l2_ctrl_subdev_subscribe_event);
2903
2807unsigned int v4l2_ctrl_poll(struct file *file, struct poll_table_struct *wait) 2904unsigned int v4l2_ctrl_poll(struct file *file, struct poll_table_struct *wait)
2808{ 2905{
2809 struct v4l2_fh *fh = file->private_data; 2906 struct v4l2_fh *fh = file->private_data;
diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c
index 98dcad9c8a3b..51b3a7713dcd 100644
--- a/drivers/media/v4l2-core/v4l2-dev.c
+++ b/drivers/media/v4l2-core/v4l2-dev.c
@@ -568,11 +568,6 @@ static void determine_valid_ioctls(struct video_device *vdev)
568 if (ops->vidioc_s_priority || 568 if (ops->vidioc_s_priority ||
569 test_bit(V4L2_FL_USE_FH_PRIO, &vdev->flags)) 569 test_bit(V4L2_FL_USE_FH_PRIO, &vdev->flags))
570 set_bit(_IOC_NR(VIDIOC_S_PRIORITY), valid_ioctls); 570 set_bit(_IOC_NR(VIDIOC_S_PRIORITY), valid_ioctls);
571 SET_VALID_IOCTL(ops, VIDIOC_REQBUFS, vidioc_reqbufs);
572 SET_VALID_IOCTL(ops, VIDIOC_QUERYBUF, vidioc_querybuf);
573 SET_VALID_IOCTL(ops, VIDIOC_QBUF, vidioc_qbuf);
574 SET_VALID_IOCTL(ops, VIDIOC_EXPBUF, vidioc_expbuf);
575 SET_VALID_IOCTL(ops, VIDIOC_DQBUF, vidioc_dqbuf);
576 SET_VALID_IOCTL(ops, VIDIOC_STREAMON, vidioc_streamon); 571 SET_VALID_IOCTL(ops, VIDIOC_STREAMON, vidioc_streamon);
577 SET_VALID_IOCTL(ops, VIDIOC_STREAMOFF, vidioc_streamoff); 572 SET_VALID_IOCTL(ops, VIDIOC_STREAMOFF, vidioc_streamoff);
578 /* Note: the control handler can also be passed through the filehandle, 573 /* Note: the control handler can also be passed through the filehandle,
@@ -605,8 +600,6 @@ static void determine_valid_ioctls(struct video_device *vdev)
605 SET_VALID_IOCTL(ops, VIDIOC_DQEVENT, vidioc_subscribe_event); 600 SET_VALID_IOCTL(ops, VIDIOC_DQEVENT, vidioc_subscribe_event);
606 SET_VALID_IOCTL(ops, VIDIOC_SUBSCRIBE_EVENT, vidioc_subscribe_event); 601 SET_VALID_IOCTL(ops, VIDIOC_SUBSCRIBE_EVENT, vidioc_subscribe_event);
607 SET_VALID_IOCTL(ops, VIDIOC_UNSUBSCRIBE_EVENT, vidioc_unsubscribe_event); 602 SET_VALID_IOCTL(ops, VIDIOC_UNSUBSCRIBE_EVENT, vidioc_unsubscribe_event);
608 SET_VALID_IOCTL(ops, VIDIOC_CREATE_BUFS, vidioc_create_bufs);
609 SET_VALID_IOCTL(ops, VIDIOC_PREPARE_BUF, vidioc_prepare_buf);
610 if (ops->vidioc_enum_freq_bands || ops->vidioc_g_tuner || ops->vidioc_g_modulator) 603 if (ops->vidioc_enum_freq_bands || ops->vidioc_g_tuner || ops->vidioc_g_modulator)
611 set_bit(_IOC_NR(VIDIOC_ENUM_FREQ_BANDS), valid_ioctls); 604 set_bit(_IOC_NR(VIDIOC_ENUM_FREQ_BANDS), valid_ioctls);
612 605
@@ -672,6 +665,13 @@ static void determine_valid_ioctls(struct video_device *vdev)
672 } 665 }
673 if (!is_radio) { 666 if (!is_radio) {
674 /* ioctls valid for video or vbi */ 667 /* ioctls valid for video or vbi */
668 SET_VALID_IOCTL(ops, VIDIOC_REQBUFS, vidioc_reqbufs);
669 SET_VALID_IOCTL(ops, VIDIOC_QUERYBUF, vidioc_querybuf);
670 SET_VALID_IOCTL(ops, VIDIOC_QBUF, vidioc_qbuf);
671 SET_VALID_IOCTL(ops, VIDIOC_EXPBUF, vidioc_expbuf);
672 SET_VALID_IOCTL(ops, VIDIOC_DQBUF, vidioc_dqbuf);
673 SET_VALID_IOCTL(ops, VIDIOC_CREATE_BUFS, vidioc_create_bufs);
674 SET_VALID_IOCTL(ops, VIDIOC_PREPARE_BUF, vidioc_prepare_buf);
675 if (ops->vidioc_s_std) 675 if (ops->vidioc_s_std)
676 set_bit(_IOC_NR(VIDIOC_ENUMSTD), valid_ioctls); 676 set_bit(_IOC_NR(VIDIOC_ENUMSTD), valid_ioctls);
677 if (ops->vidioc_g_std || vdev->current_norm) 677 if (ops->vidioc_g_std || vdev->current_norm)
diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
index 513969fa695d..8ed5da2170bf 100644
--- a/drivers/media/v4l2-core/v4l2-device.c
+++ b/drivers/media/v4l2-core/v4l2-device.c
@@ -112,7 +112,7 @@ void v4l2_device_unregister(struct v4l2_device *v4l2_dev)
112 /* Unregister subdevs */ 112 /* Unregister subdevs */
113 list_for_each_entry_safe(sd, next, &v4l2_dev->subdevs, list) { 113 list_for_each_entry_safe(sd, next, &v4l2_dev->subdevs, list) {
114 v4l2_device_unregister_subdev(sd); 114 v4l2_device_unregister_subdev(sd);
115#if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE)) 115#if IS_ENABLED(CONFIG_I2C)
116 if (sd->flags & V4L2_SUBDEV_FL_IS_I2C) { 116 if (sd->flags & V4L2_SUBDEV_FL_IS_I2C) {
117 struct i2c_client *client = v4l2_get_subdevdata(sd); 117 struct i2c_client *client = v4l2_get_subdevdata(sd);
118 118
@@ -159,31 +159,21 @@ int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev,
159 sd->v4l2_dev = v4l2_dev; 159 sd->v4l2_dev = v4l2_dev;
160 if (sd->internal_ops && sd->internal_ops->registered) { 160 if (sd->internal_ops && sd->internal_ops->registered) {
161 err = sd->internal_ops->registered(sd); 161 err = sd->internal_ops->registered(sd);
162 if (err) { 162 if (err)
163 module_put(sd->owner); 163 goto error_module;
164 return err;
165 }
166 } 164 }
167 165
168 /* This just returns 0 if either of the two args is NULL */ 166 /* This just returns 0 if either of the two args is NULL */
169 err = v4l2_ctrl_add_handler(v4l2_dev->ctrl_handler, sd->ctrl_handler, NULL); 167 err = v4l2_ctrl_add_handler(v4l2_dev->ctrl_handler, sd->ctrl_handler, NULL);
170 if (err) { 168 if (err)
171 if (sd->internal_ops && sd->internal_ops->unregistered) 169 goto error_unregister;
172 sd->internal_ops->unregistered(sd);
173 module_put(sd->owner);
174 return err;
175 }
176 170
177#if defined(CONFIG_MEDIA_CONTROLLER) 171#if defined(CONFIG_MEDIA_CONTROLLER)
178 /* Register the entity. */ 172 /* Register the entity. */
179 if (v4l2_dev->mdev) { 173 if (v4l2_dev->mdev) {
180 err = media_device_register_entity(v4l2_dev->mdev, entity); 174 err = media_device_register_entity(v4l2_dev->mdev, entity);
181 if (err < 0) { 175 if (err < 0)
182 if (sd->internal_ops && sd->internal_ops->unregistered) 176 goto error_unregister;
183 sd->internal_ops->unregistered(sd);
184 module_put(sd->owner);
185 return err;
186 }
187 } 177 }
188#endif 178#endif
189 179
@@ -192,6 +182,14 @@ int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev,
192 spin_unlock(&v4l2_dev->lock); 182 spin_unlock(&v4l2_dev->lock);
193 183
194 return 0; 184 return 0;
185
186error_unregister:
187 if (sd->internal_ops && sd->internal_ops->unregistered)
188 sd->internal_ops->unregistered(sd);
189error_module:
190 module_put(sd->owner);
191 sd->v4l2_dev = NULL;
192 return err;
195} 193}
196EXPORT_SYMBOL_GPL(v4l2_device_register_subdev); 194EXPORT_SYMBOL_GPL(v4l2_device_register_subdev);
197 195
diff --git a/drivers/media/v4l2-core/v4l2-event.c b/drivers/media/v4l2-core/v4l2-event.c
index c72009218152..86dcb5483c42 100644
--- a/drivers/media/v4l2-core/v4l2-event.c
+++ b/drivers/media/v4l2-core/v4l2-event.c
@@ -311,3 +311,10 @@ int v4l2_event_unsubscribe(struct v4l2_fh *fh,
311 return 0; 311 return 0;
312} 312}
313EXPORT_SYMBOL_GPL(v4l2_event_unsubscribe); 313EXPORT_SYMBOL_GPL(v4l2_event_unsubscribe);
314
315int v4l2_event_subdev_unsubscribe(struct v4l2_subdev *sd, struct v4l2_fh *fh,
316 struct v4l2_event_subscription *sub)
317{
318 return v4l2_event_unsubscribe(fh, sub);
319}
320EXPORT_SYMBOL_GPL(v4l2_event_subdev_unsubscribe);
diff --git a/drivers/media/v4l2-core/v4l2-mem2mem.c b/drivers/media/v4l2-core/v4l2-mem2mem.c
index 438ea45d1074..da99cf727162 100644
--- a/drivers/media/v4l2-core/v4l2-mem2mem.c
+++ b/drivers/media/v4l2-core/v4l2-mem2mem.c
@@ -62,7 +62,7 @@ struct v4l2_m2m_dev {
62 struct list_head job_queue; 62 struct list_head job_queue;
63 spinlock_t job_spinlock; 63 spinlock_t job_spinlock;
64 64
65 struct v4l2_m2m_ops *m2m_ops; 65 const struct v4l2_m2m_ops *m2m_ops;
66}; 66};
67 67
68static struct v4l2_m2m_queue_ctx *get_queue_ctx(struct v4l2_m2m_ctx *m2m_ctx, 68static struct v4l2_m2m_queue_ctx *get_queue_ctx(struct v4l2_m2m_ctx *m2m_ctx,
@@ -519,7 +519,7 @@ EXPORT_SYMBOL(v4l2_m2m_mmap);
519 * 519 *
520 * Usually called from driver's probe() function. 520 * Usually called from driver's probe() function.
521 */ 521 */
522struct v4l2_m2m_dev *v4l2_m2m_init(struct v4l2_m2m_ops *m2m_ops) 522struct v4l2_m2m_dev *v4l2_m2m_init(const struct v4l2_m2m_ops *m2m_ops)
523{ 523{
524 struct v4l2_m2m_dev *m2m_dev; 524 struct v4l2_m2m_dev *m2m_dev;
525 525
diff --git a/drivers/media/v4l2-core/videobuf-core.c b/drivers/media/v4l2-core/videobuf-core.c
index 5449e8aa984a..fb5ee5dd8fe9 100644
--- a/drivers/media/v4l2-core/videobuf-core.c
+++ b/drivers/media/v4l2-core/videobuf-core.c
@@ -340,7 +340,7 @@ static void videobuf_status(struct videobuf_queue *q, struct v4l2_buffer *b,
340 break; 340 break;
341 } 341 }
342 342
343 b->flags = 0; 343 b->flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
344 if (vb->map) 344 if (vb->map)
345 b->flags |= V4L2_BUF_FLAG_MAPPED; 345 b->flags |= V4L2_BUF_FLAG_MAPPED;
346 346
diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c
index e02c4797b1c6..db1235dcb328 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -40,9 +40,10 @@ module_param(debug, int, 0644);
40#define call_qop(q, op, args...) \ 40#define call_qop(q, op, args...) \
41 (((q)->ops->op) ? ((q)->ops->op(args)) : 0) 41 (((q)->ops->op) ? ((q)->ops->op(args)) : 0)
42 42
43#define V4L2_BUFFER_STATE_FLAGS (V4L2_BUF_FLAG_MAPPED | V4L2_BUF_FLAG_QUEUED | \ 43#define V4L2_BUFFER_MASK_FLAGS (V4L2_BUF_FLAG_MAPPED | V4L2_BUF_FLAG_QUEUED | \
44 V4L2_BUF_FLAG_DONE | V4L2_BUF_FLAG_ERROR | \ 44 V4L2_BUF_FLAG_DONE | V4L2_BUF_FLAG_ERROR | \
45 V4L2_BUF_FLAG_PREPARED) 45 V4L2_BUF_FLAG_PREPARED | \
46 V4L2_BUF_FLAG_TIMESTAMP_MASK)
46 47
47/** 48/**
48 * __vb2_buf_mem_alloc() - allocate video memory for the given buffer 49 * __vb2_buf_mem_alloc() - allocate video memory for the given buffer
@@ -401,7 +402,8 @@ static void __fill_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b)
401 /* 402 /*
402 * Clear any buffer state related flags. 403 * Clear any buffer state related flags.
403 */ 404 */
404 b->flags &= ~V4L2_BUFFER_STATE_FLAGS; 405 b->flags &= ~V4L2_BUFFER_MASK_FLAGS;
406 b->flags |= V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
405 407
406 switch (vb->state) { 408 switch (vb->state) {
407 case VB2_BUF_STATE_QUEUED: 409 case VB2_BUF_STATE_QUEUED:
@@ -941,7 +943,7 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b
941 943
942 vb->v4l2_buf.field = b->field; 944 vb->v4l2_buf.field = b->field;
943 vb->v4l2_buf.timestamp = b->timestamp; 945 vb->v4l2_buf.timestamp = b->timestamp;
944 vb->v4l2_buf.flags = b->flags & ~V4L2_BUFFER_STATE_FLAGS; 946 vb->v4l2_buf.flags = b->flags & ~V4L2_BUFFER_MASK_FLAGS;
945} 947}
946 948
947/** 949/**
@@ -1963,6 +1965,11 @@ unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait)
1963 poll_wait(file, &fh->wait, wait); 1965 poll_wait(file, &fh->wait, wait);
1964 } 1966 }
1965 1967
1968 if (!V4L2_TYPE_IS_OUTPUT(q->type) && !(req_events & (POLLIN | POLLRDNORM)))
1969 return res;
1970 if (V4L2_TYPE_IS_OUTPUT(q->type) && !(req_events & (POLLOUT | POLLWRNORM)))
1971 return res;
1972
1966 /* 1973 /*
1967 * Start file I/O emulator only if streaming API has not been used yet. 1974 * Start file I/O emulator only if streaming API has not been used yet.
1968 */ 1975 */
diff --git a/drivers/staging/media/Kconfig b/drivers/staging/media/Kconfig
index 427218b8b10f..ae0abc350e34 100644
--- a/drivers/staging/media/Kconfig
+++ b/drivers/staging/media/Kconfig
@@ -23,6 +23,8 @@ source "drivers/staging/media/as102/Kconfig"
23 23
24source "drivers/staging/media/cxd2099/Kconfig" 24source "drivers/staging/media/cxd2099/Kconfig"
25 25
26source "drivers/staging/media/davinci_vpfe/Kconfig"
27
26source "drivers/staging/media/dt3155v4l/Kconfig" 28source "drivers/staging/media/dt3155v4l/Kconfig"
27 29
28source "drivers/staging/media/go7007/Kconfig" 30source "drivers/staging/media/go7007/Kconfig"
diff --git a/drivers/staging/media/Makefile b/drivers/staging/media/Makefile
index aec6eb963940..2b97cae99499 100644
--- a/drivers/staging/media/Makefile
+++ b/drivers/staging/media/Makefile
@@ -4,3 +4,4 @@ obj-$(CONFIG_LIRC_STAGING) += lirc/
4obj-$(CONFIG_SOLO6X10) += solo6x10/ 4obj-$(CONFIG_SOLO6X10) += solo6x10/
5obj-$(CONFIG_VIDEO_DT3155) += dt3155v4l/ 5obj-$(CONFIG_VIDEO_DT3155) += dt3155v4l/
6obj-$(CONFIG_VIDEO_GO7007) += go7007/ 6obj-$(CONFIG_VIDEO_GO7007) += go7007/
7obj-$(CONFIG_VIDEO_DM365_VPFE) += davinci_vpfe/
diff --git a/drivers/staging/media/as102/as102_usb_drv.c b/drivers/staging/media/as102/as102_usb_drv.c
index aaf1bc2ad1b2..9f275f020150 100644
--- a/drivers/staging/media/as102/as102_usb_drv.c
+++ b/drivers/staging/media/as102/as102_usb_drv.c
@@ -374,10 +374,8 @@ static int as102_usb_probe(struct usb_interface *intf,
374 } 374 }
375 375
376 as102_dev = kzalloc(sizeof(struct as102_dev_t), GFP_KERNEL); 376 as102_dev = kzalloc(sizeof(struct as102_dev_t), GFP_KERNEL);
377 if (as102_dev == NULL) { 377 if (as102_dev == NULL)
378 dev_err(&intf->dev, "%s: kzalloc failed\n", __func__);
379 return -ENOMEM; 378 return -ENOMEM;
380 }
381 379
382 /* Assign the user-friendly device name */ 380 /* Assign the user-friendly device name */
383 for (i = 0; i < ARRAY_SIZE(as102_usb_id_table); i++) { 381 for (i = 0; i < ARRAY_SIZE(as102_usb_id_table); i++) {
diff --git a/drivers/staging/media/as102/as10x_cmd_cfg.c b/drivers/staging/media/as102/as10x_cmd_cfg.c
index d2a4bce89623..4a2bbd766655 100644
--- a/drivers/staging/media/as102/as10x_cmd_cfg.c
+++ b/drivers/staging/media/as102/as10x_cmd_cfg.c
@@ -197,7 +197,7 @@ out:
197 * @prsp: pointer to AS10x command response buffer 197 * @prsp: pointer to AS10x command response buffer
198 * @proc_id: id of the command 198 * @proc_id: id of the command
199 * 199 *
200 * Since the contex command reponse does not follow the common 200 * Since the contex command response does not follow the common
201 * response, a specific parse function is required. 201 * response, a specific parse function is required.
202 * Return 0 on success or negative value in case of error. 202 * Return 0 on success or negative value in case of error.
203 */ 203 */
diff --git a/drivers/staging/media/cxd2099/cxd2099.c b/drivers/staging/media/cxd2099/cxd2099.c
index 0ff19724992f..822c487592a4 100644
--- a/drivers/staging/media/cxd2099/cxd2099.c
+++ b/drivers/staging/media/cxd2099/cxd2099.c
@@ -66,8 +66,9 @@ static int i2c_write_reg(struct i2c_adapter *adapter, u8 adr,
66 struct i2c_msg msg = {.addr = adr, .flags = 0, .buf = m, .len = 2}; 66 struct i2c_msg msg = {.addr = adr, .flags = 0, .buf = m, .len = 2};
67 67
68 if (i2c_transfer(adapter, &msg, 1) != 1) { 68 if (i2c_transfer(adapter, &msg, 1) != 1) {
69 printk(KERN_ERR "Failed to write to I2C register %02x@%02x!\n", 69 dev_err(&adapter->dev,
70 reg, adr); 70 "Failed to write to I2C register %02x@%02x!\n",
71 reg, adr);
71 return -1; 72 return -1;
72 } 73 }
73 return 0; 74 return 0;
@@ -79,7 +80,7 @@ static int i2c_write(struct i2c_adapter *adapter, u8 adr,
79 struct i2c_msg msg = {.addr = adr, .flags = 0, .buf = data, .len = len}; 80 struct i2c_msg msg = {.addr = adr, .flags = 0, .buf = data, .len = len};
80 81
81 if (i2c_transfer(adapter, &msg, 1) != 1) { 82 if (i2c_transfer(adapter, &msg, 1) != 1) {
82 printk(KERN_ERR "Failed to write to I2C!\n"); 83 dev_err(&adapter->dev, "Failed to write to I2C!\n");
83 return -1; 84 return -1;
84 } 85 }
85 return 0; 86 return 0;
@@ -94,7 +95,7 @@ static int i2c_read_reg(struct i2c_adapter *adapter, u8 adr,
94 .buf = val, .len = 1} }; 95 .buf = val, .len = 1} };
95 96
96 if (i2c_transfer(adapter, msgs, 2) != 2) { 97 if (i2c_transfer(adapter, msgs, 2) != 2) {
97 printk(KERN_ERR "error in i2c_read_reg\n"); 98 dev_err(&adapter->dev, "error in i2c_read_reg\n");
98 return -1; 99 return -1;
99 } 100 }
100 return 0; 101 return 0;
@@ -109,7 +110,7 @@ static int i2c_read(struct i2c_adapter *adapter, u8 adr,
109 .buf = data, .len = n} }; 110 .buf = data, .len = n} };
110 111
111 if (i2c_transfer(adapter, msgs, 2) != 2) { 112 if (i2c_transfer(adapter, msgs, 2) != 2) {
112 printk(KERN_ERR "error in i2c_read\n"); 113 dev_err(&adapter->dev, "error in i2c_read\n");
113 return -1; 114 return -1;
114 } 115 }
115 return 0; 116 return 0;
@@ -277,7 +278,7 @@ static void cam_mode(struct cxd *ci, int mode)
277#ifdef BUFFER_MODE 278#ifdef BUFFER_MODE
278 if (!ci->en.read_data) 279 if (!ci->en.read_data)
279 return; 280 return;
280 printk(KERN_INFO "enable cam buffer mode\n"); 281 dev_info(&ci->i2c->dev, "enable cam buffer mode\n");
281 /* write_reg(ci, 0x0d, 0x00); */ 282 /* write_reg(ci, 0x0d, 0x00); */
282 /* write_reg(ci, 0x0e, 0x01); */ 283 /* write_reg(ci, 0x0e, 0x01); */
283 write_regm(ci, 0x08, 0x40, 0x40); 284 write_regm(ci, 0x08, 0x40, 0x40);
@@ -524,7 +525,7 @@ static int slot_reset(struct dvb_ca_en50221 *ca, int slot)
524 msleep(10); 525 msleep(10);
525#if 0 526#if 0
526 read_reg(ci, 0x06, &val); 527 read_reg(ci, 0x06, &val);
527 printk(KERN_INFO "%d:%02x\n", i, val); 528 dev_info(&ci->i2c->dev, "%d:%02x\n", i, val);
528 if (!(val&0x10)) 529 if (!(val&0x10))
529 break; 530 break;
530#else 531#else
@@ -542,7 +543,7 @@ static int slot_shutdown(struct dvb_ca_en50221 *ca, int slot)
542{ 543{
543 struct cxd *ci = ca->data; 544 struct cxd *ci = ca->data;
544 545
545 printk(KERN_INFO "slot_shutdown\n"); 546 dev_info(&ci->i2c->dev, "slot_shutdown\n");
546 mutex_lock(&ci->lock); 547 mutex_lock(&ci->lock);
547 write_regm(ci, 0x09, 0x08, 0x08); 548 write_regm(ci, 0x09, 0x08, 0x08);
548 write_regm(ci, 0x20, 0x80, 0x80); /* Reset CAM Mode */ 549 write_regm(ci, 0x20, 0x80, 0x80); /* Reset CAM Mode */
@@ -578,10 +579,10 @@ static int campoll(struct cxd *ci)
578 579
579 if (istat&0x40) { 580 if (istat&0x40) {
580 ci->dr = 1; 581 ci->dr = 1;
581 printk(KERN_INFO "DR\n"); 582 dev_info(&ci->i2c->dev, "DR\n");
582 } 583 }
583 if (istat&0x20) 584 if (istat&0x20)
584 printk(KERN_INFO "WC\n"); 585 dev_info(&ci->i2c->dev, "WC\n");
585 586
586 if (istat&2) { 587 if (istat&2) {
587 u8 slotstat; 588 u8 slotstat;
@@ -597,7 +598,7 @@ static int campoll(struct cxd *ci)
597 if (ci->slot_stat) { 598 if (ci->slot_stat) {
598 ci->slot_stat = 0; 599 ci->slot_stat = 0;
599 write_regm(ci, 0x03, 0x00, 0x08); 600 write_regm(ci, 0x03, 0x00, 0x08);
600 printk(KERN_INFO "NO CAM\n"); 601 dev_info(&ci->i2c->dev, "NO CAM\n");
601 ci->ready = 0; 602 ci->ready = 0;
602 } 603 }
603 } 604 }
@@ -634,7 +635,7 @@ static int read_data(struct dvb_ca_en50221 *ca, int slot, u8 *ebuf, int ecount)
634 campoll(ci); 635 campoll(ci);
635 mutex_unlock(&ci->lock); 636 mutex_unlock(&ci->lock);
636 637
637 printk(KERN_INFO "read_data\n"); 638 dev_info(&ci->i2c->dev, "read_data\n");
638 if (!ci->dr) 639 if (!ci->dr)
639 return 0; 640 return 0;
640 641
@@ -687,7 +688,7 @@ struct dvb_ca_en50221 *cxd2099_attach(struct cxd2099_cfg *cfg,
687 u8 val; 688 u8 val;
688 689
689 if (i2c_read_reg(i2c, cfg->adr, 0, &val) < 0) { 690 if (i2c_read_reg(i2c, cfg->adr, 0, &val) < 0) {
690 printk(KERN_INFO "No CXD2099 detected at %02x\n", cfg->adr); 691 dev_info(&i2c->dev, "No CXD2099 detected at %02x\n", cfg->adr);
691 return NULL; 692 return NULL;
692 } 693 }
693 694
@@ -705,7 +706,7 @@ struct dvb_ca_en50221 *cxd2099_attach(struct cxd2099_cfg *cfg,
705 ci->en = en_templ; 706 ci->en = en_templ;
706 ci->en.data = ci; 707 ci->en.data = ci;
707 init(ci); 708 init(ci);
708 printk(KERN_INFO "Attached CXD2099AR at %02x\n", ci->cfg.adr); 709 dev_info(&i2c->dev, "Attached CXD2099AR at %02x\n", ci->cfg.adr);
709 return &ci->en; 710 return &ci->en;
710} 711}
711EXPORT_SYMBOL(cxd2099_attach); 712EXPORT_SYMBOL(cxd2099_attach);
diff --git a/drivers/staging/media/cxd2099/cxd2099.h b/drivers/staging/media/cxd2099/cxd2099.h
index 19c588a59588..0eb607c5b423 100644
--- a/drivers/staging/media/cxd2099/cxd2099.h
+++ b/drivers/staging/media/cxd2099/cxd2099.h
@@ -43,7 +43,7 @@ struct dvb_ca_en50221 *cxd2099_attach(struct cxd2099_cfg *cfg,
43static inline struct dvb_ca_en50221 *cxd2099_attach(struct cxd2099_cfg *cfg, 43static inline struct dvb_ca_en50221 *cxd2099_attach(struct cxd2099_cfg *cfg,
44 void *priv, struct i2c_adapter *i2c) 44 void *priv, struct i2c_adapter *i2c)
45{ 45{
46 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 46 dev_warn(&i2c->dev, "%s: driver disabled by Kconfig\n", __func__);
47 return NULL; 47 return NULL;
48} 48}
49#endif 49#endif
diff --git a/drivers/staging/media/davinci_vpfe/Kconfig b/drivers/staging/media/davinci_vpfe/Kconfig
new file mode 100644
index 000000000000..2e4a28b018e8
--- /dev/null
+++ b/drivers/staging/media/davinci_vpfe/Kconfig
@@ -0,0 +1,9 @@
1config VIDEO_DM365_VPFE
2 tristate "DM365 VPFE Media Controller Capture Driver"
3 depends on VIDEO_V4L2 && ARCH_DAVINCI_DM365 && !VIDEO_VPFE_CAPTURE
4 select VIDEOBUF2_DMA_CONTIG
5 help
6 Support for DM365 VPFE based Media Controller Capture driver.
7
8 To compile this driver as a module, choose M here: the
9 module will be called vpfe-mc-capture.
diff --git a/drivers/staging/media/davinci_vpfe/Makefile b/drivers/staging/media/davinci_vpfe/Makefile
new file mode 100644
index 000000000000..c64515c644cd
--- /dev/null
+++ b/drivers/staging/media/davinci_vpfe/Makefile
@@ -0,0 +1,3 @@
1obj-$(CONFIG_VIDEO_DM365_VPFE) += \
2 dm365_isif.o dm365_ipipe_hw.o dm365_ipipe.o \
3 dm365_resizer.o dm365_ipipeif.o vpfe_mc_capture.o vpfe_video.o
diff --git a/drivers/staging/media/davinci_vpfe/TODO b/drivers/staging/media/davinci_vpfe/TODO
new file mode 100644
index 000000000000..7015ab35ded5
--- /dev/null
+++ b/drivers/staging/media/davinci_vpfe/TODO
@@ -0,0 +1,37 @@
1TODO (general):
2==================================
3
4- User space interface refinement
5 - Controls should be used when possible rather than private ioctl
6 - No enums should be used
7 - Use of MC and V4L2 subdev APIs when applicable
8 - Single interface header might suffice
9 - Current interface forces to configure everything at once
10- Get rid of the dm365_ipipe_hw.[ch] layer
11- Active external sub-devices defined by link configuration; no strcmp
12 needed
13- More generic platform data (i2c adapters)
14- The driver should have no knowledge of possible external subdevs; see
15 struct vpfe_subdev_id
16- Some of the hardware control should be refactorede
17- Check proper serialisation (through mutexes and spinlocks)
18- Names that are visible in kernel global namespace should have a common
19 prefix (or a few)
20- While replacing the older driver in media folder, provide a compatibility
21 layer and compatibility tests that warrants (using the libv4l's LD_PRELOAD
22 approach) there is no regression for the users using the older driver.
23
24Building of uImage and Applications:
25==================================
26
27As of now since the interface will undergo few changes all the include
28files are present in staging itself, to build for dm365 follow below steps,
29
30- copy vpfe.h from drivers/staging/media/davinci_vpfe/ to
31 include/media/davinci/ folder for building the uImage.
32- copy davinci_vpfe_user.h from drivers/staging/media/davinci_vpfe/ to
33 include/uapi/linux/davinci_vpfe.h, and add a entry in Kbuild (required
34 for building application).
35- copy dm365_ipipeif_user.h from drivers/staging/media/davinci_vpfe/ to
36 include/uapi/linux/dm365_ipipeif.h and a entry in Kbuild (required
37 for building application).
diff --git a/drivers/staging/media/davinci_vpfe/davinci-vpfe-mc.txt b/drivers/staging/media/davinci_vpfe/davinci-vpfe-mc.txt
new file mode 100644
index 000000000000..1dbd56418704
--- /dev/null
+++ b/drivers/staging/media/davinci_vpfe/davinci-vpfe-mc.txt
@@ -0,0 +1,154 @@
1Davinci Video processing Front End (VPFE) driver
2
3Copyright (C) 2012 Texas Instruments Inc
4
5Contacts: Manjunath Hadli <manjunath.hadli@ti.com>
6 Prabhakar Lad <prabhakar.lad@ti.com>
7
8
9Introduction
10============
11
12This file documents the Texas Instruments Davinci Video processing Front End
13(VPFE) driver located under drivers/media/platform/davinci. The original driver
14exists for Davinci VPFE, which is now being changed to Media Controller
15Framework.
16
17Currently the driver has been successfully used on the following
18version of Davinci:
19
20 DM365/DM368
21
22The driver implements V4L2, Media controller and v4l2_subdev interfaces. Sensor,
23lens and flash drivers using the v4l2_subdev interface in the kernel are
24supported.
25
26
27Split to subdevs
28================
29
30The Davinci VPFE is split into V4L2 subdevs, each of the blocks inside the VPFE
31having one subdev to represent it. Each of the subdevs provide a V4L2 subdev
32interface to userspace.
33
34 DAVINCI ISIF
35 DAVINCI IPIPEIF
36 DAVINCI IPIPE
37 DAVINCI CROP RESIZER
38 DAVINCI RESIZER A
39 DAVINCI RESIZER B
40
41Each possible link in the VPFE is modeled by a link in the Media controller
42interface. For an example program see [1].
43
44
45ISIF, IPIPE, and RESIZER block IOCTLs
46======================================
47
48The Davinci Video processing Front End (VPFE) driver supports standard V4L2
49IOCTLs and controls where possible and practical. Much of the functions provided
50by the VPFE, however, does not fall under the standard IOCTL's.
51
52In general, there is a private ioctl for configuring each of the blocks
53containing hardware-dependent functions.
54
55The following private IOCTLs are supported:
56
57 VIDIOC_VPFE_ISIF_[S/G]_RAW_PARAMS
58 VIDIOC_VPFE_IPIPE_[S/G]_CONFIG
59 VIDIOC_VPFE_RSZ_[S/G]_CONFIG
60
61The parameter structures used by these ioctl's are described in
62include/uapi/linux/davinci_vpfe.h.
63
64The VIDIOC_VPFE_ISIF_S_RAW_PARAMS, VIDIOC_VPFE_IPIPE_S_CONFIG and
65VIDIOC_VPFE_RSZ_S_CONFIG are used to configure, enable and disable functions in
66the isif, ipipe and resizer blocks respectively. These IOCTL's control several
67functions in the blocks they control. VIDIOC_VPFE_ISIF_S_RAW_PARAMS IOCTL
68accepts a pointer to struct vpfe_isif_raw_config as its argument. Similarly
69VIDIOC_VPFE_IPIPE_S_CONFIG accepts a pointer to struct vpfe_ipipe_config. And
70VIDIOC_VPFE_RSZ_S_CONFIG accepts a pointer to struct vpfe_rsz_config as its
71argument. Similarly VIDIOC_VPFE_ISIF_G_RAW_PARAMS, VIDIOC_VPFE_IPIPE_G_CONFIG
72and VIDIOC_VPFE_RSZ_G_CONFIG are used to get the current configuration set in
73the isif, ipipe and resizer blocks respectively.
74
75The detailed functions of the VPFE itself related to a given VPFE block is
76described in the Technical Reference Manuals (TRMs) --- see the end of the
77document for those.
78
79
80IPIPEIF block IOCTLs
81======================================
82
83The following private IOCTLs are supported:
84
85 VIDIOC_VPFE_IPIPEIF_[S/G]_CONFIG
86
87The parameter structures used by these ioctl's are described in
88include/uapi/linux/dm365_ipipeif.h
89
90The VIDIOC_VPFE_IPIPEIF_S_CONFIG is used to configure the ipipeif
91hardware block. The VIDIOC_VPFE_IPIPEIF_S_CONFIG and
92VIDIOC_VPFE_IPIPEIF_G_CONFIG accepts a pointer to struct ipipeif_params
93as its argument.
94
95
96VPFE Operating Modes
97==========================================
98
99a: Continuous Modes
100------------------------
101
1021: tvp514x/tvp7002/mt9p031---> DAVINCI ISIF---> SDRAM
103
1042: tvp514x/tvp7002/mt9p031---> DAVINCI ISIF---> DAVINCI IPIPEIF--->|
105 |
106 <--------------------<----------------<---------------------<---|
107 |
108 V
109 DAVINCI CROP RESIZER--->DAVINCI RESIZER [A/B]---> SDRAM
110
1113: tvp514x/tvp7002/mt9p031---> DAVINCI ISIF---> DAVINCI IPIPEIF--->|
112 |
113 <--------------------<----------------<---------------------<---|
114 |
115 V
116 DAVINCI IPIPE---> DAVINCI CROP RESIZER--->DAVINCI RESIZER [A/B]---> SDRAM
117
118a: Single Shot Modes
119------------------------
120
1211: SDRAM---> DAVINCI IPIPEIF---> DAVINCI IPIPE---> DAVINCI CROP RESIZER--->|
122 |
123 <----------------<----------------<------------------<---------------<--|
124 |
125 V
126DAVINCI RESIZER [A/B]---> SDRAM
127
1282: SDRAM---> DAVINCI IPIPEIF---> DAVINCI CROP RESIZER--->|
129 |
130 <----------------<----------------<---------------<---|
131 |
132 V
133DAVINCI RESIZER [A/B]---> SDRAM
134
135
136Technical reference manuals (TRMs) and other documentation
137==========================================================
138
139Davinci DM365 TRM:
140<URL:http://www.ti.com/lit/ds/sprs457e/sprs457e.pdf>
141Referenced MARCH 2009-REVISED JUNE 2011
142
143Davinci DM368 TRM:
144<URL:http://www.ti.com/lit/ds/sprs668c/sprs668c.pdf>
145Referenced APRIL 2010-REVISED JUNE 2011
146
147Davinci Video Processing Front End (VPFE) DM36x
148<URL:http://www.ti.com/lit/ug/sprufg8c/sprufg8c.pdf>
149
150
151References
152==========
153
154[1] http://git.ideasonboard.org/?p=media-ctl.git;a=summary
diff --git a/drivers/staging/media/davinci_vpfe/davinci_vpfe_user.h b/drivers/staging/media/davinci_vpfe/davinci_vpfe_user.h
new file mode 100644
index 000000000000..7b7e7b26c1e8
--- /dev/null
+++ b/drivers/staging/media/davinci_vpfe/davinci_vpfe_user.h
@@ -0,0 +1,1290 @@
1/*
2 * Copyright (C) 2012 Texas Instruments Inc
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation version 2.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Contributors:
18 * Manjunath Hadli <manjunath.hadli@ti.com>
19 * Prabhakar Lad <prabhakar.lad@ti.com>
20 */
21
22#ifndef _DAVINCI_VPFE_USER_H
23#define _DAVINCI_VPFE_USER_H
24
25#include <linux/types.h>
26#include <linux/videodev2.h>
27
28/*
29 * Private IOCTL
30 *
31 * VIDIOC_VPFE_ISIF_S_RAW_PARAMS: Set raw params in isif
32 * VIDIOC_VPFE_ISIF_G_RAW_PARAMS: Get raw params from isif
33 * VIDIOC_VPFE_PRV_S_CONFIG: Set ipipe engine configuration
34 * VIDIOC_VPFE_PRV_G_CONFIG: Get ipipe engine configuration
35 * VIDIOC_VPFE_RSZ_S_CONFIG: Set resizer engine configuration
36 * VIDIOC_VPFE_RSZ_G_CONFIG: Get resizer engine configuration
37 */
38
39#define VIDIOC_VPFE_ISIF_S_RAW_PARAMS \
40 _IOW('V', BASE_VIDIOC_PRIVATE + 1, struct vpfe_isif_raw_config)
41#define VIDIOC_VPFE_ISIF_G_RAW_PARAMS \
42 _IOR('V', BASE_VIDIOC_PRIVATE + 2, struct vpfe_isif_raw_config)
43#define VIDIOC_VPFE_IPIPE_S_CONFIG \
44 _IOWR('P', BASE_VIDIOC_PRIVATE + 3, struct vpfe_ipipe_config)
45#define VIDIOC_VPFE_IPIPE_G_CONFIG \
46 _IOWR('P', BASE_VIDIOC_PRIVATE + 4, struct vpfe_ipipe_config)
47#define VIDIOC_VPFE_RSZ_S_CONFIG \
48 _IOWR('R', BASE_VIDIOC_PRIVATE + 5, struct vpfe_rsz_config)
49#define VIDIOC_VPFE_RSZ_G_CONFIG \
50 _IOWR('R', BASE_VIDIOC_PRIVATE + 6, struct vpfe_rsz_config)
51
52/*
53 * Private Control's for ISIF
54 */
55#define VPFE_ISIF_CID_CRGAIN (V4L2_CID_USER_BASE | 0xa001)
56#define VPFE_ISIF_CID_CGRGAIN (V4L2_CID_USER_BASE | 0xa002)
57#define VPFE_ISIF_CID_CGBGAIN (V4L2_CID_USER_BASE | 0xa003)
58#define VPFE_ISIF_CID_CBGAIN (V4L2_CID_USER_BASE | 0xa004)
59#define VPFE_ISIF_CID_GAIN_OFFSET (V4L2_CID_USER_BASE | 0xa005)
60
61/*
62 * Private Control's for ISIF and IPIPEIF
63 */
64#define VPFE_CID_DPCM_PREDICTOR (V4L2_CID_USER_BASE | 0xa006)
65
66/************************************************************************
67 * Vertical Defect Correction parameters
68 ***********************************************************************/
69
70/**
71 * vertical defect correction methods
72 */
73enum vpfe_isif_vdfc_corr_mode {
74 /* Defect level subtraction. Just fed through if saturating */
75 VPFE_ISIF_VDFC_NORMAL,
76 /**
77 * Defect level subtraction. Horizontal interpolation ((i-2)+(i+2))/2
78 * if data saturating
79 */
80 VPFE_ISIF_VDFC_HORZ_INTERPOL_IF_SAT,
81 /* Horizontal interpolation (((i-2)+(i+2))/2) */
82 VPFE_ISIF_VDFC_HORZ_INTERPOL
83};
84
85/**
86 * Max Size of the Vertical Defect Correction table
87 */
88#define VPFE_ISIF_VDFC_TABLE_SIZE 8
89
90/**
91 * Values used for shifting up the vdfc defect level
92 */
93enum vpfe_isif_vdfc_shift {
94 /* No Shift */
95 VPFE_ISIF_VDFC_NO_SHIFT,
96 /* Shift by 1 bit */
97 VPFE_ISIF_VDFC_SHIFT_1,
98 /* Shift by 2 bit */
99 VPFE_ISIF_VDFC_SHIFT_2,
100 /* Shift by 3 bit */
101 VPFE_ISIF_VDFC_SHIFT_3,
102 /* Shift by 4 bit */
103 VPFE_ISIF_VDFC_SHIFT_4
104};
105
106/**
107 * Defect Correction (DFC) table entry
108 */
109struct vpfe_isif_vdfc_entry {
110 /* vertical position of defect */
111 unsigned short pos_vert;
112 /* horizontal position of defect */
113 unsigned short pos_horz;
114 /**
115 * Defect level of Vertical line defect position. This is subtracted
116 * from the data at the defect position
117 */
118 unsigned char level_at_pos;
119 /**
120 * Defect level of the pixels upper than the vertical line defect.
121 * This is subtracted from the data
122 */
123 unsigned char level_up_pixels;
124 /**
125 * Defect level of the pixels lower than the vertical line defect.
126 * This is subtracted from the data
127 */
128 unsigned char level_low_pixels;
129};
130
131/**
132 * Structure for Defect Correction (DFC) parameter
133 */
134struct vpfe_isif_dfc {
135 /* enable vertical defect correction */
136 unsigned char en;
137 /* Correction methods */
138 enum vpfe_isif_vdfc_corr_mode corr_mode;
139 /**
140 * 0 - whole line corrected, 1 - not
141 * pixels upper than the defect
142 */
143 unsigned char corr_whole_line;
144 /**
145 * defect level shift value. level_at_pos, level_upper_pos,
146 * and level_lower_pos can be shifted up by this value
147 */
148 enum vpfe_isif_vdfc_shift def_level_shift;
149 /* defect saturation level */
150 unsigned short def_sat_level;
151 /* number of vertical defects. Max is VPFE_ISIF_VDFC_TABLE_SIZE */
152 short num_vdefects;
153 /* VDFC table ptr */
154 struct vpfe_isif_vdfc_entry table[VPFE_ISIF_VDFC_TABLE_SIZE];
155};
156
157/************************************************************************
158* Digital/Black clamp or DC Subtract parameters
159************************************************************************/
160/**
161 * Horizontal Black Clamp modes
162 */
163enum vpfe_isif_horz_bc_mode {
164 /**
165 * Horizontal clamp disabled. Only vertical clamp
166 * value is subtracted
167 */
168 VPFE_ISIF_HORZ_BC_DISABLE,
169 /**
170 * Horizontal clamp value is calculated and subtracted
171 * from image data along with vertical clamp value
172 */
173 VPFE_ISIF_HORZ_BC_CLAMP_CALC_ENABLED,
174 /**
175 * Horizontal clamp value calculated from previous image
176 * is subtracted from image data along with vertical clamp
177 * value. How the horizontal clamp value for the first image
178 * is calculated in this case ???
179 */
180 VPFE_ISIF_HORZ_BC_CLAMP_NOT_UPDATED
181};
182
183/**
184 * Base window selection for Horizontal Black Clamp calculations
185 */
186enum vpfe_isif_horz_bc_base_win_sel {
187 /* Select Most left window for bc calculation */
188 VPFE_ISIF_SEL_MOST_LEFT_WIN,
189
190 /* Select Most right window for bc calculation */
191 VPFE_ISIF_SEL_MOST_RIGHT_WIN,
192};
193
194/* Size of window in horizontal direction for horizontal bc */
195enum vpfe_isif_horz_bc_sz_h {
196 VPFE_ISIF_HORZ_BC_SZ_H_2PIXELS,
197 VPFE_ISIF_HORZ_BC_SZ_H_4PIXELS,
198 VPFE_ISIF_HORZ_BC_SZ_H_8PIXELS,
199 VPFE_ISIF_HORZ_BC_SZ_H_16PIXELS
200};
201
202/* Size of window in vertcal direction for vertical bc */
203enum vpfe_isif_horz_bc_sz_v {
204 VPFE_ISIF_HORZ_BC_SZ_H_32PIXELS,
205 VPFE_ISIF_HORZ_BC_SZ_H_64PIXELS,
206 VPFE_ISIF_HORZ_BC_SZ_H_128PIXELS,
207 VPFE_ISIF_HORZ_BC_SZ_H_256PIXELS
208};
209
210/**
211 * Structure for Horizontal Black Clamp config params
212 */
213struct vpfe_isif_horz_bclamp {
214 /* horizontal clamp mode */
215 enum vpfe_isif_horz_bc_mode mode;
216 /**
217 * pixel value limit enable.
218 * 0 - limit disabled
219 * 1 - pixel value limited to 1023
220 */
221 unsigned char clamp_pix_limit;
222 /**
223 * Select most left or right window for clamp val
224 * calculation
225 */
226 enum vpfe_isif_horz_bc_base_win_sel base_win_sel_calc;
227 /* Window count per color for calculation. range 1-32 */
228 unsigned char win_count_calc;
229 /* Window start position - horizontal for calculation. 0 - 8191 */
230 unsigned short win_start_h_calc;
231 /* Window start position - vertical for calculation 0 - 8191 */
232 unsigned short win_start_v_calc;
233 /* Width of the sample window in pixels for calculation */
234 enum vpfe_isif_horz_bc_sz_h win_h_sz_calc;
235 /* Height of the sample window in pixels for calculation */
236 enum vpfe_isif_horz_bc_sz_v win_v_sz_calc;
237};
238
239/**
240 * Black Clamp vertical reset values
241 */
242enum vpfe_isif_vert_bc_reset_val_sel {
243 /* Reset value used is the clamp value calculated */
244 VPFE_ISIF_VERT_BC_USE_HORZ_CLAMP_VAL,
245 /* Reset value used is reset_clamp_val configured */
246 VPFE_ISIF_VERT_BC_USE_CONFIG_CLAMP_VAL,
247 /* No update, previous image value is used */
248 VPFE_ISIF_VERT_BC_NO_UPDATE
249};
250
251enum vpfe_isif_vert_bc_sz_h {
252 VPFE_ISIF_VERT_BC_SZ_H_2PIXELS,
253 VPFE_ISIF_VERT_BC_SZ_H_4PIXELS,
254 VPFE_ISIF_VERT_BC_SZ_H_8PIXELS,
255 VPFE_ISIF_VERT_BC_SZ_H_16PIXELS,
256 VPFE_ISIF_VERT_BC_SZ_H_32PIXELS,
257 VPFE_ISIF_VERT_BC_SZ_H_64PIXELS
258};
259
260/**
261 * Structure for Vertical Black Clamp configuration params
262 */
263struct vpfe_isif_vert_bclamp {
264 /* Reset value selection for vertical clamp calculation */
265 enum vpfe_isif_vert_bc_reset_val_sel reset_val_sel;
266 /* U12 value if reset_sel = ISIF_BC_VERT_USE_CONFIG_CLAMP_VAL */
267 unsigned short reset_clamp_val;
268 /**
269 * U8Q8. Line average coefficient used in vertical clamp
270 * calculation
271 */
272 unsigned char line_ave_coef;
273 /* Width in pixels of the optical black region used for calculation. */
274 enum vpfe_isif_vert_bc_sz_h ob_h_sz_calc;
275 /* Height of the optical black region for calculation */
276 unsigned short ob_v_sz_calc;
277 /* Optical black region start position - horizontal. 0 - 8191 */
278 unsigned short ob_start_h;
279 /* Optical black region start position - vertical 0 - 8191 */
280 unsigned short ob_start_v;
281};
282
283/**
284 * Structure for Black Clamp configuration params
285 */
286struct vpfe_isif_black_clamp {
287 /**
288 * this offset value is added irrespective of the clamp
289 * enable status. S13
290 */
291 unsigned short dc_offset;
292 /**
293 * Enable black/digital clamp value to be subtracted
294 * from the image data
295 */
296 unsigned char en;
297 /**
298 * black clamp mode. same/separate clamp for 4 colors
299 * 0 - disable - same clamp value for all colors
300 * 1 - clamp value calculated separately for all colors
301 */
302 unsigned char bc_mode_color;
303 /* Vertical start position for bc subtraction */
304 unsigned short vert_start_sub;
305 /* Black clamp for horizontal direction */
306 struct vpfe_isif_horz_bclamp horz;
307 /* Black clamp for vertical direction */
308 struct vpfe_isif_vert_bclamp vert;
309};
310
311/*************************************************************************
312** Color Space Conversion (CSC)
313*************************************************************************/
314/**
315 * Number of Coefficient values used for CSC
316 */
317#define VPFE_ISIF_CSC_NUM_COEFF 16
318
319struct float_8_bit {
320 /* 8 bit integer part */
321 __u8 integer;
322 /* 8 bit decimal part */
323 __u8 decimal;
324};
325
326struct float_16_bit {
327 /* 16 bit integer part */
328 __u16 integer;
329 /* 16 bit decimal part */
330 __u16 decimal;
331};
332
333/*************************************************************************
334** Color Space Conversion parameters
335*************************************************************************/
336/**
337 * Structure used for CSC config params
338 */
339struct vpfe_isif_color_space_conv {
340 /* Enable color space conversion */
341 unsigned char en;
342 /**
343 * csc coefficient table. S8Q5, M00 at index 0, M01 at index 1, and
344 * so forth
345 */
346 struct float_8_bit coeff[VPFE_ISIF_CSC_NUM_COEFF];
347};
348
349enum vpfe_isif_datasft {
350 /* No Shift */
351 VPFE_ISIF_NO_SHIFT,
352 /* 1 bit Shift */
353 VPFE_ISIF_1BIT_SHIFT,
354 /* 2 bit Shift */
355 VPFE_ISIF_2BIT_SHIFT,
356 /* 3 bit Shift */
357 VPFE_ISIF_3BIT_SHIFT,
358 /* 4 bit Shift */
359 VPFE_ISIF_4BIT_SHIFT,
360 /* 5 bit Shift */
361 VPFE_ISIF_5BIT_SHIFT,
362 /* 6 bit Shift */
363 VPFE_ISIF_6BIT_SHIFT
364};
365
366#define VPFE_ISIF_LINEAR_TAB_SIZE 192
367/*************************************************************************
368** Linearization parameters
369*************************************************************************/
370/**
371 * Structure for Sensor data linearization
372 */
373struct vpfe_isif_linearize {
374 /* Enable or Disable linearization of data */
375 unsigned char en;
376 /* Shift value applied */
377 enum vpfe_isif_datasft corr_shft;
378 /* scale factor applied U11Q10 */
379 struct float_16_bit scale_fact;
380 /* Size of the linear table */
381 unsigned short table[VPFE_ISIF_LINEAR_TAB_SIZE];
382};
383
384/*************************************************************************
385** ISIF Raw configuration parameters
386*************************************************************************/
387enum vpfe_isif_fmt_mode {
388 VPFE_ISIF_SPLIT,
389 VPFE_ISIF_COMBINE
390};
391
392enum vpfe_isif_lnum {
393 VPFE_ISIF_1LINE,
394 VPFE_ISIF_2LINES,
395 VPFE_ISIF_3LINES,
396 VPFE_ISIF_4LINES
397};
398
399enum vpfe_isif_line {
400 VPFE_ISIF_1STLINE,
401 VPFE_ISIF_2NDLINE,
402 VPFE_ISIF_3RDLINE,
403 VPFE_ISIF_4THLINE
404};
405
406struct vpfe_isif_fmtplen {
407 /**
408 * number of program entries for SET0, range 1 - 16
409 * when fmtmode is ISIF_SPLIT, 1 - 8 when fmtmode is
410 * ISIF_COMBINE
411 */
412 unsigned short plen0;
413 /**
414 * number of program entries for SET1, range 1 - 16
415 * when fmtmode is ISIF_SPLIT, 1 - 8 when fmtmode is
416 * ISIF_COMBINE
417 */
418 unsigned short plen1;
419 /**
420 * number of program entries for SET2, range 1 - 16
421 * when fmtmode is ISIF_SPLIT, 1 - 8 when fmtmode is
422 * ISIF_COMBINE
423 */
424 unsigned short plen2;
425 /**
426 * number of program entries for SET3, range 1 - 16
427 * when fmtmode is ISIF_SPLIT, 1 - 8 when fmtmode is
428 * ISIF_COMBINE
429 */
430 unsigned short plen3;
431};
432
433struct vpfe_isif_fmt_cfg {
434 /* Split or combine or line alternate */
435 enum vpfe_isif_fmt_mode fmtmode;
436 /* enable or disable line alternating mode */
437 unsigned char ln_alter_en;
438 /* Split/combine line number */
439 enum vpfe_isif_lnum lnum;
440 /* Address increment Range 1 - 16 */
441 unsigned int addrinc;
442};
443
444struct vpfe_isif_fmt_addr_ptr {
445 /* Initial address */
446 unsigned int init_addr;
447 /* output line number */
448 enum vpfe_isif_line out_line;
449};
450
451struct vpfe_isif_fmtpgm_ap {
452 /* program address pointer */
453 unsigned char pgm_aptr;
454 /* program address increment or decrement */
455 unsigned char pgmupdt;
456};
457
458struct vpfe_isif_data_formatter {
459 /* Enable/Disable data formatter */
460 unsigned char en;
461 /* data formatter configuration */
462 struct vpfe_isif_fmt_cfg cfg;
463 /* Formatter program entries length */
464 struct vpfe_isif_fmtplen plen;
465 /* first pixel in a line fed to formatter */
466 unsigned short fmtrlen;
467 /* HD interval for output line. Only valid when split line */
468 unsigned short fmthcnt;
469 /* formatter address pointers */
470 struct vpfe_isif_fmt_addr_ptr fmtaddr_ptr[16];
471 /* program enable/disable */
472 unsigned char pgm_en[32];
473 /* program address pointers */
474 struct vpfe_isif_fmtpgm_ap fmtpgm_ap[32];
475};
476
477struct vpfe_isif_df_csc {
478 /* Color Space Conversion configuration, 0 - csc, 1 - df */
479 unsigned int df_or_csc;
480 /* csc configuration valid if df_or_csc is 0 */
481 struct vpfe_isif_color_space_conv csc;
482 /* data formatter configuration valid if df_or_csc is 1 */
483 struct vpfe_isif_data_formatter df;
484 /* start pixel in a line at the input */
485 unsigned int start_pix;
486 /* number of pixels in input line */
487 unsigned int num_pixels;
488 /* start line at the input */
489 unsigned int start_line;
490 /* number of lines at the input */
491 unsigned int num_lines;
492};
493
494struct vpfe_isif_gain_offsets_adj {
495 /* Enable or Disable Gain adjustment for SDRAM data */
496 unsigned char gain_sdram_en;
497 /* Enable or Disable Gain adjustment for IPIPE data */
498 unsigned char gain_ipipe_en;
499 /* Enable or Disable Gain adjustment for H3A data */
500 unsigned char gain_h3a_en;
501 /* Enable or Disable Gain adjustment for SDRAM data */
502 unsigned char offset_sdram_en;
503 /* Enable or Disable Gain adjustment for IPIPE data */
504 unsigned char offset_ipipe_en;
505 /* Enable or Disable Gain adjustment for H3A data */
506 unsigned char offset_h3a_en;
507};
508
509struct vpfe_isif_cul {
510 /* Horizontal Cull pattern for odd lines */
511 unsigned char hcpat_odd;
512 /* Horizontal Cull pattern for even lines */
513 unsigned char hcpat_even;
514 /* Vertical Cull pattern */
515 unsigned char vcpat;
516 /* Enable or disable lpf. Apply when cull is enabled */
517 unsigned char en_lpf;
518};
519
520/* all the stuff in this struct will be provided by userland */
521struct vpfe_isif_raw_config {
522 /* Linearization parameters for image sensor data input */
523 struct vpfe_isif_linearize linearize;
524 /* Data formatter or CSC */
525 struct vpfe_isif_df_csc df_csc;
526 /* Defect Pixel Correction (DFC) confguration */
527 struct vpfe_isif_dfc dfc;
528 /* Black/Digital Clamp configuration */
529 struct vpfe_isif_black_clamp bclamp;
530 /* Gain, offset adjustments */
531 struct vpfe_isif_gain_offsets_adj gain_offset;
532 /* Culling */
533 struct vpfe_isif_cul culling;
534 /* horizontal offset for Gain/LSC/DFC */
535 unsigned short horz_offset;
536 /* vertical offset for Gain/LSC/DFC */
537 unsigned short vert_offset;
538};
539
540/**********************************************************************
541 IPIPE API Structures
542**********************************************************************/
543
544/* IPIPE module configurations */
545
546/* IPIPE input configuration */
547#define VPFE_IPIPE_INPUT_CONFIG (1 << 0)
548/* LUT based Defect Pixel Correction */
549#define VPFE_IPIPE_LUTDPC (1 << 1)
550/* On the fly (OTF) Defect Pixel Correction */
551#define VPFE_IPIPE_OTFDPC (1 << 2)
552/* Noise Filter - 1 */
553#define VPFE_IPIPE_NF1 (1 << 3)
554/* Noise Filter - 2 */
555#define VPFE_IPIPE_NF2 (1 << 4)
556/* White Balance. Also a control ID */
557#define VPFE_IPIPE_WB (1 << 5)
558/* 1st RGB to RBG Blend module */
559#define VPFE_IPIPE_RGB2RGB_1 (1 << 6)
560/* 2nd RGB to RBG Blend module */
561#define VPFE_IPIPE_RGB2RGB_2 (1 << 7)
562/* Gamma Correction */
563#define VPFE_IPIPE_GAMMA (1 << 8)
564/* 3D LUT color conversion */
565#define VPFE_IPIPE_3D_LUT (1 << 9)
566/* RGB to YCbCr module */
567#define VPFE_IPIPE_RGB2YUV (1 << 10)
568/* YUV 422 conversion module */
569#define VPFE_IPIPE_YUV422_CONV (1 << 11)
570/* Edge Enhancement */
571#define VPFE_IPIPE_YEE (1 << 12)
572/* Green Imbalance Correction */
573#define VPFE_IPIPE_GIC (1 << 13)
574/* CFA Interpolation */
575#define VPFE_IPIPE_CFA (1 << 14)
576/* Chroma Artifact Reduction */
577#define VPFE_IPIPE_CAR (1 << 15)
578/* Chroma Gain Suppression */
579#define VPFE_IPIPE_CGS (1 << 16)
580/* Global brightness and contrast control */
581#define VPFE_IPIPE_GBCE (1 << 17)
582
583#define VPFE_IPIPE_MAX_MODULES 18
584
585struct ipipe_float_u16 {
586 unsigned short integer;
587 unsigned short decimal;
588};
589
590struct ipipe_float_s16 {
591 short integer;
592 unsigned short decimal;
593};
594
595struct ipipe_float_u8 {
596 unsigned char integer;
597 unsigned char decimal;
598};
599
600/* Copy method selection for vertical correction
601 * Used when ipipe_dfc_corr_meth is IPIPE_DPC_CTORB_AFTER_HINT
602 */
603enum vpfe_ipipe_dpc_corr_meth {
604 /* replace by black or white dot specified by repl_white */
605 VPFE_IPIPE_DPC_REPL_BY_DOT = 0,
606 /* Copy from left */
607 VPFE_IPIPE_DPC_CL = 1,
608 /* Copy from right */
609 VPFE_IPIPE_DPC_CR = 2,
610 /* Horizontal interpolation */
611 VPFE_IPIPE_DPC_H_INTP = 3,
612 /* Vertical interpolation */
613 VPFE_IPIPE_DPC_V_INTP = 4,
614 /* Copy from top */
615 VPFE_IPIPE_DPC_CT = 5,
616 /* Copy from bottom */
617 VPFE_IPIPE_DPC_CB = 6,
618 /* 2D interpolation */
619 VPFE_IPIPE_DPC_2D_INTP = 7,
620};
621
622struct vpfe_ipipe_lutdpc_entry {
623 /* Horizontal position */
624 unsigned short horz_pos;
625 /* vertical position */
626 unsigned short vert_pos;
627 enum vpfe_ipipe_dpc_corr_meth method;
628};
629
630#define VPFE_IPIPE_MAX_SIZE_DPC 256
631
632/* Structure for configuring DPC module */
633struct vpfe_ipipe_lutdpc {
634 /* 0 - disable, 1 - enable */
635 unsigned char en;
636 /* 0 - replace with black dot, 1 - white dot when correction
637 * method is IPIPE_DFC_REPL_BY_DOT=0,
638 */
639 unsigned char repl_white;
640 /* number of entries in the correction table. Currently only
641 * support up-to 256 entries. infinite mode is not supported
642 */
643 unsigned short dpc_size;
644 struct vpfe_ipipe_lutdpc_entry table[VPFE_IPIPE_MAX_SIZE_DPC];
645};
646
647enum vpfe_ipipe_otfdpc_det_meth {
648 VPFE_IPIPE_DPC_OTF_MIN_MAX,
649 VPFE_IPIPE_DPC_OTF_MIN_MAX2
650};
651
652struct vpfe_ipipe_otfdpc_thr {
653 unsigned short r;
654 unsigned short gr;
655 unsigned short gb;
656 unsigned short b;
657};
658
659enum vpfe_ipipe_otfdpc_alg {
660 VPFE_IPIPE_OTFDPC_2_0,
661 VPFE_IPIPE_OTFDPC_3_0
662};
663
664struct vpfe_ipipe_otfdpc_2_0_cfg {
665 /* defect detection threshold for MIN_MAX2 method (DPC 2.0 alg) */
666 struct vpfe_ipipe_otfdpc_thr det_thr;
667 /* defect correction threshold for MIN_MAX2 method (DPC 2.0 alg) or
668 * maximum value for MIN_MAX method
669 */
670 struct vpfe_ipipe_otfdpc_thr corr_thr;
671};
672
673struct vpfe_ipipe_otfdpc_3_0_cfg {
674 /* DPC3.0 activity adj shf. activity = (max2-min2) >> (6 -shf)
675 */
676 unsigned char act_adj_shf;
677 /* DPC3.0 detection threshold, THR */
678 unsigned short det_thr;
679 /* DPC3.0 detection threshold slope, SLP */
680 unsigned short det_slp;
681 /* DPC3.0 detection threshold min, MIN */
682 unsigned short det_thr_min;
683 /* DPC3.0 detection threshold max, MAX */
684 unsigned short det_thr_max;
685 /* DPC3.0 correction threshold, THR */
686 unsigned short corr_thr;
687 /* DPC3.0 correction threshold slope, SLP */
688 unsigned short corr_slp;
689 /* DPC3.0 correction threshold min, MIN */
690 unsigned short corr_thr_min;
691 /* DPC3.0 correction threshold max, MAX */
692 unsigned short corr_thr_max;
693};
694
695struct vpfe_ipipe_otfdpc {
696 /* 0 - disable, 1 - enable */
697 unsigned char en;
698 /* defect detection method */
699 enum vpfe_ipipe_otfdpc_det_meth det_method;
700 /* Algorithm used. Applicable only when IPIPE_DPC_OTF_MIN_MAX2 is
701 * used
702 */
703 enum vpfe_ipipe_otfdpc_alg alg;
704 union {
705 /* if alg is IPIPE_OTFDPC_2_0 */
706 struct vpfe_ipipe_otfdpc_2_0_cfg dpc_2_0;
707 /* if alg is IPIPE_OTFDPC_3_0 */
708 struct vpfe_ipipe_otfdpc_3_0_cfg dpc_3_0;
709 } alg_cfg;
710};
711
712/* Threshold values table size */
713#define VPFE_IPIPE_NF_THR_TABLE_SIZE 8
714/* Intensity values table size */
715#define VPFE_IPIPE_NF_STR_TABLE_SIZE 8
716
717/* NF, sampling method for green pixels */
718enum vpfe_ipipe_nf_sampl_meth {
719 /* Same as R or B */
720 VPFE_IPIPE_NF_BOX,
721 /* Diamond mode */
722 VPFE_IPIPE_NF_DIAMOND
723};
724
725/* Structure for configuring NF module */
726struct vpfe_ipipe_nf {
727 /* 0 - disable, 1 - enable */
728 unsigned char en;
729 /* Sampling method for green pixels */
730 enum vpfe_ipipe_nf_sampl_meth gr_sample_meth;
731 /* Down shift value in LUT reference address
732 */
733 unsigned char shft_val;
734 /* Spread value in NF algorithm
735 */
736 unsigned char spread_val;
737 /* Apply LSC gain to threshold. Enable this only if
738 * LSC is enabled in ISIF
739 */
740 unsigned char apply_lsc_gain;
741 /* Threshold values table */
742 unsigned short thr[VPFE_IPIPE_NF_THR_TABLE_SIZE];
743 /* intensity values table */
744 unsigned char str[VPFE_IPIPE_NF_STR_TABLE_SIZE];
745 /* Edge detection minimum threshold */
746 unsigned short edge_det_min_thr;
747 /* Edge detection maximum threshold */
748 unsigned short edge_det_max_thr;
749};
750
751enum vpfe_ipipe_gic_alg {
752 VPFE_IPIPE_GIC_ALG_CONST_GAIN,
753 VPFE_IPIPE_GIC_ALG_ADAPT_GAIN
754};
755
756enum vpfe_ipipe_gic_thr_sel {
757 VPFE_IPIPE_GIC_THR_REG,
758 VPFE_IPIPE_GIC_THR_NF
759};
760
761enum vpfe_ipipe_gic_wt_fn_type {
762 /* Use difference as index */
763 VPFE_IPIPE_GIC_WT_FN_TYP_DIF,
764 /* Use weight function as index */
765 VPFE_IPIPE_GIC_WT_FN_TYP_HP_VAL
766};
767
768/* structure for Green Imbalance Correction */
769struct vpfe_ipipe_gic {
770 /* 0 - disable, 1 - enable */
771 unsigned char en;
772 /* 0 - Constant gain , 1 - Adaptive gain algorithm */
773 enum vpfe_ipipe_gic_alg gic_alg;
774 /* GIC gain or weight. Used for Constant gain and Adaptive algorithms
775 */
776 unsigned short gain;
777 /* Threshold selection. GIC register values or NF2 thr table */
778 enum vpfe_ipipe_gic_thr_sel thr_sel;
779 /* thr1. Used when thr_sel is IPIPE_GIC_THR_REG */
780 unsigned short thr;
781 /* this value is used for thr2-thr1, thr3-thr2 or
782 * thr4-thr3 when wt_fn_type is index. Otherwise it
783 * is the
784 */
785 unsigned short slope;
786 /* Apply LSC gain to threshold. Enable this only if
787 * LSC is enabled in ISIF & thr_sel is IPIPE_GIC_THR_REG
788 */
789 unsigned char apply_lsc_gain;
790 /* Multiply Nf2 threshold by this gain. Use this when thr_sel
791 * is IPIPE_GIC_THR_NF
792 */
793 struct ipipe_float_u8 nf2_thr_gain;
794 /* Weight function uses difference as index or high pass value.
795 * Used for adaptive gain algorithm
796 */
797 enum vpfe_ipipe_gic_wt_fn_type wt_fn_type;
798};
799
800/* Structure for configuring WB module */
801struct vpfe_ipipe_wb {
802 /* Offset (S12) for R */
803 short ofst_r;
804 /* Offset (S12) for Gr */
805 short ofst_gr;
806 /* Offset (S12) for Gb */
807 short ofst_gb;
808 /* Offset (S12) for B */
809 short ofst_b;
810 /* Gain (U13Q9) for Red */
811 struct ipipe_float_u16 gain_r;
812 /* Gain (U13Q9) for Gr */
813 struct ipipe_float_u16 gain_gr;
814 /* Gain (U13Q9) for Gb */
815 struct ipipe_float_u16 gain_gb;
816 /* Gain (U13Q9) for Blue */
817 struct ipipe_float_u16 gain_b;
818};
819
820enum vpfe_ipipe_cfa_alg {
821 /* Algorithm is 2DirAC */
822 VPFE_IPIPE_CFA_ALG_2DIRAC,
823 /* Algorithm is 2DirAC + Digital Antialiasing (DAA) */
824 VPFE_IPIPE_CFA_ALG_2DIRAC_DAA,
825 /* Algorithm is DAA */
826 VPFE_IPIPE_CFA_ALG_DAA
827};
828
829/* Structure for CFA Interpolation */
830struct vpfe_ipipe_cfa {
831 /* 2DirAC or 2DirAC + DAA */
832 enum vpfe_ipipe_cfa_alg alg;
833 /* 2Dir CFA HP value Low Threshold */
834 unsigned short hpf_thr_2dir;
835 /* 2Dir CFA HP value slope */
836 unsigned short hpf_slp_2dir;
837 /* 2Dir CFA HP mix threshold */
838 unsigned short hp_mix_thr_2dir;
839 /* 2Dir CFA HP mix slope */
840 unsigned short hp_mix_slope_2dir;
841 /* 2Dir Direction threshold */
842 unsigned short dir_thr_2dir;
843 /* 2Dir Direction slope */
844 unsigned short dir_slope_2dir;
845 /* 2Dir Non Directional Weight */
846 unsigned short nd_wt_2dir;
847 /* DAA Mono Hue Fraction */
848 unsigned short hue_fract_daa;
849 /* DAA Mono Edge threshold */
850 unsigned short edge_thr_daa;
851 /* DAA Mono threshold minimum */
852 unsigned short thr_min_daa;
853 /* DAA Mono threshold slope */
854 unsigned short thr_slope_daa;
855 /* DAA Mono slope minimum */
856 unsigned short slope_min_daa;
857 /* DAA Mono slope slope */
858 unsigned short slope_slope_daa;
859 /* DAA Mono LP wight */
860 unsigned short lp_wt_daa;
861};
862
863/* Struct for configuring RGB2RGB blending module */
864struct vpfe_ipipe_rgb2rgb {
865 /* Matrix coefficient for RR S12Q8 for ID = 1 and S11Q8 for ID = 2 */
866 struct ipipe_float_s16 coef_rr;
867 /* Matrix coefficient for GR S12Q8/S11Q8 */
868 struct ipipe_float_s16 coef_gr;
869 /* Matrix coefficient for BR S12Q8/S11Q8 */
870 struct ipipe_float_s16 coef_br;
871 /* Matrix coefficient for RG S12Q8/S11Q8 */
872 struct ipipe_float_s16 coef_rg;
873 /* Matrix coefficient for GG S12Q8/S11Q8 */
874 struct ipipe_float_s16 coef_gg;
875 /* Matrix coefficient for BG S12Q8/S11Q8 */
876 struct ipipe_float_s16 coef_bg;
877 /* Matrix coefficient for RB S12Q8/S11Q8 */
878 struct ipipe_float_s16 coef_rb;
879 /* Matrix coefficient for GB S12Q8/S11Q8 */
880 struct ipipe_float_s16 coef_gb;
881 /* Matrix coefficient for BB S12Q8/S11Q8 */
882 struct ipipe_float_s16 coef_bb;
883 /* Output offset for R S13/S11 */
884 int out_ofst_r;
885 /* Output offset for G S13/S11 */
886 int out_ofst_g;
887 /* Output offset for B S13/S11 */
888 int out_ofst_b;
889};
890
891#define VPFE_IPIPE_MAX_SIZE_GAMMA 512
892
893enum vpfe_ipipe_gamma_tbl_size {
894 VPFE_IPIPE_GAMMA_TBL_SZ_64 = 64,
895 VPFE_IPIPE_GAMMA_TBL_SZ_128 = 128,
896 VPFE_IPIPE_GAMMA_TBL_SZ_256 = 256,
897 VPFE_IPIPE_GAMMA_TBL_SZ_512 = 512,
898};
899
900enum vpfe_ipipe_gamma_tbl_sel {
901 VPFE_IPIPE_GAMMA_TBL_RAM = 0,
902 VPFE_IPIPE_GAMMA_TBL_ROM = 1,
903};
904
905struct vpfe_ipipe_gamma_entry {
906 /* 10 bit slope */
907 short slope;
908 /* 10 bit offset */
909 unsigned short offset;
910};
911
912/* Structure for configuring Gamma correction module */
913struct vpfe_ipipe_gamma {
914 /* 0 - Enable Gamma correction for Red
915 * 1 - bypass Gamma correction. Data is divided by 16
916 */
917 unsigned char bypass_r;
918 /* 0 - Enable Gamma correction for Blue
919 * 1 - bypass Gamma correction. Data is divided by 16
920 */
921 unsigned char bypass_b;
922 /* 0 - Enable Gamma correction for Green
923 * 1 - bypass Gamma correction. Data is divided by 16
924 */
925 unsigned char bypass_g;
926 /* IPIPE_GAMMA_TBL_RAM or IPIPE_GAMMA_TBL_ROM */
927 enum vpfe_ipipe_gamma_tbl_sel tbl_sel;
928 /* Table size for RAM gamma table.
929 */
930 enum vpfe_ipipe_gamma_tbl_size tbl_size;
931 /* R table */
932 struct vpfe_ipipe_gamma_entry table_r[VPFE_IPIPE_MAX_SIZE_GAMMA];
933 /* Blue table */
934 struct vpfe_ipipe_gamma_entry table_b[VPFE_IPIPE_MAX_SIZE_GAMMA];
935 /* Green table */
936 struct vpfe_ipipe_gamma_entry table_g[VPFE_IPIPE_MAX_SIZE_GAMMA];
937};
938
939#define VPFE_IPIPE_MAX_SIZE_3D_LUT 729
940
941struct vpfe_ipipe_3d_lut_entry {
942 /* 10 bit entry for red */
943 unsigned short r;
944 /* 10 bit entry for green */
945 unsigned short g;
946 /* 10 bit entry for blue */
947 unsigned short b;
948};
949
950/* structure for 3D-LUT */
951struct vpfe_ipipe_3d_lut {
952 /* enable/disable 3D lut */
953 unsigned char en;
954 /* 3D - LUT table entry */
955 struct vpfe_ipipe_3d_lut_entry table[VPFE_IPIPE_MAX_SIZE_3D_LUT];
956};
957
958/* Struct for configuring rgb2ycbcr module */
959struct vpfe_ipipe_rgb2yuv {
960 /* Matrix coefficient for RY S12Q8 */
961 struct ipipe_float_s16 coef_ry;
962 /* Matrix coefficient for GY S12Q8 */
963 struct ipipe_float_s16 coef_gy;
964 /* Matrix coefficient for BY S12Q8 */
965 struct ipipe_float_s16 coef_by;
966 /* Matrix coefficient for RCb S12Q8 */
967 struct ipipe_float_s16 coef_rcb;
968 /* Matrix coefficient for GCb S12Q8 */
969 struct ipipe_float_s16 coef_gcb;
970 /* Matrix coefficient for BCb S12Q8 */
971 struct ipipe_float_s16 coef_bcb;
972 /* Matrix coefficient for RCr S12Q8 */
973 struct ipipe_float_s16 coef_rcr;
974 /* Matrix coefficient for GCr S12Q8 */
975 struct ipipe_float_s16 coef_gcr;
976 /* Matrix coefficient for BCr S12Q8 */
977 struct ipipe_float_s16 coef_bcr;
978 /* Output offset for R S11 */
979 int out_ofst_y;
980 /* Output offset for Cb S11 */
981 int out_ofst_cb;
982 /* Output offset for Cr S11 */
983 int out_ofst_cr;
984};
985
986enum vpfe_ipipe_gbce_type {
987 VPFE_IPIPE_GBCE_Y_VAL_TBL = 0,
988 VPFE_IPIPE_GBCE_GAIN_TBL = 1,
989};
990
991#define VPFE_IPIPE_MAX_SIZE_GBCE_LUT 1024
992
993/* structure for Global brightness and Contrast */
994struct vpfe_ipipe_gbce {
995 /* enable/disable GBCE */
996 unsigned char en;
997 /* Y - value table or Gain table */
998 enum vpfe_ipipe_gbce_type type;
999 /* ptr to LUT for GBCE with 1024 entries */
1000 unsigned short table[VPFE_IPIPE_MAX_SIZE_GBCE_LUT];
1001};
1002
1003/* Chrominance position. Applicable only for YCbCr input
1004 * Applied after edge enhancement
1005 */
1006enum vpfe_chr_pos {
1007 /* Co-siting, same position with luminance */
1008 VPFE_IPIPE_YUV422_CHR_POS_COSITE = 0,
1009 /* Centering, In the middle of luminance */
1010 VPFE_IPIPE_YUV422_CHR_POS_CENTRE = 1,
1011};
1012
1013/* Structure for configuring yuv422 conversion module */
1014struct vpfe_ipipe_yuv422_conv {
1015 /* Max Chrominance value */
1016 unsigned char en_chrom_lpf;
1017 /* 1 - enable LPF for chrminance, 0 - disable */
1018 enum vpfe_chr_pos chrom_pos;
1019};
1020
1021#define VPFE_IPIPE_MAX_SIZE_YEE_LUT 1024
1022
1023enum vpfe_ipipe_yee_merge_meth {
1024 VPFE_IPIPE_YEE_ABS_MAX = 0,
1025 VPFE_IPIPE_YEE_EE_ES = 1,
1026};
1027
1028/* Structure for configuring YUV Edge Enhancement module */
1029struct vpfe_ipipe_yee {
1030 /* 1 - enable enhancement, 0 - disable */
1031 unsigned char en;
1032 /* enable/disable halo reduction in edge sharpner */
1033 unsigned char en_halo_red;
1034 /* Merge method between Edge Enhancer and Edge sharpner */
1035 enum vpfe_ipipe_yee_merge_meth merge_meth;
1036 /* HPF Shift length */
1037 unsigned char hpf_shft;
1038 /* HPF Coefficient 00, S10 */
1039 short hpf_coef_00;
1040 /* HPF Coefficient 01, S10 */
1041 short hpf_coef_01;
1042 /* HPF Coefficient 02, S10 */
1043 short hpf_coef_02;
1044 /* HPF Coefficient 10, S10 */
1045 short hpf_coef_10;
1046 /* HPF Coefficient 11, S10 */
1047 short hpf_coef_11;
1048 /* HPF Coefficient 12, S10 */
1049 short hpf_coef_12;
1050 /* HPF Coefficient 20, S10 */
1051 short hpf_coef_20;
1052 /* HPF Coefficient 21, S10 */
1053 short hpf_coef_21;
1054 /* HPF Coefficient 22, S10 */
1055 short hpf_coef_22;
1056 /* Lower threshold before referring to LUT */
1057 unsigned short yee_thr;
1058 /* Edge sharpener Gain */
1059 unsigned short es_gain;
1060 /* Edge sharpener lower threshold */
1061 unsigned short es_thr1;
1062 /* Edge sharpener upper threshold */
1063 unsigned short es_thr2;
1064 /* Edge sharpener gain on gradient */
1065 unsigned short es_gain_grad;
1066 /* Edge sharpener offset on gradient */
1067 unsigned short es_ofst_grad;
1068 /* Ptr to EE table. Must have 1024 entries */
1069 short table[VPFE_IPIPE_MAX_SIZE_YEE_LUT];
1070};
1071
1072enum vpfe_ipipe_car_meth {
1073 /* Chromatic Gain Control */
1074 VPFE_IPIPE_CAR_CHR_GAIN_CTRL = 0,
1075 /* Dynamic switching between CHR_GAIN_CTRL
1076 * and MED_FLTR
1077 */
1078 VPFE_IPIPE_CAR_DYN_SWITCH = 1,
1079 /* Median Filter */
1080 VPFE_IPIPE_CAR_MED_FLTR = 2,
1081};
1082
1083enum vpfe_ipipe_car_hpf_type {
1084 VPFE_IPIPE_CAR_HPF_Y = 0,
1085 VPFE_IPIPE_CAR_HPF_H = 1,
1086 VPFE_IPIPE_CAR_HPF_V = 2,
1087 VPFE_IPIPE_CAR_HPF_2D = 3,
1088 /* 2D HPF from YUV Edge Enhancement */
1089 VPFE_IPIPE_CAR_HPF_2D_YEE = 4,
1090};
1091
1092struct vpfe_ipipe_car_gain {
1093 /* csup_gain */
1094 unsigned char gain;
1095 /* csup_shf. */
1096 unsigned char shft;
1097 /* gain minimum */
1098 unsigned short gain_min;
1099};
1100
1101/* Structure for Chromatic Artifact Reduction */
1102struct vpfe_ipipe_car {
1103 /* enable/disable */
1104 unsigned char en;
1105 /* Gain control or Dynamic switching */
1106 enum vpfe_ipipe_car_meth meth;
1107 /* Gain1 function configuration for Gain control */
1108 struct vpfe_ipipe_car_gain gain1;
1109 /* Gain2 function configuration for Gain control */
1110 struct vpfe_ipipe_car_gain gain2;
1111 /* HPF type used for CAR */
1112 enum vpfe_ipipe_car_hpf_type hpf;
1113 /* csup_thr: HPF threshold for Gain control */
1114 unsigned char hpf_thr;
1115 /* Down shift value for hpf. 2 bits */
1116 unsigned char hpf_shft;
1117 /* switch limit for median filter */
1118 unsigned char sw0;
1119 /* switch coefficient for Gain control */
1120 unsigned char sw1;
1121};
1122
1123/* structure for Chromatic Gain Suppression */
1124struct vpfe_ipipe_cgs {
1125 /* enable/disable */
1126 unsigned char en;
1127 /* gain1 bright side threshold */
1128 unsigned char h_thr;
1129 /* gain1 bright side slope */
1130 unsigned char h_slope;
1131 /* gain1 down shift value for bright side */
1132 unsigned char h_shft;
1133 /* gain1 bright side minimum gain */
1134 unsigned char h_min;
1135};
1136
1137/* Max pixels allowed in the input. If above this either decimation
1138 * or frame division mode to be enabled
1139 */
1140#define VPFE_IPIPE_MAX_INPUT_WIDTH 2600
1141
1142struct vpfe_ipipe_input_config {
1143 unsigned int vst;
1144 unsigned int hst;
1145};
1146
1147/**
1148 * struct vpfe_ipipe_config - IPIPE engine configuration (user)
1149 * @input_config: Pointer to structure for ipipe configuration.
1150 * @flag: Specifies which ISP IPIPE functions should be enabled.
1151 * @lutdpc: Pointer to luma enhancement structure.
1152 * @otfdpc: Pointer to structure for defect correction.
1153 * @nf1: Pointer to structure for Noise Filter.
1154 * @nf2: Pointer to structure for Noise Filter.
1155 * @gic: Pointer to structure for Green Imbalance.
1156 * @wbal: Pointer to structure for White Balance.
1157 * @cfa: Pointer to structure containing the CFA interpolation.
1158 * @rgb2rgb1: Pointer to structure for RGB to RGB Blending.
1159 * @rgb2rgb2: Pointer to structure for RGB to RGB Blending.
1160 * @gamma: Pointer to gamma structure.
1161 * @lut: Pointer to structure for 3D LUT.
1162 * @rgb2yuv: Pointer to structure for RGB-YCbCr conversion.
1163 * @gbce: Pointer to structure for Global Brightness,Contrast Control.
1164 * @yuv422_conv: Pointer to structure for YUV 422 conversion.
1165 * @yee: Pointer to structure for Edge Enhancer.
1166 * @car: Pointer to structure for Chromatic Artifact Reduction.
1167 * @cgs: Pointer to structure for Chromatic Gain Suppression.
1168 */
1169struct vpfe_ipipe_config {
1170 __u32 flag;
1171 struct vpfe_ipipe_input_config __user *input_config;
1172 struct vpfe_ipipe_lutdpc __user *lutdpc;
1173 struct vpfe_ipipe_otfdpc __user *otfdpc;
1174 struct vpfe_ipipe_nf __user *nf1;
1175 struct vpfe_ipipe_nf __user *nf2;
1176 struct vpfe_ipipe_gic __user *gic;
1177 struct vpfe_ipipe_wb __user *wbal;
1178 struct vpfe_ipipe_cfa __user *cfa;
1179 struct vpfe_ipipe_rgb2rgb __user *rgb2rgb1;
1180 struct vpfe_ipipe_rgb2rgb __user *rgb2rgb2;
1181 struct vpfe_ipipe_gamma __user *gamma;
1182 struct vpfe_ipipe_3d_lut __user *lut;
1183 struct vpfe_ipipe_rgb2yuv __user *rgb2yuv;
1184 struct vpfe_ipipe_gbce __user *gbce;
1185 struct vpfe_ipipe_yuv422_conv __user *yuv422_conv;
1186 struct vpfe_ipipe_yee __user *yee;
1187 struct vpfe_ipipe_car __user *car;
1188 struct vpfe_ipipe_cgs __user *cgs;
1189};
1190
1191/*******************************************************************
1192** Resizer API structures
1193*******************************************************************/
1194/* Interpolation types used for horizontal rescale */
1195enum vpfe_rsz_intp_t {
1196 VPFE_RSZ_INTP_CUBIC,
1197 VPFE_RSZ_INTP_LINEAR
1198};
1199
1200/* Horizontal LPF intensity selection */
1201enum vpfe_rsz_h_lpf_lse_t {
1202 VPFE_RSZ_H_LPF_LSE_INTERN,
1203 VPFE_RSZ_H_LPF_LSE_USER_VAL
1204};
1205
1206enum vpfe_rsz_down_scale_ave_sz {
1207 VPFE_IPIPE_DWN_SCALE_1_OVER_2,
1208 VPFE_IPIPE_DWN_SCALE_1_OVER_4,
1209 VPFE_IPIPE_DWN_SCALE_1_OVER_8,
1210 VPFE_IPIPE_DWN_SCALE_1_OVER_16,
1211 VPFE_IPIPE_DWN_SCALE_1_OVER_32,
1212 VPFE_IPIPE_DWN_SCALE_1_OVER_64,
1213 VPFE_IPIPE_DWN_SCALE_1_OVER_128,
1214 VPFE_IPIPE_DWN_SCALE_1_OVER_256
1215};
1216
1217struct vpfe_rsz_output_spec {
1218 /* enable horizontal flip */
1219 unsigned char h_flip;
1220 /* enable vertical flip */
1221 unsigned char v_flip;
1222 /* line start offset for y. */
1223 unsigned int vst_y;
1224 /* line start offset for c. Only for 420 */
1225 unsigned int vst_c;
1226 /* vertical rescale interpolation type, YCbCr or Luminance */
1227 enum vpfe_rsz_intp_t v_typ_y;
1228 /* vertical rescale interpolation type for Chrominance */
1229 enum vpfe_rsz_intp_t v_typ_c;
1230 /* vertical lpf intensity - Luminance */
1231 unsigned char v_lpf_int_y;
1232 /* vertical lpf intensity - Chrominance */
1233 unsigned char v_lpf_int_c;
1234 /* horizontal rescale interpolation types, YCbCr or Luminance */
1235 enum vpfe_rsz_intp_t h_typ_y;
1236 /* horizontal rescale interpolation types, Chrominance */
1237 enum vpfe_rsz_intp_t h_typ_c;
1238 /* horizontal lpf intensity - Luminance */
1239 unsigned char h_lpf_int_y;
1240 /* horizontal lpf intensity - Chrominance */
1241 unsigned char h_lpf_int_c;
1242 /* Use down scale mode for scale down */
1243 unsigned char en_down_scale;
1244 /* if downscale, set the downscale more average size for horizontal
1245 * direction. Used only if output width and height is less than
1246 * input sizes
1247 */
1248 enum vpfe_rsz_down_scale_ave_sz h_dscale_ave_sz;
1249 /* if downscale, set the downscale more average size for vertical
1250 * direction. Used only if output width and height is less than
1251 * input sizes
1252 */
1253 enum vpfe_rsz_down_scale_ave_sz v_dscale_ave_sz;
1254 /* Y offset. If set, the offset would be added to the base address
1255 */
1256 unsigned int user_y_ofst;
1257 /* C offset. If set, the offset would be added to the base address
1258 */
1259 unsigned int user_c_ofst;
1260};
1261
1262struct vpfe_rsz_config_params {
1263 unsigned int vst;
1264 /* horizontal start position of the image
1265 * data to IPIPE
1266 */
1267 unsigned int hst;
1268 /* output spec of the image data coming out of resizer - 0(UYVY).
1269 */
1270 struct vpfe_rsz_output_spec output1;
1271 /* output spec of the image data coming out of resizer - 1(UYVY).
1272 */
1273 struct vpfe_rsz_output_spec output2;
1274 /* 0 , chroma sample at odd pixel, 1 - even pixel */
1275 unsigned char chroma_sample_even;
1276 unsigned char frame_div_mode_en;
1277 unsigned char yuv_y_min;
1278 unsigned char yuv_y_max;
1279 unsigned char yuv_c_min;
1280 unsigned char yuv_c_max;
1281 enum vpfe_chr_pos out_chr_pos;
1282 unsigned char bypass;
1283};
1284
1285/* Structure for VIDIOC_VPFE_RSZ_[S/G]_CONFIG IOCTLs */
1286struct vpfe_rsz_config {
1287 struct vpfe_rsz_config_params *config;
1288};
1289
1290#endif /* _DAVINCI_VPFE_USER_H */
diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipe.c b/drivers/staging/media/davinci_vpfe/dm365_ipipe.c
new file mode 100644
index 000000000000..92853539cc0a
--- /dev/null
+++ b/drivers/staging/media/davinci_vpfe/dm365_ipipe.c
@@ -0,0 +1,1863 @@
1/*
2 * Copyright (C) 2012 Texas Instruments Inc
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation version 2.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Contributors:
18 * Manjunath Hadli <manjunath.hadli@ti.com>
19 * Prabhakar Lad <prabhakar.lad@ti.com>
20 *
21 *
22 * IPIPE allows fine tuning of the input image using different
23 * tuning modules in IPIPE. Some examples :- Noise filter, Defect
24 * pixel correction etc. It essentially operate on Bayer Raw data
25 * or YUV raw data. To do image tuning, application call,
26 *
27 */
28
29#include <linux/slab.h>
30
31#include "dm365_ipipe.h"
32#include "dm365_ipipe_hw.h"
33#include "vpfe_mc_capture.h"
34
35#define MIN_OUT_WIDTH 32
36#define MIN_OUT_HEIGHT 32
37
38/* ipipe input format's */
39static const unsigned int ipipe_input_fmts[] = {
40 V4L2_MBUS_FMT_UYVY8_2X8,
41 V4L2_MBUS_FMT_SGRBG12_1X12,
42 V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8,
43 V4L2_MBUS_FMT_SGRBG10_ALAW8_1X8,
44};
45
46/* ipipe output format's */
47static const unsigned int ipipe_output_fmts[] = {
48 V4L2_MBUS_FMT_UYVY8_2X8,
49};
50
51static int ipipe_validate_lutdpc_params(struct vpfe_ipipe_lutdpc *lutdpc)
52{
53 int i;
54
55 if (lutdpc->en > 1 || lutdpc->repl_white > 1 ||
56 lutdpc->dpc_size > LUT_DPC_MAX_SIZE)
57 return -EINVAL;
58
59 if (lutdpc->en && !lutdpc->table)
60 return -EINVAL;
61
62 for (i = 0; i < lutdpc->dpc_size; i++)
63 if (lutdpc->table[i].horz_pos > LUT_DPC_H_POS_MASK ||
64 lutdpc->table[i].vert_pos > LUT_DPC_V_POS_MASK)
65 return -EINVAL;
66
67 return 0;
68}
69
70static int ipipe_set_lutdpc_params(struct vpfe_ipipe_device *ipipe, void *param)
71{
72 struct vpfe_ipipe_lutdpc *lutdpc = &ipipe->config.lutdpc;
73 struct vpfe_ipipe_lutdpc *dpc_param;
74 struct device *dev;
75
76 if (!param) {
77 memset((void *)lutdpc, 0, sizeof(struct vpfe_ipipe_lutdpc));
78 goto success;
79 }
80
81 dev = ipipe->subdev.v4l2_dev->dev;
82 dpc_param = (struct vpfe_ipipe_lutdpc *)param;
83 lutdpc->en = dpc_param->en;
84 lutdpc->repl_white = dpc_param->repl_white;
85 lutdpc->dpc_size = dpc_param->dpc_size;
86 memcpy(&lutdpc->table, &dpc_param->table,
87 (dpc_param->dpc_size * sizeof(struct vpfe_ipipe_lutdpc_entry)));
88 if (ipipe_validate_lutdpc_params(lutdpc) < 0)
89 return -EINVAL;
90
91success:
92 ipipe_set_lutdpc_regs(ipipe->base_addr, ipipe->isp5_base_addr, lutdpc);
93
94 return 0;
95}
96
97static int ipipe_get_lutdpc_params(struct vpfe_ipipe_device *ipipe, void *param)
98{
99 struct vpfe_ipipe_lutdpc *lut_param = (struct vpfe_ipipe_lutdpc *)param;
100 struct vpfe_ipipe_lutdpc *lutdpc = &ipipe->config.lutdpc;
101
102 lut_param->en = lutdpc->en;
103 lut_param->repl_white = lutdpc->repl_white;
104 lut_param->dpc_size = lutdpc->dpc_size;
105 memcpy(&lut_param->table, &lutdpc->table,
106 (lutdpc->dpc_size * sizeof(struct vpfe_ipipe_lutdpc_entry)));
107
108 return 0;
109}
110
111static int ipipe_set_input_config(struct vpfe_ipipe_device *ipipe, void *param)
112{
113 struct vpfe_ipipe_input_config *config = &ipipe->config.input_config;
114
115 if (!param)
116 memset(config, 0, sizeof(struct vpfe_ipipe_input_config));
117 else
118 memcpy(config, param, sizeof(struct vpfe_ipipe_input_config));
119 return 0;
120}
121
122static int ipipe_get_input_config(struct vpfe_ipipe_device *ipipe, void *param)
123{
124 struct vpfe_ipipe_input_config *config = &ipipe->config.input_config;
125
126 if (!param)
127 return -EINVAL;
128
129 memcpy(param, config, sizeof(struct vpfe_ipipe_input_config));
130
131 return 0;
132}
133
134static int ipipe_validate_otfdpc_params(struct vpfe_ipipe_otfdpc *dpc_param)
135{
136 struct vpfe_ipipe_otfdpc_2_0_cfg *dpc_2_0;
137 struct vpfe_ipipe_otfdpc_3_0_cfg *dpc_3_0;
138
139 if (dpc_param->en > 1)
140 return -EINVAL;
141
142 if (dpc_param->alg == VPFE_IPIPE_OTFDPC_2_0) {
143 dpc_2_0 = &dpc_param->alg_cfg.dpc_2_0;
144 if (dpc_2_0->det_thr.r > OTFDPC_DPC2_THR_MASK ||
145 dpc_2_0->det_thr.gr > OTFDPC_DPC2_THR_MASK ||
146 dpc_2_0->det_thr.gb > OTFDPC_DPC2_THR_MASK ||
147 dpc_2_0->det_thr.b > OTFDPC_DPC2_THR_MASK ||
148 dpc_2_0->corr_thr.r > OTFDPC_DPC2_THR_MASK ||
149 dpc_2_0->corr_thr.gr > OTFDPC_DPC2_THR_MASK ||
150 dpc_2_0->corr_thr.gb > OTFDPC_DPC2_THR_MASK ||
151 dpc_2_0->corr_thr.b > OTFDPC_DPC2_THR_MASK)
152 return -EINVAL;
153 return 0;
154 }
155
156 dpc_3_0 = &dpc_param->alg_cfg.dpc_3_0;
157
158 if (dpc_3_0->act_adj_shf > OTF_DPC3_0_SHF_MASK ||
159 dpc_3_0->det_thr > OTF_DPC3_0_DET_MASK ||
160 dpc_3_0->det_slp > OTF_DPC3_0_SLP_MASK ||
161 dpc_3_0->det_thr_min > OTF_DPC3_0_DET_MASK ||
162 dpc_3_0->det_thr_max > OTF_DPC3_0_DET_MASK ||
163 dpc_3_0->corr_thr > OTF_DPC3_0_CORR_MASK ||
164 dpc_3_0->corr_slp > OTF_DPC3_0_SLP_MASK ||
165 dpc_3_0->corr_thr_min > OTF_DPC3_0_CORR_MASK ||
166 dpc_3_0->corr_thr_max > OTF_DPC3_0_CORR_MASK)
167 return -EINVAL;
168
169 return 0;
170}
171
172static int ipipe_set_otfdpc_params(struct vpfe_ipipe_device *ipipe, void *param)
173{
174 struct vpfe_ipipe_otfdpc *dpc_param = (struct vpfe_ipipe_otfdpc *)param;
175 struct vpfe_ipipe_otfdpc *otfdpc = &ipipe->config.otfdpc;
176 struct device *dev;
177
178 if (!param) {
179 memset((void *)otfdpc, 0, sizeof(struct ipipe_otfdpc_2_0));
180 goto success;
181 }
182 dev = ipipe->subdev.v4l2_dev->dev;
183 memcpy(otfdpc, dpc_param, sizeof(struct vpfe_ipipe_otfdpc));
184 if (ipipe_validate_otfdpc_params(otfdpc) < 0) {
185 dev_err(dev, "Invalid otfdpc params\n");
186 return -EINVAL;
187 }
188
189success:
190 ipipe_set_otfdpc_regs(ipipe->base_addr, otfdpc);
191
192 return 0;
193}
194
195static int ipipe_get_otfdpc_params(struct vpfe_ipipe_device *ipipe, void *param)
196{
197 struct vpfe_ipipe_otfdpc *dpc_param = (struct vpfe_ipipe_otfdpc *)param;
198 struct vpfe_ipipe_otfdpc *otfdpc = &ipipe->config.otfdpc;
199
200 memcpy(dpc_param, otfdpc, sizeof(struct vpfe_ipipe_otfdpc));
201 return 0;
202}
203
204static int ipipe_validate_nf_params(struct vpfe_ipipe_nf *nf_param)
205{
206 int i;
207
208 if (nf_param->en > 1 || nf_param->shft_val > D2F_SHFT_VAL_MASK ||
209 nf_param->spread_val > D2F_SPR_VAL_MASK ||
210 nf_param->apply_lsc_gain > 1 ||
211 nf_param->edge_det_min_thr > D2F_EDGE_DET_THR_MASK ||
212 nf_param->edge_det_max_thr > D2F_EDGE_DET_THR_MASK)
213 return -EINVAL;
214
215 for (i = 0; i < VPFE_IPIPE_NF_THR_TABLE_SIZE; i++)
216 if (nf_param->thr[i] > D2F_THR_VAL_MASK)
217 return -EINVAL;
218
219 for (i = 0; i < VPFE_IPIPE_NF_STR_TABLE_SIZE; i++)
220 if (nf_param->str[i] > D2F_STR_VAL_MASK)
221 return -EINVAL;
222
223 return 0;
224}
225
226static int ipipe_set_nf_params(struct vpfe_ipipe_device *ipipe,
227 unsigned int id, void *param)
228{
229 struct vpfe_ipipe_nf *nf_param = (struct vpfe_ipipe_nf *)param;
230 struct vpfe_ipipe_nf *nf = &ipipe->config.nf1;
231 struct device *dev;
232
233 if (id == IPIPE_D2F_2ND)
234 nf = &ipipe->config.nf2;
235
236 if (!nf_param) {
237 memset((void *)nf, 0, sizeof(struct vpfe_ipipe_nf));
238 goto success;
239 }
240
241 dev = ipipe->subdev.v4l2_dev->dev;
242 memcpy(nf, nf_param, sizeof(struct vpfe_ipipe_nf));
243 if (ipipe_validate_nf_params(nf) < 0) {
244 dev_err(dev, "Invalid nf params\n");
245 return -EINVAL;
246 }
247
248success:
249 ipipe_set_d2f_regs(ipipe->base_addr, id, nf);
250
251 return 0;
252}
253
254static int ipipe_set_nf1_params(struct vpfe_ipipe_device *ipipe, void *param)
255{
256 return ipipe_set_nf_params(ipipe, IPIPE_D2F_1ST, param);
257}
258
259static int ipipe_set_nf2_params(struct vpfe_ipipe_device *ipipe, void *param)
260{
261 return ipipe_set_nf_params(ipipe, IPIPE_D2F_2ND, param);
262}
263
264static int ipipe_get_nf_params(struct vpfe_ipipe_device *ipipe,
265 unsigned int id, void *param)
266{
267 struct vpfe_ipipe_nf *nf_param = (struct vpfe_ipipe_nf *)param;
268 struct vpfe_ipipe_nf *nf = &ipipe->config.nf1;
269
270 if (id == IPIPE_D2F_2ND)
271 nf = &ipipe->config.nf2;
272
273 memcpy(nf_param, nf, sizeof(struct vpfe_ipipe_nf));
274
275 return 0;
276}
277
278static int ipipe_get_nf1_params(struct vpfe_ipipe_device *ipipe, void *param)
279{
280 return ipipe_get_nf_params(ipipe, IPIPE_D2F_1ST, param);
281}
282
283static int ipipe_get_nf2_params(struct vpfe_ipipe_device *ipipe, void *param)
284{
285 return ipipe_get_nf_params(ipipe, IPIPE_D2F_2ND, param);
286}
287
288static int ipipe_validate_gic_params(struct vpfe_ipipe_gic *gic)
289{
290 if (gic->en > 1 || gic->gain > GIC_GAIN_MASK ||
291 gic->thr > GIC_THR_MASK || gic->slope > GIC_SLOPE_MASK ||
292 gic->apply_lsc_gain > 1 ||
293 gic->nf2_thr_gain.integer > GIC_NFGAN_INT_MASK ||
294 gic->nf2_thr_gain.decimal > GIC_NFGAN_DECI_MASK)
295 return -EINVAL;
296
297 return 0;
298}
299
300static int ipipe_set_gic_params(struct vpfe_ipipe_device *ipipe, void *param)
301{
302 struct vpfe_ipipe_gic *gic_param = (struct vpfe_ipipe_gic *)param;
303 struct device *dev = ipipe->subdev.v4l2_dev->dev;
304 struct vpfe_ipipe_gic *gic = &ipipe->config.gic;
305
306 if (!gic_param) {
307 memset((void *)gic, 0, sizeof(struct vpfe_ipipe_gic));
308 goto success;
309 }
310
311 memcpy(gic, gic_param, sizeof(struct vpfe_ipipe_gic));
312 if (ipipe_validate_gic_params(gic) < 0) {
313 dev_err(dev, "Invalid gic params\n");
314 return -EINVAL;
315 }
316
317success:
318 ipipe_set_gic_regs(ipipe->base_addr, gic);
319
320 return 0;
321}
322
323static int ipipe_get_gic_params(struct vpfe_ipipe_device *ipipe, void *param)
324{
325 struct vpfe_ipipe_gic *gic_param = (struct vpfe_ipipe_gic *)param;
326 struct vpfe_ipipe_gic *gic = &ipipe->config.gic;
327
328 memcpy(gic_param, gic, sizeof(struct vpfe_ipipe_gic));
329
330 return 0;
331}
332
333static int ipipe_validate_wb_params(struct vpfe_ipipe_wb *wbal)
334{
335 if (wbal->ofst_r > WB_OFFSET_MASK ||
336 wbal->ofst_gr > WB_OFFSET_MASK ||
337 wbal->ofst_gb > WB_OFFSET_MASK ||
338 wbal->ofst_b > WB_OFFSET_MASK ||
339 wbal->gain_r.integer > WB_GAIN_INT_MASK ||
340 wbal->gain_r.decimal > WB_GAIN_DECI_MASK ||
341 wbal->gain_gr.integer > WB_GAIN_INT_MASK ||
342 wbal->gain_gr.decimal > WB_GAIN_DECI_MASK ||
343 wbal->gain_gb.integer > WB_GAIN_INT_MASK ||
344 wbal->gain_gb.decimal > WB_GAIN_DECI_MASK ||
345 wbal->gain_b.integer > WB_GAIN_INT_MASK ||
346 wbal->gain_b.decimal > WB_GAIN_DECI_MASK)
347 return -EINVAL;
348
349 return 0;
350}
351
352static int ipipe_set_wb_params(struct vpfe_ipipe_device *ipipe, void *param)
353{
354 struct vpfe_ipipe_wb *wb_param = (struct vpfe_ipipe_wb *)param;
355 struct vpfe_ipipe_wb *wbal = &ipipe->config.wbal;
356
357 if (!wb_param) {
358 const struct vpfe_ipipe_wb wb_defaults = {
359 .gain_r = {2, 0x0},
360 .gain_gr = {2, 0x0},
361 .gain_gb = {2, 0x0},
362 .gain_b = {2, 0x0}
363 };
364 memcpy(wbal, &wb_defaults, sizeof(struct vpfe_ipipe_wb));
365 goto success;
366 }
367
368 memcpy(wbal, wb_param, sizeof(struct vpfe_ipipe_wb));
369 if (ipipe_validate_wb_params(wbal) < 0)
370 return -EINVAL;
371
372success:
373 ipipe_set_wb_regs(ipipe->base_addr, wbal);
374
375 return 0;
376}
377
378static int ipipe_get_wb_params(struct vpfe_ipipe_device *ipipe, void *param)
379{
380 struct vpfe_ipipe_wb *wb_param = (struct vpfe_ipipe_wb *)param;
381 struct vpfe_ipipe_wb *wbal = &ipipe->config.wbal;
382
383 memcpy(wb_param, wbal, sizeof(struct vpfe_ipipe_wb));
384 return 0;
385}
386
387static int ipipe_validate_cfa_params(struct vpfe_ipipe_cfa *cfa)
388{
389 if (cfa->hpf_thr_2dir > CFA_HPF_THR_2DIR_MASK ||
390 cfa->hpf_slp_2dir > CFA_HPF_SLOPE_2DIR_MASK ||
391 cfa->hp_mix_thr_2dir > CFA_HPF_MIX_THR_2DIR_MASK ||
392 cfa->hp_mix_slope_2dir > CFA_HPF_MIX_SLP_2DIR_MASK ||
393 cfa->dir_thr_2dir > CFA_DIR_THR_2DIR_MASK ||
394 cfa->dir_slope_2dir > CFA_DIR_SLP_2DIR_MASK ||
395 cfa->nd_wt_2dir > CFA_ND_WT_2DIR_MASK ||
396 cfa->hue_fract_daa > CFA_DAA_HUE_FRA_MASK ||
397 cfa->edge_thr_daa > CFA_DAA_EDG_THR_MASK ||
398 cfa->thr_min_daa > CFA_DAA_THR_MIN_MASK ||
399 cfa->thr_slope_daa > CFA_DAA_THR_SLP_MASK ||
400 cfa->slope_min_daa > CFA_DAA_SLP_MIN_MASK ||
401 cfa->slope_slope_daa > CFA_DAA_SLP_SLP_MASK ||
402 cfa->lp_wt_daa > CFA_DAA_LP_WT_MASK)
403 return -EINVAL;
404
405 return 0;
406}
407
408static int ipipe_set_cfa_params(struct vpfe_ipipe_device *ipipe, void *param)
409{
410 struct vpfe_ipipe_cfa *cfa_param = (struct vpfe_ipipe_cfa *)param;
411 struct vpfe_ipipe_cfa *cfa = &ipipe->config.cfa;
412
413 if (!cfa_param) {
414 memset(cfa, 0, sizeof(struct vpfe_ipipe_cfa));
415 cfa->alg = VPFE_IPIPE_CFA_ALG_2DIRAC;
416 goto success;
417 }
418
419 memcpy(cfa, cfa_param, sizeof(struct vpfe_ipipe_cfa));
420 if (ipipe_validate_cfa_params(cfa) < 0)
421 return -EINVAL;
422
423success:
424 ipipe_set_cfa_regs(ipipe->base_addr, cfa);
425
426 return 0;
427}
428
429static int ipipe_get_cfa_params(struct vpfe_ipipe_device *ipipe, void *param)
430{
431 struct vpfe_ipipe_cfa *cfa_param = (struct vpfe_ipipe_cfa *)param;
432 struct vpfe_ipipe_cfa *cfa = &ipipe->config.cfa;
433
434 memcpy(cfa_param, cfa, sizeof(struct vpfe_ipipe_cfa));
435 return 0;
436}
437
438static int
439ipipe_validate_rgb2rgb_params(struct vpfe_ipipe_rgb2rgb *rgb2rgb,
440 unsigned int id)
441{
442 u32 gain_int_upper = RGB2RGB_1_GAIN_INT_MASK;
443 u32 offset_upper = RGB2RGB_1_OFST_MASK;
444
445 if (id == IPIPE_RGB2RGB_2) {
446 offset_upper = RGB2RGB_2_OFST_MASK;
447 gain_int_upper = RGB2RGB_2_GAIN_INT_MASK;
448 }
449
450 if (rgb2rgb->coef_rr.decimal > RGB2RGB_GAIN_DECI_MASK ||
451 rgb2rgb->coef_rr.integer > gain_int_upper)
452 return -EINVAL;
453
454 if (rgb2rgb->coef_gr.decimal > RGB2RGB_GAIN_DECI_MASK ||
455 rgb2rgb->coef_gr.integer > gain_int_upper)
456 return -EINVAL;
457
458 if (rgb2rgb->coef_br.decimal > RGB2RGB_GAIN_DECI_MASK ||
459 rgb2rgb->coef_br.integer > gain_int_upper)
460 return -EINVAL;
461
462 if (rgb2rgb->coef_rg.decimal > RGB2RGB_GAIN_DECI_MASK ||
463 rgb2rgb->coef_rg.integer > gain_int_upper)
464 return -EINVAL;
465
466 if (rgb2rgb->coef_gg.decimal > RGB2RGB_GAIN_DECI_MASK ||
467 rgb2rgb->coef_gg.integer > gain_int_upper)
468 return -EINVAL;
469
470 if (rgb2rgb->coef_bg.decimal > RGB2RGB_GAIN_DECI_MASK ||
471 rgb2rgb->coef_bg.integer > gain_int_upper)
472 return -EINVAL;
473
474 if (rgb2rgb->coef_rb.decimal > RGB2RGB_GAIN_DECI_MASK ||
475 rgb2rgb->coef_rb.integer > gain_int_upper)
476 return -EINVAL;
477
478 if (rgb2rgb->coef_gb.decimal > RGB2RGB_GAIN_DECI_MASK ||
479 rgb2rgb->coef_gb.integer > gain_int_upper)
480 return -EINVAL;
481
482 if (rgb2rgb->coef_bb.decimal > RGB2RGB_GAIN_DECI_MASK ||
483 rgb2rgb->coef_bb.integer > gain_int_upper)
484 return -EINVAL;
485
486 if (rgb2rgb->out_ofst_r > offset_upper ||
487 rgb2rgb->out_ofst_g > offset_upper ||
488 rgb2rgb->out_ofst_b > offset_upper)
489 return -EINVAL;
490
491 return 0;
492}
493
494static int ipipe_set_rgb2rgb_params(struct vpfe_ipipe_device *ipipe,
495 unsigned int id, void *param)
496{
497 struct vpfe_ipipe_rgb2rgb *rgb2rgb = &ipipe->config.rgb2rgb1;
498 struct device *dev = ipipe->subdev.v4l2_dev->dev;
499 struct vpfe_ipipe_rgb2rgb *rgb2rgb_param;
500
501 rgb2rgb_param = (struct vpfe_ipipe_rgb2rgb *)param;
502
503 if (id == IPIPE_RGB2RGB_2)
504 rgb2rgb = &ipipe->config.rgb2rgb2;
505
506 if (!rgb2rgb_param) {
507 const struct vpfe_ipipe_rgb2rgb rgb2rgb_defaults = {
508 .coef_rr = {1, 0}, /* 256 */
509 .coef_gr = {0, 0},
510 .coef_br = {0, 0},
511 .coef_rg = {0, 0},
512 .coef_gg = {1, 0}, /* 256 */
513 .coef_bg = {0, 0},
514 .coef_rb = {0, 0},
515 .coef_gb = {0, 0},
516 .coef_bb = {1, 0}, /* 256 */
517 };
518 /* Copy defaults for rgb2rgb conversion */
519 memcpy(rgb2rgb, &rgb2rgb_defaults,
520 sizeof(struct vpfe_ipipe_rgb2rgb));
521 goto success;
522 }
523
524 memcpy(rgb2rgb, rgb2rgb_param, sizeof(struct vpfe_ipipe_rgb2rgb));
525 if (ipipe_validate_rgb2rgb_params(rgb2rgb, id) < 0) {
526 dev_err(dev, "Invalid rgb2rgb params\n");
527 return -EINVAL;
528 }
529
530success:
531 ipipe_set_rgb2rgb_regs(ipipe->base_addr, id, rgb2rgb);
532
533 return 0;
534}
535
536static int
537ipipe_set_rgb2rgb_1_params(struct vpfe_ipipe_device *ipipe, void *param)
538{
539 return ipipe_set_rgb2rgb_params(ipipe, IPIPE_RGB2RGB_1, param);
540}
541
542static int
543ipipe_set_rgb2rgb_2_params(struct vpfe_ipipe_device *ipipe, void *param)
544{
545 return ipipe_set_rgb2rgb_params(ipipe, IPIPE_RGB2RGB_2, param);
546}
547
548static int ipipe_get_rgb2rgb_params(struct vpfe_ipipe_device *ipipe,
549 unsigned int id, void *param)
550{
551 struct vpfe_ipipe_rgb2rgb *rgb2rgb = &ipipe->config.rgb2rgb1;
552 struct vpfe_ipipe_rgb2rgb *rgb2rgb_param;
553
554 rgb2rgb_param = (struct vpfe_ipipe_rgb2rgb *)param;
555
556 if (id == IPIPE_RGB2RGB_2)
557 rgb2rgb = &ipipe->config.rgb2rgb2;
558
559 memcpy(rgb2rgb_param, rgb2rgb, sizeof(struct vpfe_ipipe_rgb2rgb));
560
561 return 0;
562}
563
564static int
565ipipe_get_rgb2rgb_1_params(struct vpfe_ipipe_device *ipipe, void *param)
566{
567 return ipipe_get_rgb2rgb_params(ipipe, IPIPE_RGB2RGB_1, param);
568}
569
570static int
571ipipe_get_rgb2rgb_2_params(struct vpfe_ipipe_device *ipipe, void *param)
572{
573 return ipipe_get_rgb2rgb_params(ipipe, IPIPE_RGB2RGB_2, param);
574}
575
576static int
577ipipe_validate_gamma_entry(struct vpfe_ipipe_gamma_entry *table, int size)
578{
579 int i;
580
581 if (!table)
582 return -EINVAL;
583
584 for (i = 0; i < size; i++)
585 if (table[i].slope > GAMMA_MASK ||
586 table[i].offset > GAMMA_MASK)
587 return -EINVAL;
588
589 return 0;
590}
591
592static int
593ipipe_validate_gamma_params(struct vpfe_ipipe_gamma *gamma, struct device *dev)
594{
595 int table_size;
596 int err;
597
598 if (gamma->bypass_r > 1 ||
599 gamma->bypass_b > 1 ||
600 gamma->bypass_g > 1)
601 return -EINVAL;
602
603 if (gamma->tbl_sel != VPFE_IPIPE_GAMMA_TBL_RAM)
604 return 0;
605
606 table_size = gamma->tbl_size;
607 if (!gamma->bypass_r) {
608 err = ipipe_validate_gamma_entry(gamma->table_r, table_size);
609 if (err) {
610 dev_err(dev, "GAMMA R - table entry invalid\n");
611 return err;
612 }
613 }
614
615 if (!gamma->bypass_b) {
616 err = ipipe_validate_gamma_entry(gamma->table_b, table_size);
617 if (err) {
618 dev_err(dev, "GAMMA B - table entry invalid\n");
619 return err;
620 }
621 }
622
623 if (!gamma->bypass_g) {
624 err = ipipe_validate_gamma_entry(gamma->table_g, table_size);
625 if (err) {
626 dev_err(dev, "GAMMA G - table entry invalid\n");
627 return err;
628 }
629 }
630
631 return 0;
632}
633
634static int
635ipipe_set_gamma_params(struct vpfe_ipipe_device *ipipe, void *param)
636{
637 struct vpfe_ipipe_gamma *gamma_param = (struct vpfe_ipipe_gamma *)param;
638 struct vpfe_ipipe_gamma *gamma = &ipipe->config.gamma;
639 struct device *dev = ipipe->subdev.v4l2_dev->dev;
640 int table_size;
641
642 if (!gamma_param) {
643 memset(gamma, 0, sizeof(struct vpfe_ipipe_gamma));
644 gamma->tbl_sel = VPFE_IPIPE_GAMMA_TBL_ROM;
645 goto success;
646 }
647
648 gamma->bypass_r = gamma_param->bypass_r;
649 gamma->bypass_b = gamma_param->bypass_b;
650 gamma->bypass_g = gamma_param->bypass_g;
651 gamma->tbl_sel = gamma_param->tbl_sel;
652 gamma->tbl_size = gamma_param->tbl_size;
653
654 if (ipipe_validate_gamma_params(gamma, dev) < 0)
655 return -EINVAL;
656
657 if (gamma_param->tbl_sel != VPFE_IPIPE_GAMMA_TBL_RAM)
658 goto success;
659
660 table_size = gamma->tbl_size;
661 if (!gamma_param->bypass_r)
662 memcpy(&gamma->table_r, &gamma_param->table_r,
663 (table_size * sizeof(struct vpfe_ipipe_gamma_entry)));
664
665 if (!gamma_param->bypass_b)
666 memcpy(&gamma->table_b, &gamma_param->table_b,
667 (table_size * sizeof(struct vpfe_ipipe_gamma_entry)));
668
669 if (!gamma_param->bypass_g)
670 memcpy(&gamma->table_g, &gamma_param->table_g,
671 (table_size * sizeof(struct vpfe_ipipe_gamma_entry)));
672
673success:
674 ipipe_set_gamma_regs(ipipe->base_addr, ipipe->isp5_base_addr, gamma);
675
676 return 0;
677}
678
679static int ipipe_get_gamma_params(struct vpfe_ipipe_device *ipipe, void *param)
680{
681 struct vpfe_ipipe_gamma *gamma_param = (struct vpfe_ipipe_gamma *)param;
682 struct vpfe_ipipe_gamma *gamma = &ipipe->config.gamma;
683 struct device *dev = ipipe->subdev.v4l2_dev->dev;
684 int table_size;
685
686 gamma_param->bypass_r = gamma->bypass_r;
687 gamma_param->bypass_g = gamma->bypass_g;
688 gamma_param->bypass_b = gamma->bypass_b;
689 gamma_param->tbl_sel = gamma->tbl_sel;
690 gamma_param->tbl_size = gamma->tbl_size;
691
692 if (gamma->tbl_sel != VPFE_IPIPE_GAMMA_TBL_RAM)
693 return 0;
694
695 table_size = gamma->tbl_size;
696
697 if (!gamma->bypass_r && !gamma_param->table_r) {
698 dev_err(dev,
699 "ipipe_get_gamma_params: table ptr empty for R\n");
700 return -EINVAL;
701 }
702 memcpy(gamma_param->table_r, gamma->table_r,
703 (table_size * sizeof(struct vpfe_ipipe_gamma_entry)));
704
705 if (!gamma->bypass_g && !gamma_param->table_g) {
706 dev_err(dev, "ipipe_get_gamma_params: table ptr empty for G\n");
707 return -EINVAL;
708 }
709 memcpy(gamma_param->table_g, gamma->table_g,
710 (table_size * sizeof(struct vpfe_ipipe_gamma_entry)));
711
712 if (!gamma->bypass_b && !gamma_param->table_b) {
713 dev_err(dev, "ipipe_get_gamma_params: table ptr empty for B\n");
714 return -EINVAL;
715 }
716 memcpy(gamma_param->table_b, gamma->table_b,
717 (table_size * sizeof(struct vpfe_ipipe_gamma_entry)));
718
719 return 0;
720}
721
722static int ipipe_validate_3d_lut_params(struct vpfe_ipipe_3d_lut *lut)
723{
724 int i;
725
726 if (!lut->en)
727 return 0;
728
729 for (i = 0; i < VPFE_IPIPE_MAX_SIZE_3D_LUT; i++)
730 if (lut->table[i].r > D3_LUT_ENTRY_MASK ||
731 lut->table[i].g > D3_LUT_ENTRY_MASK ||
732 lut->table[i].b > D3_LUT_ENTRY_MASK)
733 return -EINVAL;
734
735 return 0;
736}
737
738static int ipipe_get_3d_lut_params(struct vpfe_ipipe_device *ipipe, void *param)
739{
740 struct vpfe_ipipe_3d_lut *lut_param = (struct vpfe_ipipe_3d_lut *)param;
741 struct vpfe_ipipe_3d_lut *lut = &ipipe->config.lut;
742 struct device *dev = ipipe->subdev.v4l2_dev->dev;
743
744 lut_param->en = lut->en;
745 if (!lut_param->table) {
746 dev_err(dev, "ipipe_get_3d_lut_params: Invalid table ptr\n");
747 return -EINVAL;
748 }
749
750 memcpy(lut_param->table, &lut->table,
751 (VPFE_IPIPE_MAX_SIZE_3D_LUT *
752 sizeof(struct vpfe_ipipe_3d_lut_entry)));
753
754 return 0;
755}
756
757static int
758ipipe_set_3d_lut_params(struct vpfe_ipipe_device *ipipe, void *param)
759{
760 struct vpfe_ipipe_3d_lut *lut_param = (struct vpfe_ipipe_3d_lut *)param;
761 struct vpfe_ipipe_3d_lut *lut = &ipipe->config.lut;
762 struct device *dev = ipipe->subdev.v4l2_dev->dev;
763
764 if (!lut_param) {
765 memset(lut, 0, sizeof(struct vpfe_ipipe_3d_lut));
766 goto success;
767 }
768
769 memcpy(lut, lut_param, sizeof(struct vpfe_ipipe_3d_lut));
770 if (ipipe_validate_3d_lut_params(lut) < 0) {
771 dev_err(dev, "Invalid 3D-LUT Params\n");
772 return -EINVAL;
773 }
774
775success:
776 ipipe_set_3d_lut_regs(ipipe->base_addr, ipipe->isp5_base_addr, lut);
777
778 return 0;
779}
780
781static int ipipe_validate_rgb2yuv_params(struct vpfe_ipipe_rgb2yuv *rgb2yuv)
782{
783 if (rgb2yuv->coef_ry.decimal > RGB2YCBCR_COEF_DECI_MASK ||
784 rgb2yuv->coef_ry.integer > RGB2YCBCR_COEF_INT_MASK)
785 return -EINVAL;
786
787 if (rgb2yuv->coef_gy.decimal > RGB2YCBCR_COEF_DECI_MASK ||
788 rgb2yuv->coef_gy.integer > RGB2YCBCR_COEF_INT_MASK)
789 return -EINVAL;
790
791 if (rgb2yuv->coef_by.decimal > RGB2YCBCR_COEF_DECI_MASK ||
792 rgb2yuv->coef_by.integer > RGB2YCBCR_COEF_INT_MASK)
793 return -EINVAL;
794
795 if (rgb2yuv->coef_rcb.decimal > RGB2YCBCR_COEF_DECI_MASK ||
796 rgb2yuv->coef_rcb.integer > RGB2YCBCR_COEF_INT_MASK)
797 return -EINVAL;
798
799 if (rgb2yuv->coef_gcb.decimal > RGB2YCBCR_COEF_DECI_MASK ||
800 rgb2yuv->coef_gcb.integer > RGB2YCBCR_COEF_INT_MASK)
801 return -EINVAL;
802
803 if (rgb2yuv->coef_bcb.decimal > RGB2YCBCR_COEF_DECI_MASK ||
804 rgb2yuv->coef_bcb.integer > RGB2YCBCR_COEF_INT_MASK)
805 return -EINVAL;
806
807 if (rgb2yuv->coef_rcr.decimal > RGB2YCBCR_COEF_DECI_MASK ||
808 rgb2yuv->coef_rcr.integer > RGB2YCBCR_COEF_INT_MASK)
809 return -EINVAL;
810
811 if (rgb2yuv->coef_gcr.decimal > RGB2YCBCR_COEF_DECI_MASK ||
812 rgb2yuv->coef_gcr.integer > RGB2YCBCR_COEF_INT_MASK)
813 return -EINVAL;
814
815 if (rgb2yuv->coef_bcr.decimal > RGB2YCBCR_COEF_DECI_MASK ||
816 rgb2yuv->coef_bcr.integer > RGB2YCBCR_COEF_INT_MASK)
817 return -EINVAL;
818
819 if (rgb2yuv->out_ofst_y > RGB2YCBCR_OFST_MASK ||
820 rgb2yuv->out_ofst_cb > RGB2YCBCR_OFST_MASK ||
821 rgb2yuv->out_ofst_cr > RGB2YCBCR_OFST_MASK)
822 return -EINVAL;
823
824 return 0;
825}
826
827static int
828ipipe_set_rgb2yuv_params(struct vpfe_ipipe_device *ipipe, void *param)
829{
830 struct vpfe_ipipe_rgb2yuv *rgb2yuv = &ipipe->config.rgb2yuv;
831 struct device *dev = ipipe->subdev.v4l2_dev->dev;
832 struct vpfe_ipipe_rgb2yuv *rgb2yuv_param;
833
834 rgb2yuv_param = (struct vpfe_ipipe_rgb2yuv *)param;
835 if (!rgb2yuv_param) {
836 /* Defaults for rgb2yuv conversion */
837 const struct vpfe_ipipe_rgb2yuv rgb2yuv_defaults = {
838 .coef_ry = {0, 0x4d},
839 .coef_gy = {0, 0x96},
840 .coef_by = {0, 0x1d},
841 .coef_rcb = {0xf, 0xd5},
842 .coef_gcb = {0xf, 0xab},
843 .coef_bcb = {0, 0x80},
844 .coef_rcr = {0, 0x80},
845 .coef_gcr = {0xf, 0x95},
846 .coef_bcr = {0xf, 0xeb},
847 .out_ofst_cb = 0x80,
848 .out_ofst_cr = 0x80,
849 };
850 /* Copy defaults for rgb2yuv conversion */
851 memcpy(rgb2yuv, &rgb2yuv_defaults,
852 sizeof(struct vpfe_ipipe_rgb2yuv));
853 goto success;
854 }
855
856 memcpy(rgb2yuv, rgb2yuv_param, sizeof(struct vpfe_ipipe_rgb2yuv));
857 if (ipipe_validate_rgb2yuv_params(rgb2yuv) < 0) {
858 dev_err(dev, "Invalid rgb2yuv params\n");
859 return -EINVAL;
860 }
861
862success:
863 ipipe_set_rgb2ycbcr_regs(ipipe->base_addr, rgb2yuv);
864
865 return 0;
866}
867
868static int
869ipipe_get_rgb2yuv_params(struct vpfe_ipipe_device *ipipe, void *param)
870{
871 struct vpfe_ipipe_rgb2yuv *rgb2yuv = &ipipe->config.rgb2yuv;
872 struct vpfe_ipipe_rgb2yuv *rgb2yuv_param;
873
874 rgb2yuv_param = (struct vpfe_ipipe_rgb2yuv *)param;
875 memcpy(rgb2yuv_param, rgb2yuv, sizeof(struct vpfe_ipipe_rgb2yuv));
876 return 0;
877}
878
879static int ipipe_validate_gbce_params(struct vpfe_ipipe_gbce *gbce)
880{
881 u32 max = GBCE_Y_VAL_MASK;
882 int i;
883
884 if (!gbce->en)
885 return 0;
886
887 if (gbce->type == VPFE_IPIPE_GBCE_GAIN_TBL)
888 max = GBCE_GAIN_VAL_MASK;
889
890 for (i = 0; i < VPFE_IPIPE_MAX_SIZE_GBCE_LUT; i++)
891 if (gbce->table[i] > max)
892 return -EINVAL;
893
894 return 0;
895}
896
897static int ipipe_set_gbce_params(struct vpfe_ipipe_device *ipipe, void *param)
898{
899 struct vpfe_ipipe_gbce *gbce_param = (struct vpfe_ipipe_gbce *)param;
900 struct vpfe_ipipe_gbce *gbce = &ipipe->config.gbce;
901 struct device *dev = ipipe->subdev.v4l2_dev->dev;
902
903 if (!gbce_param) {
904 memset(gbce, 0 , sizeof(struct vpfe_ipipe_gbce));
905 } else {
906 memcpy(gbce, gbce_param, sizeof(struct vpfe_ipipe_gbce));
907 if (ipipe_validate_gbce_params(gbce) < 0) {
908 dev_err(dev, "Invalid gbce params\n");
909 return -EINVAL;
910 }
911 }
912
913 ipipe_set_gbce_regs(ipipe->base_addr, ipipe->isp5_base_addr, gbce);
914
915 return 0;
916}
917
918static int ipipe_get_gbce_params(struct vpfe_ipipe_device *ipipe, void *param)
919{
920 struct vpfe_ipipe_gbce *gbce_param = (struct vpfe_ipipe_gbce *)param;
921 struct vpfe_ipipe_gbce *gbce = &ipipe->config.gbce;
922 struct device *dev = ipipe->subdev.v4l2_dev->dev;
923
924 gbce_param->en = gbce->en;
925 gbce_param->type = gbce->type;
926 if (!gbce_param->table) {
927 dev_err(dev, "ipipe_get_gbce_params: Invalid table ptr\n");
928 return -EINVAL;
929 }
930
931 memcpy(gbce_param->table, gbce->table,
932 (VPFE_IPIPE_MAX_SIZE_GBCE_LUT * sizeof(unsigned short)));
933
934 return 0;
935}
936
937static int
938ipipe_validate_yuv422_conv_params(struct vpfe_ipipe_yuv422_conv *yuv422_conv)
939{
940 if (yuv422_conv->en_chrom_lpf > 1)
941 return -EINVAL;
942
943 return 0;
944}
945
946static int
947ipipe_set_yuv422_conv_params(struct vpfe_ipipe_device *ipipe, void *param)
948{
949 struct vpfe_ipipe_yuv422_conv *yuv422_conv = &ipipe->config.yuv422_conv;
950 struct vpfe_ipipe_yuv422_conv *yuv422_conv_param;
951 struct device *dev = ipipe->subdev.v4l2_dev->dev;
952
953 yuv422_conv_param = (struct vpfe_ipipe_yuv422_conv *)param;
954 if (!yuv422_conv_param) {
955 memset(yuv422_conv, 0, sizeof(struct vpfe_ipipe_yuv422_conv));
956 yuv422_conv->chrom_pos = VPFE_IPIPE_YUV422_CHR_POS_COSITE;
957 } else {
958 memcpy(yuv422_conv, yuv422_conv_param,
959 sizeof(struct vpfe_ipipe_yuv422_conv));
960 if (ipipe_validate_yuv422_conv_params(yuv422_conv) < 0) {
961 dev_err(dev, "Invalid yuv422 params\n");
962 return -EINVAL;
963 }
964 }
965
966 ipipe_set_yuv422_conv_regs(ipipe->base_addr, yuv422_conv);
967
968 return 0;
969}
970
971static int
972ipipe_get_yuv422_conv_params(struct vpfe_ipipe_device *ipipe, void *param)
973{
974 struct vpfe_ipipe_yuv422_conv *yuv422_conv = &ipipe->config.yuv422_conv;
975 struct vpfe_ipipe_yuv422_conv *yuv422_conv_param;
976
977 yuv422_conv_param = (struct vpfe_ipipe_yuv422_conv *)param;
978 memcpy(yuv422_conv_param, yuv422_conv,
979 sizeof(struct vpfe_ipipe_yuv422_conv));
980
981 return 0;
982}
983
984static int ipipe_validate_yee_params(struct vpfe_ipipe_yee *yee)
985{
986 int i;
987
988 if (yee->en > 1 ||
989 yee->en_halo_red > 1 ||
990 yee->hpf_shft > YEE_HPF_SHIFT_MASK)
991 return -EINVAL;
992
993 if (yee->hpf_coef_00 > YEE_COEF_MASK ||
994 yee->hpf_coef_01 > YEE_COEF_MASK ||
995 yee->hpf_coef_02 > YEE_COEF_MASK ||
996 yee->hpf_coef_10 > YEE_COEF_MASK ||
997 yee->hpf_coef_11 > YEE_COEF_MASK ||
998 yee->hpf_coef_12 > YEE_COEF_MASK ||
999 yee->hpf_coef_20 > YEE_COEF_MASK ||
1000 yee->hpf_coef_21 > YEE_COEF_MASK ||
1001 yee->hpf_coef_22 > YEE_COEF_MASK)
1002 return -EINVAL;
1003
1004 if (yee->yee_thr > YEE_THR_MASK ||
1005 yee->es_gain > YEE_ES_GAIN_MASK ||
1006 yee->es_thr1 > YEE_ES_THR1_MASK ||
1007 yee->es_thr2 > YEE_THR_MASK ||
1008 yee->es_gain_grad > YEE_THR_MASK ||
1009 yee->es_ofst_grad > YEE_THR_MASK)
1010 return -EINVAL;
1011
1012 for (i = 0; i < VPFE_IPIPE_MAX_SIZE_YEE_LUT ; i++)
1013 if (yee->table[i] > YEE_ENTRY_MASK)
1014 return -EINVAL;
1015
1016 return 0;
1017}
1018
1019static int ipipe_set_yee_params(struct vpfe_ipipe_device *ipipe, void *param)
1020{
1021 struct vpfe_ipipe_yee *yee_param = (struct vpfe_ipipe_yee *)param;
1022 struct device *dev = ipipe->subdev.v4l2_dev->dev;
1023 struct vpfe_ipipe_yee *yee = &ipipe->config.yee;
1024
1025 if (!yee_param) {
1026 memset(yee, 0, sizeof(struct vpfe_ipipe_yee));
1027 } else {
1028 memcpy(yee, yee_param, sizeof(struct vpfe_ipipe_yee));
1029 if (ipipe_validate_yee_params(yee) < 0) {
1030 dev_err(dev, "Invalid yee params\n");
1031 return -EINVAL;
1032 }
1033 }
1034
1035 ipipe_set_ee_regs(ipipe->base_addr, ipipe->isp5_base_addr, yee);
1036
1037 return 0;
1038}
1039
1040static int ipipe_get_yee_params(struct vpfe_ipipe_device *ipipe, void *param)
1041{
1042 struct vpfe_ipipe_yee *yee_param = (struct vpfe_ipipe_yee *)param;
1043 struct vpfe_ipipe_yee *yee = &ipipe->config.yee;
1044
1045 yee_param->en = yee->en;
1046 yee_param->en_halo_red = yee->en_halo_red;
1047 yee_param->merge_meth = yee->merge_meth;
1048 yee_param->hpf_shft = yee->hpf_shft;
1049 yee_param->hpf_coef_00 = yee->hpf_coef_00;
1050 yee_param->hpf_coef_01 = yee->hpf_coef_01;
1051 yee_param->hpf_coef_02 = yee->hpf_coef_02;
1052 yee_param->hpf_coef_10 = yee->hpf_coef_10;
1053 yee_param->hpf_coef_11 = yee->hpf_coef_11;
1054 yee_param->hpf_coef_12 = yee->hpf_coef_12;
1055 yee_param->hpf_coef_20 = yee->hpf_coef_20;
1056 yee_param->hpf_coef_21 = yee->hpf_coef_21;
1057 yee_param->hpf_coef_22 = yee->hpf_coef_22;
1058 yee_param->yee_thr = yee->yee_thr;
1059 yee_param->es_gain = yee->es_gain;
1060 yee_param->es_thr1 = yee->es_thr1;
1061 yee_param->es_thr2 = yee->es_thr2;
1062 yee_param->es_gain_grad = yee->es_gain_grad;
1063 yee_param->es_ofst_grad = yee->es_ofst_grad;
1064 memcpy(yee_param->table, &yee->table,
1065 (VPFE_IPIPE_MAX_SIZE_YEE_LUT * sizeof(short)));
1066
1067 return 0;
1068}
1069
1070static int ipipe_validate_car_params(struct vpfe_ipipe_car *car)
1071{
1072 if (car->en > 1 || car->hpf_shft > CAR_HPF_SHIFT_MASK ||
1073 car->gain1.shft > CAR_GAIN1_SHFT_MASK ||
1074 car->gain1.gain_min > CAR_GAIN_MIN_MASK ||
1075 car->gain2.shft > CAR_GAIN2_SHFT_MASK ||
1076 car->gain2.gain_min > CAR_GAIN_MIN_MASK)
1077 return -EINVAL;
1078
1079 return 0;
1080}
1081
1082static int ipipe_set_car_params(struct vpfe_ipipe_device *ipipe, void *param)
1083{
1084 struct vpfe_ipipe_car *car_param = (struct vpfe_ipipe_car *)param;
1085 struct device *dev = ipipe->subdev.v4l2_dev->dev;
1086 struct vpfe_ipipe_car *car = &ipipe->config.car;
1087
1088 if (!car_param) {
1089 memset(car , 0, sizeof(struct vpfe_ipipe_car));
1090 } else {
1091 memcpy(car, car_param, sizeof(struct vpfe_ipipe_car));
1092 if (ipipe_validate_car_params(car) < 0) {
1093 dev_err(dev, "Invalid car params\n");
1094 return -EINVAL;
1095 }
1096 }
1097
1098 ipipe_set_car_regs(ipipe->base_addr, car);
1099
1100 return 0;
1101}
1102
1103static int ipipe_get_car_params(struct vpfe_ipipe_device *ipipe, void *param)
1104{
1105 struct vpfe_ipipe_car *car_param = (struct vpfe_ipipe_car *)param;
1106 struct vpfe_ipipe_car *car = &ipipe->config.car;
1107
1108 memcpy(car_param, car, sizeof(struct vpfe_ipipe_car));
1109 return 0;
1110}
1111
1112static int ipipe_validate_cgs_params(struct vpfe_ipipe_cgs *cgs)
1113{
1114 if (cgs->en > 1 || cgs->h_shft > CAR_SHIFT_MASK)
1115 return -EINVAL;
1116
1117 return 0;
1118}
1119
1120static int ipipe_set_cgs_params(struct vpfe_ipipe_device *ipipe, void *param)
1121{
1122 struct vpfe_ipipe_cgs *cgs_param = (struct vpfe_ipipe_cgs *)param;
1123 struct device *dev = ipipe->subdev.v4l2_dev->dev;
1124 struct vpfe_ipipe_cgs *cgs = &ipipe->config.cgs;
1125
1126 if (!cgs_param) {
1127 memset(cgs, 0, sizeof(struct vpfe_ipipe_cgs));
1128 } else {
1129 memcpy(cgs, cgs_param, sizeof(struct vpfe_ipipe_cgs));
1130 if (ipipe_validate_cgs_params(cgs) < 0) {
1131 dev_err(dev, "Invalid cgs params\n");
1132 return -EINVAL;
1133 }
1134 }
1135
1136 ipipe_set_cgs_regs(ipipe->base_addr, cgs);
1137
1138 return 0;
1139}
1140
1141static int ipipe_get_cgs_params(struct vpfe_ipipe_device *ipipe, void *param)
1142{
1143 struct vpfe_ipipe_cgs *cgs_param = (struct vpfe_ipipe_cgs *)param;
1144 struct vpfe_ipipe_cgs *cgs = &ipipe->config.cgs;
1145
1146 memcpy(cgs_param, cgs, sizeof(struct vpfe_ipipe_cgs));
1147
1148 return 0;
1149}
1150
1151static const struct ipipe_module_if ipipe_modules[VPFE_IPIPE_MAX_MODULES] = {
1152 /* VPFE_IPIPE_INPUT_CONFIG */ {
1153 offsetof(struct ipipe_module_params, input_config),
1154 FIELD_SIZEOF(struct ipipe_module_params, input_config),
1155 offsetof(struct vpfe_ipipe_config, input_config),
1156 ipipe_set_input_config,
1157 ipipe_get_input_config,
1158 }, /* VPFE_IPIPE_LUTDPC */ {
1159 offsetof(struct ipipe_module_params, lutdpc),
1160 FIELD_SIZEOF(struct ipipe_module_params, lutdpc),
1161 offsetof(struct vpfe_ipipe_config, lutdpc),
1162 ipipe_set_lutdpc_params,
1163 ipipe_get_lutdpc_params,
1164 }, /* VPFE_IPIPE_OTFDPC */ {
1165 offsetof(struct ipipe_module_params, otfdpc),
1166 FIELD_SIZEOF(struct ipipe_module_params, otfdpc),
1167 offsetof(struct vpfe_ipipe_config, otfdpc),
1168 ipipe_set_otfdpc_params,
1169 ipipe_get_otfdpc_params,
1170 }, /* VPFE_IPIPE_NF1 */ {
1171 offsetof(struct ipipe_module_params, nf1),
1172 FIELD_SIZEOF(struct ipipe_module_params, nf1),
1173 offsetof(struct vpfe_ipipe_config, nf1),
1174 ipipe_set_nf1_params,
1175 ipipe_get_nf1_params,
1176 }, /* VPFE_IPIPE_NF2 */ {
1177 offsetof(struct ipipe_module_params, nf2),
1178 FIELD_SIZEOF(struct ipipe_module_params, nf2),
1179 offsetof(struct vpfe_ipipe_config, nf2),
1180 ipipe_set_nf2_params,
1181 ipipe_get_nf2_params,
1182 }, /* VPFE_IPIPE_WB */ {
1183 offsetof(struct ipipe_module_params, wbal),
1184 FIELD_SIZEOF(struct ipipe_module_params, wbal),
1185 offsetof(struct vpfe_ipipe_config, wbal),
1186 ipipe_set_wb_params,
1187 ipipe_get_wb_params,
1188 }, /* VPFE_IPIPE_RGB2RGB_1 */ {
1189 offsetof(struct ipipe_module_params, rgb2rgb1),
1190 FIELD_SIZEOF(struct ipipe_module_params, rgb2rgb1),
1191 offsetof(struct vpfe_ipipe_config, rgb2rgb1),
1192 ipipe_set_rgb2rgb_1_params,
1193 ipipe_get_rgb2rgb_1_params,
1194 }, /* VPFE_IPIPE_RGB2RGB_2 */ {
1195 offsetof(struct ipipe_module_params, rgb2rgb2),
1196 FIELD_SIZEOF(struct ipipe_module_params, rgb2rgb2),
1197 offsetof(struct vpfe_ipipe_config, rgb2rgb2),
1198 ipipe_set_rgb2rgb_2_params,
1199 ipipe_get_rgb2rgb_2_params,
1200 }, /* VPFE_IPIPE_GAMMA */ {
1201 offsetof(struct ipipe_module_params, gamma),
1202 FIELD_SIZEOF(struct ipipe_module_params, gamma),
1203 offsetof(struct vpfe_ipipe_config, gamma),
1204 ipipe_set_gamma_params,
1205 ipipe_get_gamma_params,
1206 }, /* VPFE_IPIPE_3D_LUT */ {
1207 offsetof(struct ipipe_module_params, lut),
1208 FIELD_SIZEOF(struct ipipe_module_params, lut),
1209 offsetof(struct vpfe_ipipe_config, lut),
1210 ipipe_set_3d_lut_params,
1211 ipipe_get_3d_lut_params,
1212 }, /* VPFE_IPIPE_RGB2YUV */ {
1213 offsetof(struct ipipe_module_params, rgb2yuv),
1214 FIELD_SIZEOF(struct ipipe_module_params, rgb2yuv),
1215 offsetof(struct vpfe_ipipe_config, rgb2yuv),
1216 ipipe_set_rgb2yuv_params,
1217 ipipe_get_rgb2yuv_params,
1218 }, /* VPFE_IPIPE_YUV422_CONV */ {
1219 offsetof(struct ipipe_module_params, yuv422_conv),
1220 FIELD_SIZEOF(struct ipipe_module_params, yuv422_conv),
1221 offsetof(struct vpfe_ipipe_config, yuv422_conv),
1222 ipipe_set_yuv422_conv_params,
1223 ipipe_get_yuv422_conv_params,
1224 }, /* VPFE_IPIPE_YEE */ {
1225 offsetof(struct ipipe_module_params, yee),
1226 FIELD_SIZEOF(struct ipipe_module_params, yee),
1227 offsetof(struct vpfe_ipipe_config, yee),
1228 ipipe_set_yee_params,
1229 ipipe_get_yee_params,
1230 }, /* VPFE_IPIPE_GIC */ {
1231 offsetof(struct ipipe_module_params, gic),
1232 FIELD_SIZEOF(struct ipipe_module_params, gic),
1233 offsetof(struct vpfe_ipipe_config, gic),
1234 ipipe_set_gic_params,
1235 ipipe_get_gic_params,
1236 }, /* VPFE_IPIPE_CFA */ {
1237 offsetof(struct ipipe_module_params, cfa),
1238 FIELD_SIZEOF(struct ipipe_module_params, cfa),
1239 offsetof(struct vpfe_ipipe_config, cfa),
1240 ipipe_set_cfa_params,
1241 ipipe_get_cfa_params,
1242 }, /* VPFE_IPIPE_CAR */ {
1243 offsetof(struct ipipe_module_params, car),
1244 FIELD_SIZEOF(struct ipipe_module_params, car),
1245 offsetof(struct vpfe_ipipe_config, car),
1246 ipipe_set_car_params,
1247 ipipe_get_car_params,
1248 }, /* VPFE_IPIPE_CGS */ {
1249 offsetof(struct ipipe_module_params, cgs),
1250 FIELD_SIZEOF(struct ipipe_module_params, cgs),
1251 offsetof(struct vpfe_ipipe_config, cgs),
1252 ipipe_set_cgs_params,
1253 ipipe_get_cgs_params,
1254 }, /* VPFE_IPIPE_GBCE */ {
1255 offsetof(struct ipipe_module_params, gbce),
1256 FIELD_SIZEOF(struct ipipe_module_params, gbce),
1257 offsetof(struct vpfe_ipipe_config, gbce),
1258 ipipe_set_gbce_params,
1259 ipipe_get_gbce_params,
1260 },
1261};
1262
1263static int ipipe_s_config(struct v4l2_subdev *sd, struct vpfe_ipipe_config *cfg)
1264{
1265 struct vpfe_ipipe_device *ipipe = v4l2_get_subdevdata(sd);
1266 unsigned int i;
1267 int rval = 0;
1268
1269 for (i = 0; i < ARRAY_SIZE(ipipe_modules); i++) {
1270 unsigned int bit = 1 << i;
1271 if (cfg->flag & bit) {
1272 const struct ipipe_module_if *module_if =
1273 &ipipe_modules[i];
1274 struct ipipe_module_params *params;
1275 void __user *from = *(void * __user *)
1276 ((void *)cfg + module_if->config_offset);
1277 size_t size;
1278 void *to;
1279
1280 params = kmalloc(sizeof(struct ipipe_module_params),
1281 GFP_KERNEL);
1282 to = (void *)params + module_if->param_offset;
1283 size = module_if->param_size;
1284
1285 if (to && from && size) {
1286 if (copy_from_user(to, from, size)) {
1287 rval = -EFAULT;
1288 break;
1289 }
1290 rval = module_if->set(ipipe, to);
1291 if (rval)
1292 goto error;
1293 } else if (to && !from && size) {
1294 rval = module_if->set(ipipe, NULL);
1295 if (rval)
1296 goto error;
1297 }
1298 kfree(params);
1299 }
1300 }
1301error:
1302 return rval;
1303}
1304
1305static int ipipe_g_config(struct v4l2_subdev *sd, struct vpfe_ipipe_config *cfg)
1306{
1307 struct vpfe_ipipe_device *ipipe = v4l2_get_subdevdata(sd);
1308 unsigned int i;
1309 int rval = 0;
1310
1311 for (i = 1; i < ARRAY_SIZE(ipipe_modules); i++) {
1312 unsigned int bit = 1 << i;
1313 if (cfg->flag & bit) {
1314 const struct ipipe_module_if *module_if =
1315 &ipipe_modules[i];
1316 struct ipipe_module_params *params;
1317 void __user *to = *(void * __user *)
1318 ((void *)cfg + module_if->config_offset);
1319 size_t size;
1320 void *from;
1321
1322 params = kmalloc(sizeof(struct ipipe_module_params),
1323 GFP_KERNEL);
1324 from = (void *)params + module_if->param_offset;
1325 size = module_if->param_size;
1326
1327 if (to && from && size) {
1328 rval = module_if->get(ipipe, from);
1329 if (rval)
1330 goto error;
1331 if (copy_to_user(to, from, size)) {
1332 rval = -EFAULT;
1333 break;
1334 }
1335 }
1336 kfree(params);
1337 }
1338 }
1339error:
1340 return rval;
1341}
1342
1343/*
1344 * ipipe_ioctl() - Handle ipipe module private ioctl's
1345 * @sd: pointer to v4l2 subdev structure
1346 * @cmd: configuration command
1347 * @arg: configuration argument
1348 */
1349static long ipipe_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
1350{
1351 int ret = 0;
1352
1353 switch (cmd) {
1354 case VIDIOC_VPFE_IPIPE_S_CONFIG:
1355 ret = ipipe_s_config(sd, arg);
1356 break;
1357
1358 case VIDIOC_VPFE_IPIPE_G_CONFIG:
1359 ret = ipipe_g_config(sd, arg);
1360 break;
1361
1362 default:
1363 ret = -ENOIOCTLCMD;
1364 }
1365 return ret;
1366}
1367
1368void vpfe_ipipe_enable(struct vpfe_device *vpfe_dev, int en)
1369{
1370 struct vpfe_ipipeif_device *ipipeif = &vpfe_dev->vpfe_ipipeif;
1371 struct vpfe_ipipe_device *ipipe = &vpfe_dev->vpfe_ipipe;
1372 unsigned char val;
1373
1374 if (ipipe->input == IPIPE_INPUT_NONE)
1375 return;
1376
1377 /* ipipe is set to single shot */
1378 if (ipipeif->input == IPIPEIF_INPUT_MEMORY && en) {
1379 /* for single-shot mode, need to wait for h/w to
1380 * reset many register bits
1381 */
1382 do {
1383 val = regr_ip(vpfe_dev->vpfe_ipipe.base_addr,
1384 IPIPE_SRC_EN);
1385 } while (val);
1386 }
1387 regw_ip(vpfe_dev->vpfe_ipipe.base_addr, en, IPIPE_SRC_EN);
1388}
1389
1390/*
1391 * ipipe_set_stream() - Enable/Disable streaming on the ipipe subdevice
1392 * @sd: pointer to v4l2 subdev structure
1393 * @enable: 1 == Enable, 0 == Disable
1394 */
1395static int ipipe_set_stream(struct v4l2_subdev *sd, int enable)
1396{
1397 struct vpfe_ipipe_device *ipipe = v4l2_get_subdevdata(sd);
1398 struct vpfe_device *vpfe_dev = to_vpfe_device(ipipe);
1399
1400 if (enable && ipipe->input != IPIPE_INPUT_NONE &&
1401 ipipe->output != IPIPE_OUTPUT_NONE) {
1402 if (config_ipipe_hw(ipipe) < 0)
1403 return -EINVAL;
1404 }
1405
1406 vpfe_ipipe_enable(vpfe_dev, enable);
1407
1408 return 0;
1409}
1410
1411/*
1412 * __ipipe_get_format() - helper function for getting ipipe format
1413 * @ipipe: pointer to ipipe private structure.
1414 * @pad: pad number.
1415 * @fh: V4L2 subdev file handle.
1416 * @which: wanted subdev format.
1417 *
1418 */
1419static struct v4l2_mbus_framefmt *
1420__ipipe_get_format(struct vpfe_ipipe_device *ipipe,
1421 struct v4l2_subdev_fh *fh, unsigned int pad,
1422 enum v4l2_subdev_format_whence which)
1423{
1424 if (which == V4L2_SUBDEV_FORMAT_TRY)
1425 return v4l2_subdev_get_try_format(fh, pad);
1426
1427 return &ipipe->formats[pad];
1428}
1429
1430/*
1431 * ipipe_try_format() - Handle try format by pad subdev method
1432 * @ipipe: VPFE ipipe device.
1433 * @fh: V4L2 subdev file handle.
1434 * @pad: pad num.
1435 * @fmt: pointer to v4l2 format structure.
1436 * @which : wanted subdev format
1437 */
1438static void
1439ipipe_try_format(struct vpfe_ipipe_device *ipipe,
1440 struct v4l2_subdev_fh *fh, unsigned int pad,
1441 struct v4l2_mbus_framefmt *fmt,
1442 enum v4l2_subdev_format_whence which)
1443{
1444 unsigned int max_out_height;
1445 unsigned int max_out_width;
1446 unsigned int i;
1447
1448 max_out_width = IPIPE_MAX_OUTPUT_WIDTH_A;
1449 max_out_height = IPIPE_MAX_OUTPUT_HEIGHT_A;
1450
1451 if (pad == IPIPE_PAD_SINK) {
1452 for (i = 0; i < ARRAY_SIZE(ipipe_input_fmts); i++)
1453 if (fmt->code == ipipe_input_fmts[i])
1454 break;
1455
1456 /* If not found, use SBGGR10 as default */
1457 if (i >= ARRAY_SIZE(ipipe_input_fmts))
1458 fmt->code = V4L2_MBUS_FMT_SGRBG12_1X12;
1459 } else if (pad == IPIPE_PAD_SOURCE) {
1460 for (i = 0; i < ARRAY_SIZE(ipipe_output_fmts); i++)
1461 if (fmt->code == ipipe_output_fmts[i])
1462 break;
1463
1464 /* If not found, use UYVY as default */
1465 if (i >= ARRAY_SIZE(ipipe_output_fmts))
1466 fmt->code = V4L2_MBUS_FMT_UYVY8_2X8;
1467 }
1468
1469 fmt->width = clamp_t(u32, fmt->width, MIN_OUT_HEIGHT, max_out_width);
1470 fmt->height = clamp_t(u32, fmt->height, MIN_OUT_WIDTH, max_out_height);
1471}
1472
1473/*
1474 * ipipe_set_format() - Handle set format by pads subdev method
1475 * @sd: pointer to v4l2 subdev structure
1476 * @fh: V4L2 subdev file handle
1477 * @fmt: pointer to v4l2 subdev format structure
1478 * return -EINVAL or zero on success
1479 */
1480static int
1481ipipe_set_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1482 struct v4l2_subdev_format *fmt)
1483{
1484 struct vpfe_ipipe_device *ipipe = v4l2_get_subdevdata(sd);
1485 struct v4l2_mbus_framefmt *format;
1486
1487 format = __ipipe_get_format(ipipe, fh, fmt->pad, fmt->which);
1488 if (format == NULL)
1489 return -EINVAL;
1490
1491 ipipe_try_format(ipipe, fh, fmt->pad, &fmt->format, fmt->which);
1492 *format = fmt->format;
1493
1494 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY)
1495 return 0;
1496
1497 if (fmt->pad == IPIPE_PAD_SINK &&
1498 (ipipe->input == IPIPE_INPUT_CCDC ||
1499 ipipe->input == IPIPE_INPUT_MEMORY))
1500 ipipe->formats[fmt->pad] = fmt->format;
1501 else if (fmt->pad == IPIPE_PAD_SOURCE &&
1502 ipipe->output == IPIPE_OUTPUT_RESIZER)
1503 ipipe->formats[fmt->pad] = fmt->format;
1504 else
1505 return -EINVAL;
1506
1507 return 0;
1508}
1509
1510/*
1511 * ipipe_get_format() - Handle get format by pads subdev method.
1512 * @sd: pointer to v4l2 subdev structure.
1513 * @fh: V4L2 subdev file handle.
1514 * @fmt: pointer to v4l2 subdev format structure.
1515 */
1516static int
1517ipipe_get_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1518 struct v4l2_subdev_format *fmt)
1519{
1520 struct vpfe_ipipe_device *ipipe = v4l2_get_subdevdata(sd);
1521
1522 if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE)
1523 fmt->format = ipipe->formats[fmt->pad];
1524 else
1525 fmt->format = *(v4l2_subdev_get_try_format(fh, fmt->pad));
1526
1527 return 0;
1528}
1529
1530/*
1531 * ipipe_enum_frame_size() - enum frame sizes on pads
1532 * @sd: pointer to v4l2 subdev structure.
1533 * @fh: V4L2 subdev file handle.
1534 * @fse: pointer to v4l2_subdev_frame_size_enum structure.
1535 */
1536static int
1537ipipe_enum_frame_size(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1538 struct v4l2_subdev_frame_size_enum *fse)
1539{
1540 struct vpfe_ipipe_device *ipipe = v4l2_get_subdevdata(sd);
1541 struct v4l2_mbus_framefmt format;
1542
1543 if (fse->index != 0)
1544 return -EINVAL;
1545
1546 format.code = fse->code;
1547 format.width = 1;
1548 format.height = 1;
1549 ipipe_try_format(ipipe, fh, fse->pad, &format,
1550 V4L2_SUBDEV_FORMAT_TRY);
1551 fse->min_width = format.width;
1552 fse->min_height = format.height;
1553
1554 if (format.code != fse->code)
1555 return -EINVAL;
1556
1557 format.code = fse->code;
1558 format.width = -1;
1559 format.height = -1;
1560 ipipe_try_format(ipipe, fh, fse->pad, &format,
1561 V4L2_SUBDEV_FORMAT_TRY);
1562 fse->max_width = format.width;
1563 fse->max_height = format.height;
1564
1565 return 0;
1566}
1567
1568/*
1569 * ipipe_enum_mbus_code() - enum mbus codes for pads
1570 * @sd: pointer to v4l2 subdev structure.
1571 * @fh: V4L2 subdev file handle
1572 * @code: pointer to v4l2_subdev_mbus_code_enum structure
1573 */
1574static int
1575ipipe_enum_mbus_code(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1576 struct v4l2_subdev_mbus_code_enum *code)
1577{
1578 switch (code->pad) {
1579 case IPIPE_PAD_SINK:
1580 if (code->index >= ARRAY_SIZE(ipipe_input_fmts))
1581 return -EINVAL;
1582 code->code = ipipe_input_fmts[code->index];
1583 break;
1584
1585 case IPIPE_PAD_SOURCE:
1586 if (code->index >= ARRAY_SIZE(ipipe_output_fmts))
1587 return -EINVAL;
1588 code->code = ipipe_output_fmts[code->index];
1589 break;
1590
1591 default:
1592 return -EINVAL;
1593 }
1594
1595 return 0;
1596}
1597
1598/*
1599 * ipipe_s_ctrl() - Handle set control subdev method
1600 * @ctrl: pointer to v4l2 control structure
1601 */
1602static int ipipe_s_ctrl(struct v4l2_ctrl *ctrl)
1603{
1604 struct vpfe_ipipe_device *ipipe =
1605 container_of(ctrl->handler, struct vpfe_ipipe_device, ctrls);
1606 struct ipipe_lum_adj *lum_adj = &ipipe->config.lum_adj;
1607
1608 switch (ctrl->id) {
1609 case V4L2_CID_BRIGHTNESS:
1610 lum_adj->brightness = ctrl->val;
1611 ipipe_set_lum_adj_regs(ipipe->base_addr, lum_adj);
1612 break;
1613
1614 case V4L2_CID_CONTRAST:
1615 lum_adj->contrast = ctrl->val;
1616 ipipe_set_lum_adj_regs(ipipe->base_addr, lum_adj);
1617 break;
1618
1619 default:
1620 return -EINVAL;
1621 }
1622
1623 return 0;
1624}
1625
1626/*
1627 * ipipe_init_formats() - Initialize formats on all pads
1628 * @sd: pointer to v4l2 subdev structure.
1629 * @fh: V4L2 subdev file handle
1630 *
1631 * Initialize all pad formats with default values. If fh is not NULL, try
1632 * formats are initialized on the file handle. Otherwise active formats are
1633 * initialized on the device.
1634 */
1635static int
1636ipipe_init_formats(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
1637{
1638 struct v4l2_subdev_format format;
1639
1640 memset(&format, 0, sizeof(format));
1641 format.pad = IPIPE_PAD_SINK;
1642 format.which = fh ? V4L2_SUBDEV_FORMAT_TRY : V4L2_SUBDEV_FORMAT_ACTIVE;
1643 format.format.code = V4L2_MBUS_FMT_SGRBG12_1X12;
1644 format.format.width = IPIPE_MAX_OUTPUT_WIDTH_A;
1645 format.format.height = IPIPE_MAX_OUTPUT_HEIGHT_A;
1646 ipipe_set_format(sd, fh, &format);
1647
1648 memset(&format, 0, sizeof(format));
1649 format.pad = IPIPE_PAD_SOURCE;
1650 format.which = fh ? V4L2_SUBDEV_FORMAT_TRY : V4L2_SUBDEV_FORMAT_ACTIVE;
1651 format.format.code = V4L2_MBUS_FMT_UYVY8_2X8;
1652 format.format.width = IPIPE_MAX_OUTPUT_WIDTH_A;
1653 format.format.height = IPIPE_MAX_OUTPUT_HEIGHT_A;
1654 ipipe_set_format(sd, fh, &format);
1655
1656 return 0;
1657}
1658
1659/* subdev core operations */
1660static const struct v4l2_subdev_core_ops ipipe_v4l2_core_ops = {
1661 .ioctl = ipipe_ioctl,
1662};
1663
1664static const struct v4l2_ctrl_ops ipipe_ctrl_ops = {
1665 .s_ctrl = ipipe_s_ctrl,
1666};
1667
1668/* subdev file operations */
1669static const struct v4l2_subdev_internal_ops ipipe_v4l2_internal_ops = {
1670 .open = ipipe_init_formats,
1671};
1672
1673/* subdev video operations */
1674static const struct v4l2_subdev_video_ops ipipe_v4l2_video_ops = {
1675 .s_stream = ipipe_set_stream,
1676};
1677
1678/* subdev pad operations */
1679static const struct v4l2_subdev_pad_ops ipipe_v4l2_pad_ops = {
1680 .enum_mbus_code = ipipe_enum_mbus_code,
1681 .enum_frame_size = ipipe_enum_frame_size,
1682 .get_fmt = ipipe_get_format,
1683 .set_fmt = ipipe_set_format,
1684};
1685
1686/* v4l2 subdev operation */
1687static const struct v4l2_subdev_ops ipipe_v4l2_ops = {
1688 .core = &ipipe_v4l2_core_ops,
1689 .video = &ipipe_v4l2_video_ops,
1690 .pad = &ipipe_v4l2_pad_ops,
1691};
1692
1693/*
1694 * Media entity operations
1695 */
1696
1697/*
1698 * ipipe_link_setup() - Setup ipipe connections
1699 * @entity: ipipe media entity
1700 * @local: Pad at the local end of the link
1701 * @remote: Pad at the remote end of the link
1702 * @flags: Link flags
1703 *
1704 * return -EINVAL or zero on success
1705 */
1706static int
1707ipipe_link_setup(struct media_entity *entity, const struct media_pad *local,
1708 const struct media_pad *remote, u32 flags)
1709{
1710 struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
1711 struct vpfe_ipipe_device *ipipe = v4l2_get_subdevdata(sd);
1712 struct vpfe_device *vpfe_dev = to_vpfe_device(ipipe);
1713 u16 ipipeif_sink = vpfe_dev->vpfe_ipipeif.input;
1714
1715 switch (local->index | media_entity_type(remote->entity)) {
1716 case IPIPE_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
1717 if (!(flags & MEDIA_LNK_FL_ENABLED)) {
1718 ipipe->input = IPIPE_INPUT_NONE;
1719 break;
1720 }
1721 if (ipipe->input != IPIPE_INPUT_NONE)
1722 return -EBUSY;
1723 if (ipipeif_sink == IPIPEIF_INPUT_MEMORY)
1724 ipipe->input = IPIPE_INPUT_MEMORY;
1725 else
1726 ipipe->input = IPIPE_INPUT_CCDC;
1727 break;
1728
1729 case IPIPE_PAD_SOURCE | MEDIA_ENT_T_V4L2_SUBDEV:
1730 /* out to RESIZER */
1731 if (flags & MEDIA_LNK_FL_ENABLED)
1732 ipipe->output = IPIPE_OUTPUT_RESIZER;
1733 else
1734 ipipe->output = IPIPE_OUTPUT_NONE;
1735 break;
1736
1737 default:
1738 return -EINVAL;
1739 }
1740
1741 return 0;
1742}
1743
1744static const struct media_entity_operations ipipe_media_ops = {
1745 .link_setup = ipipe_link_setup,
1746};
1747
1748/*
1749 * vpfe_ipipe_unregister_entities() - ipipe unregister entity
1750 * @vpfe_ipipe: pointer to ipipe subdevice structure.
1751 */
1752void vpfe_ipipe_unregister_entities(struct vpfe_ipipe_device *vpfe_ipipe)
1753{
1754 /* cleanup entity */
1755 media_entity_cleanup(&vpfe_ipipe->subdev.entity);
1756 /* unregister subdev */
1757 v4l2_device_unregister_subdev(&vpfe_ipipe->subdev);
1758}
1759
1760/*
1761 * vpfe_ipipe_register_entities() - ipipe register entity
1762 * @ipipe: pointer to ipipe subdevice structure.
1763 * @vdev: pointer to v4l2 device structure.
1764 */
1765int
1766vpfe_ipipe_register_entities(struct vpfe_ipipe_device *ipipe,
1767 struct v4l2_device *vdev)
1768{
1769 int ret;
1770
1771 /* Register the subdev */
1772 ret = v4l2_device_register_subdev(vdev, &ipipe->subdev);
1773 if (ret) {
1774 pr_err("Failed to register ipipe as v4l2 subdevice\n");
1775 return ret;
1776 }
1777
1778 return ret;
1779}
1780
1781#define IPIPE_CONTRAST_HIGH 0xff
1782#define IPIPE_BRIGHT_HIGH 0xff
1783
1784/*
1785 * vpfe_ipipe_init() - ipipe module initialization.
1786 * @ipipe: pointer to ipipe subdevice structure.
1787 * @pdev: platform device pointer.
1788 */
1789int
1790vpfe_ipipe_init(struct vpfe_ipipe_device *ipipe, struct platform_device *pdev)
1791{
1792 struct media_pad *pads = &ipipe->pads[0];
1793 struct v4l2_subdev *sd = &ipipe->subdev;
1794 struct media_entity *me = &sd->entity;
1795 static resource_size_t res_len;
1796 struct resource *res;
1797
1798 res = platform_get_resource(pdev, IORESOURCE_MEM, 4);
1799 if (!res)
1800 return -ENOENT;
1801
1802 res_len = resource_size(res);
1803 res = request_mem_region(res->start, res_len, res->name);
1804 if (!res)
1805 return -EBUSY;
1806 ipipe->base_addr = ioremap_nocache(res->start, res_len);
1807 if (!ipipe->base_addr)
1808 return -EBUSY;
1809
1810 res = platform_get_resource(pdev, IORESOURCE_MEM, 6);
1811 if (!res)
1812 return -ENOENT;
1813 ipipe->isp5_base_addr = ioremap_nocache(res->start, res_len);
1814 if (!ipipe->isp5_base_addr)
1815 return -EBUSY;
1816
1817 v4l2_subdev_init(sd, &ipipe_v4l2_ops);
1818 sd->internal_ops = &ipipe_v4l2_internal_ops;
1819 strlcpy(sd->name, "DAVINCI IPIPE", sizeof(sd->name));
1820 sd->grp_id = 1 << 16; /* group ID for davinci subdevs */
1821 v4l2_set_subdevdata(sd, ipipe);
1822 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
1823
1824 pads[IPIPE_PAD_SINK].flags = MEDIA_PAD_FL_SINK;
1825 pads[IPIPE_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE;
1826
1827 ipipe->input = IPIPE_INPUT_NONE;
1828 ipipe->output = IPIPE_OUTPUT_NONE;
1829
1830 me->ops = &ipipe_media_ops;
1831 v4l2_ctrl_handler_init(&ipipe->ctrls, 2);
1832 v4l2_ctrl_new_std(&ipipe->ctrls, &ipipe_ctrl_ops,
1833 V4L2_CID_BRIGHTNESS, 0,
1834 IPIPE_BRIGHT_HIGH, 1, 16);
1835 v4l2_ctrl_new_std(&ipipe->ctrls, &ipipe_ctrl_ops,
1836 V4L2_CID_CONTRAST, 0,
1837 IPIPE_CONTRAST_HIGH, 1, 16);
1838
1839
1840 v4l2_ctrl_handler_setup(&ipipe->ctrls);
1841 sd->ctrl_handler = &ipipe->ctrls;
1842
1843 return media_entity_init(me, IPIPE_PADS_NUM, pads, 0);
1844}
1845
1846/*
1847 * vpfe_ipipe_cleanup() - ipipe subdevice cleanup.
1848 * @ipipe: pointer to ipipe subdevice
1849 * @dev: pointer to platform device
1850 */
1851void vpfe_ipipe_cleanup(struct vpfe_ipipe_device *ipipe,
1852 struct platform_device *pdev)
1853{
1854 struct resource *res;
1855
1856 v4l2_ctrl_handler_free(&ipipe->ctrls);
1857
1858 iounmap(ipipe->base_addr);
1859 iounmap(ipipe->isp5_base_addr);
1860 res = platform_get_resource(pdev, IORESOURCE_MEM, 4);
1861 if (res)
1862 release_mem_region(res->start, res->end - res->start + 1);
1863}
diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipe.h b/drivers/staging/media/davinci_vpfe/dm365_ipipe.h
new file mode 100644
index 000000000000..cf4204603eb8
--- /dev/null
+++ b/drivers/staging/media/davinci_vpfe/dm365_ipipe.h
@@ -0,0 +1,179 @@
1/*
2 * Copyright (C) 2012 Texas Instruments Inc
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation version 2.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Contributors:
18 * Manjunath Hadli <manjunath.hadli@ti.com>
19 * Prabhakar Lad <prabhakar.lad@ti.com>
20 */
21
22#ifndef _DAVINCI_VPFE_DM365_IPIPE_H
23#define _DAVINCI_VPFE_DM365_IPIPE_H
24
25#include <linux/platform_device.h>
26
27#include <media/v4l2-ctrls.h>
28#include <media/v4l2-subdev.h>
29
30#include "davinci_vpfe_user.h"
31#include "vpfe_video.h"
32
33#define CEIL(a, b) (((a) + (b-1)) / (b))
34
35enum ipipe_noise_filter {
36 IPIPE_D2F_1ST = 0,
37 IPIPE_D2F_2ND = 1,
38};
39
40/* Used for driver storage */
41struct ipipe_otfdpc_2_0 {
42 /* 0 - disable, 1 - enable */
43 unsigned char en;
44 /* defect detection method */
45 enum vpfe_ipipe_otfdpc_det_meth det_method;
46 /* Algorithm used. Applicable only when IPIPE_DPC_OTF_MIN_MAX2 is
47 * used
48 */
49 enum vpfe_ipipe_otfdpc_alg alg;
50 struct vpfe_ipipe_otfdpc_2_0_cfg otfdpc_2_0;
51};
52
53struct ipipe_otfdpc_3_0 {
54 /* 0 - disable, 1 - enable */
55 unsigned char en;
56 /* defect detection method */
57 enum vpfe_ipipe_otfdpc_det_meth det_method;
58 /* Algorithm used. Applicable only when IPIPE_DPC_OTF_MIN_MAX2 is
59 * used
60 */
61 enum vpfe_ipipe_otfdpc_alg alg;
62 struct vpfe_ipipe_otfdpc_3_0_cfg otfdpc_3_0;
63};
64
65/* Structure for configuring Luminance Adjustment module */
66struct ipipe_lum_adj {
67 /* Brightness adjustments */
68 unsigned char brightness;
69 /* contrast adjustments */
70 unsigned char contrast;
71};
72
73enum ipipe_rgb2rgb {
74 IPIPE_RGB2RGB_1 = 0,
75 IPIPE_RGB2RGB_2 = 1,
76};
77
78struct ipipe_module_params {
79 __u32 flag;
80 struct vpfe_ipipe_input_config input_config;
81 struct vpfe_ipipe_lutdpc lutdpc;
82 struct vpfe_ipipe_otfdpc otfdpc;
83 struct vpfe_ipipe_nf nf1;
84 struct vpfe_ipipe_nf nf2;
85 struct vpfe_ipipe_gic gic;
86 struct vpfe_ipipe_wb wbal;
87 struct vpfe_ipipe_cfa cfa;
88 struct vpfe_ipipe_rgb2rgb rgb2rgb1;
89 struct vpfe_ipipe_rgb2rgb rgb2rgb2;
90 struct vpfe_ipipe_gamma gamma;
91 struct vpfe_ipipe_3d_lut lut;
92 struct vpfe_ipipe_rgb2yuv rgb2yuv;
93 struct vpfe_ipipe_gbce gbce;
94 struct vpfe_ipipe_yuv422_conv yuv422_conv;
95 struct vpfe_ipipe_yee yee;
96 struct vpfe_ipipe_car car;
97 struct vpfe_ipipe_cgs cgs;
98 struct ipipe_lum_adj lum_adj;
99};
100
101#define IPIPE_PAD_SINK 0
102#define IPIPE_PAD_SOURCE 1
103
104#define IPIPE_PADS_NUM 2
105
106#define IPIPE_OUTPUT_NONE 0
107#define IPIPE_OUTPUT_RESIZER (1 << 0)
108
109enum ipipe_input_entity {
110 IPIPE_INPUT_NONE = 0,
111 IPIPE_INPUT_MEMORY = 1,
112 IPIPE_INPUT_CCDC = 2,
113};
114
115
116struct vpfe_ipipe_device {
117 struct v4l2_subdev subdev;
118 struct media_pad pads[IPIPE_PADS_NUM];
119 struct v4l2_mbus_framefmt formats[IPIPE_PADS_NUM];
120 enum ipipe_input_entity input;
121 unsigned int output;
122 struct v4l2_ctrl_handler ctrls;
123 void *__iomem base_addr;
124 void *__iomem isp5_base_addr;
125 struct ipipe_module_params config;
126};
127
128struct ipipe_module_if {
129 unsigned int param_offset;
130 unsigned int param_size;
131 unsigned int config_offset;
132 int (*set)(struct vpfe_ipipe_device *ipipe, void *param);
133 int (*get)(struct vpfe_ipipe_device *ipipe, void *param);
134};
135
136/* data paths */
137enum ipipe_data_paths {
138 IPIPE_RAW2YUV,
139 /* Bayer RAW input to YCbCr output */
140 IPIPE_RAW2RAW,
141 /* Bayer Raw to Bayer output */
142 IPIPE_RAW2BOX,
143 /* Bayer Raw to Boxcar output */
144 IPIPE_YUV2YUV
145 /* YUV Raw to YUV Raw output */
146};
147
148#define IPIPE_COLPTN_R_Ye 0x0
149#define IPIPE_COLPTN_Gr_Cy 0x1
150#define IPIPE_COLPTN_Gb_G 0x2
151#define IPIPE_COLPTN_B_Mg 0x3
152
153#define COLPAT_EE_SHIFT 0
154#define COLPAT_EO_SHIFT 2
155#define COLPAT_OE_SHIFT 4
156#define COLPAT_OO_SHIFT 6
157
158#define ipipe_sgrbg_pattern \
159 (IPIPE_COLPTN_Gr_Cy << COLPAT_EE_SHIFT | \
160 IPIPE_COLPTN_R_Ye << COLPAT_EO_SHIFT | \
161 IPIPE_COLPTN_B_Mg << COLPAT_OE_SHIFT | \
162 IPIPE_COLPTN_Gb_G << COLPAT_OO_SHIFT)
163
164#define ipipe_srggb_pattern \
165 (IPIPE_COLPTN_R_Ye << COLPAT_EE_SHIFT | \
166 IPIPE_COLPTN_Gr_Cy << COLPAT_EO_SHIFT | \
167 IPIPE_COLPTN_Gb_G << COLPAT_OE_SHIFT | \
168 IPIPE_COLPTN_B_Mg << COLPAT_OO_SHIFT)
169
170int vpfe_ipipe_register_entities(struct vpfe_ipipe_device *ipipe,
171 struct v4l2_device *v4l2_dev);
172int vpfe_ipipe_init(struct vpfe_ipipe_device *ipipe,
173 struct platform_device *pdev);
174void vpfe_ipipe_unregister_entities(struct vpfe_ipipe_device *ipipe);
175void vpfe_ipipe_cleanup(struct vpfe_ipipe_device *ipipe,
176 struct platform_device *pdev);
177void vpfe_ipipe_enable(struct vpfe_device *vpfe_dev, int en);
178
179#endif /* _DAVINCI_VPFE_DM365_IPIPE_H */
diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipe_hw.c b/drivers/staging/media/davinci_vpfe/dm365_ipipe_hw.c
new file mode 100644
index 000000000000..e027b92b54ef
--- /dev/null
+++ b/drivers/staging/media/davinci_vpfe/dm365_ipipe_hw.c
@@ -0,0 +1,1048 @@
1/*
2 * Copyright (C) 2012 Texas Instruments Inc
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation version 2.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Contributors:
18 * Manjunath Hadli <manjunath.hadli@ti.com>
19 * Prabhakar Lad <prabhakar.lad@ti.com>
20 */
21
22#include "dm365_ipipe_hw.h"
23
24#define IPIPE_MODE_CONTINUOUS 0
25#define IPIPE_MODE_SINGLE_SHOT 1
26
27static void ipipe_clock_enable(void *__iomem base_addr)
28{
29 /* enable IPIPE MMR for register write access */
30 regw_ip(base_addr, IPIPE_GCK_MMR_DEFAULT, IPIPE_GCK_MMR);
31
32 /* enable the clock wb,cfa,dfc,d2f,pre modules */
33 regw_ip(base_addr, IPIPE_GCK_PIX_DEFAULT, IPIPE_GCK_PIX);
34}
35
36static void
37rsz_set_common_params(void *__iomem rsz_base, struct resizer_params *params)
38{
39 struct rsz_common_params *rsz_common = &params->rsz_common;
40 u32 val;
41
42 /* Set mode */
43 regw_rsz(rsz_base, params->oper_mode, RSZ_SRC_MODE);
44
45 /* data source selection and bypass */
46 val = (rsz_common->passthrough << RSZ_BYPASS_SHIFT) |
47 rsz_common->source;
48 regw_rsz(rsz_base, val, RSZ_SRC_FMT0);
49
50 /* src image selection */
51 val = (rsz_common->raw_flip & 1) |
52 (rsz_common->src_img_fmt << RSZ_SRC_IMG_FMT_SHIFT) |
53 ((rsz_common->y_c & 1) << RSZ_SRC_Y_C_SEL_SHIFT);
54 regw_rsz(rsz_base, val, RSZ_SRC_FMT1);
55
56 regw_rsz(rsz_base, rsz_common->vps & IPIPE_RSZ_VPS_MASK, RSZ_SRC_VPS);
57 regw_rsz(rsz_base, rsz_common->hps & IPIPE_RSZ_HPS_MASK, RSZ_SRC_HPS);
58 regw_rsz(rsz_base, rsz_common->vsz & IPIPE_RSZ_VSZ_MASK, RSZ_SRC_VSZ);
59 regw_rsz(rsz_base, rsz_common->hsz & IPIPE_RSZ_HSZ_MASK, RSZ_SRC_HSZ);
60 regw_rsz(rsz_base, rsz_common->yuv_y_min, RSZ_YUV_Y_MIN);
61 regw_rsz(rsz_base, rsz_common->yuv_y_max, RSZ_YUV_Y_MAX);
62 regw_rsz(rsz_base, rsz_common->yuv_c_min, RSZ_YUV_C_MIN);
63 regw_rsz(rsz_base, rsz_common->yuv_c_max, RSZ_YUV_C_MAX);
64 /* chromatic position */
65 regw_rsz(rsz_base, rsz_common->out_chr_pos, RSZ_YUV_PHS);
66}
67
68static void
69rsz_set_rsz_regs(void *__iomem rsz_base, unsigned int rsz_id,
70 struct resizer_params *params)
71{
72 struct resizer_scale_param *rsc_params;
73 struct rsz_ext_mem_param *ext_mem;
74 struct resizer_rgb *rgb;
75 u32 reg_base;
76 u32 val;
77
78 rsc_params = &params->rsz_rsc_param[rsz_id];
79 rgb = &params->rsz2rgb[rsz_id];
80 ext_mem = &params->ext_mem_param[rsz_id];
81
82 if (rsz_id == RSZ_A) {
83 val = rsc_params->h_flip << RSZA_H_FLIP_SHIFT;
84 val |= rsc_params->v_flip << RSZA_V_FLIP_SHIFT;
85 reg_base = RSZ_EN_A;
86 } else {
87 val = rsc_params->h_flip << RSZB_H_FLIP_SHIFT;
88 val |= rsc_params->v_flip << RSZB_V_FLIP_SHIFT;
89 reg_base = RSZ_EN_B;
90 }
91 /* update flip settings */
92 regw_rsz(rsz_base, val, RSZ_SEQ);
93
94 regw_rsz(rsz_base, params->oper_mode, reg_base + RSZ_MODE);
95
96 val = (rsc_params->cen << RSZ_CEN_SHIFT) | rsc_params->yen;
97 regw_rsz(rsz_base, val, reg_base + RSZ_420);
98
99 regw_rsz(rsz_base, rsc_params->i_vps & RSZ_VPS_MASK,
100 reg_base + RSZ_I_VPS);
101 regw_rsz(rsz_base, rsc_params->i_hps & RSZ_HPS_MASK,
102 reg_base + RSZ_I_HPS);
103 regw_rsz(rsz_base, rsc_params->o_vsz & RSZ_O_VSZ_MASK,
104 reg_base + RSZ_O_VSZ);
105 regw_rsz(rsz_base, rsc_params->o_hsz & RSZ_O_HSZ_MASK,
106 reg_base + RSZ_O_HSZ);
107 regw_rsz(rsz_base, rsc_params->v_phs_y & RSZ_V_PHS_MASK,
108 reg_base + RSZ_V_PHS_Y);
109 regw_rsz(rsz_base, rsc_params->v_phs_c & RSZ_V_PHS_MASK,
110 reg_base + RSZ_V_PHS_C);
111
112 /* keep this additional adjustment to zero for now */
113 regw_rsz(rsz_base, rsc_params->v_dif & RSZ_V_DIF_MASK,
114 reg_base + RSZ_V_DIF);
115
116 val = (rsc_params->v_typ_y & 1) |
117 ((rsc_params->v_typ_c & 1) << RSZ_TYP_C_SHIFT);
118 regw_rsz(rsz_base, val, reg_base + RSZ_V_TYP);
119
120 val = (rsc_params->v_lpf_int_y & RSZ_LPF_INT_MASK) |
121 ((rsc_params->v_lpf_int_c & RSZ_LPF_INT_MASK) <<
122 RSZ_LPF_INT_C_SHIFT);
123 regw_rsz(rsz_base, val, reg_base + RSZ_V_LPF);
124
125 regw_rsz(rsz_base, rsc_params->h_phs &
126 RSZ_H_PHS_MASK, reg_base + RSZ_H_PHS);
127
128 regw_rsz(rsz_base, 0, reg_base + RSZ_H_PHS_ADJ);
129 regw_rsz(rsz_base, rsc_params->h_dif &
130 RSZ_H_DIF_MASK, reg_base + RSZ_H_DIF);
131
132 val = (rsc_params->h_typ_y & 1) |
133 ((rsc_params->h_typ_c & 1) << RSZ_TYP_C_SHIFT);
134 regw_rsz(rsz_base, val, reg_base + RSZ_H_TYP);
135
136 val = (rsc_params->h_lpf_int_y & RSZ_LPF_INT_MASK) |
137 ((rsc_params->h_lpf_int_c & RSZ_LPF_INT_MASK) <<
138 RSZ_LPF_INT_C_SHIFT);
139 regw_rsz(rsz_base, val, reg_base + RSZ_H_LPF);
140
141 regw_rsz(rsz_base, rsc_params->dscale_en & 1, reg_base + RSZ_DWN_EN);
142
143 val = (rsc_params->h_dscale_ave_sz & RSZ_DWN_SCALE_AV_SZ_MASK) |
144 ((rsc_params->v_dscale_ave_sz & RSZ_DWN_SCALE_AV_SZ_MASK) <<
145 RSZ_DWN_SCALE_AV_SZ_V_SHIFT);
146 regw_rsz(rsz_base, val, reg_base + RSZ_DWN_AV);
147
148 /* setting rgb conversion parameters */
149 regw_rsz(rsz_base, rgb->rgb_en, reg_base + RSZ_RGB_EN);
150
151 val = (rgb->rgb_typ << RSZ_RGB_TYP_SHIFT) |
152 (rgb->rgb_msk0 << RSZ_RGB_MSK0_SHIFT) |
153 (rgb->rgb_msk1 << RSZ_RGB_MSK1_SHIFT);
154 regw_rsz(rsz_base, val, reg_base + RSZ_RGB_TYP);
155
156 regw_rsz(rsz_base, rgb->rgb_alpha_val & RSZ_RGB_ALPHA_MASK,
157 reg_base + RSZ_RGB_BLD);
158
159 /* setting external memory parameters */
160 regw_rsz(rsz_base, ext_mem->rsz_sdr_oft_y, reg_base + RSZ_SDR_Y_OFT);
161 regw_rsz(rsz_base, ext_mem->rsz_sdr_ptr_s_y,
162 reg_base + RSZ_SDR_Y_PTR_S);
163 regw_rsz(rsz_base, ext_mem->rsz_sdr_ptr_e_y,
164 reg_base + RSZ_SDR_Y_PTR_E);
165 regw_rsz(rsz_base, ext_mem->rsz_sdr_oft_c, reg_base + RSZ_SDR_C_OFT);
166 regw_rsz(rsz_base, ext_mem->rsz_sdr_ptr_s_c,
167 reg_base + RSZ_SDR_C_PTR_S);
168 regw_rsz(rsz_base, (ext_mem->rsz_sdr_ptr_e_c >> 1),
169 reg_base + RSZ_SDR_C_PTR_E);
170}
171
172/*set the registers of either RSZ0 or RSZ1 */
173static void
174ipipe_setup_resizer(void *__iomem rsz_base, struct resizer_params *params)
175{
176 /* enable MMR gate to write to Resizer */
177 regw_rsz(rsz_base, 1, RSZ_GCK_MMR);
178
179 /* Enable resizer if it is not in bypass mode */
180 if (params->rsz_common.passthrough)
181 regw_rsz(rsz_base, 0, RSZ_GCK_SDR);
182 else
183 regw_rsz(rsz_base, 1, RSZ_GCK_SDR);
184
185 rsz_set_common_params(rsz_base, params);
186
187 regw_rsz(rsz_base, params->rsz_en[RSZ_A], RSZ_EN_A);
188
189 if (params->rsz_en[RSZ_A])
190 /*setting rescale parameters */
191 rsz_set_rsz_regs(rsz_base, RSZ_A, params);
192
193 regw_rsz(rsz_base, params->rsz_en[RSZ_B], RSZ_EN_B);
194
195 if (params->rsz_en[RSZ_B])
196 rsz_set_rsz_regs(rsz_base, RSZ_B, params);
197}
198
199static u32 ipipe_get_color_pat(enum v4l2_mbus_pixelcode pix)
200{
201 switch (pix) {
202 case V4L2_MBUS_FMT_SGRBG10_ALAW8_1X8:
203 case V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8:
204 case V4L2_MBUS_FMT_SGRBG12_1X12:
205 return ipipe_sgrbg_pattern;
206
207 default:
208 return ipipe_srggb_pattern;
209 }
210}
211
212static int ipipe_get_data_path(struct vpfe_ipipe_device *ipipe)
213{
214 enum v4l2_mbus_pixelcode temp_pix_fmt;
215
216 switch (ipipe->formats[IPIPE_PAD_SINK].code) {
217 case V4L2_MBUS_FMT_SBGGR8_1X8:
218 case V4L2_MBUS_FMT_SGRBG10_ALAW8_1X8:
219 case V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8:
220 case V4L2_MBUS_FMT_SGRBG12_1X12:
221 temp_pix_fmt = V4L2_MBUS_FMT_SGRBG12_1X12;
222 break;
223
224 default:
225 temp_pix_fmt = V4L2_MBUS_FMT_UYVY8_2X8;
226 }
227
228 if (temp_pix_fmt == V4L2_MBUS_FMT_SGRBG12_1X12) {
229 if (ipipe->formats[IPIPE_PAD_SOURCE].code ==
230 V4L2_MBUS_FMT_SGRBG12_1X12)
231 return IPIPE_RAW2RAW;
232 return IPIPE_RAW2YUV;
233 }
234
235 return IPIPE_YUV2YUV;
236}
237
238static int get_ipipe_mode(struct vpfe_ipipe_device *ipipe)
239{
240 struct vpfe_device *vpfe_dev = to_vpfe_device(ipipe);
241 u16 ipipeif_sink = vpfe_dev->vpfe_ipipeif.input;
242
243 if (ipipeif_sink == IPIPEIF_INPUT_MEMORY)
244 return IPIPE_MODE_SINGLE_SHOT;
245 else if (ipipeif_sink == IPIPEIF_INPUT_ISIF)
246 return IPIPE_MODE_CONTINUOUS;
247
248 return -EINVAL;
249}
250
251int config_ipipe_hw(struct vpfe_ipipe_device *ipipe)
252{
253 struct vpfe_ipipe_input_config *config = &ipipe->config.input_config;
254 void __iomem *ipipe_base = ipipe->base_addr;
255 struct v4l2_mbus_framefmt *outformat;
256 u32 color_pat;
257 u32 ipipe_mode;
258 u32 data_path;
259
260 /* enable clock to IPIPE */
261 vpss_enable_clock(VPSS_IPIPE_CLOCK, 1);
262 ipipe_clock_enable(ipipe_base);
263
264 if (ipipe->input == IPIPE_INPUT_NONE) {
265 regw_ip(ipipe_base, 0, IPIPE_SRC_EN);
266 return 0;
267 }
268
269 ipipe_mode = get_ipipe_mode(ipipe);
270 if (ipipe < 0) {
271 pr_err("Failed to get ipipe mode");
272 return -EINVAL;
273 }
274 regw_ip(ipipe_base, ipipe_mode, IPIPE_SRC_MODE);
275
276 data_path = ipipe_get_data_path(ipipe);
277 regw_ip(ipipe_base, data_path, IPIPE_SRC_FMT);
278
279 regw_ip(ipipe_base, config->vst & IPIPE_RSZ_VPS_MASK, IPIPE_SRC_VPS);
280 regw_ip(ipipe_base, config->hst & IPIPE_RSZ_HPS_MASK, IPIPE_SRC_HPS);
281
282 outformat = &ipipe->formats[IPIPE_PAD_SOURCE];
283 regw_ip(ipipe_base, (outformat->height + 1) & IPIPE_RSZ_VSZ_MASK,
284 IPIPE_SRC_VSZ);
285 regw_ip(ipipe_base, (outformat->width + 1) & IPIPE_RSZ_HSZ_MASK,
286 IPIPE_SRC_HSZ);
287
288 if (data_path == IPIPE_RAW2YUV ||
289 data_path == IPIPE_RAW2RAW) {
290 color_pat =
291 ipipe_get_color_pat(ipipe->formats[IPIPE_PAD_SINK].code);
292 regw_ip(ipipe_base, color_pat, IPIPE_SRC_COL);
293 }
294
295 return 0;
296}
297
298/*
299 * config_rsz_hw() - Performs hardware setup of resizer.
300 */
301int config_rsz_hw(struct vpfe_resizer_device *resizer,
302 struct resizer_params *config)
303{
304 struct vpfe_device *vpfe_dev = to_vpfe_device(resizer);
305 void *__iomem ipipe_base = vpfe_dev->vpfe_ipipe.base_addr;
306 void *__iomem rsz_base = vpfe_dev->vpfe_resizer.base_addr;
307
308 /* enable VPSS clock */
309 vpss_enable_clock(VPSS_IPIPE_CLOCK, 1);
310 ipipe_clock_enable(ipipe_base);
311
312 ipipe_setup_resizer(rsz_base, config);
313
314 return 0;
315}
316
317static void
318rsz_set_y_address(void *__iomem rsz_base, unsigned int address,
319 unsigned int offset)
320{
321 u32 val;
322
323 val = address & SET_LOW_ADDR;
324 regw_rsz(rsz_base, val, offset + RSZ_SDR_Y_BAD_L);
325 regw_rsz(rsz_base, val, offset + RSZ_SDR_Y_SAD_L);
326
327 val = (address & SET_HIGH_ADDR) >> 16;
328 regw_rsz(rsz_base, val, offset + RSZ_SDR_Y_BAD_H);
329 regw_rsz(rsz_base, val, offset + RSZ_SDR_Y_SAD_H);
330}
331
332static void
333rsz_set_c_address(void *__iomem rsz_base, unsigned int address,
334 unsigned int offset)
335{
336 u32 val;
337
338 val = address & SET_LOW_ADDR;
339 regw_rsz(rsz_base, val, offset + RSZ_SDR_C_BAD_L);
340 regw_rsz(rsz_base, val, offset + RSZ_SDR_C_SAD_L);
341
342 val = (address & SET_HIGH_ADDR) >> 16;
343 regw_rsz(rsz_base, val, offset + RSZ_SDR_C_BAD_H);
344 regw_rsz(rsz_base, val, offset + RSZ_SDR_C_SAD_H);
345}
346
347/*
348 * resizer_set_outaddr() - set the address for given resize_no
349 * @rsz_base: resizer base address
350 * @params: pointer to ipipe_params structure
351 * @resize_no: 0 - Resizer-A, 1 - Resizer B
352 * @address: the address to set
353 */
354int
355resizer_set_outaddr(void *__iomem rsz_base, struct resizer_params *params,
356 int resize_no, unsigned int address)
357{
358 struct resizer_scale_param *rsc_param;
359 struct rsz_ext_mem_param *mem_param;
360 struct rsz_common_params *rsz_common;
361 unsigned int rsz_start_add;
362 unsigned int val;
363
364 if (resize_no != RSZ_A && resize_no != RSZ_B)
365 return -EINVAL;
366
367 mem_param = &params->ext_mem_param[resize_no];
368 rsc_param = &params->rsz_rsc_param[resize_no];
369 rsz_common = &params->rsz_common;
370
371 if (resize_no == RSZ_A)
372 rsz_start_add = RSZ_EN_A;
373 else
374 rsz_start_add = RSZ_EN_B;
375
376 /* y_c = 0 for y, = 1 for c */
377 if (rsz_common->src_img_fmt == RSZ_IMG_420) {
378 if (rsz_common->y_c) {
379 /* C channel */
380 val = address + mem_param->flip_ofst_c;
381 rsz_set_c_address(rsz_base, val, rsz_start_add);
382 } else {
383 val = address + mem_param->flip_ofst_y;
384 rsz_set_y_address(rsz_base, val, rsz_start_add);
385 }
386 } else {
387 if (rsc_param->cen && rsc_param->yen) {
388 /* 420 */
389 val = address + mem_param->c_offset +
390 mem_param->flip_ofst_c +
391 mem_param->user_y_ofst +
392 mem_param->user_c_ofst;
393 if (resize_no == RSZ_B)
394 val +=
395 params->ext_mem_param[RSZ_A].user_y_ofst +
396 params->ext_mem_param[RSZ_A].user_c_ofst;
397 /* set C address */
398 rsz_set_c_address(rsz_base, val, rsz_start_add);
399 }
400 val = address + mem_param->flip_ofst_y + mem_param->user_y_ofst;
401 if (resize_no == RSZ_B)
402 val += params->ext_mem_param[RSZ_A].user_y_ofst +
403 params->ext_mem_param[RSZ_A].user_c_ofst;
404 /* set Y address */
405 rsz_set_y_address(rsz_base, val, rsz_start_add);
406 }
407 /* resizer must be enabled */
408 regw_rsz(rsz_base, params->rsz_en[resize_no], rsz_start_add);
409
410 return 0;
411}
412
413void
414ipipe_set_lutdpc_regs(void *__iomem base_addr, void *__iomem isp5_base_addr,
415 struct vpfe_ipipe_lutdpc *dpc)
416{
417 u32 max_tbl_size = LUT_DPC_MAX_SIZE >> 1;
418 u32 lut_start_addr = DPC_TB0_START_ADDR;
419 u32 val;
420 u32 count;
421
422 ipipe_clock_enable(base_addr);
423 regw_ip(base_addr, dpc->en, DPC_LUT_EN);
424
425 if (dpc->en != 1)
426 return;
427
428 val = LUTDPC_TBL_256_EN | (dpc->repl_white & 1);
429 regw_ip(base_addr, val, DPC_LUT_SEL);
430 regw_ip(base_addr, LUT_DPC_START_ADDR, DPC_LUT_ADR);
431 regw_ip(base_addr, dpc->dpc_size, DPC_LUT_SIZ & LUT_DPC_SIZE_MASK);
432
433 if (dpc->table == NULL)
434 return;
435
436 for (count = 0; count < dpc->dpc_size; count++) {
437 if (count >= max_tbl_size)
438 lut_start_addr = DPC_TB1_START_ADDR;
439 val = (dpc->table[count].horz_pos & LUT_DPC_H_POS_MASK) |
440 ((dpc->table[count].vert_pos & LUT_DPC_V_POS_MASK) <<
441 LUT_DPC_V_POS_SHIFT) | (dpc->table[count].method <<
442 LUT_DPC_CORR_METH_SHIFT);
443 w_ip_table(isp5_base_addr, val, (lut_start_addr +
444 ((count % max_tbl_size) << 2)));
445 }
446}
447
448static void
449set_dpc_thresholds(void *__iomem base_addr,
450 struct vpfe_ipipe_otfdpc_2_0_cfg *dpc_thr)
451{
452 regw_ip(base_addr, dpc_thr->corr_thr.r & OTFDPC_DPC2_THR_MASK,
453 DPC_OTF_2C_THR_R);
454 regw_ip(base_addr, dpc_thr->corr_thr.gr & OTFDPC_DPC2_THR_MASK,
455 DPC_OTF_2C_THR_GR);
456 regw_ip(base_addr, dpc_thr->corr_thr.gb & OTFDPC_DPC2_THR_MASK,
457 DPC_OTF_2C_THR_GB);
458 regw_ip(base_addr, dpc_thr->corr_thr.b & OTFDPC_DPC2_THR_MASK,
459 DPC_OTF_2C_THR_B);
460 regw_ip(base_addr, dpc_thr->det_thr.r & OTFDPC_DPC2_THR_MASK,
461 DPC_OTF_2D_THR_R);
462 regw_ip(base_addr, dpc_thr->det_thr.gr & OTFDPC_DPC2_THR_MASK,
463 DPC_OTF_2D_THR_GR);
464 regw_ip(base_addr, dpc_thr->det_thr.gb & OTFDPC_DPC2_THR_MASK,
465 DPC_OTF_2D_THR_GB);
466 regw_ip(base_addr, dpc_thr->det_thr.b & OTFDPC_DPC2_THR_MASK,
467 DPC_OTF_2D_THR_B);
468}
469
470void ipipe_set_otfdpc_regs(void *__iomem base_addr,
471 struct vpfe_ipipe_otfdpc *otfdpc)
472{
473 struct vpfe_ipipe_otfdpc_2_0_cfg *dpc_2_0 = &otfdpc->alg_cfg.dpc_2_0;
474 struct vpfe_ipipe_otfdpc_3_0_cfg *dpc_3_0 = &otfdpc->alg_cfg.dpc_3_0;
475 u32 val;
476
477 ipipe_clock_enable(base_addr);
478
479 regw_ip(base_addr, (otfdpc->en & 1), DPC_OTF_EN);
480 if (!otfdpc->en)
481 return;
482
483 /* dpc enabled */
484 val = (otfdpc->det_method << OTF_DET_METHOD_SHIFT) | otfdpc->alg;
485 regw_ip(base_addr, val, DPC_OTF_TYP);
486
487 if (otfdpc->det_method == VPFE_IPIPE_DPC_OTF_MIN_MAX) {
488 /* ALG= 0, TYP = 0, DPC_OTF_2D_THR_[x]=0
489 * DPC_OTF_2C_THR_[x] = Maximum thresohld
490 * MinMax method
491 */
492 dpc_2_0->det_thr.r = dpc_2_0->det_thr.gb =
493 dpc_2_0->det_thr.gr = dpc_2_0->det_thr.b = 0;
494 set_dpc_thresholds(base_addr, dpc_2_0);
495 return;
496 }
497 /* MinMax2 */
498 if (otfdpc->alg == VPFE_IPIPE_OTFDPC_2_0) {
499 set_dpc_thresholds(base_addr, dpc_2_0);
500 return;
501 }
502 regw_ip(base_addr, dpc_3_0->act_adj_shf &
503 OTF_DPC3_0_SHF_MASK, DPC_OTF_3_SHF);
504 /* Detection thresholds */
505 regw_ip(base_addr, ((dpc_3_0->det_thr & OTF_DPC3_0_THR_MASK) <<
506 OTF_DPC3_0_THR_SHIFT), DPC_OTF_3D_THR);
507 regw_ip(base_addr, dpc_3_0->det_slp &
508 OTF_DPC3_0_SLP_MASK, DPC_OTF_3D_SLP);
509 regw_ip(base_addr, dpc_3_0->det_thr_min &
510 OTF_DPC3_0_DET_MASK, DPC_OTF_3D_MIN);
511 regw_ip(base_addr, dpc_3_0->det_thr_max &
512 OTF_DPC3_0_DET_MASK, DPC_OTF_3D_MAX);
513 /* Correction thresholds */
514 regw_ip(base_addr, ((dpc_3_0->corr_thr & OTF_DPC3_0_THR_MASK) <<
515 OTF_DPC3_0_THR_SHIFT), DPC_OTF_3C_THR);
516 regw_ip(base_addr, dpc_3_0->corr_slp &
517 OTF_DPC3_0_SLP_MASK, DPC_OTF_3C_SLP);
518 regw_ip(base_addr, dpc_3_0->corr_thr_min &
519 OTF_DPC3_0_CORR_MASK, DPC_OTF_3C_MIN);
520 regw_ip(base_addr, dpc_3_0->corr_thr_max &
521 OTF_DPC3_0_CORR_MASK, DPC_OTF_3C_MAX);
522}
523
524/* 2D Noise filter */
525void
526ipipe_set_d2f_regs(void *__iomem base_addr, unsigned int id,
527 struct vpfe_ipipe_nf *noise_filter)
528{
529
530 u32 offset = D2F_1ST;
531 int count;
532 u32 val;
533
534 if (id == IPIPE_D2F_2ND)
535 offset = D2F_2ND;
536
537 ipipe_clock_enable(base_addr);
538 regw_ip(base_addr, noise_filter->en & 1, offset + D2F_EN);
539 if (!noise_filter->en)
540 return;
541
542 /*noise filter enabled */
543 /* Combine all the fields to make D2F_CFG register of IPIPE */
544 val = ((noise_filter->spread_val & D2F_SPR_VAL_MASK) <<
545 D2F_SPR_VAL_SHIFT) | ((noise_filter->shft_val &
546 D2F_SHFT_VAL_MASK) << D2F_SHFT_VAL_SHIFT) |
547 (noise_filter->gr_sample_meth << D2F_SAMPLE_METH_SHIFT) |
548 ((noise_filter->apply_lsc_gain & 1) <<
549 D2F_APPLY_LSC_GAIN_SHIFT) | D2F_USE_SPR_REG_VAL;
550 regw_ip(base_addr, val, offset + D2F_TYP);
551
552 /* edge detection minimum */
553 regw_ip(base_addr, noise_filter->edge_det_min_thr &
554 D2F_EDGE_DET_THR_MASK, offset + D2F_EDG_MIN);
555
556 /* edge detection maximum */
557 regw_ip(base_addr, noise_filter->edge_det_max_thr &
558 D2F_EDGE_DET_THR_MASK, offset + D2F_EDG_MAX);
559
560 for (count = 0; count < VPFE_IPIPE_NF_STR_TABLE_SIZE; count++)
561 regw_ip(base_addr,
562 (noise_filter->str[count] & D2F_STR_VAL_MASK),
563 offset + D2F_STR + count * 4);
564
565 for (count = 0; count < VPFE_IPIPE_NF_THR_TABLE_SIZE; count++)
566 regw_ip(base_addr, noise_filter->thr[count] & D2F_THR_VAL_MASK,
567 offset + D2F_THR + count * 4);
568}
569
570#define IPIPE_U8Q5(decimal, integer) \
571 (((decimal & 0x1f) | ((integer & 0x7) << 5)))
572
573/* Green Imbalance Correction */
574void ipipe_set_gic_regs(void *__iomem base_addr, struct vpfe_ipipe_gic *gic)
575{
576 u32 val;
577
578 ipipe_clock_enable(base_addr);
579 regw_ip(base_addr, gic->en & 1, GIC_EN);
580
581 if (!gic->en)
582 return;
583
584 /*gic enabled */
585 val = (gic->wt_fn_type << GIC_TYP_SHIFT) |
586 (gic->thr_sel << GIC_THR_SEL_SHIFT) |
587 ((gic->apply_lsc_gain & 1) << GIC_APPLY_LSC_GAIN_SHIFT);
588 regw_ip(base_addr, val, GIC_TYP);
589
590 regw_ip(base_addr, gic->gain & GIC_GAIN_MASK, GIC_GAN);
591
592 if (gic->gic_alg != VPFE_IPIPE_GIC_ALG_ADAPT_GAIN) {
593 /* Constant Gain. Set threshold to maximum */
594 regw_ip(base_addr, GIC_THR_MASK, GIC_THR);
595 return;
596 }
597
598 if (gic->thr_sel == VPFE_IPIPE_GIC_THR_REG) {
599 regw_ip(base_addr, gic->thr & GIC_THR_MASK, GIC_THR);
600 regw_ip(base_addr, gic->slope & GIC_SLOPE_MASK, GIC_SLP);
601 } else {
602 /* Use NF thresholds */
603 val = IPIPE_U8Q5(gic->nf2_thr_gain.decimal,
604 gic->nf2_thr_gain.integer);
605 regw_ip(base_addr, val, GIC_NFGAN);
606 }
607}
608
609#define IPIPE_U13Q9(decimal, integer) \
610 (((decimal & 0x1ff) | ((integer & 0xf) << 9)))
611/* White balance */
612void ipipe_set_wb_regs(void *__iomem base_addr, struct vpfe_ipipe_wb *wb)
613{
614 u32 val;
615
616 ipipe_clock_enable(base_addr);
617 /* Ofsets. S12 */
618 regw_ip(base_addr, wb->ofst_r & WB_OFFSET_MASK, WB2_OFT_R);
619 regw_ip(base_addr, wb->ofst_gr & WB_OFFSET_MASK, WB2_OFT_GR);
620 regw_ip(base_addr, wb->ofst_gb & WB_OFFSET_MASK, WB2_OFT_GB);
621 regw_ip(base_addr, wb->ofst_b & WB_OFFSET_MASK, WB2_OFT_B);
622
623 /* Gains. U13Q9 */
624 val = IPIPE_U13Q9(wb->gain_r.decimal, wb->gain_r.integer);
625 regw_ip(base_addr, val, WB2_WGN_R);
626
627 val = IPIPE_U13Q9(wb->gain_gr.decimal, wb->gain_gr.integer);
628 regw_ip(base_addr, val, WB2_WGN_GR);
629
630 val = IPIPE_U13Q9(wb->gain_gb.decimal, wb->gain_gb.integer);
631 regw_ip(base_addr, val, WB2_WGN_GB);
632
633 val = IPIPE_U13Q9(wb->gain_b.decimal, wb->gain_b.integer);
634 regw_ip(base_addr, val, WB2_WGN_B);
635}
636
637/* CFA */
638void ipipe_set_cfa_regs(void *__iomem base_addr, struct vpfe_ipipe_cfa *cfa)
639{
640 ipipe_clock_enable(base_addr);
641
642 regw_ip(base_addr, cfa->alg, CFA_MODE);
643 regw_ip(base_addr, cfa->hpf_thr_2dir & CFA_HPF_THR_2DIR_MASK,
644 CFA_2DIR_HPF_THR);
645 regw_ip(base_addr, cfa->hpf_slp_2dir & CFA_HPF_SLOPE_2DIR_MASK,
646 CFA_2DIR_HPF_SLP);
647 regw_ip(base_addr, cfa->hp_mix_thr_2dir & CFA_HPF_MIX_THR_2DIR_MASK,
648 CFA_2DIR_MIX_THR);
649 regw_ip(base_addr, cfa->hp_mix_slope_2dir & CFA_HPF_MIX_SLP_2DIR_MASK,
650 CFA_2DIR_MIX_SLP);
651 regw_ip(base_addr, cfa->dir_thr_2dir & CFA_DIR_THR_2DIR_MASK,
652 CFA_2DIR_DIR_THR);
653 regw_ip(base_addr, cfa->dir_slope_2dir & CFA_DIR_SLP_2DIR_MASK,
654 CFA_2DIR_DIR_SLP);
655 regw_ip(base_addr, cfa->nd_wt_2dir & CFA_ND_WT_2DIR_MASK,
656 CFA_2DIR_NDWT);
657 regw_ip(base_addr, cfa->hue_fract_daa & CFA_DAA_HUE_FRA_MASK,
658 CFA_MONO_HUE_FRA);
659 regw_ip(base_addr, cfa->edge_thr_daa & CFA_DAA_EDG_THR_MASK,
660 CFA_MONO_EDG_THR);
661 regw_ip(base_addr, cfa->thr_min_daa & CFA_DAA_THR_MIN_MASK,
662 CFA_MONO_THR_MIN);
663 regw_ip(base_addr, cfa->thr_slope_daa & CFA_DAA_THR_SLP_MASK,
664 CFA_MONO_THR_SLP);
665 regw_ip(base_addr, cfa->slope_min_daa & CFA_DAA_SLP_MIN_MASK,
666 CFA_MONO_SLP_MIN);
667 regw_ip(base_addr, cfa->slope_slope_daa & CFA_DAA_SLP_SLP_MASK,
668 CFA_MONO_SLP_SLP);
669 regw_ip(base_addr, cfa->lp_wt_daa & CFA_DAA_LP_WT_MASK,
670 CFA_MONO_LPWT);
671}
672
673void
674ipipe_set_rgb2rgb_regs(void *__iomem base_addr, unsigned int id,
675 struct vpfe_ipipe_rgb2rgb *rgb)
676{
677 u32 offset_mask = RGB2RGB_1_OFST_MASK;
678 u32 offset = RGB1_MUL_BASE;
679 u32 integ_mask = 0xf;
680 u32 val;
681
682 ipipe_clock_enable(base_addr);
683
684 if (id == IPIPE_RGB2RGB_2) {
685 /* For second RGB module, gain integer is 3 bits instead
686 of 4, offset has 11 bits insread of 13 */
687 offset = RGB2_MUL_BASE;
688 integ_mask = 0x7;
689 offset_mask = RGB2RGB_2_OFST_MASK;
690 }
691 /* Gains */
692 val = (rgb->coef_rr.decimal & 0xff) |
693 ((rgb->coef_rr.integer & integ_mask) << 8);
694 regw_ip(base_addr, val, offset + RGB_MUL_RR);
695 val = (rgb->coef_gr.decimal & 0xff) |
696 ((rgb->coef_gr.integer & integ_mask) << 8);
697 regw_ip(base_addr, val, offset + RGB_MUL_GR);
698 val = (rgb->coef_br.decimal & 0xff) |
699 ((rgb->coef_br.integer & integ_mask) << 8);
700 regw_ip(base_addr, val, offset + RGB_MUL_BR);
701 val = (rgb->coef_rg.decimal & 0xff) |
702 ((rgb->coef_rg.integer & integ_mask) << 8);
703 regw_ip(base_addr, val, offset + RGB_MUL_RG);
704 val = (rgb->coef_gg.decimal & 0xff) |
705 ((rgb->coef_gg.integer & integ_mask) << 8);
706 regw_ip(base_addr, val, offset + RGB_MUL_GG);
707 val = (rgb->coef_bg.decimal & 0xff) |
708 ((rgb->coef_bg.integer & integ_mask) << 8);
709 regw_ip(base_addr, val, offset + RGB_MUL_BG);
710 val = (rgb->coef_rb.decimal & 0xff) |
711 ((rgb->coef_rb.integer & integ_mask) << 8);
712 regw_ip(base_addr, val, offset + RGB_MUL_RB);
713 val = (rgb->coef_gb.decimal & 0xff) |
714 ((rgb->coef_gb.integer & integ_mask) << 8);
715 regw_ip(base_addr, val, offset + RGB_MUL_GB);
716 val = (rgb->coef_bb.decimal & 0xff) |
717 ((rgb->coef_bb.integer & integ_mask) << 8);
718 regw_ip(base_addr, val, offset + RGB_MUL_BB);
719
720 /* Offsets */
721 regw_ip(base_addr, rgb->out_ofst_r & offset_mask, offset + RGB_OFT_OR);
722 regw_ip(base_addr, rgb->out_ofst_g & offset_mask, offset + RGB_OFT_OG);
723 regw_ip(base_addr, rgb->out_ofst_b & offset_mask, offset + RGB_OFT_OB);
724}
725
726static void
727ipipe_update_gamma_tbl(void *__iomem isp5_base_addr,
728 struct vpfe_ipipe_gamma_entry *table, int size, u32 addr)
729{
730 int count;
731 u32 val;
732
733 for (count = 0; count < size; count++) {
734 val = table[count].slope & GAMMA_MASK;
735 val |= (table[count].offset & GAMMA_MASK) << GAMMA_SHIFT;
736 w_ip_table(isp5_base_addr, val, (addr + (count * 4)));
737 }
738}
739
740void
741ipipe_set_gamma_regs(void *__iomem base_addr, void *__iomem isp5_base_addr,
742 struct vpfe_ipipe_gamma *gamma)
743{
744 int table_size;
745 u32 val;
746
747 ipipe_clock_enable(base_addr);
748 val = (gamma->bypass_r << GAMMA_BYPR_SHIFT) |
749 (gamma->bypass_b << GAMMA_BYPG_SHIFT) |
750 (gamma->bypass_g << GAMMA_BYPB_SHIFT) |
751 (gamma->tbl_sel << GAMMA_TBL_SEL_SHIFT) |
752 (gamma->tbl_size << GAMMA_TBL_SIZE_SHIFT);
753
754 regw_ip(base_addr, val, GMM_CFG);
755
756 if (gamma->tbl_sel != VPFE_IPIPE_GAMMA_TBL_RAM)
757 return;
758
759 table_size = gamma->tbl_size;
760
761 if (!gamma->bypass_r && gamma->table_r != NULL)
762 ipipe_update_gamma_tbl(isp5_base_addr, gamma->table_r,
763 table_size, GAMMA_R_START_ADDR);
764 if (!gamma->bypass_b && gamma->table_b != NULL)
765 ipipe_update_gamma_tbl(isp5_base_addr, gamma->table_b,
766 table_size, GAMMA_B_START_ADDR);
767 if (!gamma->bypass_g && gamma->table_g != NULL)
768 ipipe_update_gamma_tbl(isp5_base_addr, gamma->table_g,
769 table_size, GAMMA_G_START_ADDR);
770}
771
772void
773ipipe_set_3d_lut_regs(void *__iomem base_addr, void *__iomem isp5_base_addr,
774 struct vpfe_ipipe_3d_lut *lut_3d)
775{
776 struct vpfe_ipipe_3d_lut_entry *tbl;
777 u32 bnk_index;
778 u32 tbl_index;
779 u32 val;
780 u32 i;
781
782 ipipe_clock_enable(base_addr);
783 regw_ip(base_addr, lut_3d->en, D3LUT_EN);
784
785 if (!lut_3d->en)
786 return;
787
788 /* lut_3d enabled */
789 if (!lut_3d->table)
790 return;
791
792 /* valied table */
793 tbl = lut_3d->table;
794 for (i = 0 ; i < VPFE_IPIPE_MAX_SIZE_3D_LUT; i++) {
795 /* Each entry has 0-9 (B), 10-19 (G) and
796 20-29 R values */
797 val = tbl[i].b & D3_LUT_ENTRY_MASK;
798 val |= (tbl[i].g & D3_LUT_ENTRY_MASK) <<
799 D3_LUT_ENTRY_G_SHIFT;
800 val |= (tbl[i].r & D3_LUT_ENTRY_MASK) <<
801 D3_LUT_ENTRY_R_SHIFT;
802 bnk_index = i % 4;
803 tbl_index = i >> 2;
804 tbl_index <<= 2;
805 if (bnk_index == 0)
806 w_ip_table(isp5_base_addr, val,
807 tbl_index + D3L_TB0_START_ADDR);
808 else if (bnk_index == 1)
809 w_ip_table(isp5_base_addr, val,
810 tbl_index + D3L_TB1_START_ADDR);
811 else if (bnk_index == 2)
812 w_ip_table(isp5_base_addr, val,
813 tbl_index + D3L_TB2_START_ADDR);
814 else
815 w_ip_table(isp5_base_addr, val,
816 tbl_index + D3L_TB3_START_ADDR);
817 }
818}
819
820/* Lumina adjustments */
821void
822ipipe_set_lum_adj_regs(void *__iomem base_addr, struct ipipe_lum_adj *lum_adj)
823{
824 u32 val;
825
826 ipipe_clock_enable(base_addr);
827
828 /* combine fields of YUV_ADJ to set brightness and contrast */
829 val = lum_adj->contrast << LUM_ADJ_CONTR_SHIFT |
830 lum_adj->brightness << LUM_ADJ_BRIGHT_SHIFT;
831 regw_ip(base_addr, val, YUV_ADJ);
832}
833
834#define IPIPE_S12Q8(decimal, integer) \
835 (((decimal & 0xff) | ((integer & 0xf) << 8)))
836
837void ipipe_set_rgb2ycbcr_regs(void *__iomem base_addr,
838 struct vpfe_ipipe_rgb2yuv *yuv)
839{
840 u32 val;
841
842 /* S10Q8 */
843 ipipe_clock_enable(base_addr);
844 val = IPIPE_S12Q8(yuv->coef_ry.decimal, yuv->coef_ry.integer);
845 regw_ip(base_addr, val, YUV_MUL_RY);
846 val = IPIPE_S12Q8(yuv->coef_gy.decimal, yuv->coef_gy.integer);
847 regw_ip(base_addr, val, YUV_MUL_GY);
848 val = IPIPE_S12Q8(yuv->coef_by.decimal, yuv->coef_by.integer);
849 regw_ip(base_addr, val, YUV_MUL_BY);
850 val = IPIPE_S12Q8(yuv->coef_rcb.decimal, yuv->coef_rcb.integer);
851 regw_ip(base_addr, val, YUV_MUL_RCB);
852 val = IPIPE_S12Q8(yuv->coef_gcb.decimal, yuv->coef_gcb.integer);
853 regw_ip(base_addr, val, YUV_MUL_GCB);
854 val = IPIPE_S12Q8(yuv->coef_bcb.decimal, yuv->coef_bcb.integer);
855 regw_ip(base_addr, val, YUV_MUL_BCB);
856 val = IPIPE_S12Q8(yuv->coef_rcr.decimal, yuv->coef_rcr.integer);
857 regw_ip(base_addr, val, YUV_MUL_RCR);
858 val = IPIPE_S12Q8(yuv->coef_gcr.decimal, yuv->coef_gcr.integer);
859 regw_ip(base_addr, val, YUV_MUL_GCR);
860 val = IPIPE_S12Q8(yuv->coef_bcr.decimal, yuv->coef_bcr.integer);
861 regw_ip(base_addr, val, YUV_MUL_BCR);
862 regw_ip(base_addr, yuv->out_ofst_y & RGB2YCBCR_OFST_MASK, YUV_OFT_Y);
863 regw_ip(base_addr, yuv->out_ofst_cb & RGB2YCBCR_OFST_MASK, YUV_OFT_CB);
864 regw_ip(base_addr, yuv->out_ofst_cr & RGB2YCBCR_OFST_MASK, YUV_OFT_CR);
865}
866
867/* YUV 422 conversion */
868void
869ipipe_set_yuv422_conv_regs(void *__iomem base_addr,
870 struct vpfe_ipipe_yuv422_conv *conv)
871{
872 u32 val;
873
874 ipipe_clock_enable(base_addr);
875
876 /* Combine all the fields to make YUV_PHS register of IPIPE */
877 val = (conv->chrom_pos << 0) | (conv->en_chrom_lpf << 1);
878 regw_ip(base_addr, val, YUV_PHS);
879}
880
881void
882ipipe_set_gbce_regs(void *__iomem base_addr, void *__iomem isp5_base_addr,
883 struct vpfe_ipipe_gbce *gbce)
884{
885 unsigned int count;
886 u32 mask = GBCE_Y_VAL_MASK;
887
888 if (gbce->type == VPFE_IPIPE_GBCE_GAIN_TBL)
889 mask = GBCE_GAIN_VAL_MASK;
890
891 ipipe_clock_enable(base_addr);
892 regw_ip(base_addr, gbce->en & 1, GBCE_EN);
893
894 if (!gbce->en)
895 return;
896
897 regw_ip(base_addr, gbce->type, GBCE_TYP);
898
899 if (!gbce->table)
900 return;
901
902 for (count = 0; count < VPFE_IPIPE_MAX_SIZE_GBCE_LUT ; count += 2)
903 w_ip_table(isp5_base_addr, ((gbce->table[count + 1] & mask) <<
904 GBCE_ENTRY_SHIFT) | (gbce->table[count] & mask),
905 ((count/2) << 2) + GBCE_TB_START_ADDR);
906}
907
908void
909ipipe_set_ee_regs(void *__iomem base_addr, void *__iomem isp5_base_addr,
910 struct vpfe_ipipe_yee *ee)
911{
912 unsigned int count;
913 u32 val;
914
915 ipipe_clock_enable(base_addr);
916 regw_ip(base_addr, ee->en, YEE_EN);
917
918 if (!ee->en)
919 return;
920
921 val = ee->en_halo_red & 1;
922 val |= ee->merge_meth << YEE_HALO_RED_EN_SHIFT;
923 regw_ip(base_addr, val, YEE_TYP);
924
925 regw_ip(base_addr, ee->hpf_shft, YEE_SHF);
926 regw_ip(base_addr, ee->hpf_coef_00 & YEE_COEF_MASK, YEE_MUL_00);
927 regw_ip(base_addr, ee->hpf_coef_01 & YEE_COEF_MASK, YEE_MUL_01);
928 regw_ip(base_addr, ee->hpf_coef_02 & YEE_COEF_MASK, YEE_MUL_02);
929 regw_ip(base_addr, ee->hpf_coef_10 & YEE_COEF_MASK, YEE_MUL_10);
930 regw_ip(base_addr, ee->hpf_coef_11 & YEE_COEF_MASK, YEE_MUL_11);
931 regw_ip(base_addr, ee->hpf_coef_12 & YEE_COEF_MASK, YEE_MUL_12);
932 regw_ip(base_addr, ee->hpf_coef_20 & YEE_COEF_MASK, YEE_MUL_20);
933 regw_ip(base_addr, ee->hpf_coef_21 & YEE_COEF_MASK, YEE_MUL_21);
934 regw_ip(base_addr, ee->hpf_coef_22 & YEE_COEF_MASK, YEE_MUL_22);
935 regw_ip(base_addr, ee->yee_thr & YEE_THR_MASK, YEE_THR);
936 regw_ip(base_addr, ee->es_gain & YEE_ES_GAIN_MASK, YEE_E_GAN);
937 regw_ip(base_addr, ee->es_thr1 & YEE_ES_THR1_MASK, YEE_E_THR1);
938 regw_ip(base_addr, ee->es_thr2 & YEE_THR_MASK, YEE_E_THR2);
939 regw_ip(base_addr, ee->es_gain_grad & YEE_THR_MASK, YEE_G_GAN);
940 regw_ip(base_addr, ee->es_ofst_grad & YEE_THR_MASK, YEE_G_OFT);
941
942 if (ee->table == NULL)
943 return;
944
945 for (count = 0; count < VPFE_IPIPE_MAX_SIZE_YEE_LUT; count += 2)
946 w_ip_table(isp5_base_addr, ((ee->table[count + 1] &
947 YEE_ENTRY_MASK) << YEE_ENTRY_SHIFT) |
948 (ee->table[count] & YEE_ENTRY_MASK),
949 ((count/2) << 2) + YEE_TB_START_ADDR);
950}
951
952/* Chromatic Artifact Correction. CAR */
953static void ipipe_set_mf(void *__iomem base_addr)
954{
955 /* typ to dynamic switch */
956 regw_ip(base_addr, VPFE_IPIPE_CAR_DYN_SWITCH, CAR_TYP);
957 /* Set SW0 to maximum */
958 regw_ip(base_addr, CAR_MF_THR, CAR_SW);
959}
960
961static void
962ipipe_set_gain_ctrl(void *__iomem base_addr, struct vpfe_ipipe_car *car)
963{
964 regw_ip(base_addr, VPFE_IPIPE_CAR_CHR_GAIN_CTRL, CAR_TYP);
965 regw_ip(base_addr, car->hpf, CAR_HPF_TYP);
966 regw_ip(base_addr, car->hpf_shft & CAR_HPF_SHIFT_MASK, CAR_HPF_SHF);
967 regw_ip(base_addr, car->hpf_thr, CAR_HPF_THR);
968 regw_ip(base_addr, car->gain1.gain, CAR_GN1_GAN);
969 regw_ip(base_addr, car->gain1.shft & CAR_GAIN1_SHFT_MASK, CAR_GN1_SHF);
970 regw_ip(base_addr, car->gain1.gain_min & CAR_GAIN_MIN_MASK,
971 CAR_GN1_MIN);
972 regw_ip(base_addr, car->gain2.gain, CAR_GN2_GAN);
973 regw_ip(base_addr, car->gain2.shft & CAR_GAIN2_SHFT_MASK, CAR_GN2_SHF);
974 regw_ip(base_addr, car->gain2.gain_min & CAR_GAIN_MIN_MASK,
975 CAR_GN2_MIN);
976}
977
978void ipipe_set_car_regs(void *__iomem base_addr, struct vpfe_ipipe_car *car)
979{
980 u32 val;
981
982 ipipe_clock_enable(base_addr);
983 regw_ip(base_addr, car->en, CAR_EN);
984
985 if (!car->en)
986 return;
987
988 switch (car->meth) {
989 case VPFE_IPIPE_CAR_MED_FLTR:
990 ipipe_set_mf(base_addr);
991 break;
992
993 case VPFE_IPIPE_CAR_CHR_GAIN_CTRL:
994 ipipe_set_gain_ctrl(base_addr, car);
995 break;
996
997 default:
998 /* Dynamic switch between MF and Gain Ctrl. */
999 ipipe_set_mf(base_addr);
1000 ipipe_set_gain_ctrl(base_addr, car);
1001 /* Set the threshold for switching between
1002 * the two Here we overwrite the MF SW0 value
1003 */
1004 regw_ip(base_addr, VPFE_IPIPE_CAR_DYN_SWITCH, CAR_TYP);
1005 val = car->sw1;
1006 val <<= CAR_SW1_SHIFT;
1007 val |= car->sw0;
1008 regw_ip(base_addr, val, CAR_SW);
1009 }
1010}
1011
1012/* Chromatic Gain Suppression */
1013void ipipe_set_cgs_regs(void *__iomem base_addr, struct vpfe_ipipe_cgs *cgs)
1014{
1015 ipipe_clock_enable(base_addr);
1016 regw_ip(base_addr, cgs->en, CGS_EN);
1017
1018 if (!cgs->en)
1019 return;
1020
1021 /* Set the bright side parameters */
1022 regw_ip(base_addr, cgs->h_thr, CGS_GN1_H_THR);
1023 regw_ip(base_addr, cgs->h_slope, CGS_GN1_H_GAN);
1024 regw_ip(base_addr, cgs->h_shft & CAR_SHIFT_MASK, CGS_GN1_H_SHF);
1025 regw_ip(base_addr, cgs->h_min, CGS_GN1_H_MIN);
1026}
1027
1028void rsz_src_enable(void *__iomem rsz_base, int enable)
1029{
1030 regw_rsz(rsz_base, enable, RSZ_SRC_EN);
1031}
1032
1033int rsz_enable(void *__iomem rsz_base, int rsz_id, int enable)
1034{
1035 if (rsz_id == RSZ_A) {
1036 regw_rsz(rsz_base, enable, RSZ_EN_A);
1037 /* We always enable RSZ_A. RSZ_B is enable upon request from
1038 * application. So enable RSZ_SRC_EN along with RSZ_A
1039 */
1040 regw_rsz(rsz_base, enable, RSZ_SRC_EN);
1041 } else if (rsz_id == RSZ_B) {
1042 regw_rsz(rsz_base, enable, RSZ_EN_B);
1043 } else {
1044 BUG();
1045 }
1046
1047 return 0;
1048}
diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipe_hw.h b/drivers/staging/media/davinci_vpfe/dm365_ipipe_hw.h
new file mode 100644
index 000000000000..010fdb247faf
--- /dev/null
+++ b/drivers/staging/media/davinci_vpfe/dm365_ipipe_hw.h
@@ -0,0 +1,559 @@
1/*
2 * Copyright (C) 2012 Texas Instruments Inc
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation version 2.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Contributors:
18 * Manjunath Hadli <manjunath.hadli@ti.com>
19 * Prabhakar Lad <prabhakar.lad@ti.com>
20 */
21
22#ifndef _DAVINCI_VPFE_DM365_IPIPE_HW_H
23#define _DAVINCI_VPFE_DM365_IPIPE_HW_H
24
25#include "vpfe_mc_capture.h"
26
27#define SET_LOW_ADDR 0x0000ffff
28#define SET_HIGH_ADDR 0xffff0000
29
30/* Below are the internal tables */
31#define DPC_TB0_START_ADDR 0x8000
32#define DPC_TB1_START_ADDR 0x8400
33
34#define GAMMA_R_START_ADDR 0xa800
35#define GAMMA_G_START_ADDR 0xb000
36#define GAMMA_B_START_ADDR 0xb800
37
38/* RAM table addresses for edge enhancement correction*/
39#define YEE_TB_START_ADDR 0x8800
40
41/* RAM table address for GBC LUT */
42#define GBCE_TB_START_ADDR 0x9000
43
44/* RAM table for 3D NF LUT */
45#define D3L_TB0_START_ADDR 0x9800
46#define D3L_TB1_START_ADDR 0x9c00
47#define D3L_TB2_START_ADDR 0xa000
48#define D3L_TB3_START_ADDR 0xa400
49
50/* IPIPE Register Offsets from the base address */
51#define IPIPE_SRC_EN 0x0000
52#define IPIPE_SRC_MODE 0x0004
53#define IPIPE_SRC_FMT 0x0008
54#define IPIPE_SRC_COL 0x000c
55#define IPIPE_SRC_VPS 0x0010
56#define IPIPE_SRC_VSZ 0x0014
57#define IPIPE_SRC_HPS 0x0018
58#define IPIPE_SRC_HSZ 0x001c
59
60#define IPIPE_SEL_SBU 0x0020
61
62#define IPIPE_DMA_STA 0x0024
63#define IPIPE_GCK_MMR 0x0028
64#define IPIPE_GCK_PIX 0x002c
65#define IPIPE_RESERVED0 0x0030
66
67/* Defect Correction */
68#define DPC_LUT_EN 0x0034
69#define DPC_LUT_SEL 0x0038
70#define DPC_LUT_ADR 0x003c
71#define DPC_LUT_SIZ 0x0040
72#define DPC_OTF_EN 0x0044
73#define DPC_OTF_TYP 0x0048
74#define DPC_OTF_2D_THR_R 0x004c
75#define DPC_OTF_2D_THR_GR 0x0050
76#define DPC_OTF_2D_THR_GB 0x0054
77#define DPC_OTF_2D_THR_B 0x0058
78#define DPC_OTF_2C_THR_R 0x005c
79#define DPC_OTF_2C_THR_GR 0x0060
80#define DPC_OTF_2C_THR_GB 0x0064
81#define DPC_OTF_2C_THR_B 0x0068
82#define DPC_OTF_3_SHF 0x006c
83#define DPC_OTF_3D_THR 0x0070
84#define DPC_OTF_3D_SLP 0x0074
85#define DPC_OTF_3D_MIN 0x0078
86#define DPC_OTF_3D_MAX 0x007c
87#define DPC_OTF_3C_THR 0x0080
88#define DPC_OTF_3C_SLP 0x0084
89#define DPC_OTF_3C_MIN 0x0088
90#define DPC_OTF_3C_MAX 0x008c
91
92/* Lense Shading Correction */
93#define LSC_VOFT 0x90
94#define LSC_VA2 0x94
95#define LSC_VA1 0x98
96#define LSC_VS 0x9c
97#define LSC_HOFT 0xa0
98#define LSC_HA2 0xa4
99#define LSC_HA1 0xa8
100#define LSC_HS 0xac
101#define LSC_GAIN_R 0xb0
102#define LSC_GAIN_GR 0xb4
103#define LSC_GAIN_GB 0xb8
104#define LSC_GAIN_B 0xbc
105#define LSC_OFT_R 0xc0
106#define LSC_OFT_GR 0xc4
107#define LSC_OFT_GB 0xc8
108#define LSC_OFT_B 0xcc
109#define LSC_SHF 0xd0
110#define LSC_MAX 0xd4
111
112/* Noise Filter 1. Ofsets from start address given */
113#define D2F_1ST 0xd8
114#define D2F_EN 0x0
115#define D2F_TYP 0x4
116#define D2F_THR 0x8
117#define D2F_STR 0x28
118#define D2F_SPR 0x48
119#define D2F_EDG_MIN 0x68
120#define D2F_EDG_MAX 0x6c
121
122/* Noise Filter 2 */
123#define D2F_2ND 0x148
124
125/* GIC */
126#define GIC_EN 0x1b8
127#define GIC_TYP 0x1bc
128#define GIC_GAN 0x1c0
129#define GIC_NFGAN 0x1c4
130#define GIC_THR 0x1c8
131#define GIC_SLP 0x1cc
132
133/* White Balance */
134#define WB2_OFT_R 0x1d0
135#define WB2_OFT_GR 0x1d4
136#define WB2_OFT_GB 0x1d8
137#define WB2_OFT_B 0x1dc
138#define WB2_WGN_R 0x1e0
139#define WB2_WGN_GR 0x1e4
140#define WB2_WGN_GB 0x1e8
141#define WB2_WGN_B 0x1ec
142
143/* CFA interpolation */
144#define CFA_MODE 0x1f0
145#define CFA_2DIR_HPF_THR 0x1f4
146#define CFA_2DIR_HPF_SLP 0x1f8
147#define CFA_2DIR_MIX_THR 0x1fc
148#define CFA_2DIR_MIX_SLP 0x200
149#define CFA_2DIR_DIR_THR 0x204
150#define CFA_2DIR_DIR_SLP 0x208
151#define CFA_2DIR_NDWT 0x20c
152#define CFA_MONO_HUE_FRA 0x210
153#define CFA_MONO_EDG_THR 0x214
154#define CFA_MONO_THR_MIN 0x218
155#define CFA_MONO_THR_SLP 0x21c
156#define CFA_MONO_SLP_MIN 0x220
157#define CFA_MONO_SLP_SLP 0x224
158#define CFA_MONO_LPWT 0x228
159
160/* RGB to RGB conversiona - 1st */
161#define RGB1_MUL_BASE 0x22c
162/* Offsets from base */
163#define RGB_MUL_RR 0x0
164#define RGB_MUL_GR 0x4
165#define RGB_MUL_BR 0x8
166#define RGB_MUL_RG 0xc
167#define RGB_MUL_GG 0x10
168#define RGB_MUL_BG 0x14
169#define RGB_MUL_RB 0x18
170#define RGB_MUL_GB 0x1c
171#define RGB_MUL_BB 0x20
172#define RGB_OFT_OR 0x24
173#define RGB_OFT_OG 0x28
174#define RGB_OFT_OB 0x2c
175
176/* Gamma */
177#define GMM_CFG 0x25c
178
179/* RGB to RGB conversiona - 2nd */
180#define RGB2_MUL_BASE 0x260
181
182/* 3D LUT */
183#define D3LUT_EN 0x290
184
185/* RGB to YUV(YCbCr) conversion */
186#define YUV_ADJ 0x294
187#define YUV_MUL_RY 0x298
188#define YUV_MUL_GY 0x29c
189#define YUV_MUL_BY 0x2a0
190#define YUV_MUL_RCB 0x2a4
191#define YUV_MUL_GCB 0x2a8
192#define YUV_MUL_BCB 0x2ac
193#define YUV_MUL_RCR 0x2b0
194#define YUV_MUL_GCR 0x2b4
195#define YUV_MUL_BCR 0x2b8
196#define YUV_OFT_Y 0x2bc
197#define YUV_OFT_CB 0x2c0
198#define YUV_OFT_CR 0x2c4
199#define YUV_PHS 0x2c8
200
201/* Global Brightness and Contrast */
202#define GBCE_EN 0x2cc
203#define GBCE_TYP 0x2d0
204
205/* Edge Enhancer */
206#define YEE_EN 0x2d4
207#define YEE_TYP 0x2d8
208#define YEE_SHF 0x2dc
209#define YEE_MUL_00 0x2e0
210#define YEE_MUL_01 0x2e4
211#define YEE_MUL_02 0x2e8
212#define YEE_MUL_10 0x2ec
213#define YEE_MUL_11 0x2f0
214#define YEE_MUL_12 0x2f4
215#define YEE_MUL_20 0x2f8
216#define YEE_MUL_21 0x2fc
217#define YEE_MUL_22 0x300
218#define YEE_THR 0x304
219#define YEE_E_GAN 0x308
220#define YEE_E_THR1 0x30c
221#define YEE_E_THR2 0x310
222#define YEE_G_GAN 0x314
223#define YEE_G_OFT 0x318
224
225/* Chroma Artifact Reduction */
226#define CAR_EN 0x31c
227#define CAR_TYP 0x320
228#define CAR_SW 0x324
229#define CAR_HPF_TYP 0x328
230#define CAR_HPF_SHF 0x32c
231#define CAR_HPF_THR 0x330
232#define CAR_GN1_GAN 0x334
233#define CAR_GN1_SHF 0x338
234#define CAR_GN1_MIN 0x33c
235#define CAR_GN2_GAN 0x340
236#define CAR_GN2_SHF 0x344
237#define CAR_GN2_MIN 0x348
238
239/* Chroma Gain Suppression */
240#define CGS_EN 0x34c
241#define CGS_GN1_L_THR 0x350
242#define CGS_GN1_L_GAN 0x354
243#define CGS_GN1_L_SHF 0x358
244#define CGS_GN1_L_MIN 0x35c
245#define CGS_GN1_H_THR 0x360
246#define CGS_GN1_H_GAN 0x364
247#define CGS_GN1_H_SHF 0x368
248#define CGS_GN1_H_MIN 0x36c
249#define CGS_GN2_L_THR 0x370
250#define CGS_GN2_L_GAN 0x374
251#define CGS_GN2_L_SHF 0x378
252#define CGS_GN2_L_MIN 0x37c
253
254/* Resizer */
255#define RSZ_SRC_EN 0x0
256#define RSZ_SRC_MODE 0x4
257#define RSZ_SRC_FMT0 0x8
258#define RSZ_SRC_FMT1 0xc
259#define RSZ_SRC_VPS 0x10
260#define RSZ_SRC_VSZ 0x14
261#define RSZ_SRC_HPS 0x18
262#define RSZ_SRC_HSZ 0x1c
263#define RSZ_DMA_RZA 0x20
264#define RSZ_DMA_RZB 0x24
265#define RSZ_DMA_STA 0x28
266#define RSZ_GCK_MMR 0x2c
267#define RSZ_RESERVED0 0x30
268#define RSZ_GCK_SDR 0x34
269#define RSZ_IRQ_RZA 0x38
270#define RSZ_IRQ_RZB 0x3c
271#define RSZ_YUV_Y_MIN 0x40
272#define RSZ_YUV_Y_MAX 0x44
273#define RSZ_YUV_C_MIN 0x48
274#define RSZ_YUV_C_MAX 0x4c
275#define RSZ_YUV_PHS 0x50
276#define RSZ_SEQ 0x54
277
278/* Resizer Rescale Parameters */
279#define RSZ_EN_A 0x58
280#define RSZ_EN_B 0xe8
281/* offset of the registers to be added with base register of
282 either RSZ0 or RSZ1
283*/
284#define RSZ_MODE 0x4
285#define RSZ_420 0x8
286#define RSZ_I_VPS 0xc
287#define RSZ_I_HPS 0x10
288#define RSZ_O_VSZ 0x14
289#define RSZ_O_HSZ 0x18
290#define RSZ_V_PHS_Y 0x1c
291#define RSZ_V_PHS_C 0x20
292#define RSZ_V_DIF 0x24
293#define RSZ_V_TYP 0x28
294#define RSZ_V_LPF 0x2c
295#define RSZ_H_PHS 0x30
296#define RSZ_H_PHS_ADJ 0x34
297#define RSZ_H_DIF 0x38
298#define RSZ_H_TYP 0x3c
299#define RSZ_H_LPF 0x40
300#define RSZ_DWN_EN 0x44
301#define RSZ_DWN_AV 0x48
302
303/* Resizer RGB Conversion Parameters */
304#define RSZ_RGB_EN 0x4c
305#define RSZ_RGB_TYP 0x50
306#define RSZ_RGB_BLD 0x54
307
308/* Resizer External Memory Parameters */
309#define RSZ_SDR_Y_BAD_H 0x58
310#define RSZ_SDR_Y_BAD_L 0x5c
311#define RSZ_SDR_Y_SAD_H 0x60
312#define RSZ_SDR_Y_SAD_L 0x64
313#define RSZ_SDR_Y_OFT 0x68
314#define RSZ_SDR_Y_PTR_S 0x6c
315#define RSZ_SDR_Y_PTR_E 0x70
316#define RSZ_SDR_C_BAD_H 0x74
317#define RSZ_SDR_C_BAD_L 0x78
318#define RSZ_SDR_C_SAD_H 0x7c
319#define RSZ_SDR_C_SAD_L 0x80
320#define RSZ_SDR_C_OFT 0x84
321#define RSZ_SDR_C_PTR_S 0x88
322#define RSZ_SDR_C_PTR_E 0x8c
323
324/* Macro for resizer */
325#define RSZ_YUV_Y_MIN 0x40
326#define RSZ_YUV_Y_MAX 0x44
327#define RSZ_YUV_C_MIN 0x48
328#define RSZ_YUV_C_MAX 0x4c
329
330#define IPIPE_GCK_MMR_DEFAULT 1
331#define IPIPE_GCK_PIX_DEFAULT 0xe
332#define RSZ_GCK_MMR_DEFAULT 1
333#define RSZ_GCK_SDR_DEFAULT 1
334
335/* LUTDPC */
336#define LUTDPC_TBL_256_EN 0
337#define LUTDPC_INF_TBL_EN 1
338#define LUT_DPC_START_ADDR 0
339#define LUT_DPC_H_POS_MASK 0x1fff
340#define LUT_DPC_V_POS_MASK 0x1fff
341#define LUT_DPC_V_POS_SHIFT 13
342#define LUT_DPC_CORR_METH_SHIFT 26
343#define LUT_DPC_MAX_SIZE 256
344#define LUT_DPC_SIZE_MASK 0x3ff
345
346/* OTFDPC */
347#define OTFDPC_DPC2_THR_MASK 0xfff
348#define OTF_DET_METHOD_SHIFT 1
349#define OTF_DPC3_0_SHF_MASK 3
350#define OTF_DPC3_0_THR_SHIFT 6
351#define OTF_DPC3_0_THR_MASK 0x3f
352#define OTF_DPC3_0_SLP_MASK 0x3f
353#define OTF_DPC3_0_DET_MASK 0xfff
354#define OTF_DPC3_0_CORR_MASK 0xfff
355
356/* NF (D2F) */
357#define D2F_SPR_VAL_MASK 0x1f
358#define D2F_SPR_VAL_SHIFT 0
359#define D2F_SHFT_VAL_MASK 3
360#define D2F_SHFT_VAL_SHIFT 5
361#define D2F_SAMPLE_METH_SHIFT 7
362#define D2F_APPLY_LSC_GAIN_SHIFT 8
363#define D2F_USE_SPR_REG_VAL 0
364#define D2F_STR_VAL_MASK 0x1f
365#define D2F_THR_VAL_MASK 0x3ff
366#define D2F_EDGE_DET_THR_MASK 0x7ff
367
368/* Green Imbalance Correction */
369#define GIC_TYP_SHIFT 0
370#define GIC_THR_SEL_SHIFT 1
371#define GIC_APPLY_LSC_GAIN_SHIFT 2
372#define GIC_GAIN_MASK 0xff
373#define GIC_THR_MASK 0xfff
374#define GIC_SLOPE_MASK 0xfff
375#define GIC_NFGAN_INT_MASK 7
376#define GIC_NFGAN_DECI_MASK 0x1f
377
378/* WB */
379#define WB_OFFSET_MASK 0xfff
380#define WB_GAIN_INT_MASK 0xf
381#define WB_GAIN_DECI_MASK 0x1ff
382
383/* CFA */
384#define CFA_HPF_THR_2DIR_MASK 0x1fff
385#define CFA_HPF_SLOPE_2DIR_MASK 0x3ff
386#define CFA_HPF_MIX_THR_2DIR_MASK 0x1fff
387#define CFA_HPF_MIX_SLP_2DIR_MASK 0x3ff
388#define CFA_DIR_THR_2DIR_MASK 0x3ff
389#define CFA_DIR_SLP_2DIR_MASK 0x7f
390#define CFA_ND_WT_2DIR_MASK 0x3f
391#define CFA_DAA_HUE_FRA_MASK 0x3f
392#define CFA_DAA_EDG_THR_MASK 0xff
393#define CFA_DAA_THR_MIN_MASK 0x3ff
394#define CFA_DAA_THR_SLP_MASK 0x3ff
395#define CFA_DAA_SLP_MIN_MASK 0x3ff
396#define CFA_DAA_SLP_SLP_MASK 0x3ff
397#define CFA_DAA_LP_WT_MASK 0x3f
398
399/* RGB2RGB */
400#define RGB2RGB_1_OFST_MASK 0x1fff
401#define RGB2RGB_1_GAIN_INT_MASK 0xf
402#define RGB2RGB_GAIN_DECI_MASK 0xff
403#define RGB2RGB_2_OFST_MASK 0x7ff
404#define RGB2RGB_2_GAIN_INT_MASK 0x7
405
406/* Gamma */
407#define GAMMA_BYPR_SHIFT 0
408#define GAMMA_BYPG_SHIFT 1
409#define GAMMA_BYPB_SHIFT 2
410#define GAMMA_TBL_SEL_SHIFT 4
411#define GAMMA_TBL_SIZE_SHIFT 5
412#define GAMMA_MASK 0x3ff
413#define GAMMA_SHIFT 10
414
415/* 3D LUT */
416#define D3_LUT_ENTRY_MASK 0x3ff
417#define D3_LUT_ENTRY_R_SHIFT 20
418#define D3_LUT_ENTRY_G_SHIFT 10
419#define D3_LUT_ENTRY_B_SHIFT 0
420
421/* Lumina adj */
422#define LUM_ADJ_CONTR_SHIFT 0
423#define LUM_ADJ_BRIGHT_SHIFT 8
424
425/* RGB2YCbCr */
426#define RGB2YCBCR_OFST_MASK 0x7ff
427#define RGB2YCBCR_COEF_INT_MASK 0xf
428#define RGB2YCBCR_COEF_DECI_MASK 0xff
429
430/* GBCE */
431#define GBCE_Y_VAL_MASK 0xff
432#define GBCE_GAIN_VAL_MASK 0x3ff
433#define GBCE_ENTRY_SHIFT 10
434
435/* Edge Enhancements */
436#define YEE_HALO_RED_EN_SHIFT 1
437#define YEE_HPF_SHIFT_MASK 0xf
438#define YEE_COEF_MASK 0x3ff
439#define YEE_THR_MASK 0x3f
440#define YEE_ES_GAIN_MASK 0xfff
441#define YEE_ES_THR1_MASK 0xfff
442#define YEE_ENTRY_SHIFT 9
443#define YEE_ENTRY_MASK 0x1ff
444
445/* CAR */
446#define CAR_MF_THR 0xff
447#define CAR_SW1_SHIFT 8
448#define CAR_GAIN1_SHFT_MASK 7
449#define CAR_GAIN_MIN_MASK 0x1ff
450#define CAR_GAIN2_SHFT_MASK 0xf
451#define CAR_HPF_SHIFT_MASK 3
452
453/* CGS */
454#define CAR_SHIFT_MASK 3
455
456/* Resizer */
457#define RSZ_BYPASS_SHIFT 1
458#define RSZ_SRC_IMG_FMT_SHIFT 1
459#define RSZ_SRC_Y_C_SEL_SHIFT 2
460#define IPIPE_RSZ_VPS_MASK 0xffff
461#define IPIPE_RSZ_HPS_MASK 0xffff
462#define IPIPE_RSZ_VSZ_MASK 0x1fff
463#define IPIPE_RSZ_HSZ_MASK 0x1fff
464#define RSZ_HPS_MASK 0x1fff
465#define RSZ_VPS_MASK 0x1fff
466#define RSZ_O_HSZ_MASK 0x1fff
467#define RSZ_O_VSZ_MASK 0x1fff
468#define RSZ_V_PHS_MASK 0x3fff
469#define RSZ_V_DIF_MASK 0x3fff
470
471#define RSZA_H_FLIP_SHIFT 0
472#define RSZA_V_FLIP_SHIFT 1
473#define RSZB_H_FLIP_SHIFT 2
474#define RSZB_V_FLIP_SHIFT 3
475#define RSZ_A 0
476#define RSZ_B 1
477#define RSZ_CEN_SHIFT 1
478#define RSZ_YEN_SHIFT 0
479#define RSZ_TYP_Y_SHIFT 0
480#define RSZ_TYP_C_SHIFT 1
481#define RSZ_LPF_INT_MASK 0x3f
482#define RSZ_LPF_INT_MASK 0x3f
483#define RSZ_LPF_INT_C_SHIFT 6
484#define RSZ_H_PHS_MASK 0x3fff
485#define RSZ_H_DIF_MASK 0x3fff
486#define RSZ_DIFF_DOWN_THR 256
487#define RSZ_DWN_SCALE_AV_SZ_V_SHIFT 3
488#define RSZ_DWN_SCALE_AV_SZ_MASK 7
489#define RSZ_RGB_MSK1_SHIFT 2
490#define RSZ_RGB_MSK0_SHIFT 1
491#define RSZ_RGB_TYP_SHIFT 0
492#define RSZ_RGB_ALPHA_MASK 0xff
493
494static inline u32 regr_ip(void *__iomem addr, u32 offset)
495{
496 return readl(addr + offset);
497}
498
499static inline void regw_ip(void *__iomem addr, u32 val, u32 offset)
500{
501 writel(val, addr + offset);
502}
503
504static inline u32 w_ip_table(void *__iomem addr, u32 val, u32 offset)
505{
506 writel(val, addr + offset);
507
508 return val;
509}
510
511static inline u32 regr_rsz(void *__iomem addr, u32 offset)
512{
513 return readl(addr + offset);
514}
515
516static inline u32 regw_rsz(void *__iomem addr, u32 val, u32 offset)
517{
518 writel(val, addr + offset);
519
520 return val;
521}
522
523int config_ipipe_hw(struct vpfe_ipipe_device *ipipe);
524int resizer_set_outaddr(void *__iomem rsz_base, struct resizer_params *params,
525 int resize_no, unsigned int address);
526int rsz_enable(void *__iomem rsz_base, int rsz_id, int enable);
527void rsz_src_enable(void *__iomem rsz_base, int enable);
528void rsz_set_in_pix_format(unsigned char y_c);
529int config_rsz_hw(struct vpfe_resizer_device *resizer,
530 struct resizer_params *config);
531void ipipe_set_d2f_regs(void *__iomem base_addr, unsigned int id,
532 struct vpfe_ipipe_nf *noise_filter);
533void ipipe_set_rgb2rgb_regs(void *__iomem base_addr, unsigned int id,
534 struct vpfe_ipipe_rgb2rgb *rgb);
535void ipipe_set_yuv422_conv_regs(void *__iomem base_addr,
536 struct vpfe_ipipe_yuv422_conv *conv);
537void ipipe_set_lum_adj_regs(void *__iomem base_addr,
538 struct ipipe_lum_adj *lum_adj);
539void ipipe_set_rgb2ycbcr_regs(void *__iomem base_addr,
540 struct vpfe_ipipe_rgb2yuv *yuv);
541void ipipe_set_lutdpc_regs(void *__iomem base_addr,
542 void *__iomem isp5_base_addr, struct vpfe_ipipe_lutdpc *lutdpc);
543void ipipe_set_otfdpc_regs(void *__iomem base_addr,
544 struct vpfe_ipipe_otfdpc *otfdpc);
545void ipipe_set_3d_lut_regs(void *__iomem base_addr,
546 void *__iomem isp5_base_addr, struct vpfe_ipipe_3d_lut *lut_3d);
547void ipipe_set_gamma_regs(void *__iomem base_addr,
548 void *__iomem isp5_base_addr, struct vpfe_ipipe_gamma *gamma);
549void ipipe_set_ee_regs(void *__iomem base_addr,
550 void *__iomem isp5_base_addr, struct vpfe_ipipe_yee *ee);
551void ipipe_set_gbce_regs(void *__iomem base_addr,
552 void *__iomem isp5_base_addr, struct vpfe_ipipe_gbce *gbce);
553void ipipe_set_gic_regs(void *__iomem base_addr, struct vpfe_ipipe_gic *gic);
554void ipipe_set_cfa_regs(void *__iomem base_addr, struct vpfe_ipipe_cfa *cfa);
555void ipipe_set_car_regs(void *__iomem base_addr, struct vpfe_ipipe_car *car);
556void ipipe_set_cgs_regs(void *__iomem base_addr, struct vpfe_ipipe_cgs *cgs);
557void ipipe_set_wb_regs(void *__iomem base_addr, struct vpfe_ipipe_wb *wb);
558
559#endif /* _DAVINCI_VPFE_DM365_IPIPE_HW_H */
diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c b/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
new file mode 100644
index 000000000000..c8cae51d3d00
--- /dev/null
+++ b/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
@@ -0,0 +1,1071 @@
1/*
2 * Copyright (C) 2012 Texas Instruments Inc
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation version 2.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Contributors:
18 * Manjunath Hadli <manjunath.hadli@ti.com>
19 * Prabhakar Lad <prabhakar.lad@ti.com>
20 */
21
22#include "dm365_ipipeif.h"
23#include "vpfe_mc_capture.h"
24
25static const unsigned int ipipeif_input_fmts[] = {
26 V4L2_MBUS_FMT_UYVY8_2X8,
27 V4L2_MBUS_FMT_SGRBG12_1X12,
28 V4L2_MBUS_FMT_Y8_1X8,
29 V4L2_MBUS_FMT_UV8_1X8,
30 V4L2_MBUS_FMT_YDYUYDYV8_1X16,
31 V4L2_MBUS_FMT_SBGGR8_1X8,
32};
33
34static const unsigned int ipipeif_output_fmts[] = {
35 V4L2_MBUS_FMT_UYVY8_2X8,
36 V4L2_MBUS_FMT_SGRBG12_1X12,
37 V4L2_MBUS_FMT_Y8_1X8,
38 V4L2_MBUS_FMT_UV8_1X8,
39 V4L2_MBUS_FMT_YDYUYDYV8_1X16,
40 V4L2_MBUS_FMT_SBGGR8_1X8,
41 V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8,
42 V4L2_MBUS_FMT_SGRBG10_ALAW8_1X8,
43};
44
45static int
46ipipeif_get_pack_mode(enum v4l2_mbus_pixelcode in_pix_fmt)
47{
48 switch (in_pix_fmt) {
49 case V4L2_MBUS_FMT_SBGGR8_1X8:
50 case V4L2_MBUS_FMT_Y8_1X8:
51 case V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8:
52 case V4L2_MBUS_FMT_UV8_1X8:
53 return IPIPEIF_5_1_PACK_8_BIT;
54
55 case V4L2_MBUS_FMT_SGRBG10_ALAW8_1X8:
56 return IPIPEIF_5_1_PACK_8_BIT_A_LAW;
57
58 case V4L2_MBUS_FMT_SGRBG12_1X12:
59 return IPIPEIF_5_1_PACK_16_BIT;
60
61 case V4L2_MBUS_FMT_SBGGR12_1X12:
62 return IPIPEIF_5_1_PACK_12_BIT;
63
64 default:
65 return IPIPEIF_5_1_PACK_16_BIT;
66 }
67}
68
69static inline u32 ipipeif_read(void *addr, u32 offset)
70{
71 return readl(addr + offset);
72}
73
74static inline void ipipeif_write(u32 val, void *addr, u32 offset)
75{
76 writel(val, addr + offset);
77}
78
79static void ipipeif_config_dpc(void *addr, struct ipipeif_dpc *dpc)
80{
81 u32 val = 0;
82
83 if (dpc->en) {
84 val = (dpc->en & 1) << IPIPEIF_DPC2_EN_SHIFT;
85 val |= dpc->thr & IPIPEIF_DPC2_THR_MASK;
86 }
87 ipipeif_write(val, addr, IPIPEIF_DPC2);
88}
89
90#define IPIPEIF_MODE_CONTINUOUS 0
91#define IPIPEIF_MODE_ONE_SHOT 1
92
93static int get_oneshot_mode(enum ipipeif_input_entity input)
94{
95 if (input == IPIPEIF_INPUT_MEMORY)
96 return IPIPEIF_MODE_ONE_SHOT;
97 else if (input == IPIPEIF_INPUT_ISIF)
98 return IPIPEIF_MODE_CONTINUOUS;
99
100 return -EINVAL;
101}
102
103static int
104ipipeif_get_cfg_src1(struct vpfe_ipipeif_device *ipipeif)
105{
106 struct v4l2_mbus_framefmt *informat;
107
108 informat = &ipipeif->formats[IPIPEIF_PAD_SINK];
109 if (ipipeif->input == IPIPEIF_INPUT_MEMORY &&
110 (informat->code == V4L2_MBUS_FMT_Y8_1X8 ||
111 informat->code == V4L2_MBUS_FMT_UV8_1X8))
112 return IPIPEIF_CCDC;
113
114 return IPIPEIF_SRC1_PARALLEL_PORT;
115}
116
117static int
118ipipeif_get_data_shift(struct vpfe_ipipeif_device *ipipeif)
119{
120 struct v4l2_mbus_framefmt *informat;
121
122 informat = &ipipeif->formats[IPIPEIF_PAD_SINK];
123
124 switch (informat->code) {
125 case V4L2_MBUS_FMT_SGRBG12_1X12:
126 return IPIPEIF_5_1_BITS11_0;
127
128 case V4L2_MBUS_FMT_Y8_1X8:
129 case V4L2_MBUS_FMT_UV8_1X8:
130 return IPIPEIF_5_1_BITS11_0;
131
132 default:
133 return IPIPEIF_5_1_BITS7_0;
134 }
135}
136
137static enum ipipeif_input_source
138ipipeif_get_source(struct vpfe_ipipeif_device *ipipeif)
139{
140 struct v4l2_mbus_framefmt *informat;
141
142 informat = &ipipeif->formats[IPIPEIF_PAD_SINK];
143 if (ipipeif->input == IPIPEIF_INPUT_ISIF)
144 return IPIPEIF_CCDC;
145
146 if (informat->code == V4L2_MBUS_FMT_UYVY8_2X8)
147 return IPIPEIF_SDRAM_YUV;
148
149 return IPIPEIF_SDRAM_RAW;
150}
151
152void vpfe_ipipeif_ss_buffer_isr(struct vpfe_ipipeif_device *ipipeif)
153{
154 struct vpfe_video_device *video_in = &ipipeif->video_in;
155
156 if (ipipeif->input != IPIPEIF_INPUT_MEMORY)
157 return;
158
159 spin_lock(&video_in->dma_queue_lock);
160 vpfe_video_process_buffer_complete(video_in);
161 video_in->state = VPFE_VIDEO_BUFFER_NOT_QUEUED;
162 vpfe_video_schedule_next_buffer(video_in);
163 spin_unlock(&video_in->dma_queue_lock);
164}
165
166int vpfe_ipipeif_decimation_enabled(struct vpfe_device *vpfe_dev)
167{
168 struct vpfe_ipipeif_device *ipipeif = &vpfe_dev->vpfe_ipipeif;
169
170 return ipipeif->config.decimation;
171}
172
173int vpfe_ipipeif_get_rsz(struct vpfe_device *vpfe_dev)
174{
175 struct vpfe_ipipeif_device *ipipeif = &vpfe_dev->vpfe_ipipeif;
176
177 return ipipeif->config.rsz;
178}
179
180#define RD_DATA_15_2 0x7
181
182/*
183 * ipipeif_hw_setup() - This function sets up IPIPEIF
184 * @sd: pointer to v4l2 subdev structure
185 * return -EINVAL or zero on success
186 */
187static int ipipeif_hw_setup(struct v4l2_subdev *sd)
188{
189 struct vpfe_ipipeif_device *ipipeif = v4l2_get_subdevdata(sd);
190 struct v4l2_mbus_framefmt *informat, *outformat;
191 struct ipipeif_params params = ipipeif->config;
192 enum ipipeif_input_source ipipeif_source;
193 enum v4l2_mbus_pixelcode isif_port_if;
194 void *ipipeif_base_addr;
195 unsigned int val;
196 int data_shift;
197 int pack_mode;
198 int source1;
199
200 ipipeif_base_addr = ipipeif->ipipeif_base_addr;
201
202 /* Enable clock to IPIPEIF and IPIPE */
203 vpss_enable_clock(VPSS_IPIPEIF_CLOCK, 1);
204
205 informat = &ipipeif->formats[IPIPEIF_PAD_SINK];
206 outformat = &ipipeif->formats[IPIPEIF_PAD_SOURCE];
207
208 /* Combine all the fields to make CFG1 register of IPIPEIF */
209 val = get_oneshot_mode(ipipeif->input);
210 if (val < 0) {
211 pr_err("ipipeif: links setup required");
212 return -EINVAL;
213 }
214 val = val << ONESHOT_SHIFT;
215
216 ipipeif_source = ipipeif_get_source(ipipeif);
217 val |= ipipeif_source << INPSRC_SHIFT;
218
219 val |= params.clock_select << CLKSEL_SHIFT;
220 val |= params.avg_filter << AVGFILT_SHIFT;
221 val |= params.decimation << DECIM_SHIFT;
222
223 pack_mode = ipipeif_get_pack_mode(informat->code);
224 val |= pack_mode << PACK8IN_SHIFT;
225
226 source1 = ipipeif_get_cfg_src1(ipipeif);
227 val |= source1 << INPSRC1_SHIFT;
228
229 data_shift = ipipeif_get_data_shift(ipipeif);
230 if (ipipeif_source != IPIPEIF_SDRAM_YUV)
231 val |= data_shift << DATASFT_SHIFT;
232 else
233 val &= ~(RD_DATA_15_2 << DATASFT_SHIFT);
234
235 ipipeif_write(val, ipipeif_base_addr, IPIPEIF_CFG1);
236
237 switch (ipipeif_source) {
238 case IPIPEIF_CCDC:
239 ipipeif_write(ipipeif->gain, ipipeif_base_addr, IPIPEIF_GAIN);
240 break;
241
242 case IPIPEIF_SDRAM_RAW:
243 case IPIPEIF_CCDC_DARKFM:
244 ipipeif_write(ipipeif->gain, ipipeif_base_addr, IPIPEIF_GAIN);
245 /* fall through */
246 case IPIPEIF_SDRAM_YUV:
247 val |= data_shift << DATASFT_SHIFT;
248 ipipeif_write(params.ppln, ipipeif_base_addr, IPIPEIF_PPLN);
249 ipipeif_write(params.lpfr, ipipeif_base_addr, IPIPEIF_LPFR);
250 ipipeif_write(informat->width, ipipeif_base_addr, IPIPEIF_HNUM);
251 ipipeif_write(informat->height,
252 ipipeif_base_addr, IPIPEIF_VNUM);
253 break;
254
255 default:
256 return -EINVAL;
257 }
258
259 /*check if decimation is enable or not */
260 if (params.decimation)
261 ipipeif_write(params.rsz, ipipeif_base_addr, IPIPEIF_RSZ);
262
263 /* Setup sync alignment and initial rsz position */
264 val = params.if_5_1.align_sync & 1;
265 val <<= IPIPEIF_INIRSZ_ALNSYNC_SHIFT;
266 val |= params.if_5_1.rsz_start & IPIPEIF_INIRSZ_MASK;
267 ipipeif_write(val, ipipeif_base_addr, IPIPEIF_INIRSZ);
268 isif_port_if = informat->code;
269
270 if (isif_port_if == V4L2_MBUS_FMT_Y8_1X8)
271 isif_port_if = V4L2_MBUS_FMT_YUYV8_1X16;
272 else if (isif_port_if == V4L2_MBUS_FMT_UV8_1X8)
273 isif_port_if = V4L2_MBUS_FMT_SGRBG12_1X12;
274
275 /* Enable DPCM decompression */
276 switch (ipipeif_source) {
277 case IPIPEIF_SDRAM_RAW:
278 val = 0;
279 if (outformat->code == V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8) {
280 val = 1;
281 val |= (IPIPEIF_DPCM_8BIT_10BIT & 1) <<
282 IPIPEIF_DPCM_BITS_SHIFT;
283 val |= (ipipeif->dpcm_predictor & 1) <<
284 IPIPEIF_DPCM_PRED_SHIFT;
285 }
286 ipipeif_write(val, ipipeif_base_addr, IPIPEIF_DPCM);
287
288 /* set DPC */
289 ipipeif_config_dpc(ipipeif_base_addr, &params.if_5_1.dpc);
290
291 ipipeif_write(params.if_5_1.clip,
292 ipipeif_base_addr, IPIPEIF_OCLIP);
293
294 /* fall through for SDRAM YUV mode */
295 /* configure CFG2 */
296 val = ipipeif_read(ipipeif_base_addr, IPIPEIF_CFG2);
297 switch (isif_port_if) {
298 case V4L2_MBUS_FMT_YUYV8_1X16:
299 case V4L2_MBUS_FMT_UYVY8_2X8:
300 case V4L2_MBUS_FMT_Y8_1X8:
301 RESETBIT(val, IPIPEIF_CFG2_YUV8_SHIFT);
302 SETBIT(val, IPIPEIF_CFG2_YUV16_SHIFT);
303 ipipeif_write(val, ipipeif_base_addr, IPIPEIF_CFG2);
304 break;
305
306 default:
307 RESETBIT(val, IPIPEIF_CFG2_YUV8_SHIFT);
308 RESETBIT(val, IPIPEIF_CFG2_YUV16_SHIFT);
309 ipipeif_write(val, ipipeif_base_addr, IPIPEIF_CFG2);
310 break;
311 }
312
313 case IPIPEIF_SDRAM_YUV:
314 /* Set clock divider */
315 if (params.clock_select == IPIPEIF_SDRAM_CLK) {
316 val = ipipeif_read(ipipeif_base_addr, IPIPEIF_CLKDIV);
317 val |= (params.if_5_1.clk_div.m - 1) <<
318 IPIPEIF_CLKDIV_M_SHIFT;
319 val |= (params.if_5_1.clk_div.n - 1);
320 ipipeif_write(val, ipipeif_base_addr, IPIPEIF_CLKDIV);
321 }
322 break;
323
324 case IPIPEIF_CCDC:
325 case IPIPEIF_CCDC_DARKFM:
326 /* set DPC */
327 ipipeif_config_dpc(ipipeif_base_addr, &params.if_5_1.dpc);
328
329 /* Set DF gain & threshold control */
330 val = 0;
331 if (params.if_5_1.df_gain_en) {
332 val = params.if_5_1.df_gain_thr &
333 IPIPEIF_DF_GAIN_THR_MASK;
334 ipipeif_write(val, ipipeif_base_addr, IPIPEIF_DFSGTH);
335 val = (params.if_5_1.df_gain_en & 1) <<
336 IPIPEIF_DF_GAIN_EN_SHIFT;
337 val |= params.if_5_1.df_gain &
338 IPIPEIF_DF_GAIN_MASK;
339 }
340 ipipeif_write(val, ipipeif_base_addr, IPIPEIF_DFSGVL);
341 /* configure CFG2 */
342 val = VPFE_PINPOL_POSITIVE << IPIPEIF_CFG2_HDPOL_SHIFT;
343 val |= VPFE_PINPOL_POSITIVE << IPIPEIF_CFG2_VDPOL_SHIFT;
344
345 switch (isif_port_if) {
346 case V4L2_MBUS_FMT_YUYV8_1X16:
347 case V4L2_MBUS_FMT_YUYV10_1X20:
348 RESETBIT(val, IPIPEIF_CFG2_YUV8_SHIFT);
349 SETBIT(val, IPIPEIF_CFG2_YUV16_SHIFT);
350 break;
351
352 case V4L2_MBUS_FMT_YUYV8_2X8:
353 case V4L2_MBUS_FMT_UYVY8_2X8:
354 case V4L2_MBUS_FMT_Y8_1X8:
355 case V4L2_MBUS_FMT_YUYV10_2X10:
356 SETBIT(val, IPIPEIF_CFG2_YUV8_SHIFT);
357 SETBIT(val, IPIPEIF_CFG2_YUV16_SHIFT);
358 val |= IPIPEIF_CBCR_Y << IPIPEIF_CFG2_YUV8P_SHIFT;
359 break;
360
361 default:
362 /* Bayer */
363 ipipeif_write(params.if_5_1.clip, ipipeif_base_addr,
364 IPIPEIF_OCLIP);
365 }
366 ipipeif_write(val, ipipeif_base_addr, IPIPEIF_CFG2);
367 break;
368
369 default:
370 return -EINVAL;
371 }
372
373 return 0;
374}
375
376static int
377ipipeif_set_config(struct v4l2_subdev *sd, struct ipipeif_params *config)
378{
379 struct vpfe_ipipeif_device *ipipeif = v4l2_get_subdevdata(sd);
380 struct device *dev = ipipeif->subdev.v4l2_dev->dev;
381
382 if (!config) {
383 dev_err(dev, "Invalid configuration pointer\n");
384 return -EINVAL;
385 }
386
387 ipipeif->config.clock_select = config->clock_select;
388 ipipeif->config.ppln = config->ppln;
389 ipipeif->config.lpfr = config->lpfr;
390 ipipeif->config.rsz = config->rsz;
391 ipipeif->config.decimation = config->decimation;
392 if (ipipeif->config.decimation &&
393 (ipipeif->config.rsz < IPIPEIF_RSZ_MIN ||
394 ipipeif->config.rsz > IPIPEIF_RSZ_MAX)) {
395 dev_err(dev, "rsz range is %d to %d\n",
396 IPIPEIF_RSZ_MIN, IPIPEIF_RSZ_MAX);
397 return -EINVAL;
398 }
399
400 ipipeif->config.avg_filter = config->avg_filter;
401
402 ipipeif->config.if_5_1.df_gain_thr = config->if_5_1.df_gain_thr;
403 ipipeif->config.if_5_1.df_gain = config->if_5_1.df_gain;
404 ipipeif->config.if_5_1.df_gain_en = config->if_5_1.df_gain_en;
405
406 ipipeif->config.if_5_1.rsz_start = config->if_5_1.rsz_start;
407 ipipeif->config.if_5_1.align_sync = config->if_5_1.align_sync;
408 ipipeif->config.if_5_1.clip = config->if_5_1.clip;
409
410 ipipeif->config.if_5_1.dpc.en = config->if_5_1.dpc.en;
411 ipipeif->config.if_5_1.dpc.thr = config->if_5_1.dpc.thr;
412
413 ipipeif->config.if_5_1.clk_div.m = config->if_5_1.clk_div.m;
414 ipipeif->config.if_5_1.clk_div.n = config->if_5_1.clk_div.n;
415
416 return 0;
417}
418
419static int
420ipipeif_get_config(struct v4l2_subdev *sd, void __user *arg)
421{
422 struct vpfe_ipipeif_device *ipipeif = v4l2_get_subdevdata(sd);
423 struct ipipeif_params *config = (struct ipipeif_params *)arg;
424 struct device *dev = ipipeif->subdev.v4l2_dev->dev;
425
426 if (!arg) {
427 dev_err(dev, "Invalid configuration pointer\n");
428 return -EINVAL;
429 }
430
431 config->clock_select = ipipeif->config.clock_select;
432 config->ppln = ipipeif->config.ppln;
433 config->lpfr = ipipeif->config.lpfr;
434 config->rsz = ipipeif->config.rsz;
435 config->decimation = ipipeif->config.decimation;
436 config->avg_filter = ipipeif->config.avg_filter;
437
438 config->if_5_1.df_gain_thr = ipipeif->config.if_5_1.df_gain_thr;
439 config->if_5_1.df_gain = ipipeif->config.if_5_1.df_gain;
440 config->if_5_1.df_gain_en = ipipeif->config.if_5_1.df_gain_en;
441
442 config->if_5_1.rsz_start = ipipeif->config.if_5_1.rsz_start;
443 config->if_5_1.align_sync = ipipeif->config.if_5_1.align_sync;
444 config->if_5_1.clip = ipipeif->config.if_5_1.clip;
445
446 config->if_5_1.dpc.en = ipipeif->config.if_5_1.dpc.en;
447 config->if_5_1.dpc.thr = ipipeif->config.if_5_1.dpc.thr;
448
449 config->if_5_1.clk_div.m = ipipeif->config.if_5_1.clk_div.m;
450 config->if_5_1.clk_div.n = ipipeif->config.if_5_1.clk_div.n;
451
452 return 0;
453}
454
455/*
456 * ipipeif_ioctl() - Handle ipipeif module private ioctl's
457 * @sd: pointer to v4l2 subdev structure
458 * @cmd: configuration command
459 * @arg: configuration argument
460 */
461static long ipipeif_ioctl(struct v4l2_subdev *sd,
462 unsigned int cmd, void *arg)
463{
464 struct ipipeif_params *config = (struct ipipeif_params *)arg;
465 int ret = -ENOIOCTLCMD;
466
467 switch (cmd) {
468 case VIDIOC_VPFE_IPIPEIF_S_CONFIG:
469 ret = ipipeif_set_config(sd, config);
470 break;
471
472 case VIDIOC_VPFE_IPIPEIF_G_CONFIG:
473 ret = ipipeif_get_config(sd, arg);
474 break;
475 }
476 return ret;
477}
478
479/*
480 * ipipeif_s_ctrl() - Handle set control subdev method
481 * @ctrl: pointer to v4l2 control structure
482 */
483static int ipipeif_s_ctrl(struct v4l2_ctrl *ctrl)
484{
485 struct vpfe_ipipeif_device *ipipeif =
486 container_of(ctrl->handler, struct vpfe_ipipeif_device, ctrls);
487
488 switch (ctrl->id) {
489 case VPFE_CID_DPCM_PREDICTOR:
490 ipipeif->dpcm_predictor = ctrl->val;
491 break;
492
493 case V4L2_CID_GAIN:
494 ipipeif->gain = ctrl->val;
495 break;
496
497 default:
498 return -EINVAL;
499 }
500
501 return 0;
502}
503
504#define ENABLE_IPIPEIF 0x1
505
506void vpfe_ipipeif_enable(struct vpfe_device *vpfe_dev)
507{
508 struct vpfe_ipipeif_device *ipipeif = &vpfe_dev->vpfe_ipipeif;
509 void *ipipeif_base_addr = ipipeif->ipipeif_base_addr;
510 unsigned char val;
511
512 if (ipipeif->input != IPIPEIF_INPUT_MEMORY)
513 return;
514
515 do {
516 val = ipipeif_read(ipipeif_base_addr, IPIPEIF_ENABLE);
517 } while (val & 0x1);
518
519 ipipeif_write(ENABLE_IPIPEIF, ipipeif_base_addr, IPIPEIF_ENABLE);
520}
521
522/*
523 * ipipeif_set_stream() - Enable/Disable streaming on ipipeif subdev
524 * @sd: pointer to v4l2 subdev structure
525 * @enable: 1 == Enable, 0 == Disable
526 */
527static int ipipeif_set_stream(struct v4l2_subdev *sd, int enable)
528{
529 struct vpfe_ipipeif_device *ipipeif = v4l2_get_subdevdata(sd);
530 struct vpfe_device *vpfe_dev = to_vpfe_device(ipipeif);
531 int ret = 0;
532
533 if (!enable)
534 return ret;
535
536 ret = ipipeif_hw_setup(sd);
537 if (!ret)
538 vpfe_ipipeif_enable(vpfe_dev);
539
540 return ret;
541}
542
543/*
544 * ipipeif_enum_mbus_code() - Handle pixel format enumeration
545 * @sd: pointer to v4l2 subdev structure
546 * @fh: V4L2 subdev file handle
547 * @code: pointer to v4l2_subdev_mbus_code_enum structure
548 * return -EINVAL or zero on success
549 */
550static int ipipeif_enum_mbus_code(struct v4l2_subdev *sd,
551 struct v4l2_subdev_fh *fh,
552 struct v4l2_subdev_mbus_code_enum *code)
553{
554 switch (code->pad) {
555 case IPIPEIF_PAD_SINK:
556 if (code->index >= ARRAY_SIZE(ipipeif_input_fmts))
557 return -EINVAL;
558
559 code->code = ipipeif_input_fmts[code->index];
560 break;
561
562 case IPIPEIF_PAD_SOURCE:
563 if (code->index >= ARRAY_SIZE(ipipeif_output_fmts))
564 return -EINVAL;
565
566 code->code = ipipeif_output_fmts[code->index];
567 break;
568
569 default:
570 return -EINVAL;
571 }
572
573 return 0;
574}
575
576/*
577 * ipipeif_get_format() - Handle get format by pads subdev method
578 * @sd: pointer to v4l2 subdev structure
579 * @fh: V4L2 subdev file handle
580 * @fmt: pointer to v4l2 subdev format structure
581 */
582static int
583ipipeif_get_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
584 struct v4l2_subdev_format *fmt)
585{
586 struct vpfe_ipipeif_device *ipipeif = v4l2_get_subdevdata(sd);
587
588 if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE)
589 fmt->format = ipipeif->formats[fmt->pad];
590 else
591 fmt->format = *(v4l2_subdev_get_try_format(fh, fmt->pad));
592
593 return 0;
594}
595
596#define MIN_OUT_WIDTH 32
597#define MIN_OUT_HEIGHT 32
598
599/*
600 * ipipeif_try_format() - Handle try format by pad subdev method
601 * @ipipeif: VPFE ipipeif device.
602 * @fh: V4L2 subdev file handle.
603 * @pad: pad num.
604 * @fmt: pointer to v4l2 format structure.
605 * @which : wanted subdev format
606 */
607static void
608ipipeif_try_format(struct vpfe_ipipeif_device *ipipeif,
609 struct v4l2_subdev_fh *fh, unsigned int pad,
610 struct v4l2_mbus_framefmt *fmt,
611 enum v4l2_subdev_format_whence which)
612{
613 unsigned int max_out_height;
614 unsigned int max_out_width;
615 unsigned int i;
616
617 max_out_width = IPIPE_MAX_OUTPUT_WIDTH_A;
618 max_out_height = IPIPE_MAX_OUTPUT_HEIGHT_A;
619
620 if (pad == IPIPEIF_PAD_SINK) {
621 for (i = 0; i < ARRAY_SIZE(ipipeif_input_fmts); i++)
622 if (fmt->code == ipipeif_input_fmts[i])
623 break;
624
625 /* If not found, use SBGGR10 as default */
626 if (i >= ARRAY_SIZE(ipipeif_input_fmts))
627 fmt->code = V4L2_MBUS_FMT_SGRBG12_1X12;
628 } else if (pad == IPIPEIF_PAD_SOURCE) {
629 for (i = 0; i < ARRAY_SIZE(ipipeif_output_fmts); i++)
630 if (fmt->code == ipipeif_output_fmts[i])
631 break;
632
633 /* If not found, use UYVY as default */
634 if (i >= ARRAY_SIZE(ipipeif_output_fmts))
635 fmt->code = V4L2_MBUS_FMT_UYVY8_2X8;
636 }
637
638 fmt->width = clamp_t(u32, fmt->width, MIN_OUT_HEIGHT, max_out_width);
639 fmt->height = clamp_t(u32, fmt->height, MIN_OUT_WIDTH, max_out_height);
640}
641
642static int
643ipipeif_enum_frame_size(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
644 struct v4l2_subdev_frame_size_enum *fse)
645{
646 struct vpfe_ipipeif_device *ipipeif = v4l2_get_subdevdata(sd);
647 struct v4l2_mbus_framefmt format;
648
649 if (fse->index != 0)
650 return -EINVAL;
651
652 format.code = fse->code;
653 format.width = 1;
654 format.height = 1;
655 ipipeif_try_format(ipipeif, fh, fse->pad, &format,
656 V4L2_SUBDEV_FORMAT_TRY);
657 fse->min_width = format.width;
658 fse->min_height = format.height;
659
660 if (format.code != fse->code)
661 return -EINVAL;
662
663 format.code = fse->code;
664 format.width = -1;
665 format.height = -1;
666 ipipeif_try_format(ipipeif, fh, fse->pad, &format,
667 V4L2_SUBDEV_FORMAT_TRY);
668 fse->max_width = format.width;
669 fse->max_height = format.height;
670
671 return 0;
672}
673
674/*
675 * __ipipeif_get_format() - helper function for getting ipipeif format
676 * @ipipeif: pointer to ipipeif private structure.
677 * @pad: pad number.
678 * @fh: V4L2 subdev file handle.
679 * @which: wanted subdev format.
680 *
681 */
682static struct v4l2_mbus_framefmt *
683__ipipeif_get_format(struct vpfe_ipipeif_device *ipipeif,
684 struct v4l2_subdev_fh *fh, unsigned int pad,
685 enum v4l2_subdev_format_whence which)
686{
687 if (which == V4L2_SUBDEV_FORMAT_TRY)
688 return v4l2_subdev_get_try_format(fh, pad);
689
690 return &ipipeif->formats[pad];
691}
692
693/*
694 * ipipeif_set_format() - Handle set format by pads subdev method
695 * @sd: pointer to v4l2 subdev structure
696 * @fh: V4L2 subdev file handle
697 * @fmt: pointer to v4l2 subdev format structure
698 * return -EINVAL or zero on success
699 */
700static int
701ipipeif_set_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
702 struct v4l2_subdev_format *fmt)
703{
704 struct vpfe_ipipeif_device *ipipeif = v4l2_get_subdevdata(sd);
705 struct v4l2_mbus_framefmt *format;
706
707 format = __ipipeif_get_format(ipipeif, fh, fmt->pad, fmt->which);
708 if (format == NULL)
709 return -EINVAL;
710
711 ipipeif_try_format(ipipeif, fh, fmt->pad, &fmt->format, fmt->which);
712 *format = fmt->format;
713
714 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY)
715 return 0;
716
717 if (fmt->pad == IPIPEIF_PAD_SINK &&
718 ipipeif->input != IPIPEIF_INPUT_NONE)
719 ipipeif->formats[fmt->pad] = fmt->format;
720 else if (fmt->pad == IPIPEIF_PAD_SOURCE &&
721 ipipeif->output != IPIPEIF_OUTPUT_NONE)
722 ipipeif->formats[fmt->pad] = fmt->format;
723 else
724 return -EINVAL;
725
726 return 0;
727}
728
729static void ipipeif_set_default_config(struct vpfe_ipipeif_device *ipipeif)
730{
731#define WIDTH_I 640
732#define HEIGHT_I 480
733
734 const struct ipipeif_params ipipeif_defaults = {
735 .clock_select = IPIPEIF_SDRAM_CLK,
736 .ppln = WIDTH_I + 8,
737 .lpfr = HEIGHT_I + 10,
738 .rsz = 16, /* resize ratio 16/rsz */
739 .decimation = IPIPEIF_DECIMATION_OFF,
740 .avg_filter = IPIPEIF_AVG_OFF,
741 .if_5_1 = {
742 .clk_div = {
743 .m = 1, /* clock = sdram clock * (m/n) */
744 .n = 6
745 },
746 .clip = 4095,
747 },
748 };
749 memset(&ipipeif->config, 0, sizeof(struct ipipeif_params));
750 memcpy(&ipipeif->config, &ipipeif_defaults,
751 sizeof(struct ipipeif_params));
752}
753
754/*
755 * ipipeif_init_formats() - Initialize formats on all pads
756 * @sd: VPFE ipipeif V4L2 subdevice
757 * @fh: V4L2 subdev file handle
758 *
759 * Initialize all pad formats with default values. If fh is not NULL, try
760 * formats are initialized on the file handle. Otherwise active formats are
761 * initialized on the device.
762 */
763static int
764ipipeif_init_formats(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
765{
766 struct vpfe_ipipeif_device *ipipeif = v4l2_get_subdevdata(sd);
767 struct v4l2_subdev_format format;
768
769 memset(&format, 0, sizeof(format));
770 format.pad = IPIPEIF_PAD_SINK;
771 format.which = fh ? V4L2_SUBDEV_FORMAT_TRY : V4L2_SUBDEV_FORMAT_ACTIVE;
772 format.format.code = V4L2_MBUS_FMT_SGRBG12_1X12;
773 format.format.width = IPIPE_MAX_OUTPUT_WIDTH_A;
774 format.format.height = IPIPE_MAX_OUTPUT_HEIGHT_A;
775 ipipeif_set_format(sd, fh, &format);
776
777 memset(&format, 0, sizeof(format));
778 format.pad = IPIPEIF_PAD_SOURCE;
779 format.which = fh ? V4L2_SUBDEV_FORMAT_TRY : V4L2_SUBDEV_FORMAT_ACTIVE;
780 format.format.code = V4L2_MBUS_FMT_UYVY8_2X8;
781 format.format.width = IPIPE_MAX_OUTPUT_WIDTH_A;
782 format.format.height = IPIPE_MAX_OUTPUT_HEIGHT_A;
783 ipipeif_set_format(sd, fh, &format);
784
785 ipipeif_set_default_config(ipipeif);
786
787 return 0;
788}
789
790/*
791 * ipipeif_video_in_queue() - ipipeif video in queue
792 * @vpfe_dev: vpfe device pointer
793 * @addr: buffer address
794 */
795static int
796ipipeif_video_in_queue(struct vpfe_device *vpfe_dev, unsigned long addr)
797{
798 struct vpfe_ipipeif_device *ipipeif = &vpfe_dev->vpfe_ipipeif;
799 void *ipipeif_base_addr = ipipeif->ipipeif_base_addr;
800 unsigned int adofs;
801 u32 val;
802
803 if (ipipeif->input != IPIPEIF_INPUT_MEMORY)
804 return -EINVAL;
805
806 switch (ipipeif->formats[IPIPEIF_PAD_SINK].code) {
807 case V4L2_MBUS_FMT_Y8_1X8:
808 case V4L2_MBUS_FMT_UV8_1X8:
809 case V4L2_MBUS_FMT_YDYUYDYV8_1X16:
810 adofs = ipipeif->formats[IPIPEIF_PAD_SINK].width;
811 break;
812
813 default:
814 adofs = ipipeif->formats[IPIPEIF_PAD_SINK].width << 1;
815 break;
816 }
817
818 /* adjust the line len to be a multiple of 32 */
819 adofs += 31;
820 adofs &= ~0x1f;
821 val = (adofs >> 5) & IPIPEIF_ADOFS_LSB_MASK;
822 ipipeif_write(val, ipipeif_base_addr, IPIPEIF_ADOFS);
823
824 /* lower sixteen bit */
825 val = (addr >> IPIPEIF_ADDRL_SHIFT) & IPIPEIF_ADDRL_MASK;
826 ipipeif_write(val, ipipeif_base_addr, IPIPEIF_ADDRL);
827
828 /* upper next seven bit */
829 val = (addr >> IPIPEIF_ADDRU_SHIFT) & IPIPEIF_ADDRU_MASK;
830 ipipeif_write(val, ipipeif_base_addr, IPIPEIF_ADDRU);
831
832 return 0;
833}
834
835/* subdev core operations */
836static const struct v4l2_subdev_core_ops ipipeif_v4l2_core_ops = {
837 .ioctl = ipipeif_ioctl,
838};
839
840static const struct v4l2_ctrl_ops ipipeif_ctrl_ops = {
841 .s_ctrl = ipipeif_s_ctrl,
842};
843
844static const struct v4l2_ctrl_config vpfe_ipipeif_dpcm_pred = {
845 .ops = &ipipeif_ctrl_ops,
846 .id = VPFE_CID_DPCM_PREDICTOR,
847 .name = "DPCM Predictor",
848 .type = V4L2_CTRL_TYPE_INTEGER,
849 .min = 0,
850 .max = 1,
851 .step = 1,
852 .def = 0,
853};
854
855/* subdev file operations */
856static const struct v4l2_subdev_internal_ops ipipeif_v4l2_internal_ops = {
857 .open = ipipeif_init_formats,
858};
859
860/* subdev video operations */
861static const struct v4l2_subdev_video_ops ipipeif_v4l2_video_ops = {
862 .s_stream = ipipeif_set_stream,
863};
864
865/* subdev pad operations */
866static const struct v4l2_subdev_pad_ops ipipeif_v4l2_pad_ops = {
867 .enum_mbus_code = ipipeif_enum_mbus_code,
868 .enum_frame_size = ipipeif_enum_frame_size,
869 .get_fmt = ipipeif_get_format,
870 .set_fmt = ipipeif_set_format,
871};
872
873/* subdev operations */
874static const struct v4l2_subdev_ops ipipeif_v4l2_ops = {
875 .core = &ipipeif_v4l2_core_ops,
876 .video = &ipipeif_v4l2_video_ops,
877 .pad = &ipipeif_v4l2_pad_ops,
878};
879
880static const struct vpfe_video_operations video_in_ops = {
881 .queue = ipipeif_video_in_queue,
882};
883
884static int
885ipipeif_link_setup(struct media_entity *entity, const struct media_pad *local,
886 const struct media_pad *remote, u32 flags)
887{
888 struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
889 struct vpfe_ipipeif_device *ipipeif = v4l2_get_subdevdata(sd);
890 struct vpfe_device *vpfe = to_vpfe_device(ipipeif);
891
892 switch (local->index | media_entity_type(remote->entity)) {
893 case IPIPEIF_PAD_SINK | MEDIA_ENT_T_DEVNODE:
894 /* Single shot mode */
895 if (!(flags & MEDIA_LNK_FL_ENABLED)) {
896 ipipeif->input = IPIPEIF_INPUT_NONE;
897 break;
898 }
899 ipipeif->input = IPIPEIF_INPUT_MEMORY;
900 break;
901
902 case IPIPEIF_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
903 /* read from isif */
904 if (!(flags & MEDIA_LNK_FL_ENABLED)) {
905 ipipeif->input = IPIPEIF_INPUT_NONE;
906 break;
907 }
908 if (ipipeif->input != IPIPEIF_INPUT_NONE)
909 return -EBUSY;
910
911 ipipeif->input = IPIPEIF_INPUT_ISIF;
912 break;
913
914 case IPIPEIF_PAD_SOURCE | MEDIA_ENT_T_V4L2_SUBDEV:
915 if (!(flags & MEDIA_LNK_FL_ENABLED)) {
916 ipipeif->output = IPIPEIF_OUTPUT_NONE;
917 break;
918 }
919 if (remote->entity == &vpfe->vpfe_ipipe.subdev.entity)
920 /* connencted to ipipe */
921 ipipeif->output = IPIPEIF_OUTPUT_IPIPE;
922 else if (remote->entity == &vpfe->vpfe_resizer.
923 crop_resizer.subdev.entity)
924 /* connected to resizer */
925 ipipeif->output = IPIPEIF_OUTPUT_RESIZER;
926 else
927 return -EINVAL;
928 break;
929
930 default:
931 return -EINVAL;
932 }
933
934 return 0;
935}
936
937static const struct media_entity_operations ipipeif_media_ops = {
938 .link_setup = ipipeif_link_setup,
939};
940
941/*
942 * vpfe_ipipeif_unregister_entities() - Unregister entity
943 * @ipipeif - pointer to ipipeif subdevice structure.
944 */
945void vpfe_ipipeif_unregister_entities(struct vpfe_ipipeif_device *ipipeif)
946{
947 /* unregister video device */
948 vpfe_video_unregister(&ipipeif->video_in);
949
950 /* cleanup entity */
951 media_entity_cleanup(&ipipeif->subdev.entity);
952 /* unregister subdev */
953 v4l2_device_unregister_subdev(&ipipeif->subdev);
954}
955
956int
957vpfe_ipipeif_register_entities(struct vpfe_ipipeif_device *ipipeif,
958 struct v4l2_device *vdev)
959{
960 struct vpfe_device *vpfe_dev = to_vpfe_device(ipipeif);
961 unsigned int flags;
962 int ret;
963
964 /* Register the subdev */
965 ret = v4l2_device_register_subdev(vdev, &ipipeif->subdev);
966 if (ret < 0)
967 return ret;
968
969 ret = vpfe_video_register(&ipipeif->video_in, vdev);
970 if (ret) {
971 pr_err("Failed to register ipipeif video-in device\n");
972 goto fail;
973 }
974 ipipeif->video_in.vpfe_dev = vpfe_dev;
975
976 flags = 0;
977 ret = media_entity_create_link(&ipipeif->video_in.video_dev.entity, 0,
978 &ipipeif->subdev.entity, 0, flags);
979 if (ret < 0)
980 goto fail;
981
982 return 0;
983fail:
984 v4l2_device_unregister_subdev(&ipipeif->subdev);
985
986 return ret;
987}
988
989#define IPIPEIF_GAIN_HIGH 0x3ff
990#define IPIPEIF_DEFAULT_GAIN 0x200
991
992int vpfe_ipipeif_init(struct vpfe_ipipeif_device *ipipeif,
993 struct platform_device *pdev)
994{
995 struct v4l2_subdev *sd = &ipipeif->subdev;
996 struct media_pad *pads = &ipipeif->pads[0];
997 struct media_entity *me = &sd->entity;
998 static resource_size_t res_len;
999 struct resource *res;
1000 int ret;
1001
1002 res = platform_get_resource(pdev, IORESOURCE_MEM, 3);
1003 if (!res)
1004 return -ENOENT;
1005
1006 res_len = resource_size(res);
1007 res = request_mem_region(res->start, res_len, res->name);
1008 if (!res)
1009 return -EBUSY;
1010
1011 ipipeif->ipipeif_base_addr = ioremap_nocache(res->start, res_len);
1012 if (!ipipeif->ipipeif_base_addr) {
1013 ret = -EBUSY;
1014 goto fail;
1015 }
1016
1017 v4l2_subdev_init(sd, &ipipeif_v4l2_ops);
1018
1019 sd->internal_ops = &ipipeif_v4l2_internal_ops;
1020 strlcpy(sd->name, "DAVINCI IPIPEIF", sizeof(sd->name));
1021 sd->grp_id = 1 << 16; /* group ID for davinci subdevs */
1022
1023 v4l2_set_subdevdata(sd, ipipeif);
1024
1025 sd->flags |= V4L2_SUBDEV_FL_HAS_EVENTS | V4L2_SUBDEV_FL_HAS_DEVNODE;
1026 pads[IPIPEIF_PAD_SINK].flags = MEDIA_PAD_FL_SINK;
1027 pads[IPIPEIF_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE;
1028 ipipeif->input = IPIPEIF_INPUT_NONE;
1029 ipipeif->output = IPIPEIF_OUTPUT_NONE;
1030 me->ops = &ipipeif_media_ops;
1031
1032 ret = media_entity_init(me, IPIPEIF_NUM_PADS, pads, 0);
1033 if (ret)
1034 goto fail;
1035
1036 v4l2_ctrl_handler_init(&ipipeif->ctrls, 2);
1037 v4l2_ctrl_new_std(&ipipeif->ctrls, &ipipeif_ctrl_ops,
1038 V4L2_CID_GAIN, 0,
1039 IPIPEIF_GAIN_HIGH, 1, IPIPEIF_DEFAULT_GAIN);
1040 v4l2_ctrl_new_custom(&ipipeif->ctrls, &vpfe_ipipeif_dpcm_pred, NULL);
1041 v4l2_ctrl_handler_setup(&ipipeif->ctrls);
1042 sd->ctrl_handler = &ipipeif->ctrls;
1043
1044 ipipeif->video_in.ops = &video_in_ops;
1045 ipipeif->video_in.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
1046 ret = vpfe_video_init(&ipipeif->video_in, "IPIPEIF");
1047 if (ret) {
1048 pr_err("Failed to init IPIPEIF video-in device\n");
1049 goto fail;
1050 }
1051 ipipeif_set_default_config(ipipeif);
1052 return 0;
1053fail:
1054 release_mem_region(res->start, res_len);
1055 return ret;
1056}
1057
1058void
1059vpfe_ipipeif_cleanup(struct vpfe_ipipeif_device *ipipeif,
1060 struct platform_device *pdev)
1061{
1062 struct resource *res;
1063
1064 v4l2_ctrl_handler_free(&ipipeif->ctrls);
1065 iounmap(ipipeif->ipipeif_base_addr);
1066 res = platform_get_resource(pdev, IORESOURCE_MEM, 3);
1067 if (res)
1068 release_mem_region(res->start,
1069 res->end - res->start + 1);
1070
1071}
diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipeif.h b/drivers/staging/media/davinci_vpfe/dm365_ipipeif.h
new file mode 100644
index 000000000000..608701fc5fed
--- /dev/null
+++ b/drivers/staging/media/davinci_vpfe/dm365_ipipeif.h
@@ -0,0 +1,233 @@
1/*
2 * Copyright (C) 2012 Texas Instruments Inc
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation version 2.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Contributors:
18 * Manjunath Hadli <manjunath.hadli@ti.com>
19 * Prabhakar Lad <prabhakar.lad@ti.com>
20 */
21
22#ifndef _DAVINCI_VPFE_DM365_IPIPEIF_H
23#define _DAVINCI_VPFE_DM365_IPIPEIF_H
24
25#include <linux/platform_device.h>
26
27#include <media/davinci/vpss.h>
28#include <media/v4l2-ctrls.h>
29#include <media/v4l2-subdev.h>
30
31#include "dm365_ipipeif_user.h"
32#include "vpfe_video.h"
33
34/* IPIPE base specific types */
35enum ipipeif_data_shift {
36 IPIPEIF_BITS15_2 = 0,
37 IPIPEIF_BITS14_1 = 1,
38 IPIPEIF_BITS13_0 = 2,
39 IPIPEIF_BITS12_0 = 3,
40 IPIPEIF_BITS11_0 = 4,
41 IPIPEIF_BITS10_0 = 5,
42 IPIPEIF_BITS9_0 = 6,
43};
44
45enum ipipeif_clkdiv {
46 IPIPEIF_DIVIDE_HALF = 0,
47 IPIPEIF_DIVIDE_THIRD = 1,
48 IPIPEIF_DIVIDE_FOURTH = 2,
49 IPIPEIF_DIVIDE_FIFTH = 3,
50 IPIPEIF_DIVIDE_SIXTH = 4,
51 IPIPEIF_DIVIDE_EIGHTH = 5,
52 IPIPEIF_DIVIDE_SIXTEENTH = 6,
53 IPIPEIF_DIVIDE_THIRTY = 7,
54};
55
56enum ipipeif_pack_mode {
57 IPIPEIF_PACK_16_BIT = 0,
58 IPIPEIF_PACK_8_BIT = 1,
59};
60
61enum ipipeif_5_1_pack_mode {
62 IPIPEIF_5_1_PACK_16_BIT = 0,
63 IPIPEIF_5_1_PACK_8_BIT = 1,
64 IPIPEIF_5_1_PACK_8_BIT_A_LAW = 2,
65 IPIPEIF_5_1_PACK_12_BIT = 3
66};
67
68enum ipipeif_input_source {
69 IPIPEIF_CCDC = 0,
70 IPIPEIF_SDRAM_RAW = 1,
71 IPIPEIF_CCDC_DARKFM = 2,
72 IPIPEIF_SDRAM_YUV = 3,
73};
74
75enum ipipeif_ialaw {
76 IPIPEIF_ALAW_OFF = 0,
77 IPIPEIF_ALAW_ON = 1,
78};
79
80enum ipipeif_input_src1 {
81 IPIPEIF_SRC1_PARALLEL_PORT = 0,
82 IPIPEIF_SRC1_SDRAM_RAW = 1,
83 IPIPEIF_SRC1_ISIF_DARKFM = 2,
84 IPIPEIF_SRC1_SDRAM_YUV = 3,
85};
86
87enum ipipeif_dfs_dir {
88 IPIPEIF_PORT_MINUS_SDRAM = 0,
89 IPIPEIF_SDRAM_MINUS_PORT = 1,
90};
91
92enum ipipeif_chroma_phase {
93 IPIPEIF_CBCR_Y = 0,
94 IPIPEIF_Y_CBCR = 1,
95};
96
97enum ipipeif_dpcm_type {
98 IPIPEIF_DPCM_8BIT_10BIT = 0,
99 IPIPEIF_DPCM_8BIT_12BIT = 1,
100};
101
102/* data shift for IPIPE 5.1 */
103enum ipipeif_5_1_data_shift {
104 IPIPEIF_5_1_BITS11_0 = 0,
105 IPIPEIF_5_1_BITS10_0 = 1,
106 IPIPEIF_5_1_BITS9_0 = 2,
107 IPIPEIF_5_1_BITS8_0 = 3,
108 IPIPEIF_5_1_BITS7_0 = 4,
109 IPIPEIF_5_1_BITS15_4 = 5,
110};
111
112#define IPIPEIF_PAD_SINK 0
113#define IPIPEIF_PAD_SOURCE 1
114
115#define IPIPEIF_NUM_PADS 2
116
117enum ipipeif_input_entity {
118 IPIPEIF_INPUT_NONE = 0,
119 IPIPEIF_INPUT_ISIF = 1,
120 IPIPEIF_INPUT_MEMORY = 2,
121};
122
123enum ipipeif_output_entity {
124 IPIPEIF_OUTPUT_NONE = 0,
125 IPIPEIF_OUTPUT_IPIPE = 1,
126 IPIPEIF_OUTPUT_RESIZER = 2,
127};
128
129struct vpfe_ipipeif_device {
130 struct v4l2_subdev subdev;
131 struct media_pad pads[IPIPEIF_NUM_PADS];
132 struct v4l2_mbus_framefmt formats[IPIPEIF_NUM_PADS];
133 enum ipipeif_input_entity input;
134 unsigned int output;
135 struct vpfe_video_device video_in;
136 struct v4l2_ctrl_handler ctrls;
137 void *__iomem ipipeif_base_addr;
138 struct ipipeif_params config;
139 int dpcm_predictor;
140 int gain;
141};
142
143/* IPIPEIF Register Offsets from the base address */
144#define IPIPEIF_ENABLE 0x00
145#define IPIPEIF_CFG1 0x04
146#define IPIPEIF_PPLN 0x08
147#define IPIPEIF_LPFR 0x0c
148#define IPIPEIF_HNUM 0x10
149#define IPIPEIF_VNUM 0x14
150#define IPIPEIF_ADDRU 0x18
151#define IPIPEIF_ADDRL 0x1c
152#define IPIPEIF_ADOFS 0x20
153#define IPIPEIF_RSZ 0x24
154#define IPIPEIF_GAIN 0x28
155
156/* Below registers are available only on IPIPE 5.1 */
157#define IPIPEIF_DPCM 0x2c
158#define IPIPEIF_CFG2 0x30
159#define IPIPEIF_INIRSZ 0x34
160#define IPIPEIF_OCLIP 0x38
161#define IPIPEIF_DTUDF 0x3c
162#define IPIPEIF_CLKDIV 0x40
163#define IPIPEIF_DPC1 0x44
164#define IPIPEIF_DPC2 0x48
165#define IPIPEIF_DFSGVL 0x4c
166#define IPIPEIF_DFSGTH 0x50
167#define IPIPEIF_RSZ3A 0x54
168#define IPIPEIF_INIRSZ3A 0x58
169#define IPIPEIF_RSZ_MIN 16
170#define IPIPEIF_RSZ_MAX 112
171#define IPIPEIF_RSZ_CONST 16
172#define SETBIT(reg, bit) (reg = ((reg) | ((0x00000001)<<(bit))))
173#define RESETBIT(reg, bit) (reg = ((reg) & (~(0x00000001<<(bit)))))
174
175#define IPIPEIF_ADOFS_LSB_MASK 0x1ff
176#define IPIPEIF_ADOFS_LSB_SHIFT 5
177#define IPIPEIF_ADOFS_MSB_MASK 0x200
178#define IPIPEIF_ADDRU_MASK 0x7ff
179#define IPIPEIF_ADDRL_SHIFT 5
180#define IPIPEIF_ADDRL_MASK 0xffff
181#define IPIPEIF_ADDRU_SHIFT 21
182#define IPIPEIF_ADDRMSB_SHIFT 31
183#define IPIPEIF_ADDRMSB_LEFT_SHIFT 10
184
185/* CFG1 Masks and shifts */
186#define ONESHOT_SHIFT 0
187#define DECIM_SHIFT 1
188#define INPSRC_SHIFT 2
189#define CLKDIV_SHIFT 4
190#define AVGFILT_SHIFT 7
191#define PACK8IN_SHIFT 8
192#define IALAW_SHIFT 9
193#define CLKSEL_SHIFT 10
194#define DATASFT_SHIFT 11
195#define INPSRC1_SHIFT 14
196
197/* DPC2 */
198#define IPIPEIF_DPC2_EN_SHIFT 12
199#define IPIPEIF_DPC2_THR_MASK 0xfff
200/* Applicable for IPIPE 5.1 */
201#define IPIPEIF_DF_GAIN_EN_SHIFT 10
202#define IPIPEIF_DF_GAIN_MASK 0x3ff
203#define IPIPEIF_DF_GAIN_THR_MASK 0xfff
204/* DPCM */
205#define IPIPEIF_DPCM_BITS_SHIFT 2
206#define IPIPEIF_DPCM_PRED_SHIFT 1
207/* CFG2 */
208#define IPIPEIF_CFG2_HDPOL_SHIFT 1
209#define IPIPEIF_CFG2_VDPOL_SHIFT 2
210#define IPIPEIF_CFG2_YUV8_SHIFT 6
211#define IPIPEIF_CFG2_YUV16_SHIFT 3
212#define IPIPEIF_CFG2_YUV8P_SHIFT 7
213
214/* INIRSZ */
215#define IPIPEIF_INIRSZ_ALNSYNC_SHIFT 13
216#define IPIPEIF_INIRSZ_MASK 0x1fff
217
218/* CLKDIV */
219#define IPIPEIF_CLKDIV_M_SHIFT 8
220
221void vpfe_ipipeif_enable(struct vpfe_device *vpfe_dev);
222void vpfe_ipipeif_ss_buffer_isr(struct vpfe_ipipeif_device *ipipeif);
223int vpfe_ipipeif_decimation_enabled(struct vpfe_device *vpfe_dev);
224int vpfe_ipipeif_get_rsz(struct vpfe_device *vpfe_dev);
225void vpfe_ipipeif_cleanup(struct vpfe_ipipeif_device *ipipeif,
226 struct platform_device *pdev);
227int vpfe_ipipeif_init(struct vpfe_ipipeif_device *ipipeif,
228 struct platform_device *pdev);
229int vpfe_ipipeif_register_entities(struct vpfe_ipipeif_device *ipipeif,
230 struct v4l2_device *vdev);
231void vpfe_ipipeif_unregister_entities(struct vpfe_ipipeif_device *ipipeif);
232
233#endif /* _DAVINCI_VPFE_DM365_IPIPEIF_H */
diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipeif_user.h b/drivers/staging/media/davinci_vpfe/dm365_ipipeif_user.h
new file mode 100644
index 000000000000..e2a69b59554a
--- /dev/null
+++ b/drivers/staging/media/davinci_vpfe/dm365_ipipeif_user.h
@@ -0,0 +1,93 @@
1/*
2 * Copyright (C) 2012 Texas Instruments Inc
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation version 2.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Contributors:
18 * Manjunath Hadli <manjunath.hadli@ti.com>
19 * Prabhakar Lad <prabhakar.lad@ti.com>
20 */
21
22#ifndef _DAVINCI_VPFE_DM365_IPIPEIF_USER_H
23#define _DAVINCI_VPFE_DM365_IPIPEIF_USER_H
24
25/* clockdiv for IPIPE 5.1 */
26struct ipipeif_5_1_clkdiv {
27 unsigned char m;
28 unsigned char n;
29};
30
31enum ipipeif_decimation {
32 IPIPEIF_DECIMATION_OFF,
33 IPIPEIF_DECIMATION_ON
34};
35
36/* DPC at the if for IPIPE 5.1 */
37struct ipipeif_dpc {
38 /* 0 - disable, 1 - enable */
39 unsigned char en;
40 /* threshold */
41 unsigned short thr;
42};
43
44enum ipipeif_clock {
45 IPIPEIF_PIXCEL_CLK,
46 IPIPEIF_SDRAM_CLK
47};
48
49enum ipipeif_avg_filter {
50 IPIPEIF_AVG_OFF,
51 IPIPEIF_AVG_ON
52};
53
54struct ipipeif_5_1 {
55 struct ipipeif_5_1_clkdiv clk_div;
56 /* Defect pixel correction */
57 struct ipipeif_dpc dpc;
58 /* clipped to this value */
59 unsigned short clip;
60 /* Align HSync and VSync to rsz_start */
61 unsigned char align_sync;
62 /* resizer start position */
63 unsigned int rsz_start;
64 /* DF gain enable */
65 unsigned char df_gain_en;
66 /* DF gain value */
67 unsigned short df_gain;
68 /* DF gain threshold value */
69 unsigned short df_gain_thr;
70};
71
72struct ipipeif_params {
73 enum ipipeif_clock clock_select;
74 unsigned int ppln;
75 unsigned int lpfr;
76 unsigned char rsz;
77 enum ipipeif_decimation decimation;
78 enum ipipeif_avg_filter avg_filter;
79 /* IPIPE 5.1 */
80 struct ipipeif_5_1 if_5_1;
81};
82
83/*
84 * Private IOCTL
85 * VIDIOC_VPFE_IPIPEIF_S_CONFIG: Set IPIEIF configuration
86 * VIDIOC_VPFE_IPIPEIF_G_CONFIG: Get IPIEIF configuration
87 */
88#define VIDIOC_VPFE_IPIPEIF_S_CONFIG \
89 _IOWR('I', BASE_VIDIOC_PRIVATE + 1, struct ipipeif_params)
90#define VIDIOC_VPFE_IPIPEIF_G_CONFIG \
91 _IOWR('I', BASE_VIDIOC_PRIVATE + 2, struct ipipeif_params)
92
93#endif /* _DAVINCI_VPFE_DM365_IPIPEIF_USER_H */
diff --git a/drivers/staging/media/davinci_vpfe/dm365_isif.c b/drivers/staging/media/davinci_vpfe/dm365_isif.c
new file mode 100644
index 000000000000..ebeea72e176a
--- /dev/null
+++ b/drivers/staging/media/davinci_vpfe/dm365_isif.c
@@ -0,0 +1,2104 @@
1/*
2 * Copyright (C) 2012 Texas Instruments Inc
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation version 2.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Contributors:
18 * Manjunath Hadli <manjunath.hadli@ti.com>
19 * Prabhakar Lad <prabhakar.lad@ti.com>
20 */
21
22#include "dm365_isif.h"
23#include "vpfe_mc_capture.h"
24
25#define MAX_WIDTH 4096
26#define MAX_HEIGHT 4096
27
28static const unsigned int isif_fmts[] = {
29 V4L2_MBUS_FMT_YUYV8_2X8,
30 V4L2_MBUS_FMT_UYVY8_2X8,
31 V4L2_MBUS_FMT_YUYV8_1X16,
32 V4L2_MBUS_FMT_YUYV10_1X20,
33 V4L2_MBUS_FMT_SGRBG12_1X12,
34 V4L2_MBUS_FMT_SGRBG10_ALAW8_1X8,
35 V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8,
36};
37
38#define ISIF_COLPTN_R_Ye 0x0
39#define ISIF_COLPTN_Gr_Cy 0x1
40#define ISIF_COLPTN_Gb_G 0x2
41#define ISIF_COLPTN_B_Mg 0x3
42
43#define ISIF_CCOLP_CP01_0 0
44#define ISIF_CCOLP_CP03_2 2
45#define ISIF_CCOLP_CP05_4 4
46#define ISIF_CCOLP_CP07_6 6
47#define ISIF_CCOLP_CP11_0 8
48#define ISIF_CCOLP_CP13_2 10
49#define ISIF_CCOLP_CP15_4 12
50#define ISIF_CCOLP_CP17_6 14
51
52static const u32 isif_sgrbg_pattern =
53 ISIF_COLPTN_Gr_Cy << ISIF_CCOLP_CP01_0 |
54 ISIF_COLPTN_R_Ye << ISIF_CCOLP_CP03_2 |
55 ISIF_COLPTN_B_Mg << ISIF_CCOLP_CP05_4 |
56 ISIF_COLPTN_Gb_G << ISIF_CCOLP_CP07_6 |
57 ISIF_COLPTN_Gr_Cy << ISIF_CCOLP_CP11_0 |
58 ISIF_COLPTN_R_Ye << ISIF_CCOLP_CP13_2 |
59 ISIF_COLPTN_B_Mg << ISIF_CCOLP_CP15_4 |
60 ISIF_COLPTN_Gb_G << ISIF_CCOLP_CP17_6;
61
62static const u32 isif_srggb_pattern =
63 ISIF_COLPTN_R_Ye << ISIF_CCOLP_CP01_0 |
64 ISIF_COLPTN_Gr_Cy << ISIF_CCOLP_CP03_2 |
65 ISIF_COLPTN_Gb_G << ISIF_CCOLP_CP05_4 |
66 ISIF_COLPTN_B_Mg << ISIF_CCOLP_CP07_6 |
67 ISIF_COLPTN_R_Ye << ISIF_CCOLP_CP11_0 |
68 ISIF_COLPTN_Gr_Cy << ISIF_CCOLP_CP13_2 |
69 ISIF_COLPTN_Gb_G << ISIF_CCOLP_CP15_4 |
70 ISIF_COLPTN_B_Mg << ISIF_CCOLP_CP17_6;
71
72static inline u32 isif_read(void *__iomem base_addr, u32 offset)
73{
74 return readl(base_addr + offset);
75}
76
77static inline void isif_write(void *__iomem base_addr, u32 val, u32 offset)
78{
79 writel(val, base_addr + offset);
80}
81
82static inline u32 isif_merge(void *__iomem base_addr, u32 mask, u32 val,
83 u32 offset)
84{
85 u32 new_val = (isif_read(base_addr, offset) & ~mask) | (val & mask);
86
87 isif_write(base_addr, new_val, offset);
88
89 return new_val;
90}
91
92static void isif_enable_output_to_sdram(struct vpfe_isif_device *isif, int en)
93{
94 isif_merge(isif->isif_cfg.base_addr, ISIF_SYNCEN_WEN_MASK,
95 en << ISIF_SYNCEN_WEN_SHIFT, SYNCEN);
96}
97
98static inline void
99isif_regw_lin_tbl(struct vpfe_isif_device *isif, u32 val, u32 offset, int i)
100{
101 if (!i)
102 writel(val, isif->isif_cfg.linear_tbl0_addr + offset);
103 else
104 writel(val, isif->isif_cfg.linear_tbl1_addr + offset);
105}
106
107static void isif_disable_all_modules(struct vpfe_isif_device *isif)
108{
109 /* disable BC */
110 isif_write(isif->isif_cfg.base_addr, 0, CLAMPCFG);
111 /* disable vdfc */
112 isif_write(isif->isif_cfg.base_addr, 0, DFCCTL);
113 /* disable CSC */
114 isif_write(isif->isif_cfg.base_addr, 0, CSCCTL);
115 /* disable linearization */
116 isif_write(isif->isif_cfg.base_addr, 0, LINCFG0);
117}
118
119static void isif_enable(struct vpfe_isif_device *isif, int en)
120{
121 if (!en)
122 /* Before disable isif, disable all ISIF modules */
123 isif_disable_all_modules(isif);
124
125 /*
126 * wait for next VD. Assume lowest scan rate is 12 Hz. So
127 * 100 msec delay is good enough
128 */
129 msleep(100);
130 isif_merge(isif->isif_cfg.base_addr, ISIF_SYNCEN_VDHDEN_MASK,
131 en, SYNCEN);
132}
133
134/*
135 * ISIF helper functions
136 */
137
138#define DM365_ISIF_MDFS_OFFSET 15
139#define DM365_ISIF_MDFS_MASK 0x1
140
141/* get field id in isif hardware */
142enum v4l2_field vpfe_isif_get_fid(struct vpfe_device *vpfe_dev)
143{
144 struct vpfe_isif_device *isif = &vpfe_dev->vpfe_isif;
145 u32 field_status;
146
147 field_status = isif_read(isif->isif_cfg.base_addr, MODESET);
148 field_status = (field_status >> DM365_ISIF_MDFS_OFFSET) &
149 DM365_ISIF_MDFS_MASK;
150 return field_status;
151}
152
153static int
154isif_set_pixel_format(struct vpfe_isif_device *isif, unsigned int pixfmt)
155{
156 if (isif->formats[ISIF_PAD_SINK].code == V4L2_MBUS_FMT_SGRBG12_1X12) {
157 if (pixfmt == V4L2_PIX_FMT_SBGGR16)
158 isif->isif_cfg.data_pack = ISIF_PACK_16BIT;
159 else if ((pixfmt == V4L2_PIX_FMT_SGRBG10DPCM8) ||
160 (pixfmt == V4L2_PIX_FMT_SGRBG10ALAW8))
161 isif->isif_cfg.data_pack = ISIF_PACK_8BIT;
162 else
163 return -EINVAL;
164
165 isif->isif_cfg.bayer.pix_fmt = ISIF_PIXFMT_RAW;
166 isif->isif_cfg.bayer.v4l2_pix_fmt = pixfmt;
167 } else {
168 if (pixfmt == V4L2_PIX_FMT_YUYV)
169 isif->isif_cfg.ycbcr.pix_order = ISIF_PIXORDER_YCBYCR;
170 else if (pixfmt == V4L2_PIX_FMT_UYVY)
171 isif->isif_cfg.ycbcr.pix_order = ISIF_PIXORDER_CBYCRY;
172 else
173 return -EINVAL;
174
175 isif->isif_cfg.data_pack = ISIF_PACK_8BIT;
176 isif->isif_cfg.ycbcr.v4l2_pix_fmt = pixfmt;
177 }
178
179 return 0;
180}
181
182static int
183isif_set_frame_format(struct vpfe_isif_device *isif,
184 enum isif_frmfmt frm_fmt)
185{
186 if (isif->formats[ISIF_PAD_SINK].code == V4L2_MBUS_FMT_SGRBG12_1X12)
187 isif->isif_cfg.bayer.frm_fmt = frm_fmt;
188 else
189 isif->isif_cfg.ycbcr.frm_fmt = frm_fmt;
190
191 return 0;
192}
193
194static int isif_set_image_window(struct vpfe_isif_device *isif)
195{
196 struct v4l2_rect *win = &isif->crop;
197
198 if (isif->formats[ISIF_PAD_SINK].code == V4L2_MBUS_FMT_SGRBG12_1X12) {
199 isif->isif_cfg.bayer.win.top = win->top;
200 isif->isif_cfg.bayer.win.left = win->left;
201 isif->isif_cfg.bayer.win.width = win->width;
202 isif->isif_cfg.bayer.win.height = win->height;
203 return 0;
204 }
205 isif->isif_cfg.ycbcr.win.top = win->top;
206 isif->isif_cfg.ycbcr.win.left = win->left;
207 isif->isif_cfg.ycbcr.win.width = win->width;
208 isif->isif_cfg.ycbcr.win.height = win->height;
209
210 return 0;
211}
212
213static int
214isif_set_buftype(struct vpfe_isif_device *isif, enum isif_buftype buf_type)
215{
216 if (isif->formats[ISIF_PAD_SINK].code == V4L2_MBUS_FMT_SGRBG12_1X12)
217 isif->isif_cfg.bayer.buf_type = buf_type;
218 else
219 isif->isif_cfg.ycbcr.buf_type = buf_type;
220
221 return 0;
222}
223
224/* configure format in isif hardware */
225static int
226isif_config_format(struct vpfe_device *vpfe_dev, unsigned int pad)
227{
228 struct vpfe_isif_device *vpfe_isif = &vpfe_dev->vpfe_isif;
229 enum isif_frmfmt frm_fmt = ISIF_FRMFMT_INTERLACED;
230 struct v4l2_pix_format format;
231 int ret = 0;
232
233 v4l2_fill_pix_format(&format, &vpfe_dev->vpfe_isif.formats[pad]);
234 mbus_to_pix(&vpfe_dev->vpfe_isif.formats[pad], &format);
235
236 if (isif_set_pixel_format(vpfe_isif, format.pixelformat) < 0) {
237 v4l2_err(&vpfe_dev->v4l2_dev,
238 "Failed to set pixel format in isif\n");
239 return -EINVAL;
240 }
241
242 /* call for s_crop will override these values */
243 vpfe_isif->crop.left = 0;
244 vpfe_isif->crop.top = 0;
245 vpfe_isif->crop.width = format.width;
246 vpfe_isif->crop.height = format.height;
247
248 /* configure the image window */
249 isif_set_image_window(vpfe_isif);
250
251 switch (vpfe_dev->vpfe_isif.formats[pad].field) {
252 case V4L2_FIELD_INTERLACED:
253 /* do nothing, since it is default */
254 ret = isif_set_buftype(vpfe_isif, ISIF_BUFTYPE_FLD_INTERLEAVED);
255 break;
256
257 case V4L2_FIELD_NONE:
258 frm_fmt = ISIF_FRMFMT_PROGRESSIVE;
259 /* buffer type only applicable for interlaced scan */
260 break;
261
262 case V4L2_FIELD_SEQ_TB:
263 ret = isif_set_buftype(vpfe_isif, ISIF_BUFTYPE_FLD_SEPARATED);
264 break;
265
266 default:
267 return -EINVAL;
268 }
269
270 /* set the frame format */
271 if (!ret)
272 ret = isif_set_frame_format(vpfe_isif, frm_fmt);
273
274 return ret;
275}
276
277/*
278 * isif_try_format() - Try video format on a pad
279 * @isif: VPFE isif device
280 * @fh: V4L2 subdev file handle
281 * @fmt: pointer to v4l2 subdev format structure
282 */
283static void
284isif_try_format(struct vpfe_isif_device *isif, struct v4l2_subdev_fh *fh,
285 struct v4l2_subdev_format *fmt)
286{
287 unsigned int width = fmt->format.width;
288 unsigned int height = fmt->format.height;
289 unsigned int i;
290
291 for (i = 0; i < ARRAY_SIZE(isif_fmts); i++) {
292 if (fmt->format.code == isif_fmts[i])
293 break;
294 }
295
296 /* If not found, use YUYV8_2x8 as default */
297 if (i >= ARRAY_SIZE(isif_fmts))
298 fmt->format.code = V4L2_MBUS_FMT_YUYV8_2X8;
299
300 /* Clamp the size. */
301 fmt->format.width = clamp_t(u32, width, 32, MAX_WIDTH);
302 fmt->format.height = clamp_t(u32, height, 32, MAX_HEIGHT);
303
304 /* The data formatter truncates the number of horizontal output
305 * pixels to a multiple of 16. To avoid clipping data, allow
306 * callers to request an output size bigger than the input size
307 * up to the nearest multiple of 16.
308 */
309 if (fmt->pad == ISIF_PAD_SOURCE)
310 fmt->format.width &= ~15;
311}
312
313/*
314 * vpfe_isif_buffer_isr() - isif module non-progressive buffer scheduling isr
315 * @isif: Pointer to isif subdevice.
316 */
317void vpfe_isif_buffer_isr(struct vpfe_isif_device *isif)
318{
319 struct vpfe_device *vpfe_dev = to_vpfe_device(isif);
320 struct vpfe_video_device *video = &isif->video_out;
321 enum v4l2_field field;
322 int fid;
323
324 if (!video->started)
325 return;
326
327 field = video->fmt.fmt.pix.field;
328
329 if (field == V4L2_FIELD_NONE) {
330 /* handle progressive frame capture */
331 if (video->cur_frm != video->next_frm)
332 vpfe_video_process_buffer_complete(video);
333 return;
334 }
335
336 /* interlaced or TB capture check which field we
337 * are in hardware
338 */
339 fid = vpfe_isif_get_fid(vpfe_dev);
340
341 /* switch the software maintained field id */
342 video->field_id ^= 1;
343 if (fid == video->field_id) {
344 /* we are in-sync here,continue */
345 if (fid == 0) {
346 /*
347 * One frame is just being captured. If the
348 * next frame is available, release the current
349 * frame and move on
350 */
351 if (video->cur_frm != video->next_frm)
352 vpfe_video_process_buffer_complete(video);
353 /*
354 * based on whether the two fields are stored
355 * interleavely or separately in memory,
356 * reconfigure the ISIF memory address
357 */
358 if (field == V4L2_FIELD_SEQ_TB)
359 vpfe_video_schedule_bottom_field(video);
360 return;
361 }
362 /*
363 * if one field is just being captured configure
364 * the next frame get the next frame from the
365 * empty queue if no frame is available hold on
366 * to the current buffer
367 */
368 spin_lock(&video->dma_queue_lock);
369 if (!list_empty(&video->dma_queue) &&
370 video->cur_frm == video->next_frm)
371 vpfe_video_schedule_next_buffer(video);
372 spin_unlock(&video->dma_queue_lock);
373 } else if (fid == 0) {
374 /*
375 * out of sync. Recover from any hardware out-of-sync.
376 * May loose one frame
377 */
378 video->field_id = fid;
379 }
380}
381
382/*
383 * vpfe_isif_vidint1_isr() - ISIF module progressive buffer scheduling isr
384 * @isif: Pointer to isif subdevice.
385 */
386void vpfe_isif_vidint1_isr(struct vpfe_isif_device *isif)
387{
388 struct vpfe_video_device *video = &isif->video_out;
389
390 if (!video->started)
391 return;
392
393 spin_lock(&video->dma_queue_lock);
394 if (video->fmt.fmt.pix.field == V4L2_FIELD_NONE &&
395 !list_empty(&video->dma_queue) && video->cur_frm == video->next_frm)
396 vpfe_video_schedule_next_buffer(video);
397
398 spin_unlock(&video->dma_queue_lock);
399}
400
401/*
402 * VPFE video operations
403 */
404
405static int isif_video_queue(struct vpfe_device *vpfe_dev, unsigned long addr)
406{
407 struct vpfe_isif_device *isif = &vpfe_dev->vpfe_isif;
408
409 isif_write(isif->isif_cfg.base_addr, (addr >> 21) &
410 ISIF_CADU_BITS, CADU);
411 isif_write(isif->isif_cfg.base_addr, (addr >> 5) &
412 ISIF_CADL_BITS, CADL);
413
414 return 0;
415}
416
417static const struct vpfe_video_operations isif_video_ops = {
418 .queue = isif_video_queue,
419};
420
421/*
422 * V4L2 subdev operations
423 */
424
425/* Parameter operations */
426static int isif_get_params(struct v4l2_subdev *sd, void *params)
427{
428 struct vpfe_isif_device *isif = v4l2_get_subdevdata(sd);
429
430 /* only raw module parameters can be set through the IOCTL */
431 if (isif->formats[ISIF_PAD_SINK].code != V4L2_MBUS_FMT_SGRBG12_1X12)
432 return -EINVAL;
433 memcpy(params, &isif->isif_cfg.bayer.config_params,
434 sizeof(isif->isif_cfg.bayer.config_params));
435 return 0;
436}
437
438static int isif_validate_df_csc_params(struct vpfe_isif_df_csc *df_csc)
439{
440 struct vpfe_isif_color_space_conv *csc;
441 int err = -EINVAL;
442 int csc_df_en;
443 int i;
444
445 if (!df_csc->df_or_csc) {
446 /* csc configuration */
447 csc = &df_csc->csc;
448 if (csc->en) {
449 csc_df_en = 1;
450 for (i = 0; i < VPFE_ISIF_CSC_NUM_COEFF; i++)
451 if (csc->coeff[i].integer >
452 ISIF_CSC_COEF_INTEG_MASK ||
453 csc->coeff[i].decimal >
454 ISIF_CSC_COEF_DECIMAL_MASK) {
455 pr_err("Invalid CSC coefficients\n");
456 return err;
457 }
458 }
459 }
460 if (df_csc->start_pix > ISIF_DF_CSC_SPH_MASK) {
461 pr_err("Invalid df_csc start pix value\n");
462 return err;
463 }
464
465 if (df_csc->num_pixels > ISIF_DF_NUMPIX) {
466 pr_err("Invalid df_csc num pixels value\n");
467 return err;
468 }
469
470 if (df_csc->start_line > ISIF_DF_CSC_LNH_MASK) {
471 pr_err("Invalid df_csc start_line value\n");
472 return err;
473 }
474
475 if (df_csc->num_lines > ISIF_DF_NUMLINES) {
476 pr_err("Invalid df_csc num_lines value\n");
477 return err;
478 }
479
480 return 0;
481}
482
483#define DM365_ISIF_MAX_VDFLSFT 4
484#define DM365_ISIF_MAX_VDFSLV 4095
485#define DM365_ISIF_MAX_DFCMEM0 0x1fff
486#define DM365_ISIF_MAX_DFCMEM1 0x1fff
487
488static int isif_validate_dfc_params(struct vpfe_isif_dfc *dfc)
489{
490 int err = -EINVAL;
491 int i;
492
493 if (!dfc->en)
494 return 0;
495
496 if (dfc->corr_whole_line > 1) {
497 pr_err("Invalid corr_whole_line value\n");
498 return err;
499 }
500
501 if (dfc->def_level_shift > DM365_ISIF_MAX_VDFLSFT) {
502 pr_err("Invalid def_level_shift value\n");
503 return err;
504 }
505
506 if (dfc->def_sat_level > DM365_ISIF_MAX_VDFSLV) {
507 pr_err("Invalid def_sat_level value\n");
508 return err;
509 }
510
511 if (!dfc->num_vdefects ||
512 dfc->num_vdefects > VPFE_ISIF_VDFC_TABLE_SIZE) {
513 pr_err("Invalid num_vdefects value\n");
514 return err;
515 }
516
517 for (i = 0; i < VPFE_ISIF_VDFC_TABLE_SIZE; i++) {
518 if (dfc->table[i].pos_vert > DM365_ISIF_MAX_DFCMEM0) {
519 pr_err("Invalid pos_vert value\n");
520 return err;
521 }
522 if (dfc->table[i].pos_horz > DM365_ISIF_MAX_DFCMEM1) {
523 pr_err("Invalid pos_horz value\n");
524 return err;
525 }
526 }
527
528 return 0;
529}
530
531#define DM365_ISIF_MAX_CLVRV 0xfff
532#define DM365_ISIF_MAX_CLDC 0x1fff
533#define DM365_ISIF_MAX_CLHSH 0x1fff
534#define DM365_ISIF_MAX_CLHSV 0x1fff
535#define DM365_ISIF_MAX_CLVSH 0x1fff
536#define DM365_ISIF_MAX_CLVSV 0x1fff
537#define DM365_ISIF_MAX_HEIGHT_BLACK_REGION 0x1fff
538
539static int isif_validate_bclamp_params(struct vpfe_isif_black_clamp *bclamp)
540{
541 int err = -EINVAL;
542
543 if (bclamp->dc_offset > DM365_ISIF_MAX_CLDC) {
544 pr_err("Invalid bclamp dc_offset value\n");
545 return err;
546 }
547 if (!bclamp->en)
548 return 0;
549 if (bclamp->horz.clamp_pix_limit > 1) {
550 pr_err("Invalid bclamp horz clamp_pix_limit value\n");
551 return err;
552 }
553 if (bclamp->horz.win_count_calc < 1 ||
554 bclamp->horz.win_count_calc > 32) {
555 pr_err("Invalid bclamp horz win_count_calc value\n");
556 return err;
557 }
558 if (bclamp->horz.win_start_h_calc > DM365_ISIF_MAX_CLHSH) {
559 pr_err("Invalid bclamp win_start_v_calc value\n");
560 return err;
561 }
562
563 if (bclamp->horz.win_start_v_calc > DM365_ISIF_MAX_CLHSV) {
564 pr_err("Invalid bclamp win_start_v_calc value\n");
565 return err;
566 }
567 if (bclamp->vert.reset_clamp_val > DM365_ISIF_MAX_CLVRV) {
568 pr_err("Invalid bclamp reset_clamp_val value\n");
569 return err;
570 }
571 if (bclamp->vert.ob_v_sz_calc > DM365_ISIF_MAX_HEIGHT_BLACK_REGION) {
572 pr_err("Invalid bclamp ob_v_sz_calc value\n");
573 return err;
574 }
575 if (bclamp->vert.ob_start_h > DM365_ISIF_MAX_CLVSH) {
576 pr_err("Invalid bclamp ob_start_h value\n");
577 return err;
578 }
579 if (bclamp->vert.ob_start_v > DM365_ISIF_MAX_CLVSV) {
580 pr_err("Invalid bclamp ob_start_h value\n");
581 return err;
582 }
583 return 0;
584}
585
586static int
587isif_validate_raw_params(struct vpfe_isif_raw_config *params)
588{
589 int ret;
590
591 ret = isif_validate_df_csc_params(&params->df_csc);
592 if (ret)
593 return ret;
594 ret = isif_validate_dfc_params(&params->dfc);
595 if (ret)
596 return ret;
597 ret = isif_validate_bclamp_params(&params->bclamp);
598 return ret;
599}
600
601static int isif_set_params(struct v4l2_subdev *sd, void *params)
602{
603 struct vpfe_isif_device *isif = v4l2_get_subdevdata(sd);
604 struct vpfe_isif_raw_config isif_raw_params;
605 int ret = -EINVAL;
606
607 /* only raw module parameters can be set through the IOCTL */
608 if (isif->formats[ISIF_PAD_SINK].code != V4L2_MBUS_FMT_SGRBG12_1X12)
609 return ret;
610
611 memcpy(&isif_raw_params, params, sizeof(isif_raw_params));
612 if (!isif_validate_raw_params(&isif_raw_params)) {
613 memcpy(&isif->isif_cfg.bayer.config_params, &isif_raw_params,
614 sizeof(isif_raw_params));
615 ret = 0;
616 }
617 return ret;
618}
619/*
620 * isif_ioctl() - isif module private ioctl's
621 * @sd: VPFE isif V4L2 subdevice
622 * @cmd: ioctl command
623 * @arg: ioctl argument
624 *
625 * Return 0 on success or a negative error code otherwise.
626 */
627static long isif_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
628{
629 int ret;
630
631 switch (cmd) {
632 case VIDIOC_VPFE_ISIF_S_RAW_PARAMS:
633 ret = isif_set_params(sd, arg);
634 break;
635
636 case VIDIOC_VPFE_ISIF_G_RAW_PARAMS:
637 ret = isif_get_params(sd, arg);
638 break;
639
640 default:
641 ret = -ENOIOCTLCMD;
642 }
643 return ret;
644}
645
646static void isif_config_gain_offset(struct vpfe_isif_device *isif)
647{
648 struct vpfe_isif_gain_offsets_adj *gain_off_ptr =
649 &isif->isif_cfg.bayer.config_params.gain_offset;
650 void *__iomem base = isif->isif_cfg.base_addr;
651 u32 val;
652
653 val = ((gain_off_ptr->gain_sdram_en & 1) << GAIN_SDRAM_EN_SHIFT) |
654 ((gain_off_ptr->gain_ipipe_en & 1) << GAIN_IPIPE_EN_SHIFT) |
655 ((gain_off_ptr->gain_h3a_en & 1) << GAIN_H3A_EN_SHIFT) |
656 ((gain_off_ptr->offset_sdram_en & 1) << OFST_SDRAM_EN_SHIFT) |
657 ((gain_off_ptr->offset_ipipe_en & 1) << OFST_IPIPE_EN_SHIFT) |
658 ((gain_off_ptr->offset_h3a_en & 1) << OFST_H3A_EN_SHIFT);
659 isif_merge(base, GAIN_OFFSET_EN_MASK, val, CGAMMAWD);
660
661 isif_write(base, isif->isif_cfg.isif_gain_params.cr_gain, CRGAIN);
662 isif_write(base, isif->isif_cfg.isif_gain_params.cgr_gain, CGRGAIN);
663 isif_write(base, isif->isif_cfg.isif_gain_params.cgb_gain, CGBGAIN);
664 isif_write(base, isif->isif_cfg.isif_gain_params.cb_gain, CBGAIN);
665 isif_write(base, isif->isif_cfg.isif_gain_params.offset & OFFSET_MASK,
666 COFSTA);
667
668}
669
670static void isif_config_bclamp(struct vpfe_isif_device *isif,
671 struct vpfe_isif_black_clamp *bc)
672{
673 u32 val;
674
675 /**
676 * DC Offset is always added to image data irrespective of bc enable
677 * status
678 */
679 val = bc->dc_offset & ISIF_BC_DCOFFSET_MASK;
680 isif_write(isif->isif_cfg.base_addr, val, CLDCOFST);
681
682 if (!bc->en)
683 return;
684
685 val = (bc->bc_mode_color & ISIF_BC_MODE_COLOR_MASK) <<
686 ISIF_BC_MODE_COLOR_SHIFT;
687
688 /* Enable BC and horizontal clamp caculation paramaters */
689 val = val | 1 | ((bc->horz.mode & ISIF_HORZ_BC_MODE_MASK) <<
690 ISIF_HORZ_BC_MODE_SHIFT);
691
692 isif_write(isif->isif_cfg.base_addr, val, CLAMPCFG);
693
694 if (bc->horz.mode != VPFE_ISIF_HORZ_BC_DISABLE) {
695 /*
696 * Window count for calculation
697 * Base window selection
698 * pixel limit
699 * Horizontal size of window
700 * vertical size of the window
701 * Horizontal start position of the window
702 * Vertical start position of the window
703 */
704 val = (bc->horz.win_count_calc & ISIF_HORZ_BC_WIN_COUNT_MASK) |
705 ((bc->horz.base_win_sel_calc & 1) <<
706 ISIF_HORZ_BC_WIN_SEL_SHIFT) |
707 ((bc->horz.clamp_pix_limit & 1) <<
708 ISIF_HORZ_BC_PIX_LIMIT_SHIFT) |
709 ((bc->horz.win_h_sz_calc &
710 ISIF_HORZ_BC_WIN_H_SIZE_MASK) <<
711 ISIF_HORZ_BC_WIN_H_SIZE_SHIFT) |
712 ((bc->horz.win_v_sz_calc &
713 ISIF_HORZ_BC_WIN_V_SIZE_MASK) <<
714 ISIF_HORZ_BC_WIN_V_SIZE_SHIFT);
715
716 isif_write(isif->isif_cfg.base_addr, val, CLHWIN0);
717
718 val = bc->horz.win_start_h_calc & ISIF_HORZ_BC_WIN_START_H_MASK;
719 isif_write(isif->isif_cfg.base_addr, val, CLHWIN1);
720
721 val = bc->horz.win_start_v_calc & ISIF_HORZ_BC_WIN_START_V_MASK;
722 isif_write(isif->isif_cfg.base_addr, val, CLHWIN2);
723 }
724
725 /* vertical clamp caculation paramaters */
726 /* OB H Valid */
727 val = bc->vert.ob_h_sz_calc & ISIF_VERT_BC_OB_H_SZ_MASK;
728
729 /* Reset clamp value sel for previous line */
730 val |= (bc->vert.reset_val_sel & ISIF_VERT_BC_RST_VAL_SEL_MASK) <<
731 ISIF_VERT_BC_RST_VAL_SEL_SHIFT;
732
733 /* Line average coefficient */
734 val |= bc->vert.line_ave_coef << ISIF_VERT_BC_LINE_AVE_COEF_SHIFT;
735 isif_write(isif->isif_cfg.base_addr, val, CLVWIN0);
736
737 /* Configured reset value */
738 if (bc->vert.reset_val_sel == VPFE_ISIF_VERT_BC_USE_CONFIG_CLAMP_VAL) {
739 val = bc->vert.reset_clamp_val & ISIF_VERT_BC_RST_VAL_MASK;
740 isif_write(isif->isif_cfg.base_addr, val, CLVRV);
741 }
742
743 /* Optical Black horizontal start position */
744 val = bc->vert.ob_start_h & ISIF_VERT_BC_OB_START_HORZ_MASK;
745 isif_write(isif->isif_cfg.base_addr, val, CLVWIN1);
746
747 /* Optical Black vertical start position */
748 val = bc->vert.ob_start_v & ISIF_VERT_BC_OB_START_VERT_MASK;
749 isif_write(isif->isif_cfg.base_addr, val, CLVWIN2);
750
751 val = bc->vert.ob_v_sz_calc & ISIF_VERT_BC_OB_VERT_SZ_MASK;
752 isif_write(isif->isif_cfg.base_addr, val, CLVWIN3);
753
754 /* Vertical start position for BC subtraction */
755 val = bc->vert_start_sub & ISIF_BC_VERT_START_SUB_V_MASK;
756 isif_write(isif->isif_cfg.base_addr, val, CLSV);
757}
758
759/* This function will configure the window size to be capture in ISIF reg */
760static void
761isif_setwin(struct vpfe_isif_device *isif, struct v4l2_rect *image_win,
762 enum isif_frmfmt frm_fmt, int ppc, int mode)
763{
764 int horz_nr_pixels;
765 int vert_nr_lines;
766 int horz_start;
767 int vert_start;
768 int mid_img;
769
770 /*
771 * ppc - per pixel count. indicates how many pixels per cell
772 * output to SDRAM. example, for ycbcr, it is one y and one c, so 2.
773 * raw capture this is 1
774 */
775 horz_start = image_win->left << (ppc - 1);
776 horz_nr_pixels = (image_win->width << (ppc - 1)) - 1;
777
778 /* Writing the horizontal info into the registers */
779 isif_write(isif->isif_cfg.base_addr,
780 horz_start & START_PX_HOR_MASK, SPH);
781 isif_write(isif->isif_cfg.base_addr,
782 horz_nr_pixels & NUM_PX_HOR_MASK, LNH);
783 vert_start = image_win->top;
784
785 if (frm_fmt == ISIF_FRMFMT_INTERLACED) {
786 vert_nr_lines = (image_win->height >> 1) - 1;
787 vert_start >>= 1;
788 /* To account for VD since line 0 doesn't have any data */
789 vert_start += 1;
790 } else {
791 /* To account for VD since line 0 doesn't have any data */
792 vert_start += 1;
793 vert_nr_lines = image_win->height - 1;
794 /* configure VDINT0 and VDINT1 */
795 mid_img = vert_start + (image_win->height / 2);
796 isif_write(isif->isif_cfg.base_addr, mid_img, VDINT1);
797 }
798
799 if (!mode)
800 isif_write(isif->isif_cfg.base_addr, 0, VDINT0);
801 else
802 isif_write(isif->isif_cfg.base_addr, vert_nr_lines, VDINT0);
803 isif_write(isif->isif_cfg.base_addr,
804 vert_start & START_VER_ONE_MASK, SLV0);
805 isif_write(isif->isif_cfg.base_addr,
806 vert_start & START_VER_TWO_MASK, SLV1);
807 isif_write(isif->isif_cfg.base_addr,
808 vert_nr_lines & NUM_LINES_VER, LNV);
809}
810
811#define DM365_ISIF_DFCMWR_MEMORY_WRITE 1
812#define DM365_ISIF_DFCMRD_MEMORY_READ 0x2
813
814static void
815isif_config_dfc(struct vpfe_isif_device *isif, struct vpfe_isif_dfc *vdfc)
816{
817#define DFC_WRITE_WAIT_COUNT 1000
818 u32 count = DFC_WRITE_WAIT_COUNT;
819 u32 val;
820 int i;
821
822 if (!vdfc->en)
823 return;
824
825 /* Correction mode */
826 val = (vdfc->corr_mode & ISIF_VDFC_CORR_MOD_MASK) <<
827 ISIF_VDFC_CORR_MOD_SHIFT;
828
829 /* Correct whole line or partial */
830 if (vdfc->corr_whole_line)
831 val |= 1 << ISIF_VDFC_CORR_WHOLE_LN_SHIFT;
832
833 /* level shift value */
834 val |= (vdfc->def_level_shift & ISIF_VDFC_LEVEL_SHFT_MASK) <<
835 ISIF_VDFC_LEVEL_SHFT_SHIFT;
836
837 isif_write(isif->isif_cfg.base_addr, val, DFCCTL);
838
839 /* Defect saturation level */
840 val = vdfc->def_sat_level & ISIF_VDFC_SAT_LEVEL_MASK;
841 isif_write(isif->isif_cfg.base_addr, val, VDFSATLV);
842
843 isif_write(isif->isif_cfg.base_addr, vdfc->table[0].pos_vert &
844 ISIF_VDFC_POS_MASK, DFCMEM0);
845 isif_write(isif->isif_cfg.base_addr, vdfc->table[0].pos_horz &
846 ISIF_VDFC_POS_MASK, DFCMEM1);
847 if (vdfc->corr_mode == VPFE_ISIF_VDFC_NORMAL ||
848 vdfc->corr_mode == VPFE_ISIF_VDFC_HORZ_INTERPOL_IF_SAT) {
849 isif_write(isif->isif_cfg.base_addr,
850 vdfc->table[0].level_at_pos, DFCMEM2);
851 isif_write(isif->isif_cfg.base_addr,
852 vdfc->table[0].level_up_pixels, DFCMEM3);
853 isif_write(isif->isif_cfg.base_addr,
854 vdfc->table[0].level_low_pixels, DFCMEM4);
855 }
856
857 val = isif_read(isif->isif_cfg.base_addr, DFCMEMCTL);
858 /* set DFCMARST and set DFCMWR */
859 val |= 1 << ISIF_DFCMEMCTL_DFCMARST_SHIFT;
860 val |= 1;
861 isif_write(isif->isif_cfg.base_addr, val, DFCMEMCTL);
862
863 while (count && (isif_read(isif->isif_cfg.base_addr, DFCMEMCTL) & 0x01))
864 count--;
865
866 val = isif_read(isif->isif_cfg.base_addr, DFCMEMCTL);
867 if (!count) {
868 pr_debug("defect table write timeout !!\n");
869 return;
870 }
871
872 for (i = 1; i < vdfc->num_vdefects; i++) {
873 isif_write(isif->isif_cfg.base_addr, vdfc->table[i].pos_vert &
874 ISIF_VDFC_POS_MASK, DFCMEM0);
875
876 isif_write(isif->isif_cfg.base_addr, vdfc->table[i].pos_horz &
877 ISIF_VDFC_POS_MASK, DFCMEM1);
878
879 if (vdfc->corr_mode == VPFE_ISIF_VDFC_NORMAL ||
880 vdfc->corr_mode == VPFE_ISIF_VDFC_HORZ_INTERPOL_IF_SAT) {
881 isif_write(isif->isif_cfg.base_addr,
882 vdfc->table[i].level_at_pos, DFCMEM2);
883 isif_write(isif->isif_cfg.base_addr,
884 vdfc->table[i].level_up_pixels, DFCMEM3);
885 isif_write(isif->isif_cfg.base_addr,
886 vdfc->table[i].level_low_pixels, DFCMEM4);
887 }
888 val = isif_read(isif->isif_cfg.base_addr, DFCMEMCTL);
889 /* clear DFCMARST and set DFCMWR */
890 val &= ~(1 << ISIF_DFCMEMCTL_DFCMARST_SHIFT);
891 val |= 1;
892 isif_write(isif->isif_cfg.base_addr, val, DFCMEMCTL);
893
894 count = DFC_WRITE_WAIT_COUNT;
895 while (count && (isif_read(isif->isif_cfg.base_addr,
896 DFCMEMCTL) & 0x01))
897 count--;
898
899 val = isif_read(isif->isif_cfg.base_addr, DFCMEMCTL);
900 if (!count) {
901 pr_debug("defect table write timeout !!\n");
902 return;
903 }
904 }
905 if (vdfc->num_vdefects < VPFE_ISIF_VDFC_TABLE_SIZE) {
906 /* Extra cycle needed */
907 isif_write(isif->isif_cfg.base_addr, 0, DFCMEM0);
908 isif_write(isif->isif_cfg.base_addr,
909 DM365_ISIF_MAX_DFCMEM1, DFCMEM1);
910 isif_write(isif->isif_cfg.base_addr,
911 DM365_ISIF_DFCMWR_MEMORY_WRITE, DFCMEMCTL);
912 }
913 /* enable VDFC */
914 isif_merge(isif->isif_cfg.base_addr, (1 << ISIF_VDFC_EN_SHIFT),
915 (1 << ISIF_VDFC_EN_SHIFT), DFCCTL);
916
917 isif_merge(isif->isif_cfg.base_addr, (1 << ISIF_VDFC_EN_SHIFT),
918 (0 << ISIF_VDFC_EN_SHIFT), DFCCTL);
919
920 isif_write(isif->isif_cfg.base_addr, 0x6, DFCMEMCTL);
921 for (i = 0 ; i < vdfc->num_vdefects; i++) {
922 count = DFC_WRITE_WAIT_COUNT;
923 while (count &&
924 (isif_read(isif->isif_cfg.base_addr, DFCMEMCTL) & 0x2))
925 count--;
926 val = isif_read(isif->isif_cfg.base_addr, DFCMEMCTL);
927 if (!count) {
928 pr_debug("defect table write timeout !!\n");
929 return;
930 }
931 isif_write(isif->isif_cfg.base_addr,
932 DM365_ISIF_DFCMRD_MEMORY_READ, DFCMEMCTL);
933 }
934}
935
936static void
937isif_config_csc(struct vpfe_isif_device *isif, struct vpfe_isif_df_csc *df_csc)
938{
939 u32 val1;
940 u32 val2;
941 u32 i;
942
943 if (!df_csc->csc.en) {
944 isif_write(isif->isif_cfg.base_addr, 0, CSCCTL);
945 return;
946 }
947 /* initialize all bits to 0 */
948 val1 = 0;
949 for (i = 0; i < VPFE_ISIF_CSC_NUM_COEFF; i++) {
950 if ((i % 2) == 0) {
951 /* CSCM - LSB */
952 val1 = ((df_csc->csc.coeff[i].integer &
953 ISIF_CSC_COEF_INTEG_MASK) <<
954 ISIF_CSC_COEF_INTEG_SHIFT) |
955 ((df_csc->csc.coeff[i].decimal &
956 ISIF_CSC_COEF_DECIMAL_MASK));
957 } else {
958
959 /* CSCM - MSB */
960 val2 = ((df_csc->csc.coeff[i].integer &
961 ISIF_CSC_COEF_INTEG_MASK) <<
962 ISIF_CSC_COEF_INTEG_SHIFT) |
963 ((df_csc->csc.coeff[i].decimal &
964 ISIF_CSC_COEF_DECIMAL_MASK));
965 val2 <<= ISIF_CSCM_MSB_SHIFT;
966 val2 |= val1;
967 isif_write(isif->isif_cfg.base_addr, val2,
968 (CSCM0 + ((i-1) << 1)));
969 }
970 }
971 /* program the active area */
972 isif_write(isif->isif_cfg.base_addr, df_csc->start_pix &
973 ISIF_DF_CSC_SPH_MASK, FMTSPH);
974 /*
975 * one extra pixel as required for CSC. Actually number of
976 * pixel - 1 should be configured in this register. So we
977 * need to subtract 1 before writing to FMTSPH, but we will
978 * not do this since csc requires one extra pixel
979 */
980 isif_write(isif->isif_cfg.base_addr, df_csc->num_pixels &
981 ISIF_DF_CSC_SPH_MASK, FMTLNH);
982 isif_write(isif->isif_cfg.base_addr, df_csc->start_line &
983 ISIF_DF_CSC_SPH_MASK, FMTSLV);
984 /*
985 * one extra line as required for CSC. See reason documented for
986 * num_pixels
987 */
988 isif_write(isif->isif_cfg.base_addr, df_csc->num_lines &
989 ISIF_DF_CSC_SPH_MASK, FMTLNV);
990 /* Enable CSC */
991 isif_write(isif->isif_cfg.base_addr, 1, CSCCTL);
992}
993
994static void
995isif_config_linearization(struct vpfe_isif_device *isif,
996 struct vpfe_isif_linearize *linearize)
997{
998 u32 val;
999 u32 i;
1000
1001 if (!linearize->en) {
1002 isif_write(isif->isif_cfg.base_addr, 0, LINCFG0);
1003 return;
1004 }
1005 /* shift value for correction */
1006 val = (linearize->corr_shft & ISIF_LIN_CORRSFT_MASK) <<
1007 ISIF_LIN_CORRSFT_SHIFT;
1008 /* enable */
1009 val |= 1;
1010 isif_write(isif->isif_cfg.base_addr, val, LINCFG0);
1011 /* Scale factor */
1012 val = (linearize->scale_fact.integer & 1) <<
1013 ISIF_LIN_SCALE_FACT_INTEG_SHIFT;
1014 val |= linearize->scale_fact.decimal & ISIF_LIN_SCALE_FACT_DECIMAL_MASK;
1015 isif_write(isif->isif_cfg.base_addr, val, LINCFG1);
1016
1017 for (i = 0; i < VPFE_ISIF_LINEAR_TAB_SIZE; i++) {
1018 val = linearize->table[i] & ISIF_LIN_ENTRY_MASK;
1019 if (i%2)
1020 isif_regw_lin_tbl(isif, val, ((i >> 1) << 2), 1);
1021 else
1022 isif_regw_lin_tbl(isif, val, ((i >> 1) << 2), 0);
1023 }
1024}
1025
1026static void
1027isif_config_culling(struct vpfe_isif_device *isif, struct vpfe_isif_cul *cul)
1028{
1029 u32 val;
1030
1031 /* Horizontal pattern */
1032 val = cul->hcpat_even << CULL_PAT_EVEN_LINE_SHIFT;
1033 val |= cul->hcpat_odd;
1034 isif_write(isif->isif_cfg.base_addr, val, CULH);
1035 /* vertical pattern */
1036 isif_write(isif->isif_cfg.base_addr, cul->vcpat, CULV);
1037 /* LPF */
1038 isif_merge(isif->isif_cfg.base_addr, ISIF_LPF_MASK << ISIF_LPF_SHIFT,
1039 cul->en_lpf << ISIF_LPF_SHIFT, MODESET);
1040}
1041
1042static int isif_get_pix_fmt(u32 mbus_code)
1043{
1044 switch (mbus_code) {
1045 case V4L2_MBUS_FMT_SGRBG10_ALAW8_1X8:
1046 case V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8:
1047 case V4L2_MBUS_FMT_SGRBG12_1X12:
1048 return ISIF_PIXFMT_RAW;
1049
1050 case V4L2_MBUS_FMT_YUYV8_2X8:
1051 case V4L2_MBUS_FMT_UYVY8_2X8:
1052 case V4L2_MBUS_FMT_YUYV10_2X10:
1053 case V4L2_MBUS_FMT_Y8_1X8:
1054 return ISIF_PIXFMT_YCBCR_8BIT;
1055
1056 case V4L2_MBUS_FMT_YUYV8_1X16:
1057 case V4L2_MBUS_FMT_YUYV10_1X20:
1058 return ISIF_PIXFMT_YCBCR_16BIT;
1059
1060 default:
1061 break;
1062 }
1063 return -EINVAL;
1064}
1065
1066#define ISIF_INTERLACE_INVERSE_MODE 0x4b6d
1067#define ISIF_INTERLACE_NON_INVERSE_MODE 0x0b6d
1068#define ISIF_PROGRESSIVE_INVERSE_MODE 0x4000
1069#define ISIF_PROGRESSIVE_NON_INVERSE_MODE 0x0000
1070
1071static int isif_config_raw(struct v4l2_subdev *sd, int mode)
1072{
1073 struct vpfe_isif_device *isif = v4l2_get_subdevdata(sd);
1074 struct isif_params_raw *params = &isif->isif_cfg.bayer;
1075 struct vpfe_isif_raw_config *module_params =
1076 &isif->isif_cfg.bayer.config_params;
1077 struct v4l2_mbus_framefmt *format;
1078 int pix_fmt;
1079 u32 val;
1080
1081 format = &isif->formats[ISIF_PAD_SINK];
1082
1083 /* In case of user has set BT656IF earlier, it should be reset
1084 * when configuring for raw input.
1085 */
1086 isif_write(isif->isif_cfg.base_addr, 0, REC656IF);
1087 /* Configure CCDCFG register
1088 * Set CCD Not to swap input since input is RAW data
1089 * Set FID detection function to Latch at V-Sync
1090 * Set WENLOG - isif valid area
1091 * Set TRGSEL
1092 * Set EXTRG
1093 * Packed to 8 or 16 bits
1094 */
1095 val = ISIF_YCINSWP_RAW | ISIF_CCDCFG_FIDMD_LATCH_VSYNC |
1096 ISIF_CCDCFG_WENLOG_AND | ISIF_CCDCFG_TRGSEL_WEN |
1097 ISIF_CCDCFG_EXTRG_DISABLE | (isif->isif_cfg.data_pack &
1098 ISIF_DATA_PACK_MASK);
1099 isif_write(isif->isif_cfg.base_addr, val, CCDCFG);
1100
1101 pix_fmt = isif_get_pix_fmt(format->code);
1102 if (pix_fmt < 0) {
1103 pr_debug("Invalid pix_fmt(input mode)\n");
1104 return -EINVAL;
1105 }
1106 /*
1107 * Configure the vertical sync polarity(MODESET.VDPOL)
1108 * Configure the horizontal sync polarity (MODESET.HDPOL)
1109 * Configure frame id polarity (MODESET.FLDPOL)
1110 * Configure data polarity
1111 * Configure External WEN Selection
1112 * Configure frame format(progressive or interlace)
1113 * Configure pixel format (Input mode)
1114 * Configure the data shift
1115 */
1116 val = ISIF_VDHDOUT_INPUT | ((params->vd_pol & ISIF_VD_POL_MASK) <<
1117 ISIF_VD_POL_SHIFT) | ((params->hd_pol & ISIF_HD_POL_MASK) <<
1118 ISIF_HD_POL_SHIFT) | ((params->fid_pol & ISIF_FID_POL_MASK) <<
1119 ISIF_FID_POL_SHIFT) | ((ISIF_DATAPOL_NORMAL &
1120 ISIF_DATAPOL_MASK) << ISIF_DATAPOL_SHIFT) | ((ISIF_EXWEN_DISABLE &
1121 ISIF_EXWEN_MASK) << ISIF_EXWEN_SHIFT) | ((params->frm_fmt &
1122 ISIF_FRM_FMT_MASK) << ISIF_FRM_FMT_SHIFT) | ((pix_fmt &
1123 ISIF_INPUT_MASK) << ISIF_INPUT_SHIFT);
1124
1125 /* currently only V4L2_MBUS_FMT_SGRBG12_1X12 is
1126 * supported. shift appropriately depending on
1127 * different MBUS fmt's added
1128 */
1129 if (format->code == V4L2_MBUS_FMT_SGRBG12_1X12)
1130 val |= ((VPFE_ISIF_NO_SHIFT &
1131 ISIF_DATASFT_MASK) << ISIF_DATASFT_SHIFT);
1132
1133 isif_write(isif->isif_cfg.base_addr, val, MODESET);
1134 /*
1135 * Configure GAMMAWD register
1136 * CFA pattern setting
1137 */
1138 val = (params->cfa_pat & ISIF_GAMMAWD_CFA_MASK) <<
1139 ISIF_GAMMAWD_CFA_SHIFT;
1140 /* Gamma msb */
1141 if (params->v4l2_pix_fmt == V4L2_PIX_FMT_SGRBG10ALAW8)
1142 val = val | ISIF_ALAW_ENABLE;
1143
1144 val = val | ((params->data_msb & ISIF_ALAW_GAMA_WD_MASK) <<
1145 ISIF_ALAW_GAMA_WD_SHIFT);
1146
1147 isif_write(isif->isif_cfg.base_addr, val, CGAMMAWD);
1148 /* Configure DPCM compression settings */
1149 if (params->v4l2_pix_fmt == V4L2_PIX_FMT_SGRBG10DPCM8) {
1150 val = 1 << ISIF_DPCM_EN_SHIFT;
1151 val |= (params->dpcm_predictor &
1152 ISIF_DPCM_PREDICTOR_MASK) << ISIF_DPCM_PREDICTOR_SHIFT;
1153 }
1154 isif_write(isif->isif_cfg.base_addr, val, MISC);
1155 /* Configure Gain & Offset */
1156 isif_config_gain_offset(isif);
1157 /* Configure Color pattern */
1158 if (format->code == V4L2_MBUS_FMT_SGRBG12_1X12)
1159 val = isif_sgrbg_pattern;
1160 else
1161 /* default set to rggb */
1162 val = isif_srggb_pattern;
1163
1164 isif_write(isif->isif_cfg.base_addr, val, CCOLP);
1165
1166 /* Configure HSIZE register */
1167 val = (params->horz_flip_en & ISIF_HSIZE_FLIP_MASK) <<
1168 ISIF_HSIZE_FLIP_SHIFT;
1169
1170 /* calculate line offset in 32 bytes based on pack value */
1171 if (isif->isif_cfg.data_pack == ISIF_PACK_8BIT)
1172 val |= ((params->win.width + 31) >> 5) & ISIF_LINEOFST_MASK;
1173 else if (isif->isif_cfg.data_pack == ISIF_PACK_12BIT)
1174 val |= ((((params->win.width + (params->win.width >> 2)) +
1175 31) >> 5) & ISIF_LINEOFST_MASK);
1176 else
1177 val |= (((params->win.width * 2) + 31) >> 5) &
1178 ISIF_LINEOFST_MASK;
1179 isif_write(isif->isif_cfg.base_addr, val, HSIZE);
1180 /* Configure SDOFST register */
1181 if (params->frm_fmt == ISIF_FRMFMT_INTERLACED) {
1182 if (params->image_invert_en)
1183 /* For interlace inverse mode */
1184 isif_write(isif->isif_cfg.base_addr,
1185 ISIF_INTERLACE_INVERSE_MODE, SDOFST);
1186 else
1187 /* For interlace non inverse mode */
1188 isif_write(isif->isif_cfg.base_addr,
1189 ISIF_INTERLACE_NON_INVERSE_MODE, SDOFST);
1190 } else if (params->frm_fmt == ISIF_FRMFMT_PROGRESSIVE) {
1191 if (params->image_invert_en)
1192 isif_write(isif->isif_cfg.base_addr,
1193 ISIF_PROGRESSIVE_INVERSE_MODE, SDOFST);
1194 else
1195 /* For progessive non inverse mode */
1196 isif_write(isif->isif_cfg.base_addr,
1197 ISIF_PROGRESSIVE_NON_INVERSE_MODE, SDOFST);
1198 }
1199 /* Configure video window */
1200 isif_setwin(isif, &params->win, params->frm_fmt, 1, mode);
1201 /* Configure Black Clamp */
1202 isif_config_bclamp(isif, &module_params->bclamp);
1203 /* Configure Vertical Defection Pixel Correction */
1204 isif_config_dfc(isif, &module_params->dfc);
1205 if (!module_params->df_csc.df_or_csc)
1206 /* Configure Color Space Conversion */
1207 isif_config_csc(isif, &module_params->df_csc);
1208
1209 isif_config_linearization(isif, &module_params->linearize);
1210 /* Configure Culling */
1211 isif_config_culling(isif, &module_params->culling);
1212 /* Configure Horizontal and vertical offsets(DFC,LSC,Gain) */
1213 val = module_params->horz_offset & ISIF_DATA_H_OFFSET_MASK;
1214 isif_write(isif->isif_cfg.base_addr, val, DATAHOFST);
1215
1216 val = module_params->vert_offset & ISIF_DATA_V_OFFSET_MASK;
1217 isif_write(isif->isif_cfg.base_addr, val, DATAVOFST);
1218
1219 return 0;
1220}
1221
1222#define DM365_ISIF_HSIZE_MASK 0xffffffe0
1223#define DM365_ISIF_SDOFST_2_LINES 0x00000249
1224
1225/* This function will configure ISIF for YCbCr parameters. */
1226static int isif_config_ycbcr(struct v4l2_subdev *sd, int mode)
1227{
1228 struct vpfe_isif_device *isif = v4l2_get_subdevdata(sd);
1229 struct isif_ycbcr_config *params = &isif->isif_cfg.ycbcr;
1230 struct v4l2_mbus_framefmt *format;
1231 int pix_fmt;
1232 u32 modeset;
1233 u32 ccdcfg;
1234
1235 format = &isif->formats[ISIF_PAD_SINK];
1236 /*
1237 * first reset the ISIF
1238 * all registers have default values after reset
1239 * This is important since we assume default values to be set in
1240 * a lot of registers that we didn't touch
1241 */
1242 /* start with all bits zero */
1243 ccdcfg = modeset = 0;
1244 pix_fmt = isif_get_pix_fmt(format->code);
1245 if (pix_fmt < 0) {
1246 pr_debug("Invalid pix_fmt(input mode)\n");
1247 return -EINVAL;
1248 }
1249 /* configure pixel format or input mode */
1250 modeset = modeset | ((pix_fmt & ISIF_INPUT_MASK) <<
1251 ISIF_INPUT_SHIFT) | ((params->frm_fmt & ISIF_FRM_FMT_MASK) <<
1252 ISIF_FRM_FMT_SHIFT) | (((params->fid_pol &
1253 ISIF_FID_POL_MASK) << ISIF_FID_POL_SHIFT)) |
1254 (((params->hd_pol & ISIF_HD_POL_MASK) << ISIF_HD_POL_SHIFT)) |
1255 (((params->vd_pol & ISIF_VD_POL_MASK) << ISIF_VD_POL_SHIFT));
1256 /* pack the data to 8-bit CCDCCFG */
1257 switch (format->code) {
1258 case V4L2_MBUS_FMT_YUYV8_2X8:
1259 case V4L2_MBUS_FMT_UYVY8_2X8:
1260 if (pix_fmt != ISIF_PIXFMT_YCBCR_8BIT) {
1261 pr_debug("Invalid pix_fmt(input mode)\n");
1262 return -EINVAL;
1263 }
1264 modeset |= ((VPFE_PINPOL_NEGATIVE & ISIF_VD_POL_MASK) <<
1265 ISIF_VD_POL_SHIFT);
1266 isif_write(isif->isif_cfg.base_addr, 3, REC656IF);
1267 ccdcfg = ccdcfg | ISIF_PACK_8BIT | ISIF_YCINSWP_YCBCR;
1268 break;
1269
1270 case V4L2_MBUS_FMT_YUYV10_2X10:
1271 if (pix_fmt != ISIF_PIXFMT_YCBCR_8BIT) {
1272 pr_debug("Invalid pix_fmt(input mode)\n");
1273 return -EINVAL;
1274 }
1275 /* setup BT.656, embedded sync */
1276 isif_write(isif->isif_cfg.base_addr, 3, REC656IF);
1277 /* enable 10 bit mode in ccdcfg */
1278 ccdcfg = ccdcfg | ISIF_PACK_8BIT | ISIF_YCINSWP_YCBCR |
1279 ISIF_BW656_ENABLE;
1280 break;
1281
1282 case V4L2_MBUS_FMT_YUYV10_1X20:
1283 if (pix_fmt != ISIF_PIXFMT_YCBCR_16BIT) {
1284 pr_debug("Invalid pix_fmt(input mode)\n");
1285 return -EINVAL;
1286 }
1287 isif_write(isif->isif_cfg.base_addr, 3, REC656IF);
1288 break;
1289
1290 case V4L2_MBUS_FMT_Y8_1X8:
1291 ccdcfg |= ISIF_PACK_8BIT;
1292 ccdcfg |= ISIF_YCINSWP_YCBCR;
1293 if (pix_fmt != ISIF_PIXFMT_YCBCR_8BIT) {
1294 pr_debug("Invalid pix_fmt(input mode)\n");
1295 return -EINVAL;
1296 }
1297 break;
1298
1299 case V4L2_MBUS_FMT_YUYV8_1X16:
1300 if (pix_fmt != ISIF_PIXFMT_YCBCR_16BIT) {
1301 pr_debug("Invalid pix_fmt(input mode)\n");
1302 return -EINVAL;
1303 }
1304 break;
1305
1306 default:
1307 /* should never come here */
1308 pr_debug("Invalid interface type\n");
1309 return -EINVAL;
1310 }
1311 isif_write(isif->isif_cfg.base_addr, modeset, MODESET);
1312 /* Set up pix order */
1313 ccdcfg |= (params->pix_order & ISIF_PIX_ORDER_MASK) <<
1314 ISIF_PIX_ORDER_SHIFT;
1315 isif_write(isif->isif_cfg.base_addr, ccdcfg, CCDCFG);
1316 /* configure video window */
1317 if (format->code == V4L2_MBUS_FMT_YUYV10_1X20 ||
1318 format->code == V4L2_MBUS_FMT_YUYV8_1X16)
1319 isif_setwin(isif, &params->win, params->frm_fmt, 1, mode);
1320 else
1321 isif_setwin(isif, &params->win, params->frm_fmt, 2, mode);
1322
1323 /*
1324 * configure the horizontal line offset
1325 * this is done by rounding up width to a multiple of 16 pixels
1326 * and multiply by two to account for y:cb:cr 4:2:2 data
1327 */
1328 isif_write(isif->isif_cfg.base_addr,
1329 ((((params->win.width * 2) + 31) &
1330 DM365_ISIF_HSIZE_MASK) >> 5), HSIZE);
1331
1332 /* configure the memory line offset */
1333 if (params->frm_fmt == ISIF_FRMFMT_INTERLACED &&
1334 params->buf_type == ISIF_BUFTYPE_FLD_INTERLEAVED)
1335 /* two fields are interleaved in memory */
1336 isif_write(isif->isif_cfg.base_addr,
1337 DM365_ISIF_SDOFST_2_LINES, SDOFST);
1338 return 0;
1339}
1340
1341static int isif_configure(struct v4l2_subdev *sd, int mode)
1342{
1343 struct vpfe_isif_device *isif = v4l2_get_subdevdata(sd);
1344 struct v4l2_mbus_framefmt *format;
1345
1346 format = &isif->formats[ISIF_PAD_SINK];
1347
1348 switch (format->code) {
1349 case V4L2_MBUS_FMT_SGRBG10_ALAW8_1X8:
1350 case V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8:
1351 case V4L2_MBUS_FMT_SGRBG12_1X12:
1352 return isif_config_raw(sd, mode);
1353
1354 case V4L2_MBUS_FMT_YUYV8_2X8:
1355 case V4L2_MBUS_FMT_UYVY8_2X8:
1356 case V4L2_MBUS_FMT_YUYV10_2X10:
1357 case V4L2_MBUS_FMT_Y8_1X8:
1358 case V4L2_MBUS_FMT_YUYV8_1X16:
1359 case V4L2_MBUS_FMT_YUYV10_1X20:
1360 return isif_config_ycbcr(sd, mode);
1361
1362 default:
1363 break;
1364 }
1365 return -EINVAL;
1366}
1367
1368/*
1369 * isif_set_stream() - Enable/Disable streaming on the ISIF module
1370 * @sd: VPFE ISIF V4L2 subdevice
1371 * @enable: Enable/disable stream
1372 */
1373static int isif_set_stream(struct v4l2_subdev *sd, int enable)
1374{
1375 struct vpfe_isif_device *isif = v4l2_get_subdevdata(sd);
1376 int ret;
1377
1378 if (enable) {
1379 ret = isif_configure(sd,
1380 (isif->output == ISIF_OUTPUT_MEMORY) ? 0 : 1);
1381 if (ret)
1382 return ret;
1383 if (isif->output == ISIF_OUTPUT_MEMORY)
1384 isif_enable_output_to_sdram(isif, 1);
1385 isif_enable(isif, 1);
1386 } else {
1387 isif_enable(isif, 0);
1388 isif_enable_output_to_sdram(isif, 0);
1389 }
1390
1391 return 0;
1392}
1393
1394/*
1395 * __isif_get_format() - helper function for getting isif format
1396 * @isif: pointer to isif private structure.
1397 * @pad: pad number.
1398 * @fh: V4L2 subdev file handle.
1399 * @which: wanted subdev format.
1400 */
1401static struct v4l2_mbus_framefmt *
1402__isif_get_format(struct vpfe_isif_device *isif, struct v4l2_subdev_fh *fh,
1403 unsigned int pad, enum v4l2_subdev_format_whence which)
1404{
1405 if (which == V4L2_SUBDEV_FORMAT_TRY) {
1406 struct v4l2_subdev_format fmt;
1407
1408 fmt.pad = pad;
1409 fmt.which = which;
1410
1411 return v4l2_subdev_get_try_format(fh, pad);
1412 }
1413 return &isif->formats[pad];
1414}
1415
1416/*
1417* isif_set_format() - set format on pad
1418* @sd : VPFE ISIF device
1419* @fh : V4L2 subdev file handle
1420* @fmt : pointer to v4l2 subdev format structure
1421*
1422* Return 0 on success or -EINVAL if format or pad is invalid
1423*/
1424static int
1425isif_set_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1426 struct v4l2_subdev_format *fmt)
1427{
1428 struct vpfe_isif_device *isif = v4l2_get_subdevdata(sd);
1429 struct vpfe_device *vpfe_dev = to_vpfe_device(isif);
1430 struct v4l2_mbus_framefmt *format;
1431
1432 format = __isif_get_format(isif, fh, fmt->pad, fmt->which);
1433 if (format == NULL)
1434 return -EINVAL;
1435
1436 isif_try_format(isif, fh, fmt);
1437 memcpy(format, &fmt->format, sizeof(*format));
1438
1439 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY)
1440 return 0;
1441
1442 if (fmt->pad == ISIF_PAD_SOURCE)
1443 return isif_config_format(vpfe_dev, fmt->pad);
1444
1445 return 0;
1446}
1447
1448/*
1449 * isif_get_format() - Retrieve the video format on a pad
1450 * @sd: VPFE ISIF V4L2 subdevice
1451 * @fh: V4L2 subdev file handle
1452 * @fmt: pointer to v4l2 subdev format structure
1453 *
1454 * Return 0 on success or -EINVAL if the pad is invalid or doesn't correspond
1455 * to the format type.
1456 */
1457static int
1458isif_get_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1459 struct v4l2_subdev_format *fmt)
1460{
1461 struct vpfe_isif_device *vpfe_isif = v4l2_get_subdevdata(sd);
1462 struct v4l2_mbus_framefmt *format;
1463
1464 format = __isif_get_format(vpfe_isif, fh, fmt->pad, fmt->which);
1465 if (format == NULL)
1466 return -EINVAL;
1467
1468 memcpy(&fmt->format, format, sizeof(fmt->format));
1469
1470 return 0;
1471}
1472
1473/*
1474 * isif_enum_frame_size() - enum frame sizes on pads
1475 * @sd: VPFE isif V4L2 subdevice
1476 * @fh: V4L2 subdev file handle
1477 * @code: pointer to v4l2_subdev_frame_size_enum structure
1478 */
1479static int
1480isif_enum_frame_size(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1481 struct v4l2_subdev_frame_size_enum *fse)
1482{
1483 struct vpfe_isif_device *isif = v4l2_get_subdevdata(sd);
1484 struct v4l2_subdev_format format;
1485
1486 if (fse->index != 0)
1487 return -EINVAL;
1488
1489 format.pad = fse->pad;
1490 format.format.code = fse->code;
1491 format.format.width = 1;
1492 format.format.height = 1;
1493 format.which = V4L2_SUBDEV_FORMAT_TRY;
1494 isif_try_format(isif, fh, &format);
1495 fse->min_width = format.format.width;
1496 fse->min_height = format.format.height;
1497
1498 if (format.format.code != fse->code)
1499 return -EINVAL;
1500
1501 format.pad = fse->pad;
1502 format.format.code = fse->code;
1503 format.format.width = -1;
1504 format.format.height = -1;
1505 format.which = V4L2_SUBDEV_FORMAT_TRY;
1506 isif_try_format(isif, fh, &format);
1507 fse->max_width = format.format.width;
1508 fse->max_height = format.format.height;
1509
1510 return 0;
1511}
1512
1513/*
1514 * isif_enum_mbus_code() - enum mbus codes for pads
1515 * @sd: VPFE isif V4L2 subdevice
1516 * @fh: V4L2 subdev file handle
1517 * @code: pointer to v4l2_subdev_mbus_code_enum structure
1518 */
1519static int
1520isif_enum_mbus_code(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1521 struct v4l2_subdev_mbus_code_enum *code)
1522{
1523 switch (code->pad) {
1524 case ISIF_PAD_SINK:
1525 case ISIF_PAD_SOURCE:
1526 if (code->index >= ARRAY_SIZE(isif_fmts))
1527 return -EINVAL;
1528 code->code = isif_fmts[code->index];
1529 break;
1530
1531 default:
1532 return -EINVAL;
1533 }
1534
1535 return 0;
1536}
1537
1538/*
1539 * isif_pad_set_crop() - set crop rectangle on pad
1540 * @sd: VPFE isif V4L2 subdevice
1541 * @fh: V4L2 subdev file handle
1542 * @code: pointer to v4l2_subdev_mbus_code_enum structure
1543 *
1544 * Return 0 on success, -EINVAL if pad is invalid
1545 */
1546static int
1547isif_pad_set_crop(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1548 struct v4l2_subdev_crop *crop)
1549{
1550 struct vpfe_isif_device *vpfe_isif = v4l2_get_subdevdata(sd);
1551 struct v4l2_mbus_framefmt *format;
1552
1553 /* check wether its a valid pad */
1554 if (crop->pad != ISIF_PAD_SINK)
1555 return -EINVAL;
1556
1557 format = __isif_get_format(vpfe_isif, fh, crop->pad, crop->which);
1558 if (format == NULL)
1559 return -EINVAL;
1560
1561 /* check wether crop rect is within limits */
1562 if (crop->rect.top < 0 || crop->rect.left < 0 ||
1563 (crop->rect.left + crop->rect.width >
1564 vpfe_isif->formats[ISIF_PAD_SINK].width) ||
1565 (crop->rect.top + crop->rect.height >
1566 vpfe_isif->formats[ISIF_PAD_SINK].height)) {
1567 crop->rect.left = 0;
1568 crop->rect.top = 0;
1569 crop->rect.width = format->width;
1570 crop->rect.height = format->height;
1571 }
1572 /* adjust the width to 16 pixel boundry */
1573 crop->rect.width = ((crop->rect.width + 15) & ~0xf);
1574 vpfe_isif->crop = crop->rect;
1575 if (crop->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
1576 isif_set_image_window(vpfe_isif);
1577 } else {
1578 struct v4l2_rect *rect;
1579
1580 rect = v4l2_subdev_get_try_crop(fh, ISIF_PAD_SINK);
1581 memcpy(rect, &vpfe_isif->crop, sizeof(*rect));
1582 }
1583 return 0;
1584}
1585
1586/*
1587 * isif_pad_get_crop() - get crop rectangle on pad
1588 * @sd: VPFE isif V4L2 subdevice
1589 * @fh: V4L2 subdev file handle
1590 * @code: pointer to v4l2_subdev_mbus_code_enum structure
1591 *
1592 * Return 0 on success, -EINVAL if pad is invalid
1593 */
1594static int
1595isif_pad_get_crop(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1596 struct v4l2_subdev_crop *crop)
1597{
1598 struct vpfe_isif_device *vpfe_isif = v4l2_get_subdevdata(sd);
1599
1600 /* check wether its a valid pad */
1601 if (crop->pad != ISIF_PAD_SINK)
1602 return -EINVAL;
1603
1604 if (crop->which == V4L2_SUBDEV_FORMAT_TRY) {
1605 struct v4l2_rect *rect;
1606 rect = v4l2_subdev_get_try_crop(fh, ISIF_PAD_SINK);
1607 memcpy(&crop->rect, rect, sizeof(*rect));
1608 } else {
1609 crop->rect = vpfe_isif->crop;
1610 }
1611
1612 return 0;
1613}
1614
1615/*
1616 * isif_init_formats() - Initialize formats on all pads
1617 * @sd: VPFE isif V4L2 subdevice
1618 * @fh: V4L2 subdev file handle
1619 *
1620 * Initialize all pad formats with default values. If fh is not NULL, try
1621 * formats are initialized on the file handle. Otherwise active formats are
1622 * initialized on the device.
1623 */
1624static int
1625isif_init_formats(struct v4l2_subdev *sd,
1626 struct v4l2_subdev_fh *fh)
1627{
1628 struct v4l2_subdev_format format;
1629 struct v4l2_subdev_crop crop;
1630
1631 memset(&format, 0, sizeof(format));
1632 format.pad = ISIF_PAD_SINK;
1633 format.which = fh ? V4L2_SUBDEV_FORMAT_TRY : V4L2_SUBDEV_FORMAT_ACTIVE;
1634 format.format.code = V4L2_MBUS_FMT_SGRBG12_1X12;
1635 format.format.width = MAX_WIDTH;
1636 format.format.height = MAX_HEIGHT;
1637 isif_set_format(sd, fh, &format);
1638
1639 memset(&format, 0, sizeof(format));
1640 format.pad = ISIF_PAD_SOURCE;
1641 format.which = fh ? V4L2_SUBDEV_FORMAT_TRY : V4L2_SUBDEV_FORMAT_ACTIVE;
1642 format.format.code = V4L2_MBUS_FMT_SGRBG12_1X12;
1643 format.format.width = MAX_WIDTH;
1644 format.format.height = MAX_HEIGHT;
1645 isif_set_format(sd, fh, &format);
1646
1647 memset(&crop, 0, sizeof(crop));
1648 crop.pad = ISIF_PAD_SINK;
1649 crop.which = fh ? V4L2_SUBDEV_FORMAT_TRY : V4L2_SUBDEV_FORMAT_ACTIVE;
1650 crop.rect.width = MAX_WIDTH;
1651 crop.rect.height = MAX_HEIGHT;
1652 isif_pad_set_crop(sd, fh, &crop);
1653
1654 return 0;
1655}
1656
1657/* subdev core operations */
1658static const struct v4l2_subdev_core_ops isif_v4l2_core_ops = {
1659 .ioctl = isif_ioctl,
1660};
1661
1662/* subdev file operations */
1663static const struct v4l2_subdev_internal_ops isif_v4l2_internal_ops = {
1664 .open = isif_init_formats,
1665};
1666
1667/* subdev video operations */
1668static const struct v4l2_subdev_video_ops isif_v4l2_video_ops = {
1669 .s_stream = isif_set_stream,
1670};
1671
1672/* subdev pad operations */
1673static const struct v4l2_subdev_pad_ops isif_v4l2_pad_ops = {
1674 .enum_mbus_code = isif_enum_mbus_code,
1675 .enum_frame_size = isif_enum_frame_size,
1676 .get_fmt = isif_get_format,
1677 .set_fmt = isif_set_format,
1678 .set_crop = isif_pad_set_crop,
1679 .get_crop = isif_pad_get_crop,
1680};
1681
1682/* subdev operations */
1683static const struct v4l2_subdev_ops isif_v4l2_ops = {
1684 .core = &isif_v4l2_core_ops,
1685 .video = &isif_v4l2_video_ops,
1686 .pad = &isif_v4l2_pad_ops,
1687};
1688
1689/*
1690 * Media entity operations
1691 */
1692
1693/*
1694 * isif_link_setup() - Setup isif connections
1695 * @entity: isif media entity
1696 * @local: Pad at the local end of the link
1697 * @remote: Pad at the remote end of the link
1698 * @flags: Link flags
1699 *
1700 * return -EINVAL or zero on success
1701 */
1702static int
1703isif_link_setup(struct media_entity *entity, const struct media_pad *local,
1704 const struct media_pad *remote, u32 flags)
1705{
1706 struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
1707 struct vpfe_isif_device *isif = v4l2_get_subdevdata(sd);
1708
1709 switch (local->index | media_entity_type(remote->entity)) {
1710 case ISIF_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
1711 /* read from decoder/sensor */
1712 if (!(flags & MEDIA_LNK_FL_ENABLED)) {
1713 isif->input = ISIF_INPUT_NONE;
1714 break;
1715 }
1716 if (isif->input != ISIF_INPUT_NONE)
1717 return -EBUSY;
1718 isif->input = ISIF_INPUT_PARALLEL;
1719 break;
1720
1721 case ISIF_PAD_SOURCE | MEDIA_ENT_T_DEVNODE:
1722 /* write to memory */
1723 if (flags & MEDIA_LNK_FL_ENABLED)
1724 isif->output = ISIF_OUTPUT_MEMORY;
1725 else
1726 isif->output = ISIF_OUTPUT_NONE;
1727 break;
1728
1729 case ISIF_PAD_SOURCE | MEDIA_ENT_T_V4L2_SUBDEV:
1730 if (flags & MEDIA_LNK_FL_ENABLED)
1731 isif->output = ISIF_OUTPUT_IPIPEIF;
1732 else
1733 isif->output = ISIF_OUTPUT_NONE;
1734 break;
1735
1736 default:
1737 return -EINVAL;
1738 }
1739
1740 return 0;
1741}
1742static const struct media_entity_operations isif_media_ops = {
1743 .link_setup = isif_link_setup,
1744};
1745
1746/*
1747 * vpfe_isif_unregister_entities() - isif unregister entity
1748 * @isif - pointer to isif subdevice structure.
1749 */
1750void vpfe_isif_unregister_entities(struct vpfe_isif_device *isif)
1751{
1752 vpfe_video_unregister(&isif->video_out);
1753 /* cleanup entity */
1754 media_entity_cleanup(&isif->subdev.entity);
1755 /* unregister subdev */
1756 v4l2_device_unregister_subdev(&isif->subdev);
1757}
1758
1759static void isif_restore_defaults(struct vpfe_isif_device *isif)
1760{
1761 enum vpss_ccdc_source_sel source = VPSS_CCDCIN;
1762 int i;
1763
1764 memset(&isif->isif_cfg.bayer.config_params, 0,
1765 sizeof(struct vpfe_isif_raw_config));
1766
1767 isif->isif_cfg.bayer.config_params.linearize.corr_shft =
1768 VPFE_ISIF_NO_SHIFT;
1769 isif->isif_cfg.bayer.config_params.linearize.scale_fact.integer = 1;
1770 isif->isif_cfg.bayer.config_params.culling.hcpat_odd =
1771 ISIF_CULLING_HCAPT_ODD;
1772 isif->isif_cfg.bayer.config_params.culling.hcpat_even =
1773 ISIF_CULLING_HCAPT_EVEN;
1774 isif->isif_cfg.bayer.config_params.culling.vcpat = ISIF_CULLING_VCAPT;
1775 /* Enable clock to ISIF, IPIPEIF and BL */
1776 vpss_enable_clock(VPSS_CCDC_CLOCK, 1);
1777 vpss_enable_clock(VPSS_IPIPEIF_CLOCK, 1);
1778 vpss_enable_clock(VPSS_BL_CLOCK, 1);
1779
1780 /* set all registers to default value */
1781 for (i = 0; i <= 0x1f8; i += 4)
1782 isif_write(isif->isif_cfg.base_addr, 0, i);
1783 /* no culling support */
1784 isif_write(isif->isif_cfg.base_addr, 0xffff, CULH);
1785 isif_write(isif->isif_cfg.base_addr, 0xff, CULV);
1786
1787 /* Set default offset and gain */
1788 isif_config_gain_offset(isif);
1789 vpss_select_ccdc_source(source);
1790}
1791
1792/*
1793 * vpfe_isif_register_entities() - isif register entity
1794 * @isif - pointer to isif subdevice structure.
1795 * @vdev: pointer to v4l2 device structure.
1796 */
1797int vpfe_isif_register_entities(struct vpfe_isif_device *isif,
1798 struct v4l2_device *vdev)
1799{
1800 struct vpfe_device *vpfe_dev = to_vpfe_device(isif);
1801 unsigned int flags;
1802 int ret;
1803
1804 /* Register the subdev */
1805 ret = v4l2_device_register_subdev(vdev, &isif->subdev);
1806 if (ret < 0)
1807 return ret;
1808
1809 isif_restore_defaults(isif);
1810 ret = vpfe_video_register(&isif->video_out, vdev);
1811 if (ret) {
1812 pr_err("Failed to register isif video out device\n");
1813 goto out_video_register;
1814 }
1815 isif->video_out.vpfe_dev = vpfe_dev;
1816 flags = 0;
1817 /* connect isif to video node */
1818 ret = media_entity_create_link(&isif->subdev.entity, 1,
1819 &isif->video_out.video_dev.entity,
1820 0, flags);
1821 if (ret < 0)
1822 goto out_create_link;
1823 return 0;
1824out_create_link:
1825 vpfe_video_unregister(&isif->video_out);
1826out_video_register:
1827 v4l2_device_unregister_subdev(&isif->subdev);
1828 return ret;
1829}
1830
1831/* -------------------------------------------------------------------
1832 * V4L2 subdev control operations
1833 */
1834
1835static int vpfe_isif_s_ctrl(struct v4l2_ctrl *ctrl)
1836{
1837 struct vpfe_isif_device *isif =
1838 container_of(ctrl->handler, struct vpfe_isif_device, ctrls);
1839 struct isif_oper_config *config = &isif->isif_cfg;
1840
1841 switch (ctrl->id) {
1842 case VPFE_CID_DPCM_PREDICTOR:
1843 config->bayer.dpcm_predictor = ctrl->val;
1844 break;
1845
1846 case VPFE_ISIF_CID_CRGAIN:
1847 config->isif_gain_params.cr_gain = ctrl->val;
1848 break;
1849
1850 case VPFE_ISIF_CID_CGRGAIN:
1851 config->isif_gain_params.cgr_gain = ctrl->val;
1852 break;
1853
1854 case VPFE_ISIF_CID_CGBGAIN:
1855 config->isif_gain_params.cgb_gain = ctrl->val;
1856 break;
1857
1858 case VPFE_ISIF_CID_CBGAIN:
1859 config->isif_gain_params.cb_gain = ctrl->val;
1860 break;
1861
1862 case VPFE_ISIF_CID_GAIN_OFFSET:
1863 config->isif_gain_params.offset = ctrl->val;
1864 break;
1865
1866 default:
1867 return -EINVAL;
1868 }
1869 return 0;
1870}
1871
1872static const struct v4l2_ctrl_ops vpfe_isif_ctrl_ops = {
1873 .s_ctrl = vpfe_isif_s_ctrl,
1874};
1875
1876static const struct v4l2_ctrl_config vpfe_isif_dpcm_pred = {
1877 .ops = &vpfe_isif_ctrl_ops,
1878 .id = VPFE_CID_DPCM_PREDICTOR,
1879 .name = "DPCM Predictor",
1880 .type = V4L2_CTRL_TYPE_INTEGER,
1881 .min = 0,
1882 .max = 1,
1883 .step = 1,
1884 .def = 0,
1885};
1886
1887static const struct v4l2_ctrl_config vpfe_isif_crgain = {
1888 .ops = &vpfe_isif_ctrl_ops,
1889 .id = VPFE_ISIF_CID_CRGAIN,
1890 .name = "CRGAIN",
1891 .type = V4L2_CTRL_TYPE_INTEGER,
1892 .min = 0,
1893 .max = (1 << 12) - 1,
1894 .step = 1,
1895 .def = 0,
1896};
1897
1898static const struct v4l2_ctrl_config vpfe_isif_cgrgain = {
1899 .ops = &vpfe_isif_ctrl_ops,
1900 .id = VPFE_ISIF_CID_CGRGAIN,
1901 .name = "CGRGAIN",
1902 .type = V4L2_CTRL_TYPE_INTEGER,
1903 .min = 0,
1904 .max = (1 << 12) - 1,
1905 .step = 1,
1906 .def = 0,
1907};
1908
1909static const struct v4l2_ctrl_config vpfe_isif_cgbgain = {
1910 .ops = &vpfe_isif_ctrl_ops,
1911 .id = VPFE_ISIF_CID_CGBGAIN,
1912 .name = "CGBGAIN",
1913 .type = V4L2_CTRL_TYPE_INTEGER,
1914 .min = 0,
1915 .max = (1 << 12) - 1,
1916 .step = 1,
1917 .def = 0,
1918};
1919
1920static const struct v4l2_ctrl_config vpfe_isif_cbgain = {
1921 .ops = &vpfe_isif_ctrl_ops,
1922 .id = VPFE_ISIF_CID_CBGAIN,
1923 .name = "CBGAIN",
1924 .type = V4L2_CTRL_TYPE_INTEGER,
1925 .min = 0,
1926 .max = (1 << 12) - 1,
1927 .step = 1,
1928 .def = 0,
1929};
1930
1931static const struct v4l2_ctrl_config vpfe_isif_gain_offset = {
1932 .ops = &vpfe_isif_ctrl_ops,
1933 .id = VPFE_ISIF_CID_GAIN_OFFSET,
1934 .name = "Gain Offset",
1935 .type = V4L2_CTRL_TYPE_INTEGER,
1936 .min = 0,
1937 .max = (1 << 12) - 1,
1938 .step = 1,
1939 .def = 0,
1940};
1941
1942static void isif_remove(struct vpfe_isif_device *isif,
1943 struct platform_device *pdev)
1944{
1945 struct resource *res;
1946 int i = 0;
1947
1948 iounmap(isif->isif_cfg.base_addr);
1949 iounmap(isif->isif_cfg.linear_tbl0_addr);
1950 iounmap(isif->isif_cfg.linear_tbl1_addr);
1951
1952 while (i < 3) {
1953 res = platform_get_resource(pdev, IORESOURCE_MEM, i);
1954 if (res)
1955 release_mem_region(res->start,
1956 res->end - res->start + 1);
1957 i++;
1958 }
1959}
1960
1961static void isif_config_defaults(struct vpfe_isif_device *isif)
1962{
1963 isif->isif_cfg.ycbcr.v4l2_pix_fmt = V4L2_PIX_FMT_UYVY;
1964 isif->isif_cfg.ycbcr.pix_fmt = ISIF_PIXFMT_YCBCR_8BIT;
1965 isif->isif_cfg.ycbcr.frm_fmt = ISIF_FRMFMT_INTERLACED;
1966 isif->isif_cfg.ycbcr.fid_pol = VPFE_PINPOL_POSITIVE;
1967 isif->isif_cfg.ycbcr.vd_pol = VPFE_PINPOL_POSITIVE;
1968 isif->isif_cfg.ycbcr.hd_pol = VPFE_PINPOL_POSITIVE;
1969 isif->isif_cfg.ycbcr.pix_order = ISIF_PIXORDER_CBYCRY;
1970 isif->isif_cfg.ycbcr.buf_type = ISIF_BUFTYPE_FLD_INTERLEAVED;
1971
1972 isif->isif_cfg.bayer.v4l2_pix_fmt = V4L2_PIX_FMT_SGRBG10ALAW8;
1973 isif->isif_cfg.bayer.pix_fmt = ISIF_PIXFMT_RAW;
1974 isif->isif_cfg.bayer.frm_fmt = ISIF_FRMFMT_PROGRESSIVE;
1975 isif->isif_cfg.bayer.fid_pol = VPFE_PINPOL_POSITIVE;
1976 isif->isif_cfg.bayer.vd_pol = VPFE_PINPOL_POSITIVE;
1977 isif->isif_cfg.bayer.hd_pol = VPFE_PINPOL_POSITIVE;
1978 isif->isif_cfg.bayer.cfa_pat = ISIF_CFA_PAT_MOSAIC;
1979 isif->isif_cfg.bayer.data_msb = ISIF_BIT_MSB_11;
1980 isif->isif_cfg.data_pack = ISIF_PACK_8BIT;
1981}
1982/*
1983 * vpfe_isif_init() - Initialize V4L2 subdev and media entity
1984 * @isif: VPFE isif module
1985 * @pdev: Pointer to platform device structure.
1986 * Return 0 on success and a negative error code on failure.
1987 */
1988int vpfe_isif_init(struct vpfe_isif_device *isif, struct platform_device *pdev)
1989{
1990 struct v4l2_subdev *sd = &isif->subdev;
1991 struct media_pad *pads = &isif->pads[0];
1992 struct media_entity *me = &sd->entity;
1993 static resource_size_t res_len;
1994 struct resource *res;
1995 void *__iomem addr;
1996 int status;
1997 int i = 0;
1998
1999 /* Get the ISIF base address, linearization table0 and table1 addr. */
2000 while (i < 3) {
2001 res = platform_get_resource(pdev, IORESOURCE_MEM, i);
2002 if (!res) {
2003 status = -ENOENT;
2004 goto fail_nobase_res;
2005 }
2006 res_len = res->end - res->start + 1;
2007 res = request_mem_region(res->start, res_len, res->name);
2008 if (!res) {
2009 status = -EBUSY;
2010 goto fail_nobase_res;
2011 }
2012 addr = ioremap_nocache(res->start, res_len);
2013 if (!addr) {
2014 status = -EBUSY;
2015 goto fail_base_iomap;
2016 }
2017 switch (i) {
2018 case 0:
2019 /* ISIF base address */
2020 isif->isif_cfg.base_addr = addr;
2021 break;
2022 case 1:
2023 /* ISIF linear tbl0 address */
2024 isif->isif_cfg.linear_tbl0_addr = addr;
2025 break;
2026 default:
2027 /* ISIF linear tbl0 address */
2028 isif->isif_cfg.linear_tbl1_addr = addr;
2029 break;
2030 }
2031 i++;
2032 }
2033 davinci_cfg_reg(DM365_VIN_CAM_WEN);
2034 davinci_cfg_reg(DM365_VIN_CAM_VD);
2035 davinci_cfg_reg(DM365_VIN_CAM_HD);
2036 davinci_cfg_reg(DM365_VIN_YIN4_7_EN);
2037 davinci_cfg_reg(DM365_VIN_YIN0_3_EN);
2038
2039 /* queue ops */
2040 isif->video_out.ops = &isif_video_ops;
2041 v4l2_subdev_init(sd, &isif_v4l2_ops);
2042 sd->internal_ops = &isif_v4l2_internal_ops;
2043 strlcpy(sd->name, "DAVINCI ISIF", sizeof(sd->name));
2044 sd->grp_id = 1 << 16; /* group ID for davinci subdevs */
2045 v4l2_set_subdevdata(sd, isif);
2046 sd->flags |= V4L2_SUBDEV_FL_HAS_EVENTS | V4L2_SUBDEV_FL_HAS_DEVNODE;
2047 pads[ISIF_PAD_SINK].flags = MEDIA_PAD_FL_SINK;
2048 pads[ISIF_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE;
2049
2050 isif->input = ISIF_INPUT_NONE;
2051 isif->output = ISIF_OUTPUT_NONE;
2052 me->ops = &isif_media_ops;
2053 status = media_entity_init(me, ISIF_PADS_NUM, pads, 0);
2054 if (status)
2055 goto isif_fail;
2056 isif->video_out.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
2057 status = vpfe_video_init(&isif->video_out, "ISIF");
2058 if (status) {
2059 pr_err("Failed to init isif-out video device\n");
2060 goto isif_fail;
2061 }
2062 v4l2_ctrl_handler_init(&isif->ctrls, 6);
2063 v4l2_ctrl_new_custom(&isif->ctrls, &vpfe_isif_crgain, NULL);
2064 v4l2_ctrl_new_custom(&isif->ctrls, &vpfe_isif_cgrgain, NULL);
2065 v4l2_ctrl_new_custom(&isif->ctrls, &vpfe_isif_cgbgain, NULL);
2066 v4l2_ctrl_new_custom(&isif->ctrls, &vpfe_isif_cbgain, NULL);
2067 v4l2_ctrl_new_custom(&isif->ctrls, &vpfe_isif_gain_offset, NULL);
2068 v4l2_ctrl_new_custom(&isif->ctrls, &vpfe_isif_dpcm_pred, NULL);
2069
2070 v4l2_ctrl_handler_setup(&isif->ctrls);
2071 sd->ctrl_handler = &isif->ctrls;
2072 isif_config_defaults(isif);
2073 return 0;
2074fail_base_iomap:
2075 release_mem_region(res->start, res_len);
2076 i--;
2077fail_nobase_res:
2078 if (isif->isif_cfg.base_addr)
2079 iounmap(isif->isif_cfg.base_addr);
2080 if (isif->isif_cfg.linear_tbl0_addr)
2081 iounmap(isif->isif_cfg.linear_tbl0_addr);
2082
2083 while (i >= 0) {
2084 res = platform_get_resource(pdev, IORESOURCE_MEM, i);
2085 release_mem_region(res->start, res_len);
2086 i--;
2087 }
2088 return status;
2089isif_fail:
2090 v4l2_ctrl_handler_free(&isif->ctrls);
2091 isif_remove(isif, pdev);
2092 return status;
2093}
2094
2095/*
2096 * vpfe_isif_cleanup - isif module cleanup
2097 * @isif: pointer to isif subdevice
2098 * @dev: pointer to platform device structure
2099 */
2100void
2101vpfe_isif_cleanup(struct vpfe_isif_device *isif, struct platform_device *pdev)
2102{
2103 isif_remove(isif, pdev);
2104}
diff --git a/drivers/staging/media/davinci_vpfe/dm365_isif.h b/drivers/staging/media/davinci_vpfe/dm365_isif.h
new file mode 100644
index 000000000000..473fd2cfe350
--- /dev/null
+++ b/drivers/staging/media/davinci_vpfe/dm365_isif.h
@@ -0,0 +1,203 @@
1/*
2 * Copyright (C) 2012 Texas Instruments Inc
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation version 2.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Contributors:
18 * Manjunath Hadli <manjunath.hadli@ti.com>
19 * Prabhakar Lad <prabhakar.lad@ti.com>
20 */
21
22#ifndef _DAVINCI_VPFE_DM365_ISIF_H
23#define _DAVINCI_VPFE_DM365_ISIF_H
24
25#include <linux/platform_device.h>
26
27#include <mach/mux.h>
28
29#include <media/davinci/vpfe_types.h>
30#include <media/v4l2-ctrls.h>
31#include <media/v4l2-device.h>
32
33#include "davinci_vpfe_user.h"
34#include "dm365_isif_regs.h"
35#include "vpfe_video.h"
36
37#define ISIF_CULLING_HCAPT_ODD 0xff
38#define ISIF_CULLING_HCAPT_EVEN 0xff
39#define ISIF_CULLING_VCAPT 0xff
40
41#define ISIF_CADU_BITS 0x07ff
42#define ISIF_CADL_BITS 0x0ffff
43
44enum isif_pixfmt {
45 ISIF_PIXFMT_RAW = 0,
46 ISIF_PIXFMT_YCBCR_16BIT = 1,
47 ISIF_PIXFMT_YCBCR_8BIT = 2,
48};
49
50enum isif_frmfmt {
51 ISIF_FRMFMT_PROGRESSIVE = 0,
52 ISIF_FRMFMT_INTERLACED = 1,
53};
54
55/* PIXEL ORDER IN MEMORY from LSB to MSB */
56/* only applicable for 8-bit input mode */
57enum isif_pixorder {
58 ISIF_PIXORDER_YCBYCR = 0,
59 ISIF_PIXORDER_CBYCRY = 1,
60};
61
62enum isif_buftype {
63 ISIF_BUFTYPE_FLD_INTERLEAVED = 0,
64 ISIF_BUFTYPE_FLD_SEPARATED = 1,
65};
66
67struct isif_ycbcr_config {
68 /* v4l2 pixel format */
69 unsigned long v4l2_pix_fmt;
70 /* isif pixel format */
71 enum isif_pixfmt pix_fmt;
72 /* isif frame format */
73 enum isif_frmfmt frm_fmt;
74 /* isif crop window */
75 struct v4l2_rect win;
76 /* field polarity */
77 enum vpfe_pin_pol fid_pol;
78 /* interface VD polarity */
79 enum vpfe_pin_pol vd_pol;
80 /* interface HD polarity */
81 enum vpfe_pin_pol hd_pol;
82 /* isif pix order. Only used for ycbcr capture */
83 enum isif_pixorder pix_order;
84 /* isif buffer type. Only used for ycbcr capture */
85 enum isif_buftype buf_type;
86};
87
88enum isif_cfa_pattern {
89 ISIF_CFA_PAT_MOSAIC = 0,
90 ISIF_CFA_PAT_STRIPE = 1,
91};
92
93enum isif_data_msb {
94 /* MSB b15 */
95 ISIF_BIT_MSB_15 = 0,
96 /* MSB b14 */
97 ISIF_BIT_MSB_14 = 1,
98 /* MSB b13 */
99 ISIF_BIT_MSB_13 = 2,
100 /* MSB b12 */
101 ISIF_BIT_MSB_12 = 3,
102 /* MSB b11 */
103 ISIF_BIT_MSB_11 = 4,
104 /* MSB b10 */
105 ISIF_BIT_MSB_10 = 5,
106 /* MSB b9 */
107 ISIF_BIT_MSB_9 = 6,
108 /* MSB b8 */
109 ISIF_BIT_MSB_8 = 7,
110 /* MSB b7 */
111 ISIF_BIT_MSB_7 = 8,
112};
113
114struct isif_params_raw {
115 /* v4l2 pixel format */
116 unsigned long v4l2_pix_fmt;
117 /* isif pixel format */
118 enum isif_pixfmt pix_fmt;
119 /* isif frame format */
120 enum isif_frmfmt frm_fmt;
121 /* video window */
122 struct v4l2_rect win;
123 /* field polarity */
124 enum vpfe_pin_pol fid_pol;
125 /* interface VD polarity */
126 enum vpfe_pin_pol vd_pol;
127 /* interface HD polarity */
128 enum vpfe_pin_pol hd_pol;
129 /* buffer type. Applicable for interlaced mode */
130 enum isif_buftype buf_type;
131 /* cfa pattern */
132 enum isif_cfa_pattern cfa_pat;
133 /* Data MSB position */
134 enum isif_data_msb data_msb;
135 /* Enable horizontal flip */
136 unsigned char horz_flip_en;
137 /* Enable image invert vertically */
138 unsigned char image_invert_en;
139 unsigned char dpcm_predictor;
140 struct vpfe_isif_raw_config config_params;
141};
142
143enum isif_data_pack {
144 ISIF_PACK_16BIT = 0,
145 ISIF_PACK_12BIT = 1,
146 ISIF_PACK_8BIT = 2,
147};
148
149struct isif_gain_values {
150 unsigned int cr_gain;
151 unsigned int cgr_gain;
152 unsigned int cgb_gain;
153 unsigned int cb_gain;
154 unsigned int offset;
155};
156
157struct isif_oper_config {
158 struct isif_ycbcr_config ycbcr;
159 struct isif_params_raw bayer;
160 enum isif_data_pack data_pack;
161 struct isif_gain_values isif_gain_params;
162 void *__iomem base_addr;
163 void *__iomem linear_tbl0_addr;
164 void *__iomem linear_tbl1_addr;
165};
166
167#define ISIF_PAD_SINK 0
168#define ISIF_PAD_SOURCE 1
169
170#define ISIF_PADS_NUM 2
171
172enum isif_input_entity {
173 ISIF_INPUT_NONE = 0,
174 ISIF_INPUT_PARALLEL = 1,
175};
176
177#define ISIF_OUTPUT_NONE (0)
178#define ISIF_OUTPUT_MEMORY (1 << 0)
179#define ISIF_OUTPUT_IPIPEIF (1 << 1)
180
181struct vpfe_isif_device {
182 struct v4l2_subdev subdev;
183 struct media_pad pads[ISIF_PADS_NUM];
184 struct v4l2_mbus_framefmt formats[ISIF_PADS_NUM];
185 enum isif_input_entity input;
186 unsigned int output;
187 struct v4l2_ctrl_handler ctrls;
188 struct v4l2_rect crop;
189 struct isif_oper_config isif_cfg;
190 struct vpfe_video_device video_out;
191};
192
193enum v4l2_field vpfe_isif_get_fid(struct vpfe_device *vpfe_dev);
194void vpfe_isif_unregister_entities(struct vpfe_isif_device *isif);
195int vpfe_isif_register_entities(struct vpfe_isif_device *isif,
196 struct v4l2_device *dev);
197int vpfe_isif_init(struct vpfe_isif_device *isif, struct platform_device *pdev);
198void vpfe_isif_cleanup(struct vpfe_isif_device *vpfe_isif,
199 struct platform_device *pdev);
200void vpfe_isif_vidint1_isr(struct vpfe_isif_device *isif);
201void vpfe_isif_buffer_isr(struct vpfe_isif_device *isif);
202
203#endif /* _DAVINCI_VPFE_DM365_ISIF_H */
diff --git a/drivers/staging/media/davinci_vpfe/dm365_isif_regs.h b/drivers/staging/media/davinci_vpfe/dm365_isif_regs.h
new file mode 100644
index 000000000000..8aceabb43f8e
--- /dev/null
+++ b/drivers/staging/media/davinci_vpfe/dm365_isif_regs.h
@@ -0,0 +1,294 @@
1/*
2 * Copyright (C) 2012 Texas Instruments Inc
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation version 2.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Contributors:
18 * Manjunath Hadli <manjunath.hadli@ti.com>
19 * Prabhakar Lad <prabhakar.lad@ti.com>
20 */
21
22#ifndef _DAVINCI_VPFE_DM365_ISIF_REGS_H
23#define _DAVINCI_VPFE_DM365_ISIF_REGS_H
24
25/* ISIF registers relative offsets */
26#define SYNCEN 0x00
27#define MODESET 0x04
28#define HDW 0x08
29#define VDW 0x0c
30#define PPLN 0x10
31#define LPFR 0x14
32#define SPH 0x18
33#define LNH 0x1c
34#define SLV0 0x20
35#define SLV1 0x24
36#define LNV 0x28
37#define CULH 0x2c
38#define CULV 0x30
39#define HSIZE 0x34
40#define SDOFST 0x38
41#define CADU 0x3c
42#define CADL 0x40
43#define LINCFG0 0x44
44#define LINCFG1 0x48
45#define CCOLP 0x4c
46#define CRGAIN 0x50
47#define CGRGAIN 0x54
48#define CGBGAIN 0x58
49#define CBGAIN 0x5c
50#define COFSTA 0x60
51#define FLSHCFG0 0x64
52#define FLSHCFG1 0x68
53#define FLSHCFG2 0x6c
54#define VDINT0 0x70
55#define VDINT1 0x74
56#define VDINT2 0x78
57#define MISC 0x7c
58#define CGAMMAWD 0x80
59#define REC656IF 0x84
60#define CCDCFG 0x88
61/*****************************************************
62* Defect Correction registers
63*****************************************************/
64#define DFCCTL 0x8c
65#define VDFSATLV 0x90
66#define DFCMEMCTL 0x94
67#define DFCMEM0 0x98
68#define DFCMEM1 0x9c
69#define DFCMEM2 0xa0
70#define DFCMEM3 0xa4
71#define DFCMEM4 0xa8
72/****************************************************
73* Black Clamp registers
74****************************************************/
75#define CLAMPCFG 0xac
76#define CLDCOFST 0xb0
77#define CLSV 0xb4
78#define CLHWIN0 0xb8
79#define CLHWIN1 0xbc
80#define CLHWIN2 0xc0
81#define CLVRV 0xc4
82#define CLVWIN0 0xc8
83#define CLVWIN1 0xcc
84#define CLVWIN2 0xd0
85#define CLVWIN3 0xd4
86/****************************************************
87* Lense Shading Correction
88****************************************************/
89#define DATAHOFST 0xd8
90#define DATAVOFST 0xdc
91#define LSCHVAL 0xe0
92#define LSCVVAL 0xe4
93#define TWODLSCCFG 0xe8
94#define TWODLSCOFST 0xec
95#define TWODLSCINI 0xf0
96#define TWODLSCGRBU 0xf4
97#define TWODLSCGRBL 0xf8
98#define TWODLSCGROF 0xfc
99#define TWODLSCORBU 0x100
100#define TWODLSCORBL 0x104
101#define TWODLSCOROF 0x108
102#define TWODLSCIRQEN 0x10c
103#define TWODLSCIRQST 0x110
104/****************************************************
105* Data formatter
106****************************************************/
107#define FMTCFG 0x114
108#define FMTPLEN 0x118
109#define FMTSPH 0x11c
110#define FMTLNH 0x120
111#define FMTSLV 0x124
112#define FMTLNV 0x128
113#define FMTRLEN 0x12c
114#define FMTHCNT 0x130
115#define FMTAPTR_BASE 0x134
116/* Below macro for addresses FMTAPTR0 - FMTAPTR15 */
117#define FMTAPTR(i) (FMTAPTR_BASE + (i * 4))
118#define FMTPGMVF0 0x174
119#define FMTPGMVF1 0x178
120#define FMTPGMAPU0 0x17c
121#define FMTPGMAPU1 0x180
122#define FMTPGMAPS0 0x184
123#define FMTPGMAPS1 0x188
124#define FMTPGMAPS2 0x18c
125#define FMTPGMAPS3 0x190
126#define FMTPGMAPS4 0x194
127#define FMTPGMAPS5 0x198
128#define FMTPGMAPS6 0x19c
129#define FMTPGMAPS7 0x1a0
130/************************************************
131* Color Space Converter
132************************************************/
133#define CSCCTL 0x1a4
134#define CSCM0 0x1a8
135#define CSCM1 0x1ac
136#define CSCM2 0x1b0
137#define CSCM3 0x1b4
138#define CSCM4 0x1b8
139#define CSCM5 0x1bc
140#define CSCM6 0x1c0
141#define CSCM7 0x1c4
142#define OBWIN0 0x1c8
143#define OBWIN1 0x1cc
144#define OBWIN2 0x1d0
145#define OBWIN3 0x1d4
146#define OBVAL0 0x1d8
147#define OBVAL1 0x1dc
148#define OBVAL2 0x1e0
149#define OBVAL3 0x1e4
150#define OBVAL4 0x1e8
151#define OBVAL5 0x1ec
152#define OBVAL6 0x1f0
153#define OBVAL7 0x1f4
154#define CLKCTL 0x1f8
155
156/* Masks & Shifts below */
157#define START_PX_HOR_MASK 0x7fff
158#define NUM_PX_HOR_MASK 0x7fff
159#define START_VER_ONE_MASK 0x7fff
160#define START_VER_TWO_MASK 0x7fff
161#define NUM_LINES_VER 0x7fff
162
163/* gain - offset masks */
164#define OFFSET_MASK 0xfff
165#define GAIN_SDRAM_EN_SHIFT 12
166#define GAIN_IPIPE_EN_SHIFT 13
167#define GAIN_H3A_EN_SHIFT 14
168#define OFST_SDRAM_EN_SHIFT 8
169#define OFST_IPIPE_EN_SHIFT 9
170#define OFST_H3A_EN_SHIFT 10
171#define GAIN_OFFSET_EN_MASK 0x7700
172
173/* Culling */
174#define CULL_PAT_EVEN_LINE_SHIFT 8
175
176/* CCDCFG register */
177#define ISIF_YCINSWP_RAW (0x00 << 4)
178#define ISIF_YCINSWP_YCBCR (0x01 << 4)
179#define ISIF_CCDCFG_FIDMD_LATCH_VSYNC (0x00 << 6)
180#define ISIF_CCDCFG_WENLOG_AND (0x00 << 8)
181#define ISIF_CCDCFG_TRGSEL_WEN (0x00 << 9)
182#define ISIF_CCDCFG_EXTRG_DISABLE (0x00 << 10)
183#define ISIF_LATCH_ON_VSYNC_DISABLE (0x01 << 15)
184#define ISIF_LATCH_ON_VSYNC_ENABLE (0x00 << 15)
185#define ISIF_DATA_PACK_MASK 0x03
186#define ISIF_PIX_ORDER_SHIFT 11
187#define ISIF_PIX_ORDER_MASK 0x01
188#define ISIF_BW656_ENABLE (0x01 << 5)
189
190/* MODESET registers */
191#define ISIF_VDHDOUT_INPUT (0x00 << 0)
192#define ISIF_INPUT_MASK 0x03
193#define ISIF_INPUT_SHIFT 12
194#define ISIF_FID_POL_MASK 0x01
195#define ISIF_FID_POL_SHIFT 4
196#define ISIF_HD_POL_MASK 0x01
197#define ISIF_HD_POL_SHIFT 3
198#define ISIF_VD_POL_MASK 0x01
199#define ISIF_VD_POL_SHIFT 2
200#define ISIF_DATAPOL_NORMAL 0x00
201#define ISIF_DATAPOL_MASK 0x01
202#define ISIF_DATAPOL_SHIFT 6
203#define ISIF_EXWEN_DISABLE 0x00
204#define ISIF_EXWEN_MASK 0x01
205#define ISIF_EXWEN_SHIFT 5
206#define ISIF_FRM_FMT_MASK 0x01
207#define ISIF_FRM_FMT_SHIFT 7
208#define ISIF_DATASFT_MASK 0x07
209#define ISIF_DATASFT_SHIFT 8
210#define ISIF_LPF_SHIFT 14
211#define ISIF_LPF_MASK 0x1
212
213/* GAMMAWD registers */
214#define ISIF_ALAW_GAMA_WD_MASK 0xf
215#define ISIF_ALAW_GAMA_WD_SHIFT 1
216#define ISIF_ALAW_ENABLE 0x01
217#define ISIF_GAMMAWD_CFA_MASK 0x01
218#define ISIF_GAMMAWD_CFA_SHIFT 5
219
220/* HSIZE registers */
221#define ISIF_HSIZE_FLIP_MASK 0x01
222#define ISIF_HSIZE_FLIP_SHIFT 12
223#define ISIF_LINEOFST_MASK 0xfff
224
225/* MISC registers */
226#define ISIF_DPCM_EN_SHIFT 12
227#define ISIF_DPCM_PREDICTOR_SHIFT 13
228#define ISIF_DPCM_PREDICTOR_MASK 1
229
230/* Black clamp related */
231#define ISIF_BC_DCOFFSET_MASK 0x1fff
232#define ISIF_BC_MODE_COLOR_MASK 1
233#define ISIF_BC_MODE_COLOR_SHIFT 4
234#define ISIF_HORZ_BC_MODE_MASK 3
235#define ISIF_HORZ_BC_MODE_SHIFT 1
236#define ISIF_HORZ_BC_WIN_COUNT_MASK 0x1f
237#define ISIF_HORZ_BC_WIN_SEL_SHIFT 5
238#define ISIF_HORZ_BC_PIX_LIMIT_SHIFT 6
239#define ISIF_HORZ_BC_WIN_H_SIZE_MASK 3
240#define ISIF_HORZ_BC_WIN_H_SIZE_SHIFT 8
241#define ISIF_HORZ_BC_WIN_V_SIZE_MASK 3
242#define ISIF_HORZ_BC_WIN_V_SIZE_SHIFT 12
243#define ISIF_HORZ_BC_WIN_START_H_MASK 0x1fff
244#define ISIF_HORZ_BC_WIN_START_V_MASK 0x1fff
245#define ISIF_VERT_BC_OB_H_SZ_MASK 7
246#define ISIF_VERT_BC_RST_VAL_SEL_MASK 3
247#define ISIF_VERT_BC_RST_VAL_SEL_SHIFT 4
248#define ISIF_VERT_BC_LINE_AVE_COEF_SHIFT 8
249#define ISIF_VERT_BC_OB_START_HORZ_MASK 0x1fff
250#define ISIF_VERT_BC_OB_START_VERT_MASK 0x1fff
251#define ISIF_VERT_BC_OB_VERT_SZ_MASK 0x1fff
252#define ISIF_VERT_BC_RST_VAL_MASK 0xfff
253#define ISIF_BC_VERT_START_SUB_V_MASK 0x1fff
254
255/* VDFC registers */
256#define ISIF_VDFC_EN_SHIFT 4
257#define ISIF_VDFC_CORR_MOD_MASK 3
258#define ISIF_VDFC_CORR_MOD_SHIFT 5
259#define ISIF_VDFC_CORR_WHOLE_LN_SHIFT 7
260#define ISIF_VDFC_LEVEL_SHFT_MASK 7
261#define ISIF_VDFC_LEVEL_SHFT_SHIFT 8
262#define ISIF_VDFC_SAT_LEVEL_MASK 0xfff
263#define ISIF_VDFC_POS_MASK 0x1fff
264#define ISIF_DFCMEMCTL_DFCMARST_SHIFT 2
265
266/* CSC registers */
267#define ISIF_CSC_COEF_INTEG_MASK 7
268#define ISIF_CSC_COEF_DECIMAL_MASK 0x1f
269#define ISIF_CSC_COEF_INTEG_SHIFT 5
270#define ISIF_CSCM_MSB_SHIFT 8
271#define ISIF_DF_CSC_SPH_MASK 0x1fff
272#define ISIF_DF_CSC_LNH_MASK 0x1fff
273#define ISIF_DF_CSC_SLV_MASK 0x1fff
274#define ISIF_DF_CSC_LNV_MASK 0x1fff
275#define ISIF_DF_NUMLINES 0x7fff
276#define ISIF_DF_NUMPIX 0x1fff
277
278/* Offsets for LSC/DFC/Gain */
279#define ISIF_DATA_H_OFFSET_MASK 0x1fff
280#define ISIF_DATA_V_OFFSET_MASK 0x1fff
281
282/* Linearization */
283#define ISIF_LIN_CORRSFT_MASK 7
284#define ISIF_LIN_CORRSFT_SHIFT 4
285#define ISIF_LIN_SCALE_FACT_INTEG_SHIFT 10
286#define ISIF_LIN_SCALE_FACT_DECIMAL_MASK 0x3ff
287#define ISIF_LIN_ENTRY_MASK 0x3ff
288
289/* masks and shifts*/
290#define ISIF_SYNCEN_VDHDEN_MASK (1 << 0)
291#define ISIF_SYNCEN_WEN_MASK (1 << 1)
292#define ISIF_SYNCEN_WEN_SHIFT 1
293
294#endif /* _DAVINCI_VPFE_DM365_ISIF_REGS_H */
diff --git a/drivers/staging/media/davinci_vpfe/dm365_resizer.c b/drivers/staging/media/davinci_vpfe/dm365_resizer.c
new file mode 100644
index 000000000000..9cb0262b9b33
--- /dev/null
+++ b/drivers/staging/media/davinci_vpfe/dm365_resizer.c
@@ -0,0 +1,1999 @@
1/*
2 * Copyright (C) 2012 Texas Instruments Inc
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation version 2.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Contributors:
18 * Manjunath Hadli <manjunath.hadli@ti.com>
19 * Prabhakar Lad <prabhakar.lad@ti.com>
20 *
21 *
22 * Resizer allows upscaling or downscaling a image to a desired
23 * resolution. There are 2 resizer modules. both operating on the
24 * same input image, but can have different output resolution.
25 */
26
27#include "dm365_ipipe_hw.h"
28#include "dm365_resizer.h"
29
30#define MIN_IN_WIDTH 32
31#define MIN_IN_HEIGHT 32
32#define MAX_IN_WIDTH 4095
33#define MAX_IN_HEIGHT 4095
34#define MIN_OUT_WIDTH 16
35#define MIN_OUT_HEIGHT 2
36
37static const unsigned int resizer_input_formats[] = {
38 V4L2_MBUS_FMT_UYVY8_2X8,
39 V4L2_MBUS_FMT_Y8_1X8,
40 V4L2_MBUS_FMT_UV8_1X8,
41 V4L2_MBUS_FMT_SGRBG12_1X12,
42};
43
44static const unsigned int resizer_output_formats[] = {
45 V4L2_MBUS_FMT_UYVY8_2X8,
46 V4L2_MBUS_FMT_Y8_1X8,
47 V4L2_MBUS_FMT_UV8_1X8,
48 V4L2_MBUS_FMT_YDYUYDYV8_1X16,
49 V4L2_MBUS_FMT_SGRBG12_1X12,
50};
51
52/* resizer_calculate_line_length() - This function calculates the line length of
53 * various image planes at the input and
54 * output.
55 */
56static void
57resizer_calculate_line_length(enum v4l2_mbus_pixelcode pix, int width,
58 int height, int *line_len, int *line_len_c)
59{
60 *line_len = 0;
61 *line_len_c = 0;
62
63 if (pix == V4L2_MBUS_FMT_UYVY8_2X8 ||
64 pix == V4L2_MBUS_FMT_SGRBG12_1X12) {
65 *line_len = width << 1;
66 } else if (pix == V4L2_MBUS_FMT_Y8_1X8 ||
67 pix == V4L2_MBUS_FMT_UV8_1X8) {
68 *line_len = width;
69 *line_len_c = width;
70 } else {
71 /* YUV 420 */
72 /* round width to upper 32 byte boundary */
73 *line_len = width;
74 *line_len_c = width;
75 }
76 /* adjust the line len to be a multiple of 32 */
77 *line_len += 31;
78 *line_len &= ~0x1f;
79 *line_len_c += 31;
80 *line_len_c &= ~0x1f;
81}
82
83static inline int
84resizer_validate_output_image_format(struct device *dev,
85 struct v4l2_mbus_framefmt *format,
86 int *in_line_len, int *in_line_len_c)
87{
88 if (format->code != V4L2_MBUS_FMT_UYVY8_2X8 &&
89 format->code != V4L2_MBUS_FMT_Y8_1X8 &&
90 format->code != V4L2_MBUS_FMT_UV8_1X8 &&
91 format->code != V4L2_MBUS_FMT_YDYUYDYV8_1X16 &&
92 format->code != V4L2_MBUS_FMT_SGRBG12_1X12) {
93 dev_err(dev, "Invalid Mbus format, %d\n", format->code);
94 return -EINVAL;
95 }
96 if (!format->width || !format->height) {
97 dev_err(dev, "invalid width or height\n");
98 return -EINVAL;
99 }
100 resizer_calculate_line_length(format->code, format->width,
101 format->height, in_line_len, in_line_len_c);
102 return 0;
103}
104
105static void
106resizer_configure_passthru(struct vpfe_resizer_device *resizer, int bypass)
107{
108 struct resizer_params *param = &resizer->config;
109
110 param->rsz_rsc_param[RSZ_A].cen = DISABLE;
111 param->rsz_rsc_param[RSZ_A].yen = DISABLE;
112 param->rsz_rsc_param[RSZ_A].v_phs_y = 0;
113 param->rsz_rsc_param[RSZ_A].v_phs_c = 0;
114 param->rsz_rsc_param[RSZ_A].v_dif = 256;
115 param->rsz_rsc_param[RSZ_A].v_lpf_int_y = 0;
116 param->rsz_rsc_param[RSZ_A].v_lpf_int_c = 0;
117 param->rsz_rsc_param[RSZ_A].h_phs = 0;
118 param->rsz_rsc_param[RSZ_A].h_dif = 256;
119 param->rsz_rsc_param[RSZ_A].h_lpf_int_y = 0;
120 param->rsz_rsc_param[RSZ_A].h_lpf_int_c = 0;
121 param->rsz_rsc_param[RSZ_A].dscale_en = DISABLE;
122 param->rsz2rgb[RSZ_A].rgb_en = DISABLE;
123 param->rsz_en[RSZ_A] = ENABLE;
124 param->rsz_en[RSZ_B] = DISABLE;
125 if (bypass) {
126 param->rsz_rsc_param[RSZ_A].i_vps = 0;
127 param->rsz_rsc_param[RSZ_A].i_hps = 0;
128 /* Raw Bypass */
129 param->rsz_common.passthrough = BYPASS_ON;
130 }
131}
132
133static void
134configure_resizer_out_params(struct vpfe_resizer_device *resizer, int index,
135 void *output_spec, unsigned char partial,
136 unsigned flag)
137{
138 struct resizer_params *param = &resizer->config;
139 struct v4l2_mbus_framefmt *outformat;
140 struct vpfe_rsz_output_spec *output;
141
142 if (index == RSZ_A &&
143 resizer->resizer_a.output == RESIZER_OUTPUT_NONE) {
144 param->rsz_en[index] = DISABLE;
145 return;
146 }
147 if (index == RSZ_B &&
148 resizer->resizer_b.output == RESIZER_OUTPUT_NONE) {
149 param->rsz_en[index] = DISABLE;
150 return;
151 }
152 output = (struct vpfe_rsz_output_spec *)output_spec;
153 param->rsz_en[index] = ENABLE;
154 if (partial) {
155 param->rsz_rsc_param[index].h_flip = output->h_flip;
156 param->rsz_rsc_param[index].v_flip = output->v_flip;
157 param->rsz_rsc_param[index].v_typ_y = output->v_typ_y;
158 param->rsz_rsc_param[index].v_typ_c = output->v_typ_c;
159 param->rsz_rsc_param[index].v_lpf_int_y =
160 output->v_lpf_int_y;
161 param->rsz_rsc_param[index].v_lpf_int_c =
162 output->v_lpf_int_c;
163 param->rsz_rsc_param[index].h_typ_y = output->h_typ_y;
164 param->rsz_rsc_param[index].h_typ_c = output->h_typ_c;
165 param->rsz_rsc_param[index].h_lpf_int_y =
166 output->h_lpf_int_y;
167 param->rsz_rsc_param[index].h_lpf_int_c =
168 output->h_lpf_int_c;
169 param->rsz_rsc_param[index].dscale_en =
170 output->en_down_scale;
171 param->rsz_rsc_param[index].h_dscale_ave_sz =
172 output->h_dscale_ave_sz;
173 param->rsz_rsc_param[index].v_dscale_ave_sz =
174 output->v_dscale_ave_sz;
175 param->ext_mem_param[index].user_y_ofst =
176 (output->user_y_ofst + 31) & ~0x1f;
177 param->ext_mem_param[index].user_c_ofst =
178 (output->user_c_ofst + 31) & ~0x1f;
179 return;
180 }
181
182 if (index == RSZ_A)
183 outformat = &resizer->resizer_a.formats[RESIZER_PAD_SOURCE];
184 else
185 outformat = &resizer->resizer_b.formats[RESIZER_PAD_SOURCE];
186 param->rsz_rsc_param[index].o_vsz = outformat->height - 1;
187 param->rsz_rsc_param[index].o_hsz = outformat->width - 1;
188 param->ext_mem_param[index].rsz_sdr_ptr_s_y = output->vst_y;
189 param->ext_mem_param[index].rsz_sdr_ptr_e_y = outformat->height;
190 param->ext_mem_param[index].rsz_sdr_ptr_s_c = output->vst_c;
191 param->ext_mem_param[index].rsz_sdr_ptr_e_c = outformat->height;
192
193 if (!flag)
194 return;
195 /* update common parameters */
196 param->rsz_rsc_param[index].h_flip = output->h_flip;
197 param->rsz_rsc_param[index].v_flip = output->v_flip;
198 param->rsz_rsc_param[index].v_typ_y = output->v_typ_y;
199 param->rsz_rsc_param[index].v_typ_c = output->v_typ_c;
200 param->rsz_rsc_param[index].v_lpf_int_y = output->v_lpf_int_y;
201 param->rsz_rsc_param[index].v_lpf_int_c = output->v_lpf_int_c;
202 param->rsz_rsc_param[index].h_typ_y = output->h_typ_y;
203 param->rsz_rsc_param[index].h_typ_c = output->h_typ_c;
204 param->rsz_rsc_param[index].h_lpf_int_y = output->h_lpf_int_y;
205 param->rsz_rsc_param[index].h_lpf_int_c = output->h_lpf_int_c;
206 param->rsz_rsc_param[index].dscale_en = output->en_down_scale;
207 param->rsz_rsc_param[index].h_dscale_ave_sz = output->h_dscale_ave_sz;
208 param->rsz_rsc_param[index].v_dscale_ave_sz = output->h_dscale_ave_sz;
209 param->ext_mem_param[index].user_y_ofst =
210 (output->user_y_ofst + 31) & ~0x1f;
211 param->ext_mem_param[index].user_c_ofst =
212 (output->user_c_ofst + 31) & ~0x1f;
213}
214
215/*
216 * resizer_calculate_resize_ratios() - Calculates resize ratio for resizer
217 * A or B. This is called after setting
218 * the input size or output size.
219 * @resizer: Pointer to VPFE resizer subdevice.
220 * @index: index RSZ_A-resizer-A RSZ_B-resizer-B.
221 */
222void
223resizer_calculate_resize_ratios(struct vpfe_resizer_device *resizer, int index)
224{
225 struct resizer_params *param = &resizer->config;
226 struct v4l2_mbus_framefmt *informat, *outformat;
227
228 informat = &resizer->crop_resizer.formats[RESIZER_CROP_PAD_SINK];
229
230 if (index == RSZ_A)
231 outformat = &resizer->resizer_a.formats[RESIZER_PAD_SOURCE];
232 else
233 outformat = &resizer->resizer_b.formats[RESIZER_PAD_SOURCE];
234
235 if (outformat->field != V4L2_FIELD_INTERLACED)
236 param->rsz_rsc_param[index].v_dif =
237 ((informat->height) * 256) / (outformat->height);
238 else
239 param->rsz_rsc_param[index].v_dif =
240 ((informat->height >> 1) * 256) / (outformat->height);
241 param->rsz_rsc_param[index].h_dif =
242 ((informat->width) * 256) / (outformat->width);
243}
244
245void
246static resizer_enable_422_420_conversion(struct resizer_params *param,
247 int index, bool en)
248{
249 param->rsz_rsc_param[index].cen = en;
250 param->rsz_rsc_param[index].yen = en;
251}
252
253/* resizer_calculate_sdram_offsets() - This function calculates the offsets from
254 * start of buffer for the C plane when
255 * output format is YUV420SP. It also
256 * calculates the offsets from the start of
257 * the buffer when the image is flipped
258 * vertically or horizontally for ycbcr/y/c
259 * planes.
260 * @resizer: Pointer to resizer subdevice.
261 * @index: index RSZ_A-resizer-A RSZ_B-resizer-B.
262 */
263static int
264resizer_calculate_sdram_offsets(struct vpfe_resizer_device *resizer, int index)
265{
266 struct resizer_params *param = &resizer->config;
267 struct v4l2_mbus_framefmt *outformat;
268 int bytesperpixel = 2;
269 int image_height;
270 int image_width;
271 int yuv_420 = 0;
272 int offset = 0;
273
274 if (index == RSZ_A)
275 outformat = &resizer->resizer_a.formats[RESIZER_PAD_SOURCE];
276 else
277 outformat = &resizer->resizer_b.formats[RESIZER_PAD_SOURCE];
278
279 image_height = outformat->height + 1;
280 image_width = outformat->width + 1;
281 param->ext_mem_param[index].c_offset = 0;
282 param->ext_mem_param[index].flip_ofst_y = 0;
283 param->ext_mem_param[index].flip_ofst_c = 0;
284 if (outformat->code == V4L2_MBUS_FMT_YDYUYDYV8_1X16) {
285 /* YUV 420 */
286 yuv_420 = 1;
287 bytesperpixel = 1;
288 }
289
290 if (param->rsz_rsc_param[index].h_flip)
291 /* width * bytesperpixel - 1 */
292 offset = (image_width * bytesperpixel) - 1;
293 if (param->rsz_rsc_param[index].v_flip)
294 offset += (image_height - 1) *
295 param->ext_mem_param[index].rsz_sdr_oft_y;
296 param->ext_mem_param[index].flip_ofst_y = offset;
297 if (!yuv_420)
298 return 0;
299 offset = 0;
300 /* half height for c-plane */
301 if (param->rsz_rsc_param[index].h_flip)
302 /* width * bytesperpixel - 1 */
303 offset = image_width - 1;
304 if (param->rsz_rsc_param[index].v_flip)
305 offset += (((image_height >> 1) - 1) *
306 param->ext_mem_param[index].rsz_sdr_oft_c);
307 param->ext_mem_param[index].flip_ofst_c = offset;
308 param->ext_mem_param[index].c_offset =
309 param->ext_mem_param[index].rsz_sdr_oft_y * image_height;
310 return 0;
311}
312
313int resizer_configure_output_win(struct vpfe_resizer_device *resizer)
314{
315 struct resizer_params *param = &resizer->config;
316 struct vpfe_rsz_output_spec output_specs;
317 struct v4l2_mbus_framefmt *outformat;
318 int line_len_c;
319 int line_len;
320 int ret;
321
322 outformat = &resizer->resizer_a.formats[RESIZER_PAD_SOURCE];
323
324 output_specs.vst_y = param->user_config.vst;
325 if (outformat->code == V4L2_MBUS_FMT_YDYUYDYV8_1X16)
326 output_specs.vst_c = param->user_config.vst;
327
328 configure_resizer_out_params(resizer, RSZ_A, &output_specs, 0, 0);
329 resizer_calculate_line_length(outformat->code,
330 param->rsz_rsc_param[0].o_hsz + 1,
331 param->rsz_rsc_param[0].o_vsz + 1,
332 &line_len, &line_len_c);
333 param->ext_mem_param[0].rsz_sdr_oft_y = line_len;
334 param->ext_mem_param[0].rsz_sdr_oft_c = line_len_c;
335 resizer_calculate_resize_ratios(resizer, RSZ_A);
336 if (param->rsz_en[RSZ_B])
337 resizer_calculate_resize_ratios(resizer, RSZ_B);
338
339 if (outformat->code == V4L2_MBUS_FMT_YDYUYDYV8_1X16)
340 resizer_enable_422_420_conversion(param, RSZ_A, ENABLE);
341 else
342 resizer_enable_422_420_conversion(param, RSZ_A, DISABLE);
343
344 ret = resizer_calculate_sdram_offsets(resizer, RSZ_A);
345 if (!ret && param->rsz_en[RSZ_B])
346 ret = resizer_calculate_sdram_offsets(resizer, RSZ_B);
347
348 if (ret)
349 pr_err("Error in calculating sdram offsets\n");
350 return ret;
351}
352
353static int
354resizer_calculate_down_scale_f_div_param(struct device *dev,
355 int input_width, int output_width,
356 struct resizer_scale_param *param)
357{
358 /* rsz = R, input_width = H, output width = h in the equation */
359 unsigned int two_power;
360 unsigned int upper_h1;
361 unsigned int upper_h2;
362 unsigned int val1;
363 unsigned int val;
364 unsigned int rsz;
365 unsigned int h1;
366 unsigned int h2;
367 unsigned int o;
368 unsigned int n;
369
370 upper_h1 = input_width >> 1;
371 n = param->h_dscale_ave_sz;
372 /* 2 ^ (scale+1) */
373 two_power = 1 << (n + 1);
374 upper_h1 = (upper_h1 >> (n + 1)) << (n + 1);
375 upper_h2 = input_width - upper_h1;
376 if (upper_h2 % two_power) {
377 dev_err(dev, "frame halves to be a multiple of 2 power n+1\n");
378 return -EINVAL;
379 }
380 two_power = 1 << n;
381 rsz = (input_width << 8) / output_width;
382 val = rsz * two_power;
383 val = ((upper_h1 << 8) / val) + 1;
384 if (!(val % 2)) {
385 h1 = val;
386 } else {
387 val = upper_h1 << 8;
388 val >>= n + 1;
389 val -= rsz >> 1;
390 val /= rsz << 1;
391 val <<= 1;
392 val += 2;
393 h1 = val;
394 }
395 o = 10 + (two_power << 2);
396 if (((input_width << 7) / rsz) % 2)
397 o += (((CEIL(rsz, 1024)) << 1) << n);
398 h2 = output_width - h1;
399 /* phi */
400 val = (h1 * rsz) - (((upper_h1 - (o - 10)) / two_power) << 8);
401 /* skip */
402 val1 = ((val - 1024) >> 9) << 1;
403 param->f_div.num_passes = MAX_PASSES;
404 param->f_div.pass[0].o_hsz = h1 - 1;
405 param->f_div.pass[0].i_hps = 0;
406 param->f_div.pass[0].h_phs = 0;
407 param->f_div.pass[0].src_hps = 0;
408 param->f_div.pass[0].src_hsz = upper_h1 + o;
409 param->f_div.pass[1].o_hsz = h2 - 1;
410 param->f_div.pass[1].i_hps = 10 + (val1 * two_power);
411 param->f_div.pass[1].h_phs = (val - (val1 << 8));
412 param->f_div.pass[1].src_hps = upper_h1 - o;
413 param->f_div.pass[1].src_hsz = upper_h2 + o;
414
415 return 0;
416}
417
418static int
419resizer_configure_common_in_params(struct vpfe_resizer_device *resizer)
420{
421 struct vpfe_device *vpfe_dev = to_vpfe_device(resizer);
422 struct resizer_params *param = &resizer->config;
423 struct vpfe_rsz_config_params *user_config;
424 struct v4l2_mbus_framefmt *informat;
425
426 informat = &resizer->crop_resizer.formats[RESIZER_CROP_PAD_SINK];
427 user_config = &resizer->config.user_config;
428 param->rsz_common.vps = param->user_config.vst;
429 param->rsz_common.hps = param->user_config.hst;
430
431 if (vpfe_ipipeif_decimation_enabled(vpfe_dev))
432 param->rsz_common.hsz = (((informat->width - 1) *
433 IPIPEIF_RSZ_CONST) / vpfe_ipipeif_get_rsz(vpfe_dev));
434 else
435 param->rsz_common.hsz = informat->width - 1;
436
437 if (informat->field == V4L2_FIELD_INTERLACED)
438 param->rsz_common.vsz = (informat->height - 1) >> 1;
439 else
440 param->rsz_common.vsz = informat->height - 1;
441
442 param->rsz_common.raw_flip = 0;
443
444 if (resizer->crop_resizer.input == RESIZER_CROP_INPUT_IPIPEIF)
445 param->rsz_common.source = IPIPEIF_DATA;
446 else
447 param->rsz_common.source = IPIPE_DATA;
448
449 switch (informat->code) {
450 case V4L2_MBUS_FMT_UYVY8_2X8:
451 param->rsz_common.src_img_fmt = RSZ_IMG_422;
452 param->rsz_common.raw_flip = 0;
453 break;
454
455 case V4L2_MBUS_FMT_Y8_1X8:
456 param->rsz_common.src_img_fmt = RSZ_IMG_420;
457 /* Select y */
458 param->rsz_common.y_c = 0;
459 param->rsz_common.raw_flip = 0;
460 break;
461
462 case V4L2_MBUS_FMT_UV8_1X8:
463 param->rsz_common.src_img_fmt = RSZ_IMG_420;
464 /* Select y */
465 param->rsz_common.y_c = 1;
466 param->rsz_common.raw_flip = 0;
467 break;
468
469 case V4L2_MBUS_FMT_SGRBG12_1X12:
470 param->rsz_common.raw_flip = 1;
471 break;
472
473 default:
474 param->rsz_common.src_img_fmt = RSZ_IMG_422;
475 param->rsz_common.source = IPIPE_DATA;
476 }
477
478 param->rsz_common.yuv_y_min = user_config->yuv_y_min;
479 param->rsz_common.yuv_y_max = user_config->yuv_y_max;
480 param->rsz_common.yuv_c_min = user_config->yuv_c_min;
481 param->rsz_common.yuv_c_max = user_config->yuv_c_max;
482 param->rsz_common.out_chr_pos = user_config->out_chr_pos;
483 param->rsz_common.rsz_seq_crv = user_config->chroma_sample_even;
484
485 return 0;
486}
487static int
488resizer_configure_in_continious_mode(struct vpfe_resizer_device *resizer)
489{
490 struct device *dev = resizer->crop_resizer.subdev.v4l2_dev->dev;
491 struct resizer_params *param = &resizer->config;
492 struct vpfe_rsz_config_params *cont_config;
493 int line_len_c;
494 int line_len;
495 int ret;
496
497 if (resizer->resizer_a.output != RESIZER_OUPUT_MEMORY) {
498 dev_err(dev, "enable resizer - Resizer-A\n");
499 return -EINVAL;
500 }
501
502 cont_config = &resizer->config.user_config;
503 param->rsz_en[RSZ_A] = ENABLE;
504 configure_resizer_out_params(resizer, RSZ_A,
505 &cont_config->output1, 1, 0);
506 param->rsz_en[RSZ_B] = DISABLE;
507 param->oper_mode = RESIZER_MODE_CONTINIOUS;
508
509 if (resizer->resizer_b.output == RESIZER_OUPUT_MEMORY) {
510 struct v4l2_mbus_framefmt *outformat2;
511
512 param->rsz_en[RSZ_B] = ENABLE;
513 outformat2 = &resizer->resizer_b.formats[RESIZER_PAD_SOURCE];
514 ret = resizer_validate_output_image_format(dev, outformat2,
515 &line_len, &line_len_c);
516 if (ret)
517 return ret;
518 param->ext_mem_param[RSZ_B].rsz_sdr_oft_y = line_len;
519 param->ext_mem_param[RSZ_B].rsz_sdr_oft_c = line_len_c;
520 configure_resizer_out_params(resizer, RSZ_B,
521 &cont_config->output2, 0, 1);
522 if (outformat2->code == V4L2_MBUS_FMT_YDYUYDYV8_1X16)
523 resizer_enable_422_420_conversion(param,
524 RSZ_B, ENABLE);
525 else
526 resizer_enable_422_420_conversion(param,
527 RSZ_B, DISABLE);
528 }
529 resizer_configure_common_in_params(resizer);
530 ret = resizer_configure_output_win(resizer);
531 if (ret)
532 return ret;
533
534 param->rsz_common.passthrough = cont_config->bypass;
535 if (cont_config->bypass)
536 resizer_configure_passthru(resizer, 1);
537
538 return 0;
539}
540
541static inline int
542resizer_validate_input_image_format(struct device *dev,
543 enum v4l2_mbus_pixelcode pix,
544 int width, int height, int *line_len)
545{
546 int val;
547
548 if (pix != V4L2_MBUS_FMT_UYVY8_2X8 &&
549 pix != V4L2_MBUS_FMT_Y8_1X8 &&
550 pix != V4L2_MBUS_FMT_UV8_1X8 &&
551 pix != V4L2_MBUS_FMT_SGRBG12_1X12) {
552 dev_err(dev,
553 "resizer validate output: pix format not supported, %d\n", pix);
554 return -EINVAL;
555 }
556
557 if (!width || !height) {
558 dev_err(dev,
559 "resizer validate input: invalid width or height\n");
560 return -EINVAL;
561 }
562
563 if (pix == V4L2_MBUS_FMT_UV8_1X8)
564 resizer_calculate_line_length(pix, width,
565 height, &val, line_len);
566 else
567 resizer_calculate_line_length(pix, width,
568 height, line_len, &val);
569
570 return 0;
571}
572
573static int
574resizer_validate_decimation(struct device *dev, enum ipipeif_decimation dec_en,
575 unsigned char rsz, unsigned char frame_div_mode_en,
576 int width)
577{
578 if (dec_en && frame_div_mode_en) {
579 dev_err(dev,
580 "dec_en & frame_div_mode_en can not enabled simultaneously\n");
581 return -EINVAL;
582 }
583
584 if (frame_div_mode_en) {
585 dev_err(dev, "frame_div_mode mode not supported\n");
586 return -EINVAL;
587 }
588
589 if (!dec_en)
590 return 0;
591
592 if (width <= VPFE_IPIPE_MAX_INPUT_WIDTH) {
593 dev_err(dev,
594 "image width to be more than %d for decimation\n",
595 VPFE_IPIPE_MAX_INPUT_WIDTH);
596 return -EINVAL;
597 }
598
599 if (rsz < IPIPEIF_RSZ_MIN || rsz > IPIPEIF_RSZ_MAX) {
600 dev_err(dev, "rsz range is %d to %d\n",
601 IPIPEIF_RSZ_MIN, IPIPEIF_RSZ_MAX);
602 return -EINVAL;
603 }
604
605 return 0;
606}
607
608/* resizer_calculate_normal_f_div_param() - Algorithm to calculate the frame
609 * division parameters for resizer.
610 * in normal mode.
611 */
612static int
613resizer_calculate_normal_f_div_param(struct device *dev, int input_width,
614 int output_width, struct resizer_scale_param *param)
615{
616 /* rsz = R, input_width = H, output width = h in the equation */
617 unsigned int val1;
618 unsigned int rsz;
619 unsigned int val;
620 unsigned int h1;
621 unsigned int h2;
622 unsigned int o;
623
624 if (output_width > input_width) {
625 dev_err(dev, "frame div mode is used for scale down only\n");
626 return -EINVAL;
627 }
628
629 rsz = (input_width << 8) / output_width;
630 val = rsz << 1;
631 val = ((input_width << 8) / val) + 1;
632 o = 14;
633 if (!(val % 2)) {
634 h1 = val;
635 } else {
636 val = (input_width << 7);
637 val -= rsz >> 1;
638 val /= rsz << 1;
639 val <<= 1;
640 val += 2;
641 o += ((CEIL(rsz, 1024)) << 1);
642 h1 = val;
643 }
644 h2 = output_width - h1;
645 /* phi */
646 val = (h1 * rsz) - (((input_width >> 1) - o) << 8);
647 /* skip */
648 val1 = ((val - 1024) >> 9) << 1;
649 param->f_div.num_passes = MAX_PASSES;
650 param->f_div.pass[0].o_hsz = h1 - 1;
651 param->f_div.pass[0].i_hps = 0;
652 param->f_div.pass[0].h_phs = 0;
653 param->f_div.pass[0].src_hps = 0;
654 param->f_div.pass[0].src_hsz = (input_width >> 2) + o;
655 param->f_div.pass[1].o_hsz = h2 - 1;
656 param->f_div.pass[1].i_hps = val1;
657 param->f_div.pass[1].h_phs = (val - (val1 << 8));
658 param->f_div.pass[1].src_hps = (input_width >> 2) - o;
659 param->f_div.pass[1].src_hsz = (input_width >> 2) + o;
660
661 return 0;
662}
663
664static int
665resizer_configure_in_single_shot_mode(struct vpfe_resizer_device *resizer)
666{
667 struct vpfe_rsz_config_params *config = &resizer->config.user_config;
668 struct device *dev = resizer->crop_resizer.subdev.v4l2_dev->dev;
669 struct vpfe_device *vpfe_dev = to_vpfe_device(resizer);
670 struct v4l2_mbus_framefmt *outformat1, *outformat2;
671 struct resizer_params *param = &resizer->config;
672 struct v4l2_mbus_framefmt *informat;
673 int decimation;
674 int line_len_c;
675 int line_len;
676 int rsz;
677 int ret;
678
679 informat = &resizer->crop_resizer.formats[RESIZER_CROP_PAD_SINK];
680 outformat1 = &resizer->resizer_a.formats[RESIZER_PAD_SOURCE];
681 outformat2 = &resizer->resizer_b.formats[RESIZER_PAD_SOURCE];
682
683 decimation = vpfe_ipipeif_decimation_enabled(vpfe_dev);
684 rsz = vpfe_ipipeif_get_rsz(vpfe_dev);
685 if (decimation && param->user_config.frame_div_mode_en) {
686 dev_err(dev,
687 "dec_en & frame_div_mode_en cannot enabled simultaneously\n");
688 return -EINVAL;
689 }
690
691 ret = resizer_validate_decimation(dev, decimation, rsz,
692 param->user_config.frame_div_mode_en, informat->width);
693 if (ret)
694 return -EINVAL;
695
696 ret = resizer_validate_input_image_format(dev, informat->code,
697 informat->width, informat->height, &line_len);
698 if (ret)
699 return -EINVAL;
700
701 if (resizer->resizer_a.output != RESIZER_OUTPUT_NONE) {
702 param->rsz_en[RSZ_A] = ENABLE;
703 ret = resizer_validate_output_image_format(dev, outformat1,
704 &line_len, &line_len_c);
705 if (ret)
706 return ret;
707 param->ext_mem_param[RSZ_A].rsz_sdr_oft_y = line_len;
708 param->ext_mem_param[RSZ_A].rsz_sdr_oft_c = line_len_c;
709 configure_resizer_out_params(resizer, RSZ_A,
710 &param->user_config.output1, 0, 1);
711
712 if (outformat1->code == V4L2_MBUS_FMT_SGRBG12_1X12)
713 param->rsz_common.raw_flip = 1;
714 else
715 param->rsz_common.raw_flip = 0;
716
717 if (outformat1->code == V4L2_MBUS_FMT_YDYUYDYV8_1X16)
718 resizer_enable_422_420_conversion(param,
719 RSZ_A, ENABLE);
720 else
721 resizer_enable_422_420_conversion(param,
722 RSZ_A, DISABLE);
723 }
724
725 if (resizer->resizer_b.output != RESIZER_OUTPUT_NONE) {
726 param->rsz_en[RSZ_B] = ENABLE;
727 ret = resizer_validate_output_image_format(dev, outformat2,
728 &line_len, &line_len_c);
729 if (ret)
730 return ret;
731 param->ext_mem_param[RSZ_B].rsz_sdr_oft_y = line_len;
732 param->ext_mem_param[RSZ_B].rsz_sdr_oft_c = line_len_c;
733 configure_resizer_out_params(resizer, RSZ_B,
734 &param->user_config.output2, 0, 1);
735 if (outformat2->code == V4L2_MBUS_FMT_YDYUYDYV8_1X16)
736 resizer_enable_422_420_conversion(param,
737 RSZ_B, ENABLE);
738 else
739 resizer_enable_422_420_conversion(param,
740 RSZ_B, DISABLE);
741 }
742
743 resizer_configure_common_in_params(resizer);
744 if (resizer->resizer_a.output != RESIZER_OUTPUT_NONE) {
745 resizer_calculate_resize_ratios(resizer, RSZ_A);
746 resizer_calculate_sdram_offsets(resizer, RSZ_A);
747 /* Overriding resize ratio calculation */
748 if (informat->code == V4L2_MBUS_FMT_UV8_1X8) {
749 param->rsz_rsc_param[RSZ_A].v_dif =
750 (((informat->height + 1) * 2) * 256) /
751 (param->rsz_rsc_param[RSZ_A].o_vsz + 1);
752 }
753 }
754
755 if (resizer->resizer_b.output != RESIZER_OUTPUT_NONE) {
756 resizer_calculate_resize_ratios(resizer, RSZ_B);
757 resizer_calculate_sdram_offsets(resizer, RSZ_B);
758 /* Overriding resize ratio calculation */
759 if (informat->code == V4L2_MBUS_FMT_UV8_1X8) {
760 param->rsz_rsc_param[RSZ_B].v_dif =
761 (((informat->height + 1) * 2) * 256) /
762 (param->rsz_rsc_param[RSZ_B].o_vsz + 1);
763 }
764 }
765 if (param->user_config.frame_div_mode_en &&
766 param->rsz_en[RSZ_A]) {
767 if (!param->rsz_rsc_param[RSZ_A].dscale_en)
768 ret = resizer_calculate_normal_f_div_param(dev,
769 informat->width,
770 param->rsz_rsc_param[RSZ_A].o_vsz + 1,
771 &param->rsz_rsc_param[RSZ_A]);
772 else
773 ret = resizer_calculate_down_scale_f_div_param(dev,
774 informat->width,
775 param->rsz_rsc_param[RSZ_A].o_vsz + 1,
776 &param->rsz_rsc_param[RSZ_A]);
777 if (ret)
778 return -EINVAL;
779 }
780 if (param->user_config.frame_div_mode_en &&
781 param->rsz_en[RSZ_B]) {
782 if (!param->rsz_rsc_param[RSZ_B].dscale_en)
783 ret = resizer_calculate_normal_f_div_param(dev,
784 informat->width,
785 param->rsz_rsc_param[RSZ_B].o_vsz + 1,
786 &param->rsz_rsc_param[RSZ_B]);
787 else
788 ret = resizer_calculate_down_scale_f_div_param(dev,
789 informat->width,
790 param->rsz_rsc_param[RSZ_B].o_vsz + 1,
791 &param->rsz_rsc_param[RSZ_B]);
792 if (ret)
793 return -EINVAL;
794 }
795 param->rsz_common.passthrough = config->bypass;
796 if (config->bypass)
797 resizer_configure_passthru(resizer, 1);
798 return 0;
799}
800
801static void
802resizer_set_defualt_configuration(struct vpfe_resizer_device *resizer)
803{
804#define WIDTH_I 640
805#define HEIGHT_I 480
806#define WIDTH_O 640
807#define HEIGHT_O 480
808 const struct resizer_params rsz_default_config = {
809 .oper_mode = RESIZER_MODE_ONE_SHOT,
810 .rsz_common = {
811 .vsz = HEIGHT_I - 1,
812 .hsz = WIDTH_I - 1,
813 .src_img_fmt = RSZ_IMG_422,
814 .raw_flip = 1, /* flip preserve Raw format */
815 .source = IPIPE_DATA,
816 .passthrough = BYPASS_OFF,
817 .yuv_y_max = 255,
818 .yuv_c_max = 255,
819 .rsz_seq_crv = DISABLE,
820 .out_chr_pos = VPFE_IPIPE_YUV422_CHR_POS_COSITE,
821 },
822 .rsz_rsc_param = {
823 {
824 .h_flip = DISABLE,
825 .v_flip = DISABLE,
826 .cen = DISABLE,
827 .yen = DISABLE,
828 .o_vsz = HEIGHT_O - 1,
829 .o_hsz = WIDTH_O - 1,
830 .v_dif = 256,
831 .v_typ_y = VPFE_RSZ_INTP_CUBIC,
832 .h_typ_c = VPFE_RSZ_INTP_CUBIC,
833 .h_dif = 256,
834 .h_typ_y = VPFE_RSZ_INTP_CUBIC,
835 .h_typ_c = VPFE_RSZ_INTP_CUBIC,
836 .h_dscale_ave_sz =
837 VPFE_IPIPE_DWN_SCALE_1_OVER_2,
838 .v_dscale_ave_sz =
839 VPFE_IPIPE_DWN_SCALE_1_OVER_2,
840 },
841 {
842 .h_flip = DISABLE,
843 .v_flip = DISABLE,
844 .cen = DISABLE,
845 .yen = DISABLE,
846 .o_vsz = HEIGHT_O - 1,
847 .o_hsz = WIDTH_O - 1,
848 .v_dif = 256,
849 .v_typ_y = VPFE_RSZ_INTP_CUBIC,
850 .h_typ_c = VPFE_RSZ_INTP_CUBIC,
851 .h_dif = 256,
852 .h_typ_y = VPFE_RSZ_INTP_CUBIC,
853 .h_typ_c = VPFE_RSZ_INTP_CUBIC,
854 .h_dscale_ave_sz =
855 VPFE_IPIPE_DWN_SCALE_1_OVER_2,
856 .v_dscale_ave_sz =
857 VPFE_IPIPE_DWN_SCALE_1_OVER_2,
858 },
859 },
860 .rsz2rgb = {
861 {
862 .rgb_en = DISABLE
863 },
864 {
865 .rgb_en = DISABLE
866 }
867 },
868 .ext_mem_param = {
869 {
870 .rsz_sdr_oft_y = WIDTH_O << 1,
871 .rsz_sdr_ptr_e_y = HEIGHT_O,
872 .rsz_sdr_oft_c = WIDTH_O,
873 .rsz_sdr_ptr_e_c = HEIGHT_O >> 1,
874 },
875 {
876 .rsz_sdr_oft_y = WIDTH_O << 1,
877 .rsz_sdr_ptr_e_y = HEIGHT_O,
878 .rsz_sdr_oft_c = WIDTH_O,
879 .rsz_sdr_ptr_e_c = HEIGHT_O,
880 },
881 },
882 .rsz_en[0] = ENABLE,
883 .rsz_en[1] = DISABLE,
884 .user_config = {
885 .output1 = {
886 .v_typ_y = VPFE_RSZ_INTP_CUBIC,
887 .v_typ_c = VPFE_RSZ_INTP_CUBIC,
888 .h_typ_y = VPFE_RSZ_INTP_CUBIC,
889 .h_typ_c = VPFE_RSZ_INTP_CUBIC,
890 .h_dscale_ave_sz =
891 VPFE_IPIPE_DWN_SCALE_1_OVER_2,
892 .v_dscale_ave_sz =
893 VPFE_IPIPE_DWN_SCALE_1_OVER_2,
894 },
895 .output2 = {
896 .v_typ_y = VPFE_RSZ_INTP_CUBIC,
897 .v_typ_c = VPFE_RSZ_INTP_CUBIC,
898 .h_typ_y = VPFE_RSZ_INTP_CUBIC,
899 .h_typ_c = VPFE_RSZ_INTP_CUBIC,
900 .h_dscale_ave_sz =
901 VPFE_IPIPE_DWN_SCALE_1_OVER_2,
902 .v_dscale_ave_sz =
903 VPFE_IPIPE_DWN_SCALE_1_OVER_2,
904 },
905 .yuv_y_max = 255,
906 .yuv_c_max = 255,
907 .out_chr_pos = VPFE_IPIPE_YUV422_CHR_POS_COSITE,
908 },
909 };
910 memset(&resizer->config, 0, sizeof(struct resizer_params));
911 memcpy(&resizer->config, &rsz_default_config,
912 sizeof(struct resizer_params));
913}
914
915/*
916 * resizer_set_configuration() - set resizer config
917 * @resizer: vpfe resizer device pointer.
918 * @chan_config: resizer channel configuration.
919 */
920static int
921resizer_set_configuration(struct vpfe_resizer_device *resizer,
922 struct vpfe_rsz_config *chan_config)
923{
924 if (!chan_config->config)
925 resizer_set_defualt_configuration(resizer);
926 else
927 if (copy_from_user(&resizer->config.user_config,
928 chan_config->config, sizeof(struct vpfe_rsz_config_params)))
929 return -EFAULT;
930
931 return 0;
932}
933
934/*
935 * resizer_get_configuration() - get resizer config
936 * @resizer: vpfe resizer device pointer.
937 * @channel: image processor logical channel.
938 * @chan_config: resizer channel configuration.
939 */
940static int
941resizer_get_configuration(struct vpfe_resizer_device *resizer,
942 struct vpfe_rsz_config *chan_config)
943{
944 struct device *dev = resizer->crop_resizer.subdev.v4l2_dev->dev;
945
946 if (!chan_config->config) {
947 dev_err(dev, "Resizer channel invalid pointer\n");
948 return -EINVAL;
949 }
950
951 if (copy_to_user((void *)chan_config->config,
952 (void *)&resizer->config.user_config,
953 sizeof(struct vpfe_rsz_config_params))) {
954 dev_err(dev, "resizer_get_configuration: Error in copy to user\n");
955 return -EFAULT;
956 }
957
958 return 0;
959}
960
961/*
962 * VPFE video operations
963 */
964
965/*
966 * resizer_a_video_out_queue() - RESIZER-A video out queue
967 * @vpfe_dev: vpfe device pointer.
968 * @addr: buffer address.
969 */
970static int resizer_a_video_out_queue(struct vpfe_device *vpfe_dev,
971 unsigned long addr)
972{
973 struct vpfe_resizer_device *resizer = &vpfe_dev->vpfe_resizer;
974
975 return resizer_set_outaddr(resizer->base_addr,
976 &resizer->config, RSZ_A, addr);
977}
978
979/*
980 * resizer_b_video_out_queue() - RESIZER-B video out queue
981 * @vpfe_dev: vpfe device pointer.
982 * @addr: buffer address.
983 */
984static int resizer_b_video_out_queue(struct vpfe_device *vpfe_dev,
985 unsigned long addr)
986{
987 struct vpfe_resizer_device *resizer = &vpfe_dev->vpfe_resizer;
988
989 return resizer_set_outaddr(resizer->base_addr,
990 &resizer->config, RSZ_B, addr);
991}
992
993static const struct vpfe_video_operations resizer_a_video_ops = {
994 .queue = resizer_a_video_out_queue,
995};
996
997static const struct vpfe_video_operations resizer_b_video_ops = {
998 .queue = resizer_b_video_out_queue,
999};
1000
1001static void resizer_enable(struct vpfe_resizer_device *resizer, int en)
1002{
1003 struct vpfe_device *vpfe_dev = to_vpfe_device(resizer);
1004 u16 ipipeif_sink = vpfe_dev->vpfe_ipipeif.input;
1005 unsigned char val;
1006
1007 if (resizer->crop_resizer.input == RESIZER_CROP_INPUT_NONE)
1008 return;
1009
1010 if (resizer->crop_resizer.input == RESIZER_CROP_INPUT_IPIPEIF &&
1011 ipipeif_sink == IPIPEIF_INPUT_MEMORY) {
1012 do {
1013 val = regr_rsz(resizer->base_addr, RSZ_SRC_EN);
1014 } while (val);
1015
1016 if (resizer->resizer_a.output != RESIZER_OUTPUT_NONE) {
1017 do {
1018 val = regr_rsz(resizer->base_addr, RSZ_A);
1019 } while (val);
1020 }
1021 if (resizer->resizer_b.output != RESIZER_OUTPUT_NONE) {
1022 do {
1023 val = regr_rsz(resizer->base_addr, RSZ_B);
1024 } while (val);
1025 }
1026 }
1027 if (resizer->resizer_a.output != RESIZER_OUTPUT_NONE)
1028 rsz_enable(resizer->base_addr, RSZ_A, en);
1029
1030 if (resizer->resizer_b.output != RESIZER_OUTPUT_NONE)
1031 rsz_enable(resizer->base_addr, RSZ_B, en);
1032}
1033
1034
1035/*
1036 * resizer_ss_isr() - resizer module single-shot buffer scheduling isr
1037 * @resizer: vpfe resizer device pointer.
1038 */
1039static void resizer_ss_isr(struct vpfe_resizer_device *resizer)
1040{
1041 struct vpfe_video_device *video_out = &resizer->resizer_a.video_out;
1042 struct vpfe_video_device *video_out2 = &resizer->resizer_b.video_out;
1043 struct vpfe_device *vpfe_dev = to_vpfe_device(resizer);
1044 struct vpfe_pipeline *pipe = &video_out->pipe;
1045 u16 ipipeif_sink = vpfe_dev->vpfe_ipipeif.input;
1046 u32 val;
1047
1048 if (ipipeif_sink != IPIPEIF_INPUT_MEMORY)
1049 return;
1050
1051 if (resizer->resizer_a.output == RESIZER_OUPUT_MEMORY) {
1052 val = vpss_dma_complete_interrupt();
1053 if (val != 0 && val != 2)
1054 return;
1055 }
1056
1057 if (resizer->resizer_a.output == RESIZER_OUPUT_MEMORY) {
1058 spin_lock(&video_out->dma_queue_lock);
1059 vpfe_video_process_buffer_complete(video_out);
1060 video_out->state = VPFE_VIDEO_BUFFER_NOT_QUEUED;
1061 vpfe_video_schedule_next_buffer(video_out);
1062 spin_unlock(&video_out->dma_queue_lock);
1063 }
1064
1065 /* If resizer B is enabled */
1066 if (pipe->output_num > 1 && resizer->resizer_b.output ==
1067 RESIZER_OUPUT_MEMORY) {
1068 spin_lock(&video_out->dma_queue_lock);
1069 vpfe_video_process_buffer_complete(video_out2);
1070 video_out2->state = VPFE_VIDEO_BUFFER_NOT_QUEUED;
1071 vpfe_video_schedule_next_buffer(video_out2);
1072 spin_unlock(&video_out2->dma_queue_lock);
1073 }
1074
1075 /* start HW if buffers are queued */
1076 if (vpfe_video_is_pipe_ready(pipe) &&
1077 resizer->resizer_a.output == RESIZER_OUPUT_MEMORY) {
1078 resizer_enable(resizer, 1);
1079 vpfe_ipipe_enable(vpfe_dev, 1);
1080 vpfe_ipipeif_enable(vpfe_dev);
1081 }
1082}
1083
1084/*
1085 * vpfe_resizer_buffer_isr() - resizer module buffer scheduling isr
1086 * @resizer: vpfe resizer device pointer.
1087 */
1088void vpfe_resizer_buffer_isr(struct vpfe_resizer_device *resizer)
1089{
1090 struct vpfe_device *vpfe_dev = to_vpfe_device(resizer);
1091 struct vpfe_video_device *video_out = &resizer->resizer_a.video_out;
1092 struct vpfe_video_device *video_out2 = &resizer->resizer_b.video_out;
1093 struct vpfe_pipeline *pipe = &resizer->resizer_a.video_out.pipe;
1094 enum v4l2_field field;
1095 int fid;
1096
1097 if (!video_out->started)
1098 return;
1099
1100 if (resizer->crop_resizer.input == RESIZER_CROP_INPUT_NONE)
1101 return;
1102
1103 field = video_out->fmt.fmt.pix.field;
1104 if (field == V4L2_FIELD_NONE) {
1105 /* handle progressive frame capture */
1106 if (video_out->cur_frm != video_out->next_frm) {
1107 vpfe_video_process_buffer_complete(video_out);
1108 if (pipe->output_num > 1)
1109 vpfe_video_process_buffer_complete(video_out2);
1110 }
1111
1112 video_out->skip_frame_count--;
1113 if (!video_out->skip_frame_count) {
1114 video_out->skip_frame_count =
1115 video_out->skip_frame_count_init;
1116 rsz_src_enable(resizer->base_addr, 1);
1117 } else {
1118 rsz_src_enable(resizer->base_addr, 0);
1119 }
1120 return;
1121 }
1122
1123 /* handle interlaced frame capture */
1124 fid = vpfe_isif_get_fid(vpfe_dev);
1125
1126 /* switch the software maintained field id */
1127 video_out->field_id ^= 1;
1128 if (fid == video_out->field_id) {
1129 /*
1130 * we are in-sync here,continue.
1131 * One frame is just being captured. If the
1132 * next frame is available, release the current
1133 * frame and move on
1134 */
1135 if (fid == 0 && video_out->cur_frm != video_out->next_frm) {
1136 vpfe_video_process_buffer_complete(video_out);
1137 if (pipe->output_num > 1)
1138 vpfe_video_process_buffer_complete(video_out2);
1139 }
1140 } else if (fid == 0) {
1141 /*
1142 * out of sync. Recover from any hardware out-of-sync.
1143 * May loose one frame
1144 */
1145 video_out->field_id = fid;
1146 }
1147}
1148
1149/*
1150 * vpfe_resizer_dma_isr() - resizer module dma isr
1151 * @resizer: vpfe resizer device pointer.
1152 */
1153void vpfe_resizer_dma_isr(struct vpfe_resizer_device *resizer)
1154{
1155 struct vpfe_video_device *video_out2 = &resizer->resizer_b.video_out;
1156 struct vpfe_video_device *video_out = &resizer->resizer_a.video_out;
1157 struct vpfe_device *vpfe_dev = to_vpfe_device(resizer);
1158 struct vpfe_pipeline *pipe = &video_out->pipe;
1159 int schedule_capture = 0;
1160 enum v4l2_field field;
1161 int fid;
1162
1163 if (!video_out->started)
1164 return;
1165
1166 if (pipe->state == VPFE_PIPELINE_STREAM_SINGLESHOT) {
1167 resizer_ss_isr(resizer);
1168 return;
1169 }
1170
1171 field = video_out->fmt.fmt.pix.field;
1172 if (field == V4L2_FIELD_NONE) {
1173 if (!list_empty(&video_out->dma_queue) &&
1174 video_out->cur_frm == video_out->next_frm)
1175 schedule_capture = 1;
1176 } else {
1177 fid = vpfe_isif_get_fid(vpfe_dev);
1178 if (fid == video_out->field_id) {
1179 /* we are in-sync here,continue */
1180 if (fid == 1 && !list_empty(&video_out->dma_queue) &&
1181 video_out->cur_frm == video_out->next_frm)
1182 schedule_capture = 1;
1183 }
1184 }
1185
1186 if (!schedule_capture)
1187 return;
1188
1189 spin_lock(&video_out->dma_queue_lock);
1190 vpfe_video_schedule_next_buffer(video_out);
1191 spin_unlock(&video_out->dma_queue_lock);
1192 if (pipe->output_num > 1) {
1193 spin_lock(&video_out2->dma_queue_lock);
1194 vpfe_video_schedule_next_buffer(video_out2);
1195 spin_unlock(&video_out2->dma_queue_lock);
1196 }
1197}
1198
1199/*
1200 * V4L2 subdev operations
1201 */
1202
1203/*
1204 * resizer_ioctl() - Handle resizer module private ioctl's
1205 * @sd: pointer to v4l2 subdev structure
1206 * @cmd: configuration command
1207 * @arg: configuration argument
1208 */
1209static long resizer_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
1210{
1211 struct vpfe_resizer_device *resizer = v4l2_get_subdevdata(sd);
1212 struct device *dev = resizer->crop_resizer.subdev.v4l2_dev->dev;
1213 struct vpfe_rsz_config *user_config;
1214 int ret = -ENOIOCTLCMD;
1215
1216 if (&resizer->crop_resizer.subdev != sd)
1217 return ret;
1218
1219 switch (cmd) {
1220 case VIDIOC_VPFE_RSZ_S_CONFIG:
1221 user_config = (struct vpfe_rsz_config *)arg;
1222 ret = resizer_set_configuration(resizer, user_config);
1223 break;
1224
1225 case VIDIOC_VPFE_RSZ_G_CONFIG:
1226 user_config = (struct vpfe_rsz_config *)arg;
1227 if (!user_config->config) {
1228 dev_err(dev, "error in VIDIOC_VPFE_RSZ_G_CONFIG\n");
1229 return -EINVAL;
1230 }
1231 ret = resizer_get_configuration(resizer, user_config);
1232 break;
1233 }
1234 return ret;
1235}
1236
1237static int resizer_do_hw_setup(struct vpfe_resizer_device *resizer)
1238{
1239 struct vpfe_device *vpfe_dev = to_vpfe_device(resizer);
1240 u16 ipipeif_sink = vpfe_dev->vpfe_ipipeif.input;
1241 u16 ipipeif_source = vpfe_dev->vpfe_ipipeif.output;
1242 struct resizer_params *param = &resizer->config;
1243 int ret = 0;
1244
1245 if (resizer->resizer_a.output == RESIZER_OUPUT_MEMORY ||
1246 resizer->resizer_b.output == RESIZER_OUPUT_MEMORY) {
1247 if (ipipeif_sink == IPIPEIF_INPUT_MEMORY &&
1248 ipipeif_source == IPIPEIF_OUTPUT_RESIZER)
1249 ret = resizer_configure_in_single_shot_mode(resizer);
1250 else
1251 ret = resizer_configure_in_continious_mode(resizer);
1252 if (ret)
1253 return ret;
1254 ret = config_rsz_hw(resizer, param);
1255 }
1256 return ret;
1257}
1258
1259/*
1260 * resizer_set_stream() - Enable/Disable streaming on resizer subdev
1261 * @sd: pointer to v4l2 subdev structure
1262 * @enable: 1 == Enable, 0 == Disable
1263 */
1264static int resizer_set_stream(struct v4l2_subdev *sd, int enable)
1265{
1266 struct vpfe_resizer_device *resizer = v4l2_get_subdevdata(sd);
1267
1268 if (&resizer->crop_resizer.subdev != sd)
1269 return 0;
1270
1271 if (resizer->resizer_a.output != RESIZER_OUPUT_MEMORY)
1272 return 0;
1273
1274 switch (enable) {
1275 case 1:
1276 if (resizer_do_hw_setup(resizer) < 0)
1277 return -EINVAL;
1278 resizer_enable(resizer, enable);
1279 break;
1280
1281 case 0:
1282 resizer_enable(resizer, enable);
1283 break;
1284 }
1285
1286 return 0;
1287}
1288
1289/*
1290 * __resizer_get_format() - helper function for getting resizer format
1291 * @sd: pointer to subdev.
1292 * @fh: V4L2 subdev file handle.
1293 * @pad: pad number.
1294 * @which: wanted subdev format.
1295 * Retun wanted mbus frame format.
1296 */
1297static struct v4l2_mbus_framefmt *
1298__resizer_get_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1299 unsigned int pad, enum v4l2_subdev_format_whence which)
1300{
1301 struct vpfe_resizer_device *resizer = v4l2_get_subdevdata(sd);
1302
1303 if (which == V4L2_SUBDEV_FORMAT_TRY)
1304 return v4l2_subdev_get_try_format(fh, pad);
1305 if (&resizer->crop_resizer.subdev == sd)
1306 return &resizer->crop_resizer.formats[pad];
1307 if (&resizer->resizer_a.subdev == sd)
1308 return &resizer->resizer_a.formats[pad];
1309 if (&resizer->resizer_b.subdev == sd)
1310 return &resizer->resizer_b.formats[pad];
1311 return NULL;
1312}
1313
1314/*
1315 * resizer_try_format() - Handle try format by pad subdev method
1316 * @sd: pointer to subdev.
1317 * @fh: V4L2 subdev file handle.
1318 * @pad: pad num.
1319 * @fmt: pointer to v4l2 format structure.
1320 * @which: wanted subdev format.
1321 */
1322static void
1323resizer_try_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1324 unsigned int pad, struct v4l2_mbus_framefmt *fmt,
1325 enum v4l2_subdev_format_whence which)
1326{
1327 struct vpfe_resizer_device *resizer = v4l2_get_subdevdata(sd);
1328 unsigned int max_out_height;
1329 unsigned int max_out_width;
1330 unsigned int i;
1331
1332 if ((&resizer->resizer_a.subdev == sd && pad == RESIZER_PAD_SINK) ||
1333 (&resizer->resizer_b.subdev == sd && pad == RESIZER_PAD_SINK) ||
1334 (&resizer->crop_resizer.subdev == sd &&
1335 (pad == RESIZER_CROP_PAD_SOURCE ||
1336 pad == RESIZER_CROP_PAD_SOURCE2 || pad == RESIZER_CROP_PAD_SINK))) {
1337 for (i = 0; i < ARRAY_SIZE(resizer_input_formats); i++) {
1338 if (fmt->code == resizer_input_formats[i])
1339 break;
1340 }
1341 /* If not found, use UYVY as default */
1342 if (i >= ARRAY_SIZE(resizer_input_formats))
1343 fmt->code = V4L2_MBUS_FMT_UYVY8_2X8;
1344
1345 fmt->width = clamp_t(u32, fmt->width, MIN_IN_WIDTH,
1346 MAX_IN_WIDTH);
1347 fmt->height = clamp_t(u32, fmt->height, MIN_IN_HEIGHT,
1348 MAX_IN_HEIGHT);
1349 } else if (&resizer->resizer_a.subdev == sd &&
1350 pad == RESIZER_PAD_SOURCE) {
1351 max_out_width = IPIPE_MAX_OUTPUT_WIDTH_A;
1352 max_out_height = IPIPE_MAX_OUTPUT_HEIGHT_A;
1353
1354 for (i = 0; i < ARRAY_SIZE(resizer_output_formats); i++) {
1355 if (fmt->code == resizer_output_formats[i])
1356 break;
1357 }
1358 /* If not found, use UYVY as default */
1359 if (i >= ARRAY_SIZE(resizer_output_formats))
1360 fmt->code = V4L2_MBUS_FMT_UYVY8_2X8;
1361
1362 fmt->width = clamp_t(u32, fmt->width, MIN_OUT_WIDTH,
1363 max_out_width);
1364 fmt->width &= ~15;
1365 fmt->height = clamp_t(u32, fmt->height, MIN_OUT_HEIGHT,
1366 max_out_height);
1367 } else if (&resizer->resizer_b.subdev == sd &&
1368 pad == RESIZER_PAD_SOURCE) {
1369 max_out_width = IPIPE_MAX_OUTPUT_WIDTH_B;
1370 max_out_height = IPIPE_MAX_OUTPUT_HEIGHT_B;
1371
1372 for (i = 0; i < ARRAY_SIZE(resizer_output_formats); i++) {
1373 if (fmt->code == resizer_output_formats[i])
1374 break;
1375 }
1376 /* If not found, use UYVY as default */
1377 if (i >= ARRAY_SIZE(resizer_output_formats))
1378 fmt->code = V4L2_MBUS_FMT_UYVY8_2X8;
1379
1380 fmt->width = clamp_t(u32, fmt->width, MIN_OUT_WIDTH,
1381 max_out_width);
1382 fmt->width &= ~15;
1383 fmt->height = clamp_t(u32, fmt->height, MIN_OUT_HEIGHT,
1384 max_out_height);
1385 }
1386}
1387
1388/*
1389 * resizer_set_format() - Handle set format by pads subdev method
1390 * @sd: pointer to v4l2 subdev structure
1391 * @fh: V4L2 subdev file handle
1392 * @fmt: pointer to v4l2 subdev format structure
1393 * return -EINVAL or zero on success
1394 */
1395static int resizer_set_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1396 struct v4l2_subdev_format *fmt)
1397{
1398 struct vpfe_resizer_device *resizer = v4l2_get_subdevdata(sd);
1399 struct v4l2_mbus_framefmt *format;
1400
1401 format = __resizer_get_format(sd, fh, fmt->pad, fmt->which);
1402 if (format == NULL)
1403 return -EINVAL;
1404
1405 resizer_try_format(sd, fh, fmt->pad, &fmt->format, fmt->which);
1406 *format = fmt->format;
1407
1408 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY)
1409 return 0;
1410
1411 if (&resizer->crop_resizer.subdev == sd) {
1412 if (fmt->pad == RESIZER_CROP_PAD_SINK) {
1413 resizer->crop_resizer.formats[fmt->pad] = fmt->format;
1414 } else if (fmt->pad == RESIZER_CROP_PAD_SOURCE &&
1415 resizer->crop_resizer.output == RESIZER_A) {
1416 resizer->crop_resizer.formats[fmt->pad] = fmt->format;
1417 resizer->crop_resizer.
1418 formats[RESIZER_CROP_PAD_SOURCE2] = fmt->format;
1419 } else if (fmt->pad == RESIZER_CROP_PAD_SOURCE2 &&
1420 resizer->crop_resizer.output2 == RESIZER_B) {
1421 resizer->crop_resizer.formats[fmt->pad] = fmt->format;
1422 resizer->crop_resizer.
1423 formats[RESIZER_CROP_PAD_SOURCE] = fmt->format;
1424 } else {
1425 return -EINVAL;
1426 }
1427 } else if (&resizer->resizer_a.subdev == sd) {
1428 if (fmt->pad == RESIZER_PAD_SINK)
1429 resizer->resizer_a.formats[fmt->pad] = fmt->format;
1430 else if (fmt->pad == RESIZER_PAD_SOURCE)
1431 resizer->resizer_a.formats[fmt->pad] = fmt->format;
1432 else
1433 return -EINVAL;
1434 } else if (&resizer->resizer_b.subdev == sd) {
1435 if (fmt->pad == RESIZER_PAD_SINK)
1436 resizer->resizer_b.formats[fmt->pad] = fmt->format;
1437 else if (fmt->pad == RESIZER_PAD_SOURCE)
1438 resizer->resizer_b.formats[fmt->pad] = fmt->format;
1439 else
1440 return -EINVAL;
1441 } else {
1442 return -EINVAL;
1443 }
1444
1445 return 0;
1446}
1447
1448/*
1449 * resizer_get_format() - Retrieve the video format on a pad
1450 * @sd: pointer to v4l2 subdev structure.
1451 * @fh: V4L2 subdev file handle.
1452 * @fmt: pointer to v4l2 subdev format structure
1453 * return -EINVAL or zero on success
1454 */
1455static int resizer_get_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1456 struct v4l2_subdev_format *fmt)
1457{
1458 struct v4l2_mbus_framefmt *format;
1459
1460 format = __resizer_get_format(sd, fh, fmt->pad, fmt->which);
1461 if (format == NULL)
1462 return -EINVAL;
1463
1464 fmt->format = *format;
1465
1466 return 0;
1467}
1468
1469/*
1470 * resizer_enum_frame_size() - enum frame sizes on pads
1471 * @sd: Pointer to subdevice.
1472 * @fh: V4L2 subdev file handle.
1473 * @code: pointer to v4l2_subdev_frame_size_enum structure.
1474 */
1475static int resizer_enum_frame_size(struct v4l2_subdev *sd,
1476 struct v4l2_subdev_fh *fh,
1477 struct v4l2_subdev_frame_size_enum *fse)
1478{
1479 struct v4l2_mbus_framefmt format;
1480
1481 if (fse->index != 0)
1482 return -EINVAL;
1483
1484 format.code = fse->code;
1485 format.width = 1;
1486 format.height = 1;
1487 resizer_try_format(sd, fh, fse->pad, &format,
1488 V4L2_SUBDEV_FORMAT_TRY);
1489 fse->min_width = format.width;
1490 fse->min_height = format.height;
1491
1492 if (format.code != fse->code)
1493 return -EINVAL;
1494
1495 format.code = fse->code;
1496 format.width = -1;
1497 format.height = -1;
1498 resizer_try_format(sd, fh, fse->pad, &format,
1499 V4L2_SUBDEV_FORMAT_TRY);
1500 fse->max_width = format.width;
1501 fse->max_height = format.height;
1502
1503 return 0;
1504}
1505
1506/*
1507 * resizer_enum_mbus_code() - enum mbus codes for pads
1508 * @sd: Pointer to subdevice.
1509 * @fh: V4L2 subdev file handle
1510 * @code: pointer to v4l2_subdev_mbus_code_enum structure
1511 */
1512static int resizer_enum_mbus_code(struct v4l2_subdev *sd,
1513 struct v4l2_subdev_fh *fh,
1514 struct v4l2_subdev_mbus_code_enum *code)
1515{
1516 if (code->pad == RESIZER_PAD_SINK) {
1517 if (code->index >= ARRAY_SIZE(resizer_input_formats))
1518 return -EINVAL;
1519
1520 code->code = resizer_input_formats[code->index];
1521 } else if (code->pad == RESIZER_PAD_SOURCE) {
1522 if (code->index >= ARRAY_SIZE(resizer_output_formats))
1523 return -EINVAL;
1524
1525 code->code = resizer_output_formats[code->index];
1526 }
1527
1528 return 0;
1529}
1530
1531/*
1532 * resizer_init_formats() - Initialize formats on all pads
1533 * @sd: Pointer to subdevice.
1534 * @fh: V4L2 subdev file handle.
1535 *
1536 * Initialize all pad formats with default values. If fh is not NULL, try
1537 * formats are initialized on the file handle. Otherwise active formats are
1538 * initialized on the device.
1539 */
1540static int resizer_init_formats(struct v4l2_subdev *sd,
1541 struct v4l2_subdev_fh *fh)
1542{
1543 __u32 which = fh ? V4L2_SUBDEV_FORMAT_TRY : V4L2_SUBDEV_FORMAT_ACTIVE;
1544 struct vpfe_resizer_device *resizer = v4l2_get_subdevdata(sd);
1545 struct v4l2_subdev_format format;
1546
1547 if (&resizer->crop_resizer.subdev == sd) {
1548 memset(&format, 0, sizeof(format));
1549 format.pad = RESIZER_CROP_PAD_SINK;
1550 format.which = which;
1551 format.format.code = V4L2_MBUS_FMT_YUYV8_2X8;
1552 format.format.width = MAX_IN_WIDTH;
1553 format.format.height = MAX_IN_HEIGHT;
1554 resizer_set_format(sd, fh, &format);
1555
1556 memset(&format, 0, sizeof(format));
1557 format.pad = RESIZER_CROP_PAD_SOURCE;
1558 format.which = which;
1559 format.format.code = V4L2_MBUS_FMT_UYVY8_2X8;
1560 format.format.width = MAX_IN_WIDTH;
1561 format.format.height = MAX_IN_WIDTH;
1562 resizer_set_format(sd, fh, &format);
1563
1564 memset(&format, 0, sizeof(format));
1565 format.pad = RESIZER_CROP_PAD_SOURCE2;
1566 format.which = which;
1567 format.format.code = V4L2_MBUS_FMT_UYVY8_2X8;
1568 format.format.width = MAX_IN_WIDTH;
1569 format.format.height = MAX_IN_WIDTH;
1570 resizer_set_format(sd, fh, &format);
1571 } else if (&resizer->resizer_a.subdev == sd) {
1572 memset(&format, 0, sizeof(format));
1573 format.pad = RESIZER_PAD_SINK;
1574 format.which = which;
1575 format.format.code = V4L2_MBUS_FMT_YUYV8_2X8;
1576 format.format.width = MAX_IN_WIDTH;
1577 format.format.height = MAX_IN_HEIGHT;
1578 resizer_set_format(sd, fh, &format);
1579
1580 memset(&format, 0, sizeof(format));
1581 format.pad = RESIZER_PAD_SOURCE;
1582 format.which = which;
1583 format.format.code = V4L2_MBUS_FMT_UYVY8_2X8;
1584 format.format.width = IPIPE_MAX_OUTPUT_WIDTH_A;
1585 format.format.height = IPIPE_MAX_OUTPUT_HEIGHT_A;
1586 resizer_set_format(sd, fh, &format);
1587 } else if (&resizer->resizer_b.subdev == sd) {
1588 memset(&format, 0, sizeof(format));
1589 format.pad = RESIZER_PAD_SINK;
1590 format.which = which;
1591 format.format.code = V4L2_MBUS_FMT_YUYV8_2X8;
1592 format.format.width = MAX_IN_WIDTH;
1593 format.format.height = MAX_IN_HEIGHT;
1594 resizer_set_format(sd, fh, &format);
1595
1596 memset(&format, 0, sizeof(format));
1597 format.pad = RESIZER_PAD_SOURCE;
1598 format.which = which;
1599 format.format.code = V4L2_MBUS_FMT_UYVY8_2X8;
1600 format.format.width = IPIPE_MAX_OUTPUT_WIDTH_B;
1601 format.format.height = IPIPE_MAX_OUTPUT_HEIGHT_B;
1602 resizer_set_format(sd, fh, &format);
1603 }
1604
1605 return 0;
1606}
1607
1608/* subdev core operations */
1609static const struct v4l2_subdev_core_ops resizer_v4l2_core_ops = {
1610 .ioctl = resizer_ioctl,
1611};
1612
1613/* subdev internal operations */
1614static const struct v4l2_subdev_internal_ops resizer_v4l2_internal_ops = {
1615 .open = resizer_init_formats,
1616};
1617
1618/* subdev video operations */
1619static const struct v4l2_subdev_video_ops resizer_v4l2_video_ops = {
1620 .s_stream = resizer_set_stream,
1621};
1622
1623/* subdev pad operations */
1624static const struct v4l2_subdev_pad_ops resizer_v4l2_pad_ops = {
1625 .enum_mbus_code = resizer_enum_mbus_code,
1626 .enum_frame_size = resizer_enum_frame_size,
1627 .get_fmt = resizer_get_format,
1628 .set_fmt = resizer_set_format,
1629};
1630
1631/* subdev operations */
1632static const struct v4l2_subdev_ops resizer_v4l2_ops = {
1633 .core = &resizer_v4l2_core_ops,
1634 .video = &resizer_v4l2_video_ops,
1635 .pad = &resizer_v4l2_pad_ops,
1636};
1637
1638/*
1639 * Media entity operations
1640 */
1641
1642/*
1643 * resizer_link_setup() - Setup resizer connections
1644 * @entity: Pointer to media entity structure
1645 * @local: Pointer to local pad array
1646 * @remote: Pointer to remote pad array
1647 * @flags: Link flags
1648 * return -EINVAL or zero on success
1649 */
1650static int resizer_link_setup(struct media_entity *entity,
1651 const struct media_pad *local,
1652 const struct media_pad *remote, u32 flags)
1653{
1654 struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
1655 struct vpfe_resizer_device *resizer = v4l2_get_subdevdata(sd);
1656 struct vpfe_device *vpfe_dev = to_vpfe_device(resizer);
1657 u16 ipipeif_source = vpfe_dev->vpfe_ipipeif.output;
1658 u16 ipipe_source = vpfe_dev->vpfe_ipipe.output;
1659
1660 if (&resizer->crop_resizer.subdev == sd) {
1661 switch (local->index | media_entity_type(remote->entity)) {
1662 case RESIZER_CROP_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
1663 if (!(flags & MEDIA_LNK_FL_ENABLED)) {
1664 resizer->crop_resizer.input =
1665 RESIZER_CROP_INPUT_NONE;
1666 break;
1667 }
1668
1669 if (resizer->crop_resizer.input !=
1670 RESIZER_CROP_INPUT_NONE)
1671 return -EBUSY;
1672 if (ipipeif_source == IPIPEIF_OUTPUT_RESIZER)
1673 resizer->crop_resizer.input =
1674 RESIZER_CROP_INPUT_IPIPEIF;
1675 else if (ipipe_source == IPIPE_OUTPUT_RESIZER)
1676 resizer->crop_resizer.input =
1677 RESIZER_CROP_INPUT_IPIPE;
1678 else
1679 return -EINVAL;
1680 break;
1681
1682 case RESIZER_CROP_PAD_SOURCE | MEDIA_ENT_T_V4L2_SUBDEV:
1683 if (!(flags & MEDIA_LNK_FL_ENABLED)) {
1684 resizer->crop_resizer.output =
1685 RESIZER_CROP_OUTPUT_NONE;
1686 break;
1687 }
1688 if (resizer->crop_resizer.output !=
1689 RESIZER_CROP_OUTPUT_NONE)
1690 return -EBUSY;
1691 resizer->crop_resizer.output = RESIZER_A;
1692 break;
1693
1694 case RESIZER_CROP_PAD_SOURCE2 | MEDIA_ENT_T_V4L2_SUBDEV:
1695 if (!(flags & MEDIA_LNK_FL_ENABLED)) {
1696 resizer->crop_resizer.output2 =
1697 RESIZER_CROP_OUTPUT_NONE;
1698 break;
1699 }
1700 if (resizer->crop_resizer.output2 !=
1701 RESIZER_CROP_OUTPUT_NONE)
1702 return -EBUSY;
1703 resizer->crop_resizer.output2 = RESIZER_B;
1704 break;
1705
1706 default:
1707 return -EINVAL;
1708 }
1709 } else if (&resizer->resizer_a.subdev == sd) {
1710 switch (local->index | media_entity_type(remote->entity)) {
1711 case RESIZER_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
1712 if (!(flags & MEDIA_LNK_FL_ENABLED)) {
1713 resizer->resizer_a.input = RESIZER_INPUT_NONE;
1714 break;
1715 }
1716 if (resizer->resizer_a.input != RESIZER_INPUT_NONE)
1717 return -EBUSY;
1718 resizer->resizer_a.input = RESIZER_INPUT_CROP_RESIZER;
1719 break;
1720
1721 case RESIZER_PAD_SOURCE | MEDIA_ENT_T_DEVNODE:
1722 if (!(flags & MEDIA_LNK_FL_ENABLED)) {
1723 resizer->resizer_a.output = RESIZER_OUTPUT_NONE;
1724 break;
1725 }
1726 if (resizer->resizer_a.output != RESIZER_OUTPUT_NONE)
1727 return -EBUSY;
1728 resizer->resizer_a.output = RESIZER_OUPUT_MEMORY;
1729 break;
1730
1731 default:
1732 return -EINVAL;
1733 }
1734 } else if (&resizer->resizer_b.subdev == sd) {
1735 switch (local->index | media_entity_type(remote->entity)) {
1736 case RESIZER_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
1737 if (!(flags & MEDIA_LNK_FL_ENABLED)) {
1738 resizer->resizer_b.input = RESIZER_INPUT_NONE;
1739 break;
1740 }
1741 if (resizer->resizer_b.input != RESIZER_INPUT_NONE)
1742 return -EBUSY;
1743 resizer->resizer_b.input = RESIZER_INPUT_CROP_RESIZER;
1744 break;
1745
1746 case RESIZER_PAD_SOURCE | MEDIA_ENT_T_DEVNODE:
1747 if (!(flags & MEDIA_LNK_FL_ENABLED)) {
1748 resizer->resizer_b.output = RESIZER_OUTPUT_NONE;
1749 break;
1750 }
1751 if (resizer->resizer_b.output != RESIZER_OUTPUT_NONE)
1752 return -EBUSY;
1753 resizer->resizer_b.output = RESIZER_OUPUT_MEMORY;
1754 break;
1755
1756 default:
1757 return -EINVAL;
1758 }
1759 } else {
1760 return -EINVAL;
1761 }
1762
1763 return 0;
1764}
1765
1766static const struct media_entity_operations resizer_media_ops = {
1767 .link_setup = resizer_link_setup,
1768};
1769
1770/*
1771 * vpfe_resizer_unregister_entities() - Unregister entity
1772 * @vpfe_rsz - pointer to resizer subdevice structure.
1773 */
1774void vpfe_resizer_unregister_entities(struct vpfe_resizer_device *vpfe_rsz)
1775{
1776 /* unregister video devices */
1777 vpfe_video_unregister(&vpfe_rsz->resizer_a.video_out);
1778 vpfe_video_unregister(&vpfe_rsz->resizer_b.video_out);
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 */
1785 v4l2_device_unregister_subdev(&vpfe_rsz->crop_resizer.subdev);
1786 v4l2_device_unregister_subdev(&vpfe_rsz->resizer_a.subdev);
1787 v4l2_device_unregister_subdev(&vpfe_rsz->resizer_b.subdev);
1788}
1789
1790/*
1791 * vpfe_resizer_register_entities() - Register entity
1792 * @resizer - pointer to resizer devive.
1793 * @vdev: pointer to v4l2 device structure.
1794 */
1795int vpfe_resizer_register_entities(struct vpfe_resizer_device *resizer,
1796 struct v4l2_device *vdev)
1797{
1798 struct vpfe_device *vpfe_dev = to_vpfe_device(resizer);
1799 unsigned int flags = 0;
1800 int ret;
1801
1802 /* Register the crop resizer subdev */
1803 ret = v4l2_device_register_subdev(vdev, &resizer->crop_resizer.subdev);
1804 if (ret < 0) {
1805 pr_err("Failed to register crop resizer as v4l2-subdev\n");
1806 return ret;
1807 }
1808 /* Register Resizer-A subdev */
1809 ret = v4l2_device_register_subdev(vdev, &resizer->resizer_a.subdev);
1810 if (ret < 0) {
1811 pr_err("Failed to register resizer-a as v4l2-subdev\n");
1812 return ret;
1813 }
1814 /* Register Resizer-B subdev */
1815 ret = v4l2_device_register_subdev(vdev, &resizer->resizer_b.subdev);
1816 if (ret < 0) {
1817 pr_err("Failed to register resizer-b as v4l2-subdev\n");
1818 return ret;
1819 }
1820 /* Register video-out device for resizer-a */
1821 ret = vpfe_video_register(&resizer->resizer_a.video_out, vdev);
1822 if (ret) {
1823 pr_err("Failed to register RSZ-A video-out device\n");
1824 goto out_video_out2_register;
1825 }
1826 resizer->resizer_a.video_out.vpfe_dev = vpfe_dev;
1827
1828 /* Register video-out device for resizer-b */
1829 ret = vpfe_video_register(&resizer->resizer_b.video_out, vdev);
1830 if (ret) {
1831 pr_err("Failed to register RSZ-B video-out device\n");
1832 goto out_video_out2_register;
1833 }
1834 resizer->resizer_b.video_out.vpfe_dev = vpfe_dev;
1835
1836 /* create link between Resizer Crop----> Resizer A*/
1837 ret = media_entity_create_link(&resizer->crop_resizer.subdev.entity, 1,
1838 &resizer->resizer_a.subdev.entity,
1839 0, flags);
1840 if (ret < 0)
1841 goto out_create_link;
1842
1843 /* create link between Resizer Crop----> Resizer B*/
1844 ret = media_entity_create_link(&resizer->crop_resizer.subdev.entity, 2,
1845 &resizer->resizer_b.subdev.entity,
1846 0, flags);
1847 if (ret < 0)
1848 goto out_create_link;
1849
1850 /* create link between Resizer A ----> video out */
1851 ret = media_entity_create_link(&resizer->resizer_a.subdev.entity, 1,
1852 &resizer->resizer_a.video_out.video_dev.entity, 0, flags);
1853 if (ret < 0)
1854 goto out_create_link;
1855
1856 /* create link between Resizer B ----> video out */
1857 ret = media_entity_create_link(&resizer->resizer_b.subdev.entity, 1,
1858 &resizer->resizer_b.video_out.video_dev.entity, 0, flags);
1859 if (ret < 0)
1860 goto out_create_link;
1861
1862 return 0;
1863
1864out_create_link:
1865 vpfe_video_unregister(&resizer->resizer_b.video_out);
1866out_video_out2_register:
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);
1872 v4l2_device_unregister_subdev(&resizer->resizer_a.subdev);
1873 v4l2_device_unregister_subdev(&resizer->resizer_b.subdev);
1874 return ret;
1875}
1876
1877/*
1878 * vpfe_resizer_init() - resizer device initialization.
1879 * @vpfe_rsz - pointer to resizer device
1880 * @pdev: platform device pointer.
1881 */
1882int vpfe_resizer_init(struct vpfe_resizer_device *vpfe_rsz,
1883 struct platform_device *pdev)
1884{
1885 struct v4l2_subdev *sd = &vpfe_rsz->crop_resizer.subdev;
1886 struct media_pad *pads = &vpfe_rsz->crop_resizer.pads[0];
1887 struct media_entity *me = &sd->entity;
1888 static resource_size_t res_len;
1889 struct resource *res;
1890 int ret;
1891
1892 res = platform_get_resource(pdev, IORESOURCE_MEM, 5);
1893 if (!res)
1894 return -ENOENT;
1895
1896 res_len = resource_size(res);
1897 res = request_mem_region(res->start, res_len, res->name);
1898 if (!res)
1899 return -EBUSY;
1900
1901 vpfe_rsz->base_addr = ioremap_nocache(res->start, res_len);
1902 if (!vpfe_rsz->base_addr)
1903 return -EBUSY;
1904
1905 v4l2_subdev_init(sd, &resizer_v4l2_ops);
1906 sd->internal_ops = &resizer_v4l2_internal_ops;
1907 strlcpy(sd->name, "DAVINCI RESIZER CROP", sizeof(sd->name));
1908 sd->grp_id = 1 << 16; /* group ID for davinci subdevs */
1909 v4l2_set_subdevdata(sd, vpfe_rsz);
1910 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
1911
1912 pads[RESIZER_CROP_PAD_SINK].flags = MEDIA_PAD_FL_SINK;
1913 pads[RESIZER_CROP_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE;
1914 pads[RESIZER_CROP_PAD_SOURCE2].flags = MEDIA_PAD_FL_SOURCE;
1915
1916 vpfe_rsz->crop_resizer.input = RESIZER_CROP_INPUT_NONE;
1917 vpfe_rsz->crop_resizer.output = RESIZER_CROP_OUTPUT_NONE;
1918 vpfe_rsz->crop_resizer.output2 = RESIZER_CROP_OUTPUT_NONE;
1919 vpfe_rsz->crop_resizer.rsz_device = vpfe_rsz;
1920 me->ops = &resizer_media_ops;
1921 ret = media_entity_init(me, RESIZER_CROP_PADS_NUM, pads, 0);
1922 if (ret)
1923 return ret;
1924
1925 sd = &vpfe_rsz->resizer_a.subdev;
1926 pads = &vpfe_rsz->resizer_a.pads[0];
1927 me = &sd->entity;
1928
1929 v4l2_subdev_init(sd, &resizer_v4l2_ops);
1930 sd->internal_ops = &resizer_v4l2_internal_ops;
1931 strlcpy(sd->name, "DAVINCI RESIZER A", sizeof(sd->name));
1932 sd->grp_id = 1 << 16; /* group ID for davinci subdevs */
1933 v4l2_set_subdevdata(sd, vpfe_rsz);
1934 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
1935
1936 pads[RESIZER_PAD_SINK].flags = MEDIA_PAD_FL_SINK;
1937 pads[RESIZER_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE;
1938
1939 vpfe_rsz->resizer_a.input = RESIZER_INPUT_NONE;
1940 vpfe_rsz->resizer_a.output = RESIZER_OUTPUT_NONE;
1941 vpfe_rsz->resizer_a.rsz_device = vpfe_rsz;
1942 me->ops = &resizer_media_ops;
1943 ret = media_entity_init(me, RESIZER_PADS_NUM, pads, 0);
1944 if (ret)
1945 return ret;
1946
1947 sd = &vpfe_rsz->resizer_b.subdev;
1948 pads = &vpfe_rsz->resizer_b.pads[0];
1949 me = &sd->entity;
1950
1951 v4l2_subdev_init(sd, &resizer_v4l2_ops);
1952 sd->internal_ops = &resizer_v4l2_internal_ops;
1953 strlcpy(sd->name, "DAVINCI RESIZER B", sizeof(sd->name));
1954 sd->grp_id = 1 << 16; /* group ID for davinci subdevs */
1955 v4l2_set_subdevdata(sd, vpfe_rsz);
1956 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
1957
1958 pads[RESIZER_PAD_SINK].flags = MEDIA_PAD_FL_SINK;
1959 pads[RESIZER_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE;
1960
1961 vpfe_rsz->resizer_b.input = RESIZER_INPUT_NONE;
1962 vpfe_rsz->resizer_b.output = RESIZER_OUTPUT_NONE;
1963 vpfe_rsz->resizer_b.rsz_device = vpfe_rsz;
1964 me->ops = &resizer_media_ops;
1965 ret = media_entity_init(me, RESIZER_PADS_NUM, pads, 0);
1966 if (ret)
1967 return ret;
1968
1969 vpfe_rsz->resizer_a.video_out.ops = &resizer_a_video_ops;
1970 vpfe_rsz->resizer_a.video_out.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1971 ret = vpfe_video_init(&vpfe_rsz->resizer_a.video_out, "RSZ-A");
1972 if (ret) {
1973 pr_err("Failed to init RSZ video-out device\n");
1974 return ret;
1975 }
1976 vpfe_rsz->resizer_b.video_out.ops = &resizer_b_video_ops;
1977 vpfe_rsz->resizer_b.video_out.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1978 ret = vpfe_video_init(&vpfe_rsz->resizer_b.video_out, "RSZ-B");
1979 if (ret) {
1980 pr_err("Failed to init RSZ video-out2 device\n");
1981 return ret;
1982 }
1983 memset(&vpfe_rsz->config, 0, sizeof(struct resizer_params));
1984
1985 return 0;
1986}
1987
1988void
1989vpfe_resizer_cleanup(struct vpfe_resizer_device *vpfe_rsz,
1990 struct platform_device *pdev)
1991{
1992 struct resource *res;
1993
1994 iounmap(vpfe_rsz->base_addr);
1995 res = platform_get_resource(pdev, IORESOURCE_MEM, 5);
1996 if (res)
1997 release_mem_region(res->start,
1998 res->end - res->start + 1);
1999}
diff --git a/drivers/staging/media/davinci_vpfe/dm365_resizer.h b/drivers/staging/media/davinci_vpfe/dm365_resizer.h
new file mode 100644
index 000000000000..59a79422b914
--- /dev/null
+++ b/drivers/staging/media/davinci_vpfe/dm365_resizer.h
@@ -0,0 +1,244 @@
1/*
2 * Copyright (C) 2012 Texas Instruments Inc
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation version 2.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Contributors:
18 * Manjunath Hadli <manjunath.hadli@ti.com>
19 * Prabhakar Lad <prabhakar.lad@ti.com>
20 */
21
22#ifndef _DAVINCI_VPFE_DM365_RESIZER_H
23#define _DAVINCI_VPFE_DM365_RESIZER_H
24
25enum resizer_oper_mode {
26 RESIZER_MODE_CONTINIOUS = 0,
27 RESIZER_MODE_ONE_SHOT = 1,
28};
29
30struct f_div_pass {
31 unsigned int o_hsz;
32 unsigned int i_hps;
33 unsigned int h_phs;
34 unsigned int src_hps;
35 unsigned int src_hsz;
36};
37
38#define MAX_PASSES 2
39
40struct f_div_param {
41 unsigned char en;
42 unsigned int num_passes;
43 struct f_div_pass pass[MAX_PASSES];
44};
45
46/* Resizer Rescale Parameters*/
47struct resizer_scale_param {
48 bool h_flip;
49 bool v_flip;
50 bool cen;
51 bool yen;
52 unsigned short i_vps;
53 unsigned short i_hps;
54 unsigned short o_vsz;
55 unsigned short o_hsz;
56 unsigned short v_phs_y;
57 unsigned short v_phs_c;
58 unsigned short v_dif;
59 /* resize method - Luminance */
60 enum vpfe_rsz_intp_t v_typ_y;
61 /* resize method - Chrominance */
62 enum vpfe_rsz_intp_t v_typ_c;
63 /* vertical lpf intensity - Luminance */
64 unsigned char v_lpf_int_y;
65 /* vertical lpf intensity - Chrominance */
66 unsigned char v_lpf_int_c;
67 unsigned short h_phs;
68 unsigned short h_dif;
69 /* resize method - Luminance */
70 enum vpfe_rsz_intp_t h_typ_y;
71 /* resize method - Chrominance */
72 enum vpfe_rsz_intp_t h_typ_c;
73 /* horizontal lpf intensity - Luminance */
74 unsigned char h_lpf_int_y;
75 /* horizontal lpf intensity - Chrominance */
76 unsigned char h_lpf_int_c;
77 bool dscale_en;
78 enum vpfe_rsz_down_scale_ave_sz h_dscale_ave_sz;
79 enum vpfe_rsz_down_scale_ave_sz v_dscale_ave_sz;
80 /* store the calculated frame division parameter */
81 struct f_div_param f_div;
82};
83
84enum resizer_rgb_t {
85 OUTPUT_32BIT,
86 OUTPUT_16BIT
87};
88
89enum resizer_rgb_msk_t {
90 NOMASK = 0,
91 MASKLAST2 = 1,
92};
93
94/* Resizer RGB Conversion Parameters */
95struct resizer_rgb {
96 bool rgb_en;
97 enum resizer_rgb_t rgb_typ;
98 enum resizer_rgb_msk_t rgb_msk0;
99 enum resizer_rgb_msk_t rgb_msk1;
100 unsigned int rgb_alpha_val;
101};
102
103/* Resizer External Memory Parameters */
104struct rsz_ext_mem_param {
105 unsigned int rsz_sdr_oft_y;
106 unsigned int rsz_sdr_ptr_s_y;
107 unsigned int rsz_sdr_ptr_e_y;
108 unsigned int rsz_sdr_oft_c;
109 unsigned int rsz_sdr_ptr_s_c;
110 unsigned int rsz_sdr_ptr_e_c;
111 /* offset to be added to buffer start when flipping for y/ycbcr */
112 unsigned int flip_ofst_y;
113 /* offset to be added to buffer start when flipping for c */
114 unsigned int flip_ofst_c;
115 /* c offset for YUV 420SP */
116 unsigned int c_offset;
117 /* User Defined Y offset for YUV 420SP or YUV420ILE data */
118 unsigned int user_y_ofst;
119 /* User Defined C offset for YUV 420SP data */
120 unsigned int user_c_ofst;
121};
122
123enum rsz_data_source {
124 IPIPE_DATA,
125 IPIPEIF_DATA
126};
127
128enum rsz_src_img_fmt {
129 RSZ_IMG_422,
130 RSZ_IMG_420
131};
132
133enum rsz_dpaths_bypass_t {
134 BYPASS_OFF = 0,
135 BYPASS_ON = 1,
136};
137
138struct rsz_common_params {
139 unsigned int vps;
140 unsigned int vsz;
141 unsigned int hps;
142 unsigned int hsz;
143 /* 420 or 422 */
144 enum rsz_src_img_fmt src_img_fmt;
145 /* Y or C when src_fmt is 420, 0 - y, 1 - c */
146 unsigned char y_c;
147 /* flip raw or ycbcr */
148 unsigned char raw_flip;
149 /* IPIPE or IPIPEIF data */
150 enum rsz_data_source source;
151 enum rsz_dpaths_bypass_t passthrough;
152 unsigned char yuv_y_min;
153 unsigned char yuv_y_max;
154 unsigned char yuv_c_min;
155 unsigned char yuv_c_max;
156 bool rsz_seq_crv;
157 enum vpfe_chr_pos out_chr_pos;
158};
159
160struct resizer_params {
161 enum resizer_oper_mode oper_mode;
162 struct rsz_common_params rsz_common;
163 struct resizer_scale_param rsz_rsc_param[2];
164 struct resizer_rgb rsz2rgb[2];
165 struct rsz_ext_mem_param ext_mem_param[2];
166 bool rsz_en[2];
167 struct vpfe_rsz_config_params user_config;
168};
169
170#define ENABLE 1
171#define DISABLE (!ENABLE)
172
173#define RESIZER_CROP_PAD_SINK 0
174#define RESIZER_CROP_PAD_SOURCE 1
175#define RESIZER_CROP_PAD_SOURCE2 2
176
177#define RESIZER_CROP_PADS_NUM 3
178
179enum resizer_crop_input_entity {
180 RESIZER_CROP_INPUT_NONE = 0,
181 RESIZER_CROP_INPUT_IPIPEIF = 1,
182 RESIZER_CROP_INPUT_IPIPE = 2,
183};
184
185enum resizer_crop_output_entity {
186 RESIZER_CROP_OUTPUT_NONE,
187 RESIZER_A,
188 RESIZER_B,
189};
190
191struct dm365_crop_resizer_device {
192 struct v4l2_subdev subdev;
193 struct media_pad pads[RESIZER_CROP_PADS_NUM];
194 struct v4l2_mbus_framefmt formats[RESIZER_CROP_PADS_NUM];
195 enum resizer_crop_input_entity input;
196 enum resizer_crop_output_entity output;
197 enum resizer_crop_output_entity output2;
198 struct vpfe_resizer_device *rsz_device;
199};
200
201#define RESIZER_PAD_SINK 0
202#define RESIZER_PAD_SOURCE 1
203
204#define RESIZER_PADS_NUM 2
205
206enum resizer_input_entity {
207 RESIZER_INPUT_NONE = 0,
208 RESIZER_INPUT_CROP_RESIZER = 1,
209};
210
211enum resizer_output_entity {
212 RESIZER_OUTPUT_NONE = 0,
213 RESIZER_OUPUT_MEMORY = 1,
214};
215
216struct dm365_resizer_device {
217 struct v4l2_subdev subdev;
218 struct media_pad pads[RESIZER_PADS_NUM];
219 struct v4l2_mbus_framefmt formats[RESIZER_PADS_NUM];
220 enum resizer_input_entity input;
221 enum resizer_output_entity output;
222 struct vpfe_video_device video_out;
223 struct vpfe_resizer_device *rsz_device;
224};
225
226struct vpfe_resizer_device {
227 struct dm365_crop_resizer_device crop_resizer;
228 struct dm365_resizer_device resizer_a;
229 struct dm365_resizer_device resizer_b;
230 struct resizer_params config;
231 void *__iomem base_addr;
232};
233
234int vpfe_resizer_init(struct vpfe_resizer_device *vpfe_rsz,
235 struct platform_device *pdev);
236int vpfe_resizer_register_entities(struct vpfe_resizer_device *vpfe_rsz,
237 struct v4l2_device *v4l2_dev);
238void vpfe_resizer_unregister_entities(struct vpfe_resizer_device *vpfe_rsz);
239void vpfe_resizer_cleanup(struct vpfe_resizer_device *vpfe_rsz,
240 struct platform_device *pdev);
241void vpfe_resizer_buffer_isr(struct vpfe_resizer_device *resizer);
242void vpfe_resizer_dma_isr(struct vpfe_resizer_device *resizer);
243
244#endif /* _DAVINCI_VPFE_DM365_RESIZER_H */
diff --git a/drivers/staging/media/davinci_vpfe/vpfe.h b/drivers/staging/media/davinci_vpfe/vpfe.h
new file mode 100644
index 000000000000..0587bc52a840
--- /dev/null
+++ b/drivers/staging/media/davinci_vpfe/vpfe.h
@@ -0,0 +1,86 @@
1/*
2 * Copyright (C) 2012 Texas Instruments Inc
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation version 2.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Contributors:
18 * Manjunath Hadli <manjunath.hadli@ti.com>
19 * Prabhakar Lad <prabhakar.lad@ti.com>
20 */
21
22#ifndef _VPFE_H
23#define _VPFE_H
24
25#ifdef __KERNEL__
26#include <linux/v4l2-subdev.h>
27#include <linux/clk.h>
28#include <linux/i2c.h>
29
30#include <media/davinci/vpfe_types.h>
31
32#define CAPTURE_DRV_NAME "vpfe-capture"
33
34struct vpfe_route {
35 __u32 input;
36 __u32 output;
37};
38
39enum vpfe_subdev_id {
40 VPFE_SUBDEV_TVP5146 = 1,
41 VPFE_SUBDEV_MT9T031 = 2,
42 VPFE_SUBDEV_TVP7002 = 3,
43 VPFE_SUBDEV_MT9P031 = 4,
44};
45
46struct vpfe_ext_subdev_info {
47 /* v4l2 subdev */
48 struct v4l2_subdev *subdev;
49 /* Sub device module name */
50 char module_name[32];
51 /* Sub device group id */
52 int grp_id;
53 /* Number of inputs supported */
54 int num_inputs;
55 /* inputs available at the sub device */
56 struct v4l2_input *inputs;
57 /* Sub dev routing information for each input */
58 struct vpfe_route *routes;
59 /* ccdc bus/interface configuration */
60 struct vpfe_hw_if_param ccdc_if_params;
61 /* i2c subdevice board info */
62 struct i2c_board_info board_info;
63 /* Is this a camera sub device ? */
64 unsigned is_camera:1;
65 /* check if sub dev supports routing */
66 unsigned can_route:1;
67 /* registered ? */
68 unsigned registered:1;
69};
70
71struct vpfe_config {
72 /* Number of sub devices connected to vpfe */
73 int num_subdevs;
74 /* information about each subdev */
75 struct vpfe_ext_subdev_info *sub_devs;
76 /* evm card info */
77 char *card_name;
78 /* setup function for the input path */
79 int (*setup_input)(enum vpfe_subdev_id id);
80 /* number of clocks */
81 int num_clocks;
82 /* clocks used for vpfe capture */
83 char *clocks[];
84};
85#endif
86#endif
diff --git a/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c b/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c
new file mode 100644
index 000000000000..7b351717bcbb
--- /dev/null
+++ b/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c
@@ -0,0 +1,740 @@
1/*
2 * Copyright (C) 2012 Texas Instruments Inc
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation version 2.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Contributors:
18 * Manjunath Hadli <manjunath.hadli@ti.com>
19 * Prabhakar Lad <prabhakar.lad@ti.com>
20 *
21 *
22 * Driver name : VPFE Capture driver
23 * VPFE Capture driver allows applications to capture and stream video
24 * frames on DaVinci SoCs (DM6446, DM355 etc) from a YUV source such as
25 * TVP5146 or Raw Bayer RGB image data from an image sensor
26 * such as Microns' MT9T001, MT9T031 etc.
27 *
28 * These SoCs have, in common, a Video Processing Subsystem (VPSS) that
29 * consists of a Video Processing Front End (VPFE) for capturing
30 * video/raw image data and Video Processing Back End (VPBE) for displaying
31 * YUV data through an in-built analog encoder or Digital LCD port. This
32 * driver is for capture through VPFE. A typical EVM using these SoCs have
33 * following high level configuration.
34 *
35 * decoder(TVP5146/ YUV/
36 * MT9T001) --> Raw Bayer RGB ---> MUX -> VPFE (CCDC/ISIF)
37 * data input | |
38 * V |
39 * SDRAM |
40 * V
41 * Image Processor
42 * |
43 * V
44 * SDRAM
45 * The data flow happens from a decoder connected to the VPFE over a
46 * YUV embedded (BT.656/BT.1120) or separate sync or raw bayer rgb interface
47 * and to the input of VPFE through an optional MUX (if more inputs are
48 * to be interfaced on the EVM). The input data is first passed through
49 * CCDC (CCD Controller, a.k.a Image Sensor Interface, ISIF). The CCDC
50 * does very little or no processing on YUV data and does pre-process Raw
51 * Bayer RGB data through modules such as Defect Pixel Correction (DFC)
52 * Color Space Conversion (CSC), data gain/offset etc. After this, data
53 * can be written to SDRAM or can be connected to the image processing
54 * block such as IPIPE (on DM355/DM365 only).
55 *
56 * Features supported
57 * - MMAP IO
58 * - USERPTR IO
59 * - Capture using TVP5146 over BT.656
60 * - Support for interfacing decoders using sub device model
61 * - Work with DM365 or DM355 or DM6446 CCDC to do Raw Bayer
62 * RGB/YUV data capture to SDRAM.
63 * - Chaining of Image Processor
64 * - SINGLE-SHOT mode
65 */
66
67#include <linux/interrupt.h>
68#include <linux/module.h>
69#include <linux/slab.h>
70
71#include "vpfe.h"
72#include "vpfe_mc_capture.h"
73
74static bool debug;
75static bool interface;
76
77module_param(interface, bool, S_IRUGO);
78module_param(debug, bool, 0644);
79
80/**
81 * VPFE capture can be used for capturing video such as from TVP5146 or TVP7002
82 * and for capture raw bayer data from camera sensors such as mt9p031. At this
83 * point there is problem in co-existence of mt9p031 and tvp5146 due to i2c
84 * address collision. So set the variable below from bootargs to do either video
85 * capture or camera capture.
86 * interface = 0 - video capture (from TVP514x or such),
87 * interface = 1 - Camera capture (from mt9p031 or such)
88 * Re-visit this when we fix the co-existence issue
89 */
90MODULE_PARM_DESC(interface, "interface 0-1 (default:0)");
91MODULE_PARM_DESC(debug, "Debug level 0-1");
92
93MODULE_DESCRIPTION("VPFE Video for Linux Capture Driver");
94MODULE_LICENSE("GPL");
95MODULE_AUTHOR("Texas Instruments");
96
97/* map mbus_fmt to pixelformat */
98void mbus_to_pix(const struct v4l2_mbus_framefmt *mbus,
99 struct v4l2_pix_format *pix)
100{
101 switch (mbus->code) {
102 case V4L2_MBUS_FMT_UYVY8_2X8:
103 pix->pixelformat = V4L2_PIX_FMT_UYVY;
104 pix->bytesperline = pix->width * 2;
105 break;
106
107 case V4L2_MBUS_FMT_YUYV8_2X8:
108 pix->pixelformat = V4L2_PIX_FMT_YUYV;
109 pix->bytesperline = pix->width * 2;
110 break;
111
112 case V4L2_MBUS_FMT_YUYV10_1X20:
113 pix->pixelformat = V4L2_PIX_FMT_UYVY;
114 pix->bytesperline = pix->width * 2;
115 break;
116
117 case V4L2_MBUS_FMT_SGRBG12_1X12:
118 pix->pixelformat = V4L2_PIX_FMT_SBGGR16;
119 pix->bytesperline = pix->width * 2;
120 break;
121
122 case V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8:
123 pix->pixelformat = V4L2_PIX_FMT_SGRBG10DPCM8;
124 pix->bytesperline = pix->width;
125 break;
126
127 case V4L2_MBUS_FMT_SGRBG10_ALAW8_1X8:
128 pix->pixelformat = V4L2_PIX_FMT_SGRBG10ALAW8;
129 pix->bytesperline = pix->width;
130 break;
131
132 case V4L2_MBUS_FMT_YDYUYDYV8_1X16:
133 pix->pixelformat = V4L2_PIX_FMT_NV12;
134 pix->bytesperline = pix->width;
135 break;
136
137 case V4L2_MBUS_FMT_Y8_1X8:
138 pix->pixelformat = V4L2_PIX_FMT_GREY;
139 pix->bytesperline = pix->width;
140 break;
141
142 case V4L2_MBUS_FMT_UV8_1X8:
143 pix->pixelformat = V4L2_PIX_FMT_UV8;
144 pix->bytesperline = pix->width;
145 break;
146
147 default:
148 pr_err("Invalid mbus code set\n");
149 }
150 /* pitch should be 32 bytes aligned */
151 pix->bytesperline = ALIGN(pix->bytesperline, 32);
152 if (pix->pixelformat == V4L2_PIX_FMT_NV12)
153 pix->sizeimage = pix->bytesperline * pix->height +
154 ((pix->bytesperline * pix->height) >> 1);
155 else
156 pix->sizeimage = pix->bytesperline * pix->height;
157}
158
159/* ISR for VINT0*/
160static irqreturn_t vpfe_isr(int irq, void *dev_id)
161{
162 struct vpfe_device *vpfe_dev = dev_id;
163
164 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_isr\n");
165 vpfe_isif_buffer_isr(&vpfe_dev->vpfe_isif);
166 vpfe_resizer_buffer_isr(&vpfe_dev->vpfe_resizer);
167 return IRQ_HANDLED;
168}
169
170/* vpfe_vdint1_isr() - isr handler for VINT1 interrupt */
171static irqreturn_t vpfe_vdint1_isr(int irq, void *dev_id)
172{
173 struct vpfe_device *vpfe_dev = dev_id;
174
175 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_vdint1_isr\n");
176 vpfe_isif_vidint1_isr(&vpfe_dev->vpfe_isif);
177 return IRQ_HANDLED;
178}
179
180/* vpfe_imp_dma_isr() - ISR for ipipe dma completion */
181static irqreturn_t vpfe_imp_dma_isr(int irq, void *dev_id)
182{
183 struct vpfe_device *vpfe_dev = dev_id;
184
185 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_imp_dma_isr\n");
186 vpfe_ipipeif_ss_buffer_isr(&vpfe_dev->vpfe_ipipeif);
187 vpfe_resizer_dma_isr(&vpfe_dev->vpfe_resizer);
188 return IRQ_HANDLED;
189}
190
191/*
192 * vpfe_disable_clock() - Disable clocks for vpfe capture driver
193 * @vpfe_dev - ptr to vpfe capture device
194 *
195 * Disables clocks defined in vpfe configuration. The function
196 * assumes that at least one clock is to be defined which is
197 * true as of now.
198 */
199static void vpfe_disable_clock(struct vpfe_device *vpfe_dev)
200{
201 struct vpfe_config *vpfe_cfg = vpfe_dev->cfg;
202 int i;
203
204 for (i = 0; i < vpfe_cfg->num_clocks; i++) {
205 clk_disable_unprepare(vpfe_dev->clks[i]);
206 clk_put(vpfe_dev->clks[i]);
207 }
208 kzfree(vpfe_dev->clks);
209 v4l2_info(vpfe_dev->pdev->driver, "vpfe capture clocks disabled\n");
210}
211
212/*
213 * vpfe_enable_clock() - Enable clocks for vpfe capture driver
214 * @vpfe_dev - ptr to vpfe capture device
215 *
216 * Enables clocks defined in vpfe configuration. The function
217 * assumes that at least one clock is to be defined which is
218 * true as of now.
219 */
220static int vpfe_enable_clock(struct vpfe_device *vpfe_dev)
221{
222 struct vpfe_config *vpfe_cfg = vpfe_dev->cfg;
223 int ret = -EFAULT;
224 int i;
225
226 if (!vpfe_cfg->num_clocks)
227 return 0;
228
229 vpfe_dev->clks = kzalloc(vpfe_cfg->num_clocks *
230 sizeof(struct clock *), GFP_KERNEL);
231 if (vpfe_dev->clks == NULL) {
232 v4l2_err(vpfe_dev->pdev->driver, "Memory allocation failed\n");
233 return -ENOMEM;
234 }
235
236 for (i = 0; i < vpfe_cfg->num_clocks; i++) {
237 if (vpfe_cfg->clocks[i] == NULL) {
238 v4l2_err(vpfe_dev->pdev->driver,
239 "clock %s is not defined in vpfe config\n",
240 vpfe_cfg->clocks[i]);
241 goto out;
242 }
243
244 vpfe_dev->clks[i] =
245 clk_get(vpfe_dev->pdev, vpfe_cfg->clocks[i]);
246 if (vpfe_dev->clks[i] == NULL) {
247 v4l2_err(vpfe_dev->pdev->driver,
248 "Failed to get clock %s\n",
249 vpfe_cfg->clocks[i]);
250 goto out;
251 }
252
253 if (clk_prepare_enable(vpfe_dev->clks[i])) {
254 v4l2_err(vpfe_dev->pdev->driver,
255 "vpfe clock %s not enabled\n",
256 vpfe_cfg->clocks[i]);
257 goto out;
258 }
259
260 v4l2_info(vpfe_dev->pdev->driver, "vpss clock %s enabled",
261 vpfe_cfg->clocks[i]);
262 }
263
264 return 0;
265out:
266 for (i = 0; i < vpfe_cfg->num_clocks; i++)
267 if (vpfe_dev->clks[i]) {
268 clk_disable_unprepare(vpfe_dev->clks[i]);
269 clk_put(vpfe_dev->clks[i]);
270 }
271
272 v4l2_err(vpfe_dev->pdev->driver, "Failed to enable clocks\n");
273 kzfree(vpfe_dev->clks);
274
275 return ret;
276}
277
278/*
279 * vpfe_detach_irq() - Detach IRQs for vpfe capture driver
280 * @vpfe_dev - ptr to vpfe capture device
281 *
282 * Detach all IRQs defined in vpfe configuration.
283 */
284static void vpfe_detach_irq(struct vpfe_device *vpfe_dev)
285{
286 free_irq(vpfe_dev->ccdc_irq0, vpfe_dev);
287 free_irq(vpfe_dev->ccdc_irq1, vpfe_dev);
288 free_irq(vpfe_dev->imp_dma_irq, vpfe_dev);
289}
290
291/*
292 * vpfe_attach_irq() - Attach IRQs for vpfe capture driver
293 * @vpfe_dev - ptr to vpfe capture device
294 *
295 * Attach all IRQs defined in vpfe configuration.
296 */
297static int vpfe_attach_irq(struct vpfe_device *vpfe_dev)
298{
299 int ret = 0;
300
301 ret = request_irq(vpfe_dev->ccdc_irq0, vpfe_isr, IRQF_DISABLED,
302 "vpfe_capture0", vpfe_dev);
303 if (ret < 0) {
304 v4l2_err(&vpfe_dev->v4l2_dev,
305 "Error: requesting VINT0 interrupt\n");
306 return ret;
307 }
308
309 ret = request_irq(vpfe_dev->ccdc_irq1, vpfe_vdint1_isr, IRQF_DISABLED,
310 "vpfe_capture1", vpfe_dev);
311 if (ret < 0) {
312 v4l2_err(&vpfe_dev->v4l2_dev,
313 "Error: requesting VINT1 interrupt\n");
314 free_irq(vpfe_dev->ccdc_irq0, vpfe_dev);
315 return ret;
316 }
317
318 ret = request_irq(vpfe_dev->imp_dma_irq, vpfe_imp_dma_isr,
319 IRQF_DISABLED, "Imp_Sdram_Irq", vpfe_dev);
320 if (ret < 0) {
321 v4l2_err(&vpfe_dev->v4l2_dev,
322 "Error: requesting IMP IRQ interrupt\n");
323 free_irq(vpfe_dev->ccdc_irq1, vpfe_dev);
324 free_irq(vpfe_dev->ccdc_irq0, vpfe_dev);
325 return ret;
326 }
327
328 return 0;
329}
330
331/*
332 * register_i2c_devices() - register all i2c v4l2 subdevs
333 * @vpfe_dev - ptr to vpfe capture device
334 *
335 * register all i2c v4l2 subdevs
336 */
337static int register_i2c_devices(struct vpfe_device *vpfe_dev)
338{
339 struct vpfe_ext_subdev_info *sdinfo;
340 struct vpfe_config *vpfe_cfg;
341 struct i2c_adapter *i2c_adap;
342 unsigned int num_subdevs;
343 int ret;
344 int i;
345 int k;
346
347 vpfe_cfg = vpfe_dev->cfg;
348 i2c_adap = i2c_get_adapter(1);
349 num_subdevs = vpfe_cfg->num_subdevs;
350 vpfe_dev->sd =
351 kzalloc(sizeof(struct v4l2_subdev *)*num_subdevs, GFP_KERNEL);
352 if (vpfe_dev->sd == NULL) {
353 v4l2_err(&vpfe_dev->v4l2_dev,
354 "unable to allocate memory for subdevice\n");
355 return -ENOMEM;
356 }
357
358 for (i = 0, k = 0; i < num_subdevs; i++) {
359 sdinfo = &vpfe_cfg->sub_devs[i];
360 /*
361 * register subdevices based on interface setting. Currently
362 * tvp5146 and mt9p031 cannot co-exists due to i2c address
363 * conflicts. So only one of them is registered. Re-visit this
364 * once we have support for i2c switch handling in i2c driver
365 * framework
366 */
367 if (interface == sdinfo->is_camera) {
368 /* setup input path */
369 if (vpfe_cfg->setup_input &&
370 vpfe_cfg->setup_input(sdinfo->grp_id) < 0) {
371 ret = -EFAULT;
372 v4l2_info(&vpfe_dev->v4l2_dev,
373 "could not setup input for %s\n",
374 sdinfo->module_name);
375 goto probe_sd_out;
376 }
377 /* Load up the subdevice */
378 vpfe_dev->sd[k] =
379 v4l2_i2c_new_subdev_board(&vpfe_dev->v4l2_dev,
380 i2c_adap, &sdinfo->board_info,
381 NULL);
382 if (vpfe_dev->sd[k]) {
383 v4l2_info(&vpfe_dev->v4l2_dev,
384 "v4l2 sub device %s registered\n",
385 sdinfo->module_name);
386
387 vpfe_dev->sd[k]->grp_id = sdinfo->grp_id;
388 k++;
389
390 sdinfo->registered = 1;
391 }
392 } else {
393 v4l2_info(&vpfe_dev->v4l2_dev,
394 "v4l2 sub device %s is not registered\n",
395 sdinfo->module_name);
396 }
397 }
398 vpfe_dev->num_ext_subdevs = k;
399
400 return 0;
401
402probe_sd_out:
403 kzfree(vpfe_dev->sd);
404
405 return ret;
406}
407
408/*
409 * vpfe_register_entities() - register all v4l2 subdevs and media entities
410 * @vpfe_dev - ptr to vpfe capture device
411 *
412 * register all v4l2 subdevs, media entities, and creates links
413 * between entities
414 */
415static int vpfe_register_entities(struct vpfe_device *vpfe_dev)
416{
417 unsigned int flags = 0;
418 int ret;
419 int i;
420
421 /* register i2c devices first */
422 ret = register_i2c_devices(vpfe_dev);
423 if (ret)
424 return ret;
425
426 /* register rest of the sub-devs */
427 ret = vpfe_isif_register_entities(&vpfe_dev->vpfe_isif,
428 &vpfe_dev->v4l2_dev);
429 if (ret)
430 return ret;
431
432 ret = vpfe_ipipeif_register_entities(&vpfe_dev->vpfe_ipipeif,
433 &vpfe_dev->v4l2_dev);
434 if (ret)
435 goto out_isif_register;
436
437 ret = vpfe_ipipe_register_entities(&vpfe_dev->vpfe_ipipe,
438 &vpfe_dev->v4l2_dev);
439 if (ret)
440 goto out_ipipeif_register;
441
442 ret = vpfe_resizer_register_entities(&vpfe_dev->vpfe_resizer,
443 &vpfe_dev->v4l2_dev);
444 if (ret)
445 goto out_ipipe_register;
446
447 /* create links now, starting with external(i2c) entities */
448 for (i = 0; i < vpfe_dev->num_ext_subdevs; i++)
449 /* if entity has no pads (ex: amplifier),
450 cant establish link */
451 if (vpfe_dev->sd[i]->entity.num_pads) {
452 ret = media_entity_create_link(&vpfe_dev->sd[i]->entity,
453 0, &vpfe_dev->vpfe_isif.subdev.entity,
454 0, flags);
455 if (ret < 0)
456 goto out_resizer_register;
457 }
458
459 ret = media_entity_create_link(&vpfe_dev->vpfe_isif.subdev.entity, 1,
460 &vpfe_dev->vpfe_ipipeif.subdev.entity,
461 0, flags);
462 if (ret < 0)
463 goto out_resizer_register;
464
465 ret = media_entity_create_link(&vpfe_dev->vpfe_ipipeif.subdev.entity, 1,
466 &vpfe_dev->vpfe_ipipe.subdev.entity,
467 0, flags);
468 if (ret < 0)
469 goto out_resizer_register;
470
471 ret = media_entity_create_link(&vpfe_dev->vpfe_ipipe.subdev.entity,
472 1, &vpfe_dev->vpfe_resizer.crop_resizer.subdev.entity,
473 0, flags);
474 if (ret < 0)
475 goto out_resizer_register;
476
477 ret = media_entity_create_link(&vpfe_dev->vpfe_ipipeif.subdev.entity, 1,
478 &vpfe_dev->vpfe_resizer.crop_resizer.subdev.entity,
479 0, flags);
480 if (ret < 0)
481 goto out_resizer_register;
482
483 ret = v4l2_device_register_subdev_nodes(&vpfe_dev->v4l2_dev);
484 if (ret < 0)
485 goto out_resizer_register;
486
487 return 0;
488
489out_resizer_register:
490 vpfe_resizer_unregister_entities(&vpfe_dev->vpfe_resizer);
491out_ipipe_register:
492 vpfe_ipipe_unregister_entities(&vpfe_dev->vpfe_ipipe);
493out_ipipeif_register:
494 vpfe_ipipeif_unregister_entities(&vpfe_dev->vpfe_ipipeif);
495out_isif_register:
496 vpfe_isif_unregister_entities(&vpfe_dev->vpfe_isif);
497
498 return ret;
499}
500
501/*
502 * vpfe_unregister_entities() - unregister all v4l2 subdevs and media entities
503 * @vpfe_dev - ptr to vpfe capture device
504 *
505 * unregister all v4l2 subdevs and media entities
506 */
507static void vpfe_unregister_entities(struct vpfe_device *vpfe_dev)
508{
509 vpfe_isif_unregister_entities(&vpfe_dev->vpfe_isif);
510 vpfe_ipipeif_unregister_entities(&vpfe_dev->vpfe_ipipeif);
511 vpfe_ipipe_unregister_entities(&vpfe_dev->vpfe_ipipe);
512 vpfe_resizer_unregister_entities(&vpfe_dev->vpfe_resizer);
513}
514
515/*
516 * vpfe_cleanup_modules() - cleanup all non-i2c v4l2 subdevs
517 * @vpfe_dev - ptr to vpfe capture device
518 * @pdev - pointer to platform device
519 *
520 * cleanup all v4l2 subdevs
521 */
522static void vpfe_cleanup_modules(struct vpfe_device *vpfe_dev,
523 struct platform_device *pdev)
524{
525 vpfe_isif_cleanup(&vpfe_dev->vpfe_isif, pdev);
526 vpfe_ipipeif_cleanup(&vpfe_dev->vpfe_ipipeif, pdev);
527 vpfe_ipipe_cleanup(&vpfe_dev->vpfe_ipipe, pdev);
528 vpfe_resizer_cleanup(&vpfe_dev->vpfe_resizer, pdev);
529}
530
531/*
532 * vpfe_initialize_modules() - initialize all non-i2c v4l2 subdevs
533 * @vpfe_dev - ptr to vpfe capture device
534 * @pdev - pointer to platform device
535 *
536 * intialize all v4l2 subdevs and media entities
537 */
538static int vpfe_initialize_modules(struct vpfe_device *vpfe_dev,
539 struct platform_device *pdev)
540{
541 int ret;
542
543 ret = vpfe_isif_init(&vpfe_dev->vpfe_isif, pdev);
544 if (ret)
545 return ret;
546
547 ret = vpfe_ipipeif_init(&vpfe_dev->vpfe_ipipeif, pdev);
548 if (ret)
549 goto out_isif_init;
550
551 ret = vpfe_ipipe_init(&vpfe_dev->vpfe_ipipe, pdev);
552 if (ret)
553 goto out_ipipeif_init;
554
555 ret = vpfe_resizer_init(&vpfe_dev->vpfe_resizer, pdev);
556 if (ret)
557 goto out_ipipe_init;
558
559 return 0;
560
561out_ipipe_init:
562 vpfe_ipipe_cleanup(&vpfe_dev->vpfe_ipipe, pdev);
563out_ipipeif_init:
564 vpfe_ipipeif_cleanup(&vpfe_dev->vpfe_ipipeif, pdev);
565out_isif_init:
566 vpfe_isif_cleanup(&vpfe_dev->vpfe_isif, pdev);
567
568 return ret;
569}
570
571/*
572 * vpfe_probe() : vpfe probe function
573 * @pdev: platform device pointer
574 *
575 * This function creates device entries by register itself to the V4L2 driver
576 * and initializes fields of each device objects
577 */
578static int vpfe_probe(struct platform_device *pdev)
579{
580 struct vpfe_device *vpfe_dev;
581 struct resource *res1;
582 int ret = -ENOMEM;
583
584 vpfe_dev = kzalloc(sizeof(*vpfe_dev), GFP_KERNEL);
585 if (!vpfe_dev) {
586 v4l2_err(pdev->dev.driver,
587 "Failed to allocate memory for vpfe_dev\n");
588 return ret;
589 }
590
591 if (pdev->dev.platform_data == NULL) {
592 v4l2_err(pdev->dev.driver, "Unable to get vpfe config\n");
593 ret = -ENOENT;
594 goto probe_free_dev_mem;
595 }
596
597 vpfe_dev->cfg = pdev->dev.platform_data;
598 if (vpfe_dev->cfg->card_name == NULL ||
599 vpfe_dev->cfg->sub_devs == NULL) {
600 v4l2_err(pdev->dev.driver, "null ptr in vpfe_cfg\n");
601 ret = -ENOENT;
602 goto probe_free_dev_mem;
603 }
604
605 /* Get VINT0 irq resource */
606 res1 = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
607 if (!res1) {
608 v4l2_err(pdev->dev.driver,
609 "Unable to get interrupt for VINT0\n");
610 ret = -ENOENT;
611 goto probe_free_dev_mem;
612 }
613 vpfe_dev->ccdc_irq0 = res1->start;
614
615 /* Get VINT1 irq resource */
616 res1 = platform_get_resource(pdev, IORESOURCE_IRQ, 1);
617 if (!res1) {
618 v4l2_err(pdev->dev.driver,
619 "Unable to get interrupt for VINT1\n");
620 ret = -ENOENT;
621 goto probe_free_dev_mem;
622 }
623 vpfe_dev->ccdc_irq1 = res1->start;
624
625 /* Get DMA irq resource */
626 res1 = platform_get_resource(pdev, IORESOURCE_IRQ, 2);
627 if (!res1) {
628 v4l2_err(pdev->dev.driver,
629 "Unable to get interrupt for DMA\n");
630 ret = -ENOENT;
631 goto probe_free_dev_mem;
632 }
633 vpfe_dev->imp_dma_irq = res1->start;
634
635 vpfe_dev->pdev = &pdev->dev;
636
637 /* enable vpss clocks */
638 ret = vpfe_enable_clock(vpfe_dev);
639 if (ret)
640 goto probe_free_dev_mem;
641
642 if (vpfe_initialize_modules(vpfe_dev, pdev))
643 goto probe_disable_clock;
644
645 vpfe_dev->media_dev.dev = vpfe_dev->pdev;
646 strcpy((char *)&vpfe_dev->media_dev.model, "davinci-media");
647
648 ret = media_device_register(&vpfe_dev->media_dev);
649 if (ret) {
650 v4l2_err(pdev->dev.driver,
651 "Unable to register media device.\n");
652 goto probe_out_entities_cleanup;
653 }
654
655 vpfe_dev->v4l2_dev.mdev = &vpfe_dev->media_dev;
656 ret = v4l2_device_register(&pdev->dev, &vpfe_dev->v4l2_dev);
657 if (ret) {
658 v4l2_err(pdev->dev.driver, "Unable to register v4l2 device.\n");
659 goto probe_out_media_unregister;
660 }
661
662 v4l2_info(&vpfe_dev->v4l2_dev, "v4l2 device registered\n");
663 /* set the driver data in platform device */
664 platform_set_drvdata(pdev, vpfe_dev);
665 /* register subdevs/entities */
666 if (vpfe_register_entities(vpfe_dev))
667 goto probe_out_v4l2_unregister;
668
669 ret = vpfe_attach_irq(vpfe_dev);
670 if (ret)
671 goto probe_out_entities_unregister;
672
673 return 0;
674
675probe_out_entities_unregister:
676 vpfe_unregister_entities(vpfe_dev);
677 kzfree(vpfe_dev->sd);
678probe_out_v4l2_unregister:
679 v4l2_device_unregister(&vpfe_dev->v4l2_dev);
680probe_out_media_unregister:
681 media_device_unregister(&vpfe_dev->media_dev);
682probe_out_entities_cleanup:
683 vpfe_cleanup_modules(vpfe_dev, pdev);
684probe_disable_clock:
685 vpfe_disable_clock(vpfe_dev);
686probe_free_dev_mem:
687 kzfree(vpfe_dev);
688
689 return ret;
690}
691
692/*
693 * vpfe_remove : This function un-registers device from V4L2 driver
694 */
695static int vpfe_remove(struct platform_device *pdev)
696{
697 struct vpfe_device *vpfe_dev = platform_get_drvdata(pdev);
698
699 v4l2_info(pdev->dev.driver, "vpfe_remove\n");
700
701 kzfree(vpfe_dev->sd);
702 vpfe_detach_irq(vpfe_dev);
703 vpfe_unregister_entities(vpfe_dev);
704 vpfe_cleanup_modules(vpfe_dev, pdev);
705 v4l2_device_unregister(&vpfe_dev->v4l2_dev);
706 media_device_unregister(&vpfe_dev->media_dev);
707 vpfe_disable_clock(vpfe_dev);
708 kzfree(vpfe_dev);
709
710 return 0;
711}
712
713static struct platform_driver vpfe_driver = {
714 .driver = {
715 .name = CAPTURE_DRV_NAME,
716 .owner = THIS_MODULE,
717 },
718 .probe = vpfe_probe,
719 .remove = vpfe_remove,
720};
721
722/**
723 * vpfe_init : This function registers device driver
724 */
725static __init int vpfe_init(void)
726{
727 /* Register driver to the kernel */
728 return platform_driver_register(&vpfe_driver);
729}
730
731/**
732 * vpfe_cleanup : This function un-registers device driver
733 */
734static void vpfe_cleanup(void)
735{
736 platform_driver_unregister(&vpfe_driver);
737}
738
739module_init(vpfe_init);
740module_exit(vpfe_cleanup);
diff --git a/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.h b/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.h
new file mode 100644
index 000000000000..68f6fe43a5b5
--- /dev/null
+++ b/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.h
@@ -0,0 +1,97 @@
1/*
2 * Copyright (C) 2012 Texas Instruments Inc
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation version 2.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Contributors:
18 * Manjunath Hadli <manjunath.hadli@ti.com>
19 * Prabhakar Lad <prabhakar.lad@ti.com>
20 */
21
22#ifndef _DAVINCI_VPFE_MC_CAPTURE_H
23#define _DAVINCI_VPFE_MC_CAPTURE_H
24
25#include "dm365_ipipe.h"
26#include "dm365_ipipeif.h"
27#include "dm365_isif.h"
28#include "dm365_resizer.h"
29#include "vpfe_video.h"
30
31#define VPFE_MAJOR_RELEASE 0
32#define VPFE_MINOR_RELEASE 0
33#define VPFE_BUILD 1
34#define VPFE_CAPTURE_VERSION_CODE ((VPFE_MAJOR_RELEASE << 16) | \
35 (VPFE_MINOR_RELEASE << 8) | \
36 VPFE_BUILD)
37
38/* IPIPE hardware limits */
39#define IPIPE_MAX_OUTPUT_WIDTH_A 2176
40#define IPIPE_MAX_OUTPUT_WIDTH_B 640
41
42/* Based on max resolution supported. QXGA */
43#define IPIPE_MAX_OUTPUT_HEIGHT_A 1536
44/* Based on max resolution supported. VGA */
45#define IPIPE_MAX_OUTPUT_HEIGHT_B 480
46
47#define to_vpfe_device(ptr_module) \
48 container_of(ptr_module, struct vpfe_device, vpfe_##ptr_module)
49#define to_device(ptr_module) \
50 (to_vpfe_device(ptr_module)->dev)
51
52struct vpfe_device {
53 /* external registered sub devices */
54 struct v4l2_subdev **sd;
55 /* number of registered external subdevs */
56 unsigned int num_ext_subdevs;
57 /* vpfe cfg */
58 struct vpfe_config *cfg;
59 /* clock ptrs for vpfe capture */
60 struct clk **clks;
61 /* V4l2 device */
62 struct v4l2_device v4l2_dev;
63 /* parent device */
64 struct device *pdev;
65 /* IRQ number for DMA transfer completion at the image processor */
66 unsigned int imp_dma_irq;
67 /* CCDC IRQs used when CCDC/ISIF output to SDRAM */
68 unsigned int ccdc_irq0;
69 unsigned int ccdc_irq1;
70 /* maximum video memory that is available*/
71 unsigned int video_limit;
72 /* media device */
73 struct media_device media_dev;
74 /* ccdc subdevice */
75 struct vpfe_isif_device vpfe_isif;
76 /* ipipeif subdevice */
77 struct vpfe_ipipeif_device vpfe_ipipeif;
78 /* ipipe subdevice */
79 struct vpfe_ipipe_device vpfe_ipipe;
80 /* resizer subdevice */
81 struct vpfe_resizer_device vpfe_resizer;
82};
83
84/* File handle structure */
85struct vpfe_fh {
86 struct v4l2_fh vfh;
87 struct vpfe_video_device *video;
88 /* Indicates whether this file handle is doing IO */
89 u8 io_allowed;
90 /* Used to keep track priority of this instance */
91 enum v4l2_priority prio;
92};
93
94void mbus_to_pix(const struct v4l2_mbus_framefmt *mbus,
95 struct v4l2_pix_format *pix);
96
97#endif /* _DAVINCI_VPFE_MC_CAPTURE_H */
diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
new file mode 100644
index 000000000000..99ccbebea598
--- /dev/null
+++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
@@ -0,0 +1,1620 @@
1/*
2 * Copyright (C) 2012 Texas Instruments Inc
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation version 2.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Contributors:
18 * Manjunath Hadli <manjunath.hadli@ti.com>
19 * Prabhakar Lad <prabhakar.lad@ti.com>
20 */
21
22#include <linux/module.h>
23#include <linux/slab.h>
24
25#include <media/v4l2-ioctl.h>
26
27#include "vpfe.h"
28#include "vpfe_mc_capture.h"
29
30/* minimum number of buffers needed in cont-mode */
31#define MIN_NUM_BUFFERS 3
32
33static int debug;
34
35/* get v4l2 subdev pointer to external subdev which is active */
36static struct media_entity *vpfe_get_input_entity
37 (struct vpfe_video_device *video)
38{
39 struct vpfe_device *vpfe_dev = video->vpfe_dev;
40 struct media_pad *remote;
41
42 remote = media_entity_remote_source(&vpfe_dev->vpfe_isif.pads[0]);
43 if (remote == NULL) {
44 pr_err("Invalid media connection to isif/ccdc\n");
45 return NULL;
46 }
47 return remote->entity;
48}
49
50/* updates external subdev(sensor/decoder) which is active */
51static int vpfe_update_current_ext_subdev(struct vpfe_video_device *video)
52{
53 struct vpfe_device *vpfe_dev = video->vpfe_dev;
54 struct vpfe_config *vpfe_cfg;
55 struct v4l2_subdev *subdev;
56 struct media_pad *remote;
57 int i;
58
59 remote = media_entity_remote_source(&vpfe_dev->vpfe_isif.pads[0]);
60 if (remote == NULL) {
61 pr_err("Invalid media connection to isif/ccdc\n");
62 return -EINVAL;
63 }
64
65 subdev = media_entity_to_v4l2_subdev(remote->entity);
66 vpfe_cfg = vpfe_dev->pdev->platform_data;
67 for (i = 0; i < vpfe_cfg->num_subdevs; i++) {
68 if (!strcmp(vpfe_cfg->sub_devs[i].module_name, subdev->name)) {
69 video->current_ext_subdev = &vpfe_cfg->sub_devs[i];
70 break;
71 }
72 }
73
74 /* if user not linked decoder/sensor to isif/ccdc */
75 if (i == vpfe_cfg->num_subdevs) {
76 pr_err("Invalid media chain connection to isif/ccdc\n");
77 return -EINVAL;
78 }
79 /* find the v4l2 subdev pointer */
80 for (i = 0; i < vpfe_dev->num_ext_subdevs; i++) {
81 if (!strcmp(video->current_ext_subdev->module_name,
82 vpfe_dev->sd[i]->name))
83 video->current_ext_subdev->subdev = vpfe_dev->sd[i];
84 }
85 return 0;
86}
87
88/* get the subdev which is connected to the output video node */
89static struct v4l2_subdev *
90vpfe_video_remote_subdev(struct vpfe_video_device *video, u32 *pad)
91{
92 struct media_pad *remote = media_entity_remote_source(&video->pad);
93
94 if (remote == NULL || remote->entity->type != MEDIA_ENT_T_V4L2_SUBDEV)
95 return NULL;
96 if (pad)
97 *pad = remote->index;
98 return media_entity_to_v4l2_subdev(remote->entity);
99}
100
101/* get the format set at output pad of the adjacent subdev */
102static int
103__vpfe_video_get_format(struct vpfe_video_device *video,
104 struct v4l2_format *format)
105{
106 struct v4l2_subdev_format fmt;
107 struct v4l2_subdev *subdev;
108 struct media_pad *remote;
109 u32 pad;
110 int ret;
111
112 subdev = vpfe_video_remote_subdev(video, &pad);
113 if (subdev == NULL)
114 return -EINVAL;
115
116 fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
117 remote = media_entity_remote_source(&video->pad);
118 fmt.pad = remote->index;
119
120 ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &fmt);
121 if (ret == -ENOIOCTLCMD)
122 return -EINVAL;
123
124 format->type = video->type;
125 /* convert mbus_format to v4l2_format */
126 v4l2_fill_pix_format(&format->fmt.pix, &fmt.format);
127 mbus_to_pix(&fmt.format, &format->fmt.pix);
128
129 return 0;
130}
131
132/* make a note of pipeline details */
133static void vpfe_prepare_pipeline(struct vpfe_video_device *video)
134{
135 struct media_entity *entity = &video->video_dev.entity;
136 struct media_device *mdev = entity->parent;
137 struct vpfe_pipeline *pipe = &video->pipe;
138 struct vpfe_video_device *far_end = NULL;
139 struct media_entity_graph graph;
140
141 pipe->input_num = 0;
142 pipe->output_num = 0;
143
144 if (video->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
145 pipe->inputs[pipe->input_num++] = video;
146 else
147 pipe->outputs[pipe->output_num++] = video;
148
149 mutex_lock(&mdev->graph_mutex);
150 media_entity_graph_walk_start(&graph, entity);
151 while ((entity = media_entity_graph_walk_next(&graph))) {
152 if (entity == &video->video_dev.entity)
153 continue;
154 if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
155 continue;
156 far_end = to_vpfe_video(media_entity_to_video_device(entity));
157 if (far_end->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
158 pipe->inputs[pipe->input_num++] = far_end;
159 else
160 pipe->outputs[pipe->output_num++] = far_end;
161 }
162 mutex_unlock(&mdev->graph_mutex);
163}
164
165/* update pipe state selected by user */
166static int vpfe_update_pipe_state(struct vpfe_video_device *video)
167{
168 struct vpfe_pipeline *pipe = &video->pipe;
169 int ret;
170
171 vpfe_prepare_pipeline(video);
172
173 /* Find out if there is any input video
174 if yes, it is single shot.
175 */
176 if (pipe->input_num == 0) {
177 pipe->state = VPFE_PIPELINE_STREAM_CONTINUOUS;
178 ret = vpfe_update_current_ext_subdev(video);
179 if (ret) {
180 pr_err("Invalid external subdev\n");
181 return ret;
182 }
183 } else {
184 pipe->state = VPFE_PIPELINE_STREAM_SINGLESHOT;
185 }
186 video->initialized = 1;
187 video->skip_frame_count = 1;
188 video->skip_frame_count_init = 1;
189 return 0;
190}
191
192/* checks wether pipeline is ready for enabling */
193int vpfe_video_is_pipe_ready(struct vpfe_pipeline *pipe)
194{
195 int i;
196
197 for (i = 0; i < pipe->input_num; i++)
198 if (!pipe->inputs[i]->started ||
199 pipe->inputs[i]->state != VPFE_VIDEO_BUFFER_QUEUED)
200 return 0;
201 for (i = 0; i < pipe->output_num; i++)
202 if (!pipe->outputs[i]->started ||
203 pipe->outputs[i]->state != VPFE_VIDEO_BUFFER_QUEUED)
204 return 0;
205 return 1;
206}
207
208/**
209 * Validate a pipeline by checking both ends of all links for format
210 * discrepancies.
211 *
212 * Return 0 if all formats match, or -EPIPE if at least one link is found with
213 * different formats on its two ends.
214 */
215static int vpfe_video_validate_pipeline(struct vpfe_pipeline *pipe)
216{
217 struct v4l2_subdev_format fmt_source;
218 struct v4l2_subdev_format fmt_sink;
219 struct v4l2_subdev *subdev;
220 struct media_pad *pad;
221 int ret;
222
223 /*
224 * Should not matter if it is output[0] or 1 as
225 * the general ideas is to traverse backwards and
226 * the fact that the out video node always has the
227 * format of the connected pad.
228 */
229 subdev = vpfe_video_remote_subdev(pipe->outputs[0], NULL);
230 if (subdev == NULL)
231 return -EPIPE;
232
233 while (1) {
234 /* Retrieve the sink format */
235 pad = &subdev->entity.pads[0];
236 if (!(pad->flags & MEDIA_PAD_FL_SINK))
237 break;
238
239 fmt_sink.which = V4L2_SUBDEV_FORMAT_ACTIVE;
240 fmt_sink.pad = pad->index;
241 ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL,
242 &fmt_sink);
243
244 if (ret < 0 && ret != -ENOIOCTLCMD)
245 return -EPIPE;
246
247 /* Retrieve the source format */
248 pad = media_entity_remote_source(pad);
249 if (pad == NULL ||
250 pad->entity->type != MEDIA_ENT_T_V4L2_SUBDEV)
251 break;
252
253 subdev = media_entity_to_v4l2_subdev(pad->entity);
254
255 fmt_source.which = V4L2_SUBDEV_FORMAT_ACTIVE;
256 fmt_source.pad = pad->index;
257 ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &fmt_source);
258 if (ret < 0 && ret != -ENOIOCTLCMD)
259 return -EPIPE;
260
261 /* Check if the two ends match */
262 if (fmt_source.format.code != fmt_sink.format.code ||
263 fmt_source.format.width != fmt_sink.format.width ||
264 fmt_source.format.height != fmt_sink.format.height)
265 return -EPIPE;
266 }
267 return 0;
268}
269
270/*
271 * vpfe_pipeline_enable() - Enable streaming on a pipeline
272 * @vpfe_dev: vpfe device
273 * @pipe: vpfe pipeline
274 *
275 * Walk the entities chain starting at the pipeline output video node and start
276 * all modules in the chain in the given mode.
277 *
278 * Return 0 if successful, or the return value of the failed video::s_stream
279 * operation otherwise.
280 */
281static int vpfe_pipeline_enable(struct vpfe_pipeline *pipe)
282{
283 struct media_entity_graph graph;
284 struct media_entity *entity;
285 struct v4l2_subdev *subdev;
286 struct media_device *mdev;
287 int ret = 0;
288
289 if (pipe->state == VPFE_PIPELINE_STREAM_CONTINUOUS)
290 entity = vpfe_get_input_entity(pipe->outputs[0]);
291 else
292 entity = &pipe->inputs[0]->video_dev.entity;
293
294 mdev = entity->parent;
295 mutex_lock(&mdev->graph_mutex);
296 media_entity_graph_walk_start(&graph, entity);
297 while ((entity = media_entity_graph_walk_next(&graph))) {
298
299 if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
300 continue;
301 subdev = media_entity_to_v4l2_subdev(entity);
302 ret = v4l2_subdev_call(subdev, video, s_stream, 1);
303 if (ret < 0 && ret != -ENOIOCTLCMD)
304 break;
305 }
306 mutex_unlock(&mdev->graph_mutex);
307 return ret;
308}
309
310/*
311 * vpfe_pipeline_disable() - Disable streaming on a pipeline
312 * @vpfe_dev: vpfe device
313 * @pipe: VPFE pipeline
314 *
315 * Walk the entities chain starting at the pipeline output video node and stop
316 * all modules in the chain.
317 *
318 * Return 0 if all modules have been properly stopped, or -ETIMEDOUT if a module
319 * can't be stopped.
320 */
321static int vpfe_pipeline_disable(struct vpfe_pipeline *pipe)
322{
323 struct media_entity_graph graph;
324 struct media_entity *entity;
325 struct v4l2_subdev *subdev;
326 struct media_device *mdev;
327 int ret = 0;
328
329 if (pipe->state == VPFE_PIPELINE_STREAM_CONTINUOUS)
330 entity = vpfe_get_input_entity(pipe->outputs[0]);
331 else
332 entity = &pipe->inputs[0]->video_dev.entity;
333
334 mdev = entity->parent;
335 mutex_lock(&mdev->graph_mutex);
336 media_entity_graph_walk_start(&graph, entity);
337
338 while ((entity = media_entity_graph_walk_next(&graph))) {
339
340 if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
341 continue;
342 subdev = media_entity_to_v4l2_subdev(entity);
343 ret = v4l2_subdev_call(subdev, video, s_stream, 0);
344 if (ret < 0 && ret != -ENOIOCTLCMD)
345 break;
346 }
347 mutex_unlock(&mdev->graph_mutex);
348
349 return (ret == 0) ? ret : -ETIMEDOUT ;
350}
351
352/*
353 * vpfe_pipeline_set_stream() - Enable/disable streaming on a pipeline
354 * @vpfe_dev: VPFE device
355 * @pipe: VPFE pipeline
356 * @state: Stream state (stopped or active)
357 *
358 * Set the pipeline to the given stream state.
359 *
360 * Return 0 if successfull, or the return value of the failed video::s_stream
361 * operation otherwise.
362 */
363static int vpfe_pipeline_set_stream(struct vpfe_pipeline *pipe,
364 enum vpfe_pipeline_stream_state state)
365{
366 if (state == VPFE_PIPELINE_STREAM_STOPPED)
367 return vpfe_pipeline_disable(pipe);
368
369 return vpfe_pipeline_enable(pipe);
370}
371
372static int all_videos_stopped(struct vpfe_video_device *video)
373{
374 struct vpfe_pipeline *pipe = &video->pipe;
375 int i;
376
377 for (i = 0; i < pipe->input_num; i++)
378 if (pipe->inputs[i]->started)
379 return 0;
380 for (i = 0; i < pipe->output_num; i++)
381 if (pipe->outputs[i]->started)
382 return 0;
383 return 1;
384}
385
386/*
387 * vpfe_open() - open video device
388 * @file: file pointer
389 *
390 * initialize media pipeline state, allocate memory for file handle
391 *
392 * Return 0 if successful, or the return -ENODEV otherwise.
393 */
394static int vpfe_open(struct file *file)
395{
396 struct vpfe_video_device *video = video_drvdata(file);
397 struct vpfe_fh *handle;
398
399 /* Allocate memory for the file handle object */
400 handle = kzalloc(sizeof(struct vpfe_fh), GFP_KERNEL);
401
402 if (handle == NULL)
403 return -ENOMEM;
404
405 v4l2_fh_init(&handle->vfh, &video->video_dev);
406 v4l2_fh_add(&handle->vfh);
407
408 mutex_lock(&video->lock);
409 /* If decoder is not initialized. initialize it */
410 if (!video->initialized && vpfe_update_pipe_state(video)) {
411 mutex_unlock(&video->lock);
412 return -ENODEV;
413 }
414 /* Increment device users counter */
415 video->usrs++;
416 /* Set io_allowed member to false */
417 handle->io_allowed = 0;
418 v4l2_prio_open(&video->prio, &handle->prio);
419 handle->video = video;
420 file->private_data = &handle->vfh;
421 mutex_unlock(&video->lock);
422
423 return 0;
424}
425
426/* get the next buffer available from dma queue */
427static unsigned long
428vpfe_video_get_next_buffer(struct vpfe_video_device *video)
429{
430 video->cur_frm = video->next_frm =
431 list_entry(video->dma_queue.next,
432 struct vpfe_cap_buffer, list);
433
434 list_del(&video->next_frm->list);
435 video->next_frm->vb.state = VB2_BUF_STATE_ACTIVE;
436 return vb2_dma_contig_plane_dma_addr(&video->next_frm->vb, 0);
437}
438
439/* schedule the next buffer which is available on dma queue */
440void vpfe_video_schedule_next_buffer(struct vpfe_video_device *video)
441{
442 struct vpfe_device *vpfe_dev = video->vpfe_dev;
443 unsigned long addr;
444
445 if (list_empty(&video->dma_queue))
446 return;
447
448 video->next_frm = list_entry(video->dma_queue.next,
449 struct vpfe_cap_buffer, list);
450
451 if (VPFE_PIPELINE_STREAM_SINGLESHOT == video->pipe.state)
452 video->cur_frm = video->next_frm;
453
454 list_del(&video->next_frm->list);
455 video->next_frm->vb.state = VB2_BUF_STATE_ACTIVE;
456 addr = vb2_dma_contig_plane_dma_addr(&video->next_frm->vb, 0);
457 video->ops->queue(vpfe_dev, addr);
458 video->state = VPFE_VIDEO_BUFFER_QUEUED;
459}
460
461/* schedule the buffer for capturing bottom field */
462void vpfe_video_schedule_bottom_field(struct vpfe_video_device *video)
463{
464 struct vpfe_device *vpfe_dev = video->vpfe_dev;
465 unsigned long addr;
466
467 addr = vb2_dma_contig_plane_dma_addr(&video->cur_frm->vb, 0);
468 addr += video->field_off;
469 video->ops->queue(vpfe_dev, addr);
470}
471
472/* make buffer available for dequeue */
473void vpfe_video_process_buffer_complete(struct vpfe_video_device *video)
474{
475 struct vpfe_pipeline *pipe = &video->pipe;
476
477 do_gettimeofday(&video->cur_frm->vb.v4l2_buf.timestamp);
478 vb2_buffer_done(&video->cur_frm->vb, VB2_BUF_STATE_DONE);
479 if (pipe->state == VPFE_PIPELINE_STREAM_CONTINUOUS)
480 video->cur_frm = video->next_frm;
481}
482
483/* vpfe_stop_capture() - stop streaming */
484static void vpfe_stop_capture(struct vpfe_video_device *video)
485{
486 struct vpfe_pipeline *pipe = &video->pipe;
487
488 video->started = 0;
489
490 if (video->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
491 return;
492 if (all_videos_stopped(video))
493 vpfe_pipeline_set_stream(pipe,
494 VPFE_PIPELINE_STREAM_STOPPED);
495}
496
497/*
498 * vpfe_release() - release video device
499 * @file: file pointer
500 *
501 * deletes buffer queue, frees the buffers and the vpfe file handle
502 *
503 * Return 0
504 */
505static int vpfe_release(struct file *file)
506{
507 struct vpfe_video_device *video = video_drvdata(file);
508 struct v4l2_fh *vfh = file->private_data;
509 struct vpfe_device *vpfe_dev = video->vpfe_dev;
510 struct vpfe_fh *fh = container_of(vfh, struct vpfe_fh, vfh);
511
512 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_release\n");
513
514 /* Get the device lock */
515 mutex_lock(&video->lock);
516 /* if this instance is doing IO */
517 if (fh->io_allowed) {
518 if (video->started) {
519 vpfe_stop_capture(video);
520 /* mark pipe state as stopped in vpfe_release(),
521 as app might call streamon() after streamoff()
522 in which case driver has to start streaming.
523 */
524 video->pipe.state = VPFE_PIPELINE_STREAM_STOPPED;
525 vb2_streamoff(&video->buffer_queue,
526 video->buffer_queue.type);
527 }
528 video->io_usrs = 0;
529 /* Free buffers allocated */
530 vb2_queue_release(&video->buffer_queue);
531 vb2_dma_contig_cleanup_ctx(video->alloc_ctx);
532 }
533 /* Decrement device users counter */
534 video->usrs--;
535 /* Close the priority */
536 v4l2_prio_close(&video->prio, fh->prio);
537 /* If this is the last file handle */
538 if (!video->usrs)
539 video->initialized = 0;
540 mutex_unlock(&video->lock);
541 file->private_data = NULL;
542 /* Free memory allocated to file handle object */
543 v4l2_fh_del(vfh);
544 kzfree(fh);
545 return 0;
546}
547
548/*
549 * vpfe_mmap() - It is used to map kernel space buffers
550 * into user spaces
551 */
552static int vpfe_mmap(struct file *file, struct vm_area_struct *vma)
553{
554 struct vpfe_video_device *video = video_drvdata(file);
555 struct vpfe_device *vpfe_dev = video->vpfe_dev;
556
557 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_mmap\n");
558 return vb2_mmap(&video->buffer_queue, vma);
559}
560
561/*
562 * vpfe_poll() - It is used for select/poll system call
563 */
564static unsigned int vpfe_poll(struct file *file, poll_table *wait)
565{
566 struct vpfe_video_device *video = video_drvdata(file);
567 struct vpfe_device *vpfe_dev = video->vpfe_dev;
568
569 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_poll\n");
570 if (video->started)
571 return vb2_poll(&video->buffer_queue, file, wait);
572 return 0;
573}
574
575/* vpfe capture driver file operations */
576static const struct v4l2_file_operations vpfe_fops = {
577 .owner = THIS_MODULE,
578 .open = vpfe_open,
579 .release = vpfe_release,
580 .unlocked_ioctl = video_ioctl2,
581 .mmap = vpfe_mmap,
582 .poll = vpfe_poll
583};
584
585/*
586 * vpfe_querycap() - query capabilities of video device
587 * @file: file pointer
588 * @priv: void pointer
589 * @cap: pointer to v4l2_capability structure
590 *
591 * fills v4l2 capabilities structure
592 *
593 * Return 0
594 */
595static int vpfe_querycap(struct file *file, void *priv,
596 struct v4l2_capability *cap)
597{
598 struct vpfe_video_device *video = video_drvdata(file);
599 struct vpfe_device *vpfe_dev = video->vpfe_dev;
600
601 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_querycap\n");
602
603 if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
604 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
605 else
606 cap->capabilities = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING;
607 cap->device_caps = cap->capabilities;
608 cap->version = VPFE_CAPTURE_VERSION_CODE;
609 strlcpy(cap->driver, CAPTURE_DRV_NAME, sizeof(cap->driver));
610 strlcpy(cap->bus_info, "VPFE", sizeof(cap->bus_info));
611 strlcpy(cap->card, vpfe_dev->cfg->card_name, sizeof(cap->card));
612
613 return 0;
614}
615
616/*
617 * vpfe_g_fmt() - get the format which is active on video device
618 * @file: file pointer
619 * @priv: void pointer
620 * @fmt: pointer to v4l2_format structure
621 *
622 * fills v4l2 format structure with active format
623 *
624 * Return 0
625 */
626static int vpfe_g_fmt(struct file *file, void *priv,
627 struct v4l2_format *fmt)
628{
629 struct vpfe_video_device *video = video_drvdata(file);
630 struct vpfe_device *vpfe_dev = video->vpfe_dev;
631
632 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_g_fmt\n");
633 /* Fill in the information about format */
634 *fmt = video->fmt;
635 return 0;
636}
637
638/*
639 * vpfe_enum_fmt() - enum formats supported on media chain
640 * @file: file pointer
641 * @priv: void pointer
642 * @fmt: pointer to v4l2_fmtdesc structure
643 *
644 * fills v4l2_fmtdesc structure with output format set on adjacent subdev,
645 * only one format is enumearted as subdevs are already configured
646 *
647 * Return 0 if successfull, error code otherwise
648 */
649static int vpfe_enum_fmt(struct file *file, void *priv,
650 struct v4l2_fmtdesc *fmt)
651{
652 struct vpfe_video_device *video = video_drvdata(file);
653 struct vpfe_device *vpfe_dev = video->vpfe_dev;
654 struct v4l2_subdev_format sd_fmt;
655 struct v4l2_mbus_framefmt mbus;
656 struct v4l2_subdev *subdev;
657 struct v4l2_format format;
658 struct media_pad *remote;
659 int ret;
660
661 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_enum_fmt\n");
662
663 /* since already subdev pad format is set,
664 only one pixel format is available */
665 if (fmt->index > 0) {
666 v4l2_err(&vpfe_dev->v4l2_dev, "Invalid index\n");
667 return -EINVAL;
668 }
669 /* get the remote pad */
670 remote = media_entity_remote_source(&video->pad);
671 if (remote == NULL) {
672 v4l2_err(&vpfe_dev->v4l2_dev,
673 "invalid remote pad for video node\n");
674 return -EINVAL;
675 }
676 /* get the remote subdev */
677 subdev = vpfe_video_remote_subdev(video, NULL);
678 if (subdev == NULL) {
679 v4l2_err(&vpfe_dev->v4l2_dev,
680 "invalid remote subdev for video node\n");
681 return -EINVAL;
682 }
683 sd_fmt.pad = remote->index;
684 sd_fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
685 /* get output format of remote subdev */
686 ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &sd_fmt);
687 if (ret) {
688 v4l2_err(&vpfe_dev->v4l2_dev,
689 "invalid remote subdev for video node\n");
690 return ret;
691 }
692 /* convert to pix format */
693 mbus.code = sd_fmt.format.code;
694 mbus_to_pix(&mbus, &format.fmt.pix);
695 /* copy the result */
696 fmt->pixelformat = format.fmt.pix.pixelformat;
697
698 return 0;
699}
700
701/*
702 * vpfe_s_fmt() - set the format on video device
703 * @file: file pointer
704 * @priv: void pointer
705 * @fmt: pointer to v4l2_format structure
706 *
707 * validate and set the format on video device
708 *
709 * Return 0 on success, error code otherwise
710 */
711static int vpfe_s_fmt(struct file *file, void *priv,
712 struct v4l2_format *fmt)
713{
714 struct vpfe_video_device *video = video_drvdata(file);
715 struct vpfe_device *vpfe_dev = video->vpfe_dev;
716 struct v4l2_format format;
717 int ret;
718
719 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_s_fmt\n");
720 /* If streaming is started, return error */
721 if (video->started) {
722 v4l2_err(&vpfe_dev->v4l2_dev, "Streaming is started\n");
723 return -EBUSY;
724 }
725 /* get adjacent subdev's output pad format */
726 ret = __vpfe_video_get_format(video, &format);
727 if (ret)
728 return ret;
729 *fmt = format;
730 video->fmt = *fmt;
731 return 0;
732}
733
734/*
735 * vpfe_try_fmt() - try the format on video device
736 * @file: file pointer
737 * @priv: void pointer
738 * @fmt: pointer to v4l2_format structure
739 *
740 * validate the format, update with correct format
741 * based on output format set on adjacent subdev
742 *
743 * Return 0 on success, error code otherwise
744 */
745static int vpfe_try_fmt(struct file *file, void *priv,
746 struct v4l2_format *fmt)
747{
748 struct vpfe_video_device *video = video_drvdata(file);
749 struct vpfe_device *vpfe_dev = video->vpfe_dev;
750 struct v4l2_format format;
751 int ret;
752
753 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_try_fmt\n");
754 /* get adjacent subdev's output pad format */
755 ret = __vpfe_video_get_format(video, &format);
756 if (ret)
757 return ret;
758
759 *fmt = format;
760 return 0;
761}
762
763/*
764 * vpfe_enum_input() - enum inputs supported on media chain
765 * @file: file pointer
766 * @priv: void pointer
767 * @fmt: pointer to v4l2_fmtdesc structure
768 *
769 * fills v4l2_input structure with input available on media chain,
770 * only one input is enumearted as media chain is setup by this time
771 *
772 * Return 0 if successfull, -EINVAL is media chain is invalid
773 */
774static int vpfe_enum_input(struct file *file, void *priv,
775 struct v4l2_input *inp)
776{
777 struct vpfe_video_device *video = video_drvdata(file);
778 struct vpfe_ext_subdev_info *sdinfo = video->current_ext_subdev;
779 struct vpfe_device *vpfe_dev = video->vpfe_dev;
780
781 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_enum_input\n");
782 /* enumerate from the subdev user has choosen through mc */
783 if (inp->index < sdinfo->num_inputs) {
784 memcpy(inp, &sdinfo->inputs[inp->index],
785 sizeof(struct v4l2_input));
786 return 0;
787 }
788 return -EINVAL;
789}
790
791/*
792 * vpfe_g_input() - get index of the input which is active
793 * @file: file pointer
794 * @priv: void pointer
795 * @index: pointer to unsigned int
796 *
797 * set index with input index which is active
798 */
799static int vpfe_g_input(struct file *file, void *priv, unsigned int *index)
800{
801 struct vpfe_video_device *video = video_drvdata(file);
802 struct vpfe_device *vpfe_dev = video->vpfe_dev;
803
804 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_g_input\n");
805
806 *index = video->current_input;
807 return 0;
808}
809
810/*
811 * vpfe_s_input() - set input which is pointed by input index
812 * @file: file pointer
813 * @priv: void pointer
814 * @index: pointer to unsigned int
815 *
816 * set input on external subdev
817 *
818 * Return 0 on success, error code otherwise
819 */
820static int vpfe_s_input(struct file *file, void *priv, unsigned int index)
821{
822 struct vpfe_video_device *video = video_drvdata(file);
823 struct vpfe_device *vpfe_dev = video->vpfe_dev;
824 struct vpfe_ext_subdev_info *sdinfo;
825 struct vpfe_route *route;
826 struct v4l2_input *inps;
827 u32 output;
828 u32 input;
829 int ret;
830 int i;
831
832 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_s_input\n");
833
834 ret = mutex_lock_interruptible(&video->lock);
835 if (ret)
836 return ret;
837 /*
838 * If streaming is started return device busy
839 * error
840 */
841 if (video->started) {
842 v4l2_err(&vpfe_dev->v4l2_dev, "Streaming is on\n");
843 ret = -EBUSY;
844 goto unlock_out;
845 }
846
847 sdinfo = video->current_ext_subdev;
848 if (!sdinfo->registered) {
849 ret = -EINVAL;
850 goto unlock_out;
851 }
852 if (vpfe_dev->cfg->setup_input &&
853 vpfe_dev->cfg->setup_input(sdinfo->grp_id) < 0) {
854 ret = -EFAULT;
855 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev,
856 "couldn't setup input for %s\n",
857 sdinfo->module_name);
858 goto unlock_out;
859 }
860 route = &sdinfo->routes[index];
861 if (route && sdinfo->can_route) {
862 input = route->input;
863 output = route->output;
864 ret = v4l2_device_call_until_err(&vpfe_dev->v4l2_dev,
865 sdinfo->grp_id, video,
866 s_routing, input, output, 0);
867 if (ret) {
868 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev,
869 "s_input:error in setting input in decoder\n");
870 ret = -EINVAL;
871 goto unlock_out;
872 }
873 }
874 /* set standards set by subdev in video device */
875 for (i = 0; i < sdinfo->num_inputs; i++) {
876 inps = &sdinfo->inputs[i];
877 video->video_dev.tvnorms |= inps->std;
878 }
879 video->current_input = index;
880unlock_out:
881 mutex_unlock(&video->lock);
882 return ret;
883}
884
885/*
886 * vpfe_querystd() - query std which is being input on external subdev
887 * @file: file pointer
888 * @priv: void pointer
889 * @std_id: pointer to v4l2_std_id structure
890 *
891 * call external subdev through v4l2_device_call_until_err to
892 * get the std that is being active.
893 *
894 * Return 0 on success, error code otherwise
895 */
896static int vpfe_querystd(struct file *file, void *priv, v4l2_std_id *std_id)
897{
898 struct vpfe_video_device *video = video_drvdata(file);
899 struct vpfe_device *vpfe_dev = video->vpfe_dev;
900 struct vpfe_ext_subdev_info *sdinfo;
901 int ret;
902
903 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_querystd\n");
904
905 ret = mutex_lock_interruptible(&video->lock);
906 sdinfo = video->current_ext_subdev;
907 if (ret)
908 return ret;
909 /* Call querystd function of decoder device */
910 ret = v4l2_device_call_until_err(&vpfe_dev->v4l2_dev, sdinfo->grp_id,
911 video, querystd, std_id);
912 mutex_unlock(&video->lock);
913 return ret;
914}
915
916/*
917 * vpfe_s_std() - set std on external subdev
918 * @file: file pointer
919 * @priv: void pointer
920 * @std_id: pointer to v4l2_std_id structure
921 *
922 * set std pointed by std_id on external subdev by calling it using
923 * v4l2_device_call_until_err
924 *
925 * Return 0 on success, error code otherwise
926 */
927static int vpfe_s_std(struct file *file, void *priv, v4l2_std_id *std_id)
928{
929 struct vpfe_video_device *video = video_drvdata(file);
930 struct vpfe_device *vpfe_dev = video->vpfe_dev;
931 struct vpfe_ext_subdev_info *sdinfo;
932 int ret;
933
934 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_s_std\n");
935
936 /* Call decoder driver function to set the standard */
937 ret = mutex_lock_interruptible(&video->lock);
938 if (ret)
939 return ret;
940 sdinfo = video->current_ext_subdev;
941 /* If streaming is started, return device busy error */
942 if (video->started) {
943 v4l2_err(&vpfe_dev->v4l2_dev, "streaming is started\n");
944 ret = -EBUSY;
945 goto unlock_out;
946 }
947 ret = v4l2_device_call_until_err(&vpfe_dev->v4l2_dev, sdinfo->grp_id,
948 core, s_std, *std_id);
949 if (ret < 0) {
950 v4l2_err(&vpfe_dev->v4l2_dev, "Failed to set standard\n");
951 video->stdid = V4L2_STD_UNKNOWN;
952 goto unlock_out;
953 }
954 video->stdid = *std_id;
955unlock_out:
956 mutex_unlock(&video->lock);
957 return ret;
958}
959
960static int vpfe_g_std(struct file *file, void *priv, v4l2_std_id *tvnorm)
961{
962 struct vpfe_video_device *video = video_drvdata(file);
963 struct vpfe_device *vpfe_dev = video->vpfe_dev;
964
965 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_g_std\n");
966 *tvnorm = video->stdid;
967 return 0;
968}
969
970/*
971 * vpfe_enum_dv_timings() - enumerate dv_timings which are supported by
972 * to external subdev
973 * @file: file pointer
974 * @priv: void pointer
975 * @timings: pointer to v4l2_enum_dv_timings structure
976 *
977 * enum dv_timings's which are supported by external subdev through
978 * v4l2_subdev_call
979 *
980 * Return 0 on success, error code otherwise
981 */
982static int
983vpfe_enum_dv_timings(struct file *file, void *fh,
984 struct v4l2_enum_dv_timings *timings)
985{
986 struct vpfe_video_device *video = video_drvdata(file);
987 struct vpfe_device *vpfe_dev = video->vpfe_dev;
988 struct v4l2_subdev *subdev = video->current_ext_subdev->subdev;
989
990 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_enum_dv_timings\n");
991 return v4l2_subdev_call(subdev, video, enum_dv_timings, timings);
992}
993
994/*
995 * vpfe_query_dv_timings() - query the dv_timings which is being input
996 * to external subdev
997 * @file: file pointer
998 * @priv: void pointer
999 * @timings: pointer to v4l2_dv_timings structure
1000 *
1001 * get dv_timings which is being input on external subdev through
1002 * v4l2_subdev_call
1003 *
1004 * Return 0 on success, error code otherwise
1005 */
1006static int
1007vpfe_query_dv_timings(struct file *file, void *fh,
1008 struct v4l2_dv_timings *timings)
1009{
1010 struct vpfe_video_device *video = video_drvdata(file);
1011 struct vpfe_device *vpfe_dev = video->vpfe_dev;
1012 struct v4l2_subdev *subdev = video->current_ext_subdev->subdev;
1013
1014 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_query_dv_timings\n");
1015 return v4l2_subdev_call(subdev, video, query_dv_timings, timings);
1016}
1017
1018/*
1019 * vpfe_s_dv_timings() - set dv_preset on external subdev
1020 * @file: file pointer
1021 * @priv: void pointer
1022 * @timings: pointer to v4l2_dv_timings structure
1023 *
1024 * set dv_timings pointed by preset on external subdev through
1025 * v4l2_device_call_until_err, this configures amplifier also
1026 *
1027 * Return 0 on success, error code otherwise
1028 */
1029static int
1030vpfe_s_dv_timings(struct file *file, void *fh,
1031 struct v4l2_dv_timings *timings)
1032{
1033 struct vpfe_video_device *video = video_drvdata(file);
1034 struct vpfe_device *vpfe_dev = video->vpfe_dev;
1035
1036 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_s_dv_timings\n");
1037
1038 video->stdid = V4L2_STD_UNKNOWN;
1039 return v4l2_device_call_until_err(&vpfe_dev->v4l2_dev,
1040 video->current_ext_subdev->grp_id,
1041 video, s_dv_timings, timings);
1042}
1043
1044/*
1045 * vpfe_g_dv_timings() - get dv_preset which is set on external subdev
1046 * @file: file pointer
1047 * @priv: void pointer
1048 * @timings: pointer to v4l2_dv_timings structure
1049 *
1050 * get dv_preset which is set on external subdev through
1051 * v4l2_subdev_call
1052 *
1053 * Return 0 on success, error code otherwise
1054 */
1055static int
1056vpfe_g_dv_timings(struct file *file, void *fh,
1057 struct v4l2_dv_timings *timings)
1058{
1059 struct vpfe_video_device *video = video_drvdata(file);
1060 struct vpfe_device *vpfe_dev = video->vpfe_dev;
1061 struct v4l2_subdev *subdev = video->current_ext_subdev->subdev;
1062
1063 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_g_dv_timings\n");
1064 return v4l2_subdev_call(subdev, video, g_dv_timings, timings);
1065}
1066
1067/*
1068 * Videobuf operations
1069 */
1070/*
1071 * vpfe_buffer_queue_setup : Callback function for buffer setup.
1072 * @vq: vb2_queue ptr
1073 * @fmt: v4l2 format
1074 * @nbuffers: ptr to number of buffers requested by application
1075 * @nplanes:: contains number of distinct video planes needed to hold a frame
1076 * @sizes[]: contains the size (in bytes) of each plane.
1077 * @alloc_ctxs: ptr to allocation context
1078 *
1079 * This callback function is called when reqbuf() is called to adjust
1080 * the buffer nbuffers and buffer size
1081 */
1082static int
1083vpfe_buffer_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
1084 unsigned int *nbuffers, unsigned int *nplanes,
1085 unsigned int sizes[], void *alloc_ctxs[])
1086{
1087 struct vpfe_fh *fh = vb2_get_drv_priv(vq);
1088 struct vpfe_video_device *video = fh->video;
1089 struct vpfe_device *vpfe_dev = video->vpfe_dev;
1090 struct vpfe_pipeline *pipe = &video->pipe;
1091 unsigned long size;
1092
1093 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_buffer_queue_setup\n");
1094 size = video->fmt.fmt.pix.sizeimage;
1095
1096 if (vpfe_dev->video_limit) {
1097 while (size * *nbuffers > vpfe_dev->video_limit)
1098 (*nbuffers)--;
1099 }
1100 if (pipe->state == VPFE_PIPELINE_STREAM_CONTINUOUS) {
1101 if (*nbuffers < MIN_NUM_BUFFERS)
1102 *nbuffers = MIN_NUM_BUFFERS;
1103 }
1104 *nplanes = 1;
1105 sizes[0] = size;
1106 alloc_ctxs[0] = video->alloc_ctx;
1107 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev,
1108 "nbuffers=%d, size=%lu\n", *nbuffers, size);
1109 return 0;
1110}
1111
1112/*
1113 * vpfe_buffer_prepare : callback function for buffer prepare
1114 * @vb: ptr to vb2_buffer
1115 *
1116 * This is the callback function for buffer prepare when vb2_qbuf()
1117 * function is called. The buffer is prepared and user space virtual address
1118 * or user address is converted into physical address
1119 */
1120static int vpfe_buffer_prepare(struct vb2_buffer *vb)
1121{
1122 struct vpfe_fh *fh = vb2_get_drv_priv(vb->vb2_queue);
1123 struct vpfe_video_device *video = fh->video;
1124 struct vpfe_device *vpfe_dev = video->vpfe_dev;
1125 unsigned long addr;
1126
1127 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_buffer_prepare\n");
1128
1129 if (vb->state != VB2_BUF_STATE_ACTIVE &&
1130 vb->state != VB2_BUF_STATE_PREPARED)
1131 return 0;
1132
1133 /* Initialize buffer */
1134 vb2_set_plane_payload(vb, 0, video->fmt.fmt.pix.sizeimage);
1135 if (vb2_plane_vaddr(vb, 0) &&
1136 vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0))
1137 return -EINVAL;
1138
1139 addr = vb2_dma_contig_plane_dma_addr(vb, 0);
1140 /* Make sure user addresses are aligned to 32 bytes */
1141 if (!ALIGN(addr, 32))
1142 return -EINVAL;
1143
1144 return 0;
1145}
1146
1147static void vpfe_buffer_queue(struct vb2_buffer *vb)
1148{
1149 /* Get the file handle object and device object */
1150 struct vpfe_fh *fh = vb2_get_drv_priv(vb->vb2_queue);
1151 struct vpfe_video_device *video = fh->video;
1152 struct vpfe_device *vpfe_dev = video->vpfe_dev;
1153 struct vpfe_pipeline *pipe = &video->pipe;
1154 struct vpfe_cap_buffer *buf = container_of(vb,
1155 struct vpfe_cap_buffer, vb);
1156 unsigned long flags;
1157 unsigned long empty;
1158 unsigned long addr;
1159
1160 spin_lock_irqsave(&video->dma_queue_lock, flags);
1161 empty = list_empty(&video->dma_queue);
1162 /* add the buffer to the DMA queue */
1163 list_add_tail(&buf->list, &video->dma_queue);
1164 spin_unlock_irqrestore(&video->dma_queue_lock, flags);
1165 /* this case happens in case of single shot */
1166 if (empty && video->started && pipe->state ==
1167 VPFE_PIPELINE_STREAM_SINGLESHOT &&
1168 video->state == VPFE_VIDEO_BUFFER_NOT_QUEUED) {
1169 spin_lock(&video->dma_queue_lock);
1170 addr = vpfe_video_get_next_buffer(video);
1171 video->ops->queue(vpfe_dev, addr);
1172
1173 video->state = VPFE_VIDEO_BUFFER_QUEUED;
1174 spin_unlock(&video->dma_queue_lock);
1175
1176 /* enable h/w each time in single shot */
1177 if (vpfe_video_is_pipe_ready(pipe))
1178 vpfe_pipeline_set_stream(pipe,
1179 VPFE_PIPELINE_STREAM_SINGLESHOT);
1180 }
1181}
1182
1183/* vpfe_start_capture() - start streaming on all the subdevs */
1184static int vpfe_start_capture(struct vpfe_video_device *video)
1185{
1186 struct vpfe_pipeline *pipe = &video->pipe;
1187 int ret = 0;
1188
1189 video->started = 1;
1190 if (vpfe_video_is_pipe_ready(pipe))
1191 ret = vpfe_pipeline_set_stream(pipe, pipe->state);
1192
1193 return ret;
1194}
1195
1196static int vpfe_start_streaming(struct vb2_queue *vq, unsigned int count)
1197{
1198 struct vpfe_fh *fh = vb2_get_drv_priv(vq);
1199 struct vpfe_video_device *video = fh->video;
1200 struct vpfe_device *vpfe_dev = video->vpfe_dev;
1201 unsigned long addr;
1202 int ret;
1203
1204 ret = mutex_lock_interruptible(&video->lock);
1205 if (ret)
1206 goto streamoff;
1207
1208 /* Get the next frame from the buffer queue */
1209 video->cur_frm = video->next_frm =
1210 list_entry(video->dma_queue.next, struct vpfe_cap_buffer, list);
1211 /* Remove buffer from the buffer queue */
1212 list_del(&video->cur_frm->list);
1213 /* Mark state of the current frame to active */
1214 video->cur_frm->vb.state = VB2_BUF_STATE_ACTIVE;
1215 /* Initialize field_id and started member */
1216 video->field_id = 0;
1217 addr = vb2_dma_contig_plane_dma_addr(&video->cur_frm->vb, 0);
1218 video->ops->queue(vpfe_dev, addr);
1219 video->state = VPFE_VIDEO_BUFFER_QUEUED;
1220
1221 ret = vpfe_start_capture(video);
1222 if (ret)
1223 goto unlock_out;
1224
1225 mutex_unlock(&video->lock);
1226
1227 return ret;
1228unlock_out:
1229 mutex_unlock(&video->lock);
1230streamoff:
1231 ret = vb2_streamoff(&video->buffer_queue, video->buffer_queue.type);
1232 return 0;
1233}
1234
1235static int vpfe_buffer_init(struct vb2_buffer *vb)
1236{
1237 struct vpfe_cap_buffer *buf = container_of(vb,
1238 struct vpfe_cap_buffer, vb);
1239
1240 INIT_LIST_HEAD(&buf->list);
1241 return 0;
1242}
1243
1244/* abort streaming and wait for last buffer */
1245static int vpfe_stop_streaming(struct vb2_queue *vq)
1246{
1247 struct vpfe_fh *fh = vb2_get_drv_priv(vq);
1248 struct vpfe_video_device *video = fh->video;
1249
1250 if (!vb2_is_streaming(vq))
1251 return 0;
1252 /* release all active buffers */
1253 while (!list_empty(&video->dma_queue)) {
1254 video->next_frm = list_entry(video->dma_queue.next,
1255 struct vpfe_cap_buffer, list);
1256 list_del(&video->next_frm->list);
1257 vb2_buffer_done(&video->next_frm->vb, VB2_BUF_STATE_ERROR);
1258 }
1259 return 0;
1260}
1261
1262static void vpfe_buf_cleanup(struct vb2_buffer *vb)
1263{
1264 struct vpfe_fh *fh = vb2_get_drv_priv(vb->vb2_queue);
1265 struct vpfe_video_device *video = fh->video;
1266 struct vpfe_device *vpfe_dev = video->vpfe_dev;
1267 struct vpfe_cap_buffer *buf = container_of(vb,
1268 struct vpfe_cap_buffer, vb);
1269
1270 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_buf_cleanup\n");
1271 if (vb->state == VB2_BUF_STATE_ACTIVE)
1272 list_del_init(&buf->list);
1273}
1274
1275static struct vb2_ops video_qops = {
1276 .queue_setup = vpfe_buffer_queue_setup,
1277 .buf_init = vpfe_buffer_init,
1278 .buf_prepare = vpfe_buffer_prepare,
1279 .start_streaming = vpfe_start_streaming,
1280 .stop_streaming = vpfe_stop_streaming,
1281 .buf_cleanup = vpfe_buf_cleanup,
1282 .buf_queue = vpfe_buffer_queue,
1283};
1284
1285/*
1286 * vpfe_reqbufs() - supported REQBUF only once opening
1287 * the device.
1288 */
1289static int vpfe_reqbufs(struct file *file, void *priv,
1290 struct v4l2_requestbuffers *req_buf)
1291{
1292 struct vpfe_video_device *video = video_drvdata(file);
1293 struct vpfe_device *vpfe_dev = video->vpfe_dev;
1294 struct vpfe_fh *fh = file->private_data;
1295 struct vb2_queue *q;
1296 int ret;
1297
1298 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_reqbufs\n");
1299
1300 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != req_buf->type &&
1301 V4L2_BUF_TYPE_VIDEO_OUTPUT != req_buf->type) {
1302 v4l2_err(&vpfe_dev->v4l2_dev, "Invalid buffer type\n");
1303 return -EINVAL;
1304 }
1305
1306 ret = mutex_lock_interruptible(&video->lock);
1307 if (ret)
1308 return ret;
1309
1310 if (video->io_usrs != 0) {
1311 v4l2_err(&vpfe_dev->v4l2_dev, "Only one IO user allowed\n");
1312 ret = -EBUSY;
1313 goto unlock_out;
1314 }
1315 video->memory = req_buf->memory;
1316
1317 /* Initialize videobuf2 queue as per the buffer type */
1318 video->alloc_ctx = vb2_dma_contig_init_ctx(vpfe_dev->pdev);
1319 if (IS_ERR(video->alloc_ctx)) {
1320 v4l2_err(&vpfe_dev->v4l2_dev, "Failed to get the context\n");
1321 return PTR_ERR(video->alloc_ctx);
1322 }
1323
1324 q = &video->buffer_queue;
1325 q->type = req_buf->type;
1326 q->io_modes = VB2_MMAP | VB2_USERPTR;
1327 q->drv_priv = fh;
1328 q->ops = &video_qops;
1329 q->mem_ops = &vb2_dma_contig_memops;
1330 q->buf_struct_size = sizeof(struct vpfe_cap_buffer);
1331
1332 ret = vb2_queue_init(q);
1333 if (ret) {
1334 v4l2_err(&vpfe_dev->v4l2_dev, "vb2_queue_init() failed\n");
1335 vb2_dma_contig_cleanup_ctx(vpfe_dev->pdev);
1336 return ret;
1337 }
1338
1339 fh->io_allowed = 1;
1340 video->io_usrs = 1;
1341 INIT_LIST_HEAD(&video->dma_queue);
1342 ret = vb2_reqbufs(&video->buffer_queue, req_buf);
1343
1344unlock_out:
1345 mutex_unlock(&video->lock);
1346 return ret;
1347}
1348
1349/*
1350 * vpfe_querybuf() - query buffers for exchange
1351 */
1352static int vpfe_querybuf(struct file *file, void *priv,
1353 struct v4l2_buffer *buf)
1354{
1355 struct vpfe_video_device *video = video_drvdata(file);
1356 struct vpfe_device *vpfe_dev = video->vpfe_dev;
1357
1358 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_querybuf\n");
1359
1360 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != buf->type &&
1361 V4L2_BUF_TYPE_VIDEO_OUTPUT != buf->type) {
1362 v4l2_err(&vpfe_dev->v4l2_dev, "Invalid buf type\n");
1363 return -EINVAL;
1364 }
1365
1366 if (video->memory != V4L2_MEMORY_MMAP) {
1367 v4l2_err(&vpfe_dev->v4l2_dev, "Invalid memory\n");
1368 return -EINVAL;
1369 }
1370
1371 /* Call vb2_querybuf to get information */
1372 return vb2_querybuf(&video->buffer_queue, buf);
1373}
1374
1375/*
1376 * vpfe_qbuf() - queue buffers for capture or processing
1377 */
1378static int vpfe_qbuf(struct file *file, void *priv,
1379 struct v4l2_buffer *p)
1380{
1381 struct vpfe_video_device *video = video_drvdata(file);
1382 struct vpfe_device *vpfe_dev = video->vpfe_dev;
1383 struct vpfe_fh *fh = file->private_data;
1384
1385 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_qbuf\n");
1386
1387 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != p->type &&
1388 V4L2_BUF_TYPE_VIDEO_OUTPUT != p->type) {
1389 v4l2_err(&vpfe_dev->v4l2_dev, "Invalid buf type\n");
1390 return -EINVAL;
1391 }
1392 /*
1393 * If this file handle is not allowed to do IO,
1394 * return error
1395 */
1396 if (!fh->io_allowed) {
1397 v4l2_err(&vpfe_dev->v4l2_dev, "fh->io_allowed\n");
1398 return -EACCES;
1399 }
1400
1401 return vb2_qbuf(&video->buffer_queue, p);
1402}
1403
1404/*
1405 * vpfe_dqbuf() - deque buffer which is done with processing
1406 */
1407static int vpfe_dqbuf(struct file *file, void *priv,
1408 struct v4l2_buffer *buf)
1409{
1410 struct vpfe_video_device *video = video_drvdata(file);
1411 struct vpfe_device *vpfe_dev = video->vpfe_dev;
1412
1413 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_dqbuf\n");
1414
1415 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != buf->type &&
1416 V4L2_BUF_TYPE_VIDEO_OUTPUT != buf->type) {
1417 v4l2_err(&vpfe_dev->v4l2_dev, "Invalid buf type\n");
1418 return -EINVAL;
1419 }
1420
1421 return vb2_dqbuf(&video->buffer_queue,
1422 buf, (file->f_flags & O_NONBLOCK));
1423}
1424
1425/*
1426 * vpfe_streamon() - get dv_preset which is set on external subdev
1427 * @file: file pointer
1428 * @priv: void pointer
1429 * @buf_type: enum v4l2_buf_type
1430 *
1431 * queue buffer onto hardware for capture/processing and
1432 * start all the subdevs which are in media chain
1433 *
1434 * Return 0 on success, error code otherwise
1435 */
1436static int vpfe_streamon(struct file *file, void *priv,
1437 enum v4l2_buf_type buf_type)
1438{
1439 struct vpfe_video_device *video = video_drvdata(file);
1440 struct vpfe_device *vpfe_dev = video->vpfe_dev;
1441 struct vpfe_pipeline *pipe = &video->pipe;
1442 struct vpfe_fh *fh = file->private_data;
1443 struct vpfe_ext_subdev_info *sdinfo;
1444 int ret = -EINVAL;
1445
1446 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_streamon\n");
1447
1448 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != buf_type &&
1449 V4L2_BUF_TYPE_VIDEO_OUTPUT != buf_type) {
1450 v4l2_err(&vpfe_dev->v4l2_dev, "Invalid buf type\n");
1451 return ret;
1452 }
1453 /* If file handle is not allowed IO, return error */
1454 if (!fh->io_allowed) {
1455 v4l2_err(&vpfe_dev->v4l2_dev, "fh->io_allowed\n");
1456 return -EACCES;
1457 }
1458 sdinfo = video->current_ext_subdev;
1459 /* If buffer queue is empty, return error */
1460 if (list_empty(&video->buffer_queue.queued_list)) {
1461 v4l2_err(&vpfe_dev->v4l2_dev, "buffer queue is empty\n");
1462 return -EIO;
1463 }
1464 /* Validate the pipeline */
1465 if (V4L2_BUF_TYPE_VIDEO_CAPTURE == buf_type) {
1466 ret = vpfe_video_validate_pipeline(pipe);
1467 if (ret < 0)
1468 return ret;
1469 }
1470 /* Call vb2_streamon to start streaming */
1471 return vb2_streamon(&video->buffer_queue, buf_type);
1472}
1473
1474/*
1475 * vpfe_streamoff() - get dv_preset which is set on external subdev
1476 * @file: file pointer
1477 * @priv: void pointer
1478 * @buf_type: enum v4l2_buf_type
1479 *
1480 * stop all the subdevs which are in media chain
1481 *
1482 * Return 0 on success, error code otherwise
1483 */
1484static int vpfe_streamoff(struct file *file, void *priv,
1485 enum v4l2_buf_type buf_type)
1486{
1487 struct vpfe_video_device *video = video_drvdata(file);
1488 struct vpfe_device *vpfe_dev = video->vpfe_dev;
1489 struct vpfe_fh *fh = file->private_data;
1490 int ret = 0;
1491
1492 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_streamoff\n");
1493
1494 if (buf_type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
1495 buf_type != V4L2_BUF_TYPE_VIDEO_OUTPUT) {
1496 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "Invalid buf type\n");
1497 return -EINVAL;
1498 }
1499
1500 /* If io is allowed for this file handle, return error */
1501 if (!fh->io_allowed) {
1502 v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "fh->io_allowed\n");
1503 return -EACCES;
1504 }
1505
1506 /* If streaming is not started, return error */
1507 if (!video->started) {
1508 v4l2_err(&vpfe_dev->v4l2_dev, "device is not started\n");
1509 return -EINVAL;
1510 }
1511
1512 ret = mutex_lock_interruptible(&video->lock);
1513 if (ret)
1514 return ret;
1515
1516 vpfe_stop_capture(video);
1517 ret = vb2_streamoff(&video->buffer_queue, buf_type);
1518 mutex_unlock(&video->lock);
1519
1520 return ret;
1521}
1522
1523/* vpfe capture ioctl operations */
1524static const struct v4l2_ioctl_ops vpfe_ioctl_ops = {
1525 .vidioc_querycap = vpfe_querycap,
1526 .vidioc_g_fmt_vid_cap = vpfe_g_fmt,
1527 .vidioc_s_fmt_vid_cap = vpfe_s_fmt,
1528 .vidioc_try_fmt_vid_cap = vpfe_try_fmt,
1529 .vidioc_enum_fmt_vid_cap = vpfe_enum_fmt,
1530 .vidioc_g_fmt_vid_out = vpfe_g_fmt,
1531 .vidioc_s_fmt_vid_out = vpfe_s_fmt,
1532 .vidioc_try_fmt_vid_out = vpfe_try_fmt,
1533 .vidioc_enum_fmt_vid_out = vpfe_enum_fmt,
1534 .vidioc_enum_input = vpfe_enum_input,
1535 .vidioc_g_input = vpfe_g_input,
1536 .vidioc_s_input = vpfe_s_input,
1537 .vidioc_querystd = vpfe_querystd,
1538 .vidioc_s_std = vpfe_s_std,
1539 .vidioc_g_std = vpfe_g_std,
1540 .vidioc_enum_dv_timings = vpfe_enum_dv_timings,
1541 .vidioc_query_dv_timings = vpfe_query_dv_timings,
1542 .vidioc_s_dv_timings = vpfe_s_dv_timings,
1543 .vidioc_g_dv_timings = vpfe_g_dv_timings,
1544 .vidioc_reqbufs = vpfe_reqbufs,
1545 .vidioc_querybuf = vpfe_querybuf,
1546 .vidioc_qbuf = vpfe_qbuf,
1547 .vidioc_dqbuf = vpfe_dqbuf,
1548 .vidioc_streamon = vpfe_streamon,
1549 .vidioc_streamoff = vpfe_streamoff,
1550};
1551
1552/* VPFE video init function */
1553int vpfe_video_init(struct vpfe_video_device *video, const char *name)
1554{
1555 const char *direction;
1556 int ret;
1557
1558 switch (video->type) {
1559 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1560 direction = "output";
1561 video->pad.flags = MEDIA_PAD_FL_SINK;
1562 video->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1563 break;
1564
1565 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
1566 direction = "input";
1567 video->pad.flags = MEDIA_PAD_FL_SOURCE;
1568 video->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
1569 break;
1570
1571 default:
1572 return -EINVAL;
1573 }
1574 /* Initialize field of video device */
1575 video->video_dev.release = video_device_release;
1576 video->video_dev.fops = &vpfe_fops;
1577 video->video_dev.ioctl_ops = &vpfe_ioctl_ops;
1578 video->video_dev.minor = -1;
1579 video->video_dev.tvnorms = 0;
1580 snprintf(video->video_dev.name, sizeof(video->video_dev.name),
1581 "DAVINCI VIDEO %s %s", name, direction);
1582
1583 /* Initialize prio member of device object */
1584 v4l2_prio_init(&video->prio);
1585 spin_lock_init(&video->irqlock);
1586 spin_lock_init(&video->dma_queue_lock);
1587 mutex_init(&video->lock);
1588 ret = media_entity_init(&video->video_dev.entity,
1589 1, &video->pad, 0);
1590 if (ret < 0)
1591 return ret;
1592
1593 video_set_drvdata(&video->video_dev, video);
1594
1595 return 0;
1596}
1597
1598/* vpfe video device register function */
1599int vpfe_video_register(struct vpfe_video_device *video,
1600 struct v4l2_device *vdev)
1601{
1602 int ret;
1603
1604 video->video_dev.v4l2_dev = vdev;
1605
1606 ret = video_register_device(&video->video_dev, VFL_TYPE_GRABBER, -1);
1607 if (ret < 0)
1608 pr_err("%s: could not register video device (%d)\n",
1609 __func__, ret);
1610 return ret;
1611}
1612
1613/* vpfe video device unregister function */
1614void vpfe_video_unregister(struct vpfe_video_device *video)
1615{
1616 if (video_is_registered(&video->video_dev)) {
1617 media_entity_cleanup(&video->video_dev.entity);
1618 video_unregister_device(&video->video_dev);
1619 }
1620}
diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.h b/drivers/staging/media/davinci_vpfe/vpfe_video.h
new file mode 100644
index 000000000000..bf8af01d4a1b
--- /dev/null
+++ b/drivers/staging/media/davinci_vpfe/vpfe_video.h
@@ -0,0 +1,155 @@
1/*
2 * Copyright (C) 2012 Texas Instruments Inc
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation version 2.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Contributors:
18 * Manjunath Hadli <manjunath.hadli@ti.com>
19 * Prabhakar Lad <prabhakar.lad@ti.com>
20 */
21
22#ifndef _DAVINCI_VPFE_VIDEO_H
23#define _DAVINCI_VPFE_VIDEO_H
24
25#include <media/videobuf2-dma-contig.h>
26
27struct vpfe_device;
28
29/*
30 * struct vpfe_video_operations - VPFE video operations
31 * @queue: Resume streaming when a buffer is queued. Called on VIDIOC_QBUF
32 * if there was no buffer previously queued.
33 */
34struct vpfe_video_operations {
35 int(*queue) (struct vpfe_device *vpfe_dev, unsigned long addr);
36};
37
38enum vpfe_pipeline_stream_state {
39 VPFE_PIPELINE_STREAM_STOPPED = 0,
40 VPFE_PIPELINE_STREAM_CONTINUOUS = 1,
41 VPFE_PIPELINE_STREAM_SINGLESHOT = 2,
42};
43
44enum vpfe_video_state {
45 /* indicates that buffer is not queued */
46 VPFE_VIDEO_BUFFER_NOT_QUEUED = 0,
47 /* indicates that buffer is queued */
48 VPFE_VIDEO_BUFFER_QUEUED = 1,
49};
50
51struct vpfe_pipeline {
52 /* media pipeline */
53 struct media_pipeline *pipe;
54 /* state of the pipeline, continuous,
55 * single-shot or stopped
56 */
57 enum vpfe_pipeline_stream_state state;
58 /* number of active input video entities */
59 unsigned int input_num;
60 /* number of active output video entities */
61 unsigned int output_num;
62 /* input video nodes in case of single-shot mode */
63 struct vpfe_video_device *inputs[10];
64 /* capturing video nodes */
65 struct vpfe_video_device *outputs[10];
66};
67
68#define to_vpfe_pipeline(__e) \
69 container_of((__e)->pipe, struct vpfe_pipeline, pipe)
70
71#define to_vpfe_video(vdev) \
72 container_of(vdev, struct vpfe_video_device, video_dev)
73
74struct vpfe_cap_buffer {
75 struct vb2_buffer vb;
76 struct list_head list;
77};
78
79struct vpfe_video_device {
80 /* vpfe device */
81 struct vpfe_device *vpfe_dev;
82 /* video dev */
83 struct video_device video_dev;
84 /* media pad of video entity */
85 struct media_pad pad;
86 /* video operations supported by video device */
87 const struct vpfe_video_operations *ops;
88 /* type of the video buffers used by user */
89 enum v4l2_buf_type type;
90 /* Indicates id of the field which is being captured */
91 u32 field_id;
92 /* pipeline for which video device is part of */
93 struct vpfe_pipeline pipe;
94 /* Indicates whether streaming started */
95 u8 started;
96 /* Indicates state of the stream */
97 unsigned int state;
98 /* current input at the sub device */
99 int current_input;
100 /*
101 * This field keeps track of type of buffer exchange mechanism
102 * user has selected
103 */
104 enum v4l2_memory memory;
105 /* Used to keep track of state of the priority */
106 struct v4l2_prio_state prio;
107 /* number of open instances of the channel */
108 u32 usrs;
109 /* flag to indicate whether decoder is initialized */
110 u8 initialized;
111 /* skip frame count */
112 u8 skip_frame_count;
113 /* skip frame count init value */
114 u8 skip_frame_count_init;
115 /* time per frame for skipping */
116 struct v4l2_fract timeperframe;
117 /* ptr to currently selected sub device */
118 struct vpfe_ext_subdev_info *current_ext_subdev;
119 /* Pointer pointing to current vpfe_cap_buffer */
120 struct vpfe_cap_buffer *cur_frm;
121 /* Pointer pointing to next vpfe_cap_buffer */
122 struct vpfe_cap_buffer *next_frm;
123 /* Used to store pixel format */
124 struct v4l2_format fmt;
125 struct vb2_queue buffer_queue;
126 /* allocator-specific contexts for each plane */
127 struct vb2_alloc_ctx *alloc_ctx;
128 /* Queue of filled frames */
129 struct list_head dma_queue;
130 spinlock_t irqlock;
131 /* IRQ lock for DMA queue */
132 spinlock_t dma_queue_lock;
133 /* lock used to access this structure */
134 struct mutex lock;
135 /* number of users performing IO */
136 u32 io_usrs;
137 /* Currently selected or default standard */
138 v4l2_std_id stdid;
139 /*
140 * offset where second field starts from the starting of the
141 * buffer for field seperated YCbCr formats
142 */
143 u32 field_off;
144};
145
146int vpfe_video_is_pipe_ready(struct vpfe_pipeline *pipe);
147void vpfe_video_unregister(struct vpfe_video_device *video);
148int vpfe_video_register(struct vpfe_video_device *video,
149 struct v4l2_device *vdev);
150int vpfe_video_init(struct vpfe_video_device *video, const char *name);
151void vpfe_video_process_buffer_complete(struct vpfe_video_device *video);
152void vpfe_video_schedule_bottom_field(struct vpfe_video_device *video);
153void vpfe_video_schedule_next_buffer(struct vpfe_video_device *video);
154
155#endif /* _DAVINCI_VPFE_VIDEO_H */
diff --git a/drivers/staging/media/dt3155v4l/dt3155v4l.c b/drivers/staging/media/dt3155v4l/dt3155v4l.c
index 479c643da2f6..e33b7f55d84e 100644
--- a/drivers/staging/media/dt3155v4l/dt3155v4l.c
+++ b/drivers/staging/media/dt3155v4l/dt3155v4l.c
@@ -785,7 +785,7 @@ dt3155_init_board(struct pci_dev *pdev)
785 } 785 }
786 write_i2c_reg(pd->regs, CONFIG, pd->config); /* ACQ_MODE_EVEN */ 786 write_i2c_reg(pd->regs, CONFIG, pd->config); /* ACQ_MODE_EVEN */
787 787
788 /* select chanel 1 for input and set sync level */ 788 /* select channel 1 for input and set sync level */
789 write_i2c_reg(pd->regs, AD_ADDR, AD_CMD_REG); 789 write_i2c_reg(pd->regs, AD_ADDR, AD_CMD_REG);
790 write_i2c_reg(pd->regs, AD_CMD, VIDEO_CNL_1 | SYNC_CNL_1 | SYNC_LVL_3); 790 write_i2c_reg(pd->regs, AD_CMD, VIDEO_CNL_1 | SYNC_CNL_1 | SYNC_LVL_3);
791 791
diff --git a/drivers/staging/media/go7007/go7007-driver.c b/drivers/staging/media/go7007/go7007-driver.c
index ece2dd146487..66950916df23 100644
--- a/drivers/staging/media/go7007/go7007-driver.c
+++ b/drivers/staging/media/go7007/go7007-driver.c
@@ -108,14 +108,13 @@ static int go7007_load_encoder(struct go7007 *go)
108 return -1; 108 return -1;
109 } 109 }
110 fw_len = fw_entry->size - 16; 110 fw_len = fw_entry->size - 16;
111 bounce = kmalloc(fw_len, GFP_KERNEL); 111 bounce = kmemdup(fw_entry->data + 16, fw_len, GFP_KERNEL);
112 if (bounce == NULL) { 112 if (bounce == NULL) {
113 v4l2_err(go, "unable to allocate %d bytes for " 113 v4l2_err(go, "unable to allocate %d bytes for "
114 "firmware transfer\n", fw_len); 114 "firmware transfer\n", fw_len);
115 release_firmware(fw_entry); 115 release_firmware(fw_entry);
116 return -1; 116 return -1;
117 } 117 }
118 memcpy(bounce, fw_entry->data + 16, fw_len);
119 release_firmware(fw_entry); 118 release_firmware(fw_entry);
120 if (go7007_interface_reset(go) < 0 || 119 if (go7007_interface_reset(go) < 0 ||
121 go7007_send_firmware(go, bounce, fw_len) < 0 || 120 go7007_send_firmware(go, bounce, fw_len) < 0 ||
@@ -173,6 +172,11 @@ static int go7007_init_encoder(struct go7007 *go)
173 go7007_write_addr(go, 0x3c82, 0x0001); 172 go7007_write_addr(go, 0x3c82, 0x0001);
174 go7007_write_addr(go, 0x3c80, 0x00fe); 173 go7007_write_addr(go, 0x3c80, 0x00fe);
175 } 174 }
175 if (go->board_id == GO7007_BOARDID_ADLINK_MPG24) {
176 /* set GPIO5 to be an output, currently low */
177 go7007_write_addr(go, 0x3c82, 0x0000);
178 go7007_write_addr(go, 0x3c80, 0x00df);
179 }
176 return 0; 180 return 0;
177} 181}
178 182
@@ -201,7 +205,8 @@ static int init_i2c_module(struct i2c_adapter *adapter, const char *type,
201 if (v4l2_i2c_new_subdev(v4l2_dev, adapter, type, addr, NULL)) 205 if (v4l2_i2c_new_subdev(v4l2_dev, adapter, type, addr, NULL))
202 return 0; 206 return 0;
203 207
204 printk(KERN_INFO "go7007: probing for module i2c:%s failed\n", type); 208 dev_info(&adapter->dev,
209 "go7007: probing for module i2c:%s failed\n", type);
205 return -1; 210 return -1;
206} 211}
207 212
@@ -217,7 +222,7 @@ int go7007_register_encoder(struct go7007 *go)
217{ 222{
218 int i, ret; 223 int i, ret;
219 224
220 printk(KERN_INFO "go7007: registering new %s\n", go->name); 225 dev_info(go->dev, "go7007: registering new %s\n", go->name);
221 226
222 mutex_lock(&go->hw_lock); 227 mutex_lock(&go->hw_lock);
223 ret = go7007_init_encoder(go); 228 ret = go7007_init_encoder(go);
@@ -571,7 +576,7 @@ struct go7007 *go7007_alloc(struct go7007_board_info *board, struct device *dev)
571 struct go7007 *go; 576 struct go7007 *go;
572 int i; 577 int i;
573 578
574 go = kmalloc(sizeof(struct go7007), GFP_KERNEL); 579 go = kzalloc(sizeof(struct go7007), GFP_KERNEL);
575 if (go == NULL) 580 if (go == NULL)
576 return NULL; 581 return NULL;
577 go->dev = dev; 582 go->dev = dev;
diff --git a/drivers/staging/media/go7007/go7007-fw.c b/drivers/staging/media/go7007/go7007-fw.c
index f99c05b454b0..a5ede1c109d0 100644
--- a/drivers/staging/media/go7007/go7007-fw.c
+++ b/drivers/staging/media/go7007/go7007-fw.c
@@ -381,11 +381,8 @@ static int gen_mjpeghdr_to_package(struct go7007 *go, __le16 *code, int space)
381 int size = 0, i, off = 0, chunk; 381 int size = 0, i, off = 0, chunk;
382 382
383 buf = kzalloc(4096, GFP_KERNEL); 383 buf = kzalloc(4096, GFP_KERNEL);
384 if (buf == NULL) { 384 if (buf == NULL)
385 dev_err(go->dev,
386 "unable to allocate 4096 bytes for firmware construction\n");
387 return -1; 385 return -1;
388 }
389 386
390 for (i = 1; i < 32; ++i) { 387 for (i = 1; i < 32; ++i) {
391 mjpeg_frame_header(go, buf + size, i); 388 mjpeg_frame_header(go, buf + size, i);
@@ -651,11 +648,9 @@ static int gen_mpeg1hdr_to_package(struct go7007 *go,
651 int i, off = 0, chunk; 648 int i, off = 0, chunk;
652 649
653 buf = kzalloc(5120, GFP_KERNEL); 650 buf = kzalloc(5120, GFP_KERNEL);
654 if (buf == NULL) { 651 if (buf == NULL)
655 dev_err(go->dev,
656 "unable to allocate 5120 bytes for firmware construction\n");
657 return -1; 652 return -1;
658 } 653
659 framelen[0] = mpeg1_frame_header(go, buf, 0, 1, PFRAME); 654 framelen[0] = mpeg1_frame_header(go, buf, 0, 1, PFRAME);
660 if (go->interlace_coding) 655 if (go->interlace_coding)
661 framelen[0] += mpeg1_frame_header(go, buf + framelen[0] / 8, 656 framelen[0] += mpeg1_frame_header(go, buf + framelen[0] / 8,
@@ -838,11 +833,9 @@ static int gen_mpeg4hdr_to_package(struct go7007 *go,
838 int i, off = 0, chunk; 833 int i, off = 0, chunk;
839 834
840 buf = kzalloc(5120, GFP_KERNEL); 835 buf = kzalloc(5120, GFP_KERNEL);
841 if (buf == NULL) { 836 if (buf == NULL)
842 dev_err(go->dev,
843 "unable to allocate 5120 bytes for firmware construction\n");
844 return -1; 837 return -1;
845 } 838
846 framelen[0] = mpeg4_frame_header(go, buf, 0, PFRAME); 839 framelen[0] = mpeg4_frame_header(go, buf, 0, PFRAME);
847 i = 368; 840 i = 368;
848 framelen[1] = mpeg4_frame_header(go, buf + i, 0, BFRAME_PRE); 841 framelen[1] = mpeg4_frame_header(go, buf + i, 0, BFRAME_PRE);
@@ -1582,12 +1575,9 @@ int go7007_construct_fw_image(struct go7007 *go, u8 **fw, int *fwlen)
1582 return -1; 1575 return -1;
1583 } 1576 }
1584 code = kzalloc(codespace * 2, GFP_KERNEL); 1577 code = kzalloc(codespace * 2, GFP_KERNEL);
1585 if (code == NULL) { 1578 if (code == NULL)
1586 dev_err(go->dev,
1587 "unable to allocate %d bytes for firmware construction\n",
1588 codespace * 2);
1589 goto fw_failed; 1579 goto fw_failed;
1590 } 1580
1591 src = (__le16 *)fw_entry->data; 1581 src = (__le16 *)fw_entry->data;
1592 srclen = fw_entry->size / 2; 1582 srclen = fw_entry->size / 2;
1593 while (srclen >= 2) { 1583 while (srclen >= 2) {
diff --git a/drivers/staging/media/go7007/go7007-i2c.c b/drivers/staging/media/go7007/go7007-i2c.c
index 6bc82aaeef11..39456a36b2c6 100644
--- a/drivers/staging/media/go7007/go7007-i2c.c
+++ b/drivers/staging/media/go7007/go7007-i2c.c
@@ -60,10 +60,10 @@ static int go7007_i2c_xfer(struct go7007 *go, u16 addr, int read,
60 60
61#ifdef GO7007_I2C_DEBUG 61#ifdef GO7007_I2C_DEBUG
62 if (read) 62 if (read)
63 printk(KERN_DEBUG "go7007-i2c: reading 0x%02x on 0x%02x\n", 63 dev_dbg(go->dev, "go7007-i2c: reading 0x%02x on 0x%02x\n",
64 command, addr); 64 command, addr);
65 else 65 else
66 printk(KERN_DEBUG 66 dev_dbg(go->dev,
67 "go7007-i2c: writing 0x%02x to 0x%02x on 0x%02x\n", 67 "go7007-i2c: writing 0x%02x to 0x%02x on 0x%02x\n",
68 *data, command, addr); 68 *data, command, addr);
69#endif 69#endif
@@ -85,7 +85,7 @@ static int go7007_i2c_xfer(struct go7007 *go, u16 addr, int read,
85 msleep(100); 85 msleep(100);
86 } 86 }
87 if (i == 10) { 87 if (i == 10) {
88 printk(KERN_ERR "go7007-i2c: I2C adapter is hung\n"); 88 dev_err(go->dev, "go7007-i2c: I2C adapter is hung\n");
89 goto i2c_done; 89 goto i2c_done;
90 } 90 }
91 91
@@ -119,7 +119,7 @@ static int go7007_i2c_xfer(struct go7007 *go, u16 addr, int read,
119 msleep(100); 119 msleep(100);
120 } 120 }
121 if (i == 10) { 121 if (i == 10) {
122 printk(KERN_ERR "go7007-i2c: I2C adapter is hung\n"); 122 dev_err(go->dev, "go7007-i2c: I2C adapter is hung\n");
123 goto i2c_done; 123 goto i2c_done;
124 } 124 }
125 125
@@ -216,7 +216,7 @@ int go7007_i2c_init(struct go7007 *go)
216 go->i2c_adapter.dev.parent = go->dev; 216 go->i2c_adapter.dev.parent = go->dev;
217 i2c_set_adapdata(&go->i2c_adapter, go); 217 i2c_set_adapdata(&go->i2c_adapter, go);
218 if (i2c_add_adapter(&go->i2c_adapter) < 0) { 218 if (i2c_add_adapter(&go->i2c_adapter) < 0) {
219 printk(KERN_ERR 219 dev_err(go->dev,
220 "go7007-i2c: error: i2c_add_adapter failed\n"); 220 "go7007-i2c: error: i2c_add_adapter failed\n");
221 return -1; 221 return -1;
222 } 222 }
diff --git a/drivers/staging/media/go7007/go7007-usb.c b/drivers/staging/media/go7007/go7007-usb.c
index 5443e25086e9..9dbf5ecd05a2 100644
--- a/drivers/staging/media/go7007/go7007-usb.c
+++ b/drivers/staging/media/go7007/go7007-usb.c
@@ -1110,9 +1110,6 @@ static int go7007_usb_probe(struct usb_interface *intf,
1110 } else { 1110 } else {
1111 u16 channel; 1111 u16 channel;
1112 1112
1113 /* set GPIO5 to be an output, currently low */
1114 go7007_write_addr(go, 0x3c82, 0x0000);
1115 go7007_write_addr(go, 0x3c80, 0x00df);
1116 /* read channel number from GPIO[1:0] */ 1113 /* read channel number from GPIO[1:0] */
1117 go7007_read_addr(go, 0x3c81, &channel); 1114 go7007_read_addr(go, 0x3c81, &channel);
1118 channel &= 0x3; 1115 channel &= 0x3;
@@ -1245,7 +1242,6 @@ static void go7007_usb_disconnect(struct usb_interface *intf)
1245 struct urb *vurb, *aurb; 1242 struct urb *vurb, *aurb;
1246 int i; 1243 int i;
1247 1244
1248 go->status = STATUS_SHUTDOWN;
1249 usb_kill_urb(usb->intr_urb); 1245 usb_kill_urb(usb->intr_urb);
1250 1246
1251 /* Free USB-related structs */ 1247 /* Free USB-related structs */
@@ -1269,6 +1265,7 @@ static void go7007_usb_disconnect(struct usb_interface *intf)
1269 kfree(go->hpi_context); 1265 kfree(go->hpi_context);
1270 1266
1271 go7007_remove(go); 1267 go7007_remove(go);
1268 go->status = STATUS_SHUTDOWN;
1272} 1269}
1273 1270
1274static struct usb_driver go7007_usb_driver = { 1271static struct usb_driver go7007_usb_driver = {
diff --git a/drivers/staging/media/go7007/go7007-v4l2.c b/drivers/staging/media/go7007/go7007-v4l2.c
index a78133b67de2..cb9fe33050c7 100644
--- a/drivers/staging/media/go7007/go7007-v4l2.c
+++ b/drivers/staging/media/go7007/go7007-v4l2.c
@@ -98,7 +98,7 @@ static int go7007_open(struct file *file)
98 98
99 if (go->status != STATUS_ONLINE) 99 if (go->status != STATUS_ONLINE)
100 return -EBUSY; 100 return -EBUSY;
101 gofh = kmalloc(sizeof(struct go7007_file), GFP_KERNEL); 101 gofh = kzalloc(sizeof(struct go7007_file), GFP_KERNEL);
102 if (gofh == NULL) 102 if (gofh == NULL)
103 return -ENOMEM; 103 return -ENOMEM;
104 ++go->ref_count; 104 ++go->ref_count;
@@ -953,6 +953,7 @@ static int vidioc_streamon(struct file *file, void *priv,
953 } 953 }
954 mutex_unlock(&go->hw_lock); 954 mutex_unlock(&go->hw_lock);
955 mutex_unlock(&gofh->lock); 955 mutex_unlock(&gofh->lock);
956 call_all(&go->v4l2_dev, video, s_stream, 1);
956 957
957 return retval; 958 return retval;
958} 959}
@@ -968,6 +969,7 @@ static int vidioc_streamoff(struct file *file, void *priv,
968 mutex_lock(&gofh->lock); 969 mutex_lock(&gofh->lock);
969 go7007_streamoff(go); 970 go7007_streamoff(go);
970 mutex_unlock(&gofh->lock); 971 mutex_unlock(&gofh->lock);
972 call_all(&go->v4l2_dev, video, s_stream, 0);
971 973
972 return 0; 974 return 0;
973} 975}
@@ -1811,8 +1813,8 @@ int go7007_v4l2_init(struct go7007 *go)
1811 } 1813 }
1812 video_set_drvdata(go->video_dev, go); 1814 video_set_drvdata(go->video_dev, go);
1813 ++go->ref_count; 1815 ++go->ref_count;
1814 printk(KERN_INFO "%s: registered device %s [v4l2]\n", 1816 dev_info(go->dev, "registered device %s [v4l2]\n",
1815 go->video_dev->name, video_device_node_name(go->video_dev)); 1817 video_device_node_name(go->video_dev));
1816 1818
1817 return 0; 1819 return 0;
1818} 1820}
@@ -1832,5 +1834,6 @@ void go7007_v4l2_remove(struct go7007 *go)
1832 mutex_unlock(&go->hw_lock); 1834 mutex_unlock(&go->hw_lock);
1833 if (go->video_dev) 1835 if (go->video_dev)
1834 video_unregister_device(go->video_dev); 1836 video_unregister_device(go->video_dev);
1835 v4l2_device_unregister(&go->v4l2_dev); 1837 if (go->status != STATUS_SHUTDOWN)
1838 v4l2_device_unregister(&go->v4l2_dev);
1836} 1839}
diff --git a/drivers/staging/media/go7007/s2250-board.c b/drivers/staging/media/go7007/s2250-board.c
index b3974100c6cd..37400bfa6ccb 100644
--- a/drivers/staging/media/go7007/s2250-board.c
+++ b/drivers/staging/media/go7007/s2250-board.c
@@ -103,8 +103,7 @@ static u16 vid_regs_fp[] = {
103}; 103};
104 104
105/* PAL specific values */ 105/* PAL specific values */
106static u16 vid_regs_fp_pal[] = 106static u16 vid_regs_fp_pal[] = {
107{
108 0x120, 0x017, 107 0x120, 0x017,
109 0x121, 0xd22, 108 0x121, 0xd22,
110 0x122, 0x122, 109 0x122, 0x122,
@@ -174,7 +173,7 @@ static int write_reg(struct i2c_client *client, u8 reg, u8 value)
174 173
175 usb = go->hpi_context; 174 usb = go->hpi_context;
176 if (mutex_lock_interruptible(&usb->i2c_lock) != 0) { 175 if (mutex_lock_interruptible(&usb->i2c_lock) != 0) {
177 printk(KERN_INFO "i2c lock failed\n"); 176 dev_info(&client->dev, "i2c lock failed\n");
178 kfree(buf); 177 kfree(buf);
179 return -EINTR; 178 return -EINTR;
180 } 179 }
@@ -213,7 +212,7 @@ static int write_reg_fp(struct i2c_client *client, u16 addr, u16 val)
213 212
214 usb = go->hpi_context; 213 usb = go->hpi_context;
215 if (mutex_lock_interruptible(&usb->i2c_lock) != 0) { 214 if (mutex_lock_interruptible(&usb->i2c_lock) != 0) {
216 printk(KERN_INFO "i2c lock failed\n"); 215 dev_info(&client->dev, "i2c lock failed\n");
217 kfree(buf); 216 kfree(buf);
218 return -EINTR; 217 return -EINTR;
219 } 218 }
@@ -231,13 +230,13 @@ static int write_reg_fp(struct i2c_client *client, u16 addr, u16 val)
231 val_read = (buf[2] << 8) + buf[3]; 230 val_read = (buf[2] << 8) + buf[3];
232 kfree(buf); 231 kfree(buf);
233 if (val_read != val) { 232 if (val_read != val) {
234 printk(KERN_INFO "invalid fp write %x %x\n", 233 dev_info(&client->dev, "invalid fp write %x %x\n",
235 val_read, val); 234 val_read, val);
236 return -EFAULT; 235 return -EFAULT;
237 } 236 }
238 if (subaddr != addr) { 237 if (subaddr != addr) {
239 printk(KERN_INFO "invalid fp write addr %x %x\n", 238 dev_info(&client->dev, "invalid fp write addr %x %x\n",
240 subaddr, addr); 239 subaddr, addr);
241 return -EFAULT; 240 return -EFAULT;
242 } 241 }
243 } else { 242 } else {
@@ -275,7 +274,7 @@ static int read_reg_fp(struct i2c_client *client, u16 addr, u16 *val)
275 memset(buf, 0xcd, 6); 274 memset(buf, 0xcd, 6);
276 usb = go->hpi_context; 275 usb = go->hpi_context;
277 if (mutex_lock_interruptible(&usb->i2c_lock) != 0) { 276 if (mutex_lock_interruptible(&usb->i2c_lock) != 0) {
278 printk(KERN_INFO "i2c lock failed\n"); 277 dev_info(&client->dev, "i2c lock failed\n");
279 kfree(buf); 278 kfree(buf);
280 return -EINTR; 279 return -EINTR;
281 } 280 }
@@ -299,7 +298,7 @@ static int write_regs(struct i2c_client *client, u8 *regs)
299 298
300 for (i = 0; !((regs[i] == 0x00) && (regs[i+1] == 0x00)); i += 2) { 299 for (i = 0; !((regs[i] == 0x00) && (regs[i+1] == 0x00)); i += 2) {
301 if (write_reg(client, regs[i], regs[i+1]) < 0) { 300 if (write_reg(client, regs[i], regs[i+1]) < 0) {
302 printk(KERN_INFO "s2250: failed\n"); 301 dev_info(&client->dev, "failed\n");
303 return -1; 302 return -1;
304 } 303 }
305 } 304 }
@@ -312,7 +311,7 @@ static int write_regs_fp(struct i2c_client *client, u16 *regs)
312 311
313 for (i = 0; !((regs[i] == 0x00) && (regs[i+1] == 0x00)); i += 2) { 312 for (i = 0; !((regs[i] == 0x00) && (regs[i+1] == 0x00)); i += 2) {
314 if (write_reg_fp(client, regs[i], regs[i+1]) < 0) { 313 if (write_reg_fp(client, regs[i], regs[i+1]) < 0) {
315 printk(KERN_INFO "s2250: failed fp\n"); 314 dev_info(&client->dev, "failed fp\n");
316 return -1; 315 return -1;
317 } 316 }
318 } 317 }
@@ -535,7 +534,7 @@ static int s2250_log_status(struct v4l2_subdev *sd)
535 v4l2_info(sd, "Brightness: %d\n", state->brightness); 534 v4l2_info(sd, "Brightness: %d\n", state->brightness);
536 v4l2_info(sd, "Contrast: %d\n", state->contrast); 535 v4l2_info(sd, "Contrast: %d\n", state->contrast);
537 v4l2_info(sd, "Saturation: %d\n", state->saturation); 536 v4l2_info(sd, "Saturation: %d\n", state->saturation);
538 v4l2_info(sd, "Hue: %d\n", state->hue); return 0; 537 v4l2_info(sd, "Hue: %d\n", state->hue);
539 v4l2_info(sd, "Audio input: %s\n", state->audio_input == 0 ? "Line In" : 538 v4l2_info(sd, "Audio input: %s\n", state->audio_input == 0 ? "Line In" :
540 state->audio_input == 1 ? "Mic" : 539 state->audio_input == 1 ? "Mic" :
541 state->audio_input == 2 ? "Mic Boost" : 540 state->audio_input == 2 ? "Mic Boost" :
@@ -606,23 +605,20 @@ static int s2250_probe(struct i2c_client *client,
606 605
607 /* initialize the audio */ 606 /* initialize the audio */
608 if (write_regs(audio, aud_regs) < 0) { 607 if (write_regs(audio, aud_regs) < 0) {
609 printk(KERN_ERR 608 dev_err(&client->dev, "error initializing audio\n");
610 "s2250: error initializing audio\n");
611 i2c_unregister_device(audio); 609 i2c_unregister_device(audio);
612 kfree(state); 610 kfree(state);
613 return 0; 611 return 0;
614 } 612 }
615 613
616 if (write_regs(client, vid_regs) < 0) { 614 if (write_regs(client, vid_regs) < 0) {
617 printk(KERN_ERR 615 dev_err(&client->dev, "error initializing decoder\n");
618 "s2250: error initializing decoder\n");
619 i2c_unregister_device(audio); 616 i2c_unregister_device(audio);
620 kfree(state); 617 kfree(state);
621 return 0; 618 return 0;
622 } 619 }
623 if (write_regs_fp(client, vid_regs_fp) < 0) { 620 if (write_regs_fp(client, vid_regs_fp) < 0) {
624 printk(KERN_ERR 621 dev_err(&client->dev, "error initializing decoder\n");
625 "s2250: error initializing decoder\n");
626 i2c_unregister_device(audio); 622 i2c_unregister_device(audio);
627 kfree(state); 623 kfree(state);
628 return 0; 624 return 0;
diff --git a/drivers/staging/media/go7007/s2250-loader.c b/drivers/staging/media/go7007/s2250-loader.c
index f1bd159ac195..72e5175fe7e3 100644
--- a/drivers/staging/media/go7007/s2250-loader.c
+++ b/drivers/staging/media/go7007/s2250-loader.c
@@ -55,16 +55,16 @@ static int s2250loader_probe(struct usb_interface *interface,
55 55
56 usbdev = usb_get_dev(interface_to_usbdev(interface)); 56 usbdev = usb_get_dev(interface_to_usbdev(interface));
57 if (!usbdev) { 57 if (!usbdev) {
58 printk(KERN_ERR "Enter s2250loader_probe failed\n"); 58 dev_err(&interface->dev, "Enter s2250loader_probe failed\n");
59 return -1; 59 return -1;
60 } 60 }
61 printk(KERN_INFO "Enter s2250loader_probe 2.6 kernel\n"); 61 dev_info(&interface->dev, "Enter s2250loader_probe 2.6 kernel\n");
62 printk(KERN_INFO "vendor id 0x%x, device id 0x%x devnum:%d\n", 62 dev_info(&interface->dev, "vendor id 0x%x, device id 0x%x devnum:%d\n",
63 usbdev->descriptor.idVendor, usbdev->descriptor.idProduct, 63 usbdev->descriptor.idVendor, usbdev->descriptor.idProduct,
64 usbdev->devnum); 64 usbdev->devnum);
65 65
66 if (usbdev->descriptor.bNumConfigurations != 1) { 66 if (usbdev->descriptor.bNumConfigurations != 1) {
67 printk(KERN_ERR "can't handle multiple config\n"); 67 dev_err(&interface->dev, "can't handle multiple config\n");
68 return -1; 68 return -1;
69 } 69 }
70 mutex_lock(&s2250_dev_table_mutex); 70 mutex_lock(&s2250_dev_table_mutex);
@@ -75,31 +75,31 @@ static int s2250loader_probe(struct usb_interface *interface,
75 } 75 }
76 76
77 if (minor < 0 || minor >= MAX_DEVICES) { 77 if (minor < 0 || minor >= MAX_DEVICES) {
78 printk(KERN_ERR "Invalid minor: %d\n", minor); 78 dev_err(&interface->dev, "Invalid minor: %d\n", minor);
79 goto failed; 79 goto failed;
80 } 80 }
81 81
82 /* Allocate dev data structure */ 82 /* Allocate dev data structure */
83 s = kmalloc(sizeof(device_extension_t), GFP_KERNEL); 83 s = kmalloc(sizeof(device_extension_t), GFP_KERNEL);
84 if (s == NULL) { 84 if (s == NULL)
85 printk(KERN_ERR "Out of memory\n");
86 goto failed; 85 goto failed;
87 } 86
88 s2250_dev_table[minor] = s; 87 s2250_dev_table[minor] = s;
89 88
90 printk(KERN_INFO "s2250loader_probe: Device %d on Bus %d Minor %d\n", 89 dev_info(&interface->dev,
91 usbdev->devnum, usbdev->bus->busnum, minor); 90 "s2250loader_probe: Device %d on Bus %d Minor %d\n",
91 usbdev->devnum, usbdev->bus->busnum, minor);
92 92
93 memset(s, 0, sizeof(device_extension_t)); 93 memset(s, 0, sizeof(device_extension_t));
94 s->usbdev = usbdev; 94 s->usbdev = usbdev;
95 printk(KERN_INFO "loading 2250 loader\n"); 95 dev_info(&interface->dev, "loading 2250 loader\n");
96 96
97 kref_init(&(s->kref)); 97 kref_init(&(s->kref));
98 98
99 mutex_unlock(&s2250_dev_table_mutex); 99 mutex_unlock(&s2250_dev_table_mutex);
100 100
101 if (request_firmware(&fw, S2250_LOADER_FIRMWARE, &usbdev->dev)) { 101 if (request_firmware(&fw, S2250_LOADER_FIRMWARE, &usbdev->dev)) {
102 printk(KERN_ERR 102 dev_err(&interface->dev,
103 "s2250: unable to load firmware from file \"%s\"\n", 103 "s2250: unable to load firmware from file \"%s\"\n",
104 S2250_LOADER_FIRMWARE); 104 S2250_LOADER_FIRMWARE);
105 goto failed2; 105 goto failed2;
@@ -107,12 +107,12 @@ static int s2250loader_probe(struct usb_interface *interface,
107 ret = usb_cypress_load_firmware(usbdev, fw, CYPRESS_FX2); 107 ret = usb_cypress_load_firmware(usbdev, fw, CYPRESS_FX2);
108 release_firmware(fw); 108 release_firmware(fw);
109 if (0 != ret) { 109 if (0 != ret) {
110 printk(KERN_ERR "loader download failed\n"); 110 dev_err(&interface->dev, "loader download failed\n");
111 goto failed2; 111 goto failed2;
112 } 112 }
113 113
114 if (request_firmware(&fw, S2250_FIRMWARE, &usbdev->dev)) { 114 if (request_firmware(&fw, S2250_FIRMWARE, &usbdev->dev)) {
115 printk(KERN_ERR 115 dev_err(&interface->dev,
116 "s2250: unable to load firmware from file \"%s\"\n", 116 "s2250: unable to load firmware from file \"%s\"\n",
117 S2250_FIRMWARE); 117 S2250_FIRMWARE);
118 goto failed2; 118 goto failed2;
@@ -120,7 +120,7 @@ static int s2250loader_probe(struct usb_interface *interface,
120 ret = usb_cypress_load_firmware(usbdev, fw, CYPRESS_FX2); 120 ret = usb_cypress_load_firmware(usbdev, fw, CYPRESS_FX2);
121 release_firmware(fw); 121 release_firmware(fw);
122 if (0 != ret) { 122 if (0 != ret) {
123 printk(KERN_ERR "firmware_s2250 download failed\n"); 123 dev_err(&interface->dev, "firmware_s2250 download failed\n");
124 goto failed2; 124 goto failed2;
125 } 125 }
126 126
@@ -133,14 +133,14 @@ failed2:
133 if (s) 133 if (s)
134 kref_put(&(s->kref), s2250loader_delete); 134 kref_put(&(s->kref), s2250loader_delete);
135 135
136 printk(KERN_ERR "probe failed\n"); 136 dev_err(&interface->dev, "probe failed\n");
137 return -1; 137 return -1;
138} 138}
139 139
140static void s2250loader_disconnect(struct usb_interface *interface) 140static void s2250loader_disconnect(struct usb_interface *interface)
141{ 141{
142 pdevice_extension_t s; 142 pdevice_extension_t s;
143 printk(KERN_INFO "s2250: disconnect\n"); 143 dev_info(&interface->dev, "s2250: disconnect\n");
144 s = usb_get_intfdata(interface); 144 s = usb_get_intfdata(interface);
145 usb_set_intfdata(interface, NULL); 145 usb_set_intfdata(interface, NULL);
146 kref_put(&(s->kref), s2250loader_delete); 146 kref_put(&(s->kref), s2250loader_delete);
diff --git a/drivers/staging/media/go7007/wis-saa7113.c b/drivers/staging/media/go7007/wis-saa7113.c
index 8810c1e6e1ed..891cde713a47 100644
--- a/drivers/staging/media/go7007/wis-saa7113.c
+++ b/drivers/staging/media/go7007/wis-saa7113.c
@@ -141,7 +141,7 @@ static int wis_saa7113_command(struct i2c_client *client,
141 } else if (dec->norm & V4L2_STD_PAL) { 141 } else if (dec->norm & V4L2_STD_PAL) {
142 write_reg(client, 0x0e, 0x01); 142 write_reg(client, 0x0e, 0x01);
143 write_reg(client, 0x10, 0x48); 143 write_reg(client, 0x10, 0x48);
144 } else if (dec->norm * V4L2_STD_SECAM) { 144 } else if (dec->norm & V4L2_STD_SECAM) {
145 write_reg(client, 0x0e, 0x50); 145 write_reg(client, 0x0e, 0x50);
146 write_reg(client, 0x10, 0x48); 146 write_reg(client, 0x10, 0x48);
147 } 147 }
diff --git a/drivers/staging/media/go7007/wis-sony-tuner.c b/drivers/staging/media/go7007/wis-sony-tuner.c
index 1291ab79d2af..5d7ff8c81d6d 100644
--- a/drivers/staging/media/go7007/wis-sony-tuner.c
+++ b/drivers/staging/media/go7007/wis-sony-tuner.c
@@ -95,8 +95,8 @@ static int set_freq(struct i2c_client *client, int freq)
95 band_name = "UHF"; 95 band_name = "UHF";
96 band_select = tun->UHF; 96 band_select = tun->UHF;
97 } 97 }
98 printk(KERN_DEBUG "wis-sony-tuner: tuning to frequency %d.%04d (%s)\n", 98 dev_dbg(&client->dev, "tuning to frequency %d.%04d (%s)\n",
99 freq / 16, (freq % 16) * 625, band_name); 99 freq / 16, (freq % 16) * 625, band_name);
100 n = freq + tun->IFPCoff; 100 n = freq + tun->IFPCoff;
101 101
102 buffer[0] = n >> 8; 102 buffer[0] = n >> 8;
@@ -288,16 +288,16 @@ static int mpx_setup(struct i2c_client *client)
288 u8 buf1[3], buf2[2]; 288 u8 buf1[3], buf2[2];
289 struct i2c_msg msgs[2]; 289 struct i2c_msg msgs[2];
290 290
291 printk(KERN_DEBUG "wis-sony-tuner: MPX registers: %04x %04x " 291 dev_dbg(&client->dev,
292 "%04x %04x %04x %04x %04x %04x\n", 292 "MPX registers: %04x %04x %04x %04x %04x %04x %04x %04x\n",
293 mpx_audio_modes[t->mpxmode].modus, 293 mpx_audio_modes[t->mpxmode].modus,
294 source, 294 source,
295 mpx_audio_modes[t->mpxmode].acb, 295 mpx_audio_modes[t->mpxmode].acb,
296 mpx_audio_modes[t->mpxmode].fm_prescale, 296 mpx_audio_modes[t->mpxmode].fm_prescale,
297 mpx_audio_modes[t->mpxmode].nicam_prescale, 297 mpx_audio_modes[t->mpxmode].nicam_prescale,
298 mpx_audio_modes[t->mpxmode].scart_prescale, 298 mpx_audio_modes[t->mpxmode].scart_prescale,
299 mpx_audio_modes[t->mpxmode].system, 299 mpx_audio_modes[t->mpxmode].system,
300 mpx_audio_modes[t->mpxmode].volume); 300 mpx_audio_modes[t->mpxmode].volume);
301 buf1[0] = 0x11; 301 buf1[0] = 0x11;
302 buf1[1] = 0x00; 302 buf1[1] = 0x00;
303 buf1[2] = 0x7e; 303 buf1[2] = 0x7e;
@@ -310,14 +310,14 @@ static int mpx_setup(struct i2c_client *client)
310 msgs[1].len = 2; 310 msgs[1].len = 2;
311 msgs[1].buf = buf2; 311 msgs[1].buf = buf2;
312 i2c_transfer(client->adapter, msgs, 2); 312 i2c_transfer(client->adapter, msgs, 2);
313 printk(KERN_DEBUG "wis-sony-tuner: MPX system: %02x%02x\n", 313 dev_dbg(&client->dev, "MPX system: %02x%02x\n",
314 buf2[0], buf2[1]); 314 buf2[0], buf2[1]);
315 buf1[0] = 0x11; 315 buf1[0] = 0x11;
316 buf1[1] = 0x02; 316 buf1[1] = 0x02;
317 buf1[2] = 0x00; 317 buf1[2] = 0x00;
318 i2c_transfer(client->adapter, msgs, 2); 318 i2c_transfer(client->adapter, msgs, 2);
319 printk(KERN_DEBUG "wis-sony-tuner: MPX status: %02x%02x\n", 319 dev_dbg(&client->dev, "MPX status: %02x%02x\n",
320 buf2[0], buf2[1]); 320 buf2[0], buf2[1]);
321 } 321 }
322#endif 322#endif
323 return 0; 323 return 0;
@@ -375,8 +375,7 @@ static int set_if(struct i2c_client *client)
375 t->mpxmode = force_mpx_mode; 375 t->mpxmode = force_mpx_mode;
376 else 376 else
377 t->mpxmode = default_mpx_mode; 377 t->mpxmode = default_mpx_mode;
378 printk(KERN_DEBUG "wis-sony-tuner: setting MPX to mode %d\n", 378 dev_dbg(&client->dev, "setting MPX to mode %d\n", t->mpxmode);
379 t->mpxmode);
380 mpx_setup(client); 379 mpx_setup(client);
381 380
382 return 0; 381 return 0;
@@ -401,8 +400,8 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
401 400
402 if (t->type >= 0) { 401 if (t->type >= 0) {
403 if (t->type != *type) 402 if (t->type != *type)
404 printk(KERN_ERR "wis-sony-tuner: type already " 403 dev_err(&client->dev,
405 "set to %d, ignoring request for %d\n", 404 "type already set to %d, ignoring request for %d\n",
406 t->type, *type); 405 t->type, *type);
407 break; 406 break;
408 } 407 }
@@ -414,28 +413,28 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
414 case 'B': 413 case 'B':
415 case 'g': 414 case 'g':
416 case 'G': 415 case 'G':
417 printk(KERN_INFO "wis-sony-tuner: forcing " 416 dev_info(&client->dev,
418 "tuner to PAL-B/G bands\n"); 417 "forcing tuner to PAL-B/G bands\n");
419 force_band = V4L2_STD_PAL_BG; 418 force_band = V4L2_STD_PAL_BG;
420 break; 419 break;
421 case 'i': 420 case 'i':
422 case 'I': 421 case 'I':
423 printk(KERN_INFO "wis-sony-tuner: forcing " 422 dev_info(&client->dev,
424 "tuner to PAL-I band\n"); 423 "forcing tuner to PAL-I band\n");
425 force_band = V4L2_STD_PAL_I; 424 force_band = V4L2_STD_PAL_I;
426 break; 425 break;
427 case 'd': 426 case 'd':
428 case 'D': 427 case 'D':
429 case 'k': 428 case 'k':
430 case 'K': 429 case 'K':
431 printk(KERN_INFO "wis-sony-tuner: forcing " 430 dev_info(&client->dev,
432 "tuner to PAL-D/K bands\n"); 431 "forcing tuner to PAL-D/K bands\n");
433 force_band = V4L2_STD_PAL_I; 432 force_band = V4L2_STD_PAL_I;
434 break; 433 break;
435 case 'l': 434 case 'l':
436 case 'L': 435 case 'L':
437 printk(KERN_INFO "wis-sony-tuner: forcing " 436 dev_info(&client->dev,
438 "tuner to SECAM-L band\n"); 437 "forcing tuner to SECAM-L band\n");
439 force_band = V4L2_STD_SECAM_L; 438 force_band = V4L2_STD_SECAM_L;
440 break; 439 break;
441 default: 440 default:
@@ -455,14 +454,15 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
455 t->std = V4L2_STD_NTSC_M; 454 t->std = V4L2_STD_NTSC_M;
456 break; 455 break;
457 default: 456 default:
458 printk(KERN_ERR "wis-sony-tuner: tuner type %d is not " 457 dev_err(&client->dev,
459 "supported by this module\n", *type); 458 "tuner type %d is not supported by this module\n",
459 *type);
460 break; 460 break;
461 } 461 }
462 if (type >= 0) 462 if (type >= 0)
463 printk(KERN_INFO 463 dev_info(&clinet->dev,
464 "wis-sony-tuner: type set to %d (%s)\n", 464 "type set to %d (%s)\n",
465 t->type, sony_tuners[t->type - 200].name); 465 t->type, sony_tuners[t->type - 200].name);
466 break; 466 break;
467 } 467 }
468#endif 468#endif
@@ -544,9 +544,8 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
544 if (force_band && (*std & force_band) != *std && 544 if (force_band && (*std & force_band) != *std &&
545 *std != V4L2_STD_PAL && 545 *std != V4L2_STD_PAL &&
546 *std != V4L2_STD_SECAM) { 546 *std != V4L2_STD_SECAM) {
547 printk(KERN_DEBUG "wis-sony-tuner: ignoring " 547 dev_dbg(&client->dev,
548 "requested TV standard in " 548 "ignoring requested TV standard in favor of force_band value\n");
549 "favor of force_band value\n");
550 t->std = force_band; 549 t->std = force_band;
551 } else if (*std & V4L2_STD_PAL_BG) { /* default */ 550 } else if (*std & V4L2_STD_PAL_BG) { /* default */
552 t->std = V4L2_STD_PAL_BG; 551 t->std = V4L2_STD_PAL_BG;
@@ -557,8 +556,8 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
557 } else if (*std & V4L2_STD_SECAM_L) { 556 } else if (*std & V4L2_STD_SECAM_L) {
558 t->std = V4L2_STD_SECAM_L; 557 t->std = V4L2_STD_SECAM_L;
559 } else { 558 } else {
560 printk(KERN_ERR "wis-sony-tuner: TV standard " 559 dev_err(&client->dev,
561 "not supported\n"); 560 "TV standard not supported\n");
562 *std = 0; /* hack to indicate EINVAL */ 561 *std = 0; /* hack to indicate EINVAL */
563 break; 562 break;
564 } 563 }
@@ -567,15 +566,15 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
567 break; 566 break;
568 case TUNER_SONY_BTF_PK467Z: 567 case TUNER_SONY_BTF_PK467Z:
569 if (!(*std & V4L2_STD_NTSC_M_JP)) { 568 if (!(*std & V4L2_STD_NTSC_M_JP)) {
570 printk(KERN_ERR "wis-sony-tuner: TV standard " 569 dev_err(&client->dev,
571 "not supported\n"); 570 "TV standard not supported\n");
572 *std = 0; /* hack to indicate EINVAL */ 571 *std = 0; /* hack to indicate EINVAL */
573 } 572 }
574 break; 573 break;
575 case TUNER_SONY_BTF_PB463Z: 574 case TUNER_SONY_BTF_PB463Z:
576 if (!(*std & V4L2_STD_NTSC_M)) { 575 if (!(*std & V4L2_STD_NTSC_M)) {
577 printk(KERN_ERR "wis-sony-tuner: TV standard " 576 dev_err(&client->dev,
578 "not supported\n"); 577 "TV standard not supported\n");
579 *std = 0; /* hack to indicate EINVAL */ 578 *std = 0; /* hack to indicate EINVAL */
580 } 579 }
581 break; 580 break;
@@ -673,8 +672,7 @@ static int wis_sony_tuner_probe(struct i2c_client *client,
673 t->audmode = V4L2_TUNER_MODE_STEREO; 672 t->audmode = V4L2_TUNER_MODE_STEREO;
674 i2c_set_clientdata(client, t); 673 i2c_set_clientdata(client, t);
675 674
676 printk(KERN_DEBUG 675 dev_dbg(&client->dev, "initializing tuner at address %d on %s\n",
677 "wis-sony-tuner: initializing tuner at address %d on %s\n",
678 client->addr, adapter->name); 676 client->addr, adapter->name);
679 677
680 return 0; 678 return 0;
diff --git a/drivers/staging/media/go7007/wis-tw2804.c b/drivers/staging/media/go7007/wis-tw2804.c
index d6410ee01be8..290fd8c7bfef 100644
--- a/drivers/staging/media/go7007/wis-tw2804.c
+++ b/drivers/staging/media/go7007/wis-tw2804.c
@@ -128,30 +128,32 @@ static int wis_tw2804_command(struct i2c_client *client,
128 int *input = arg; 128 int *input = arg;
129 129
130 if (*input < 0 || *input > 3) { 130 if (*input < 0 || *input > 3) {
131 printk(KERN_ERR "wis-tw2804: channel %d is not " 131 dev_err(&client->dev,
132 "between 0 and 3!\n", *input); 132 "channel %d is not between 0 and 3!\n", *input);
133 return 0; 133 return 0;
134 } 134 }
135 dec->channel = *input; 135 dec->channel = *input;
136 printk(KERN_DEBUG "wis-tw2804: initializing TW2804 " 136 dev_dbg(&client->dev, "initializing TW2804 channel %d\n",
137 "channel %d\n", dec->channel); 137 dec->channel);
138 if (dec->channel == 0 && 138 if (dec->channel == 0 &&
139 write_regs(client, global_registers, 0) < 0) { 139 write_regs(client, global_registers, 0) < 0) {
140 printk(KERN_ERR "wis-tw2804: error initializing " 140 dev_err(&client->dev,
141 "TW2804 global registers\n"); 141 "error initializing TW2804 global registers\n");
142 return 0; 142 return 0;
143 } 143 }
144 if (write_regs(client, channel_registers, dec->channel) < 0) { 144 if (write_regs(client, channel_registers, dec->channel) < 0) {
145 printk(KERN_ERR "wis-tw2804: error initializing " 145 dev_err(&client->dev,
146 "TW2804 channel %d\n", dec->channel); 146 "error initializing TW2804 channel %d\n",
147 dec->channel);
147 return 0; 148 return 0;
148 } 149 }
149 return 0; 150 return 0;
150 } 151 }
151 152
152 if (dec->channel < 0) { 153 if (dec->channel < 0) {
153 printk(KERN_DEBUG "wis-tw2804: ignoring command %08x until " 154 dev_dbg(&client->dev,
154 "channel number is set\n", cmd); 155 "ignoring command %08x until channel number is set\n",
156 cmd);
155 return 0; 157 return 0;
156 } 158 }
157 159
@@ -311,7 +313,7 @@ static int wis_tw2804_probe(struct i2c_client *client,
311 dec->hue = 128; 313 dec->hue = 128;
312 i2c_set_clientdata(client, dec); 314 i2c_set_clientdata(client, dec);
313 315
314 printk(KERN_DEBUG "wis-tw2804: creating TW2804 at address %d on %s\n", 316 dev_dbg(&client->dev, "creating TW2804 at address %d on %s\n",
315 client->addr, adapter->name); 317 client->addr, adapter->name);
316 318
317 return 0; 319 return 0;
diff --git a/drivers/staging/media/go7007/wis-tw9903.c b/drivers/staging/media/go7007/wis-tw9903.c
index 94071def3bb4..684ca37f0382 100644
--- a/drivers/staging/media/go7007/wis-tw9903.c
+++ b/drivers/staging/media/go7007/wis-tw9903.c
@@ -31,8 +31,7 @@ struct wis_tw9903 {
31 int hue; 31 int hue;
32}; 32};
33 33
34static u8 initial_registers[] = 34static u8 initial_registers[] = {
35{
36 0x02, 0x44, /* input 1, composite */ 35 0x02, 0x44, /* input 1, composite */
37 0x03, 0x92, /* correct digital format */ 36 0x03, 0x92, /* correct digital format */
38 0x04, 0x00, 37 0x04, 0x00,
@@ -128,8 +127,8 @@ static int wis_tw9903_command(struct i2c_client *client,
128 0x06, 0xc0, /* reset device */ 127 0x06, 0xc0, /* reset device */
129 0, 0, 128 0, 0,
130 }; 129 };
131 printk(KERN_DEBUG "vscale is %04x, hscale is %04x\n", 130 dev_dbg(&client->dev, "vscale is %04x, hscale is %04x\n",
132 vscale, hscale); 131 vscale, hscale);
133 /*write_regs(client, regs);*/ 132 /*write_regs(client, regs);*/
134 break; 133 break;
135 } 134 }
@@ -288,12 +287,11 @@ static int wis_tw9903_probe(struct i2c_client *client,
288 dec->hue = 0; 287 dec->hue = 0;
289 i2c_set_clientdata(client, dec); 288 i2c_set_clientdata(client, dec);
290 289
291 printk(KERN_DEBUG 290 dev_dbg(&client->dev, "initializing TW9903 at address %d on %s\n",
292 "wis-tw9903: initializing TW9903 at address %d on %s\n",
293 client->addr, adapter->name); 291 client->addr, adapter->name);
294 292
295 if (write_regs(client, initial_registers) < 0) { 293 if (write_regs(client, initial_registers) < 0) {
296 printk(KERN_ERR "wis-tw9903: error initializing TW9903\n"); 294 dev_err(&client->dev, "error initializing TW9903\n");
297 kfree(dec); 295 kfree(dec);
298 return -ENODEV; 296 return -ENODEV;
299 } 297 }
diff --git a/drivers/staging/media/go7007/wis-uda1342.c b/drivers/staging/media/go7007/wis-uda1342.c
index 05ac798f35f7..582ea120a531 100644
--- a/drivers/staging/media/go7007/wis-uda1342.c
+++ b/drivers/staging/media/go7007/wis-uda1342.c
@@ -47,8 +47,8 @@ static int wis_uda1342_command(struct i2c_client *client,
47 write_reg(client, 0x00, 0x1241); /* select input 1 */ 47 write_reg(client, 0x00, 0x1241); /* select input 1 */
48 break; 48 break;
49 default: 49 default:
50 printk(KERN_ERR "wis-uda1342: input %d not supported\n", 50 dev_err(&client->dev, "input %d not supported\n",
51 *inp); 51 *inp);
52 break; 52 break;
53 } 53 }
54 break; 54 break;
@@ -67,8 +67,7 @@ static int wis_uda1342_probe(struct i2c_client *client,
67 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA)) 67 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA))
68 return -ENODEV; 68 return -ENODEV;
69 69
70 printk(KERN_DEBUG 70 dev_dbg(&client->dev, "initializing UDA1342 at address %d on %s\n",
71 "wis-uda1342: initializing UDA1342 at address %d on %s\n",
72 client->addr, adapter->name); 71 client->addr, adapter->name);
73 72
74 write_reg(client, 0x00, 0x8000); /* reset registers */ 73 write_reg(client, 0x00, 0x8000); /* reset registers */
diff --git a/drivers/staging/media/lirc/lirc_bt829.c b/drivers/staging/media/lirc/lirc_bt829.c
index 951007a3fc96..fa31ee7dd6a9 100644
--- a/drivers/staging/media/lirc/lirc_bt829.c
+++ b/drivers/staging/media/lirc/lirc_bt829.c
@@ -18,6 +18,8 @@
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19*/ 19*/
20 20
21#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22
21#include <linux/kernel.h> 23#include <linux/kernel.h>
22#include <linux/module.h> 24#include <linux/module.h>
23#include <linux/threads.h> 25#include <linux/threads.h>
@@ -72,20 +74,19 @@ static struct pci_dev *do_pci_probe(void)
72 my_dev = pci_get_device(PCI_VENDOR_ID_ATI, 74 my_dev = pci_get_device(PCI_VENDOR_ID_ATI,
73 PCI_DEVICE_ID_ATI_264VT, NULL); 75 PCI_DEVICE_ID_ATI_264VT, NULL);
74 if (my_dev) { 76 if (my_dev) {
75 printk(KERN_ERR DRIVER_NAME ": Using device: %s\n", 77 pr_err("Using device: %s\n", pci_name(my_dev));
76 pci_name(my_dev));
77 pci_addr_phys = 0; 78 pci_addr_phys = 0;
78 if (my_dev->resource[0].flags & IORESOURCE_MEM) { 79 if (my_dev->resource[0].flags & IORESOURCE_MEM) {
79 pci_addr_phys = my_dev->resource[0].start; 80 pci_addr_phys = my_dev->resource[0].start;
80 printk(KERN_INFO DRIVER_NAME ": memory at 0x%08X\n", 81 pr_info("memory at 0x%08X\n",
81 (unsigned int)pci_addr_phys); 82 (unsigned int)pci_addr_phys);
82 } 83 }
83 if (pci_addr_phys == 0) { 84 if (pci_addr_phys == 0) {
84 printk(KERN_ERR DRIVER_NAME ": no memory resource ?\n"); 85 pr_err("no memory resource ?\n");
85 return NULL; 86 return NULL;
86 } 87 }
87 } else { 88 } else {
88 printk(KERN_ERR DRIVER_NAME ": pci_probe failed\n"); 89 pr_err("pci_probe failed\n");
89 return NULL; 90 return NULL;
90 } 91 }
91 return my_dev; 92 return my_dev;
@@ -140,7 +141,7 @@ int init_module(void)
140 141
141 atir_minor = lirc_register_driver(&atir_driver); 142 atir_minor = lirc_register_driver(&atir_driver);
142 if (atir_minor < 0) { 143 if (atir_minor < 0) {
143 printk(KERN_ERR DRIVER_NAME ": failed to register driver!\n"); 144 pr_err("failed to register driver!\n");
144 return atir_minor; 145 return atir_minor;
145 } 146 }
146 dprintk("driver is registered on minor %d\n", atir_minor); 147 dprintk("driver is registered on minor %d\n", atir_minor);
@@ -159,7 +160,7 @@ static int atir_init_start(void)
159{ 160{
160 pci_addr_lin = ioremap(pci_addr_phys + DATA_PCI_OFF, 0x400); 161 pci_addr_lin = ioremap(pci_addr_phys + DATA_PCI_OFF, 0x400);
161 if (pci_addr_lin == 0) { 162 if (pci_addr_lin == 0) {
162 printk(KERN_INFO DRIVER_NAME ": pci mem must be mapped\n"); 163 pr_info("pci mem must be mapped\n");
163 return 0; 164 return 0;
164 } 165 }
165 return 1; 166 return 1;
diff --git a/drivers/staging/media/lirc/lirc_igorplugusb.c b/drivers/staging/media/lirc/lirc_igorplugusb.c
index 939a801c23e4..2faa391006db 100644
--- a/drivers/staging/media/lirc/lirc_igorplugusb.c
+++ b/drivers/staging/media/lirc/lirc_igorplugusb.c
@@ -223,8 +223,8 @@ static int unregister_from_lirc(struct igorplug *ir)
223 int devnum; 223 int devnum;
224 224
225 if (!ir) { 225 if (!ir) {
226 printk(KERN_ERR "%s: called with NULL device struct!\n", 226 dev_err(&ir->usbdev->dev,
227 __func__); 227 "%s: called with NULL device struct!\n", __func__);
228 return -EINVAL; 228 return -EINVAL;
229 } 229 }
230 230
@@ -232,8 +232,8 @@ static int unregister_from_lirc(struct igorplug *ir)
232 d = ir->d; 232 d = ir->d;
233 233
234 if (!d) { 234 if (!d) {
235 printk(KERN_ERR "%s: called with NULL lirc driver struct!\n", 235 dev_err(&ir->usbdev->dev,
236 __func__); 236 "%s: called with NULL lirc driver struct!\n", __func__);
237 return -EINVAL; 237 return -EINVAL;
238 } 238 }
239 239
@@ -347,8 +347,8 @@ static int igorplugusb_remote_poll(void *data, struct lirc_buffer *buf)
347 if (ir->buf_in[2] == 0) 347 if (ir->buf_in[2] == 0)
348 send_fragment(ir, buf, DEVICE_HEADERLEN, ret); 348 send_fragment(ir, buf, DEVICE_HEADERLEN, ret);
349 else { 349 else {
350 printk(KERN_WARNING DRIVER_NAME 350 dev_warn(&ir->usbdev->dev,
351 "[%d]: Device buffer overrun.\n", ir->devnum); 351 "[%d]: Device buffer overrun.\n", ir->devnum);
352 /* HHHNNNNNNNNNNNOOOOOOOO H = header 352 /* HHHNNNNNNNNNNNOOOOOOOO H = header
353 <---[2]---> N = newer 353 <---[2]---> N = newer
354 <---------ret--------> O = older */ 354 <---------ret--------> O = older */
diff --git a/drivers/staging/media/lirc/lirc_imon.c b/drivers/staging/media/lirc/lirc_imon.c
index 2944fde89f44..0a2c45dd4475 100644
--- a/drivers/staging/media/lirc/lirc_imon.c
+++ b/drivers/staging/media/lirc/lirc_imon.c
@@ -20,6 +20,8 @@
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */ 21 */
22 22
23#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24
23#include <linux/errno.h> 25#include <linux/errno.h>
24#include <linux/init.h> 26#include <linux/init.h>
25#include <linux/kernel.h> 27#include <linux/kernel.h>
@@ -205,12 +207,12 @@ static void deregister_from_lirc(struct imon_context *context)
205 207
206 retval = lirc_unregister_driver(minor); 208 retval = lirc_unregister_driver(minor);
207 if (retval) 209 if (retval)
208 printk(KERN_ERR KBUILD_MODNAME 210 dev_err(&context->usbdev->dev,
209 ": %s: unable to deregister from lirc(%d)", 211 ": %s: unable to deregister from lirc(%d)",
210 __func__, retval); 212 __func__, retval);
211 else 213 else
212 printk(KERN_INFO MOD_NAME ": Deregistered iMON driver " 214 dev_info(&context->usbdev->dev,
213 "(minor:%d)\n", minor); 215 "Deregistered iMON driver (minor:%d)\n", minor);
214 216
215} 217}
216 218
@@ -231,8 +233,7 @@ static int display_open(struct inode *inode, struct file *file)
231 subminor = iminor(inode); 233 subminor = iminor(inode);
232 interface = usb_find_interface(&imon_driver, subminor); 234 interface = usb_find_interface(&imon_driver, subminor);
233 if (!interface) { 235 if (!interface) {
234 printk(KERN_ERR KBUILD_MODNAME 236 pr_err("%s: could not find interface for minor %d\n",
235 ": %s: could not find interface for minor %d\n",
236 __func__, subminor); 237 __func__, subminor);
237 retval = -ENODEV; 238 retval = -ENODEV;
238 goto exit; 239 goto exit;
@@ -282,8 +283,7 @@ static int display_close(struct inode *inode, struct file *file)
282 context = file->private_data; 283 context = file->private_data;
283 284
284 if (!context) { 285 if (!context) {
285 printk(KERN_ERR KBUILD_MODNAME 286 pr_err("%s: no context for device\n", __func__);
286 "%s: no context for device\n", __func__);
287 return -ENODEV; 287 return -ENODEV;
288 } 288 }
289 289
@@ -391,8 +391,7 @@ static ssize_t vfd_write(struct file *file, const char __user *buf,
391 391
392 context = file->private_data; 392 context = file->private_data;
393 if (!context) { 393 if (!context) {
394 printk(KERN_ERR KBUILD_MODNAME 394 pr_err("%s: no context for device\n", __func__);
395 "%s: no context for device\n", __func__);
396 return -ENODEV; 395 return -ENODEV;
397 } 396 }
398 397
@@ -521,8 +520,7 @@ static void ir_close(void *data)
521 520
522 context = (struct imon_context *)data; 521 context = (struct imon_context *)data;
523 if (!context) { 522 if (!context) {
524 printk(KERN_ERR KBUILD_MODNAME 523 pr_err("%s: no context for device\n", __func__);
525 "%s: no context for device\n", __func__);
526 return; 524 return;
527 } 525 }
528 526
@@ -746,7 +744,6 @@ static int imon_probe(struct usb_interface *interface,
746 744
747 context = kzalloc(sizeof(struct imon_context), GFP_KERNEL); 745 context = kzalloc(sizeof(struct imon_context), GFP_KERNEL);
748 if (!context) { 746 if (!context) {
749 dev_err(dev, "%s: kzalloc failed for context\n", __func__);
750 alloc_status = 1; 747 alloc_status = 1;
751 goto alloc_status_switch; 748 goto alloc_status_switch;
752 } 749 }
@@ -828,13 +825,11 @@ static int imon_probe(struct usb_interface *interface,
828 825
829 driver = kzalloc(sizeof(struct lirc_driver), GFP_KERNEL); 826 driver = kzalloc(sizeof(struct lirc_driver), GFP_KERNEL);
830 if (!driver) { 827 if (!driver) {
831 dev_err(dev, "%s: kzalloc failed for lirc_driver\n", __func__);
832 alloc_status = 2; 828 alloc_status = 2;
833 goto alloc_status_switch; 829 goto alloc_status_switch;
834 } 830 }
835 rbuf = kmalloc(sizeof(struct lirc_buffer), GFP_KERNEL); 831 rbuf = kmalloc(sizeof(struct lirc_buffer), GFP_KERNEL);
836 if (!rbuf) { 832 if (!rbuf) {
837 dev_err(dev, "%s: kmalloc failed for lirc_buffer\n", __func__);
838 alloc_status = 3; 833 alloc_status = 3;
839 goto alloc_status_switch; 834 goto alloc_status_switch;
840 } 835 }
@@ -1009,8 +1004,8 @@ static void imon_disconnect(struct usb_interface *interface)
1009 1004
1010 mutex_unlock(&driver_lock); 1005 mutex_unlock(&driver_lock);
1011 1006
1012 printk(KERN_INFO "%s: iMON device (intf%d) disconnected\n", 1007 dev_info(&interface->dev, "%s: iMON device (intf%d) disconnected\n",
1013 __func__, ifnum); 1008 __func__, ifnum);
1014} 1009}
1015 1010
1016static int imon_suspend(struct usb_interface *intf, pm_message_t message) 1011static int imon_suspend(struct usb_interface *intf, pm_message_t message)
diff --git a/drivers/staging/media/lirc/lirc_parallel.c b/drivers/staging/media/lirc/lirc_parallel.c
index ec14bc81851b..41d110f8bc02 100644
--- a/drivers/staging/media/lirc/lirc_parallel.c
+++ b/drivers/staging/media/lirc/lirc_parallel.c
@@ -22,6 +22,8 @@
22 * 22 *
23 */ 23 */
24 24
25#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
26
25/*** Includes ***/ 27/*** Includes ***/
26 28
27#include <linux/module.h> 29#include <linux/module.h>
@@ -115,8 +117,7 @@ static void out(int offset, int value)
115 parport_write_control(pport, value); 117 parport_write_control(pport, value);
116 break; 118 break;
117 case LIRC_LP_STATUS: 119 case LIRC_LP_STATUS:
118 printk(KERN_INFO "%s: attempt to write to status register\n", 120 pr_info("attempt to write to status register\n");
119 LIRC_DRIVER_NAME);
120 break; 121 break;
121 } 122 }
122} 123}
@@ -166,27 +167,23 @@ static unsigned int init_lirc_timer(void)
166 if (default_timer == 0) { 167 if (default_timer == 0) {
167 /* autodetect timer */ 168 /* autodetect timer */
168 newtimer = (1000000*count)/timeelapsed; 169 newtimer = (1000000*count)/timeelapsed;
169 printk(KERN_INFO "%s: %u Hz timer detected\n", 170 pr_info("%u Hz timer detected\n", newtimer);
170 LIRC_DRIVER_NAME, newtimer);
171 return newtimer; 171 return newtimer;
172 } else { 172 } else {
173 newtimer = (1000000*count)/timeelapsed; 173 newtimer = (1000000*count)/timeelapsed;
174 if (abs(newtimer - default_timer) > default_timer/10) { 174 if (abs(newtimer - default_timer) > default_timer/10) {
175 /* bad timer */ 175 /* bad timer */
176 printk(KERN_NOTICE "%s: bad timer: %u Hz\n", 176 pr_notice("bad timer: %u Hz\n", newtimer);
177 LIRC_DRIVER_NAME, newtimer); 177 pr_notice("using default timer: %u Hz\n",
178 printk(KERN_NOTICE "%s: using default timer: " 178 default_timer);
179 "%u Hz\n",
180 LIRC_DRIVER_NAME, default_timer);
181 return default_timer; 179 return default_timer;
182 } else { 180 } else {
183 printk(KERN_INFO "%s: %u Hz timer detected\n", 181 pr_info("%u Hz timer detected\n", newtimer);
184 LIRC_DRIVER_NAME, newtimer);
185 return newtimer; /* use detected value */ 182 return newtimer; /* use detected value */
186 } 183 }
187 } 184 }
188 } else { 185 } else {
189 printk(KERN_NOTICE "%s: no timer detected\n", LIRC_DRIVER_NAME); 186 pr_notice("no timer detected\n");
190 return 0; 187 return 0;
191 } 188 }
192} 189}
@@ -194,13 +191,10 @@ static unsigned int init_lirc_timer(void)
194static int lirc_claim(void) 191static int lirc_claim(void)
195{ 192{
196 if (parport_claim(ppdevice) != 0) { 193 if (parport_claim(ppdevice) != 0) {
197 printk(KERN_WARNING "%s: could not claim port\n", 194 pr_warn("could not claim port\n");
198 LIRC_DRIVER_NAME); 195 pr_warn("waiting for port becoming available\n");
199 printk(KERN_WARNING "%s: waiting for port becoming available"
200 "\n", LIRC_DRIVER_NAME);
201 if (parport_claim_or_block(ppdevice) < 0) { 196 if (parport_claim_or_block(ppdevice) < 0) {
202 printk(KERN_NOTICE "%s: could not claim port, giving" 197 pr_notice("could not claim port, giving up\n");
203 " up\n", LIRC_DRIVER_NAME);
204 return 0; 198 return 0;
205 } 199 }
206 } 200 }
@@ -219,7 +213,7 @@ static void rbuf_write(int signal)
219 if (nwptr == rptr) { 213 if (nwptr == rptr) {
220 /* no new signals will be accepted */ 214 /* no new signals will be accepted */
221 lost_irqs++; 215 lost_irqs++;
222 printk(KERN_NOTICE "%s: buffer overrun\n", LIRC_DRIVER_NAME); 216 pr_notice("buffer overrun\n");
223 return; 217 return;
224 } 218 }
225 rbuf[wptr] = signal; 219 rbuf[wptr] = signal;
@@ -290,7 +284,7 @@ static void irq_handler(void *blah)
290 if (signal > timeout 284 if (signal > timeout
291 || (check_pselecd && (in(1) & LP_PSELECD))) { 285 || (check_pselecd && (in(1) & LP_PSELECD))) {
292 signal = 0; 286 signal = 0;
293 printk(KERN_NOTICE "%s: timeout\n", LIRC_DRIVER_NAME); 287 pr_notice("timeout\n");
294 break; 288 break;
295 } 289 }
296 } while (lirc_get_signal()); 290 } while (lirc_get_signal());
@@ -644,8 +638,7 @@ static int __init lirc_parallel_init(void)
644 638
645 result = platform_driver_register(&lirc_parallel_driver); 639 result = platform_driver_register(&lirc_parallel_driver);
646 if (result) { 640 if (result) {
647 printk(KERN_NOTICE "platform_driver_register" 641 pr_notice("platform_driver_register returned %d\n", result);
648 " returned %d\n", result);
649 return result; 642 return result;
650 } 643 }
651 644
@@ -661,8 +654,7 @@ static int __init lirc_parallel_init(void)
661 654
662 pport = parport_find_base(io); 655 pport = parport_find_base(io);
663 if (pport == NULL) { 656 if (pport == NULL) {
664 printk(KERN_NOTICE "%s: no port at %x found\n", 657 pr_notice("no port at %x found\n", io);
665 LIRC_DRIVER_NAME, io);
666 result = -ENXIO; 658 result = -ENXIO;
667 goto exit_device_put; 659 goto exit_device_put;
668 } 660 }
@@ -670,8 +662,7 @@ static int __init lirc_parallel_init(void)
670 pf, kf, irq_handler, 0, NULL); 662 pf, kf, irq_handler, 0, NULL);
671 parport_put_port(pport); 663 parport_put_port(pport);
672 if (ppdevice == NULL) { 664 if (ppdevice == NULL) {
673 printk(KERN_NOTICE "%s: parport_register_device() failed\n", 665 pr_notice("parport_register_device() failed\n");
674 LIRC_DRIVER_NAME);
675 result = -ENXIO; 666 result = -ENXIO;
676 goto exit_device_put; 667 goto exit_device_put;
677 } 668 }
@@ -706,14 +697,12 @@ static int __init lirc_parallel_init(void)
706 driver.dev = &lirc_parallel_dev->dev; 697 driver.dev = &lirc_parallel_dev->dev;
707 driver.minor = lirc_register_driver(&driver); 698 driver.minor = lirc_register_driver(&driver);
708 if (driver.minor < 0) { 699 if (driver.minor < 0) {
709 printk(KERN_NOTICE "%s: register_chrdev() failed\n", 700 pr_notice("register_chrdev() failed\n");
710 LIRC_DRIVER_NAME);
711 parport_unregister_device(ppdevice); 701 parport_unregister_device(ppdevice);
712 result = -EIO; 702 result = -EIO;
713 goto exit_device_put; 703 goto exit_device_put;
714 } 704 }
715 printk(KERN_INFO "%s: installed using port 0x%04x irq %d\n", 705 pr_info("installed using port 0x%04x irq %d\n", io, irq);
716 LIRC_DRIVER_NAME, io, irq);
717 return 0; 706 return 0;
718 707
719exit_device_put: 708exit_device_put:
diff --git a/drivers/staging/media/lirc/lirc_sasem.c b/drivers/staging/media/lirc/lirc_sasem.c
index f4e4d9003f38..68acca74ddb1 100644
--- a/drivers/staging/media/lirc/lirc_sasem.c
+++ b/drivers/staging/media/lirc/lirc_sasem.c
@@ -34,6 +34,8 @@
34 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 34 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35 */ 35 */
36 36
37#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
38
37#include <linux/errno.h> 39#include <linux/errno.h>
38#include <linux/init.h> 40#include <linux/init.h>
39#include <linux/kernel.h> 41#include <linux/kernel.h>
@@ -171,7 +173,7 @@ static void delete_context(struct sasem_context *context)
171 kfree(context); 173 kfree(context);
172 174
173 if (debug) 175 if (debug)
174 printk(KERN_INFO "%s: context deleted\n", __func__); 176 pr_info("%s: context deleted\n", __func__);
175} 177}
176 178
177static void deregister_from_lirc(struct sasem_context *context) 179static void deregister_from_lirc(struct sasem_context *context)
@@ -181,11 +183,10 @@ static void deregister_from_lirc(struct sasem_context *context)
181 183
182 retval = lirc_unregister_driver(minor); 184 retval = lirc_unregister_driver(minor);
183 if (retval) 185 if (retval)
184 printk(KERN_ERR "%s: unable to deregister from lirc (%d)\n", 186 pr_err("%s: unable to deregister from lirc (%d)\n",
185 __func__, retval); 187 __func__, retval);
186 else 188 else
187 printk(KERN_INFO "Deregistered Sasem driver (minor:%d)\n", 189 pr_info("Deregistered Sasem driver (minor:%d)\n", minor);
188 minor);
189 190
190} 191}
191 192
@@ -206,8 +207,7 @@ static int vfd_open(struct inode *inode, struct file *file)
206 subminor = iminor(inode); 207 subminor = iminor(inode);
207 interface = usb_find_interface(&sasem_driver, subminor); 208 interface = usb_find_interface(&sasem_driver, subminor);
208 if (!interface) { 209 if (!interface) {
209 printk(KERN_ERR KBUILD_MODNAME 210 pr_err("%s: could not find interface for minor %d\n",
210 ": %s: could not find interface for minor %d\n",
211 __func__, subminor); 211 __func__, subminor);
212 retval = -ENODEV; 212 retval = -ENODEV;
213 goto exit; 213 goto exit;
@@ -252,8 +252,7 @@ static long vfd_ioctl(struct file *file, unsigned cmd, unsigned long arg)
252 context = (struct sasem_context *) file->private_data; 252 context = (struct sasem_context *) file->private_data;
253 253
254 if (!context) { 254 if (!context) {
255 printk(KERN_ERR KBUILD_MODNAME 255 pr_err("%s: no context for device\n", __func__);
256 ": %s: no context for device\n", __func__);
257 return -ENODEV; 256 return -ENODEV;
258 } 257 }
259 258
@@ -266,7 +265,7 @@ static long vfd_ioctl(struct file *file, unsigned cmd, unsigned long arg)
266 context->vfd_contrast = (unsigned int)arg; 265 context->vfd_contrast = (unsigned int)arg;
267 break; 266 break;
268 default: 267 default:
269 printk(KERN_INFO "Unknown IOCTL command\n"); 268 pr_info("Unknown IOCTL command\n");
270 mutex_unlock(&context->ctx_lock); 269 mutex_unlock(&context->ctx_lock);
271 return -ENOIOCTLCMD; /* not supported */ 270 return -ENOIOCTLCMD; /* not supported */
272 } 271 }
@@ -287,8 +286,7 @@ static int vfd_close(struct inode *inode, struct file *file)
287 context = (struct sasem_context *) file->private_data; 286 context = (struct sasem_context *) file->private_data;
288 287
289 if (!context) { 288 if (!context) {
290 printk(KERN_ERR KBUILD_MODNAME 289 pr_err("%s: no context for device\n", __func__);
291 ": %s: no context for device\n", __func__);
292 return -ENODEV; 290 return -ENODEV;
293 } 291 }
294 292
@@ -299,7 +297,7 @@ static int vfd_close(struct inode *inode, struct file *file)
299 retval = -EIO; 297 retval = -EIO;
300 } else { 298 } else {
301 context->vfd_isopen = 0; 299 context->vfd_isopen = 0;
302 printk(KERN_INFO "VFD port closed\n"); 300 dev_info(&context->dev->dev, "VFD port closed\n");
303 if (!context->dev_present && !context->ir_isopen) { 301 if (!context->dev_present && !context->ir_isopen) {
304 302
305 /* Device disconnected before close and IR port is 303 /* Device disconnected before close and IR port is
@@ -373,16 +371,14 @@ static ssize_t vfd_write(struct file *file, const char *buf,
373 371
374 context = (struct sasem_context *) file->private_data; 372 context = (struct sasem_context *) file->private_data;
375 if (!context) { 373 if (!context) {
376 printk(KERN_ERR KBUILD_MODNAME 374 pr_err("%s: no context for device\n", __func__);
377 ": %s: no context for device\n", __func__);
378 return -ENODEV; 375 return -ENODEV;
379 } 376 }
380 377
381 mutex_lock(&context->ctx_lock); 378 mutex_lock(&context->ctx_lock);
382 379
383 if (!context->dev_present) { 380 if (!context->dev_present) {
384 printk(KERN_ERR KBUILD_MODNAME 381 pr_err("%s: no Sasem device present\n", __func__);
385 ": %s: no Sasem device present\n", __func__);
386 retval = -ENODEV; 382 retval = -ENODEV;
387 goto exit; 383 goto exit;
388 } 384 }
@@ -519,7 +515,7 @@ static int ir_open(void *data)
519 __func__, retval); 515 __func__, retval);
520 else { 516 else {
521 context->ir_isopen = 1; 517 context->ir_isopen = 1;
522 printk(KERN_INFO "IR port opened\n"); 518 dev_info(&context->dev->dev, "IR port opened\n");
523 } 519 }
524 520
525exit: 521exit:
@@ -538,8 +534,7 @@ static void ir_close(void *data)
538 534
539 context = (struct sasem_context *)data; 535 context = (struct sasem_context *)data;
540 if (!context) { 536 if (!context) {
541 printk(KERN_ERR KBUILD_MODNAME 537 pr_err("%s: no context for device\n", __func__);
542 ": %s: no context for device\n", __func__);
543 return; 538 return;
544 } 539 }
545 540
@@ -547,7 +542,7 @@ static void ir_close(void *data)
547 542
548 usb_kill_urb(context->rx_urb); 543 usb_kill_urb(context->rx_urb);
549 context->ir_isopen = 0; 544 context->ir_isopen = 0;
550 printk(KERN_INFO "IR port closed\n"); 545 pr_info("IR port closed\n");
551 546
552 if (!context->dev_present) { 547 if (!context->dev_present) {
553 548
@@ -584,8 +579,9 @@ static void incoming_packet(struct sasem_context *context,
584 int i; 579 int i;
585 580
586 if (len != 8) { 581 if (len != 8) {
587 printk(KERN_WARNING "%s: invalid incoming packet size (%d)\n", 582 dev_warn(&context->dev->dev,
588 __func__, len); 583 "%s: invalid incoming packet size (%d)\n",
584 __func__, len);
589 return; 585 return;
590 } 586 }
591 587
@@ -663,7 +659,7 @@ static void usb_rx_callback(struct urb *urb)
663 break; 659 break;
664 660
665 default: 661 default:
666 printk(KERN_WARNING "%s: status (%d): ignored", 662 dev_warn(&urb->dev->dev, "%s: status (%d): ignored",
667 __func__, urb->status); 663 __func__, urb->status);
668 break; 664 break;
669 } 665 }
@@ -763,22 +759,16 @@ static int sasem_probe(struct usb_interface *interface,
763 759
764 context = kzalloc(sizeof(struct sasem_context), GFP_KERNEL); 760 context = kzalloc(sizeof(struct sasem_context), GFP_KERNEL);
765 if (!context) { 761 if (!context) {
766 dev_err(&interface->dev,
767 "%s: kzalloc failed for context\n", __func__);
768 alloc_status = 1; 762 alloc_status = 1;
769 goto alloc_status_switch; 763 goto alloc_status_switch;
770 } 764 }
771 driver = kzalloc(sizeof(struct lirc_driver), GFP_KERNEL); 765 driver = kzalloc(sizeof(struct lirc_driver), GFP_KERNEL);
772 if (!driver) { 766 if (!driver) {
773 dev_err(&interface->dev,
774 "%s: kzalloc failed for lirc_driver\n", __func__);
775 alloc_status = 2; 767 alloc_status = 2;
776 goto alloc_status_switch; 768 goto alloc_status_switch;
777 } 769 }
778 rbuf = kmalloc(sizeof(struct lirc_buffer), GFP_KERNEL); 770 rbuf = kmalloc(sizeof(struct lirc_buffer), GFP_KERNEL);
779 if (!rbuf) { 771 if (!rbuf) {
780 dev_err(&interface->dev,
781 "%s: kmalloc failed for lirc_buffer\n", __func__);
782 alloc_status = 3; 772 alloc_status = 3;
783 goto alloc_status_switch; 773 goto alloc_status_switch;
784 } 774 }
@@ -830,8 +820,9 @@ static int sasem_probe(struct usb_interface *interface,
830 retval = lirc_minor; 820 retval = lirc_minor;
831 goto unlock; 821 goto unlock;
832 } else 822 } else
833 printk(KERN_INFO "%s: Registered Sasem driver (minor:%d)\n", 823 dev_info(&interface->dev,
834 __func__, lirc_minor); 824 "%s: Registered Sasem driver (minor:%d)\n",
825 __func__, lirc_minor);
835 826
836 /* Needed while unregistering! */ 827 /* Needed while unregistering! */
837 driver->minor = lirc_minor; 828 driver->minor = lirc_minor;
@@ -852,15 +843,18 @@ static int sasem_probe(struct usb_interface *interface,
852 if (vfd_ep_found) { 843 if (vfd_ep_found) {
853 844
854 if (debug) 845 if (debug)
855 printk(KERN_INFO "Registering VFD with sysfs\n"); 846 dev_info(&interface->dev,
847 "Registering VFD with sysfs\n");
856 if (usb_register_dev(interface, &sasem_class)) 848 if (usb_register_dev(interface, &sasem_class))
857 /* Not a fatal error, so ignore */ 849 /* Not a fatal error, so ignore */
858 printk(KERN_INFO "%s: could not get a minor number " 850 dev_info(&interface->dev,
859 "for VFD\n", __func__); 851 "%s: could not get a minor number for VFD\n",
852 __func__);
860 } 853 }
861 854
862 printk(KERN_INFO "%s: Sasem device on usb<%d:%d> initialized\n", 855 dev_info(&interface->dev,
863 __func__, dev->bus->busnum, dev->devnum); 856 "%s: Sasem device on usb<%d:%d> initialized\n",
857 __func__, dev->bus->busnum, dev->devnum);
864unlock: 858unlock:
865 mutex_unlock(&context->ctx_lock); 859 mutex_unlock(&context->ctx_lock);
866 860
@@ -891,7 +885,7 @@ exit:
891} 885}
892 886
893/** 887/**
894 * Callback function for USB core API: disonnect 888 * Callback function for USB core API: disconnect
895 */ 889 */
896static void sasem_disconnect(struct usb_interface *interface) 890static void sasem_disconnect(struct usb_interface *interface)
897{ 891{
@@ -903,7 +897,8 @@ static void sasem_disconnect(struct usb_interface *interface)
903 context = usb_get_intfdata(interface); 897 context = usb_get_intfdata(interface);
904 mutex_lock(&context->ctx_lock); 898 mutex_lock(&context->ctx_lock);
905 899
906 printk(KERN_INFO "%s: Sasem device disconnected\n", __func__); 900 dev_info(&interface->dev, "%s: Sasem device disconnected\n",
901 __func__);
907 902
908 usb_set_intfdata(interface, NULL); 903 usb_set_intfdata(interface, NULL);
909 context->dev_present = 0; 904 context->dev_present = 0;
diff --git a/drivers/staging/media/lirc/lirc_serial.c b/drivers/staging/media/lirc/lirc_serial.c
index b5d0088f3102..af08e677b60f 100644
--- a/drivers/staging/media/lirc/lirc_serial.c
+++ b/drivers/staging/media/lirc/lirc_serial.c
@@ -48,6 +48,8 @@
48 * Steve Davies <steve@daviesfam.org> July 2001 48 * Steve Davies <steve@daviesfam.org> July 2001
49 */ 49 */
50 50
51#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
52
51#include <linux/module.h> 53#include <linux/module.h>
52#include <linux/errno.h> 54#include <linux/errno.h>
53#include <linux/signal.h> 55#include <linux/signal.h>
@@ -667,8 +669,7 @@ static irqreturn_t irq_handler(int i, void *blah)
667 counter++; 669 counter++;
668 status = sinp(UART_MSR); 670 status = sinp(UART_MSR);
669 if (counter > RS_ISR_PASS_LIMIT) { 671 if (counter > RS_ISR_PASS_LIMIT) {
670 printk(KERN_WARNING LIRC_DRIVER_NAME ": AIEEEE: " 672 pr_warn("AIEEEE: We're caught!\n");
671 "We're caught!\n");
672 break; 673 break;
673 } 674 }
674 if ((status & hardware[type].signal_pin_change) 675 if ((status & hardware[type].signal_pin_change)
@@ -703,11 +704,10 @@ static irqreturn_t irq_handler(int i, void *blah)
703 dcd = (status & hardware[type].signal_pin) ? 1 : 0; 704 dcd = (status & hardware[type].signal_pin) ? 1 : 0;
704 705
705 if (dcd == last_dcd) { 706 if (dcd == last_dcd) {
706 printk(KERN_WARNING LIRC_DRIVER_NAME 707 pr_warn("ignoring spike: %d %d %lx %lx %lx %lx\n",
707 ": ignoring spike: %d %d %lx %lx %lx %lx\n", 708 dcd, sense,
708 dcd, sense, 709 tv.tv_sec, lasttv.tv_sec,
709 tv.tv_sec, lasttv.tv_sec, 710 tv.tv_usec, lasttv.tv_usec);
710 tv.tv_usec, lasttv.tv_usec);
711 continue; 711 continue;
712 } 712 }
713 713
@@ -715,25 +715,20 @@ static irqreturn_t irq_handler(int i, void *blah)
715 if (tv.tv_sec < lasttv.tv_sec || 715 if (tv.tv_sec < lasttv.tv_sec ||
716 (tv.tv_sec == lasttv.tv_sec && 716 (tv.tv_sec == lasttv.tv_sec &&
717 tv.tv_usec < lasttv.tv_usec)) { 717 tv.tv_usec < lasttv.tv_usec)) {
718 printk(KERN_WARNING LIRC_DRIVER_NAME 718 pr_warn("AIEEEE: your clock just jumped backwards\n");
719 ": AIEEEE: your clock just jumped " 719 pr_warn("%d %d %lx %lx %lx %lx\n",
720 "backwards\n"); 720 dcd, sense,
721 printk(KERN_WARNING LIRC_DRIVER_NAME 721 tv.tv_sec, lasttv.tv_sec,
722 ": %d %d %lx %lx %lx %lx\n", 722 tv.tv_usec, lasttv.tv_usec);
723 dcd, sense,
724 tv.tv_sec, lasttv.tv_sec,
725 tv.tv_usec, lasttv.tv_usec);
726 data = PULSE_MASK; 723 data = PULSE_MASK;
727 } else if (deltv > 15) { 724 } else if (deltv > 15) {
728 data = PULSE_MASK; /* really long time */ 725 data = PULSE_MASK; /* really long time */
729 if (!(dcd^sense)) { 726 if (!(dcd^sense)) {
730 /* sanity check */ 727 /* sanity check */
731 printk(KERN_WARNING LIRC_DRIVER_NAME 728 pr_warn("AIEEEE: %d %d %lx %lx %lx %lx\n",
732 ": AIEEEE: " 729 dcd, sense,
733 "%d %d %lx %lx %lx %lx\n", 730 tv.tv_sec, lasttv.tv_sec,
734 dcd, sense, 731 tv.tv_usec, lasttv.tv_usec);
735 tv.tv_sec, lasttv.tv_sec,
736 tv.tv_usec, lasttv.tv_usec);
737 /* 732 /*
738 * detecting pulse while this 733 * detecting pulse while this
739 * MUST be a space! 734 * MUST be a space!
@@ -776,8 +771,7 @@ static int hardware_init_port(void)
776 soutp(UART_IER, scratch); 771 soutp(UART_IER, scratch);
777 if (scratch2 != 0 || scratch3 != 0x0f) { 772 if (scratch2 != 0 || scratch3 != 0x0f) {
778 /* we fail, there's nothing here */ 773 /* we fail, there's nothing here */
779 printk(KERN_ERR LIRC_DRIVER_NAME ": port existence test " 774 pr_err("port existence test failed, cannot continue\n");
780 "failed, cannot continue\n");
781 return -ENODEV; 775 return -ENODEV;
782 } 776 }
783 777
@@ -850,11 +844,9 @@ static int lirc_serial_probe(struct platform_device *dev)
850 LIRC_DRIVER_NAME, (void *)&hardware); 844 LIRC_DRIVER_NAME, (void *)&hardware);
851 if (result < 0) { 845 if (result < 0) {
852 if (result == -EBUSY) 846 if (result == -EBUSY)
853 printk(KERN_ERR LIRC_DRIVER_NAME ": IRQ %d busy\n", 847 dev_err(&dev->dev, "IRQ %d busy\n", irq);
854 irq);
855 else if (result == -EINVAL) 848 else if (result == -EINVAL)
856 printk(KERN_ERR LIRC_DRIVER_NAME 849 dev_err(&dev->dev, "Bad irq number or handler\n");
857 ": Bad irq number or handler\n");
858 return result; 850 return result;
859 } 851 }
860 852
@@ -869,14 +861,11 @@ static int lirc_serial_probe(struct platform_device *dev)
869 LIRC_DRIVER_NAME) == NULL)) 861 LIRC_DRIVER_NAME) == NULL))
870 || ((iommap == 0) 862 || ((iommap == 0)
871 && (request_region(io, 8, LIRC_DRIVER_NAME) == NULL))) { 863 && (request_region(io, 8, LIRC_DRIVER_NAME) == NULL))) {
872 printk(KERN_ERR LIRC_DRIVER_NAME 864 dev_err(&dev->dev, "port %04x already in use\n", io);
873 ": port %04x already in use\n", io); 865 dev_warn(&dev->dev, "use 'setserial /dev/ttySX uart none'\n");
874 printk(KERN_WARNING LIRC_DRIVER_NAME 866 dev_warn(&dev->dev,
875 ": use 'setserial /dev/ttySX uart none'\n"); 867 "or compile the serial port driver as module and\n");
876 printk(KERN_WARNING LIRC_DRIVER_NAME 868 dev_warn(&dev->dev, "make sure this module is loaded first\n");
877 ": or compile the serial port driver as module and\n");
878 printk(KERN_WARNING LIRC_DRIVER_NAME
879 ": make sure this module is loaded first\n");
880 result = -EBUSY; 869 result = -EBUSY;
881 goto exit_free_irq; 870 goto exit_free_irq;
882 } 871 }
@@ -907,11 +896,11 @@ static int lirc_serial_probe(struct platform_device *dev)
907 msleep(40); 896 msleep(40);
908 } 897 }
909 sense = (nlow >= nhigh ? 1 : 0); 898 sense = (nlow >= nhigh ? 1 : 0);
910 printk(KERN_INFO LIRC_DRIVER_NAME ": auto-detected active " 899 dev_info(&dev->dev, "auto-detected active %s receiver\n",
911 "%s receiver\n", sense ? "low" : "high"); 900 sense ? "low" : "high");
912 } else 901 } else
913 printk(KERN_INFO LIRC_DRIVER_NAME ": Manually using active " 902 dev_info(&dev->dev, "Manually using active %s receiver\n",
914 "%s receiver\n", sense ? "low" : "high"); 903 sense ? "low" : "high");
915 904
916 dprintk("Interrupt %d, port %04x obtained\n", irq, io); 905 dprintk("Interrupt %d, port %04x obtained\n", irq, io);
917 return 0; 906 return 0;
@@ -1251,8 +1240,7 @@ static int __init lirc_serial_init_module(void)
1251 driver.dev = &lirc_serial_dev->dev; 1240 driver.dev = &lirc_serial_dev->dev;
1252 driver.minor = lirc_register_driver(&driver); 1241 driver.minor = lirc_register_driver(&driver);
1253 if (driver.minor < 0) { 1242 if (driver.minor < 0) {
1254 printk(KERN_ERR LIRC_DRIVER_NAME 1243 pr_err("register_chrdev failed!\n");
1255 ": register_chrdev failed!\n");
1256 lirc_serial_exit(); 1244 lirc_serial_exit();
1257 return driver.minor; 1245 return driver.minor;
1258 } 1246 }
diff --git a/drivers/staging/media/lirc/lirc_sir.c b/drivers/staging/media/lirc/lirc_sir.c
index a45799874a21..63a554c36f75 100644
--- a/drivers/staging/media/lirc/lirc_sir.c
+++ b/drivers/staging/media/lirc/lirc_sir.c
@@ -33,6 +33,8 @@
33 * parts cut'n'pasted from sa1100_ir.c (C) 2000 Russell King 33 * parts cut'n'pasted from sa1100_ir.c (C) 2000 Russell King
34 */ 34 */
35 35
36#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
37
36#include <linux/module.h> 38#include <linux/module.h>
37#include <linux/sched.h> 39#include <linux/sched.h>
38#include <linux/errno.h> 40#include <linux/errno.h>
@@ -495,7 +497,7 @@ static int init_chrdev(void)
495 driver.dev = &lirc_sir_dev->dev; 497 driver.dev = &lirc_sir_dev->dev;
496 driver.minor = lirc_register_driver(&driver); 498 driver.minor = lirc_register_driver(&driver);
497 if (driver.minor < 0) { 499 if (driver.minor < 0) {
498 printk(KERN_ERR LIRC_DRIVER_NAME ": init_chrdev() failed.\n"); 500 pr_err("init_chrdev() failed.\n");
499 return -EIO; 501 return -EIO;
500 } 502 }
501 return 0; 503 return 0;
@@ -604,7 +606,7 @@ static irqreturn_t sir_interrupt(int irq, void *dev_id)
604 } 606 }
605 607
606 if (status & UTSR0_TFS) 608 if (status & UTSR0_TFS)
607 printk(KERN_ERR "transmit fifo not full, shouldn't happen\n"); 609 pr_err("transmit fifo not full, shouldn't happen\n");
608 610
609 /* We must clear certain bits. */ 611 /* We must clear certain bits. */
610 status &= (UTSR0_RID | UTSR0_RBB | UTSR0_REB); 612 status &= (UTSR0_RID | UTSR0_RBB | UTSR0_REB);
@@ -787,7 +789,7 @@ static int init_hardware(void)
787#ifdef LIRC_ON_SA1100 789#ifdef LIRC_ON_SA1100
788#ifdef CONFIG_SA1100_BITSY 790#ifdef CONFIG_SA1100_BITSY
789 if (machine_is_bitsy()) { 791 if (machine_is_bitsy()) {
790 printk(KERN_INFO "Power on IR module\n"); 792 pr_info("Power on IR module\n");
791 set_bitsy_egpio(EGPIO_BITSY_IR_ON); 793 set_bitsy_egpio(EGPIO_BITSY_IR_ON);
792 } 794 }
793#endif 795#endif
@@ -885,8 +887,7 @@ static int init_hardware(void)
885 udelay(1500); 887 udelay(1500);
886 888
887 /* read previous control byte */ 889 /* read previous control byte */
888 printk(KERN_INFO LIRC_DRIVER_NAME 890 pr_info("0x%02x\n", sinp(UART_RX));
889 ": 0x%02x\n", sinp(UART_RX));
890 891
891 /* Set DLAB 1. */ 892 /* Set DLAB 1. */
892 soutp(UART_LCR, sinp(UART_LCR) | UART_LCR_DLAB); 893 soutp(UART_LCR, sinp(UART_LCR) | UART_LCR_DLAB);
@@ -964,8 +965,7 @@ static int init_port(void)
964 /* get I/O port access and IRQ line */ 965 /* get I/O port access and IRQ line */
965#ifndef LIRC_ON_SA1100 966#ifndef LIRC_ON_SA1100
966 if (request_region(io, 8, LIRC_DRIVER_NAME) == NULL) { 967 if (request_region(io, 8, LIRC_DRIVER_NAME) == NULL) {
967 printk(KERN_ERR LIRC_DRIVER_NAME 968 pr_err("i/o port 0x%.4x already in use.\n", io);
968 ": i/o port 0x%.4x already in use.\n", io);
969 return -EBUSY; 969 return -EBUSY;
970 } 970 }
971#endif 971#endif
@@ -975,15 +975,11 @@ static int init_port(void)
975# ifndef LIRC_ON_SA1100 975# ifndef LIRC_ON_SA1100
976 release_region(io, 8); 976 release_region(io, 8);
977# endif 977# endif
978 printk(KERN_ERR LIRC_DRIVER_NAME 978 pr_err("IRQ %d already in use.\n", irq);
979 ": IRQ %d already in use.\n",
980 irq);
981 return retval; 979 return retval;
982 } 980 }
983#ifndef LIRC_ON_SA1100 981#ifndef LIRC_ON_SA1100
984 printk(KERN_INFO LIRC_DRIVER_NAME 982 pr_info("I/O port 0x%.4x, IRQ %d.\n", io, irq);
985 ": I/O port 0x%.4x, IRQ %d.\n",
986 io, irq);
987#endif 983#endif
988 984
989 init_timer(&timerlist); 985 init_timer(&timerlist);
@@ -1213,8 +1209,7 @@ static int init_lirc_sir(void)
1213 if (retval < 0) 1209 if (retval < 0)
1214 return retval; 1210 return retval;
1215 init_hardware(); 1211 init_hardware();
1216 printk(KERN_INFO LIRC_DRIVER_NAME 1212 pr_info("Installed.\n");
1217 ": Installed.\n");
1218 return 0; 1213 return 0;
1219} 1214}
1220 1215
@@ -1243,23 +1238,20 @@ static int __init lirc_sir_init(void)
1243 1238
1244 retval = platform_driver_register(&lirc_sir_driver); 1239 retval = platform_driver_register(&lirc_sir_driver);
1245 if (retval) { 1240 if (retval) {
1246 printk(KERN_ERR LIRC_DRIVER_NAME ": Platform driver register " 1241 pr_err("Platform driver register failed!\n");
1247 "failed!\n");
1248 return -ENODEV; 1242 return -ENODEV;
1249 } 1243 }
1250 1244
1251 lirc_sir_dev = platform_device_alloc("lirc_dev", 0); 1245 lirc_sir_dev = platform_device_alloc("lirc_dev", 0);
1252 if (!lirc_sir_dev) { 1246 if (!lirc_sir_dev) {
1253 printk(KERN_ERR LIRC_DRIVER_NAME ": Platform device alloc " 1247 pr_err("Platform device alloc failed!\n");
1254 "failed!\n");
1255 retval = -ENOMEM; 1248 retval = -ENOMEM;
1256 goto pdev_alloc_fail; 1249 goto pdev_alloc_fail;
1257 } 1250 }
1258 1251
1259 retval = platform_device_add(lirc_sir_dev); 1252 retval = platform_device_add(lirc_sir_dev);
1260 if (retval) { 1253 if (retval) {
1261 printk(KERN_ERR LIRC_DRIVER_NAME ": Platform device add " 1254 pr_err("Platform device add failed!\n");
1262 "failed!\n");
1263 retval = -ENODEV; 1255 retval = -ENODEV;
1264 goto pdev_add_fail; 1256 goto pdev_add_fail;
1265 } 1257 }
@@ -1292,7 +1284,7 @@ static void __exit lirc_sir_exit(void)
1292 drop_port(); 1284 drop_port();
1293 platform_device_unregister(lirc_sir_dev); 1285 platform_device_unregister(lirc_sir_dev);
1294 platform_driver_unregister(&lirc_sir_driver); 1286 platform_driver_unregister(&lirc_sir_driver);
1295 printk(KERN_INFO LIRC_DRIVER_NAME ": Uninstalled.\n"); 1287 pr_info("Uninstalled.\n");
1296} 1288}
1297 1289
1298module_init(lirc_sir_init); 1290module_init(lirc_sir_init);
diff --git a/drivers/staging/media/solo6x10/p2m.c b/drivers/staging/media/solo6x10/p2m.c
index 56210f0fc5ec..58ab61b1f1d9 100644
--- a/drivers/staging/media/solo6x10/p2m.c
+++ b/drivers/staging/media/solo6x10/p2m.c
@@ -231,15 +231,15 @@ static void run_p2m_test(struct solo_dev *solo_dev)
231 u32 size = SOLO_JPEG_EXT_ADDR(solo_dev) + SOLO_JPEG_EXT_SIZE(solo_dev); 231 u32 size = SOLO_JPEG_EXT_ADDR(solo_dev) + SOLO_JPEG_EXT_SIZE(solo_dev);
232 int i, d; 232 int i, d;
233 233
234 printk(KERN_WARNING "%s: Testing %u bytes of external ram\n", 234 dev_warn(&solo_dev->pdev->dev, "Testing %u bytes of external ram\n",
235 SOLO6X10_NAME, size); 235 size);
236 236
237 for (i = 0; i < size; i += TEST_CHUNK_SIZE) 237 for (i = 0; i < size; i += TEST_CHUNK_SIZE)
238 for (d = 0; d < 4; d++) 238 for (d = 0; d < 4; d++)
239 errs += p2m_test(solo_dev, d, i, TEST_CHUNK_SIZE); 239 errs += p2m_test(solo_dev, d, i, TEST_CHUNK_SIZE);
240 240
241 printk(KERN_WARNING "%s: Found %llu errors during p2m test\n", 241 dev_warn(&solo_dev->pdev->dev, "Found %llu errors during p2m test\n",
242 SOLO6X10_NAME, errs); 242 errs);
243 243
244 return; 244 return;
245} 245}
diff --git a/drivers/staging/media/solo6x10/v4l2-enc.c b/drivers/staging/media/solo6x10/v4l2-enc.c
index f8f0da952288..4977e869d5b7 100644
--- a/drivers/staging/media/solo6x10/v4l2-enc.c
+++ b/drivers/staging/media/solo6x10/v4l2-enc.c
@@ -1619,6 +1619,8 @@ static int solo_s_ext_ctrls(struct file *file, void *priv,
1619 solo_enc->osd_text[OSD_TEXT_MAX] = '\0'; 1619 solo_enc->osd_text[OSD_TEXT_MAX] = '\0';
1620 if (!err) 1620 if (!err)
1621 err = solo_osd_print(solo_enc); 1621 err = solo_osd_print(solo_enc);
1622 else
1623 err = -EFAULT;
1622 } 1624 }
1623 break; 1625 break;
1624 default: 1626 default:
@@ -1654,6 +1656,8 @@ static int solo_g_ext_ctrls(struct file *file, void *priv,
1654 err = copy_to_user(ctrl->string, 1656 err = copy_to_user(ctrl->string,
1655 solo_enc->osd_text, 1657 solo_enc->osd_text,
1656 OSD_TEXT_MAX); 1658 OSD_TEXT_MAX);
1659 if (err)
1660 err = -EFAULT;
1657 } 1661 }
1658 break; 1662 break;
1659 default: 1663 default:
diff --git a/drivers/staging/media/solo6x10/v4l2.c b/drivers/staging/media/solo6x10/v4l2.c
index 571c3a348d30..ca774cc57539 100644
--- a/drivers/staging/media/solo6x10/v4l2.c
+++ b/drivers/staging/media/solo6x10/v4l2.c
@@ -415,10 +415,7 @@ static int solo_start_thread(struct solo_filehandle *fh)
415{ 415{
416 fh->kthread = kthread_run(solo_thread, fh, SOLO6X10_NAME "_disp"); 416 fh->kthread = kthread_run(solo_thread, fh, SOLO6X10_NAME "_disp");
417 417
418 if (IS_ERR(fh->kthread)) 418 return PTR_RET(fh->kthread);
419 return PTR_ERR(fh->kthread);
420
421 return 0;
422} 419}
423 420
424static void solo_stop_thread(struct solo_filehandle *fh) 421static void solo_stop_thread(struct solo_filehandle *fh)
diff --git a/include/media/adv7343.h b/include/media/adv7343.h
index d6f8a4e1a1fc..944757be49bb 100644
--- a/include/media/adv7343.h
+++ b/include/media/adv7343.h
@@ -20,4 +20,56 @@
20#define ADV7343_COMPONENT_ID (1) 20#define ADV7343_COMPONENT_ID (1)
21#define ADV7343_SVIDEO_ID (2) 21#define ADV7343_SVIDEO_ID (2)
22 22
23/**
24 * adv7343_power_mode - power mode configuration.
25 * @sleep_mode: on enable the current consumption is reduced to micro ampere
26 * level. All DACs and the internal PLL circuit are disabled.
27 * Registers can be read from and written in sleep mode.
28 * @pll_control: PLL and oversampling control. This control allows internal
29 * PLL 1 circuit to be powered down and the oversampling to be
30 * switched off.
31 * @dac_1: power on/off DAC 1.
32 * @dac_2: power on/off DAC 2.
33 * @dac_3: power on/off DAC 3.
34 * @dac_4: power on/off DAC 4.
35 * @dac_5: power on/off DAC 5.
36 * @dac_6: power on/off DAC 6.
37 *
38 * Power mode register (Register 0x0), for more info refer REGISTER MAP ACCESS
39 * section of datasheet[1], table 17 page no 30.
40 *
41 * [1] http://www.analog.com/static/imported-files/data_sheets/ADV7342_7343.pdf
42 */
43struct adv7343_power_mode {
44 bool sleep_mode;
45 bool pll_control;
46 bool dac_1;
47 bool dac_2;
48 bool dac_3;
49 bool dac_4;
50 bool dac_5;
51 bool dac_6;
52};
53
54/**
55 * struct adv7343_sd_config - SD Only Output Configuration.
56 * @sd_dac_out1: Configure SD DAC Output 1.
57 * @sd_dac_out2: Configure SD DAC Output 2.
58 */
59struct adv7343_sd_config {
60 /* SD only Output Configuration */
61 bool sd_dac_out1;
62 bool sd_dac_out2;
63};
64
65/**
66 * struct adv7343_platform_data - Platform data values and access functions.
67 * @mode_config: Configuration for power mode.
68 * @sd_config: SD Only Configuration.
69 */
70struct adv7343_platform_data {
71 struct adv7343_power_mode mode_config;
72 struct adv7343_sd_config sd_config;
73};
74
23#endif /* End of #ifndef ADV7343_H */ 75#endif /* End of #ifndef ADV7343_H */
diff --git a/include/media/blackfin/bfin_capture.h b/include/media/blackfin/bfin_capture.h
index 2038a8a3f8aa..56b9ce4472fc 100644
--- a/include/media/blackfin/bfin_capture.h
+++ b/include/media/blackfin/bfin_capture.h
@@ -9,6 +9,7 @@ struct ppi_info;
9struct bcap_route { 9struct bcap_route {
10 u32 input; 10 u32 input;
11 u32 output; 11 u32 output;
12 u32 ppi_control;
12}; 13};
13 14
14struct bfin_capture_config { 15struct bfin_capture_config {
@@ -30,8 +31,8 @@ struct bfin_capture_config {
30 unsigned long ppi_control; 31 unsigned long ppi_control;
31 /* ppi interrupt mask */ 32 /* ppi interrupt mask */
32 u32 int_mask; 33 u32 int_mask;
33 /* horizontal blanking clocks */ 34 /* horizontal blanking pixels */
34 int blank_clocks; 35 int blank_pixels;
35}; 36};
36 37
37#endif 38#endif
diff --git a/include/media/blackfin/ppi.h b/include/media/blackfin/ppi.h
index 8f72f8a0b3d0..d0697f4edf87 100644
--- a/include/media/blackfin/ppi.h
+++ b/include/media/blackfin/ppi.h
@@ -21,22 +21,42 @@
21#define _PPI_H_ 21#define _PPI_H_
22 22
23#include <linux/interrupt.h> 23#include <linux/interrupt.h>
24#include <asm/blackfin.h>
25#include <asm/bfin_ppi.h>
24 26
27/* EPPI */
25#ifdef EPPI_EN 28#ifdef EPPI_EN
26#define PORT_EN EPPI_EN 29#define PORT_EN EPPI_EN
30#define PORT_DIR EPPI_DIR
27#define DMA32 0 31#define DMA32 0
28#define PACK_EN PACKEN 32#define PACK_EN PACKEN
29#endif 33#endif
30 34
35/* EPPI3 */
36#ifdef EPPI0_CTL2
37#define PORT_EN EPPI_CTL_EN
38#define PORT_DIR EPPI_CTL_DIR
39#define PACK_EN EPPI_CTL_PACKEN
40#define DMA32 0
41#define DLEN_8 EPPI_CTL_DLEN08
42#define DLEN_16 EPPI_CTL_DLEN16
43#endif
44
31struct ppi_if; 45struct ppi_if;
32 46
33struct ppi_params { 47struct ppi_params {
34 int width; 48 u32 width; /* width in pixels */
35 int height; 49 u32 height; /* height in lines */
36 int bpp; 50 u32 hdelay; /* delay after the HSYNC in pixels */
37 unsigned long ppi_control; 51 u32 vdelay; /* delay after the VSYNC in lines */
38 u32 int_mask; 52 u32 line; /* total pixels per line */
39 int blank_clocks; 53 u32 frame; /* total lines per frame */
54 u32 hsync; /* HSYNC length in pixels */
55 u32 vsync; /* VSYNC length in lines */
56 int bpp; /* bits per pixel */
57 int dlen; /* data length for ppi in bits */
58 u32 ppi_control; /* ppi configuration */
59 u32 int_mask; /* interrupt mask */
40}; 60};
41 61
42struct ppi_ops { 62struct ppi_ops {
@@ -51,6 +71,7 @@ struct ppi_ops {
51enum ppi_type { 71enum ppi_type {
52 PPI_TYPE_PPI, 72 PPI_TYPE_PPI,
53 PPI_TYPE_EPPI, 73 PPI_TYPE_EPPI,
74 PPI_TYPE_EPPI3,
54}; 75};
55 76
56struct ppi_info { 77struct ppi_info {
@@ -65,7 +86,8 @@ struct ppi_if {
65 unsigned long ppi_control; 86 unsigned long ppi_control;
66 const struct ppi_ops *ops; 87 const struct ppi_ops *ops;
67 const struct ppi_info *info; 88 const struct ppi_info *info;
68 bool err_int; 89 bool err_int; /* if we need request error interrupt */
90 bool err; /* if ppi has fifo error */
69 void *priv; 91 void *priv;
70}; 92};
71 93
diff --git a/include/media/davinci/vpbe_osd.h b/include/media/davinci/vpbe_osd.h
index 5ab0d8d41f68..42628fcfe1bd 100644
--- a/include/media/davinci/vpbe_osd.h
+++ b/include/media/davinci/vpbe_osd.h
@@ -26,7 +26,9 @@
26 26
27#include <media/davinci/vpbe_types.h> 27#include <media/davinci/vpbe_types.h>
28 28
29#define VPBE_OSD_SUBDEV_NAME "vpbe-osd" 29#define DM644X_VPBE_OSD_SUBDEV_NAME "dm644x,vpbe-osd"
30#define DM365_VPBE_OSD_SUBDEV_NAME "dm365,vpbe-osd"
31#define DM355_VPBE_OSD_SUBDEV_NAME "dm355,vpbe-osd"
30 32
31/** 33/**
32 * enum osd_layer 34 * enum osd_layer
@@ -387,7 +389,6 @@ struct osd_state {
387}; 389};
388 390
389struct osd_platform_data { 391struct osd_platform_data {
390 enum vpbe_version vpbe_type;
391 int field_inv_wa_enable; 392 int field_inv_wa_enable;
392}; 393};
393 394
diff --git a/include/media/davinci/vpbe_venc.h b/include/media/davinci/vpbe_venc.h
index cc78c2eb16da..476fafc2f522 100644
--- a/include/media/davinci/vpbe_venc.h
+++ b/include/media/davinci/vpbe_venc.h
@@ -20,7 +20,9 @@
20#include <media/v4l2-subdev.h> 20#include <media/v4l2-subdev.h>
21#include <media/davinci/vpbe_types.h> 21#include <media/davinci/vpbe_types.h>
22 22
23#define VPBE_VENC_SUBDEV_NAME "vpbe-venc" 23#define DM644X_VPBE_VENC_SUBDEV_NAME "dm644x,vpbe-venc"
24#define DM365_VPBE_VENC_SUBDEV_NAME "dm365,vpbe-venc"
25#define DM355_VPBE_VENC_SUBDEV_NAME "dm355,vpbe-venc"
24 26
25/* venc events */ 27/* venc events */
26#define VENC_END_OF_FRAME BIT(0) 28#define VENC_END_OF_FRAME BIT(0)
@@ -28,7 +30,6 @@
28#define VENC_SECOND_FIELD BIT(2) 30#define VENC_SECOND_FIELD BIT(2)
29 31
30struct venc_platform_data { 32struct venc_platform_data {
31 enum vpbe_version venc_type;
32 int (*setup_pinmux)(enum v4l2_mbus_pixelcode if_type, 33 int (*setup_pinmux)(enum v4l2_mbus_pixelcode if_type,
33 int field); 34 int field);
34 int (*setup_clock)(enum vpbe_enc_timings_type type, 35 int (*setup_clock)(enum vpbe_enc_timings_type type,
diff --git a/include/media/davinci/vpss.h b/include/media/davinci/vpss.h
index b586495bcd53..153473daaa32 100644
--- a/include/media/davinci/vpss.h
+++ b/include/media/davinci/vpss.h
@@ -105,4 +105,20 @@ enum vpss_wbl_sel {
105}; 105};
106/* clear wbl overflow flag for DM6446 */ 106/* clear wbl overflow flag for DM6446 */
107int vpss_clear_wbl_overflow(enum vpss_wbl_sel wbl_sel); 107int vpss_clear_wbl_overflow(enum vpss_wbl_sel wbl_sel);
108
109/* set sync polarity*/
110void vpss_set_sync_pol(struct vpss_sync_pol sync);
111/* set the PG_FRAME_SIZE register */
112void vpss_set_pg_frame_size(struct vpss_pg_frame_size frame_size);
113/*
114 * vpss_check_and_clear_interrupt - check and clear interrupt
115 * @irq - common enumerator for IRQ
116 *
117 * Following return values used:-
118 * 0 - interrupt occurred and cleared
119 * 1 - interrupt not occurred
120 * 2 - interrupt status not available
121 */
122int vpss_dma_complete_interrupt(void);
123
108#endif 124#endif
diff --git a/include/media/ov7670.h b/include/media/ov7670.h
index b133bc123031..1913d5123072 100644
--- a/include/media/ov7670.h
+++ b/include/media/ov7670.h
@@ -15,6 +15,8 @@ struct ov7670_config {
15 int min_height; /* Filter out smaller sizes */ 15 int min_height; /* Filter out smaller sizes */
16 int clock_speed; /* External clock speed (MHz) */ 16 int clock_speed; /* External clock speed (MHz) */
17 bool use_smbus; /* Use smbus I/O instead of I2C */ 17 bool use_smbus; /* Use smbus I/O instead of I2C */
18 bool pll_bypass; /* Choose whether to bypass the PLL */
19 bool pclk_hb_disable; /* Disable toggling pixclk during horizontal blanking */
18}; 20};
19 21
20#endif 22#endif
diff --git a/include/media/ov9650.h b/include/media/ov9650.h
new file mode 100644
index 000000000000..d630cf9e028d
--- /dev/null
+++ b/include/media/ov9650.h
@@ -0,0 +1,27 @@
1/*
2 * OV9650/OV9652 camera sensors driver
3 *
4 * Copyright (C) 2013 Sylwester Nawrocki <sylvester.nawrocki@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10#ifndef OV9650_H_
11#define OV9650_H_
12
13/**
14 * struct ov9650_platform_data - ov9650 driver platform data
15 * @mclk_frequency: the sensor's master clock frequency in Hz
16 * @gpio_pwdn: number of a GPIO connected to OV965X PWDN pin
17 * @gpio_reset: number of a GPIO connected to OV965X RESET pin
18 *
19 * If any of @gpio_pwdn or @gpio_reset are unused then they should be
20 * set to a negative value. @mclk_frequency must always be specified.
21 */
22struct ov9650_platform_data {
23 unsigned long mclk_frequency;
24 int gpio_pwdn;
25 int gpio_reset;
26};
27#endif /* OV9650_H_ */
diff --git a/include/media/rc-map.h b/include/media/rc-map.h
index 74f55a3f14eb..f74ee6f89711 100644
--- a/include/media/rc-map.h
+++ b/include/media/rc-map.h
@@ -182,6 +182,7 @@ void rc_map_init(void);
182#define RC_MAP_TEVII_NEC "rc-tevii-nec" 182#define RC_MAP_TEVII_NEC "rc-tevii-nec"
183#define RC_MAP_TIVO "rc-tivo" 183#define RC_MAP_TIVO "rc-tivo"
184#define RC_MAP_TOTAL_MEDIA_IN_HAND "rc-total-media-in-hand" 184#define RC_MAP_TOTAL_MEDIA_IN_HAND "rc-total-media-in-hand"
185#define RC_MAP_TOTAL_MEDIA_IN_HAND_02 "rc-total-media-in-hand-02"
185#define RC_MAP_TREKSTOR "rc-trekstor" 186#define RC_MAP_TREKSTOR "rc-trekstor"
186#define RC_MAP_TT_1500 "rc-tt-1500" 187#define RC_MAP_TT_1500 "rc-tt-1500"
187#define RC_MAP_TWINHAN_VP1027_DVBS "rc-twinhan1027" 188#define RC_MAP_TWINHAN_VP1027_DVBS "rc-twinhan1027"
diff --git a/include/media/s5c73m3.h b/include/media/s5c73m3.h
new file mode 100644
index 000000000000..ccb9e5448762
--- /dev/null
+++ b/include/media/s5c73m3.h
@@ -0,0 +1,55 @@
1/*
2 * Samsung LSI S5C73M3 8M pixel camera driver
3 *
4 * Copyright (C) 2012, Samsung Electronics, Co., Ltd.
5 * Sylwester Nawrocki <s.nawrocki@samsung.com>
6 * Andrzej Hajda <a.hajda@samsung.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 */
17#ifndef MEDIA_S5C73M3__
18#define MEDIA_S5C73M3__
19
20#include <linux/videodev2.h>
21#include <media/v4l2-mediabus.h>
22
23/**
24 * struct s5c73m3_gpio - data structure describing a GPIO
25 * @gpio: GPIO number
26 * @level: indicates active state of the @gpio
27 */
28struct s5c73m3_gpio {
29 int gpio;
30 int level;
31};
32
33/**
34 * struct s5c73m3_platform_data - s5c73m3 driver platform data
35 * @mclk_frequency: sensor's master clock frequency in Hz
36 * @gpio_reset: GPIO driving RESET pin
37 * @gpio_stby: GPIO driving STBY pin
38 * @nlanes: maximum number of MIPI-CSI lanes used
39 * @horiz_flip: default horizontal image flip value, non zero to enable
40 * @vert_flip: default vertical image flip value, non zero to enable
41 */
42
43struct s5c73m3_platform_data {
44 unsigned long mclk_frequency;
45
46 struct s5c73m3_gpio gpio_reset;
47 struct s5c73m3_gpio gpio_stby;
48
49 enum v4l2_mbus_type bus_type;
50 u8 nlanes;
51 u8 horiz_flip;
52 u8 vert_flip;
53};
54
55#endif /* MEDIA_S5C73M3__ */
diff --git a/include/media/s5p_fimc.h b/include/media/s5p_fimc.h
index eaea62a382f8..28f3590aa031 100644
--- a/include/media/s5p_fimc.h
+++ b/include/media/s5p_fimc.h
@@ -1,8 +1,8 @@
1/* 1/*
2 * Samsung S5P SoC camera interface driver header 2 * Samsung S5P/Exynos4 SoC series camera interface driver header
3 * 3 *
4 * Copyright (c) 2010 Samsung Electronics Co., Ltd 4 * Copyright (C) 2010 - 2013 Samsung Electronics Co., Ltd.
5 * Author: Sylwester Nawrocki, <s.nawrocki@samsung.com> 5 * 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
@@ -14,45 +14,58 @@
14 14
15#include <media/media-entity.h> 15#include <media/media-entity.h>
16 16
17enum cam_bus_type { 17/*
18 FIMC_ITU_601 = 1, 18 * Enumeration of the FIMC data bus types.
19 FIMC_ITU_656, 19 */
20 FIMC_MIPI_CSI2, 20enum fimc_bus_type {
21 FIMC_LCD_WB, /* FIFO link from LCD mixer */ 21 /* Camera parallel bus */
22 FIMC_BUS_TYPE_ITU_601 = 1,
23 /* Camera parallel bus with embedded synchronization */
24 FIMC_BUS_TYPE_ITU_656,
25 /* Camera MIPI-CSI2 serial bus */
26 FIMC_BUS_TYPE_MIPI_CSI2,
27 /* FIFO link from LCD controller (WriteBack A) */
28 FIMC_BUS_TYPE_LCD_WRITEBACK_A,
29 /* FIFO link from LCD controller (WriteBack B) */
30 FIMC_BUS_TYPE_LCD_WRITEBACK_B,
31 /* FIFO link from FIMC-IS */
32 FIMC_BUS_TYPE_ISP_WRITEBACK = FIMC_BUS_TYPE_LCD_WRITEBACK_B,
22}; 33};
23 34
24struct i2c_board_info; 35struct i2c_board_info;
25 36
26/** 37/**
27 * struct s5p_fimc_isp_info - image sensor information required for host 38 * struct fimc_source_info - video source description required for the host
28 * interace configuration. 39 * interface configuration
29 * 40 *
30 * @board_info: pointer to I2C subdevice's board info 41 * @board_info: pointer to I2C subdevice's board info
31 * @clk_frequency: frequency of the clock the host interface provides to sensor 42 * @clk_frequency: frequency of the clock the host interface provides to sensor
32 * @bus_type: determines bus type, MIPI, ITU-R BT.601 etc. 43 * @fimc_bus_type: FIMC camera input type
44 * @sensor_bus_type: image sensor bus type, MIPI, ITU-R BT.601 etc.
45 * @flags: the parallel sensor bus flags defining signals polarity (V4L2_MBUS_*)
33 * @i2c_bus_num: i2c control bus id the sensor is attached to 46 * @i2c_bus_num: i2c control bus id the sensor is attached to
34 * @mux_id: FIMC camera interface multiplexer index (separate for MIPI and ITU) 47 * @mux_id: FIMC camera interface multiplexer index (separate for MIPI and ITU)
35 * @clk_id: index of the SoC peripheral clock for sensors 48 * @clk_id: index of the SoC peripheral clock for sensors
36 * @flags: the parallel bus flags defining signals polarity (V4L2_MBUS_*)
37 */ 49 */
38struct s5p_fimc_isp_info { 50struct fimc_source_info {
39 struct i2c_board_info *board_info; 51 struct i2c_board_info *board_info;
40 unsigned long clk_frequency; 52 unsigned long clk_frequency;
41 enum cam_bus_type bus_type; 53 enum fimc_bus_type fimc_bus_type;
54 enum fimc_bus_type sensor_bus_type;
55 u16 flags;
42 u16 i2c_bus_num; 56 u16 i2c_bus_num;
43 u16 mux_id; 57 u16 mux_id;
44 u16 flags;
45 u8 clk_id; 58 u8 clk_id;
46}; 59};
47 60
48/** 61/**
49 * struct s5p_platform_fimc - camera host interface platform data 62 * struct s5p_platform_fimc - camera host interface platform data
50 * 63 *
51 * @isp_info: properties of camera sensor required for host interface setup 64 * @source_info: properties of an image source for the host interface setup
52 * @num_clients: the number of attached image sensors 65 * @num_clients: the number of attached image sources
53 */ 66 */
54struct s5p_platform_fimc { 67struct s5p_platform_fimc {
55 struct s5p_fimc_isp_info *isp_info; 68 struct fimc_source_info *source_info;
56 int num_clients; 69 int num_clients;
57}; 70};
58 71
diff --git a/include/media/soc_camera.h b/include/media/soc_camera.h
index 6442edc2a151..2cc70cf318bf 100644
--- a/include/media/soc_camera.h
+++ b/include/media/soc_camera.h
@@ -23,11 +23,11 @@
23#include <media/v4l2-device.h> 23#include <media/v4l2-device.h>
24 24
25struct file; 25struct file;
26struct soc_camera_link; 26struct soc_camera_desc;
27 27
28struct soc_camera_device { 28struct soc_camera_device {
29 struct list_head list; /* list of all registered devices */ 29 struct list_head list; /* list of all registered devices */
30 struct soc_camera_link *link; 30 struct soc_camera_desc *sdesc;
31 struct device *pdev; /* Platform device */ 31 struct device *pdev; /* Platform device */
32 struct device *parent; /* Camera host device */ 32 struct device *parent; /* Camera host device */
33 struct device *control; /* E.g., the i2c client */ 33 struct device *control; /* E.g., the i2c client */
@@ -46,9 +46,8 @@ struct soc_camera_device {
46 int num_user_formats; 46 int num_user_formats;
47 enum v4l2_field field; /* Preserve field over close() */ 47 enum v4l2_field field; /* Preserve field over close() */
48 void *host_priv; /* Per-device host private data */ 48 void *host_priv; /* Per-device host private data */
49 /* soc_camera.c private count. Only accessed with .video_lock held */ 49 /* soc_camera.c private count. Only accessed with .host_lock held */
50 int use_count; 50 int use_count;
51 struct mutex video_lock; /* Protects device data */
52 struct file *streamer; /* stream owner */ 51 struct file *streamer; /* stream owner */
53 union { 52 union {
54 struct videobuf_queue vb_vidq; 53 struct videobuf_queue vb_vidq;
@@ -62,7 +61,7 @@ struct soc_camera_device {
62struct soc_camera_host { 61struct soc_camera_host {
63 struct v4l2_device v4l2_dev; 62 struct v4l2_device v4l2_dev;
64 struct list_head list; 63 struct list_head list;
65 struct mutex host_lock; /* Protect during probing */ 64 struct mutex host_lock; /* Protect pipeline modifications */
66 unsigned char nr; /* Host number */ 65 unsigned char nr; /* Host number */
67 u32 capabilities; 66 u32 capabilities;
68 void *priv; 67 void *priv;
@@ -117,26 +116,72 @@ struct soc_camera_host_ops {
117struct i2c_board_info; 116struct i2c_board_info;
118struct regulator_bulk_data; 117struct regulator_bulk_data;
119 118
120struct soc_camera_link { 119struct soc_camera_subdev_desc {
121 /* Camera bus id, used to match a camera and a bus */
122 int bus_id;
123 /* Per camera SOCAM_SENSOR_* bus flags */ 120 /* Per camera SOCAM_SENSOR_* bus flags */
124 unsigned long flags; 121 unsigned long flags;
125 int i2c_adapter_id; 122
126 struct i2c_board_info *board_info; 123 /* sensor driver private platform data */
127 const char *module_name; 124 void *drv_priv;
128 void *priv;
129 125
130 /* Optional regulators that have to be managed on power on/off events */ 126 /* Optional regulators that have to be managed on power on/off events */
131 struct regulator_bulk_data *regulators; 127 struct regulator_bulk_data *regulators;
132 int num_regulators; 128 int num_regulators;
133 129
130 /* Optional callbacks to power on or off and reset the sensor */
131 int (*power)(struct device *, int);
132 int (*reset)(struct device *);
133
134 /*
135 * some platforms may support different data widths than the sensors
136 * native ones due to different data line routing. Let the board code
137 * overwrite the width flags.
138 */
139 int (*set_bus_param)(struct soc_camera_subdev_desc *, unsigned long flags);
140 unsigned long (*query_bus_param)(struct soc_camera_subdev_desc *);
141 void (*free_bus)(struct soc_camera_subdev_desc *);
142};
143
144struct soc_camera_host_desc {
145 /* Camera bus id, used to match a camera and a bus */
146 int bus_id;
147 int i2c_adapter_id;
148 struct i2c_board_info *board_info;
149 const char *module_name;
150
134 /* 151 /*
135 * For non-I2C devices platform has to provide methods to add a device 152 * For non-I2C devices platform has to provide methods to add a device
136 * to the system and to remove it 153 * to the system and to remove it
137 */ 154 */
138 int (*add_device)(struct soc_camera_device *); 155 int (*add_device)(struct soc_camera_device *);
139 void (*del_device)(struct soc_camera_device *); 156 void (*del_device)(struct soc_camera_device *);
157};
158
159/*
160 * 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
162 * two components.
163 */
164struct soc_camera_desc {
165 struct soc_camera_subdev_desc subdev_desc;
166 struct soc_camera_host_desc host_desc;
167};
168
169/* Prepare to replace this struct: don't change its layout any more! */
170struct soc_camera_link {
171 /*
172 * Subdevice part - keep at top and compatible to
173 * struct soc_camera_subdev_desc
174 */
175
176 /* Per camera SOCAM_SENSOR_* bus flags */
177 unsigned long flags;
178
179 void *priv;
180
181 /* Optional regulators that have to be managed on power on/off events */
182 struct regulator_bulk_data *regulators;
183 int num_regulators;
184
140 /* Optional callbacks to power on or off and reset the sensor */ 185 /* Optional callbacks to power on or off and reset the sensor */
141 int (*power)(struct device *, int); 186 int (*power)(struct device *, int);
142 int (*reset)(struct device *); 187 int (*reset)(struct device *);
@@ -148,6 +193,24 @@ struct soc_camera_link {
148 int (*set_bus_param)(struct soc_camera_link *, unsigned long flags); 193 int (*set_bus_param)(struct soc_camera_link *, unsigned long flags);
149 unsigned long (*query_bus_param)(struct soc_camera_link *); 194 unsigned long (*query_bus_param)(struct soc_camera_link *);
150 void (*free_bus)(struct soc_camera_link *); 195 void (*free_bus)(struct soc_camera_link *);
196
197 /*
198 * Host part - keep at bottom and compatible to
199 * struct soc_camera_host_desc
200 */
201
202 /* Camera bus id, used to match a camera and a bus */
203 int bus_id;
204 int i2c_adapter_id;
205 struct i2c_board_info *board_info;
206 const char *module_name;
207
208 /*
209 * For non-I2C devices platform has to provide methods to add a device
210 * to the system and to remove it
211 */
212 int (*add_device)(struct soc_camera_device *);
213 void (*del_device)(struct soc_camera_device *);
151}; 214};
152 215
153static inline struct soc_camera_host *to_soc_camera_host( 216static inline struct soc_camera_host *to_soc_camera_host(
@@ -158,10 +221,10 @@ static inline struct soc_camera_host *to_soc_camera_host(
158 return container_of(v4l2_dev, struct soc_camera_host, v4l2_dev); 221 return container_of(v4l2_dev, struct soc_camera_host, v4l2_dev);
159} 222}
160 223
161static inline struct soc_camera_link *to_soc_camera_link( 224static inline struct soc_camera_desc *to_soc_camera_desc(
162 const struct soc_camera_device *icd) 225 const struct soc_camera_device *icd)
163{ 226{
164 return icd->link; 227 return icd->sdesc;
165} 228}
166 229
167static inline struct device *to_soc_camera_control( 230static inline struct device *to_soc_camera_control(
@@ -251,19 +314,17 @@ static inline void soc_camera_limit_side(int *start, int *length,
251 *start = start_min + length_max - *length; 314 *start = start_min + length_max - *length;
252} 315}
253 316
254unsigned long soc_camera_apply_sensor_flags(struct soc_camera_link *icl, 317unsigned long soc_camera_apply_board_flags(struct soc_camera_subdev_desc *ssdd,
255 unsigned long flags);
256unsigned long soc_camera_apply_board_flags(struct soc_camera_link *icl,
257 const struct v4l2_mbus_config *cfg); 318 const struct v4l2_mbus_config *cfg);
258 319
259int soc_camera_power_on(struct device *dev, struct soc_camera_link *icl); 320int soc_camera_power_on(struct device *dev, struct soc_camera_subdev_desc *ssdd);
260int soc_camera_power_off(struct device *dev, struct soc_camera_link *icl); 321int soc_camera_power_off(struct device *dev, struct soc_camera_subdev_desc *ssdd);
261 322
262static inline int soc_camera_set_power(struct device *dev, 323static inline int soc_camera_set_power(struct device *dev,
263 struct soc_camera_link *icl, bool on) 324 struct soc_camera_subdev_desc *ssdd, bool on)
264{ 325{
265 return on ? soc_camera_power_on(dev, icl) 326 return on ? soc_camera_power_on(dev, ssdd)
266 : soc_camera_power_off(dev, icl); 327 : soc_camera_power_off(dev, ssdd);
267} 328}
268 329
269/* This is only temporary here - until v4l2-subdev begins to link to video_device */ 330/* This is only temporary here - until v4l2-subdev begins to link to video_device */
@@ -275,7 +336,7 @@ static inline struct video_device *soc_camera_i2c_to_vdev(const struct i2c_clien
275 return icd ? icd->vdev : NULL; 336 return icd ? icd->vdev : NULL;
276} 337}
277 338
278static inline struct soc_camera_link *soc_camera_i2c_to_link(const struct i2c_client *client) 339static inline struct soc_camera_subdev_desc *soc_camera_i2c_to_desc(const struct i2c_client *client)
279{ 340{
280 return client->dev.platform_data; 341 return client->dev.platform_data;
281} 342}
diff --git a/include/media/soc_camera_platform.h b/include/media/soc_camera_platform.h
index 8aa4200a0b1d..1e5065dab430 100644
--- a/include/media/soc_camera_platform.h
+++ b/include/media/soc_camera_platform.h
@@ -38,10 +38,12 @@ static inline int soc_camera_platform_add(struct soc_camera_device *icd,
38 void (*release)(struct device *dev), 38 void (*release)(struct device *dev),
39 int id) 39 int id)
40{ 40{
41 struct soc_camera_platform_info *info = plink->priv; 41 struct soc_camera_subdev_desc *ssdd =
42 (struct soc_camera_subdev_desc *)plink;
43 struct soc_camera_platform_info *info = ssdd->drv_priv;
42 int ret; 44 int ret;
43 45
44 if (icd->link != plink) 46 if (&icd->sdesc->subdev_desc != ssdd)
45 return -ENODEV; 47 return -ENODEV;
46 48
47 if (*pdev) 49 if (*pdev)
@@ -70,7 +72,9 @@ static inline void soc_camera_platform_del(const struct soc_camera_device *icd,
70 struct platform_device *pdev, 72 struct platform_device *pdev,
71 const struct soc_camera_link *plink) 73 const struct soc_camera_link *plink)
72{ 74{
73 if (icd->link != plink || !pdev) 75 const struct soc_camera_subdev_desc *ssdd =
76 (const struct soc_camera_subdev_desc *)plink;
77 if (&icd->sdesc->subdev_desc != ssdd || !pdev)
74 return; 78 return;
75 79
76 platform_device_unregister(pdev); 80 platform_device_unregister(pdev);
diff --git a/include/media/tvp514x.h b/include/media/tvp514x.h
index 74387e83f5b9..86ed7e806830 100644
--- a/include/media/tvp514x.h
+++ b/include/media/tvp514x.h
@@ -96,12 +96,9 @@ enum tvp514x_output {
96 96
97/** 97/**
98 * struct tvp514x_platform_data - Platform data values and access functions. 98 * struct tvp514x_platform_data - Platform data values and access functions.
99 * @power_set: Power state access function, zero is off, non-zero is on.
100 * @ifparm: Interface parameters access function.
101 * @priv_data_set: Device private data (pointer) access function.
102 * @clk_polarity: Clock polarity of the current interface. 99 * @clk_polarity: Clock polarity of the current interface.
103 * @ hs_polarity: HSYNC Polarity configuration for current interface. 100 * @hs_polarity: HSYNC Polarity configuration for current interface.
104 * @ vs_polarity: VSYNC Polarity configuration for current interface. 101 * @vs_polarity: VSYNC Polarity configuration for current interface.
105 */ 102 */
106struct tvp514x_platform_data { 103struct tvp514x_platform_data {
107 /* Interface control params */ 104 /* Interface control params */
diff --git a/include/media/v4l2-common.h b/include/media/v4l2-common.h
index 1a0b2db4c5d3..ec7c9c00b256 100644
--- a/include/media/v4l2-common.h
+++ b/include/media/v4l2-common.h
@@ -225,4 +225,6 @@ bool v4l2_detect_gtf(unsigned frame_height, unsigned hfreq, unsigned vsync,
225 225
226struct v4l2_fract v4l2_calc_aspect_ratio(u8 hor_landscape, u8 vert_portrait); 226struct v4l2_fract v4l2_calc_aspect_ratio(u8 hor_landscape, u8 vert_portrait);
227 227
228void v4l2_get_timestamp(struct timeval *tv);
229
228#endif /* V4L2_COMMON_H_ */ 230#endif /* V4L2_COMMON_H_ */
diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h
index 96509119f28f..f00d42bc01a6 100644
--- a/include/media/v4l2-ctrls.h
+++ b/include/media/v4l2-ctrls.h
@@ -53,6 +53,8 @@ struct v4l2_ctrl_ops {
53 int (*s_ctrl)(struct v4l2_ctrl *ctrl); 53 int (*s_ctrl)(struct v4l2_ctrl *ctrl);
54}; 54};
55 55
56typedef void (*v4l2_ctrl_notify_fnc)(struct v4l2_ctrl *ctrl, void *priv);
57
56/** struct v4l2_ctrl - The control structure. 58/** struct v4l2_ctrl - The control structure.
57 * @node: The list node. 59 * @node: The list node.
58 * @ev_subs: The list of control event subscriptions. 60 * @ev_subs: The list of control event subscriptions.
@@ -72,6 +74,8 @@ struct v4l2_ctrl_ops {
72 * set this flag directly. 74 * set this flag directly.
73 * @has_volatiles: If set, then one or more members of the cluster are volatile. 75 * @has_volatiles: If set, then one or more members of the cluster are volatile.
74 * Drivers should never touch this flag. 76 * Drivers should never touch this flag.
77 * @call_notify: If set, then call the handler's notify function whenever the
78 * control's value changes.
75 * @manual_mode_value: If the is_auto flag is set, then this is the value 79 * @manual_mode_value: If the is_auto flag is set, then this is the value
76 * of the auto control that determines if that control is in 80 * of the auto control that determines if that control is in
77 * manual mode. So if the value of the auto control equals this 81 * manual mode. So if the value of the auto control equals this
@@ -119,6 +123,7 @@ struct v4l2_ctrl {
119 unsigned int is_private:1; 123 unsigned int is_private:1;
120 unsigned int is_auto:1; 124 unsigned int is_auto:1;
121 unsigned int has_volatiles:1; 125 unsigned int has_volatiles:1;
126 unsigned int call_notify:1;
122 unsigned int manual_mode_value:8; 127 unsigned int manual_mode_value:8;
123 128
124 const struct v4l2_ctrl_ops *ops; 129 const struct v4l2_ctrl_ops *ops;
@@ -177,6 +182,10 @@ struct v4l2_ctrl_ref {
177 * control is needed multiple times, so this is a simple 182 * control is needed multiple times, so this is a simple
178 * optimization. 183 * optimization.
179 * @buckets: Buckets for the hashing. Allows for quick control lookup. 184 * @buckets: Buckets for the hashing. Allows for quick control lookup.
185 * @notify: A notify callback that is called whenever the control changes value.
186 * Note that the handler's lock is held when the notify function
187 * is called!
188 * @notify_priv: Passed as argument to the v4l2_ctrl notify callback.
180 * @nr_of_buckets: Total number of buckets in the array. 189 * @nr_of_buckets: Total number of buckets in the array.
181 * @error: The error code of the first failed control addition. 190 * @error: The error code of the first failed control addition.
182 */ 191 */
@@ -187,6 +196,8 @@ struct v4l2_ctrl_handler {
187 struct list_head ctrl_refs; 196 struct list_head ctrl_refs;
188 struct v4l2_ctrl_ref *cached; 197 struct v4l2_ctrl_ref *cached;
189 struct v4l2_ctrl_ref **buckets; 198 struct v4l2_ctrl_ref **buckets;
199 v4l2_ctrl_notify_fnc notify;
200 void *notify_priv;
190 u16 nr_of_buckets; 201 u16 nr_of_buckets;
191 int error; 202 int error;
192}; 203};
@@ -507,6 +518,26 @@ void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active);
507 */ 518 */
508void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed); 519void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed);
509 520
521/** v4l2_ctrl_modify_range() - Update the range of a control.
522 * @ctrl: The control to update.
523 * @min: The control's minimum value.
524 * @max: The control's maximum value.
525 * @step: The control's step value
526 * @def: The control's default value.
527 *
528 * Update the range of a control on the fly. This works for control types
529 * INTEGER, BOOLEAN, MENU, INTEGER MENU and BITMASK. For menu controls the
530 * @step value is interpreted as a menu_skip_mask.
531 *
532 * An error is returned if one of the range arguments is invalid for this
533 * control type.
534 *
535 * This function assumes that the control handler is not locked and will
536 * take the lock itself.
537 */
538int v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
539 s32 min, s32 max, u32 step, s32 def);
540
510/** v4l2_ctrl_lock() - Helper function to lock the handler 541/** v4l2_ctrl_lock() - Helper function to lock the handler
511 * associated with the control. 542 * associated with the control.
512 * @ctrl: The control to lock. 543 * @ctrl: The control to lock.
@@ -525,6 +556,20 @@ static inline void v4l2_ctrl_unlock(struct v4l2_ctrl *ctrl)
525 mutex_unlock(ctrl->handler->lock); 556 mutex_unlock(ctrl->handler->lock);
526} 557}
527 558
559/** v4l2_ctrl_notify() - Function to set a notify callback for a control.
560 * @ctrl: The control.
561 * @notify: The callback function.
562 * @priv: The callback private handle, passed as argument to the callback.
563 *
564 * This function sets a callback function for the control. If @ctrl is NULL,
565 * then it will do nothing. If @notify is NULL, then the notify callback will
566 * be removed.
567 *
568 * There can be only one notify. If another already exists, then a WARN_ON
569 * will be issued and the function will do nothing.
570 */
571void v4l2_ctrl_notify(struct v4l2_ctrl *ctrl, v4l2_ctrl_notify_fnc notify, void *priv);
572
528/** v4l2_ctrl_g_ctrl() - Helper function to get the control's value from within a driver. 573/** v4l2_ctrl_g_ctrl() - Helper function to get the control's value from within a driver.
529 * @ctrl: The control. 574 * @ctrl: The control.
530 * 575 *
@@ -609,4 +654,12 @@ int v4l2_subdev_s_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *cs
609int v4l2_subdev_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl); 654int v4l2_subdev_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
610int v4l2_subdev_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl); 655int v4l2_subdev_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
611 656
657/* Can be used as a subscribe_event function that just subscribes control
658 events. */
659int v4l2_ctrl_subdev_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh,
660 struct v4l2_event_subscription *sub);
661
662/* Log all controls owned by subdev's control handler. */
663int v4l2_ctrl_subdev_log_status(struct v4l2_subdev *sd);
664
612#endif 665#endif
diff --git a/include/media/v4l2-event.h b/include/media/v4l2-event.h
index eff85f934b24..be05d019de25 100644
--- a/include/media/v4l2-event.h
+++ b/include/media/v4l2-event.h
@@ -64,6 +64,7 @@
64 */ 64 */
65 65
66struct v4l2_fh; 66struct v4l2_fh;
67struct v4l2_subdev;
67struct v4l2_subscribed_event; 68struct v4l2_subscribed_event;
68struct video_device; 69struct video_device;
69 70
@@ -129,5 +130,6 @@ int v4l2_event_subscribe(struct v4l2_fh *fh,
129int v4l2_event_unsubscribe(struct v4l2_fh *fh, 130int v4l2_event_unsubscribe(struct v4l2_fh *fh,
130 const struct v4l2_event_subscription *sub); 131 const struct v4l2_event_subscription *sub);
131void v4l2_event_unsubscribe_all(struct v4l2_fh *fh); 132void v4l2_event_unsubscribe_all(struct v4l2_fh *fh);
132 133int v4l2_event_subdev_unsubscribe(struct v4l2_subdev *sd, struct v4l2_fh *fh,
134 struct v4l2_event_subscription *sub);
133#endif /* V4L2_EVENT_H */ 135#endif /* V4L2_EVENT_H */
diff --git a/include/media/v4l2-image-sizes.h b/include/media/v4l2-image-sizes.h
new file mode 100644
index 000000000000..10daf92ff1ab
--- /dev/null
+++ b/include/media/v4l2-image-sizes.h
@@ -0,0 +1,34 @@
1/*
2 * Standard image size definitions
3 *
4 * Copyright (C) 2013, Sylwester Nawrocki <sylvester.nawrocki@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10#ifndef _IMAGE_SIZES_H
11#define _IMAGE_SIZES_H
12
13#define CIF_WIDTH 352
14#define CIF_HEIGHT 288
15
16#define QCIF_WIDTH 176
17#define QCIF_HEIGHT 144
18
19#define QQCIF_WIDTH 88
20#define QQCIF_HEIGHT 72
21
22#define QQVGA_WIDTH 160
23#define QQVGA_HEIGHT 120
24
25#define QVGA_WIDTH 320
26#define QVGA_HEIGHT 240
27
28#define SXGA_WIDTH 1280
29#define SXGA_HEIGHT 1024
30
31#define VGA_WIDTH 640
32#define VGA_HEIGHT 480
33
34#endif /* _IMAGE_SIZES_H */
diff --git a/include/media/v4l2-mem2mem.h b/include/media/v4l2-mem2mem.h
index 7e82d2b193d5..d3eef01da648 100644
--- a/include/media/v4l2-mem2mem.h
+++ b/include/media/v4l2-mem2mem.h
@@ -125,7 +125,7 @@ unsigned int v4l2_m2m_poll(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
125int v4l2_m2m_mmap(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, 125int v4l2_m2m_mmap(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
126 struct vm_area_struct *vma); 126 struct vm_area_struct *vma);
127 127
128struct v4l2_m2m_dev *v4l2_m2m_init(struct v4l2_m2m_ops *m2m_ops); 128struct v4l2_m2m_dev *v4l2_m2m_init(const struct v4l2_m2m_ops *m2m_ops);
129void v4l2_m2m_release(struct v4l2_m2m_dev *m2m_dev); 129void v4l2_m2m_release(struct v4l2_m2m_dev *m2m_dev);
130 130
131struct v4l2_m2m_ctx *v4l2_m2m_ctx_init(struct v4l2_m2m_dev *m2m_dev, 131struct v4l2_m2m_ctx *v4l2_m2m_ctx_init(struct v4l2_m2m_dev *m2m_dev,
diff --git a/include/uapi/linux/dvb/frontend.h b/include/uapi/linux/dvb/frontend.h
index c12d452cb40d..c56d77c496a5 100644
--- a/include/uapi/linux/dvb/frontend.h
+++ b/include/uapi/linux/dvb/frontend.h
@@ -365,7 +365,17 @@ struct dvb_frontend_event {
365#define DTV_INTERLEAVING 60 365#define DTV_INTERLEAVING 60
366#define DTV_LNA 61 366#define DTV_LNA 61
367 367
368#define DTV_MAX_COMMAND DTV_LNA 368/* Quality parameters */
369#define DTV_STAT_SIGNAL_STRENGTH 62
370#define DTV_STAT_CNR 63
371#define DTV_STAT_PRE_ERROR_BIT_COUNT 64
372#define DTV_STAT_PRE_TOTAL_BIT_COUNT 65
373#define DTV_STAT_POST_ERROR_BIT_COUNT 66
374#define DTV_STAT_POST_TOTAL_BIT_COUNT 67
375#define DTV_STAT_ERROR_BLOCK_COUNT 68
376#define DTV_STAT_TOTAL_BLOCK_COUNT 69
377
378#define DTV_MAX_COMMAND DTV_STAT_TOTAL_BLOCK_COUNT
369 379
370typedef enum fe_pilot { 380typedef enum fe_pilot {
371 PILOT_ON, 381 PILOT_ON,
@@ -452,11 +462,78 @@ struct dtv_cmds_h {
452 __u32 reserved:30; /* Align */ 462 __u32 reserved:30; /* Align */
453}; 463};
454 464
465/**
466 * Scale types for the quality parameters.
467 * @FE_SCALE_NOT_AVAILABLE: That QoS measure is not available. That
468 * could indicate a temporary or a permanent
469 * condition.
470 * @FE_SCALE_DECIBEL: The scale is measured in 0.0001 dB steps, typically
471 * used on signal measures.
472 * @FE_SCALE_RELATIVE: The scale is a relative percentual measure,
473 * ranging from 0 (0%) to 0xffff (100%).
474 * @FE_SCALE_COUNTER: The scale counts the occurrence of an event, like
475 * bit error, block error, lapsed time.
476 */
477enum fecap_scale_params {
478 FE_SCALE_NOT_AVAILABLE = 0,
479 FE_SCALE_DECIBEL,
480 FE_SCALE_RELATIVE,
481 FE_SCALE_COUNTER
482};
483
484/**
485 * struct dtv_stats - Used for reading a DTV status property
486 *
487 * @value: value of the measure. Should range from 0 to 0xffff;
488 * @scale: Filled with enum fecap_scale_params - the scale
489 * in usage for that parameter
490 *
491 * For most delivery systems, this will return a single value for each
492 * parameter.
493 * It should be noticed, however, that new OFDM delivery systems like
494 * ISDB can use different modulation types for each group of carriers.
495 * On such standards, up to 8 groups of statistics can be provided, one
496 * for each carrier group (called "layer" on ISDB).
497 * In order to be consistent with other delivery systems, the first
498 * value refers to the entire set of carriers ("global").
499 * dtv_status:scale should use the value FE_SCALE_NOT_AVAILABLE when
500 * the value for the entire group of carriers or from one specific layer
501 * is not provided by the hardware.
502 * st.len should be filled with the latest filled status + 1.
503 *
504 * In other words, for ISDB, those values should be filled like:
505 * u.st.stat.svalue[0] = global statistics;
506 * u.st.stat.scale[0] = FE_SCALE_DECIBELS;
507 * u.st.stat.value[1] = layer A statistics;
508 * u.st.stat.scale[1] = FE_SCALE_NOT_AVAILABLE (if not available);
509 * u.st.stat.svalue[2] = layer B statistics;
510 * u.st.stat.scale[2] = FE_SCALE_DECIBELS;
511 * u.st.stat.svalue[3] = layer C statistics;
512 * u.st.stat.scale[3] = FE_SCALE_DECIBELS;
513 * u.st.len = 4;
514 */
515struct dtv_stats {
516 __u8 scale; /* enum fecap_scale_params type */
517 union {
518 __u64 uvalue; /* for counters and relative scales */
519 __s64 svalue; /* for 0.0001 dB measures */
520 };
521} __attribute__ ((packed));
522
523
524#define MAX_DTV_STATS 4
525
526struct dtv_fe_stats {
527 __u8 len;
528 struct dtv_stats stat[MAX_DTV_STATS];
529} __attribute__ ((packed));
530
455struct dtv_property { 531struct dtv_property {
456 __u32 cmd; 532 __u32 cmd;
457 __u32 reserved[3]; 533 __u32 reserved[3];
458 union { 534 union {
459 __u32 data; 535 __u32 data;
536 struct dtv_fe_stats st;
460 struct { 537 struct {
461 __u8 data[32]; 538 __u8 data[32];
462 __u32 len; 539 __u32 len;
diff --git a/include/uapi/linux/dvb/version.h b/include/uapi/linux/dvb/version.h
index 827cce7e33e3..e53e2ad4444f 100644
--- a/include/uapi/linux/dvb/version.h
+++ b/include/uapi/linux/dvb/version.h
@@ -24,6 +24,6 @@
24#define _DVBVERSION_H_ 24#define _DVBVERSION_H_
25 25
26#define DVB_API_VERSION 5 26#define DVB_API_VERSION 5
27#define DVB_API_VERSION_MINOR 9 27#define DVB_API_VERSION_MINOR 10
28 28
29#endif /*_DVBVERSION_H_*/ 29#endif /*_DVBVERSION_H_*/
diff --git a/include/uapi/linux/meye.h b/include/uapi/linux/meye.h
index 0dd49954f746..8ff50fe9e481 100644
--- a/include/uapi/linux/meye.h
+++ b/include/uapi/linux/meye.h
@@ -57,10 +57,8 @@ struct meye_params {
57#define MEYEIOC_STILLJCAPT _IOR ('v', BASE_VIDIOC_PRIVATE+5, int) 57#define MEYEIOC_STILLJCAPT _IOR ('v', BASE_VIDIOC_PRIVATE+5, int)
58 58
59/* V4L2 private controls */ 59/* V4L2 private controls */
60#define V4L2_CID_AGC V4L2_CID_PRIVATE_BASE 60#define V4L2_CID_MEYE_AGC (V4L2_CID_USER_MEYE_BASE + 0)
61#define V4L2_CID_MEYE_SHARPNESS (V4L2_CID_PRIVATE_BASE + 1) 61#define V4L2_CID_MEYE_PICTURE (V4L2_CID_USER_MEYE_BASE + 1)
62#define V4L2_CID_PICTURE (V4L2_CID_PRIVATE_BASE + 2) 62#define V4L2_CID_MEYE_FRAMERATE (V4L2_CID_USER_MEYE_BASE + 2)
63#define V4L2_CID_JPEGQUAL (V4L2_CID_PRIVATE_BASE + 3)
64#define V4L2_CID_FRAMERATE (V4L2_CID_PRIVATE_BASE + 4)
65 63
66#endif 64#endif
diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h
index f56c945cecd4..dcd63745e83a 100644
--- a/include/uapi/linux/v4l2-controls.h
+++ b/include/uapi/linux/v4l2-controls.h
@@ -88,10 +88,6 @@
88#define V4L2_CID_HFLIP (V4L2_CID_BASE+20) 88#define V4L2_CID_HFLIP (V4L2_CID_BASE+20)
89#define V4L2_CID_VFLIP (V4L2_CID_BASE+21) 89#define V4L2_CID_VFLIP (V4L2_CID_BASE+21)
90 90
91/* Deprecated; use V4L2_CID_PAN_RESET and V4L2_CID_TILT_RESET */
92#define V4L2_CID_HCENTER (V4L2_CID_BASE+22)
93#define V4L2_CID_VCENTER (V4L2_CID_BASE+23)
94
95#define V4L2_CID_POWER_LINE_FREQUENCY (V4L2_CID_BASE+24) 91#define V4L2_CID_POWER_LINE_FREQUENCY (V4L2_CID_BASE+24)
96enum v4l2_power_line_frequency { 92enum v4l2_power_line_frequency {
97 V4L2_CID_POWER_LINE_FREQUENCY_DISABLED = 0, 93 V4L2_CID_POWER_LINE_FREQUENCY_DISABLED = 0,
@@ -144,6 +140,11 @@ enum v4l2_colorfx {
144/* last CID + 1 */ 140/* last CID + 1 */
145#define V4L2_CID_LASTP1 (V4L2_CID_BASE+43) 141#define V4L2_CID_LASTP1 (V4L2_CID_BASE+43)
146 142
143/* USER-class private control IDs */
144
145/* The base for the meye driver controls. See linux/meye.h for the list
146 * of controls. We reserve 16 controls for this driver. */
147#define V4L2_CID_USER_MEYE_BASE (V4L2_CID_USER_BASE + 0x1000)
147 148
148/* MPEG-class control IDs */ 149/* MPEG-class control IDs */
149 150
@@ -782,6 +783,7 @@ enum v4l2_jpeg_chroma_subsampling {
782#define V4L2_JPEG_ACTIVE_MARKER_DQT (1 << 17) 783#define V4L2_JPEG_ACTIVE_MARKER_DQT (1 << 17)
783#define V4L2_JPEG_ACTIVE_MARKER_DHT (1 << 18) 784#define V4L2_JPEG_ACTIVE_MARKER_DHT (1 << 18)
784 785
786
785/* Image source controls */ 787/* Image source controls */
786#define V4L2_CID_IMAGE_SOURCE_CLASS_BASE (V4L2_CTRL_CLASS_IMAGE_SOURCE | 0x900) 788#define V4L2_CID_IMAGE_SOURCE_CLASS_BASE (V4L2_CTRL_CLASS_IMAGE_SOURCE | 0x900)
787#define V4L2_CID_IMAGE_SOURCE_CLASS (V4L2_CTRL_CLASS_IMAGE_SOURCE | 1) 789#define V4L2_CID_IMAGE_SOURCE_CLASS (V4L2_CTRL_CLASS_IMAGE_SOURCE | 1)
@@ -800,4 +802,27 @@ enum v4l2_jpeg_chroma_subsampling {
800#define V4L2_CID_PIXEL_RATE (V4L2_CID_IMAGE_PROC_CLASS_BASE + 2) 802#define V4L2_CID_PIXEL_RATE (V4L2_CID_IMAGE_PROC_CLASS_BASE + 2)
801#define V4L2_CID_TEST_PATTERN (V4L2_CID_IMAGE_PROC_CLASS_BASE + 3) 803#define V4L2_CID_TEST_PATTERN (V4L2_CID_IMAGE_PROC_CLASS_BASE + 3)
802 804
805
806/* DV-class control IDs defined by V4L2 */
807#define V4L2_CID_DV_CLASS_BASE (V4L2_CTRL_CLASS_DV | 0x900)
808#define V4L2_CID_DV_CLASS (V4L2_CTRL_CLASS_DV | 1)
809
810#define V4L2_CID_DV_TX_HOTPLUG (V4L2_CID_DV_CLASS_BASE + 1)
811#define V4L2_CID_DV_TX_RXSENSE (V4L2_CID_DV_CLASS_BASE + 2)
812#define V4L2_CID_DV_TX_EDID_PRESENT (V4L2_CID_DV_CLASS_BASE + 3)
813#define V4L2_CID_DV_TX_MODE (V4L2_CID_DV_CLASS_BASE + 4)
814enum v4l2_dv_tx_mode {
815 V4L2_DV_TX_MODE_DVI_D = 0,
816 V4L2_DV_TX_MODE_HDMI = 1,
817};
818#define V4L2_CID_DV_TX_RGB_RANGE (V4L2_CID_DV_CLASS_BASE + 5)
819enum v4l2_dv_rgb_range {
820 V4L2_DV_RGB_RANGE_AUTO = 0,
821 V4L2_DV_RGB_RANGE_LIMITED = 1,
822 V4L2_DV_RGB_RANGE_FULL = 2,
823};
824
825#define V4L2_CID_DV_RX_POWER_PRESENT (V4L2_CID_DV_CLASS_BASE + 100)
826#define V4L2_CID_DV_RX_RGB_RANGE (V4L2_CID_DV_CLASS_BASE + 101)
827
803#endif 828#endif
diff --git a/include/uapi/linux/v4l2-mediabus.h b/include/uapi/linux/v4l2-mediabus.h
index 7d64e0e1a18b..b9b7bea04537 100644
--- a/include/uapi/linux/v4l2-mediabus.h
+++ b/include/uapi/linux/v4l2-mediabus.h
@@ -47,8 +47,9 @@ enum v4l2_mbus_pixelcode {
47 V4L2_MBUS_FMT_RGB565_2X8_BE = 0x1007, 47 V4L2_MBUS_FMT_RGB565_2X8_BE = 0x1007,
48 V4L2_MBUS_FMT_RGB565_2X8_LE = 0x1008, 48 V4L2_MBUS_FMT_RGB565_2X8_LE = 0x1008,
49 49
50 /* YUV (including grey) - next is 0x2014 */ 50 /* YUV (including grey) - next is 0x2017 */
51 V4L2_MBUS_FMT_Y8_1X8 = 0x2001, 51 V4L2_MBUS_FMT_Y8_1X8 = 0x2001,
52 V4L2_MBUS_FMT_UV8_1X8 = 0x2015,
52 V4L2_MBUS_FMT_UYVY8_1_5X8 = 0x2002, 53 V4L2_MBUS_FMT_UYVY8_1_5X8 = 0x2002,
53 V4L2_MBUS_FMT_VYUY8_1_5X8 = 0x2003, 54 V4L2_MBUS_FMT_VYUY8_1_5X8 = 0x2003,
54 V4L2_MBUS_FMT_YUYV8_1_5X8 = 0x2004, 55 V4L2_MBUS_FMT_YUYV8_1_5X8 = 0x2004,
@@ -65,14 +66,20 @@ enum v4l2_mbus_pixelcode {
65 V4L2_MBUS_FMT_VYUY8_1X16 = 0x2010, 66 V4L2_MBUS_FMT_VYUY8_1X16 = 0x2010,
66 V4L2_MBUS_FMT_YUYV8_1X16 = 0x2011, 67 V4L2_MBUS_FMT_YUYV8_1X16 = 0x2011,
67 V4L2_MBUS_FMT_YVYU8_1X16 = 0x2012, 68 V4L2_MBUS_FMT_YVYU8_1X16 = 0x2012,
69 V4L2_MBUS_FMT_YDYUYDYV8_1X16 = 0x2014,
68 V4L2_MBUS_FMT_YUYV10_1X20 = 0x200d, 70 V4L2_MBUS_FMT_YUYV10_1X20 = 0x200d,
69 V4L2_MBUS_FMT_YVYU10_1X20 = 0x200e, 71 V4L2_MBUS_FMT_YVYU10_1X20 = 0x200e,
72 V4L2_MBUS_FMT_YUV10_1X30 = 0x2016,
70 73
71 /* Bayer - next is 0x3015 */ 74 /* Bayer - next is 0x3019 */
72 V4L2_MBUS_FMT_SBGGR8_1X8 = 0x3001, 75 V4L2_MBUS_FMT_SBGGR8_1X8 = 0x3001,
73 V4L2_MBUS_FMT_SGBRG8_1X8 = 0x3013, 76 V4L2_MBUS_FMT_SGBRG8_1X8 = 0x3013,
74 V4L2_MBUS_FMT_SGRBG8_1X8 = 0x3002, 77 V4L2_MBUS_FMT_SGRBG8_1X8 = 0x3002,
75 V4L2_MBUS_FMT_SRGGB8_1X8 = 0x3014, 78 V4L2_MBUS_FMT_SRGGB8_1X8 = 0x3014,
79 V4L2_MBUS_FMT_SBGGR10_ALAW8_1X8 = 0x3015,
80 V4L2_MBUS_FMT_SGBRG10_ALAW8_1X8 = 0x3016,
81 V4L2_MBUS_FMT_SGRBG10_ALAW8_1X8 = 0x3017,
82 V4L2_MBUS_FMT_SRGGB10_ALAW8_1X8 = 0x3018,
76 V4L2_MBUS_FMT_SBGGR10_DPCM8_1X8 = 0x300b, 83 V4L2_MBUS_FMT_SBGGR10_DPCM8_1X8 = 0x300b,
77 V4L2_MBUS_FMT_SGBRG10_DPCM8_1X8 = 0x300c, 84 V4L2_MBUS_FMT_SGBRG10_DPCM8_1X8 = 0x300c,
78 V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8 = 0x3009, 85 V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8 = 0x3009,
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 3cf3e946e331..234d1d870914 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -334,6 +334,9 @@ struct v4l2_pix_format {
334/* Palette formats */ 334/* Palette formats */
335#define V4L2_PIX_FMT_PAL8 v4l2_fourcc('P', 'A', 'L', '8') /* 8 8-bit palette */ 335#define V4L2_PIX_FMT_PAL8 v4l2_fourcc('P', 'A', 'L', '8') /* 8 8-bit palette */
336 336
337/* Chrominance formats */
338#define V4L2_PIX_FMT_UV8 v4l2_fourcc('U', 'V', '8', ' ') /* 8 UV 4:4 */
339
337/* Luminance+Chrominance formats */ 340/* Luminance+Chrominance formats */
338#define V4L2_PIX_FMT_YVU410 v4l2_fourcc('Y', 'V', 'U', '9') /* 9 YVU 4:1:0 */ 341#define V4L2_PIX_FMT_YVU410 v4l2_fourcc('Y', 'V', 'U', '9') /* 9 YVU 4:1:0 */
339#define V4L2_PIX_FMT_YVU420 v4l2_fourcc('Y', 'V', '1', '2') /* 12 YVU 4:2:0 */ 342#define V4L2_PIX_FMT_YVU420 v4l2_fourcc('Y', 'V', '1', '2') /* 12 YVU 4:2:0 */
@@ -386,6 +389,11 @@ struct v4l2_pix_format {
386#define V4L2_PIX_FMT_SGBRG12 v4l2_fourcc('G', 'B', '1', '2') /* 12 GBGB.. RGRG.. */ 389#define V4L2_PIX_FMT_SGBRG12 v4l2_fourcc('G', 'B', '1', '2') /* 12 GBGB.. RGRG.. */
387#define V4L2_PIX_FMT_SGRBG12 v4l2_fourcc('B', 'A', '1', '2') /* 12 GRGR.. BGBG.. */ 390#define V4L2_PIX_FMT_SGRBG12 v4l2_fourcc('B', 'A', '1', '2') /* 12 GRGR.. BGBG.. */
388#define V4L2_PIX_FMT_SRGGB12 v4l2_fourcc('R', 'G', '1', '2') /* 12 RGRG.. GBGB.. */ 391#define V4L2_PIX_FMT_SRGGB12 v4l2_fourcc('R', 'G', '1', '2') /* 12 RGRG.. GBGB.. */
392 /* 10bit raw bayer a-law compressed to 8 bits */
393#define V4L2_PIX_FMT_SBGGR10ALAW8 v4l2_fourcc('a', 'B', 'A', '8')
394#define V4L2_PIX_FMT_SGBRG10ALAW8 v4l2_fourcc('a', 'G', 'A', '8')
395#define V4L2_PIX_FMT_SGRBG10ALAW8 v4l2_fourcc('a', 'g', 'A', '8')
396#define V4L2_PIX_FMT_SRGGB10ALAW8 v4l2_fourcc('a', 'R', 'A', '8')
389 /* 10bit raw bayer DPCM compressed to 8 bits */ 397 /* 10bit raw bayer DPCM compressed to 8 bits */
390#define V4L2_PIX_FMT_SBGGR10DPCM8 v4l2_fourcc('b', 'B', 'A', '8') 398#define V4L2_PIX_FMT_SBGGR10DPCM8 v4l2_fourcc('b', 'B', 'A', '8')
391#define V4L2_PIX_FMT_SGBRG10DPCM8 v4l2_fourcc('b', 'G', 'A', '8') 399#define V4L2_PIX_FMT_SGBRG10DPCM8 v4l2_fourcc('b', 'G', 'A', '8')
@@ -693,6 +701,10 @@ struct v4l2_buffer {
693/* Cache handling flags */ 701/* Cache handling flags */
694#define V4L2_BUF_FLAG_NO_CACHE_INVALIDATE 0x0800 702#define V4L2_BUF_FLAG_NO_CACHE_INVALIDATE 0x0800
695#define V4L2_BUF_FLAG_NO_CACHE_CLEAN 0x1000 703#define V4L2_BUF_FLAG_NO_CACHE_CLEAN 0x1000
704/* Timestamp type */
705#define V4L2_BUF_FLAG_TIMESTAMP_MASK 0xe000
706#define V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN 0x0000
707#define V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC 0x2000
696 708
697/** 709/**
698 * struct v4l2_exportbuffer - export of video buffer as DMABUF file descriptor 710 * struct v4l2_exportbuffer - export of video buffer as DMABUF file descriptor
@@ -1342,28 +1354,6 @@ struct v4l2_querymenu {
1342#define V4L2_CID_PRIVATE_BASE 0x08000000 1354#define V4L2_CID_PRIVATE_BASE 0x08000000
1343 1355
1344 1356
1345/* DV-class control IDs defined by V4L2 */
1346#define V4L2_CID_DV_CLASS_BASE (V4L2_CTRL_CLASS_DV | 0x900)
1347#define V4L2_CID_DV_CLASS (V4L2_CTRL_CLASS_DV | 1)
1348
1349#define V4L2_CID_DV_TX_HOTPLUG (V4L2_CID_DV_CLASS_BASE + 1)
1350#define V4L2_CID_DV_TX_RXSENSE (V4L2_CID_DV_CLASS_BASE + 2)
1351#define V4L2_CID_DV_TX_EDID_PRESENT (V4L2_CID_DV_CLASS_BASE + 3)
1352#define V4L2_CID_DV_TX_MODE (V4L2_CID_DV_CLASS_BASE + 4)
1353enum v4l2_dv_tx_mode {
1354 V4L2_DV_TX_MODE_DVI_D = 0,
1355 V4L2_DV_TX_MODE_HDMI = 1,
1356};
1357#define V4L2_CID_DV_TX_RGB_RANGE (V4L2_CID_DV_CLASS_BASE + 5)
1358enum v4l2_dv_rgb_range {
1359 V4L2_DV_RGB_RANGE_AUTO = 0,
1360 V4L2_DV_RGB_RANGE_LIMITED = 1,
1361 V4L2_DV_RGB_RANGE_FULL = 2,
1362};
1363
1364#define V4L2_CID_DV_RX_POWER_PRESENT (V4L2_CID_DV_CLASS_BASE + 100)
1365#define V4L2_CID_DV_RX_RGB_RANGE (V4L2_CID_DV_CLASS_BASE + 101)
1366
1367/* 1357/*
1368 * T U N I N G 1358 * T U N I N G
1369 */ 1359 */
@@ -1810,6 +1800,7 @@ struct v4l2_event_vsync {
1810/* Payload for V4L2_EVENT_CTRL */ 1800/* Payload for V4L2_EVENT_CTRL */
1811#define V4L2_EVENT_CTRL_CH_VALUE (1 << 0) 1801#define V4L2_EVENT_CTRL_CH_VALUE (1 << 0)
1812#define V4L2_EVENT_CTRL_CH_FLAGS (1 << 1) 1802#define V4L2_EVENT_CTRL_CH_FLAGS (1 << 1)
1803#define V4L2_EVENT_CTRL_CH_RANGE (1 << 2)
1813 1804
1814struct v4l2_event_ctrl { 1805struct v4l2_event_ctrl {
1815 __u32 changes; 1806 __u32 changes;